[llvm] 52b0db2 - [InlineCost] PrinterPass prints constants to which instructions are simplified
Kirill Naumov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 17 06:41:07 PDT 2020
Author: Kirill Naumov
Date: 2020-06-17T13:40:18Z
New Revision: 52b0db22f8cfb594c32389224570681d2d2c2f21
URL: https://github.com/llvm/llvm-project/commit/52b0db22f8cfb594c32389224570681d2d2c2f21
DIFF: https://github.com/llvm/llvm-project/commit/52b0db22f8cfb594c32389224570681d2d2c2f21.diff
LOG: [InlineCost] PrinterPass prints constants to which instructions are simplified
This patch enables printing of constants to see which instructions were
constant-folded. Needed for tests and better visiual analysis of
inliner's work.
Reviewers: apilipenko, mtrofin, davidxl, fedor.sergeev
Reviewed By: mtrofin
Differential Revision: https://reviews.llvm.org/D81024
Added:
llvm/test/Transforms/Inline/simplified_to.ll
Modified:
llvm/lib/Analysis/InlineCost.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index fd4e7c765e51..0afc88d71863 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -402,6 +402,12 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
InlineResult analyze();
+ Optional<Constant*> getSimplifiedValue(Instruction *I) {
+ if (SimplifiedValues.find(I) != SimplifiedValues.end())
+ return SimplifiedValues[I];
+ return None;
+ }
+
// Keep a bunch of stats about the cost savings found so we can print them
// out when debugging.
unsigned NumConstantArgs = 0;
@@ -766,6 +772,11 @@ void InlineCostAnnotationWriter::emitInstructionAnnot(const Instruction *I,
if (Record->hasThresholdChanged())
OS << ", threshold delta = " << Record->getThresholdDelta();
}
+ auto C = ICCA->getSimplifiedValue(const_cast<Instruction *>(I));
+ if (C) {
+ OS << ", simplified to ";
+ C.getValue()->print(OS, true);
+ }
OS << "\n";
}
@@ -2545,4 +2556,4 @@ InlineCostAnnotationPrinterPass::run(Function &F,
}
}
return PreservedAnalyses::all();
-}
\ No newline at end of file
+}
diff --git a/llvm/test/Transforms/Inline/simplified_to.ll b/llvm/test/Transforms/Inline/simplified_to.ll
new file mode 100644
index 000000000000..92c84b586800
--- /dev/null
+++ b/llvm/test/Transforms/Inline/simplified_to.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -passes="print<inline-cost>" 2>&1 | FileCheck %s
+
+; CHECK-LABEL: @test()
+; CHECK: cost before = {{.*}}, cost after = {{.*}}, threshold before = {{.*}}, threshold after = {{.*}}, cost delta = {{.*}}, simplified to i1 false
+; CHECK: %1 = icmp eq i32 4, 5
+
+define i32 @test() {
+ %1 = icmp eq i32 4, 5
+ ret i32 0
+}
+
+define void @main() {
+ %1 = call i32 @test()
+ ret void
+}
More information about the llvm-commits
mailing list