[llvm-commits] CVS: llvm/lib/CodeGen/RegAllocLocal.cpp PHIElimination.cpp MachineBasicBlock.cpp
Alkis Evlogimenos
alkis at niobe.cs.uiuc.edu
Mon Feb 23 12:15:45 PST 2004
Changes in directory llvm/lib/CodeGen:
RegAllocLocal.cpp updated: 1.56 -> 1.57
PHIElimination.cpp updated: 1.18 -> 1.19
MachineBasicBlock.cpp updated: 1.7 -> 1.8
---
Log message:
Refactor rewinding code for finding the first terminator of a basic
block into MachineBasicBlock::getFirstTerminator().
This also fixes a bug in the implementation of the above in both
RegAllocLocal and InstrSched, where instructions where added after the
terminator if the basic block's only instruction was a terminator (it
shouldn't matter for RegAllocLocal since this case never occurs in
practice).
---
Diffs of the changes: (+14 -21)
Index: llvm/lib/CodeGen/RegAllocLocal.cpp
diff -u llvm/lib/CodeGen/RegAllocLocal.cpp:1.56 llvm/lib/CodeGen/RegAllocLocal.cpp:1.57
--- llvm/lib/CodeGen/RegAllocLocal.cpp:1.56 Sun Feb 22 13:37:31 2004
+++ llvm/lib/CodeGen/RegAllocLocal.cpp Mon Feb 23 12:14:48 2004
@@ -649,11 +649,7 @@
}
}
- // Rewind the iterator to point to the first flow control instruction...
- const TargetInstrInfo &TII = TM->getInstrInfo();
- MI = MBB.end();
- while (MI != MBB.begin() && TII.isTerminatorInstr((--MI)->getOpcode()));
- if (MI != MBB.end()) ++MI;
+ MI = MBB.getFirstTerminator();
// Spill all physical registers holding virtual registers now.
for (unsigned i = 0, e = RegInfo->getNumRegs(); i != e; ++i)
Index: llvm/lib/CodeGen/PHIElimination.cpp
diff -u llvm/lib/CodeGen/PHIElimination.cpp:1.18 llvm/lib/CodeGen/PHIElimination.cpp:1.19
--- llvm/lib/CodeGen/PHIElimination.cpp:1.18 Fri Feb 13 19:18:34 2004
+++ llvm/lib/CodeGen/PHIElimination.cpp Mon Feb 23 12:14:48 2004
@@ -143,22 +143,7 @@
// source path the PHI.
MachineBasicBlock &opBlock = *MI->getOperand(i).getMachineBasicBlock();
- // Figure out where to insert the copy, which is at the end of the
- // predecessor basic block, but before any terminator/branch
- // instructions...
- MachineBasicBlock::iterator I = opBlock.end();
- if (I != opBlock.begin()) { // Handle empty blocks
- --I;
- // must backtrack over ALL the branches in the previous block
- while (MII.isTerminatorInstr(I->getOpcode()) &&
- I != opBlock.begin())
- --I;
-
- // move back to the first branch instruction so new instructions
- // are inserted right in front of it and not in front of a non-branch
- if (!MII.isTerminatorInstr(I->getOpcode()))
- ++I;
- }
+ MachineBasicBlock::iterator I = opBlock.getFirstTerminator();
// Check to make sure we haven't already emitted the copy for this block.
// This can happen because PHI nodes may have multiple entries for the
Index: llvm/lib/CodeGen/MachineBasicBlock.cpp
diff -u llvm/lib/CodeGen/MachineBasicBlock.cpp:1.7 llvm/lib/CodeGen/MachineBasicBlock.cpp:1.8
--- llvm/lib/CodeGen/MachineBasicBlock.cpp:1.7 Thu Feb 19 10:13:39 2004
+++ llvm/lib/CodeGen/MachineBasicBlock.cpp Mon Feb 23 12:14:48 2004
@@ -15,6 +15,8 @@
#include "llvm/BasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/Target/TargetMachine.h"
#include "Support/LeakDetector.h"
using namespace llvm;
@@ -54,6 +56,16 @@
if (parent != toList.parent)
for (; first != last; ++first)
first->parent = toList.parent;
+}
+
+MachineBasicBlock::iterator MachineBasicBlock::getFirstTerminator()
+{
+ const TargetInstrInfo& TII = MachineFunction::get(
+ getBasicBlock()->getParent()).getTarget().getInstrInfo();
+ iterator I = end();
+ while (I != begin() && TII.isTerminatorInstr((--I)->getOpcode()));
+ if (I != end() && !TII.isTerminatorInstr(I->getOpcode())) ++I;
+ return I;
}
void MachineBasicBlock::dump() const
More information about the llvm-commits
mailing list