81#ifdef EXPENSIVE_CHECKS
87#define DEBUG_TYPE "dfa-jump-threading"
89STATISTIC(NumTransforms,
"Number of transformations done");
91STATISTIC(NumPaths,
"Number of individual paths threaded");
95 cl::desc(
"View the CFG before DFA Jump Threading"),
99 "dfa-max-path-length",
100 cl::desc(
"Max number of blocks searched to find a threading path"),
105 cl::desc(
"Max number of paths enumerated around a switch"),
110 cl::desc(
"Maximum cost accepted for the transformation"),
115class SelectInstToUnfold {
123 PHINode *getUse() {
return SIUse; }
125 explicit operator bool()
const {
return SI && SIUse; }
129 std::vector<SelectInstToUnfold> *NewSIsToUnfold,
130 std::vector<BasicBlock *> *NewBBs);
132class DFAJumpThreading {
136 : AC(AC), DT(DT),
TTI(
TTI), ORE(ORE) {}
146 for (SelectInstToUnfold SIToUnfold : SelectInsts)
147 Stack.push_back(SIToUnfold);
149 while (!
Stack.empty()) {
150 SelectInstToUnfold SIToUnfold =
Stack.pop_back_val();
152 std::vector<SelectInstToUnfold> NewSIsToUnfold;
153 std::vector<BasicBlock *> NewBBs;
154 unfold(&DTU, SIToUnfold, &NewSIsToUnfold, &NewBBs);
157 for (
const SelectInstToUnfold &NewSIToUnfold : NewSIsToUnfold)
158 Stack.push_back(NewSIToUnfold);
173void createBasicBlockAndSinkSelectInst(
176 BranchInst **NewBranch, std::vector<SelectInstToUnfold> *NewSIsToUnfold,
177 std::vector<BasicBlock *> *NewBBs) {
183 NewBBs->push_back(*NewBlock);
186 NewSIsToUnfold->push_back(SelectInstToUnfold(SIToSink, SIUse));
187 DTU->
applyUpdates({{DominatorTree::Insert, *NewBlock, EndBlock}});
198 std::vector<SelectInstToUnfold> *NewSIsToUnfold,
199 std::vector<BasicBlock *> *NewBBs) {
201 PHINode *SIUse = SIToUnfold.getUse();
218 if (
SelectInst *SIOp = dyn_cast<SelectInst>(
SI->getTrueValue())) {
219 createBasicBlockAndSinkSelectInst(DTU, SI, SIUse, SIOp, EndBlock,
220 "si.unfold.true", &TrueBlock, &TrueBranch,
221 NewSIsToUnfold, NewBBs);
223 if (
SelectInst *SIOp = dyn_cast<SelectInst>(
SI->getFalseValue())) {
224 createBasicBlockAndSinkSelectInst(DTU, SI, SIUse, SIOp, EndBlock,
225 "si.unfold.false", &FalseBlock,
226 &FalseBranch, NewSIsToUnfold, NewBBs);
231 if (!TrueBlock && !FalseBlock) {
234 NewBBs->push_back(FalseBlock);
236 DTU->
applyUpdates({{DominatorTree::Insert, FalseBlock, EndBlock}});
246 if (TrueBlock && FalseBlock) {
259 Phi.addIncoming(
Phi.getIncomingValueForBlock(StartBlock), TrueBlock);
260 Phi.addIncoming(
Phi.getIncomingValueForBlock(StartBlock), FalseBlock);
265 Value *SIOp1 =
SI->getTrueValue();
266 Value *SIOp2 =
SI->getFalseValue();
270 NewBlock = FalseBlock;
275 NewBlock = TrueBlock;
288 for (
auto II = EndBlock->
begin();
PHINode *Phi = dyn_cast<PHINode>(II);
291 Phi->addIncoming(
Phi->getIncomingValueForBlock(StartBlock), NewBlock);
297 {DominatorTree::Insert, StartBlock, FT}});
300 SI->eraseFromParent();
308typedef std::deque<BasicBlock *> PathType;
309typedef std::vector<PathType> PathsType;
311typedef std::vector<ClonedBlock> CloneList;
340struct ThreadingPath {
342 uint64_t getExitValue()
const {
return ExitVal; }
344 ExitVal =
V->getZExtValue();
347 bool isExitValueSet()
const {
return IsExitValSet; }
350 const BasicBlock *getDeterminatorBB()
const {
return DBB; }
351 void setDeterminator(
const BasicBlock *BB) { DBB = BB; }
354 const PathType &getPath()
const {
return Path; }
355 void setPath(
const PathType &NewPath) {
Path = NewPath; }
358 OS <<
Path <<
" [ " << ExitVal <<
", " << DBB->getName() <<
" ]";
365 bool IsExitValSet =
false;
382 <<
"Switch instruction is not predictable.";
387 virtual ~MainSwitch() =
default;
400 std::deque<Value *> Q;
404 Value *SICond =
SI->getCondition();
406 if (!isa<PHINode>(SICond))
409 addToQueue(SICond, Q, SeenValues);
412 Value *Current = Q.front();
415 if (
auto *Phi = dyn_cast<PHINode>(Current)) {
416 for (
Value *Incoming :
Phi->incoming_values()) {
417 addToQueue(Incoming, Q, SeenValues);
420 }
else if (
SelectInst *SelI = dyn_cast<SelectInst>(Current)) {
421 if (!isValidSelectInst(SelI))
423 addToQueue(SelI->getTrueValue(), Q, SeenValues);
424 addToQueue(SelI->getFalseValue(), Q, SeenValues);
426 if (
auto *SelIUse = dyn_cast<PHINode>(SelI->user_back()))
427 SelectInsts.push_back(SelectInstToUnfold(SelI, SelIUse));
428 }
else if (isa<Constant>(Current)) {
444 void addToQueue(
Value *Val, std::deque<Value *> &Q,
453 if (!
SI->hasOneUse())
458 if (!SIUse && !(isa<PHINode>(SIUse) || isa<SelectInst>(SIUse)))
469 if (isa<PHINode>(SIUse) &&
475 for (SelectInstToUnfold SIToUnfold : SelectInsts) {
489struct AllSwitchPaths {
494 std::vector<ThreadingPath> &getThreadingPaths() {
return TPaths; }
495 unsigned getNumThreadingPaths() {
return TPaths.size(); }
497 BasicBlock *getSwitchBlock() {
return SwitchBlock; }
500 VisitedBlocks Visited;
501 PathsType LoopPaths = paths(SwitchBlock, Visited, 1);
502 StateDefMap StateDef = getStateDefMap(LoopPaths);
504 if (StateDef.empty()) {
508 <<
"Switch instruction is not predictable.";
513 for (PathType Path : LoopPaths) {
518 if (StateDef.count(BB) != 0) {
519 const PHINode *
Phi = dyn_cast<PHINode>(StateDef[BB]);
520 assert(Phi &&
"Expected a state-defining instr to be a phi node.");
522 const Value *
V =
Phi->getIncomingValueForBlock(PrevBB);
523 if (
const ConstantInt *
C = dyn_cast<const ConstantInt>(V)) {
524 TPath.setExitValue(
C);
525 TPath.setDeterminator(BB);
531 if (TPath.isExitValueSet() && BB ==
Path.front())
537 if (TPath.isExitValueSet() && isSupported(TPath))
538 TPaths.push_back(TPath);
547 PathsType paths(
BasicBlock *BB, VisitedBlocks &Visited,
548 unsigned PathDepth)
const {
556 <<
"Exploration stopped after visiting MaxPathLength="
568 if (!Successors.
insert(Succ).second)
572 if (Succ == SwitchBlock) {
578 if (Visited.contains(Succ))
581 PathsType SuccPaths = paths(Succ, Visited, PathDepth + 1);
582 for (
const PathType &Path : SuccPaths) {
583 PathType NewPath(Path);
584 NewPath.push_front(BB);
585 Res.push_back(NewPath);
602 StateDefMap getStateDefMap(
const PathsType &LoopPaths)
const {
607 for (
const PathType &Path : LoopPaths) {
614 assert(isa<PHINode>(FirstDef) &&
"The first definition must be a phi.");
617 Stack.push_back(dyn_cast<PHINode>(FirstDef));
620 while (!
Stack.empty()) {
624 SeenValues.
insert(CurPhi);
628 bool IsOutsideLoops = LoopBBs.
count(IncomingBB) == 0;
629 if (Incoming == FirstDef || isa<ConstantInt>(Incoming) ||
630 SeenValues.
contains(Incoming) || IsOutsideLoops) {
635 if (!isa<PHINode>(Incoming))
636 return StateDefMap();
638 Stack.push_back(cast<PHINode>(Incoming));
663 bool isSupported(
const ThreadingPath &TPath) {
671 const BasicBlock *DeterminatorBB = TPath.getDeterminatorBB();
674 SwitchCondUseBB == TPath.getPath().front() &&
675 "The first BB in a threading path should have the switch instruction");
676 if (SwitchCondUseBB != TPath.getPath().front())
680 PathType
Path = TPath.getPath();
681 auto ItDet =
llvm::find(Path, DeterminatorBB);
682 std::rotate(
Path.begin(), ItDet,
Path.end());
684 bool IsDetBBSeen =
false;
685 bool IsDefBBSeen =
false;
686 bool IsUseBBSeen =
false;
688 if (BB == DeterminatorBB)
690 if (BB == SwitchCondDefBB)
692 if (BB == SwitchCondUseBB)
694 if (IsDetBBSeen && IsUseBBSeen && !IsDefBBSeen)
704 std::vector<ThreadingPath> TPaths;
712 : SwitchPaths(SwitchPaths), DT(DT), AC(AC),
TTI(
TTI), ORE(ORE),
713 EphValues(EphValues) {}
716 if (isLegalAndProfitableToTransform()) {
717 createAllExitPaths();
727 bool isLegalAndProfitableToTransform() {
733 DuplicateBlockMap DuplicateMap;
735 for (ThreadingPath &TPath : SwitchPaths->getThreadingPaths()) {
736 PathType PathBBs = TPath.getPath();
737 uint64_t NextState = TPath.getExitValue();
738 const BasicBlock *Determinator = TPath.getDeterminatorBB();
741 BasicBlock *BB = SwitchPaths->getSwitchBlock();
742 BasicBlock *VisitedBB = getClonedBB(BB, NextState, DuplicateMap);
744 Metrics.analyzeBasicBlock(BB, *
TTI, EphValues);
745 DuplicateMap[BB].push_back({BB, NextState});
750 if (PathBBs.front() == Determinator)
755 auto DetIt =
llvm::find(PathBBs, Determinator);
756 for (
auto BBIt = DetIt; BBIt != PathBBs.end(); BBIt++) {
758 VisitedBB = getClonedBB(BB, NextState, DuplicateMap);
761 Metrics.analyzeBasicBlock(BB, *
TTI, EphValues);
762 DuplicateMap[BB].push_back({BB, NextState});
766 LLVM_DEBUG(
dbgs() <<
"DFA Jump Threading: Not jump threading, contains "
767 <<
"non-duplicatable instructions.\n");
771 <<
"Contains non-duplicatable instructions.";
777 LLVM_DEBUG(
dbgs() <<
"DFA Jump Threading: Not jump threading, contains "
778 <<
"convergent instructions.\n");
781 <<
"Contains convergent instructions.";
786 if (!
Metrics.NumInsts.isValid()) {
787 LLVM_DEBUG(
dbgs() <<
"DFA Jump Threading: Not jump threading, contains "
788 <<
"instructions with invalid cost.\n");
791 <<
"Contains instructions with invalid cost.";
799 unsigned JumpTableSize = 0;
802 if (JumpTableSize == 0) {
806 unsigned CondBranches =
808 DuplicationCost =
Metrics.NumInsts / CondBranches;
816 DuplicationCost =
Metrics.NumInsts / JumpTableSize;
819 LLVM_DEBUG(
dbgs() <<
"\nDFA Jump Threading: Cost to jump thread block "
820 << SwitchPaths->getSwitchBlock()->getName()
821 <<
" is: " << DuplicationCost <<
"\n\n");
824 LLVM_DEBUG(
dbgs() <<
"Not jump threading, duplication cost exceeds the "
825 <<
"cost threshold.\n");
828 <<
"Duplication cost exceeds the cost threshold (cost="
829 <<
ore::NV(
"Cost", DuplicationCost)
837 <<
"Switch statement jump-threaded.";
844 void createAllExitPaths() {
848 BasicBlock *SwitchBlock = SwitchPaths->getSwitchBlock();
849 for (ThreadingPath &TPath : SwitchPaths->getThreadingPaths()) {
851 PathType NewPath(TPath.getPath());
852 NewPath.push_back(SwitchBlock);
853 TPath.setPath(NewPath);
857 DuplicateBlockMap DuplicateMap;
864 for (ThreadingPath &TPath : SwitchPaths->getThreadingPaths()) {
865 createExitPath(NewDefs, TPath, DuplicateMap, BlocksToClean, &DTU);
871 for (ThreadingPath &TPath : SwitchPaths->getThreadingPaths())
872 updateLastSuccessor(TPath, DuplicateMap, &DTU);
888 void createExitPath(DefMap &NewDefs, ThreadingPath &Path,
889 DuplicateBlockMap &DuplicateMap,
894 PathType PathBBs =
Path.getPath();
897 if (PathBBs.front() == Determinator)
900 auto DetIt =
llvm::find(PathBBs, Determinator);
901 auto Prev = std::prev(DetIt);
903 for (
auto BBIt = DetIt; BBIt != PathBBs.end(); BBIt++) {
909 BasicBlock *NextBB = getClonedBB(BB, NextState, DuplicateMap);
911 updatePredecessor(PrevBB, BB, NextBB, DTU);
917 BasicBlock *NewBB = cloneBlockAndUpdatePredecessor(
918 BB, PrevBB, NextState, DuplicateMap, NewDefs, DTU);
919 DuplicateMap[BB].push_back({NewBB, NextState});
920 BlocksToClean.
insert(NewBB);
931 void updateSSA(DefMap &NewDefs) {
935 for (
const auto &KV : NewDefs) {
938 std::vector<Instruction *> Cloned = KV.second;
942 for (
Use &U :
I->uses()) {
945 if (UserPN->getIncomingBlock(U) == BB)
947 }
else if (
User->getParent() == BB) {
956 if (UsesToRename.
empty())
964 unsigned VarNum = SSAUpdate.
AddVariable(
I->getName(),
I->getType());
969 while (!UsesToRename.
empty())
985 DuplicateBlockMap &DuplicateMap,
990 BB, VMap,
".jt" + std::to_string(NextState), BB->
getParent());
998 if (isa<PHINode>(&
I))
1003 AC->registerAssumption(II);
1006 updateSuccessorPhis(BB, NewBB, NextState, VMap, DuplicateMap);
1007 updatePredecessor(PrevBB, BB, NewBB, DTU);
1008 updateDefMap(NewDefs, VMap);
1013 if (SuccSet.
insert(SuccBB).second)
1014 DTU->
applyUpdates({{DominatorTree::Insert, NewBB, SuccBB}});
1026 DuplicateBlockMap &DuplicateMap) {
1027 std::vector<BasicBlock *> BlocksToUpdate;
1031 if (BB == SwitchPaths->getSwitchBlock()) {
1033 BasicBlock *NextCase = getNextCaseSuccessor(Switch, NextState);
1034 BlocksToUpdate.push_back(NextCase);
1035 BasicBlock *ClonedSucc = getClonedBB(NextCase, NextState, DuplicateMap);
1037 BlocksToUpdate.push_back(ClonedSucc);
1042 BlocksToUpdate.push_back(Succ);
1047 BasicBlock *ClonedSucc = getClonedBB(Succ, NextState, DuplicateMap);
1049 BlocksToUpdate.push_back(ClonedSucc);
1057 for (
auto II = Succ->begin();
PHINode *Phi = dyn_cast<PHINode>(II);
1059 Value *Incoming =
Phi->getIncomingValueForBlock(BB);
1061 if (isa<Constant>(Incoming)) {
1062 Phi->addIncoming(Incoming, ClonedBB);
1065 Value *ClonedVal = VMap[Incoming];
1067 Phi->addIncoming(ClonedVal, ClonedBB);
1069 Phi->addIncoming(Incoming, ClonedBB);
1081 if (!isPredecessor(OldBB, PrevBB))
1091 DTU->
applyUpdates({{DominatorTree::Delete, PrevBB, OldBB},
1092 {DominatorTree::Insert, PrevBB, NewBB}});
1101 for (
auto Entry : VMap) {
1103 dyn_cast<Instruction>(
const_cast<Value *
>(Entry.first));
1104 if (!Inst || !Entry.second || isa<BranchInst>(Inst) ||
1105 isa<SwitchInst>(Inst)) {
1109 Instruction *Cloned = dyn_cast<Instruction>(Entry.second);
1113 NewDefsVector.
push_back({Inst, Cloned});
1117 sort(NewDefsVector, [](
const auto &LHS,
const auto &RHS) {
1118 if (
LHS.first ==
RHS.first)
1119 return LHS.second->comesBefore(
RHS.second);
1120 return LHS.first->comesBefore(
RHS.first);
1123 for (
const auto &KV : NewDefsVector)
1124 NewDefs[KV.first].push_back(KV.second);
1132 void updateLastSuccessor(ThreadingPath &TPath,
1133 DuplicateBlockMap &DuplicateMap,
1135 uint64_t NextState = TPath.getExitValue();
1137 BasicBlock *LastBlock = getClonedBB(BB, NextState, DuplicateMap);
1144 BasicBlock *NextCase = getNextCaseSuccessor(Switch, NextState);
1146 std::vector<DominatorTree::UpdateType> DTUpdates;
1149 if (Succ != NextCase && SuccSet.
insert(Succ).second)
1150 DTUpdates.push_back({DominatorTree::Delete, LastBlock, Succ});
1153 Switch->eraseFromParent();
1164 std::vector<PHINode *> PhiToRemove;
1165 for (
auto II = BB->
begin();
PHINode *Phi = dyn_cast<PHINode>(II); ++II) {
1166 PhiToRemove.push_back(Phi);
1168 for (
PHINode *PN : PhiToRemove) {
1170 PN->eraseFromParent();
1176 for (
auto II = BB->
begin();
PHINode *Phi = dyn_cast<PHINode>(II); ++II) {
1177 std::vector<BasicBlock *> BlocksToRemove;
1179 if (!isPredecessor(BB, IncomingBB))
1180 BlocksToRemove.push_back(IncomingBB);
1183 Phi->removeIncomingValue(BB);
1190 DuplicateBlockMap &DuplicateMap) {
1191 CloneList ClonedBBs = DuplicateMap[BB];
1195 auto It =
llvm::find_if(ClonedBBs, [NextState](
const ClonedBlock &
C) {
1196 return C.State == NextState;
1198 return It != ClonedBBs.end() ? (*It).BB :
nullptr;
1205 for (
auto Case :
Switch->cases()) {
1206 if (Case.getCaseValue()->getZExtValue() == NextState) {
1207 NextCase = Case.getCaseSuccessor();
1212 NextCase =
Switch->getDefaultDest();
1221 AllSwitchPaths *SwitchPaths;
1227 std::vector<ThreadingPath> TPaths;
1230bool DFAJumpThreading::run(
Function &
F) {
1231 LLVM_DEBUG(
dbgs() <<
"\nDFA Jump threading: " <<
F.getName() <<
"\n");
1233 if (
F.hasOptSize()) {
1234 LLVM_DEBUG(
dbgs() <<
"Skipping due to the 'minsize' attribute\n");
1242 bool MadeChanges =
false;
1250 <<
" is a candidate\n");
1251 MainSwitch
Switch(SI, ORE);
1257 <<
"candidate for jump threading\n");
1260 unfoldSelectInstrs(DT,
Switch.getSelectInsts());
1261 if (!
Switch.getSelectInsts().empty())
1264 AllSwitchPaths SwitchPaths(&Switch, ORE);
1267 if (SwitchPaths.getNumThreadingPaths() > 0) {
1280 if (ThreadableLoops.
size() > 0)
1283 for (AllSwitchPaths SwitchPaths : ThreadableLoops) {
1284 TransformDFA Transform(&SwitchPaths, DT, AC,
TTI, ORE, EphValues);
1289#ifdef EXPENSIVE_CHECKS
1290 assert(DT->
verify(DominatorTree::VerificationLevel::Full));
1307 if (!DFAJumpThreading(&AC, &DT, &
TTI, &ORE).
run(
F))
This file implements a class to represent arbitrary precision integral constant values and operations...
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static const Function * getParent(const Value *V)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static cl::opt< unsigned > MaxPathLength("dfa-max-path-length", cl::desc("Max number of blocks searched to find a threading path"), cl::Hidden, cl::init(20))
static cl::opt< bool > ClViewCfgBefore("dfa-jump-view-cfg-before", cl::desc("View the CFG before DFA Jump Threading"), cl::Hidden, cl::init(false))
static cl::opt< unsigned > CostThreshold("dfa-cost-threshold", cl::desc("Maximum cost accepted for the transformation"), cl::Hidden, cl::init(50))
static cl::opt< unsigned > MaxNumPaths("dfa-max-num-paths", cl::desc("Max number of paths enumerated around a switch"), cl::Hidden, cl::init(200))
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
static bool isCandidate(const MachineInstr *MI, Register &DefedReg, Register FrameReg)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Class for arbitrary precision integers.
unsigned ceilLogBase2() const
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This represents the llvm.assume intrinsic.
A function analysis which provides an AssumptionCache.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
const Instruction & back() const
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
bool isUnconditional() const
This is the shared class of boolean and integer constants.
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
Analysis pass which computes a DominatorTree.
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
const BasicBlock * getParent() const
BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
This class implements a map that also provides access to all stored values in a deterministic order.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
iterator_range< const_block_iterator > blocks() const
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
void setIncomingValue(unsigned i, Value *V)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void preserve()
Mark an analysis as preserved.
Helper class for SSA formation on a set of values defined in multiple blocks.
unsigned AddVariable(StringRef Name, Type *Ty)
Add a new variable to the SSA rewriter.
void AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value.
void RewriteAllUses(DominatorTree *DT, SmallVectorImpl< PHINode * > *InsertedPHIs=nullptr)
Perform all the necessary updates, including new PHI-nodes insertion and the requested uses update.
void AddUse(unsigned Var, Use *U)
Record a use of the symbolic value.
This class represents the LLVM 'select' instruction.
const Value * getFalseValue() const
const Value * getTrueValue() const
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool contains(const T &V) const
Check if the SmallSet contains the given element.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Analysis pass providing the TargetTransformInfo.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
bool hasOneUse() const
Return true if there is exactly one use of this value.
StringRef getName() const
Return a constant reference to the value's name.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
@ Switch
The "resume-switch" lowering, where there are separate resume and destroy functions that are shared b...
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
DiagnosticInfoOptimizationBase::Argument NV
NodeAddr< InstrNode * > Instr
NodeAddr< PhiNode * > Phi
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
auto successors(const MachineBasicBlock *BB)
BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, DebugInfoFinder *DIFinder=nullptr)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
void sort(IteratorTy Start, IteratorTy End)
@ RF_IgnoreMissingLocals
If this flag is set, the remapper ignores missing function-local entries (Argument,...
@ RF_NoModuleLevelChanges
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Convert the instruction operands from referencing the current values into those specified by VM.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool pred_empty(const BasicBlock *BB)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Utility to calculate the size and a few similar metrics for a set of basic blocks.
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value * > &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop).
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Integrate with the new Pass Manager.