59#define DEBUG_TYPE "mem2reg"
61STATISTIC(NumLocalPromoted,
"Number of alloca's promoted within one block");
62STATISTIC(NumSingleStore,
"Number of alloca's promoted with a single store");
63STATISTIC(NumDeadAlloca,
"Number of dead alloca's removed");
64STATISTIC(NumPHIInsert,
"Number of PHI nodes inserted");
70 Type *ExpectedType =
nullptr;
78 ExpectedType = LI->getType();
79 else if (LI->getType() != ExpectedType)
82 if (
SI->getValueOperand() == AI)
88 Type *StoreType =
SI->getValueOperand()->getType();
90 ExpectedType = StoreType;
91 else if (StoreType != ExpectedType)
94 if (!
II->isLifetimeStartOrEnd() && !
II->isDroppable() &&
95 II->getIntrinsicID() != Intrinsic::fake_use)
120class AssignmentTrackingInfo {
127 void init(AllocaInst *AI) {
128 SmallSet<DebugVariable, 2> Vars;
130 if (Vars.
insert(DebugVariable(DVR)).second)
131 DVRAssigns.push_back(DVR);
137 void updateForDeletedStore(
138 StoreInst *ToDelete, DIBuilder &DIB,
139 SmallPtrSet<DbgVariableRecord *, 8> *DVRAssignsToDelete)
const {
142 if (DVRAssigns.empty())
151 SmallSet<DebugVariableAggregate, 2> VarHasDbgAssignForStore;
152 auto InsertValueForAssign = [&](
auto *DbgAssign,
auto *&AssignList) {
153 VarHasDbgAssignForStore.
insert(DebugVariableAggregate(DbgAssign));
154 AssignList->insert(DbgAssign);
155 createDebugValue(DIB, DbgAssign->getValue(), DbgAssign->getVariable(),
156 DbgAssign->getExpression(), DbgAssign->getDebugLoc(),
160 InsertValueForAssign(Assign, DVRAssignsToDelete);
170 auto ConvertUnlinkedAssignToValue = [&](DbgVariableRecord *
Assign) {
171 if (VarHasDbgAssignForStore.
contains(DebugVariableAggregate(Assign)))
175 for_each(DVRAssigns, ConvertUnlinkedAssignToValue);
180 void updateForNewPhi(PHINode *NewPhi, DIBuilder &DIB)
const {
184 for (
auto *DVR : DVRAssigns)
188 void clear() { DVRAssigns.clear(); }
189 bool empty() {
return DVRAssigns.empty(); }
193 using DPUserVec = SmallVector<DbgVariableRecord *, 1>;
198 StoreInst *OnlyStore;
200 bool OnlyUsedInOneBlock;
209 AssignmentTrackingInfo AssignmentTracking;
212 DefiningBlocks.clear();
216 OnlyUsedInOneBlock =
true;
219 AssignmentTracking.clear();
224 void AnalyzeAlloca(AllocaInst *AI) {
230 for (User *U : AI->
users()) {
235 DefiningBlocks.push_back(
SI->getParent());
238 ValueType =
SI->getValueOperand()->getType();
240 assert(ValueType ==
SI->getValueOperand()->getType() &&
241 "All stores were checked to have used the same type");
251 "All loads where checked to have used the same type");
254 if (OnlyUsedInOneBlock) {
256 OnlyBlock =
User->getParent();
257 else if (OnlyBlock !=
User->getParent())
258 OnlyUsedInOneBlock =
false;
263 std::copy_if(AllDPUsers.
begin(), AllDPUsers.
end(),
264 std::back_inserter(DPUsers),
265 [](DbgVariableRecord *DVR) { return !DVR->isDbgAssign(); });
266 AssignmentTracking.init(AI);
270using DVRIndirectValuesAtStoreMap =
274template <
typename T>
class VectorWithUndo {
279 void undo(
size_t S) {
281 while (S < Undo.size()) {
282 Vals[Undo.back().first] = Undo.back().second;
287 void resize(
size_t Sz) { Vals.resize(Sz); }
289 size_t undoSize()
const {
return Undo.size(); }
291 const T &operator[](
size_t Idx)
const {
return Vals[
Idx]; }
293 void set(
size_t Idx,
const T &Val) {
294 if (Vals[Idx] == Val)
296 Undo.emplace_back(Idx, Vals[Idx]);
300 void init(
size_t Idx,
const T &Val) {
307struct RenamePassData {
308 RenamePassData(BasicBlock *
B, BasicBlock *
P,
size_t V,
size_t L)
309 : BB(
B), Pred(
P), UndoVals(
V), UndoLocs(
L) {}
323class LargeBlockInfo {
329 DenseMap<const Instruction *, unsigned> InstNumbers;
334 static bool isInterestingInstruction(
const Instruction *
I) {
340 unsigned getInstructionIndex(
const Instruction *
I) {
341 assert(isInterestingInstruction(
I) &&
342 "Not a load/store to/from an alloca?");
345 auto It = InstNumbers.find(
I);
346 if (It != InstNumbers.end())
354 for (
const Instruction &BBI : *BB)
355 if (isInterestingInstruction(&BBI))
356 InstNumbers[&BBI] = InstNo++;
357 It = InstNumbers.find(
I);
359 assert(It != InstNumbers.end() &&
"Didn't insert instruction?");
363 void deleteValue(
const Instruction *
I) { InstNumbers.erase(
I); }
365 void clear() { InstNumbers.clear(); }
368struct PromoteMem2Reg {
370 std::vector<AllocaInst *> Allocas;
378 const SimplifyQuery SQ;
381 DenseMap<AllocaInst *, unsigned> AllocaLookup;
388 DenseMap<std::pair<unsigned, unsigned>, PHINode *> NewPhiNodes;
392 DenseMap<PHINode *, unsigned> PhiToAllocaMap;
406 SmallPtrSet<DbgVariableRecord *, 8> DVRAssignsToDelete;
409 DVRIndirectValuesAtStoreMap DVRIndirectValuesAtStore;
412 DVRIndirectValueLastStoreMap DVRIndirectValueLastStore;
419 SmallVector<unsigned> BBNumPreds;
422 VectorWithUndo<Value *> IncomingVals;
425 VectorWithUndo<DebugLoc> IncomingLocs;
431 bool NoSignedZeros =
false;
436 : Allocas(Allocas.
begin(), Allocas.
end()), DT(DT),
438 AC(AC), SQ(DT.
getRoot()->getDataLayout(),
444 void RemoveFromAllocasList(
unsigned &AllocaIdx) {
445 Allocas[AllocaIdx] = Allocas.back();
450 unsigned getNumPreds(
const BasicBlock *BB) {
452 unsigned &NP = BBNumPreds[BB->
getNumber()];
459 const SmallPtrSetImpl<BasicBlock *> &DefBlocks,
460 SmallPtrSetImpl<BasicBlock *> &LiveInBlocks);
461 void collectDVRIndirectValuesAtStores();
462 void RenamePass(BasicBlock *BB, BasicBlock *Pred);
463 bool QueuePhiNode(BasicBlock *BB,
unsigned AllocaIdx,
unsigned &
Version);
466 void cleanUpDbgAssigns() {
467 for (
auto *DVR : DVRAssignsToDelete)
468 DVR->eraseFromParent();
469 DVRAssignsToDelete.clear();
472 void pushToWorklist(BasicBlock *BB, BasicBlock *Pred) {
473 Worklist.emplace_back(BB, Pred, IncomingVals.undoSize(),
474 IncomingLocs.undoSize());
477 RenamePassData popFromWorklist() {
478 RenamePassData
R = Worklist.back();
480 IncomingVals.undo(
R.UndoVals);
481 IncomingLocs.undo(
R.UndoLocs);
516 if (AC && LI->
getMetadata(LLVMContext::MD_nonnull) &&
530 Type *PromotedType =
nullptr;
537 PromotedType =
SI->getValueOperand()->getType();
548 if (
I->isDroppable()) {
549 I->dropDroppableUse(U);
557 if (
II->isLifetimeStartOrEnd()) {
561 Store->setDebugLoc(
II->getDebugLoc());
564 I->eraseFromParent();
586 bool RequireDominatingStore =
592 Info.UsingBlocks.clear();
596 if (UserInst == OnlyStore)
604 if (RequireDominatingStore) {
609 if (StoreIndex == -1)
610 StoreIndex = LBI.getInstructionIndex(OnlyStore);
612 if (
unsigned(StoreIndex) > LBI.getInstructionIndex(LI)) {
614 Info.UsingBlocks.push_back(StoreBB);
621 Info.UsingBlocks.push_back(LI->
getParent());
639 if (!Info.UsingBlocks.empty())
644 Info.AssignmentTracking.updateForDeletedStore(Info.OnlyStore, DIB,
666 Info.OnlyStore->eraseFromParent();
667 LBI.deleteValue(Info.OnlyStore);
690 AllocaInst *AI,
const AllocaInfo &Info, LargeBlockInfo &LBI,
693 const DVRIndirectValuesAtStoreMap &DVRIndirectValuesAtStore,
694 const DVRIndirectValueLastStoreMap &DVRIndirectValueLastStore) {
702 StoresByIndexTy StoresByIndex;
706 StoresByIndex.
push_back(std::make_pair(LBI.getInstructionIndex(
SI),
SI));
719 unsigned LoadIdx = LBI.getInstructionIndex(LI);
724 std::make_pair(LoadIdx,
static_cast<StoreInst *
>(
nullptr)),
727 if (
I == StoresByIndex.begin()) {
728 if (StoresByIndex.empty())
738 ReplVal = std::prev(
I)->second->getOperand(0);
760 StoreInst *
SI = DVRIndirectValueLastStore.lookup(DbgItem);
763 Value *LastStoreValue =
nullptr;
766 LastStoreValue =
SI->getValueOperand();
772 if (
Next &&
Next->getPointerOperand() == AI) {
773 LastStoreValue =
nullptr;
775 DVRIndirectValues.
push_back({DbgItem, LastStoreValue});
783 Info.AssignmentTracking.updateForDeletedStore(
SI, DIB, DVRAssignsToDelete);
799 SI->eraseFromParent();
816 for (
auto [DbgItem, V] : DVRIndirectValues) {
834void PromoteMem2Reg::collectDVRIndirectValuesAtStores() {
837 SmallPtrSet<DbgVariableRecord *, 8> DVRIndirectValues;
838 SmallSetVector<BasicBlock *, 4> BlocksToProcess;
839 for (AllocaInst *AI : Allocas)
841 if (DVR->isDbgValue() && DVR->getExpression()->startsWithDeref()) {
842 DVRIndirectValues.
insert(DVR);
843 BlocksToProcess.
insert(DVR->getParent());
848 for (BasicBlock *BB : BlocksToProcess) {
851 SmallDenseMap<DebugVariableAggregate, SmallVector<DbgVariableRecord *, 1>>
854 SmallDenseMap<Value *, SmallVector<DbgVariableRecord *, 1>> LiveByAlloca;
856 SmallDenseMap<Value *, StoreInst *> LastStore;
857 for (Instruction &
I : *BB) {
858 for (DbgVariableRecord &DVR :
filterDbgVars(
I.getDbgRecordRange())) {
860 if (!DVR.isDbgValue())
863 auto &Live = LiveByVar[DebugVariableAggregate(&DVR)];
864 erase_if(Live, [&](DbgVariableRecord *L) {
865 if (!
L->getExpression()->fragmentsOverlap(DVR.getExpression()))
867 erase(LiveByAlloca[
L->getVariableLocationOp(0)], L);
871 if (DVRIndirectValues.
contains(&DVR)) {
872 Live.push_back(&DVR);
873 Value *Ptr = DVR.getVariableLocationOp(0);
874 LiveByAlloca[Ptr].push_back(&DVR);
875 if (StoreInst *SI = LastStore.
lookup(Ptr))
876 DVRIndirectValueLastStore[&DVR] =
SI;
883 LastStore[
SI->getPointerOperand()] =
SI;
885 auto Live = LiveByAlloca.
lookup(
SI->getPointerOperand());
887 DVRIndirectValuesAtStore[
SI] = std::move(Live);
892void PromoteMem2Reg::run() {
895 AllocaATInfo.
resize(Allocas.size());
896 AllocaDPUsers.
resize(Allocas.size());
897 AllocaValueTypes.
resize(Allocas.size());
903 NoSignedZeros =
F.getFnAttribute(
"no-signed-zeros-fp-math").getValueAsBool();
909 for (AllocaInst *AI : Allocas) {
912 "All allocas should be in the same function, which is same as DF!");
916 collectDVRIndirectValuesAtStores();
918 for (
unsigned AllocaNum = 0; AllocaNum != Allocas.size(); ++AllocaNum) {
919 AllocaInst *AI = Allocas[AllocaNum];
926 RemoveFromAllocasList(AllocaNum);
933 Info.AnalyzeAlloca(AI);
937 if (
Info.DefiningBlocks.size() == 1) {
939 &DVRAssignsToDelete)) {
941 RemoveFromAllocasList(AllocaNum);
949 if (
Info.OnlyUsedInOneBlock &&
951 &DVRAssignsToDelete, DVRIndirectValuesAtStore,
952 DVRIndirectValueLastStore)) {
954 RemoveFromAllocasList(AllocaNum);
959 if (BBNumPreds.
empty())
960 BBNumPreds.
resize(
F.getMaxBlockNumber());
963 if (!
Info.AssignmentTracking.empty())
964 AllocaATInfo[AllocaNum] =
Info.AssignmentTracking;
965 if (!
Info.DPUsers.empty())
966 AllocaDPUsers[AllocaNum] =
Info.DPUsers;
967 AllocaValueTypes[AllocaNum] =
Info.ValueType;
970 AllocaLookup[Allocas[AllocaNum]] = AllocaNum;
974 Info.DefiningBlocks);
978 SmallPtrSet<BasicBlock *, 32> LiveInBlocks;
985 IDF.setLiveInBlocks(LiveInBlocks);
986 IDF.setDefiningBlocks(DefBlocks);
988 IDF.calculate(PHIBlocks);
989 llvm::sort(PHIBlocks, [](BasicBlock *
A, BasicBlock *
B) {
990 return A->getNumber() <
B->getNumber();
994 for (BasicBlock *BB : PHIBlocks)
995 QueuePhiNode(BB, AllocaNum, CurrentVersion);
998 if (Allocas.empty()) {
1007 IncomingVals.resize(Allocas.size());
1008 for (
unsigned i = 0, e = Allocas.size(); i != e; ++i)
1014 IncomingLocs.resize(Allocas.size());
1015 for (
unsigned i = 0, e = Allocas.size(); i != e; ++i)
1019 Visited.
resize(
F.getMaxBlockNumber(),
false);
1022 pushToWorklist(&
F.front(),
nullptr);
1025 RenamePassData RPD = popFromWorklist();
1026 RenamePass(RPD.BB, RPD.Pred);
1027 }
while (!Worklist.
empty());
1030 for (Instruction *
A : Allocas) {
1036 if (!
A->use_empty())
1038 A->eraseFromParent();
1042 for (
auto &DbgUsers : AllocaDPUsers) {
1043 for (DbgVariableRecord *DbgItem : DbgUsers)
1044 if (DbgItem->isAddressOfVariable() ||
1045 DbgItem->getExpression()->startsWithDeref())
1046 DbgItem->eraseFromParent();
1053 bool EliminatedAPHI =
true;
1054 while (EliminatedAPHI) {
1055 EliminatedAPHI =
false;
1061 EliminatedAPHI = NewPhiNodes.
remove_if([&](
const auto &Entry) {
1062 PHINode *PN =
Entry.second;
1078 for (
const auto &PhiNode : NewPhiNodes) {
1081 PHINode *SomePHI = PhiNode.second;
1083 if (&BB->
front() != SomePHI)
1099 return A->getNumber() <
B->getNumber();
1110 "PHI node has entry for a block which is not a predecessor!");
1125 for (BasicBlock *Pred : Preds)
1130 NewPhiNodes.clear();
1131 cleanUpDbgAssigns();
1139void PromoteMem2Reg::ComputeLiveInBlocks(
1140 AllocaInst *AI, AllocaInfo &Info,
1141 const SmallPtrSetImpl<BasicBlock *> &DefBlocks,
1142 SmallPtrSetImpl<BasicBlock *> &LiveInBlocks) {
1146 SmallVector<BasicBlock *, 64> LiveInBlockWorklist(
Info.UsingBlocks.begin(),
1147 Info.UsingBlocks.end());
1152 for (
unsigned i = 0, e = LiveInBlockWorklist.size(); i != e; ++i) {
1154 if (!DefBlocks.
count(BB))
1161 if (
SI->getOperand(1) != AI)
1166 LiveInBlockWorklist[i] = LiveInBlockWorklist.back();
1167 LiveInBlockWorklist.pop_back();
1183 while (!LiveInBlockWorklist.empty()) {
1184 BasicBlock *BB = LiveInBlockWorklist.pop_back_val();
1188 if (!LiveInBlocks.
insert(BB).second)
1200 LiveInBlockWorklist.push_back(
P);
1208bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB,
unsigned AllocaNo,
1211 PHINode *&PN = NewPhiNodes[std::make_pair(BB->
getNumber(), AllocaNo)];
1223 PhiToAllocaMap[PN] = AllocaNo;
1230 bool ApplyMergedLoc) {
1242void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred) {
1248 if (PhiToAllocaMap.
count(APN)) {
1255 unsigned NewPHINumOperands = APN->getNumOperands();
1258 assert(NumEdges &&
"Must be at least one edge from Pred to BB!");
1263 unsigned AllocaNo = PhiToAllocaMap[APN];
1267 APN->getNumIncomingValues() > 0);
1270 for (
unsigned i = 0; i != NumEdges; ++i)
1271 APN->addIncoming(IncomingVals[AllocaNo], Pred);
1279 APN->setHasNoSignedZeros(
true);
1282 IncomingVals.set(AllocaNo, APN);
1283 AllocaATInfo[AllocaNo].updateForNewPhi(APN, DIB);
1284 for (DbgVariableRecord *DbgItem : AllocaDPUsers[AllocaNo])
1285 if (DbgItem->isAddressOfVariable())
1296 }
while (APN->getNumOperands() == NewPHINumOperands);
1313 auto AI = AllocaLookup.
find(Src);
1314 if (AI == AllocaLookup.
end())
1317 Value *
V = IncomingVals[AI->second];
1330 auto ai = AllocaLookup.
find(Dest);
1331 if (ai == AllocaLookup.
end())
1335 unsigned AllocaNo = ai->second;
1336 IncomingVals.set(AllocaNo,
SI->getOperand(0));
1339 IncomingLocs.set(AllocaNo,
SI->getDebugLoc());
1340 AllocaATInfo[AllocaNo].updateForDeletedStore(SI, DIB,
1341 &DVRAssignsToDelete);
1342 for (DbgVariableRecord *DbgItem : AllocaDPUsers[ai->second])
1343 if (DbgItem->isAddressOfVariable())
1345 SI->eraseFromParent();
1352 SmallPtrSet<BasicBlock *, 8> VisitedSuccs;
1355 if (VisitedSuccs.
insert(S).second)
1356 pushToWorklist(S, BB);
1362 if (Allocas.
empty())
1365 PromoteMem2Reg(Allocas, DT, AC).run();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis false
static const Function * getParent(const Value *V)
This file implements the BitVector class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static DeltaTreeNode * getRoot(void *Root)
This file defines the DenseMap class.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Module.h This file contains the declarations for the Module class.
uint64_t IntrinsicInst * II
static StringRef getName(Value *V)
static void ComputeLiveInBlocks(const SmallPtrSetImpl< BasicBlock * > &UsingBlocks, const SmallPtrSetImpl< BasicBlock * > &DefBlocks, SmallPtrSetImpl< BasicBlock * > &LiveInBlocks, PredIteratorCache &PredCache)
Given sets of UsingBlocks and DefBlocks, compute the set of LiveInBlocks.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
an instruction to allocate memory on the stack
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
Check if the array is empty.
A cache of @llvm.assume calls within a function.
LLVM_ABI void registerAssumption(AssumeInst *CI)
Add an @llvm.assume intrinsic to this function's cache.
LLVM Basic Block Representation.
unsigned getNumber() const
iterator begin()
Instruction iterator methods.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & front() const
InstListType::iterator iterator
Instruction iterators...
bool test(unsigned Idx) const
Returns true if bit Idx is set.
void resize(unsigned N, bool t=false)
Grow or shrink the bitvector.
BitVector & set()
Set all bits in the bitvector.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI bool startsWithDeref() const
Return whether the first element a DW_OP_deref.
LLVM_ABI std::optional< ArrayRef< uint64_t > > getSingleLocationExpressionElements() const
Returns a reference to the elements contained in this expression, skipping past the leading DW_OP_LLV...
A parsed version of the target data layout string in and methods for querying it.
LLVM_ABI void eraseFromParent()
LLVM_ABI Instruction * getInstruction()
Record of a variable value-assignment, aka a non instruction representation of the dbg....
bool isValueOfVariable() const
Determine if this describes the value of a local variable.
bool isAddressOfVariable() const
Does this describe the address of a local variable.
void setRawLocation(Metadata *NewLocation)
Use of this should generally be avoided; instead, replaceVariableLocationOp and addVariableLocationOp...
void setExpression(DIExpression *NewExpr)
DIExpression * getExpression() const
static LLVM_ABI DbgVariableRecord * createDbgVariableRecord(Value *Location, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)
bool isDbgDeclareValue() const
static DebugLoc getCompilerGenerated()
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
iterator find(const_arg_type_t< KeyT > Val)
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
bool remove_if(Predicate Pred)
Remove entries that match the given predicate.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
Class representing an expression and its matching format.
This instruction compares its operands according to the predicate given to the constructor.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Instruction * user_back()
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
iterator_range< user_iterator > users()
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM_ABI void applyMergedLocation(DebugLoc LocA, DebugLoc LocB)
Merge 2 debug locations and apply it to the Instruction.
LLVM_ABI void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
A wrapper class for inspecting calls to intrinsic functions.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
Value * getPointerOperand()
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
bool insert(const value_type &X)
Insert a new element into the SetVector.
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.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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.
typename SuperClass::iterator iterator
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< use_iterator > uses()
const ParentTy * getParent() const
self_iterator getIterator()
@ BasicBlock
Various leaf nodes.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
SmallVector< DbgVariableRecord * > getDVRAssignmentMarkers(const Instruction *Inst)
Return a range of dbg_assign records for which Inst performs the assignment they encode.
LLVM_ABI void deleteAssignmentMarkers(const Instruction *Inst)
Delete the llvm.dbg.assign intrinsics linked to Inst.
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
@ User
could "use" a pointer
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI iterator begin() const
This is an optimization pass for GlobalISel generic memory operations.
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void PromoteMemToReg(ArrayRef< AllocaInst * > Allocas, DominatorTree &DT, AssumptionCache *AC=nullptr)
Promote the specified list of alloca instructions into scalar registers, inserting PHI nodes as appro...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
@ Store
The extracted value is stored (ExtractElement only).
LLVM_ABI void InsertDebugValueAtStoreLoc(DbgVariableRecord *DVR, StoreInst *SI, DIBuilder &Builder)
===------------------------------------------------------------------—===// Dbg Intrinsic utilities
constexpr from_range_t from_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
auto pred_size(const MachineBasicBlock *BB)
LLVM_ABI bool isAllocaPromotable(const AllocaInst *AI)
Return true if this alloca is legal for promotion.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, StoreInst *SI, DIBuilder &Builder)
Inserts a dbg.value record before a store to an alloca'd value that has an associated dbg....
LLVM_ABI TinyPtrVector< DbgVariableRecord * > findDVRValues(Value *V)
As above, for DVRValues.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
IDFCalculator< false > ForwardIDFCalculator
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
auto predecessors(const MachineBasicBlock *BB)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
LLVM_ABI bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be poison, but may be undef.
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
LLVM_ABI void findDbgUsers(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the debug info records describing a value.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Function object to check whether the first component of a container supported by std::get (like std::...