15 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
16 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
37 class AssumptionCache;
40 class TargetLibraryInfo;
41 class TargetTransformInfo;
46 template<
typename T>
class SmallVectorImpl;
60 const TargetLibraryInfo *TLI =
nullptr);
70 const TargetLibraryInfo *TLI =
nullptr);
77 const TargetLibraryInfo *TLI =
nullptr);
85 const TargetLibraryInfo *TLI =
nullptr);
93 const TargetLibraryInfo *TLI =
nullptr);
140 unsigned BonusInstThreshold, AssumptionCache *AC =
nullptr);
161 bool VolatileLoads =
false,
162 Instruction *AllocaPoint =
nullptr);
174 const DataLayout &DL,
175 const Instruction *CxtI =
nullptr,
176 AssumptionCache *AC =
nullptr,
177 const DominatorTree *DT =
nullptr);
192 template <
typename IRBuilderTy>
194 bool NoAssumptions =
false) {
201 bool isInBounds = GEPOp->
isInBounds() && !NoAssumptions;
204 unsigned IntPtrWidth = IntPtrTy->getScalarType()->getIntegerBitWidth();
205 uint64_t PtrSizeMask = ~0ULL >> (64 - IntPtrWidth);
212 if (
Constant *OpC = dyn_cast<Constant>(Op)) {
213 if (OpC->isZeroValue())
217 if (
StructType *STy = dyn_cast<StructType>(*GTI)) {
218 if (OpC->getType()->isVectorTy())
219 OpC = OpC->getSplatValue();
221 uint64_t OpValue = cast<ConstantInt>(OpC)->getZExtValue();
234 Result = Builder->CreateAdd(Result, Scale, GEP->
getName()+
".offs");
239 Op = Builder->CreateIntCast(Op, IntPtrTy,
true, Op->
getName()+
".c");
243 GEP->
getName()+
".idx", isInBounds );
247 Result = Builder->CreateAdd(Op, Result, GEP->
getName()+
".offs");
259 StoreInst *
SI, DIBuilder &Builder);
264 LoadInst *LI, DIBuilder &Builder);
278 DIBuilder &Builder,
bool Deref);
288 void combineMetadata(Instruction *K,
const Instruction *J, ArrayRef<unsigned> KnownIDs);
293 const BasicBlockEdge &Edge);
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP, bool NoAssumptions=false)
EmitGEPOffset - Given a getelementptr instruction/constantexpr, emit the code necessary to compute th...
A parsed version of the target data layout string in and methods for querying it. ...
AllocaInst * DemoteRegToStack(Instruction &X, bool VolatileLoads=false, Instruction *AllocaPoint=nullptr)
DemoteRegToStack - This function takes a virtual register computed by an Instruction and replaces it ...
unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
getOrEnforceKnownAlignment - If the specified pointer has an alignment that we can determine...
DbgDeclareInst * FindAllocaDbgDeclare(Value *V)
FindAllocaDbgDeclare - Finds the llvm.dbg.declare intrinsic corresponding to an alloca, if any.
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT=nullptr)
MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its predecessor is known to have...
A cache of .assume calls within a function.
bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
SimplifyInstructionsInBlock - Scan the specified basic block and try to simplify any instructions in ...
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred)
RemovePredecessorAndSimplify - Like BasicBlock::removePredecessor, this method is called when we're a...
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)
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...
StructType - 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)
ConstantFoldTerminator - If a terminator instruction is predicated on a constant value, convert it into an unconditional branch to the constant destination.
bool EliminateDuplicatePHINodes(BasicBlock *BB)
EliminateDuplicatePHINodes - 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)
getKnownAlignment - Try to infer an alignment for the specified pointer.
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=nullptr)
FlatternCFG - This function is used to flatten a CFG.
uint64_t getElementOffset(unsigned Idx) const
bool FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold=1)
FoldBranchToCommonDest - If this basic block is ONLY a setcc and a branch, and if a predecessor branc...
The instances of the Type class are immutable: once they are created, they are never changed...
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB)
TryToSimplifyUncondBranchFromEmptyBlock - BB is known to contain an unconditional branch...
This is an important base class in LLVM.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr)
SimplifyCFG - This function is used to do simplification of a CFG.
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a trivially dead instruction...
bool LowerDbgDeclare(Function &F)
LowerDbgDeclare - 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 ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
Type * getType() const
All values are typed, get the type of this value.
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr)
RecursivelyDeleteDeadPHINode - If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use nodes that either forms a cycle or is terminated by a trivially dead instruction, delete it.
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.
bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, bool Deref)
Replaces llvm.dbg.declare instruction when an alloca is replaced with a new value.
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
AllocaInst * DemotePHIToStack(PHINode *P, Instruction *AllocaPoint=nullptr)
DemotePHIToStack - This function takes a virtual register computed by a phi node and replaces it with...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
isInstructionTriviallyDead - Return true if the result produced by the instruction is not used...
LLVM Value Representation.
bool removeUnreachableBlocks(Function &F)
Remove all blocks that can not be reached from the function's entry.
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs)
Combine the metadata of two instructions so that K can replace J.
gep_type_iterator gep_type_begin(const User *GEP)