72 #define DEBUG_TYPE "dse" 74 STATISTIC(NumRedundantStores,
"Number of redundant stores deleted");
75 STATISTIC(NumFastStores,
"Number of stores deleted");
76 STATISTIC(NumFastOther,
"Number of other instrs removed");
77 STATISTIC(NumCompletePartials,
"Number of stores dead by later partials");
78 STATISTIC(NumModifiedStores,
"Number of stores modified");
83 cl::desc(
"Enable partial-overwrite tracking in DSE"));
88 cl::desc(
"Enable partial store merging in DSE"));
119 auto It = ThrowableInst.
find(DeadInst);
120 if (It != ThrowableInst.
end())
121 ThrowableInst[It->first] =
false;
144 if (ValueSet) ValueSet->remove(DeadInst);
152 }
while (!NowDeadInsts.
empty());
155 while (!ThrowableInst.
empty() && !ThrowableInst.
back().second)
163 if (isa<StoreInst>(I))
166 switch (II->getIntrinsicID()) {
169 case Intrinsic::memset:
170 case Intrinsic::memmove:
171 case Intrinsic::memcpy:
172 case Intrinsic::memcpy_element_unordered_atomic:
173 case Intrinsic::memmove_element_unordered_atomic:
174 case Intrinsic::memset_element_unordered_atomic:
175 case Intrinsic::init_trampoline:
176 case Intrinsic::lifetime_end:
181 if (
Function *
F = CS.getCalledFunction()) {
186 case LibFunc_strncpy:
188 case LibFunc_strncat:
207 if (
auto *
MI = dyn_cast<AnyMemIntrinsic>(Inst)) {
214 switch (II->getIntrinsicID()) {
217 case Intrinsic::init_trampoline:
219 case Intrinsic::lifetime_end: {
220 uint64_t Len = cast<ConstantInt>(II->getArgOperand(0))->getZExtValue();
240 if (
auto *MTI = dyn_cast<AnyMemTransferInst>(Inst))
250 return SI->isUnordered();
253 switch (II->getIntrinsicID()) {
254 default:
llvm_unreachable(
"doesn't pass 'hasAnalyzableMemoryWrite' predicate");
255 case Intrinsic::lifetime_end:
259 case Intrinsic::init_trampoline:
262 case Intrinsic::memset:
263 case Intrinsic::memmove:
264 case Intrinsic::memcpy:
267 case Intrinsic::memcpy_element_unordered_atomic:
268 case Intrinsic::memmove_element_unordered_atomic:
269 case Intrinsic::memset_element_unordered_atomic:
276 return CS.getInstruction()->use_empty();
285 if (isa<StoreInst>(I))
289 switch (II->getIntrinsicID()) {
290 default:
return false;
291 case Intrinsic::memset:
292 case Intrinsic::memcpy:
293 case Intrinsic::memcpy_element_unordered_atomic:
294 case Intrinsic::memset_element_unordered_atomic:
311 return isa<AnyMemSetInst>(
I);
319 "unable to find pointer written for analyzable instruction?");
342 OW_PartialEarlierWithFullLater,
359 int64_t &EarlierOff, int64_t &LaterOff,
379 if (LaterSize >= EarlierSize)
397 if (ObjectSize == LaterSize && ObjectSize >= EarlierSize)
427 if (EarlierOff >= LaterOff &&
428 LaterSize >= EarlierSize &&
429 uint64_t(EarlierOff - LaterOff) + EarlierSize <= LaterSize)
438 LaterOff < int64_t(EarlierOff + EarlierSize) &&
439 int64_t(LaterOff + LaterSize) >= EarlierOff) {
442 auto &IM = IOL[DepWrite];
443 LLVM_DEBUG(
dbgs() <<
"DSE: Partial overwrite: Earlier [" << EarlierOff
444 <<
", " << int64_t(EarlierOff + EarlierSize)
445 <<
") Later [" << LaterOff <<
", " 446 << int64_t(LaterOff + LaterSize) <<
")\n");
452 int64_t LaterIntStart = LaterOff, LaterIntEnd = LaterOff + LaterSize;
456 auto ILI = IM.lower_bound(LaterIntStart);
457 if (ILI != IM.end() && ILI->second <= LaterIntEnd) {
461 LaterIntStart = std::min(LaterIntStart, ILI->second);
462 LaterIntEnd =
std::max(LaterIntEnd, ILI->first);
471 while (ILI != IM.end() && ILI->second <= LaterIntEnd) {
472 assert(ILI->second > LaterIntStart &&
"Unexpected interval");
473 LaterIntEnd =
std::max(LaterIntEnd, ILI->first);
478 IM[LaterIntEnd] = LaterIntStart;
481 if (ILI->second <= EarlierOff &&
482 ILI->first >= int64_t(EarlierOff + EarlierSize)) {
483 LLVM_DEBUG(
dbgs() <<
"DSE: Full overwrite from partials: Earlier [" 484 << EarlierOff <<
", " 485 << int64_t(EarlierOff + EarlierSize)
486 <<
") Composite Later [" << ILI->second <<
", " 487 << ILI->first <<
")\n");
488 ++NumCompletePartials;
496 int64_t(EarlierOff + EarlierSize) > LaterOff &&
497 uint64_t(LaterOff - EarlierOff) + LaterSize <= EarlierSize) {
499 << EarlierOff <<
", " 500 << int64_t(EarlierOff + EarlierSize)
501 <<
") by a later store [" << LaterOff <<
", " 502 << int64_t(LaterOff + LaterSize) <<
")\n");
504 return OW_PartialEarlierWithFullLater;
516 (LaterOff > EarlierOff && LaterOff < int64_t(EarlierOff + EarlierSize) &&
517 int64_t(LaterOff + LaterSize) >= int64_t(EarlierOff + EarlierSize)))
530 (LaterOff <= EarlierOff && int64_t(LaterOff + LaterSize) > EarlierOff)) {
531 assert(int64_t(LaterOff + LaterSize) < int64_t(EarlierOff + EarlierSize) &&
532 "Expect to be handled as OW_Complete");
560 if (!InstReadLoc.
Ptr)
564 if (AA.
isNoAlias(InstReadLoc, InstStoreLoc))
567 if (isa<AnyMemCpyInst>(Inst)) {
612 bool isFirstBlock =
true;
615 while (!WorkList.
empty()) {
624 assert(B == SecondBB &&
"first block is not the store block");
626 isFirstBlock =
false;
632 for (; BI != EI; ++BI) {
640 "Should not hit the entry block because SI must be dominated by LI");
642 if (!Visited.
insert(*PredI).second)
657 if (Pred == BB)
continue;
674 bool MadeChange =
false;
681 while (!Blocks.empty()) {
702 dbgs() <<
"DSE: Dead Store to soon to be freed memory:\n DEAD: " 703 << *Dependency <<
'\n');
738 if (isa<Constant>(UnderlyingPointer))
743 if (isa<AllocaInst>(UnderlyingPointer) || isa<Argument>(UnderlyingPointer)) {
744 DeadStackObjects.
remove(UnderlyingPointer);
752 return !AA->
isNoAlias(StackLoc, LoadedLoc);
767 bool MadeChange =
false;
776 if (isa<AllocaInst>(&
I))
788 if (AI.hasByValOrInAllocaAttr())
789 DeadStackObjects.
insert(&AI);
805 for (
const Value *Pointer : Pointers)
806 if (!DeadStackObjects.
count(Pointer)) {
815 << *Dead <<
"\n Objects: ";
821 if (std::next(
I) !=
E)
837 LLVM_DEBUG(
dbgs() <<
"DSE: Removing trivially dead instruction:\n DEAD: " 846 if (isa<AllocaInst>(BBI)) {
849 DeadStackObjects.
remove(&*BBI);
853 if (
auto *Call = dyn_cast<CallBase>(&*BBI)) {
857 DeadStackObjects.
remove(&*BBI);
874 if (DeadStackObjects.
empty())
885 if (isa<FenceInst>(*BBI))
891 if (
LoadInst *L = dyn_cast<LoadInst>(BBI)) {
892 if (!L->isUnordered())
895 }
else if (
VAArgInst *V = dyn_cast<VAArgInst>(BBI)) {
897 }
else if (!BBI->mayReadFromMemory()) {
912 if (DeadStackObjects.
empty())
920 int64_t &EarlierSize, int64_t LaterOffset,
921 int64_t LaterSize,
bool IsOverwriteEnd) {
928 auto *EarlierIntrinsic = cast<AnyMemIntrinsic>(EarlierWrite);
929 unsigned EarlierWriteAlign = EarlierIntrinsic->getDestAlignment();
931 LaterOffset = int64_t(LaterOffset + LaterSize);
933 if (!(
isPowerOf2_64(LaterOffset) && EarlierWriteAlign <= LaterOffset) &&
934 !((EarlierWriteAlign != 0) && LaterOffset % EarlierWriteAlign == 0))
937 int64_t NewLength = IsOverwriteEnd
938 ? LaterOffset - EarlierOffset
939 : EarlierSize - (LaterOffset - EarlierOffset);
941 if (
auto *AMI = dyn_cast<AtomicMemIntrinsic>(EarlierWrite)) {
944 const uint32_t ElementSize = AMI->getElementSizeInBytes();
945 if (0 != NewLength % ElementSize)
950 << (IsOverwriteEnd ?
"END" :
"BEGIN") <<
": " 951 << *EarlierWrite <<
"\n KILLER (offset " << LaterOffset
952 <<
", " << EarlierSize <<
")\n");
954 Value *EarlierWriteLength = EarlierIntrinsic->getLength();
955 Value *TrimmedLength =
957 EarlierIntrinsic->setLength(TrimmedLength);
959 EarlierSize = NewLength;
960 if (!IsOverwriteEnd) {
961 int64_t OffsetMoved = (LaterOffset - EarlierOffset);
962 Value *Indices[1] = {
965 EarlierIntrinsic->getRawDest()->getType()->getPointerElementType(),
966 EarlierIntrinsic->getRawDest(), Indices,
"", EarlierWrite);
967 NewDestGEP->
setDebugLoc(EarlierIntrinsic->getDebugLoc());
968 EarlierIntrinsic->setDest(NewDestGEP);
969 EarlierOffset = EarlierOffset + OffsetMoved;
976 int64_t &EarlierStart, int64_t &EarlierSize) {
980 OverlapIntervalsTy::iterator OII = --IntervalMap.end();
981 int64_t LaterStart = OII->second;
982 int64_t LaterSize = OII->first - LaterStart;
984 if (LaterStart > EarlierStart && LaterStart < EarlierStart + EarlierSize &&
985 LaterStart + LaterSize >= EarlierStart + EarlierSize) {
986 if (
tryToShorten(EarlierWrite, EarlierStart, EarlierSize, LaterStart,
988 IntervalMap.erase(OII);
997 int64_t &EarlierStart, int64_t &EarlierSize) {
1001 OverlapIntervalsTy::iterator OII = IntervalMap.begin();
1002 int64_t LaterStart = OII->second;
1003 int64_t LaterSize = OII->first - LaterStart;
1005 if (LaterStart <= EarlierStart && LaterStart + LaterSize > EarlierStart) {
1006 assert(LaterStart + LaterSize < EarlierStart + EarlierSize &&
1007 "Should have been handled as OW_Complete");
1008 if (
tryToShorten(EarlierWrite, EarlierStart, EarlierSize, LaterStart,
1009 LaterSize,
false)) {
1010 IntervalMap.erase(OII);
1020 bool Changed =
false;
1021 for (
auto OI : IOL) {
1027 int64_t EarlierStart = 0;
1032 tryToShortenEnd(EarlierWrite, IntervalMap, EarlierStart, EarlierSize);
1033 if (IntervalMap.empty())
1060 dbgs() <<
"DSE: Remove Store Of Load from same pointer:\n LOAD: " 1061 << *DepLoad <<
"\n STORE: " << *SI <<
'\n');
1064 ++NumRedundantStores;
1075 if (UnderlyingPointer &&
isCallocLikeFn(UnderlyingPointer, TLI) &&
1078 dbgs() <<
"DSE: Remove null store to the calloc'ed object:\n DEAD: " 1079 << *Inst <<
"\n OBJECT: " << *UnderlyingPointer <<
'\n');
1082 ++NumRedundantStores;
1093 bool MadeChange =
false;
1105 MadeChange |=
handleFree(
F, AA, MD, DT, TLI, IOL, OBB, ThrowableInst);
1115 ThrowableInst[Inst] =
true;
1171 if (!ThrowableInst.
empty())
1172 LastThrowing = ThrowableInst.
back().first;
1182 if (LastThrowing && OBB.
dominates(DepWrite, LastThrowing)) {
1184 bool IsStoreDeadOnUnwind = isa<AllocaInst>(
Underlying);
1185 if (!IsStoreDeadOnUnwind) {
1193 if (!IsStoreDeadOnUnwind)
1204 int64_t InstWriteOffset, DepWriteOffset;
1206 InstWriteOffset, DepWrite, IOL, *AA,
1208 if (OR == OW_Complete) {
1209 LLVM_DEBUG(
dbgs() <<
"DSE: Remove Dead Store:\n DEAD: " << *DepWrite
1210 <<
"\n KILLER: " << *Inst <<
'\n');
1225 "when partial-overwrite " 1226 "tracking is enabled");
1230 bool IsOverwriteEnd = (OR == OW_End);
1231 MadeChange |=
tryToShorten(DepWrite, DepWriteOffset, EarlierSize,
1232 InstWriteOffset, LaterSize, IsOverwriteEnd);
1234 OR == OW_PartialEarlierWithFullLater) {
1237 if (Earlier && isa<ConstantInt>(Earlier->getValueOperand()) &&
1239 Earlier->getValueOperand()->getType()) &&
1240 Later && isa<ConstantInt>(Later->getValueOperand()) &&
1242 Later->getValueOperand()->getType()) &&
1254 APInt EarlierValue =
1255 cast<ConstantInt>(Earlier->getValueOperand())->getValue();
1257 cast<ConstantInt>(Later->getValueOperand())->getValue();
1263 unsigned BitOffsetDiff = (InstWriteOffset - DepWriteOffset) * 8;
1264 unsigned LShiftAmount =
1266 ? EarlierValue.
getBitWidth() - BitOffsetDiff - LaterBits
1270 LShiftAmount + LaterBits);
1274 (EarlierValue & ~Mask) | (LaterValue << LShiftAmount);
1275 LLVM_DEBUG(
dbgs() <<
"DSE: Merge Stores:\n Earlier: " << *DepWrite
1276 <<
"\n Later: " << *Inst
1277 <<
"\n Merged Value: " << Merged <<
'\n');
1281 Earlier->getPointerOperand(),
false,
1282 MaybeAlign(Earlier->getAlignment()), Earlier->getOrdering(),
1283 Earlier->getSyncScopeID(), DepWrite);
1285 unsigned MDToKeep[] = {LLVMContext::MD_dbg, LLVMContext::MD_tbaa,
1286 LLVMContext::MD_alias_scope,
1287 LLVMContext::MD_noalias,
1288 LLVMContext::MD_nontemporal};
1289 SI->copyMetadata(*DepWrite, MDToKeep);
1290 ++NumModifiedStores;
1316 if (DepWrite == &BB.
front())
break;
1334 MadeChange |=
handleEndBlock(BB, AA, MD, TLI, IOL, OBB, ThrowableInst);
1342 bool MadeChange =
false;
1383 if (skipFunction(F))
1386 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1387 AliasAnalysis *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
1389 &getAnalysis<MemoryDependenceWrapperPass>().getMemDep();
1391 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
1423 return new DSELegacyPass();
Legacy wrapper pass to provide the GlobalsAAResult object.
bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout &DL, const TargetLibraryInfo *TLI, ObjectSizeOpts Opts={})
Compute the size of the object pointed by Ptr.
Value * getValueOperand()
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. ...
void eraseInstruction(const Instruction *I)
Remove from the ordering, if it is present.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM's alias analysis passes.
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL, bool AllowNonInbounds=true)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents an incoming formal argument to a Function.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
This is the interface for a simple mod/ref and alias analysis over globals.
void initializeDSELegacyPassPass(PassRegistry &)
void push_back(const T &Elt)
bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are no-alias. ...
APInt zext(unsigned width) const
Zero extend to a new width.
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated...
This class represents a function call, abstracting a target machine's calling convention.
bool isNonLocal() const
Tests if this MemDepResult represents a query that is transparent to the start of the block...
void pop_back()
Remove the last element from the vector.
bool dominates(const Instruction *A, const Instruction *B)
Find out whether A dominates B, meaning whether A comes before B in BB.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
bool salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage debug users of I by writing the...
MemDepResult getDependency(Instruction *QueryInst, OrderedBasicBlock *OBB=nullptr)
Returns the instruction on which a memory operation depends.
This class implements a map that also provides access to all stored values in a deterministic order...
STATISTIC(NumFunctions, "Total number of functions")
Analysis pass which computes a DominatorTree.
An instruction for reading from memory.
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...
static bool isPossibleSelfRead(Instruction *Inst, const MemoryLocation &InstStoreLoc, Instruction *DepWrite, const TargetLibraryInfo &TLI, AliasAnalysis &AA)
If 'Inst' might be a self read (i.e.
static void removeAccessedObjects(const MemoryLocation &LoadedLoc, SmallSetVector< const Value *, 16 > &DeadStackObjects, const DataLayout &DL, AliasAnalysis *AA, const TargetLibraryInfo *TLI, const Function *F)
Check to see if the specified location may alias any of the stack objects in the DeadStackObjects set...
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type. ...
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
static bool eliminateNoopStore(Instruction *Inst, BasicBlock::iterator &BBI, AliasAnalysis *AA, MemoryDependenceResults *MD, const DataLayout &DL, const TargetLibraryInfo *TLI, InstOverlapIntervalsTy &IOL, OrderedBasicBlock &OBB, MapVector< Instruction *, bool > &ThrowableInst)
unsigned getBitWidth() const
Return the number of bits in the APInt.
static void findUnconditionalPreds(SmallVectorImpl< BasicBlock *> &Blocks, BasicBlock *BB, DominatorTree *DT)
Find all blocks that will unconditionally lead to the block BB and append them to F...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
iterator begin()
Instruction iterator methods.
Value * getArgOperand(unsigned i) const
AnalysisUsage & addRequired()
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isDef() const
Tests if this MemDepResult represents a query that is an instruction definition dependency.
std::pair< KeyT, ValueT > & back()
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isClobber() const
Tests if this MemDepResult represents a query that is an instruction clobber dependency.
unsigned getDefaultBlockScanLimit() const
Some methods limit the number of instructions they will examine.
An analysis that produces MemoryDependenceResults for a function.
static MemoryLocation getLocForWrite(Instruction *Inst)
Return a Location stored to by the specified instruction.
bool remove(const value_type &X)
Remove an item from the set vector.
This file implements a class to represent arbitrary precision integral constant values and operations...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
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.
static Value * getStoredPointerOperand(Instruction *I)
Return the pointer that is being written to.
static MemoryLocation getForDest(const MemIntrinsic *MI)
Return a location representing the destination of a memory set or transfer.
bool has(LibFunc F) const
Tests whether a library function is available.
std::map< int64_t, int64_t > OverlapIntervalsTy
static uint64_t getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI, const Function *F)
An instruction for storing to memory.
iterator find(const KeyT &Key)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
Value * getOperand(unsigned i) const
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
uint64_t getValue() const
const BasicBlock & getEntryBlock() const
static bool handleFree(CallInst *F, AliasAnalysis *AA, MemoryDependenceResults *MD, DominatorTree *DT, const TargetLibraryInfo *TLI, InstOverlapIntervalsTy &IOL, OrderedBasicBlock &OBB, MapVector< Instruction *, bool > &ThrowableInst)
Handle frees of entire structures whose dependency is a store to a field of that structure.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
static bool runOnFunction(Function &F, bool PostInlining)
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
initializer< Ty > init(const Ty &Val)
bool erase(const KeyT &Val)
void GetUnderlyingObjects(const Value *V, SmallVectorImpl< const Value *> &Objects, const DataLayout &DL, LoopInfo *LI=nullptr, unsigned MaxLookup=6)
This method is similar to GetUnderlyingObject except that it can look through phi and select instruct...
static bool isShortenableAtTheBeginning(Instruction *I)
Returns true if the beginning of this instruction can be safely shortened in length.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A set of analyses that are preserved following a run of a transformation pass.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM Basic Block Representation.
static bool removePartiallyOverlappedStores(AliasAnalysis *AA, const DataLayout &DL, InstOverlapIntervalsTy &IOL)
static OverwriteResult isOverwrite(const MemoryLocation &Later, const MemoryLocation &Earlier, const DataLayout &DL, const TargetLibraryInfo &TLI, int64_t &EarlierOff, int64_t &LaterOff, Instruction *DepWrite, InstOverlapIntervalsTy &IOL, AliasAnalysis &AA, const Function *F)
Return 'OW_Complete' if a store to the 'Later' location completely overwrites a store to the 'Earlier...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
A manager for alias analyses.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
static bool handleEndBlock(BasicBlock &BB, AliasAnalysis *AA, MemoryDependenceResults *MD, const TargetLibraryInfo *TLI, InstOverlapIntervalsTy &IOL, OrderedBasicBlock &OBB, MapVector< Instruction *, bool > &ThrowableInst)
Remove dead stores to stack-allocated locations in the function end block.
bool mayThrow() const
Return true if this instruction may throw an exception.
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...
static bool isShortenableAtTheEnd(Instruction *I)
Returns true if the end of this instruction can be safely shortened in length.
Represent the analysis usage information of a pass.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
FunctionPass * createDeadStoreEliminationPass()
static bool memoryIsNotModifiedBetween(Instruction *FirstI, Instruction *SecondI, AliasAnalysis *AA)
Returns true if the memory which is accessed by the second instruction is not modified between the fi...
std::underlying_type< E >::type Underlying(E Val)
Check that Val is in range for E, and return Val cast to E's underlying type.
Analysis pass providing a never-invalidated alias analysis result.
FunctionPass class - This class is used to implement most global optimizations.
LocationSize Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known...
Interval::pred_iterator pred_end(Interval *I)
self_iterator getIterator()
INITIALIZE_PASS_BEGIN(DSELegacyPass, "dse", "Dead Store Elimination", false, false) INITIALIZE_PASS_END(DSELegacyPass
MemDepResult getPointerDependencyFrom(const MemoryLocation &Loc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB, Instruction *QueryInst=nullptr, unsigned *Limit=nullptr, OrderedBasicBlock *OBB=nullptr)
Returns the instruction on which a memory location depends.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A wrapper analysis pass for the legacy pass manager that exposes a MemoryDepnedenceResults instance...
static void deleteDeadInstruction(Instruction *I, BasicBlock::iterator *BBI, MemoryDependenceResults &MD, const TargetLibraryInfo &TLI, InstOverlapIntervalsTy &IOL, OrderedBasicBlock &OBB, MapVector< Instruction *, bool > &ThrowableInst, SmallSetVector< const Value *, 16 > *ValueSet=nullptr)
Delete this instruction.
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A memory dependence query can return one of three different answers.
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
static cl::opt< bool > EnablePartialOverwriteTracking("enable-dse-partial-overwrite-tracking", cl::init(true), cl::Hidden, cl::desc("Enable partial-overwrite tracking in DSE"))
static cl::opt< bool > EnablePartialStoreMerging("enable-dse-partial-store-merging", cl::init(true), cl::Hidden, cl::desc("Enable partial store merging in DSE"))
A SetVector that performs no allocations if smaller than a certain size.
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Align max(MaybeAlign Lhs, Align Rhs)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
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.
Provides information about what library functions are available for the current target.
LLVM_NODISCARD T pop_back_val()
static bool hasAnalyzableMemoryWrite(Instruction *I, const TargetLibraryInfo &TLI)
Does this instruction write some memory? This only returns true for things that we can analyze with o...
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.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Class for arbitrary precision integers.
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are must-alias.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
Represents analyses that only rely on functions' control flow.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
static bool tryToShortenBegin(Instruction *EarlierWrite, OverlapIntervalsTy &IntervalMap, int64_t &EarlierStart, int64_t &EarlierSize)
bool doesNotAccessMemory(const CallBase *Call)
Checks if the specified call is known to never read or write memory.
Instruction * getInst() const
If this is a normal dependency, returns the instruction that is depended on.
static MemoryLocation getLocForRead(Instruction *Inst, const TargetLibraryInfo &TLI)
Return the location read by the specified "hasAnalyzableMemoryWrite" instruction if any...
LLVM_NODISCARD bool empty() const
This file provides utility analysis objects describing memory locations.
void preserveSet()
Mark an analysis set as preserved.
void replaceInstruction(const Instruction *Old, const Instruction *New)
Replace Old with New in the ordering.
const Function * getParent() const
Return the enclosing method, or null if none.
bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates zero-filled memory (such as...
bool empty() const
Determine if the SetVector is empty or not.
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void preserve()
Mark an analysis as preserved.
Analysis pass providing the TargetLibraryInfo.
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
static bool eliminateDeadStores(BasicBlock &BB, AliasAnalysis *AA, MemoryDependenceResults *MD, DominatorTree *DT, const TargetLibraryInfo *TLI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const BasicBlock & front() const
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.
void removeInstruction(Instruction *InstToRemove)
Removes an instruction from the dependence analysis, updating the dependence of instructions that pre...
bool remove_if(UnaryPredicate P)
Remove items from the set vector based on a predicate function.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static bool isRemovable(Instruction *I)
If the value of this instruction and the memory it writes to is unused, may we delete this instructio...
Various options to control the behavior of getObjectSize.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
static bool isVolatile(Instruction *Inst)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
This header defines various interfaces for pass management in LLVM.
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
Value * getPointerOperand()
static bool tryToShorten(Instruction *EarlierWrite, int64_t &EarlierOffset, int64_t &EarlierSize, int64_t LaterOffset, int64_t LaterSize, bool IsOverwriteEnd)
iterator_range< arg_iterator > args()
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
static bool tryToShortenEnd(Instruction *EarlierWrite, OverlapIntervalsTy &IntervalMap, int64_t &EarlierStart, int64_t &EarlierSize)
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures, unsigned MaxUsesToExplore=DefaultMaxUsesToExplore)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
static MemoryLocation getForSource(const MemTransferInst *MTI)
Return a location representing the source of a memory transfer.
LLVM_NODISCARD bool isRefSet(const ModRefInfo MRI)