llvm.org GIT mirror llvm / d025c69
Revert http://reviews.llvm.org/D19926 as it breaks tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268681 91177308-0d34-0410-b5e6-96231b3b80d8 Dehao Chen 3 years ago
5 changed file(s) with 48 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
3838 PreservedAnalyses run(Function &F, AnalysisManager &AM);
3939 };
4040
41 struct CFGSimplifyPass : public FunctionPass {
42 static char ID; // Pass identification, replacement for typeid
43 unsigned BonusInstThreshold;
44 std::function PredicateFtor;
45
46 CFGSimplifyPass(int T = -1,
47 std::function Ftor = nullptr);
48 bool runOnFunction(Function &F) override;
49
50 void getAnalysisUsage(AnalysisUsage &AU) const override;
51 };
5241 }
5342
5443 #endif
195195 return PreservedAnalyses::all();
196196 }
197197
198 CFGSimplifyPass::CFGSimplifyPass(int T,
199 std::function Ftor)
200 : FunctionPass(ID), PredicateFtor(Ftor) {
201 BonusInstThreshold = (T == -1) ? UserBonusInstThreshold : unsigned(T);
202 initializeCFGSimplifyPassPass(*PassRegistry::getPassRegistry());
203 }
204
205 bool CFGSimplifyPass::runOnFunction(Function &F) {
206 if (PredicateFtor && !PredicateFtor(F))
207 return false;
208
209 if (skipFunction(F))
210 return false;
211
212 AssumptionCache *AC =
213 &getAnalysis().getAssumptionCache(F);
214 const TargetTransformInfo &TTI =
215 getAnalysis().getTTI(F);
216 return simplifyFunctionCFG(F, TTI, AC, BonusInstThreshold);
217 }
218
219 void CFGSimplifyPass::getAnalysisUsage(AnalysisUsage &AU) const {
220 AU.addRequired();
221 AU.addRequired();
222 AU.addPreserved();
198 namespace {
199 struct CFGSimplifyPass : public FunctionPass {
200 static char ID; // Pass identification, replacement for typeid
201 unsigned BonusInstThreshold;
202 std::function PredicateFtor;
203
204 CFGSimplifyPass(int T = -1,
205 std::function Ftor = nullptr)
206 : FunctionPass(ID), PredicateFtor(Ftor) {
207 BonusInstThreshold = (T == -1) ? UserBonusInstThreshold : unsigned(T);
208 initializeCFGSimplifyPassPass(*PassRegistry::getPassRegistry());
209 }
210 bool runOnFunction(Function &F) override {
211 if (skipFunction(F) || (PredicateFtor && !PredicateFtor(F)))
212 return false;
213
214 AssumptionCache *AC =
215 &getAnalysis().getAssumptionCache(F);
216 const TargetTransformInfo &TTI =
217 getAnalysis().getTTI(F);
218 return simplifyFunctionCFG(F, TTI, AC, BonusInstThreshold);
219 }
220
221 void getAnalysisUsage(AnalysisUsage &AU) const override {
222 AU.addRequired();
223 AU.addRequired();
224 AU.addPreserved();
225 }
226 };
223227 }
224228
225229 char CFGSimplifyPass::ID = 0;
6666 #include "llvm/Support/Debug.h"
6767 #include "llvm/Support/raw_ostream.h"
6868 #include "llvm/Transforms/Scalar.h"
69 #include "llvm/Transforms/Scalar/SimplifyCFG.h"
7069
7170 using namespace llvm;
7271
7978 initializeAddDiscriminatorsPass(*PassRegistry::getPassRegistry());
8079 }
8180
82 void getAnalysisUsage(AnalysisUsage &AU) const override {
83 AU.addRequired();
84 }
85
8681 bool runOnFunction(Function &F) override;
8782 };
8883 } // end anonymous namespace
9085 char AddDiscriminators::ID = 0;
9186 INITIALIZE_PASS_BEGIN(AddDiscriminators, "add-discriminators",
9287 "Add DWARF path discriminators", false, false)
93 INITIALIZE_PASS_DEPENDENCY(CFGSimplifyPass)
9488 INITIALIZE_PASS_END(AddDiscriminators, "add-discriminators",
9589 "Add DWARF path discriminators", false, false)
9690
2020
2121 if.then: ; preds = %entry
2222 %1 = load i32, i32* %i.addr, align 4, !dbg !10
23 ; CHECK: %1 = load i32, i32* %i.addr, align 4, !dbg ![[THEN:[0-9]+]]
2324
2425 store i32 %1, i32* %x, align 4, !dbg !10
25 ; CHECK: store i32 %1, i32* %x, align 4, !dbg ![[THEN:[0-9]+]]
26 ; CHECK: store i32 %1, i32* %x, align 4, !dbg ![[THEN]]
2627
2728 br label %if.end, !dbg !10
2829 ; CHECK: br label %if.end, !dbg ![[THEN]]
2930
3031 if.else: ; preds = %entry
3132 %2 = load i32, i32* %i.addr, align 4, !dbg !10
33 ; CHECK: %2 = load i32, i32* %i.addr, align 4, !dbg ![[ELSE:[0-9]+]]
3234
3335 %sub = sub nsw i32 0, %2, !dbg !10
34 ; CHECK: %sub = sub nsw i32 0, %1, !dbg ![[ELSE:[0-9]+]]
36 ; CHECK: %sub = sub nsw i32 0, %2, !dbg ![[ELSE]]
3537
3638 store i32 %sub, i32* %x, align 4, !dbg !10
3739 ; CHECK: store i32 %sub, i32* %x, align 4, !dbg ![[ELSE]]
2020
2121 ;
2222 %6 = load i32, i32* %2, align 4, !dbg !23, !tbaa !13
23 ; CHECK: %6 = load i32, i32* %2, align 4, !dbg ![[THEN1:[0-9]+]],{{.*}}
24
2325 %7 = icmp eq i32 %6, 5, !dbg !24
26 ; CHECK: %7 = icmp eq i32 %6, 5, !dbg ![[THEN2:[0-9]+]]
27
2428 br i1 %7, label %8, label %9, !dbg !25
29 ; CHECK: br i1 %7, label %8, label %9, !dbg ![[THEN3:[0-9]+]]
2530
2631 ;
2732 store i32 100, i32* %1, align 4, !dbg !26
28 ; CHECK: store i32 100, i32* %1, align 4, !dbg ![[THEN:[0-9]+]]
33 ; CHECK: store i32 100, i32* %1, align 4, !dbg ![[ELSE:[0-9]+]]
2934
3035 br label %10, !dbg !26
36 ; CHECK: br label %10, !dbg ![[ELSE]]
3137
3238 ;
3339 store i32 99, i32* %1, align 4, !dbg !27
34 ; CHECK: store i32 99, i32* %1, align 4, !dbg ![[ELSE:[0-9]+]]
40 ; CHECK: store i32 99, i32* %1, align 4, !dbg ![[COMBINE:[0-9]+]]
3541
3642 br label %10, !dbg !27
43 ; CHECK: br label %10, !dbg ![[COMBINE]]
3744
3845 ;
3946 %11 = load i32, i32* %1, align 4, !dbg !28
7986 !27 = !DILocation(line: 2, column: 42, scope: !20)
8087 !28 = !DILocation(line: 3, column: 1, scope: !4)
8188
82 ; CHECK: ![[THEN]] = !DILocation(line: 2, column: 25, scope: ![[THENBLOCK:[0-9]+]])
89 ; CHECK: ![[THEN1]] = !DILocation(line: 2, column: 17, scope: ![[THENBLOCK:[0-9]+]])
8390 ; CHECK: ![[THENBLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 1)
84 ; CHECK: ![[ELSE]] = !DILocation(line: 2, column: 42, scope: ![[ELSEBLOCK:[0-9]+]])
91 ; CHECK: ![[THEN2]] = !DILocation(line: 2, column: 19, scope: ![[THENBLOCK]])
92 ; CHECK: ![[THEN3]] = !DILocation(line: 2, column: 7, scope: ![[THENBLOCK]])
93 ; CHECK: ![[ELSE]] = !DILocation(line: 2, column: 25, scope: ![[ELSEBLOCK:[0-9]+]])
8594 ; CHECK: ![[ELSEBLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 2)
95 ; CHECK: ![[COMBINE]] = !DILocation(line: 2, column: 42, scope: ![[COMBINEBLOCK:[0-9]+]])
96 ; CHECK: ![[COMBINEBLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 3)