15 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
16 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
41 class AssumptionCache;
44 class TargetLibraryInfo;
45 class TargetTransformInfo;
50 template<
typename T>
class SmallVectorImpl;
64 const TargetLibraryInfo *TLI =
nullptr);
73 const TargetLibraryInfo *TLI =
nullptr);
79 const TargetLibraryInfo *TLI =
nullptr);
85 const TargetLibraryInfo *TLI =
nullptr);
93 const TargetLibraryInfo *TLI =
nullptr);
101 const TargetLibraryInfo *TLI =
nullptr);
144 unsigned BonusInstThreshold, AssumptionCache *AC =
nullptr,
145 SmallPtrSetImpl<BasicBlock *> *LoopHeaders =
nullptr,
146 bool LateSimplifyCFG =
false);
164 bool VolatileLoads =
false,
165 Instruction *AllocaPoint =
nullptr);
182 const DataLayout &
DL,
183 const Instruction *CxtI =
nullptr,
184 AssumptionCache *AC =
nullptr,
185 const DominatorTree *DT =
nullptr);
200 template <
typename IRBuilderTy>
202 bool NoAssumptions =
false) {
209 bool isInBounds = GEPOp->
isInBounds() && !NoAssumptions;
212 unsigned IntPtrWidth = IntPtrTy->getScalarType()->getIntegerBitWidth();
213 uint64_t PtrSizeMask = ~0ULL >> (64 - IntPtrWidth);
220 if (
Constant *OpC = dyn_cast<Constant>(Op)) {
221 if (OpC->isZeroValue())
225 if (
StructType *STy = GTI.getStructTypeOrNull()) {
226 if (OpC->getType()->isVectorTy())
227 OpC = OpC->getSplatValue();
229 uint64_t OpValue = cast<ConstantInt>(OpC)->getZExtValue();
242 Result = Builder->CreateAdd(Result, Scale, GEP->
getName()+
".offs");
247 Op = Builder->CreateIntCast(Op, IntPtrTy,
true, Op->
getName()+
".c");
251 GEP->
getName()+
".idx", isInBounds );
255 Result = Builder->CreateAdd(Op, Result, GEP->
getName()+
".offs");
267 StoreInst *
SI, DIBuilder &Builder);
272 LoadInst *LI, DIBuilder &Builder);
277 PHINode *LI, DIBuilder &Builder);
287 void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V);
295 Instruction *InsertBefore, DIBuilder &Builder,
304 DIBuilder &Builder,
bool Deref,
int Offset = 0);
312 DIBuilder &Builder,
int Offset = 0);
326 bool PreserveLCSSA =
false);
351 void combineMetadata(Instruction *K,
const Instruction *J, ArrayRef<unsigned> KnownIDs);
366 const BasicBlockEdge &Edge);
412 Instruction *
I,
bool MatchBSwaps,
bool MatchBitReversals,
413 SmallVectorImpl<Instruction *> &InsertedInsts);
424 const TargetLibraryInfo *TLI);
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP, bool NoAssumptions=false)
Given a getelementptr instruction/constantexpr, emit the code necessary to compute the offset from th...
A parsed version of the target data layout string in and methods for querying it. ...
bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, bool Deref, int Offset=0)
Replaces llvm.dbg.declare instruction when the alloca it describes is replaced with a new value...
AllocaInst * DemoteRegToStack(Instruction &X, bool VolatileLoads=false, Instruction *AllocaPoint=nullptr)
This function takes a virtual register computed by an Instruction and replaces it with a slot in the ...
unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, int Offset=0)
Replaces multiple llvm.dbg.value instructions when the alloca it describes is replaced with a new val...
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
DbgDeclareInst * FindAllocaDbgDeclare(Value *V)
Finds the llvm.dbg.declare intrinsic corresponding to an alloca, if any.
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!)...
void findDbgValues(SmallVectorImpl< DbgValueInst * > &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
A cache of .assume calls within a function.
bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred)
Like BasicBlock::removePredecessor, this method is called when we're about to delete Pred as a predec...
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, bool PreserveLCSSA=false)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge)
Replace each use of 'From' with 'To' if that use is dominated by the given edge.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
void salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage any dbg.value intrinsics referr...
bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
static unsigned getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=nullptr)
This function is used to flatten a CFG.
uint64_t getElementOffset(unsigned Idx) const
bool FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold=1)
If this basic block is ONLY a setcc and a branch, and if a predecessor branches to us and one of our ...
The instances of the Type class are immutable: once they are created, they are never changed...
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes...
void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
This is an important base class in LLVM.
bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx)
Given an instruction, is it legal to set operand OpIdx to a non-constant value?
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a range metadata node to a new load instruction.
bool callsGCLeafFunction(ImmutableCallSite CS)
Return true if the CallSite CS calls a gc leaf function.
bool replaceDbgDeclare(Value *Address, Value *NewAddress, Instruction *InsertBefore, DIBuilder &Builder, bool Deref, int Offset)
Replaces llvm.dbg.declare instruction when the address it describes is replaced with a new value...
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
If the specified value is a trivially dead instruction, delete it.
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr)
Remove all blocks that can not be reached from the function's entry.
Type * getType() const
All values are typed, get the type of this value.
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
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.
unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB)
Remove all instructions from a basic block other than it's terminator and any present EH pad instruct...
void removeUnwindEdge(BasicBlock *BB)
Replace 'BB's terminator with one that does not have an unwind successor block.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction * > &InsertedInsts)
Try and match a bswap or bitreverse idiom.
void maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI, const TargetLibraryInfo *TLI)
Given a CallInst, check if it calls a string function known to CodeGen, and mark it with NoBuiltin if...
void combineMetadataForCSE(Instruction *K, const Instruction *J)
Combine the metadata of two instructions so that K can replace J.
AllocaInst * DemotePHIToStack(PHINode *P, Instruction *AllocaPoint=nullptr)
This function takes a virtual register computed by a phi node and replaces it with a slot in the stac...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
LLVM Value Representation.
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
bool wouldInstructionBeTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction would have no side effects if it was not used...
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr, SmallPtrSetImpl< BasicBlock * > *LoopHeaders=nullptr, bool LateSimplifyCFG=false)
This function is used to do simplification of a CFG.
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs)
Combine the metadata of two instructions so that K can replace J.
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
gep_type_iterator gep_type_begin(const User *GEP)