aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/StackSlotColoring.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2009-05-04 00:24:50 +0000
committerEvan Cheng <evan.cheng@apple.com>2009-05-04 00:24:50 +0000
commit59a6e9b905b4843174cebe31324fad97926d74d5 (patch)
tree44a35d707e8b13bc7c9ae0bfe1924f81df874d66 /lib/CodeGen/StackSlotColoring.cpp
parent5e3ef11e85fa7208d4b08dea296680f93a46fbe0 (diff)
downloadexternal_llvm-59a6e9b905b4843174cebe31324fad97926d74d5.tar.gz
external_llvm-59a6e9b905b4843174cebe31324fad97926d74d5.tar.bz2
external_llvm-59a6e9b905b4843174cebe31324fad97926d74d5.zip
The stack slots which share the same stack slot after coloring can, but do not have to, use the same register. In fact, they each may have different register class requirements.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70815 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/StackSlotColoring.cpp')
-rw-r--r--lib/CodeGen/StackSlotColoring.cpp81
1 files changed, 37 insertions, 44 deletions
diff --git a/lib/CodeGen/StackSlotColoring.cpp b/lib/CodeGen/StackSlotColoring.cpp
index 6406b1cc25..dd36bdd604 100644
--- a/lib/CodeGen/StackSlotColoring.cpp
+++ b/lib/CodeGen/StackSlotColoring.cpp
@@ -232,61 +232,54 @@ StackSlotColoring::ColorSlotsWithFreeRegs(SmallVector<int, 16> &SlotMapping,
int SS = li->getStackSlotIndex();
if (!UsedColors[SS])
continue;
- // Get the largest common sub- register class of all the stack slots that
- // are colored to this stack slot.
- const TargetRegisterClass *RC = 0;
- for (unsigned j = 0, ee = RevMap[SS].size(); j != ee; ++j) {
- int RSS = RevMap[SS][j];
- const TargetRegisterClass *RRC = LS->getIntervalRegClass(RSS);
- if (!RC)
- RC = RRC;
- else
- RC = getCommonSubClass(RC, RRC);
- }
- // If it's not colored to another stack slot, try coloring it
- // to a "free" register.
- if (!RC)
- continue;
- unsigned Reg = VRM->getFirstUnusedRegister(RC);
- if (!Reg)
- continue;
- bool IsSafe = true;
+ // These slots allow to share the same registers.
+ bool AllColored = true;
+ SmallVector<unsigned, 4> ColoredRegs;
for (unsigned j = 0, ee = RevMap[SS].size(); j != ee; ++j) {
int RSS = RevMap[SS][j];
+ const TargetRegisterClass *RC = LS->getIntervalRegClass(RSS);
+ // If it's not colored to another stack slot, try coloring it
+ // to a "free" register.
+ if (!RC) {
+ AllColored = false;
+ continue;
+ }
+ unsigned Reg = VRM->getFirstUnusedRegister(RC);
+ if (!Reg) {
+ AllColored = false;
+ continue;
+ }
if (!AllMemRefsCanBeUnfolded(RSS)) {
- IsSafe = false;
- break;
+ AllColored = false;
+ continue;
+ } else {
+ DOUT << "Assigning fi#" << RSS << " to " << TRI->getName(Reg) << '\n';
+ ColoredRegs.push_back(Reg);
+ SlotMapping[RSS] = Reg;
+ SlotIsReg.set(RSS);
+ Changed = true;
}
}
- if (!IsSafe)
- // Try color the next spill slot.
- continue;
- DOUT << "Assigning fi#" << SS << " to " << TRI->getName(Reg)
- << ", which in turn means...\n";
// Register and its sub-registers are no longer free.
- VRM->setRegisterUsed(Reg);
- // If reg is a callee-saved register, it will have to be spilled in
- // the prologue.
- MRI->setPhysRegUsed(Reg);
- for (const unsigned *AS = TRI->getAliasSet(Reg); *AS; ++AS) {
- VRM->setRegisterUsed(*AS);
- MRI->setPhysRegUsed(*AS);
+ while (!ColoredRegs.empty()) {
+ unsigned Reg = ColoredRegs.back();
+ ColoredRegs.pop_back();
+ VRM->setRegisterUsed(Reg);
+ // If reg is a callee-saved register, it will have to be spilled in
+ // the prologue.
+ MRI->setPhysRegUsed(Reg);
+ for (const unsigned *AS = TRI->getAliasSet(Reg); *AS; ++AS) {
+ VRM->setRegisterUsed(*AS);
+ MRI->setPhysRegUsed(*AS);
+ }
}
// This spill slot is dead after the rewrites
- MFI->RemoveStackObject(SS);
-
- // Remember all these FI references will have to be unfolded.
- for (unsigned j = 0, ee = RevMap[SS].size(); j != ee; ++j) {
- int RSS = RevMap[SS][j];
- DOUT << " Assigning fi#" << RSS << " to " << TRI->getName(Reg) << '\n';
- SlotMapping[RSS] = Reg;
- SlotIsReg.set(RSS);
+ if (AllColored) {
+ MFI->RemoveStackObject(SS);
+ ++NumEliminated;
}
-
- ++NumEliminated;
- Changed = true;
}
DOUT << '\n';