blob: 90f430d5ca4c6c16bb946951db76dee704c68025 [file] [log] [blame]
Eugene Zelenko59e12822017-08-08 00:47:13 +00001//===- SIAnnotateControlFlow.cpp ------------------------------------------===//
Tom Stellardf8794352012-12-19 22:10:31 +00002//
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"
Eugene Zelenko59e12822017-08-08 00:47:13 +000017#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/SmallVector.h"
Nicolai Haehnle35617ed2018-08-30 14:21:36 +000019#include "llvm/Analysis/LegacyDivergenceAnalysis.h"
Tom Stellard0f29de72015-02-05 15:32:15 +000020#include "llvm/Analysis/LoopInfo.h"
David Blaikie31b98d22018-06-04 21:23:21 +000021#include "llvm/Transforms/Utils/Local.h"
Eugene Zelenko59e12822017-08-08 00:47:13 +000022#include "llvm/IR/BasicBlock.h"
23#include "llvm/IR/CFG.h"
24#include "llvm/IR/Constant.h"
Tom Stellardb0804ec2013-06-07 20:28:43 +000025#include "llvm/IR/Constants.h"
Eugene Zelenko59e12822017-08-08 00:47:13 +000026#include "llvm/IR/DerivedTypes.h"
Chandler Carruth5ad5f152014-01-13 09:26:24 +000027#include "llvm/IR/Dominators.h"
Eugene Zelenko59e12822017-08-08 00:47:13 +000028#include "llvm/IR/Function.h"
29#include "llvm/IR/Instruction.h"
Tom Stellardb0804ec2013-06-07 20:28:43 +000030#include "llvm/IR/Instructions.h"
Eugene Zelenko59e12822017-08-08 00:47:13 +000031#include "llvm/IR/Intrinsics.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000032#include "llvm/IR/Module.h"
Eugene Zelenko59e12822017-08-08 00:47:13 +000033#include "llvm/IR/Type.h"
34#include "llvm/IR/ValueHandle.h"
Chandler Carruthbe810232013-01-02 10:22:59 +000035#include "llvm/Pass.h"
Eugene Zelenko59e12822017-08-08 00:47:13 +000036#include "llvm/Support/Casting.h"
37#include "llvm/Support/Debug.h"
38#include "llvm/Support/ErrorHandling.h"
39#include "llvm/Support/raw_ostream.h"
Chandler Carruthbe810232013-01-02 10:22:59 +000040#include "llvm/Transforms/Utils/BasicBlockUtils.h"
Eugene Zelenko59e12822017-08-08 00:47:13 +000041#include <cassert>
42#include <utility>
Tom Stellardf8794352012-12-19 22:10:31 +000043
44using namespace llvm;
45
Chandler Carruth84e68b22014-04-22 02:41:26 +000046#define DEBUG_TYPE "si-annotate-control-flow"
47
Tom Stellardf8794352012-12-19 22:10:31 +000048namespace {
49
50// Complex types used in this pass
Eugene Zelenko59e12822017-08-08 00:47:13 +000051using StackEntry = std::pair<BasicBlock *, Value *>;
52using StackVector = SmallVector<StackEntry, 16>;
Tom Stellardf8794352012-12-19 22:10:31 +000053
Tom Stellardf8794352012-12-19 22:10:31 +000054class SIAnnotateControlFlow : public FunctionPass {
Nicolai Haehnle35617ed2018-08-30 14:21:36 +000055 LegacyDivergenceAnalysis *DA;
Tom Stellardf8794352012-12-19 22:10:31 +000056
Tom Stellardf8794352012-12-19 22:10:31 +000057 Type *Boolean;
58 Type *Void;
59 Type *Int64;
60 Type *ReturnStruct;
61
62 ConstantInt *BoolTrue;
63 ConstantInt *BoolFalse;
64 UndefValue *BoolUndef;
65 Constant *Int64Zero;
66
Matt Arsenaultc5b641a2017-03-17 20:41:45 +000067 Function *If;
68 Function *Else;
Matt Arsenaultc5b641a2017-03-17 20:41:45 +000069 Function *IfBreak;
Matt Arsenaultc5b641a2017-03-17 20:41:45 +000070 Function *Loop;
71 Function *EndCf;
Tom Stellardf8794352012-12-19 22:10:31 +000072
73 DominatorTree *DT;
74 StackVector Stack;
Tom Stellardf8794352012-12-19 22:10:31 +000075
Tom Stellard0f29de72015-02-05 15:32:15 +000076 LoopInfo *LI;
77
Nicolai Haehnle05b127d2016-04-14 17:42:35 +000078 bool isUniform(BranchInst *T);
79
Tom Stellardf8794352012-12-19 22:10:31 +000080 bool isTopOfStack(BasicBlock *BB);
81
82 Value *popSaved();
83
84 void push(BasicBlock *BB, Value *Saved);
85
86 bool isElse(PHINode *Phi);
87
88 void eraseIfUnused(PHINode *Phi);
89
90 void openIf(BranchInst *Term);
91
92 void insertElse(BranchInst *Term);
93
Sanjoy Dase6bca0e2017-05-01 17:07:49 +000094 Value *
95 handleLoopCondition(Value *Cond, PHINode *Broken, llvm::Loop *L,
Nicolai Haehnle28212cc2018-10-31 13:26:48 +000096 BranchInst *Term);
Tom Stellardf8794352012-12-19 22:10:31 +000097
98 void handleLoop(BranchInst *Term);
99
100 void closeControlFlow(BasicBlock *BB);
101
102public:
Tom Stellard77a17772016-01-20 15:48:27 +0000103 static char ID;
104
Eugene Zelenko59e12822017-08-08 00:47:13 +0000105 SIAnnotateControlFlow() : FunctionPass(ID) {}
Tom Stellardf8794352012-12-19 22:10:31 +0000106
Craig Topper5656db42014-04-29 07:57:24 +0000107 bool doInitialization(Module &M) override;
Tom Stellardf8794352012-12-19 22:10:31 +0000108
Craig Topper5656db42014-04-29 07:57:24 +0000109 bool runOnFunction(Function &F) override;
Tom Stellardf8794352012-12-19 22:10:31 +0000110
Mehdi Amini117296c2016-10-01 02:56:57 +0000111 StringRef getPassName() const override { return "SI annotate control flow"; }
Tom Stellardf8794352012-12-19 22:10:31 +0000112
Craig Topper5656db42014-04-29 07:57:24 +0000113 void getAnalysisUsage(AnalysisUsage &AU) const override {
Tom Stellard0f29de72015-02-05 15:32:15 +0000114 AU.addRequired<LoopInfoWrapperPass>();
Chandler Carruth73523022014-01-13 13:07:17 +0000115 AU.addRequired<DominatorTreeWrapperPass>();
Nicolai Haehnle35617ed2018-08-30 14:21:36 +0000116 AU.addRequired<LegacyDivergenceAnalysis>();
Chandler Carruth73523022014-01-13 13:07:17 +0000117 AU.addPreserved<DominatorTreeWrapperPass>();
Tom Stellardf8794352012-12-19 22:10:31 +0000118 FunctionPass::getAnalysisUsage(AU);
119 }
Tom Stellardf8794352012-12-19 22:10:31 +0000120};
121
122} // end anonymous namespace
123
Tom Stellard77a17772016-01-20 15:48:27 +0000124INITIALIZE_PASS_BEGIN(SIAnnotateControlFlow, DEBUG_TYPE,
125 "Annotate SI Control Flow", false, false)
Matt Arsenault31a58c62017-03-02 23:50:51 +0000126INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
Nicolai Haehnle35617ed2018-08-30 14:21:36 +0000127INITIALIZE_PASS_DEPENDENCY(LegacyDivergenceAnalysis)
Tom Stellard77a17772016-01-20 15:48:27 +0000128INITIALIZE_PASS_END(SIAnnotateControlFlow, DEBUG_TYPE,
129 "Annotate SI Control Flow", false, false)
130
Tom Stellardf8794352012-12-19 22:10:31 +0000131char SIAnnotateControlFlow::ID = 0;
132
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000133/// Initialize all the types and constants used in the pass
Tom Stellardf8794352012-12-19 22:10:31 +0000134bool SIAnnotateControlFlow::doInitialization(Module &M) {
Tom Stellardf8794352012-12-19 22:10:31 +0000135 LLVMContext &Context = M.getContext();
136
137 Void = Type::getVoidTy(Context);
138 Boolean = Type::getInt1Ty(Context);
139 Int64 = Type::getInt64Ty(Context);
Serge Guelton1b421c22017-05-11 08:46:02 +0000140 ReturnStruct = StructType::get(Boolean, Int64);
Tom Stellardf8794352012-12-19 22:10:31 +0000141
142 BoolTrue = ConstantInt::getTrue(Context);
143 BoolFalse = ConstantInt::getFalse(Context);
144 BoolUndef = UndefValue::get(Boolean);
145 Int64Zero = ConstantInt::get(Int64, 0);
146
Matt Arsenaultc5b641a2017-03-17 20:41:45 +0000147 If = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_if);
148 Else = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_else);
Matt Arsenaultc5b641a2017-03-17 20:41:45 +0000149 IfBreak = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_if_break);
Matt Arsenaultc5b641a2017-03-17 20:41:45 +0000150 Loop = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_loop);
151 EndCf = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_end_cf);
Tom Stellardf8794352012-12-19 22:10:31 +0000152 return false;
153}
154
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000155/// Is the branch condition uniform or did the StructurizeCFG pass
Nicolai Haehnle05b127d2016-04-14 17:42:35 +0000156/// consider it as such?
157bool SIAnnotateControlFlow::isUniform(BranchInst *T) {
158 return DA->isUniform(T->getCondition()) ||
159 T->getMetadata("structurizecfg.uniform") != nullptr;
160}
161
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000162/// Is BB the last block saved on the stack ?
Tom Stellardf8794352012-12-19 22:10:31 +0000163bool SIAnnotateControlFlow::isTopOfStack(BasicBlock *BB) {
Michel Danzerae0a4032013-02-14 08:00:33 +0000164 return !Stack.empty() && Stack.back().first == BB;
Tom Stellardf8794352012-12-19 22:10:31 +0000165}
166
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000167/// Pop the last saved value from the control flow stack
Tom Stellardf8794352012-12-19 22:10:31 +0000168Value *SIAnnotateControlFlow::popSaved() {
169 return Stack.pop_back_val().second;
170}
171
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000172/// Push a BB and saved value to the control flow stack
Tom Stellardf8794352012-12-19 22:10:31 +0000173void SIAnnotateControlFlow::push(BasicBlock *BB, Value *Saved) {
174 Stack.push_back(std::make_pair(BB, Saved));
175}
176
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000177/// Can the condition represented by this PHI node treated like
Tom Stellardf8794352012-12-19 22:10:31 +0000178/// an "Else" block?
179bool SIAnnotateControlFlow::isElse(PHINode *Phi) {
Tom Stellardf8794352012-12-19 22:10:31 +0000180 BasicBlock *IDom = DT->getNode(Phi->getParent())->getIDom()->getBlock();
181 for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {
182 if (Phi->getIncomingBlock(i) == IDom) {
183
184 if (Phi->getIncomingValue(i) != BoolTrue)
185 return false;
186
187 } else {
188 if (Phi->getIncomingValue(i) != BoolFalse)
189 return false;
Tom Stellardde16a2e2014-06-20 17:06:02 +0000190
Tom Stellardf8794352012-12-19 22:10:31 +0000191 }
192 }
193 return true;
194}
195
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000196// Erase "Phi" if it is not used any more
Tom Stellardf8794352012-12-19 22:10:31 +0000197void SIAnnotateControlFlow::eraseIfUnused(PHINode *Phi) {
Eugene Zelenko59e12822017-08-08 00:47:13 +0000198 if (RecursivelyDeleteDeadPHINode(Phi)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000199 LLVM_DEBUG(dbgs() << "Erased unused condition phi\n");
Matt Arsenault0607a442017-03-24 20:57:10 +0000200 }
Tom Stellardf8794352012-12-19 22:10:31 +0000201}
202
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000203/// Open a new "If" block
Tom Stellardf8794352012-12-19 22:10:31 +0000204void SIAnnotateControlFlow::openIf(BranchInst *Term) {
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000205 if (isUniform(Term))
Tom Stellardbc4497b2016-02-12 23:45:29 +0000206 return;
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000207
Tom Stellardf8794352012-12-19 22:10:31 +0000208 Value *Ret = CallInst::Create(If, Term->getCondition(), "", Term);
209 Term->setCondition(ExtractValueInst::Create(Ret, 0, "", Term));
210 push(Term->getSuccessor(1), ExtractValueInst::Create(Ret, 1, "", Term));
211}
212
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000213/// Close the last "If" block and open a new "Else" block
Tom Stellardf8794352012-12-19 22:10:31 +0000214void SIAnnotateControlFlow::insertElse(BranchInst *Term) {
Nicolai Haehnle05b127d2016-04-14 17:42:35 +0000215 if (isUniform(Term)) {
Tom Stellardbc4497b2016-02-12 23:45:29 +0000216 return;
217 }
Tom Stellardf8794352012-12-19 22:10:31 +0000218 Value *Ret = CallInst::Create(Else, popSaved(), "", Term);
219 Term->setCondition(ExtractValueInst::Create(Ret, 0, "", Term));
220 push(Term->getSuccessor(1), ExtractValueInst::Create(Ret, 1, "", Term));
221}
222
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000223/// Recursively handle the condition leading to a loop
Matt Arsenault0607a442017-03-24 20:57:10 +0000224Value *SIAnnotateControlFlow::handleLoopCondition(
Nicolai Haehnle28212cc2018-10-31 13:26:48 +0000225 Value *Cond, PHINode *Broken, llvm::Loop *L, BranchInst *Term) {
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000226 if (Instruction *Inst = dyn_cast<Instruction>(Cond)) {
Tom Stellardf8794352012-12-19 22:10:31 +0000227 BasicBlock *Parent = Inst->getParent();
Tom Stellardd4a19502015-04-14 14:36:45 +0000228 Instruction *Insert;
229 if (L->contains(Inst)) {
230 Insert = Parent->getTerminator();
231 } else {
232 Insert = L->getHeader()->getFirstNonPHIOrDbgOrLifetime();
233 }
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000234
Tom Stellardde16a2e2014-06-20 17:06:02 +0000235 Value *Args[] = { Cond, Broken };
236 return CallInst::Create(IfBreak, Args, "", Insert);
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000237 }
Tom Stellardf8794352012-12-19 22:10:31 +0000238
Matt Arsenaulte70d5dc2017-03-17 20:52:21 +0000239 // Insert IfBreak in the loop header TERM for constant COND other than true.
240 if (isa<Constant>(Cond)) {
241 Instruction *Insert = Cond == BoolTrue ?
242 Term : L->getHeader()->getTerminator();
243
Changpeng Fange07f1aa2016-02-12 17:11:04 +0000244 Value *Args[] = { Cond, Broken };
Matt Arsenaulte70d5dc2017-03-17 20:52:21 +0000245 return CallInst::Create(IfBreak, Args, "", Insert);
Tom Stellardf8794352012-12-19 22:10:31 +0000246 }
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000247
248 llvm_unreachable("Unhandled loop condition!");
Tom Stellardf8794352012-12-19 22:10:31 +0000249}
250
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000251/// Handle a back edge (loop)
Tom Stellardf8794352012-12-19 22:10:31 +0000252void SIAnnotateControlFlow::handleLoop(BranchInst *Term) {
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000253 if (isUniform(Term))
Tom Stellardbc4497b2016-02-12 23:45:29 +0000254 return;
Tom Stellardbc4497b2016-02-12 23:45:29 +0000255
Tom Stellardd4a19502015-04-14 14:36:45 +0000256 BasicBlock *BB = Term->getParent();
257 llvm::Loop *L = LI->getLoopFor(BB);
Changpeng Fang26fb9d22016-07-28 23:01:45 +0000258 if (!L)
259 return;
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000260
Tom Stellardf8794352012-12-19 22:10:31 +0000261 BasicBlock *Target = Term->getSuccessor(1);
Matt Arsenaulte70d5dc2017-03-17 20:52:21 +0000262 PHINode *Broken = PHINode::Create(Int64, 0, "phi.broken", &Target->front());
Tom Stellardf8794352012-12-19 22:10:31 +0000263
Tom Stellardf8794352012-12-19 22:10:31 +0000264 Value *Cond = Term->getCondition();
265 Term->setCondition(BoolTrue);
Nicolai Haehnle28212cc2018-10-31 13:26:48 +0000266 Value *Arg = handleLoopCondition(Cond, Broken, L, Term);
Tom Stellardf8794352012-12-19 22:10:31 +0000267
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000268 for (BasicBlock *Pred : predecessors(Target))
269 Broken->addIncoming(Pred == BB ? Arg : Int64Zero, Pred);
Tom Stellardf8794352012-12-19 22:10:31 +0000270
271 Term->setCondition(CallInst::Create(Loop, Arg, "", Term));
Matt Arsenault0607a442017-03-24 20:57:10 +0000272
Tom Stellardf8794352012-12-19 22:10:31 +0000273 push(Term->getSuccessor(0), Arg);
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000274}
275
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000276/// Close the last opened control flow
Tom Stellardf8794352012-12-19 22:10:31 +0000277void SIAnnotateControlFlow::closeControlFlow(BasicBlock *BB) {
Tom Stellard0f29de72015-02-05 15:32:15 +0000278 llvm::Loop *L = LI->getLoopFor(BB);
279
Nicolai Haehnle19f0f512016-04-14 17:42:18 +0000280 assert(Stack.back().first == BB);
Tom Stellardbc4497b2016-02-12 23:45:29 +0000281
Tom Stellard0f29de72015-02-05 15:32:15 +0000282 if (L && L->getHeader() == BB) {
283 // We can't insert an EndCF call into a loop header, because it will
284 // get executed on every iteration of the loop, when it should be
285 // executed only once before the loop.
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000286 SmallVector <BasicBlock *, 8> Latches;
Tom Stellard0f29de72015-02-05 15:32:15 +0000287 L->getLoopLatches(Latches);
288
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000289 SmallVector<BasicBlock *, 2> Preds;
290 for (BasicBlock *Pred : predecessors(BB)) {
291 if (!is_contained(Latches, Pred))
292 Preds.push_back(Pred);
Tom Stellard0f29de72015-02-05 15:32:15 +0000293 }
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000294
Alina Sbirleaab6f84f72018-08-21 23:32:03 +0000295 BB = SplitBlockPredecessors(BB, Preds, "endcf.split", DT, LI, nullptr,
296 false);
Tom Stellard0f29de72015-02-05 15:32:15 +0000297 }
298
Tom Stellardbc4497b2016-02-12 23:45:29 +0000299 Value *Exec = popSaved();
Changpeng Fang6b49fa42017-03-07 23:29:36 +0000300 Instruction *FirstInsertionPt = &*BB->getFirstInsertionPt();
301 if (!isa<UndefValue>(Exec) && !isa<UnreachableInst>(FirstInsertionPt))
302 CallInst::Create(EndCf, Exec, "", FirstInsertionPt);
Tom Stellardf8794352012-12-19 22:10:31 +0000303}
304
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000305/// Annotate the control flow with intrinsics so the backend can
Tom Stellardf8794352012-12-19 22:10:31 +0000306/// recognize if/then/else and loops.
307bool SIAnnotateControlFlow::runOnFunction(Function &F) {
Chandler Carruth73523022014-01-13 13:07:17 +0000308 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
Tom Stellard0f29de72015-02-05 15:32:15 +0000309 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
Nicolai Haehnle35617ed2018-08-30 14:21:36 +0000310 DA = &getAnalysis<LegacyDivergenceAnalysis>();
Tom Stellardf8794352012-12-19 22:10:31 +0000311
312 for (df_iterator<BasicBlock *> I = df_begin(&F.getEntryBlock()),
313 E = df_end(&F.getEntryBlock()); I != E; ++I) {
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000314 BasicBlock *BB = *I;
315 BranchInst *Term = dyn_cast<BranchInst>(BB->getTerminator());
Tom Stellardf8794352012-12-19 22:10:31 +0000316
317 if (!Term || Term->isUnconditional()) {
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000318 if (isTopOfStack(BB))
319 closeControlFlow(BB);
Tom Stellardbc4497b2016-02-12 23:45:29 +0000320
Tom Stellardf8794352012-12-19 22:10:31 +0000321 continue;
322 }
323
324 if (I.nodeVisited(Term->getSuccessor(1))) {
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000325 if (isTopOfStack(BB))
326 closeControlFlow(BB);
Tom Stellardbc4497b2016-02-12 23:45:29 +0000327
Tom Stellardf8794352012-12-19 22:10:31 +0000328 handleLoop(Term);
329 continue;
330 }
331
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000332 if (isTopOfStack(BB)) {
Tom Stellardf8794352012-12-19 22:10:31 +0000333 PHINode *Phi = dyn_cast<PHINode>(Term->getCondition());
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000334 if (Phi && Phi->getParent() == BB && isElse(Phi)) {
Tom Stellardf8794352012-12-19 22:10:31 +0000335 insertElse(Term);
336 eraseIfUnused(Phi);
337 continue;
338 }
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000339
340 closeControlFlow(BB);
Tom Stellardf8794352012-12-19 22:10:31 +0000341 }
Matt Arsenault0e6e0182017-03-15 18:00:12 +0000342
Tom Stellardf8794352012-12-19 22:10:31 +0000343 openIf(Term);
344 }
345
Matt Arsenault1491ca82018-01-17 16:30:01 +0000346 if (!Stack.empty()) {
347 // CFG was probably not structured.
348 report_fatal_error("failed to annotate CFG");
349 }
350
Tom Stellardf8794352012-12-19 22:10:31 +0000351 return true;
352}
353
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000354/// Create the annotation pass
Tom Stellardf8794352012-12-19 22:10:31 +0000355FunctionPass *llvm::createSIAnnotateControlFlowPass() {
Tom Stellardf8794352012-12-19 22:10:31 +0000356 return new SIAnnotateControlFlow();
357}