Skip to content

Commit 5a74805

Browse files
[LVI] Add NewPM printer pass (#73425)
This patch adds a NewPM printer pass for the LazyValueAnalysis.
1 parent cd9829c commit 5a74805

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

llvm/include/llvm/Analysis/LazyValueInfo.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
151151
friend struct AnalysisInfoMixin<LazyValueAnalysis>;
152152
};
153153

154+
/// Printer pass for the LazyValueAnalysis results.
155+
class LazyValueInfoPrinterPass
156+
: public PassInfoMixin<LazyValueInfoPrinterPass> {
157+
raw_ostream &OS;
158+
159+
public:
160+
explicit LazyValueInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
161+
162+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
163+
};
164+
154165
/// Wrapper around LazyValueInfo.
155166
class LazyValueInfoWrapperPass : public FunctionPass {
156167
LazyValueInfoWrapperPass(const LazyValueInfoWrapperPass&) = delete;

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,15 @@ void LazyValueInfoAnnotatedWriter::emitInstructionAnnot(
20872087

20882088
}
20892089

2090+
PreservedAnalyses LazyValueInfoPrinterPass::run(Function &F,
2091+
FunctionAnalysisManager &AM) {
2092+
OS << "LVI for function '" << F.getName() << "':\n";
2093+
auto &LVI = AM.getResult<LazyValueAnalysis>(F);
2094+
auto &DTree = AM.getResult<DominatorTreeAnalysis>(F);
2095+
LVI.printLVI(F, DTree, OS);
2096+
return PreservedAnalyses::all();
2097+
}
2098+
20902099
namespace {
20912100
// Printer class for LazyValueInfo results.
20922101
class LazyValueInfoPrinter : public FunctionPass {

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ FUNCTION_PASS("print<func-properties>", FunctionPropertiesPrinterPass(dbgs()))
400400
FUNCTION_PASS("print<inline-cost>", InlineCostAnnotationPrinterPass(dbgs()))
401401
FUNCTION_PASS("print<inliner-size-estimator>",
402402
InlineSizeEstimatorAnalysisPrinterPass(dbgs()))
403+
FUNCTION_PASS("print<lazy-value-info>", LazyValueInfoPrinterPass(dbgs()))
403404
FUNCTION_PASS("print<loops>", LoopPrinterPass(dbgs()))
404405
FUNCTION_PASS("print<memoryssa-walker>", MemorySSAWalkerPrinterPass(dbgs()))
405406
FUNCTION_PASS("print<phi-values>", PhiValuesPrinterPass(dbgs()))
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; RUN: opt %s -disable-output -passes="jump-threading,print<lazy-value-info>" 2>&1 | FileCheck %s
2+
3+
; first to populate the values.
4+
5+
define i32 @constraint(i32 %a) {
6+
; CHECK-LABEL: LVI for function 'constraint':
7+
chklt64:
8+
; CHECK-LABEL: chklt64:
9+
; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: overdefined
10+
; CHECK-NEXT: ; LatticeVal for: ' %cmp = icmp slt i32 %a, 64' in BB: '%chklt64' is: overdefined
11+
; CHECK-NEXT: ; LatticeVal for: ' %cmp = icmp slt i32 %a, 64' in BB: '%chkgt0' is: constantrange<-1, 0>
12+
; CHECK-NEXT: ; LatticeVal for: ' %cmp = icmp slt i32 %a, 64' in BB: '%notinbounds' is: overdefined
13+
; CHECK-NEXT: %cmp = icmp slt i32 %a, 64
14+
; CHECK-NEXT: ; LatticeVal for: ' br i1 %cmp, label %chkgt0, label %notinbounds' in BB: '%chklt64' is: overdefined
15+
; CHECK-NEXT: ; LatticeVal for: ' br i1 %cmp, label %chkgt0, label %notinbounds' in BB: '%chkgt0' is: overdefined
16+
; CHECK-NEXT: ; LatticeVal for: ' br i1 %cmp, label %chkgt0, label %notinbounds' in BB: '%notinbounds' is: overdefined
17+
; CHECK-NEXT: br i1 %cmp, label %chkgt0, label %notinbounds
18+
%cmp = icmp slt i32 %a, 64
19+
br i1 %cmp, label %chkgt0, label %notinbounds
20+
21+
chkgt0:
22+
; CHECK-LABEL: chkgt0:
23+
; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: constantrange<-2147483648, 64>
24+
; CHECK-NEXT: ; LatticeVal for: ' %cmp1 = icmp sgt i32 %a, 0' in BB: '%chkgt0' is: overdefined
25+
; CHECK-NEXT: ; LatticeVal for: ' %cmp1 = icmp sgt i32 %a, 0' in BB: '%inbounds' is: constantrange<-1, 0>
26+
; CHECK-NEXT: %cmp1 = icmp sgt i32 %a, 0
27+
; CHECK-NEXT: ; LatticeVal for: ' br i1 %cmp1, label %inbounds, label %notinbounds' in BB: '%chkgt0' is: overdefined
28+
; CHECK-NEXT: ; LatticeVal for: ' br i1 %cmp1, label %inbounds, label %notinbounds' in BB: '%inbounds' is: overdefined
29+
; CHECK-NEXT: br i1 %cmp1, label %inbounds, label %notinbounds
30+
%cmp1 = icmp sgt i32 %a, 0
31+
br i1 %cmp1, label %inbounds, label %notinbounds
32+
33+
inbounds:
34+
; CHECK-LABEL: inbounds:
35+
; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: constantrange<1, 64>
36+
; CHECK-NEXT: ; LatticeVal for: ' ret i32 %a' in BB: '%inbounds' is: overdefined
37+
; CHECK-NEXT: ret i32 %a
38+
ret i32 %a
39+
40+
notinbounds:
41+
; CHECK-LABEL: notinbounds:
42+
; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: constantrange<64, 1>
43+
; CHECK-NEXT: ; LatticeVal for: ' %sum = add i32 %a, 64' in BB: '%notinbounds' is: constantrange<128, 65>
44+
; CHECK-NEXT: %sum = add i32 %a, 64
45+
; CHECK-NEXT: ; LatticeVal for: ' ret i32 %sum' in BB: '%notinbounds' is: overdefined
46+
; CHECK-NEXT: ret i32 %sum
47+
%sum = add i32 %a, 64
48+
ret i32 %sum
49+
}

0 commit comments

Comments
 (0)