Lines Matching +full:flow +full:- +full:control

1 //===- SIAnnotateControlFlow.cpp ------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// Annotates the control flow with hardware specific intrinsics.
12 //===----------------------------------------------------------------------===//
31 #define DEBUG_TYPE "si-annotate-control-flow"
98 StringRef getPassName() const override { return "SI annotate control flow"; } in getPassName()
114 "Annotate SI Control Flow", false, false)
119 "Annotate SI Control Flow", false, false)
150 return UA->isUniform(T) || T->hasMetadata("structurizecfg.uniform"); in isUniform()
158 /// Pop the last saved value from the control flow stack
163 /// Push a BB and saved value to the control flow stack
171 BasicBlock *IDom = DT->getNode(Phi->getParent())->getIDom()->getBlock(); in isElse()
172 for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) { in isElse()
173 if (Phi->getIncomingBlock(i) == IDom) { in isElse()
175 if (Phi->getIncomingValue(i) != BoolTrue) in isElse()
179 if (Phi->getIncomingValue(i) != BoolFalse) in isElse()
190 if (CI->getIntrinsicID() == Intrinsic::amdgcn_kill) in hasKill()
210 Value *IfCall = IRB.CreateCall(If, {Term->getCondition()}); in openIf()
213 Term->setCondition(Cond); in openIf()
214 push(Term->getSuccessor(1), Mask); in openIf()
228 Term->setCondition(Cond); in insertElse()
229 push(Term->getSuccessor(1), Mask); in insertElse()
237 auto CreateBreak = [this, Cond, Broken](Instruction *I) -> CallInst * { in handleLoopCondition()
242 BasicBlock *Parent = Inst->getParent(); in handleLoopCondition()
244 if (L->contains(Inst)) { in handleLoopCondition()
245 Insert = Parent->getTerminator(); in handleLoopCondition()
247 Insert = L->getHeader()->getFirstNonPHIOrDbgOrLifetime(); in handleLoopCondition()
256 Term : L->getHeader()->getTerminator(); in handleLoopCondition()
262 Instruction *Insert = L->getHeader()->getFirstNonPHIOrDbgOrLifetime(); in handleLoopCondition()
274 BasicBlock *BB = Term->getParent(); in handleLoop()
275 llvm::Loop *L = LI->getLoopFor(BB); in handleLoop()
279 BasicBlock *Target = Term->getSuccessor(1); in handleLoop()
281 Broken->insertBefore(Target->begin()); in handleLoop()
283 Value *Cond = Term->getCondition(); in handleLoop()
284 Term->setCondition(BoolTrue); in handleLoop()
294 else if (L->contains(Pred) && DT->dominates(Pred, BB)) in handleLoop()
296 Broken->addIncoming(PHIValue, Pred); in handleLoop()
300 Term->setCondition(LoopCall); in handleLoop()
302 push(Term->getSuccessor(0), Arg); in handleLoop()
307 /// Close the last opened control flow
309 llvm::Loop *L = LI->getLoopFor(BB); in closeControlFlow()
313 if (L && L->getHeader() == BB) { in closeControlFlow()
318 L->getLoopLatches(Latches); in closeControlFlow()
331 BasicBlock::iterator FirstInsertionPt = BB->getFirstInsertionPt(); in closeControlFlow()
334 BasicBlock *DefBB = ExecDef->getParent(); in closeControlFlow()
335 if (!DT->dominates(DefBB, BB)) { in closeControlFlow()
337 FirstInsertionPt = SplitEdge(DefBB, BB, DT, LI)->getFirstInsertionPt(); in closeControlFlow()
339 IRBuilder<> IRB(FirstInsertionPt->getParent(), FirstInsertionPt); in closeControlFlow()
340 // TODO: StructurizeCFG 'Flow' blocks have debug locations from the in closeControlFlow()
350 /// Annotate the control flow with intrinsics so the backend can
364 BranchInst *Term = dyn_cast<BranchInst>(BB->getTerminator()); in runOnFunction()
366 if (!Term || Term->isUnconditional()) { in runOnFunction()
373 if (I.nodeVisited(Term->getSuccessor(1))) { in runOnFunction()
377 if (DT->dominates(Term->getSuccessor(1), BB)) in runOnFunction()
383 PHINode *Phi = dyn_cast<PHINode>(Term->getCondition()); in runOnFunction()
384 if (Phi && Phi->getParent() == BB && isElse(Phi) && !hasKill(BB)) { in runOnFunction()