94 #define DEBUG_TYPE "mldst-motion" 107 const int MagicCompileTimeControl = 250;
109 const bool SplitFooterBB;
120 bool isStoreSinkBarrierInRange(
const Instruction &Start,
133 assert(isDiamondHead(BB) &&
"Basic block is not head of a diamond");
140 bool MergedLoadStoreMotion::isDiamondHead(
BasicBlock *BB) {
144 if (!BI || !BI->isConditional())
158 if (!Succ0Succ || !Succ1Succ || Succ0Succ != Succ1Succ)
172 bool MergedLoadStoreMotion::isStoreSinkBarrierInRange(
const Instruction &Start,
199 !isStoreSinkBarrierInRange(*Store1->getNextNode(), BB1->
back(), Loc1) &&
200 !isStoreSinkBarrierInRange(*Store0->
getNextNode(), BB0->back(), Loc0)) {
221 NewPN->addIncoming(Opd1, S0->
getParent());
222 NewPN->addIncoming(Opd2, S1->
getParent());
229 bool MergedLoadStoreMotion::canSinkStoresAndGEPs(
StoreInst *S0,
233 return A0 && A1 && A0->
isIdenticalTo(A1) && A0->hasOneUse() &&
234 (A0->getParent() == S0->
getParent()) && A1->hasOneUse() &&
235 (A1->getParent() == S1->
getParent()) && isa<GetElementPtrInst>(A0);
249 dbgs() <<
"Instruction Left\n"; S0->
dump();
dbgs() <<
"\n";
250 dbgs() <<
"Instruction Right\n"; S1->
dump();
dbgs() <<
"\n");
261 ANew->insertBefore(SNew);
267 if (
PHINode *NewPN = getPHIOperand(BB, S0, S1))
271 A0->replaceAllUsesWith(ANew);
272 A0->eraseFromParent();
273 A1->replaceAllUsesWith(ANew);
274 A1->eraseFromParent();
283 bool MergedLoadStoreMotion::mergeStores(
BasicBlock *HeadBB) {
285 bool MergedStores =
false;
288 assert(SinkBB &&
"Footer of a diamond cannot be empty");
291 assert(SI !=
succ_end(HeadBB) &&
"Diamond head cannot have zero successors");
294 assert(SI !=
succ_end(HeadBB) &&
"Diamond head cannot have single successor");
304 int Size1 = std::distance(InstsNoDbg.begin(), InstsNoDbg.end());
319 if (NStores * Size1 >= MagicCompileTimeControl)
321 if (
StoreInst *S1 = canSinkFromBlock(Pred1, S0)) {
322 if (!canSinkStoresAndGEPs(S0, S1))
338 sinkStoresAndGEPs(SinkBB, S0, S1);
350 bool Changed =
false;
362 if (isDiamondHead(BB)) {
363 Changed |= mergeStores(BB);
370 class MergedLoadStoreMotionLegacyPass :
public FunctionPass {
371 const bool SplitFooterBB;
374 MergedLoadStoreMotionLegacyPass(
bool SplitFooterBB =
false)
387 return Impl.run(F, getAnalysis<AAResultsWrapperPass>().getAAResults());
406 return new MergedLoadStoreMotionLegacyPass(SplitFooterBB);
410 "MergedLoadStoreMotion",
false,
false)
419 if (!Impl.run(F, AA))
423 if (!Options.SplitFooterBB)
Legacy wrapper pass to provide the GlobalsAAResult object.
The access may reference and may modify the value stored in memory.
Value * getValueOperand()
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
This function determines if the specified instruction executes the same operation as the current one...
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
This class represents lattice values for constants.
This is the interface for a simple mod/ref and alias analysis over globals.
void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs)
Drop all unknown metadata except for debug locations.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
INITIALIZE_PASS_BEGIN(MergedLoadStoreMotionLegacyPass, "mldst-motion", "MergedLoadStoreMotion", false, false) INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass
reverse_iterator rbegin()
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...
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one. ...
void dump() const
Support for debugging, callable in GDB: V->dump()
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
FunctionPass * createMergedLoadStoreMotionPass(bool SplitFooterBB=false)
createMergedLoadStoreMotionPass - The public interface to this file.
mldst MergedLoadStoreMotion
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()))
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
Type * getType() const
All values are typed, get the type of this value.
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction...
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
An instruction for storing to memory.
Interval::succ_iterator succ_end(Interval *I)
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.
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock *> Preds, const char *Suffix, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
A set of analyses that are preserved following a run of a transformation pass.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
LLVM Basic Block Representation.
Conditional or Unconditional Branch instruction.
iterator_range< filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> > > instructionsWithoutDebug() const
Return a const iterator range over the instructions in the block, skipping any debug instructions...
const Instruction & front() const
A manager for alias analyses.
Represent the analysis usage information of a pass.
const Instruction & back() const
Analysis pass providing a never-invalidated alias analysis result.
FunctionPass class - This class is used to implement most global optimizations.
self_iterator getIterator()
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Representation for a specific memory location.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
Iterator for intrusive lists based on ilist_node.
void applyMergedLocation(const DILocation *LocA, const DILocation *LocB)
Merge 2 debug locations and apply it to the Instruction.
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...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Represents analyses that only rely on functions' control flow.
This pass performs merges of loads and stores on both sides of a.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
void preserveSet()
Mark an analysis set as preserved.
StringRef getName() const
Return a constant reference to the value's name.
const Function * getParent() const
Return the enclosing method, or null if none.
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
A container for analyses that lazily runs them and caches their results.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry &)
Value * getPointerOperand()
const BasicBlock * getParent() const