Move getBundleStart() into MachineInstrBundle.h.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Thu, 1 Mar 2012 01:26:01 +0000 (01:26 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Thu, 1 Mar 2012 01:26:01 +0000 (01:26 +0000)
This allows the function to be inlined, and makes it suitable for use in
getInstructionIndex().

Also provide a const version. C++ is great for touch typing practice.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151782 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineInstr.h
include/llvm/CodeGen/MachineInstrBundle.h
include/llvm/CodeGen/SlotIndexes.h
lib/CodeGen/LiveIntervalAnalysis.cpp
lib/CodeGen/MachineInstr.cpp

index cd94abae7ec4fbba759614b08fd4b8fd06d451f9..7f29d316ea8592f4c44e22738c275d4d74cc65ac 100644 (file)
@@ -234,11 +234,6 @@ public:
   /// if either itself or its following instruction is marked "InsideBundle".
   bool isBundled() const;
 
-  /// getBundleStart - If this instruction is inside a bundle return the
-  /// instruction at the start of the bundle. Otherwise just returns the
-  /// instruction itself.
-  MachineInstr* getBundleStart();
-
   /// getDebugLoc - Returns the debug location id of this MachineInstr.
   ///
   DebugLoc getDebugLoc() const { return debugLoc; }
index 9552e21fca2b2661b18e7b133d143916be4df2cc..0fb49698227679c40155833a34e5a256595f586e 100644 (file)
@@ -41,6 +41,22 @@ MachineBasicBlock::instr_iterator finalizeBundle(MachineBasicBlock &MBB,
 /// MachineFunction. Return true if any bundles are finalized.
 bool finalizeBundles(MachineFunction &MF);
 
+/// getBundleStart - Returns the first instruction in the bundle containing MI.
+///
+static inline MachineInstr *getBundleStart(MachineInstr *MI) {
+  MachineBasicBlock::instr_iterator I = MI;
+  while (I->isInsideBundle())
+    --I;
+  return I;
+}
+
+static inline const MachineInstr *getBundleStart(const MachineInstr *MI) {
+  MachineBasicBlock::const_instr_iterator I = MI;
+  while (I->isInsideBundle())
+    --I;
+  return I;
+}
+
 //===----------------------------------------------------------------------===//
 // MachineOperand iterator
 //
@@ -82,7 +98,7 @@ protected:
   ///
   explicit MachineOperandIteratorBase(MachineInstr *MI, bool WholeBundle) {
     if (WholeBundle) {
-      InstrI = MI->getBundleStart();
+      InstrI = getBundleStart(MI);
       InstrE = MI->getParent()->instr_end();
     } else {
       InstrI = InstrE = MI;
index 6c09526b59d20ab8e955b33fe08a125913dab9bd..d868cb8dade86ec671362783866b99f351bd075c 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef LLVM_CODEGEN_SLOTINDEXES_H
 #define LLVM_CODEGEN_SLOTINDEXES_H
 
-#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineInstrBundle.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -495,10 +495,7 @@ namespace llvm {
     /// Returns the base index for the given instruction.
     SlotIndex getInstructionIndex(const MachineInstr *MI) const {
       // Instructions inside a bundle have the same number as the bundle itself.
-      MachineBasicBlock::const_instr_iterator I = MI;
-      while (I->isInsideBundle())
-        --I;
-      Mi2IndexMap::const_iterator itr = mi2iMap.find(I);
+      Mi2IndexMap::const_iterator itr = mi2iMap.find(getBundleStart(MI));
       assert(itr != mi2iMap.end() && "Instruction not found in maps.");
       return itr->second;
     }
index 03ca72e0818a84a70e34dd71cfdd996263c5d1da..3e16efa7285ec0fef451ff3cf4bb452819849692 100644 (file)
@@ -1522,7 +1522,7 @@ void LiveIntervals::handleMove(MachineInstr* MI) {
   SlotIndex OldIndex = indexes_->getInstructionIndex(MI);
   indexes_->removeMachineInstrFromMaps(MI);
   SlotIndex NewIndex = MI->isInsideBundle() ?
-                        indexes_->getInstructionIndex(MI->getBundleStart()) :
+                        indexes_->getInstructionIndex(MI) :
                         indexes_->insertMachineInstrInMaps(MI);
   assert(getMBBStartIdx(MI->getParent()) <= OldIndex &&
          OldIndex < getMBBEndIdx(MI->getParent()) &&
index 3ab98e1bf57d81a1109f15ccf90c457d60f6a60b..ff32a66b14c2d162c4cc310bf5b715e1095f1cce 100644 (file)
@@ -900,16 +900,6 @@ bool MachineInstr::isBundled() const {
   return nextMI != Parent->instr_end() && nextMI->isInsideBundle();
 }
 
-MachineInstr* MachineInstr::getBundleStart() {
-  if (!isInsideBundle())
-    return this;
-  MachineBasicBlock::reverse_instr_iterator MII(this);
-  ++MII;
-  while (MII->isInsideBundle())
-    ++MII;
-  return &*MII;
-}
-
 bool MachineInstr::isStackAligningInlineAsm() const {
   if (isInlineAsm()) {
     unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm();