Go to the documentation of this file.
18 #ifndef LLVM_CODEGEN_SLOTINDEXES_H
19 #define LLVM_CODEGEN_SLOTINDEXES_H
62 #ifdef EXPENSIVE_CHECKS
68 assert(((
tmp & 0x1) == 0x0) &&
"Pointer already poisoned?");
73 bool isPoisoned()
const {
return (
reinterpret_cast<intptr_t>(mi) & 0x1) == 0x1; }
74 #endif // EXPENSIVE_CHECKS
113 #ifdef EXPENSIVE_CHECKS
115 "Attempt to access deleted list-entry.");
116 #endif // EXPENSIVE_CHECKS
120 unsigned getIndex()
const {
121 return listEntry()->
getIndex() | getSlot();
125 Slot getSlot()
const {
126 return static_cast<Slot
>(lie.
getInt());
147 "Attempt to construct index with 0 pointer.");
157 explicit operator bool()
const {
return isValid(); }
167 return lie == other.lie;
171 return lie != other.lie;
177 return getIndex() < other.getIndex();
182 return getIndex() <= other.getIndex();
188 return getIndex() > other.getIndex();
194 return getIndex() >= other.getIndex();
199 return A.lie.getPointer() ==
B.lie.getPointer();
205 return A.listEntry()->getIndex() <
B.listEntry()->getIndex();
216 return other.getIndex() - getIndex();
226 return (other.listEntry()->
getIndex() - listEntry()->getIndex())
231 bool isBlock()
const {
return getSlot() == Slot_Block; }
238 bool isRegister()
const {
return getSlot() == Slot_Register; }
241 bool isDead()
const {
return getSlot() == Slot_Dead; }
247 return SlotIndex(listEntry(), Slot_Block);
254 return SlotIndex(listEntry(), Slot_Dead);
260 return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register);
265 return SlotIndex(listEntry(), Slot_Dead);
276 if (
s == Slot_Dead) {
277 return SlotIndex(&*++listEntry()->getIterator(), Slot_Block);
285 return SlotIndex(&*++listEntry()->getIterator(), getSlot());
296 if (
s == Slot_Block) {
297 return SlotIndex(&*--listEntry()->getIterator(), Slot_Dead);
305 return SlotIndex(&*--listEntry()->getIterator(), getSlot());
314 using IdxMBBPair = std::pair<SlotIndex, MachineBasicBlock *>;
374 assert(indexList.front().getIndex() == 0 &&
"First index is not 0?");
391 bool IgnoreBundle =
false)
const {
400 "Could not use a debug instruction to query mi2iMap.");
402 assert(itr != mi2iMap.
end() &&
"Instruction not found in maps.");
409 return index.isValid() ?
index.listEntry()->getInstr() :
nullptr;
429 assert(
MBB &&
"MI must be inserted in a basic block");
436 if (MapItr != mi2iMap.
end())
437 return MapItr->second;
446 assert(
MBB &&
"MI must be inserted in a basic block");
453 if (MapItr != mi2iMap.
end())
454 return MapItr->second;
459 const std::pair<SlotIndex, SlotIndex> &
461 return MBBRanges[Num];
465 const std::pair<SlotIndex, SlotIndex> &
499 [=](
const IdxMBBPair &IM) { return IM.first < To; });
510 return idx2MBBMap.begin();
515 return idx2MBBMap.end();
521 return MI->getParent();
531 "index does not correspond to an MBB");
542 "Instructions inside bundles should use bundle start's slot.");
543 assert(mi2iMap.
find(&
MI) == mi2iMap.
end() &&
"Instr already indexed.");
546 assert(!
MI.isDebugInstr() &&
"Cannot number debug instructions.");
548 assert(
MI.getParent() !=
nullptr &&
"Instr must be added to function.");
555 prevItr = std::prev(nextItr);
559 nextItr = std::next(prevItr);
564 unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u;
565 unsigned newNumber = prevItr->getIndex() + dist;
569 indexList.
insert(nextItr, createEntry(&
MI, newNumber));
573 renumberIndexes(newItr);
575 SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block);
576 mi2iMap.
insert(std::make_pair(&
MI, newIndex));
587 bool AllowBundled =
false);
599 if (mi2iItr == mi2iMap.
end())
601 SlotIndex replaceBaseIndex = mi2iItr->second;
604 "Mismatched instruction in index tables.");
606 mi2iMap.
erase(mi2iItr);
607 mi2iMap.
insert(std::make_pair(&NewMI, replaceBaseIndex));
608 return replaceBaseIndex;
617 "Can't insert a new block at the beginning of a function.");
625 mbb->
empty() ? endEntry
630 SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
631 SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
633 MBBRanges[prevMBB->getNumber()].second = startIdx;
636 "Blocks must be added in order");
637 MBBRanges.push_back(std::make_pair(startIdx, endIdx));
638 idx2MBBMap.push_back(
IdxMBBPair(startIdx, mbb));
640 renumberIndexes(newItr);
652 #endif // LLVM_CODEGEN_SLOTINDEXES_H
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.
void dump() const
Dump this index to stderr.
void insertMBBInMaps(MachineBasicBlock *mbb)
Add the given MachineBasicBlock into the maps.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
This is an optimization pass for GlobalISel generic memory operations.
static bool isEarlierEqualInstr(SlotIndex A, SlotIndex B)
Return true if A refers to the same instruction as B or an earlier one.
bool isValid() const
Returns true if this is a valid index.
bool operator==(SlotIndex other) const
Compare two SlotIndex objects for equality.
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
void setInstr(MachineInstr *mi)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MachineInstr * getInstr() const
void getAnalysisUsage(AnalysisUsage &au) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
IndexListEntry(MachineInstr *mi, unsigned index)
bool operator!=(SlotIndex other) const
Compare two SlotIndex objects for inequality.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool erase(const KeyT &Val)
Since we know that Vector is byte aligned and we know the element offset of we should change the load into a lve *x instead of doing a load store lve *x sequence Implement passing vectors by value into calls and receiving them as arguments GCC apparently tries to then a load and vperm of Variable We need a way to teach tblgen that some operands of an intrinsic are required to be constants The verifier should enforce this constraint We currently codegen SCALAR_TO_VECTOR as a store of the scalar to a byte aligned stack slot
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
alloca< 16 x float >, align 16 %tmp2=alloca< 16 x float >, align 16 store< 16 x float > %A,< 16 x float > *%tmp %s=bitcast< 16 x float > *%tmp to i8 *%s2=bitcast< 16 x float > *%tmp2 to i8 *call void @llvm.memcpy.i64(i8 *%s, i8 *%s2, i64 64, i32 16) %R=load< 16 x float > *%tmp2 ret< 16 x float > %R } declare void @llvm.memcpy.i64(i8 *nocapture, i8 *nocapture, i64, i32) nounwind which compiles to:_foo:subl $140, %esp movaps %xmm3, 112(%esp) movaps %xmm2, 96(%esp) movaps %xmm1, 80(%esp) movaps %xmm0, 64(%esp) movl 60(%esp), %eax movl %eax, 124(%esp) movl 56(%esp), %eax movl %eax, 120(%esp) movl 52(%esp), %eax< many many more 32-bit copies > movaps(%esp), %xmm0 movaps 16(%esp), %xmm1 movaps 32(%esp), %xmm2 movaps 48(%esp), %xmm3 addl $140, %esp ret On Nehalem, it may even be cheaper to just use movups when unaligned than to fall back to lower-granularity chunks. Implement processor-specific optimizations for parity with GCC on these processors. GCC does two optimizations:1. ix86_pad_returns inserts a noop before ret instructions if immediately preceded by a conditional branch or is the target of a jump. 2. ix86_avoid_jump_misspredicts inserts noops in cases where a 16-byte block of code contains more than 3 branches. The first one is done for all AMDs, Core2, and "Generic" The second one is done for:Atom, Pentium Pro, all AMDs, Pentium 4, Nocona, Core 2, and "Generic" Testcase:int x(int a) { return(a &0xf0)> >4 tmp
SlotIndex()=default
Construct an invalid index.
An intrusive list with ownership and callbacks specified/controlled by ilist_traits,...
BasicBlockListType::iterator iterator
@ InstrDist
The default distance between instructions as returned by distance().
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
const MachineBasicBlock & front() const
bool hasIndex(const MachineInstr &instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Function object to check whether the first component of a std::pair compares less than the first comp...
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
Represent the analysis usage information of a pass.
bool isDebugInstr() const
bool operator>=(SlotIndex other) const
Compare two SlotIndex objects.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
This class implements an extremely fast bulk output stream that can only output to a stream.
This class represents an entry in the slot index list held in the SlotIndexes pass.
void dump() const
Dump the indexes.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
bool isRegister() const
isRegister - Returns true if this is a normal register use/def slot.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
void removeSingleMachineInstrFromMaps(MachineInstr &MI)
Removes a single machine instruction MI from the mapping.
SlotIndex - An opaque wrapper around machine indexes.
MBBIndexIterator findMBBIndex(SlotIndex Idx) const
Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex that is greater or equal to Idx...
SlotIndex getIndexBefore(const MachineInstr &MI) const
getIndexBefore - Returns the index of the last indexed instruction before MI, or the start index of i...
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
MBBIndexIterator MBBIndexEnd() const
Return an iterator for the end of the idx2MBBMap.
void sort(IteratorTy Start, IteratorTy End)
PointerTy getPointer() const
SlotIndex getPrevIndex() const
Returns the previous index.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
Representation of each machine instruction.
base_list_type::iterator iterator
SlotIndex replaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in maps used by register allocat...
multiplies can be turned into SHL s
Allocate memory in an ever growing pool, as if by bump-pointer.
MBBIndexIterator MBBIndexBegin() const
Returns an iterator for the begin of the idx2MBBMap.
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
Use delete by default for iplist and ilist.
iterator find(const_arg_type_t< KeyT > Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
SlotIndex getIndexAfter(const MachineInstr &MI) const
getIndexAfter - Returns the index of the first indexed instruction after MI, or the end index of its ...
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const
Move iterator to the next IdxMBBPair where the SlotIndex is greater or equal to To.
Custom traits to do nothing on deletion.
SlotIndex getLastIndex()
Returns the base index of the last slot in this analysis.
SlotIndex getNextIndex() const
Returns the next index.
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
self_iterator getIterator()
SlotIndex getNextSlot() const
Returns the next slot in the index list.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair
bool operator<=(SlotIndex other) const
Compare two SlotIndex objects.
SlotIndex(const SlotIndex &li, Slot s)
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block)
bool operator>(SlotIndex other) const
Compare two SlotIndex objects.
iterator insert(iterator where, pointer New)
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
const std::pair< SlotIndex, SlotIndex > & getMBBRange(const MachineBasicBlock *MBB) const
Return the (start,end) range of the given basic block.
unsigned getIndex() const
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Returns the last index in the given basic block.
bool operator<(SlotIndex other) const
Compare two SlotIndex objects.
PointerIntPair - This class implements a pair of a pointer and small integer.
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
bool runOnMachineFunction(MachineFunction &fn) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
int getApproxInstrDistance(SlotIndex other) const
Return the scaled distance from this index to the given one, where all slots on the same instruction ...
int distance(SlotIndex other) const
Return the distance from this index to the given one.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
void removeMachineInstrFromMaps(MachineInstr &MI, bool AllowBundled=false)
Removes machine instruction (bundle) MI from the mapping.
SlotIndex(IndexListEntry *entry, unsigned slot)
void setIndex(unsigned index)
print Instructions which execute on loop entry