- /// Returns true if there is a gap in the numbering before the given index.
- bool hasGapBeforeInstr(SlotIndex index) {
- index = index.getBaseIndex();
- SlotIndex prevIndex = index.getPrevIndex();
-
- if (prevIndex == getZeroIndex())
- return false;
-
- if (getInstructionFromIndex(prevIndex) == 0)
- return true;
-
- if (prevIndex.distance(index) >= 2 * SlotIndex::NUM)
- return true;
-
- return false;
- }
-
- /// Returns true if there is a gap in the numbering after the given index.
- bool hasGapAfterInstr(SlotIndex index) const {
- // Not implemented yet.
- assert(false &&
- "SlotIndexes::hasGapAfterInstr(SlotIndex) not implemented yet.");
- return false;
- }
-
- /// findGapBeforeInstr - Find an empty instruction slot before the
- /// specified index. If "Furthest" is true, find one that's furthest
- /// away from the index (but before any index that's occupied).
- // FIXME: This whole method should go away in future. It should
- // always be possible to insert code between existing indices.
- SlotIndex findGapBeforeInstr(SlotIndex index, bool furthest = false) {
- if (index == getZeroIndex())
- return getInvalidIndex();
-
- index = index.getBaseIndex();
- SlotIndex prevIndex = index.getPrevIndex();
-
- if (prevIndex == getZeroIndex())
- return getInvalidIndex();
-
- // Try to reuse existing index objects with null-instrs.
- if (getInstructionFromIndex(prevIndex) == 0) {
- if (furthest) {
- while (getInstructionFromIndex(prevIndex) == 0 &&
- prevIndex != getZeroIndex()) {
- prevIndex = prevIndex.getPrevIndex();
- }
-
- prevIndex = prevIndex.getNextIndex();
- }
-
- assert(getInstructionFromIndex(prevIndex) == 0 && "Index list is broken.");
-
- return prevIndex;
+ /// Insert the given machine instruction into the mapping. Returns the
+ /// assigned index.
+ /// If Late is set and there are null indexes between mi's neighboring
+ /// instructions, create the new index after the null indexes instead of
+ /// before them.
+ SlotIndex insertMachineInstrInMaps(MachineInstr *mi, bool Late = false) {
+ assert(!mi->isInsideBundle() &&
+ "Instructions inside bundles should use bundle start's slot.");
+ assert(mi2iMap.find(mi) == mi2iMap.end() && "Instr already indexed.");
+ // Numbering DBG_VALUE instructions could cause code generation to be
+ // affected by debug information.
+ assert(!mi->isDebugValue() && "Cannot number DBG_VALUE instructions.");
+
+ assert(mi->getParent() != 0 && "Instr must be added to function.");
+
+ // Get the entries where mi should be inserted.
+ IndexList::iterator prevItr, nextItr;
+ if (Late) {
+ // Insert mi's index immediately before the following instruction.
+ nextItr = getIndexAfter(mi).listEntry();
+ prevItr = prior(nextItr);
+ } else {
+ // Insert mi's index immediately after the preceeding instruction.
+ prevItr = getIndexBefore(mi).listEntry();
+ nextItr = llvm::next(prevItr);