72 #define DEBUG_TYPE "code-extractor" 80 cl::desc(
"Aggregate arguments to code-extracted functions"));
85 bool AllowVarArgs,
bool AllowAlloca) {
98 while (!ToVisit.
empty()) {
100 if (!Visited.
insert(Curr).second)
102 if (isa<BlockAddress const>(Curr))
105 if (isa<Instruction>(Curr) && cast<Instruction>(Curr)->
getParent() != &BB)
108 for (
auto const &U : Curr->
operands()) {
109 if (
auto *UU = dyn_cast<User>(U))
117 if (isa<AllocaInst>(
I)) {
123 if (
const auto *II = dyn_cast<InvokeInst>(
I)) {
126 if (
auto *UBB = II->getUnwindDest())
127 if (!Result.
count(UBB))
134 if (
const auto *CSI = dyn_cast<CatchSwitchInst>(
I)) {
135 if (
auto *UBB = CSI->getUnwindDest())
136 if (!Result.
count(UBB))
138 for (
auto *HBB : CSI->handlers())
139 if (!Result.
count(const_cast<BasicBlock*>(HBB)))
146 if (
const auto *CPI = dyn_cast<CatchPadInst>(
I)) {
147 for (
const auto *U : CPI->users())
148 if (
const auto *CRI = dyn_cast<CatchReturnInst>(U))
149 if (!Result.
count(const_cast<BasicBlock*>(CRI->getParent())))
157 if (
const auto *CPI = dyn_cast<CleanupPadInst>(
I)) {
158 for (
const auto *U : CPI->users())
159 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(U))
160 if (!Result.
count(const_cast<BasicBlock*>(CRI->getParent())))
164 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(
I)) {
165 if (
auto *UBB = CRI->getUnwindDest())
166 if (!Result.
count(UBB))
171 if (
const CallInst *CI = dyn_cast<CallInst>(
I)) {
172 if (
const Function *
F = CI->getCalledFunction()) {
173 auto IID =
F->getIntrinsicID();
195 bool AllowVarArgs,
bool AllowAlloca) {
196 assert(!BBs.
empty() &&
"The set of blocks to extract must be non-empty");
206 if (!Result.insert(BB))
210 for (
auto *BB : Result) {
215 if (BB == Result.front()) {
217 LLVM_DEBUG(
dbgs() <<
"The first block cannot be an unwind block\n");
226 if (!Result.count(PBB)) {
228 dbgs() <<
"No blocks in this region may have entries from " 229 "outside the region except for the first block!\n");
240 bool AllowAlloca, std::string Suffix)
242 BPI(BPI), AllowVarArgs(AllowVarArgs),
250 BPI(BPI), AllowVarArgs(
false),
260 if (Blocks.
count(
I->getParent()))
269 if (isa<Argument>(V))
return true;
271 if (!Blocks.
count(
I->getParent()))
278 auto hasNonCommonExitSucc = [&](
BasicBlock *Block) {
281 if (Blocks.
count(Succ))
283 if (!CommonExitBlock) {
284 CommonExitBlock = Succ;
287 if (CommonExitBlock == Succ)
295 if (
any_of(Blocks, hasNonCommonExitSucc))
298 return CommonExitBlock;
306 if (Blocks.count(&BB))
309 if (isa<DbgInfoIntrinsic>(II))
312 unsigned Opcode = II.getOpcode();
313 Value *MemAddr =
nullptr;
325 if (dyn_cast<Constant>(MemAddr))
328 if (!dyn_cast<AllocaInst>(Base) || Base == AI)
340 if (II.mayHaveSideEffects())
352 BasicBlock *SinglePredFromOutlineRegion =
nullptr;
353 assert(!Blocks.count(CommonExitBlock) &&
354 "Expect a block outside the region!");
356 if (!Blocks.count(Pred))
358 if (!SinglePredFromOutlineRegion) {
359 SinglePredFromOutlineRegion = Pred;
360 }
else if (SinglePredFromOutlineRegion != Pred) {
361 SinglePredFromOutlineRegion =
nullptr;
366 if (SinglePredFromOutlineRegion)
367 return SinglePredFromOutlineRegion;
373 while (I != BB->end()) {
386 assert(!getFirstPHI(CommonExitBlock) &&
"Phi not expected");
395 if (Blocks.count(Pred))
400 Blocks.insert(CommonExitBlock);
401 return CommonExitBlock;
410 if (Blocks.count(&BB))
422 auto GetLifeTimeMarkers =
424 bool &HoistLifeEnd) -> std::pair<Instruction *, Instruction *> {
425 Instruction *LifeStart =
nullptr, *LifeEnd =
nullptr;
433 return std::make_pair<Instruction *>(
nullptr,
nullptr);
434 LifeStart = IntrInst;
438 return std::make_pair<Instruction *>(
nullptr,
nullptr);
445 return std::make_pair<Instruction *>(
nullptr,
nullptr);
448 if (!LifeStart || !LifeEnd)
449 return std::make_pair<Instruction *>(
nullptr,
nullptr);
454 if ((SinkLifeStart || HoistLifeEnd) &&
456 return std::make_pair<Instruction *>(
nullptr,
nullptr);
459 if (HoistLifeEnd && !ExitBlock)
460 return std::make_pair<Instruction *>(
nullptr,
nullptr);
462 return std::make_pair(LifeStart, LifeEnd);
465 bool SinkLifeStart =
false, HoistLifeEnd =
false;
466 auto Markers = GetLifeTimeMarkers(AI, SinkLifeStart, HoistLifeEnd);
470 SinkCands.
insert(Markers.first);
473 HoistCands.
insert(Markers.second);
480 if (U->stripInBoundsConstantOffsets() == AI) {
481 SinkLifeStart =
false;
482 HoistLifeEnd =
false;
484 Markers = GetLifeTimeMarkers(Bitcast, SinkLifeStart, HoistLifeEnd);
493 MarkerAddr =
nullptr;
500 SinkCands.
insert(Markers.first);
502 SinkCands.
insert(MarkerAddr);
505 HoistCands.
insert(Markers.second);
536 void CodeExtractor::severSplitPHINodesOfEntry(
BasicBlock *&Header) {
537 unsigned NumPredsFromRegion = 0;
538 unsigned NumPredsOutsideRegion = 0;
549 ++NumPredsFromRegion;
551 ++NumPredsOutsideRegion;
555 if (NumPredsOutsideRegion <= 1)
return;
567 Blocks.remove(OldPred);
568 Blocks.insert(NewBB);
573 if (NumPredsFromRegion) {
574 PHINode *PN = cast<PHINode>(OldPred->begin());
586 for (AfterPHIs = OldPred->begin(); isa<PHINode>(AfterPHIs); ++AfterPHIs) {
587 PHINode *PN = cast<PHINode>(AfterPHIs);
593 NewPN->addIncoming(PN, OldPred);
612 void CodeExtractor::severSplitPHINodesOfExits(
617 for (
PHINode &PN : ExitBB->phis()) {
620 for (
unsigned i = 0; i < PN.getNumIncomingValues(); ++i)
621 if (Blocks.count(PN.getIncomingBlock(i)))
627 if (IncomingVals.
size() <= 1)
634 ExitBB->getName() +
".split",
635 ExitBB->getParent(), ExitBB);
639 if (Blocks.count(PredBB))
640 PredBB->getTerminator()->replaceUsesOfWith(ExitBB, NewBB);
642 Blocks.insert(NewBB);
649 for (
unsigned i : IncomingVals)
650 NewPN->
addIncoming(PN.getIncomingValue(i), PN.getIncomingBlock(i));
651 for (
unsigned i :
reverse(IncomingVals))
652 PN.removeIncomingValue(i,
false);
653 PN.addIncoming(NewPN, NewBB);
658 void CodeExtractor::splitReturnBlocks() {
660 if (
ReturnInst *RI = dyn_cast<ReturnInst>(Block->getTerminator())) {
662 Block->splitBasicBlock(RI->getIterator(), Block->getName() +
".ret");
691 switch (NumExitBlocks) {
698 std::vector<Type *> paramTy;
701 for (
Value *value : inputs) {
703 paramTy.push_back(value->getType());
707 for (
Value *output : outputs) {
710 paramTy.push_back(output->getType());
716 dbgs() <<
"Function type: " << *RetTy <<
" f(";
717 for (
Type *i : paramTy)
718 dbgs() << *i <<
", ";
723 if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
730 AllowVarArgs && oldFunction->
isVarArg());
732 std::string SuffixToUse =
739 oldFunction->
getName() +
"." + SuffixToUse, M);
756 if (Attr.isStringAttribute()) {
757 if (Attr.getKindAsString() ==
"thunk")
760 switch (Attr.getKindAsEnum()) {
839 for (
unsigned i = 0, e = inputs.size(); i != e; ++i) {
847 StructTy, &*AI, Idx,
"gep_" + inputs[i]->
getName(), TI);
852 std::vector<User *>
Users(inputs[i]->user_begin(), inputs[i]->user_end());
855 if (Blocks.count(inst->getParent()))
856 inst->replaceUsesOfWith(inputs[i], RewriteVal);
860 if (!AggregateArgs) {
862 for (
unsigned i = 0, e = inputs.size(); i != e; ++i, ++AI)
863 AI->
setName(inputs[i]->getName());
864 for (
unsigned i = 0, e = outputs.size(); i != e; ++i, ++AI)
865 AI->
setName(outputs[i]->getName()+
".out");
872 for (
unsigned i = 0, e =
Users.size(); i != e; ++i)
876 if (
I->isTerminator() && !Blocks.count(
I->getParent()) &&
877 I->getParent()->getParent() == oldFunction)
878 I->replaceUsesOfWith(header, newHeader);
892 std::vector<Value *> params, StructValues, ReloadOutputs, Reloads;
900 for (
Value *input : inputs)
902 StructValues.push_back(input);
904 params.push_back(input);
907 for (
Value *output : outputs) {
909 StructValues.push_back(output);
913 nullptr, output->getName() +
".loc",
915 ReloadOutputs.push_back(alloca);
916 params.push_back(alloca);
922 if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
923 std::vector<Type *> ArgTypes;
925 ve = StructValues.end(); v != ve; ++v)
926 ArgTypes.push_back((*v)->getType());
933 params.push_back(Struct);
935 for (
unsigned i = 0, e = inputs.size(); i != e; ++i) {
940 StructArgTy, Struct, Idx,
"gep_" + StructValues[i]->
getName());
949 NumExitBlocks > 1 ?
"targetBlock" :
"");
961 unsigned FirstOut = inputs.size();
963 std::advance(OutputArgBegin, inputs.size());
967 for (
unsigned i = 0, e = outputs.size(); i != e; ++i) {
968 Value *Output =
nullptr;
974 StructArgTy, Struct, Idx,
"gep_reload_" + outputs[i]->
getName());
978 Output = ReloadOutputs[i];
981 Reloads.push_back(load);
983 std::vector<User *>
Users(outputs[i]->user_begin(), outputs[i]->user_end());
984 for (
unsigned u = 0, e = Users.size(); u != e; ++u) {
999 if (
auto *InvokeI = dyn_cast<InvokeInst>(OutI))
1000 InsertPt = InvokeI->getNormalDest()->getFirstInsertionPt();
1001 else if (
auto *Phi = dyn_cast<PHINode>(OutI))
1002 InsertPt = Phi->getParent()->getFirstInsertionPt();
1004 InsertPt = std::next(OutI->getIterator());
1007 "Number of output arguments should match " 1008 "the amount of defined values");
1009 if (AggregateArgs) {
1014 StructArgTy, &*OAI, Idx,
"gep_" + outputs[i]->
getName(), &*InsertPt);
1015 new StoreInst(outputs[i], GEP, &*InsertPt);
1020 new StoreInst(outputs[i], &*OAI, &*InsertPt);
1028 codeReplacer, 0, codeReplacer);
1035 std::map<BasicBlock *, BasicBlock *> ExitBlockMap;
1037 unsigned switchVal = 0;
1044 BasicBlock *&NewTarget = ExitBlockMap[OldTarget];
1049 OldTarget->
getName() +
".exitStub",
1051 unsigned SuccNum = switchVal++;
1053 Value *brVal =
nullptr;
1054 switch (NumExitBlocks) {
1080 switch (NumExitBlocks) {
1125 void CodeExtractor::moveCodeToFunction(
Function *newFunction) {
1139 void CodeExtractor::calculateNewCallTerminatorWeights(
1151 Distribution BranchDist;
1155 BlockNode ExitNode(i);
1156 uint64_t ExitFreq = ExitWeights[TI->
getSuccessor(i)].getFrequency();
1158 BranchDist.addExit(ExitNode, ExitFreq);
1164 if (BranchDist.Total == 0)
1168 BranchDist.normalize();
1171 for (
unsigned I = 0,
E = BranchDist.Weights.
size();
I <
E; ++
I) {
1172 const auto &Weight = BranchDist.Weights[
I];
1175 BranchWeights[Weight.TargetNode.Index] = Weight.Amount;
1195 for (
auto It = BB->begin(), End = BB->end(); It != End;) {
1198 if (!II || !II->isLifetimeStartOrEnd())
1208 InputObjectsWithLifetime.
insert(Mem);
1209 II->eraseFromParent();
1212 return InputObjectsWithLifetime;
1220 if (InputObjectsWithLifetime.
empty())
1230 for (
Value *Mem : InputObjectsWithLifetime) {
1231 assert((!isa<Instruction>(Mem) ||
1233 "Input memory not defined in original function");
1234 Value *MemAsI8Ptr =
nullptr;
1235 if (Mem->getType() == Int8PtrTy)
1244 auto EndMarker =
CallInst::Create(LifetimeEndFn, {NegativeOne, MemAsI8Ptr});
1262 if (
const CallInst *CI = dyn_cast<CallInst>(&
I))
1263 if (
const Function *
F = CI->getCalledFunction())
1269 for (
auto &BB : *oldFunction) {
1270 if (Blocks.count(&BB))
1276 ValueSet inputs, outputs, SinkingCands, HoistingCands;
1283 assert(BPI &&
"Both BPI and BFI are required to preserve profile info");
1285 if (Blocks.count(Pred))
1294 splitReturnBlocks();
1303 if (!Blocks.count(*
SI)) {
1313 NumExitBlocks = ExitBlocks.
size();
1316 severSplitPHINodesOfEntry(header);
1317 severSplitPHINodesOfExits(ExitBlocks);
1321 "codeRepl", oldFunction,
1343 newFuncRoot->getInstList().push_back(BranchI);
1345 findAllocas(SinkingCands, HoistingCands, CommonExit);
1352 for (
auto *II : SinkingCands)
1353 cast<Instruction>(II)->moveBefore(*newFuncRoot,
1354 newFuncRoot->getFirstInsertionPt());
1356 if (!HoistingCands.
empty()) {
1359 for (
auto *II : HoistingCands)
1360 cast<Instruction>(II)->moveBefore(TI);
1367 ValueSet InputObjectsWithLifetime =
1372 constructFunction(inputs, outputs, header, newFuncRoot, codeReplacer,
1378 if (Count.hasValue())
1385 emitCallAndSwitchStatement(newFunction, codeReplacer, inputs, outputs);
1387 moveCodeToFunction(newFunction);
1392 InputObjectsWithLifetime, TheCall);
1399 if (BFI && NumExitBlocks > 1)
1400 calculateNewCallTerminatorWeights(codeReplacer, ExitWeights, BPI);
1412 for (
PHINode &PN : ExitBB->phis()) {
1413 Value *IncomingCodeReplacerVal =
nullptr;
1414 for (
unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
1416 if (!Blocks.count(PN.getIncomingBlock(i)))
1420 if (!IncomingCodeReplacerVal) {
1421 PN.setIncomingBlock(i, codeReplacer);
1422 IncomingCodeReplacerVal = PN.getIncomingValue(i);
1424 assert(IncomingCodeReplacerVal == PN.getIncomingValue(i) &&
1425 "PHI has two incompatbile incoming values from codeRepl");
1433 auto BlockIt = BB.begin();
1435 while (BlockIt != BB.end()) {
1438 if (isa<DbgInfoIntrinsic>(Inst))
1447 DVI->eraseFromParent();
1455 return isa<ReturnInst>(Term) || isa<ResumeInst>(Term);
1458 newFunction->setDoesNotReturn();
1461 newFunction->dump();
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
A parsed version of the target data layout string in and methods for querying it. ...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static IntegerType * getInt1Ty(LLVMContext &C)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
This class represents an incoming formal argument to a Function.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
const Value * stripInBoundsOffsets() const
Strip off pointer casts and inbounds GEPs.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
size_type size() const
Determine the number of elements in the SetVector.
A Module instance is used to store all the information related to an LLVM module. ...
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void push_back(const T &Elt)
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
This class represents a function call, abstracting a target machine's calling convention.
Value * getCondition() const
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
LLVMContext & getContext() const
All values hold a context through their type.
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
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...
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
iv Induction Variable Users
static IntegerType * getInt16Ty(LLVMContext &C)
LLVMContext & getContext() const
Get the context in which this basic block lives.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
unsigned getAllocaAddrSpace() const
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void setEntryCount(ProfileCount Count, const DenseSet< GlobalValue::GUID > *Imports=nullptr)
Set the entry count for this function.
Class to represent struct types.
LLVMContext & getContext() const
Get the global data context.
A Use represents the edge between a Value definition and its users.
bool hasUWTable() const
True if the ABI mandates (or the user requested) that this function be in a unwind table...
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
static StringRef getName(Value *V)
This file contains the simple types necessary to represent the attributes associated with functions a...
No attributes have been set.
void setName(const Twine &Name)
Change the name of the value.
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Class to represent function types.
Type * getType() const
All values are typed, get the type of this value.
bool insert(const value_type &X)
Insert a new element into the SetVector.
This is the common base class for debug info intrinsics for variables.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
AttributeList getAttributes() const
Return the attribute list for this Function.
An instruction for storing to memory.
bool hasPersonalityFn() const
Check whether this function has a personality function.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
BasicBlock * getSuccessor(unsigned idx) const
static Function * getFunction(Constant *C)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Interval::succ_iterator succ_end(Interval *I)
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
bool isVoidTy() const
Return true if this is 'void'.
const BasicBlock & getEntryBlock() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Type * getReturnType() const
Returns the type of the ret val.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
DISubprogram * getSubprogram() const
Get the attached subprogram.
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
Distribution of unscaled probability weight.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool isLifetimeStartOrEnd() const
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
static Type * getVoidTy(LLVMContext &C)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
unsigned getAddressSpace() const
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Interval::pred_iterator pred_end(Interval *I)
Value * getPointerOperand()
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
self_iterator getIterator()
static CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
const Function * getFunction() const
Return the function this instruction belongs to.
CaseIt removeCase(CaseIt I)
This method removes the specified case and its successor from the switch instruction.
Sentinal value useful for loops.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Class to represent profile counts.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
bool doesNotThrow() const
Determine if the function cannot unwind.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
const InstListType & getInstList() const
Return the underlying instruction list container.
typename vector_type::const_iterator iterator
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
void setIncomingBlock(unsigned i, BasicBlock *BB)
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=nullptr)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
void setEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors, BranchProbability Prob)
Set the raw edge probability for the given edge.
void setBlockFreq(const BasicBlock *BB, uint64_t Freq)
LLVM_NODISCARD T pop_back_val()
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
pred_range predecessors(BasicBlock *BB)
unsigned getNumIncomingValues() const
Return the number of incoming edges.
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
void push_back(pointer val)
iterator_range< user_iterator > users()
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
pointer remove(iterator &IT)
Analysis providing branch probability information.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
static IntegerType * getInt32Ty(LLVMContext &C)
void setCondition(Value *V)
LLVM_NODISCARD bool empty() const
Represents a single loop in the control flow graph.
StringRef getName() const
Return a constant reference to the value's name.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
bool empty() const
Determine if the SetVector is empty or not.
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Rename collisions when linking (static functions).
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
const BasicBlock & front() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
void setDefaultDest(BasicBlock *DefaultCase)
A vector that has set insertion semantics.
succ_range successors(Instruction *I)
static const Function * getParent(const Value *V)
AttributeSet getFnAttributes() const
The function attributes are returned.
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Split the specified block at the specified instruction - everything before SplitPt stays in Old and e...
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
void setPersonalityFn(Constant *Fn)
static BranchProbability getZero()
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
Value * getPointerOperand()
Optional< uint64_t > getProfileCountFromFreq(uint64_t Freq) const
Returns the estimated profile count of Freq.
Representative of a block.
bool empty() const
empty - Check if the array is empty.
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack