blob: b5729fef6ff07f0bdb92a63dd469e988873450d4 [file] [log] [blame]
Tom Stellardf8794352012-12-19 22:10:31 +00001//===-- SIAnnotateControlFlow.cpp - ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file
11/// Annotates the control flow with hardware specific intrinsics.
12//
13//===----------------------------------------------------------------------===//
14
15#include "AMDGPU.h"
Tom Stellardf8794352012-12-19 22:10:31 +000016#include "llvm/ADT/DepthFirstIterator.h"
Tom Stellardbc4497b2016-02-12 23:45:29 +000017#include "llvm/Analysis/DivergenceAnalysis.h"
Tom Stellard0f29de72015-02-05 15:32:15 +000018#include "llvm/Analysis/LoopInfo.h"
Tom Stellardb0804ec2013-06-07 20:28:43 +000019#include "llvm/IR/Constants.h"
Chandler Carruth5ad5f152014-01-13 09:26:24 +000020#include "llvm/IR/Dominators.h"
Tom Stellardb0804ec2013-06-07 20:28:43 +000021#include "llvm/IR/Instructions.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000022#include "llvm/IR/Module.h"
Chandler Carruthbe810232013-01-02 10:22:59 +000023#include "llvm/Pass.h"
24#include "llvm/Transforms/Utils/BasicBlockUtils.h"
Tom Stellardf8794352012-12-19 22:10:31 +000025#include "llvm/Transforms/Utils/SSAUpdater.h"
26
27using namespace llvm;
28
Chandler Carruth84e68b22014-04-22 02:41:26 +000029#define DEBUG_TYPE "si-annotate-control-flow"
30
Tom Stellardf8794352012-12-19 22:10:31 +000031namespace {
32
33// Complex types used in this pass
34typedef std::pair<BasicBlock *, Value *> StackEntry;
35typedef SmallVector<StackEntry, 16> StackVector;
36
37// Intrinsic names the control flow is annotated with
Matt Arsenault7898b902016-01-22 18:42:55 +000038static const char *const IfIntrinsic = "llvm.amdgcn.if";
39static const char *const ElseIntrinsic = "llvm.amdgcn.else";
Matt Arsenault48d70cb2016-07-09 17:18:39 +000040static const char *const BreakIntrinsic = "llvm.amdgcn.break";
Matt Arsenault7898b902016-01-22 18:42:55 +000041static const char *const IfBreakIntrinsic = "llvm.amdgcn.if.break";
42static const char *const ElseBreakIntrinsic = "llvm.amdgcn.else.break";
43static const char *const LoopIntrinsic = "llvm.amdgcn.loop";
44static const char *const EndCfIntrinsic = "llvm.amdgcn.end.cf";
Tom Stellardf8794352012-12-19 22:10:31 +000045
46class SIAnnotateControlFlow : public FunctionPass {
Tom Stellardbc4497b2016-02-12 23:45:29 +000047 DivergenceAnalysis *DA;
Tom Stellardf8794352012-12-19 22:10:31 +000048
Tom Stellardf8794352012-12-19 22:10:31 +000049 Type *Boolean;
50 Type *Void;
51 Type *Int64;
52 Type *ReturnStruct;
53
54 ConstantInt *BoolTrue;
55 ConstantInt *BoolFalse;
56 UndefValue *BoolUndef;
57 Constant *Int64Zero;
58
59 Constant *If;
60 Constant *Else;
61 Constant *Break;
62 Constant *IfBreak;
63 Constant *ElseBreak;
64 Constant *Loop;
65 Constant *EndCf;
66
67 DominatorTree *DT;
68 StackVector Stack;
Tom Stellardf8794352012-12-19 22:10:31 +000069
Tom Stellard0f29de72015-02-05 15:32:15 +000070 LoopInfo *LI;
71
Nicolai Haehnle05b127d2016-04-14 17:42:35 +000072 bool isUniform(BranchInst *T);
73
Tom Stellardf8794352012-12-19 22:10:31 +000074 bool isTopOfStack(BasicBlock *BB);
75
76 Value *popSaved();
77
78 void push(BasicBlock *BB, Value *Saved);
79
80 bool isElse(PHINode *Phi);
81
82 void eraseIfUnused(PHINode *Phi);
83
84 void openIf(BranchInst *Term);
85
86 void insertElse(BranchInst *Term);
87
Changpeng Fange07f1aa2016-02-12 17:11:04 +000088 Value *handleLoopCondition(Value *Cond, PHINode *Broken,
89 llvm::Loop *L, BranchInst *Term);
Tom Stellardf8794352012-12-19 22:10:31 +000090
91 void handleLoop(BranchInst *Term);
92
93 void closeControlFlow(BasicBlock *BB);
94
95public:
Tom Stellard77a17772016-01-20 15:48:27 +000096 static char ID;
97
Tom Stellardf8794352012-12-19 22:10:31 +000098 SIAnnotateControlFlow():
99 FunctionPass(ID) { }
100
Craig Topper5656db42014-04-29 07:57:24 +0000101 bool doInitialization(Module &M) override;
Tom Stellardf8794352012-12-19 22:10:31 +0000102
Craig Topper5656db42014-04-29 07:57:24 +0000103 bool runOnFunction(Function &F) override;
Tom Stellardf8794352012-12-19 22:10:31 +0000104
Craig Topper5656db42014-04-29 07:57:24 +0000105 const char *getPassName() const override {
Tom Stellardf8794352012-12-19 22:10:31 +0000106 return "SI annotate control flow";
107 }
108
Craig Topper5656db42014-04-29 07:57:24 +0000109 void getAnalysisUsage(AnalysisUsage &AU) const override {
Tom Stellard0f29de72015-02-05 15:32:15 +0000110 AU.addRequired<LoopInfoWrapperPass>();
Chandler Carruth73523022014-01-13 13:07:17 +0000111 AU.addRequired<DominatorTreeWrapperPass>();
Tom Stellardbc4497b2016-02-12 23:45:29 +0000112 AU.addRequired<DivergenceAnalysis>();
Chandler Carruth73523022014-01-13 13:07:17 +0000113 AU.addPreserved<DominatorTreeWrapperPass>();
Tom Stellardf8794352012-12-19 22:10:31 +0000114 FunctionPass::getAnalysisUsage(AU);
115 }
116
117};
118
119} // end anonymous namespace
120
Tom Stellard77a17772016-01-20 15:48:27 +0000121INITIALIZE_PASS_BEGIN(SIAnnotateControlFlow, DEBUG_TYPE,
122 "Annotate SI Control Flow", false, false)
Tom Stellardbc4497b2016-02-12 23:45:29 +0000123INITIALIZE_PASS_DEPENDENCY(DivergenceAnalysis)
Tom Stellard77a17772016-01-20 15:48:27 +0000124INITIALIZE_PASS_END(SIAnnotateControlFlow, DEBUG_TYPE,
125 "Annotate SI Control Flow", false, false)
126
Tom Stellardf8794352012-12-19 22:10:31 +0000127char SIAnnotateControlFlow::ID = 0;
128
129/// \brief Initialize all the types and constants used in the pass
130bool SIAnnotateControlFlow::doInitialization(Module &M) {
Tom Stellardf8794352012-12-19 22:10:31 +0000131 LLVMContext &Context = M.getContext();
132
133 Void = Type::getVoidTy(Context);
134 Boolean = Type::getInt1Ty(Context);
135 Int64 = Type::getInt64Ty(Context);
Craig Topper062a2ba2014-04-25 05:30:21 +0000136 ReturnStruct = StructType::get(Boolean, Int64, (Type *)nullptr);
Tom Stellardf8794352012-12-19 22:10:31 +0000137
138 BoolTrue = ConstantInt::getTrue(Context);
139 BoolFalse = ConstantInt::getFalse(Context);
140 BoolUndef = UndefValue::get(Boolean);
141 Int64Zero = ConstantInt::get(Int64, 0);
142
143 If = M.getOrInsertFunction(
Craig Topper062a2ba2014-04-25 05:30:21 +0000144 IfIntrinsic, ReturnStruct, Boolean, (Type *)nullptr);
Tom Stellardf8794352012-12-19 22:10:31 +0000145
146 Else = M.getOrInsertFunction(
Craig Topper062a2ba2014-04-25 05:30:21 +0000147 ElseIntrinsic, ReturnStruct, Int64, (Type *)nullptr);
Tom Stellardf8794352012-12-19 22:10:31 +0000148
Matt Arsenault48d70cb2016-07-09 17:18:39 +0000149 Break = M.getOrInsertFunction(
150 BreakIntrinsic, Int64, Int64, (Type *)nullptr);
151
Tom Stellardf8794352012-12-19 22:10:31 +0000152 IfBreak = M.getOrInsertFunction(
Craig Topper062a2ba2014-04-25 05:30:21 +0000153 IfBreakIntrinsic, Int64, Boolean, Int64, (Type *)nullptr);
Tom Stellardf8794352012-12-19 22:10:31 +0000154
155 ElseBreak = M.getOrInsertFunction(
Craig Topper062a2ba2014-04-25 05:30:21 +0000156 ElseBreakIntrinsic, Int64, Int64, Int64, (Type *)nullptr);
Tom Stellardf8794352012-12-19 22:10:31 +0000157
158 Loop = M.getOrInsertFunction(
Craig Topper062a2ba2014-04-25 05:30:21 +0000159 LoopIntrinsic, Boolean, Int64, (Type *)nullptr);
Tom Stellardf8794352012-12-19 22:10:31 +0000160
161 EndCf = M.getOrInsertFunction(
Craig Topper062a2ba2014-04-25 05:30:21 +0000162 EndCfIntrinsic, Void, Int64, (Type *)nullptr);
Tom Stellardf8794352012-12-19 22:10:31 +0000163
164 return false;
165}
166
Nicolai Haehnle05b127d2016-04-14 17:42:35 +0000167/// \brief Is the branch condition uniform or did the StructurizeCFG pass
168/// consider it as such?
169bool SIAnnotateControlFlow::isUniform(BranchInst *T) {
170 return DA->isUniform(T->getCondition()) ||
171 T->getMetadata("structurizecfg.uniform") != nullptr;
172}
173
Tom Stellardf8794352012-12-19 22:10:31 +0000174/// \brief Is BB the last block saved on the stack ?
175bool SIAnnotateControlFlow::isTopOfStack(BasicBlock *BB) {
Michel Danzerae0a4032013-02-14 08:00:33 +0000176 return !Stack.empty() && Stack.back().first == BB;
Tom Stellardf8794352012-12-19 22:10:31 +0000177}
178
179/// \brief Pop the last saved value from the control flow stack
180Value *SIAnnotateControlFlow::popSaved() {
181 return Stack.pop_back_val().second;
182}
183
184/// \brief Push a BB and saved value to the control flow stack
185void SIAnnotateControlFlow::push(BasicBlock *BB, Value *Saved) {
186 Stack.push_back(std::make_pair(BB, Saved));
187}
188
189/// \brief Can the condition represented by this PHI node treated like
190/// an "Else" block?
191bool SIAnnotateControlFlow::isElse(PHINode *Phi) {
Tom Stellardf8794352012-12-19 22:10:31 +0000192 BasicBlock *IDom = DT->getNode(Phi->getParent())->getIDom()->getBlock();
193 for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {
194 if (Phi->getIncomingBlock(i) == IDom) {
195
196 if (Phi->getIncomingValue(i) != BoolTrue)
197 return false;
198
199 } else {
200 if (Phi->getIncomingValue(i) != BoolFalse)
201 return false;
Tom Stellardde16a2e2014-06-20 17:06:02 +0000202
Tom Stellardf8794352012-12-19 22:10:31 +0000203 }
204 }
205 return true;
206}
207
208// \brief Erase "Phi" if it is not used any more
209void SIAnnotateControlFlow::eraseIfUnused(PHINode *Phi) {
210 if (!Phi->hasNUsesOrMore(1))
211 Phi->eraseFromParent();
212}
213
214/// \brief Open a new "If" block
215void SIAnnotateControlFlow::openIf(BranchInst *Term) {
Nicolai Haehnle05b127d2016-04-14 17:42:35 +0000216 if (isUniform(Term)) {
Tom Stellardbc4497b2016-02-12 23:45:29 +0000217 return;
218 }
Tom Stellardf8794352012-12-19 22:10:31 +0000219 Value *Ret = CallInst::Create(If, Term->getCondition(), "", Term);
220 Term->setCondition(ExtractValueInst::Create(Ret, 0, "", Term));
221 push(Term->getSuccessor(1), ExtractValueInst::Create(Ret, 1, "", Term));
222}
223
224/// \brief Close the last "If" block and open a new "Else" block
225void SIAnnotateControlFlow::insertElse(BranchInst *Term) {
Nicolai Haehnle05b127d2016-04-14 17:42:35 +0000226 if (isUniform(Term)) {
Tom Stellardbc4497b2016-02-12 23:45:29 +0000227 return;
228 }
Tom Stellardf8794352012-12-19 22:10:31 +0000229 Value *Ret = CallInst::Create(Else, popSaved(), "", Term);
230 Term->setCondition(ExtractValueInst::Create(Ret, 0, "", Term));
231 push(Term->getSuccessor(1), ExtractValueInst::Create(Ret, 1, "", Term));
232}
233
234/// \brief Recursively handle the condition leading to a loop
Tom Stellardd4a19502015-04-14 14:36:45 +0000235Value *SIAnnotateControlFlow::handleLoopCondition(Value *Cond, PHINode *Broken,
Changpeng Fange07f1aa2016-02-12 17:11:04 +0000236 llvm::Loop *L, BranchInst *Term) {
Tom Stellard0b7feb12015-05-01 03:44:08 +0000237
238 // Only search through PHI nodes which are inside the loop. If we try this
239 // with PHI nodes that are outside of the loop, we end up inserting new PHI
240 // nodes outside of the loop which depend on values defined inside the loop.
241 // This will break the module with
242 // 'Instruction does not dominate all users!' errors.
243 PHINode *Phi = nullptr;
244 if ((Phi = dyn_cast<PHINode>(Cond)) && L->contains(Phi)) {
245
Tom Stellardde16a2e2014-06-20 17:06:02 +0000246 BasicBlock *Parent = Phi->getParent();
247 PHINode *NewPhi = PHINode::Create(Int64, 0, "", &Parent->front());
248 Value *Ret = NewPhi;
Tom Stellardf8794352012-12-19 22:10:31 +0000249
Alp Tokerf907b892013-12-05 05:44:44 +0000250 // Handle all non-constant incoming values first
Tom Stellardf8794352012-12-19 22:10:31 +0000251 for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {
252 Value *Incoming = Phi->getIncomingValue(i);
Tom Stellardde16a2e2014-06-20 17:06:02 +0000253 BasicBlock *From = Phi->getIncomingBlock(i);
254 if (isa<ConstantInt>(Incoming)) {
255 NewPhi->addIncoming(Broken, From);
Tom Stellardf8794352012-12-19 22:10:31 +0000256 continue;
Tom Stellardde16a2e2014-06-20 17:06:02 +0000257 }
Tom Stellardf8794352012-12-19 22:10:31 +0000258
259 Phi->setIncomingValue(i, BoolFalse);
Changpeng Fange07f1aa2016-02-12 17:11:04 +0000260 Value *PhiArg = handleLoopCondition(Incoming, Broken, L, Term);
Tom Stellardde16a2e2014-06-20 17:06:02 +0000261 NewPhi->addIncoming(PhiArg, From);
Tom Stellardf8794352012-12-19 22:10:31 +0000262 }
263
Tom Stellardf8794352012-12-19 22:10:31 +0000264 BasicBlock *IDom = DT->getNode(Parent)->getIDom()->getBlock();
265
266 for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {
267
268 Value *Incoming = Phi->getIncomingValue(i);
269 if (Incoming != BoolTrue)
270 continue;
271
272 BasicBlock *From = Phi->getIncomingBlock(i);
273 if (From == IDom) {
Nicolai Haehnle279970c2016-04-12 16:10:38 +0000274 // We're in the following situation:
275 // IDom/From
276 // | \
277 // | If-block
278 // | /
279 // Parent
280 // where we want to break out of the loop if the If-block is not taken.
281 // Due to the depth-first traversal, there should be an end.cf
282 // intrinsic in Parent, and we insert an else.break before it.
283 //
284 // Note that the end.cf need not be the first non-phi instruction
285 // of parent, particularly when we're dealing with a multi-level
286 // break, but it should occur within a group of intrinsic calls
287 // at the beginning of the block.
Tom Stellardf8794352012-12-19 22:10:31 +0000288 CallInst *OldEnd = dyn_cast<CallInst>(Parent->getFirstInsertionPt());
Nicolai Haehnle279970c2016-04-12 16:10:38 +0000289 while (OldEnd && OldEnd->getCalledFunction() != EndCf)
290 OldEnd = dyn_cast<CallInst>(OldEnd->getNextNode());
Tom Stellardf8794352012-12-19 22:10:31 +0000291 if (OldEnd && OldEnd->getCalledFunction() == EndCf) {
Tom Stellardde16a2e2014-06-20 17:06:02 +0000292 Value *Args[] = { OldEnd->getArgOperand(0), NewPhi };
293 Ret = CallInst::Create(ElseBreak, Args, "", OldEnd);
Tom Stellardf8794352012-12-19 22:10:31 +0000294 continue;
295 }
296 }
Tom Stellardf8794352012-12-19 22:10:31 +0000297 TerminatorInst *Insert = From->getTerminator();
Tom Stellardde16a2e2014-06-20 17:06:02 +0000298 Value *PhiArg = CallInst::Create(Break, Broken, "", Insert);
299 NewPhi->setIncomingValue(i, PhiArg);
Tom Stellardf8794352012-12-19 22:10:31 +0000300 }
301 eraseIfUnused(Phi);
Tom Stellardde16a2e2014-06-20 17:06:02 +0000302 return Ret;
Tom Stellardf8794352012-12-19 22:10:31 +0000303
304 } else if (Instruction *Inst = dyn_cast<Instruction>(Cond)) {
305 BasicBlock *Parent = Inst->getParent();
Tom Stellardd4a19502015-04-14 14:36:45 +0000306 Instruction *Insert;
307 if (L->contains(Inst)) {
308 Insert = Parent->getTerminator();
309 } else {
310 Insert = L->getHeader()->getFirstNonPHIOrDbgOrLifetime();
311 }
Tom Stellardde16a2e2014-06-20 17:06:02 +0000312 Value *Args[] = { Cond, Broken };
313 return CallInst::Create(IfBreak, Args, "", Insert);
Tom Stellardf8794352012-12-19 22:10:31 +0000314
Changpeng Fange07f1aa2016-02-12 17:11:04 +0000315 // Insert IfBreak before TERM for constant COND.
316 } else if (isa<ConstantInt>(Cond)) {
317 Value *Args[] = { Cond, Broken };
318 return CallInst::Create(IfBreak, Args, "", Term);
319
Tom Stellardf8794352012-12-19 22:10:31 +0000320 } else {
Matt Arsenaulteaa3a7e2013-12-10 21:37:42 +0000321 llvm_unreachable("Unhandled loop condition!");
Tom Stellardf8794352012-12-19 22:10:31 +0000322 }
Matt Arsenault37fefd62016-06-10 02:18:02 +0000323 return nullptr;
Tom Stellardf8794352012-12-19 22:10:31 +0000324}
325
326/// \brief Handle a back edge (loop)
327void SIAnnotateControlFlow::handleLoop(BranchInst *Term) {
Nicolai Haehnle05b127d2016-04-14 17:42:35 +0000328 if (isUniform(Term)) {
Tom Stellardbc4497b2016-02-12 23:45:29 +0000329 return;
330 }
331
Tom Stellardd4a19502015-04-14 14:36:45 +0000332 BasicBlock *BB = Term->getParent();
333 llvm::Loop *L = LI->getLoopFor(BB);
Changpeng Fang26fb9d22016-07-28 23:01:45 +0000334 if (!L)
335 return;
Tom Stellardf8794352012-12-19 22:10:31 +0000336 BasicBlock *Target = Term->getSuccessor(1);
337 PHINode *Broken = PHINode::Create(Int64, 0, "", &Target->front());
338
Tom Stellardf8794352012-12-19 22:10:31 +0000339 Value *Cond = Term->getCondition();
340 Term->setCondition(BoolTrue);
Changpeng Fange07f1aa2016-02-12 17:11:04 +0000341 Value *Arg = handleLoopCondition(Cond, Broken, L, Term);
Tom Stellardf8794352012-12-19 22:10:31 +0000342
Tom Stellardf8794352012-12-19 22:10:31 +0000343 for (pred_iterator PI = pred_begin(Target), PE = pred_end(Target);
344 PI != PE; ++PI) {
345
346 Broken->addIncoming(*PI == BB ? Arg : Int64Zero, *PI);
347 }
348
349 Term->setCondition(CallInst::Create(Loop, Arg, "", Term));
350 push(Term->getSuccessor(0), Arg);
Tom Stellard0f29de72015-02-05 15:32:15 +0000351}/// \brief Close the last opened control flow
Tom Stellardf8794352012-12-19 22:10:31 +0000352void SIAnnotateControlFlow::closeControlFlow(BasicBlock *BB) {
Tom Stellard0f29de72015-02-05 15:32:15 +0000353 llvm::Loop *L = LI->getLoopFor(BB);
354
Nicolai Haehnle19f0f512016-04-14 17:42:18 +0000355 assert(Stack.back().first == BB);
Tom Stellardbc4497b2016-02-12 23:45:29 +0000356
Tom Stellard0f29de72015-02-05 15:32:15 +0000357 if (L && L->getHeader() == BB) {
358 // We can't insert an EndCF call into a loop header, because it will
359 // get executed on every iteration of the loop, when it should be
360 // executed only once before the loop.
361 SmallVector <BasicBlock*, 8> Latches;
362 L->getLoopLatches(Latches);
363
364 std::vector<BasicBlock*> Preds;
365 for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
366 if (std::find(Latches.begin(), Latches.end(), *PI) == Latches.end())
367 Preds.push_back(*PI);
368 }
Chandler Carruth96ada252015-07-22 09:52:54 +0000369 BB = llvm::SplitBlockPredecessors(BB, Preds, "endcf.split", DT, LI, false);
Tom Stellard0f29de72015-02-05 15:32:15 +0000370 }
371
Tom Stellardbc4497b2016-02-12 23:45:29 +0000372 Value *Exec = popSaved();
373 if (!isa<UndefValue>(Exec))
374 CallInst::Create(EndCf, Exec, "", &*BB->getFirstInsertionPt());
Tom Stellardf8794352012-12-19 22:10:31 +0000375}
376
377/// \brief Annotate the control flow with intrinsics so the backend can
378/// recognize if/then/else and loops.
379bool SIAnnotateControlFlow::runOnFunction(Function &F) {
Tom Stellardbc4497b2016-02-12 23:45:29 +0000380
Chandler Carruth73523022014-01-13 13:07:17 +0000381 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
Tom Stellard0f29de72015-02-05 15:32:15 +0000382 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
Tom Stellardbc4497b2016-02-12 23:45:29 +0000383 DA = &getAnalysis<DivergenceAnalysis>();
Tom Stellardf8794352012-12-19 22:10:31 +0000384
385 for (df_iterator<BasicBlock *> I = df_begin(&F.getEntryBlock()),
386 E = df_end(&F.getEntryBlock()); I != E; ++I) {
387
388 BranchInst *Term = dyn_cast<BranchInst>((*I)->getTerminator());
389
390 if (!Term || Term->isUnconditional()) {
391 if (isTopOfStack(*I))
392 closeControlFlow(*I);
Tom Stellardbc4497b2016-02-12 23:45:29 +0000393
Tom Stellardf8794352012-12-19 22:10:31 +0000394 continue;
395 }
396
397 if (I.nodeVisited(Term->getSuccessor(1))) {
398 if (isTopOfStack(*I))
399 closeControlFlow(*I);
Tom Stellardbc4497b2016-02-12 23:45:29 +0000400
Tom Stellardf8794352012-12-19 22:10:31 +0000401 handleLoop(Term);
402 continue;
403 }
404
405 if (isTopOfStack(*I)) {
406 PHINode *Phi = dyn_cast<PHINode>(Term->getCondition());
407 if (Phi && Phi->getParent() == *I && isElse(Phi)) {
408 insertElse(Term);
409 eraseIfUnused(Phi);
410 continue;
411 }
412 closeControlFlow(*I);
413 }
414 openIf(Term);
415 }
416
417 assert(Stack.empty());
418 return true;
419}
420
421/// \brief Create the annotation pass
422FunctionPass *llvm::createSIAnnotateControlFlowPass() {
Tom Stellardf8794352012-12-19 22:10:31 +0000423 return new SIAnnotateControlFlow();
424}