Index: src/IceRegAlloc.cpp |
diff --git a/src/IceRegAlloc.cpp b/src/IceRegAlloc.cpp |
index ced9af5474d8f193078018285ef278f76d630089..59c65f27817d799d9cdc9e05c945ad6255d33608 100644 |
--- a/src/IceRegAlloc.cpp |
+++ b/src/IceRegAlloc.cpp |
@@ -70,7 +70,8 @@ void dumpLiveRange(const Variable *Var, const Cfg *Func) { |
return; |
Ostream &Str = Func->getContext()->getStrDump(); |
char buf[30]; |
- snprintf(buf, llvm::array_lengthof(buf), "%2d", Var->getRegNumTmp()); |
+ snprintf(buf, llvm::array_lengthof(buf), "%2u", |
+ unsigned(Var->getRegNumTmp())); |
Str << "R=" << buf << " V="; |
Var->dump(Func); |
Str << " Range=" << Var->getLiveRange(); |
@@ -79,9 +80,9 @@ void dumpLiveRange(const Variable *Var, const Cfg *Func) { |
int32_t findMinWeightIndex( |
const llvm::SmallBitVector &RegMask, |
const llvm::SmallVector<RegWeight, LinearScan::REGS_SIZE> &Weights) { |
- int32_t MinWeightIndex = RegMask.find_first(); |
+ int MinWeightIndex = RegMask.find_first(); |
assert(MinWeightIndex >= 0); |
- for (int32_t i = RegMask.find_next(MinWeightIndex); i != -1; |
+ for (int i = RegMask.find_next(MinWeightIndex); i != -1; |
i = RegMask.find_next(i)) { |
if (Weights[i] < Weights[MinWeightIndex]) |
MinWeightIndex = i; |
@@ -414,7 +415,7 @@ void LinearScan::addSpillFill(IterationState &Iter) { |
if (!Var->hasRegTmp()) |
continue; |
const llvm::SmallBitVector &Aliases = *RegAliases[Var->getRegNumTmp()]; |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
Iter.RegMask[RegAlias] = false; |
} |
@@ -425,7 +426,7 @@ void LinearScan::addSpillFill(IterationState &Iter) { |
assert(FillPoint != Insts.end()); |
++FillPoint; |
// TODO(stichnot): Randomize instead of find_first(). |
- int32_t RegNum = Iter.RegMask.find_first(); |
+ int RegNum = Iter.RegMask.find_first(); |
assert(RegNum != -1); |
Iter.Cur->setRegNumTmp(RegNum); |
Variable *Preg = Target->getPhysicalRegister(RegNum, Iter.Cur->getType()); |
@@ -461,7 +462,7 @@ void LinearScan::handleActiveRangeExpiredOrInactive(const Variable *Cur) { |
// Decrement Item from RegUses[]. |
assert(Item->hasRegTmp()); |
const llvm::SmallBitVector &Aliases = *RegAliases[Item->getRegNumTmp()]; |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
--RegUses[RegAlias]; |
assert(RegUses[RegAlias] >= 0); |
@@ -486,7 +487,7 @@ void LinearScan::handleInactiveRangeExpiredOrReactivated(const Variable *Cur) { |
// Increment Item in RegUses[]. |
assert(Item->hasRegTmp()); |
const llvm::SmallBitVector &Aliases = *RegAliases[Item->getRegNumTmp()]; |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
assert(RegUses[RegAlias] >= 0); |
++RegUses[RegAlias]; |
@@ -506,7 +507,7 @@ void LinearScan::handleInactiveRangeExpiredOrReactivated(const Variable *Cur) { |
// not appear within the current Variable's live range. |
void LinearScan::findRegisterPreference(IterationState &Iter) { |
Iter.Prefer = nullptr; |
- Iter.PreferReg = Variable::NoRegister; |
+ Iter.PreferReg = RegNumT::NoRegister; |
Iter.AllowOverlap = false; |
if (!FindPreference) |
@@ -529,7 +530,7 @@ void LinearScan::findRegisterPreference(IterationState &Iter) { |
// That register must be one in the RegMask set, e.g. don't try to prefer |
// the stack pointer as a result of the stacksave intrinsic. |
const llvm::SmallBitVector &Aliases = *RegAliases[SrcVar->getRegNumTmp()]; |
- const int32_t SrcReg = (Iter.RegMask & Aliases).find_first(); |
+ const int SrcReg = (Iter.RegMask & Aliases).find_first(); |
if (SrcReg == -1) |
continue; |
@@ -567,7 +568,7 @@ void LinearScan::filterFreeWithInactiveRanges(IterationState &Iter) { |
continue; |
const llvm::SmallBitVector &Aliases = *RegAliases[Item->getRegNumTmp()]; |
// TODO(stichnot): Do this with bitvector ops, not a loop, for efficiency. |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
// Don't assert(Iter.Free[RegNum]) because in theory (though probably |
// never in practice) there could be two inactive variables that were |
@@ -577,7 +578,8 @@ void LinearScan::filterFreeWithInactiveRanges(IterationState &Iter) { |
// Disable AllowOverlap if an Inactive variable, which is not Prefer, |
// shares Prefer's register, and has a definition within Cur's live range. |
if (Iter.AllowOverlap && Item != Iter.Prefer && |
- RegAlias == Iter.PreferReg && overlapsDefs(Func, Iter.Cur, Item)) { |
+ RegNumT(RegAlias) == Iter.PreferReg && |
+ overlapsDefs(Func, Iter.Cur, Item)) { |
Iter.AllowOverlap = false; |
dumpDisableOverlap(Func, Item, "Inactive"); |
} |
@@ -601,7 +603,7 @@ void LinearScan::filterFreeWithPrecoloredRanges(IterationState &Iter) { |
continue; |
const llvm::SmallBitVector &Aliases = |
*RegAliases[Item->getRegNum()]; // Note: not getRegNumTmp() |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
Iter.Weights[RegAlias].setWeight(RegWeight::Inf); |
Iter.Free[RegAlias] = false; |
@@ -609,7 +611,7 @@ void LinearScan::filterFreeWithPrecoloredRanges(IterationState &Iter) { |
Iter.PrecoloredUnhandledMask[RegAlias] = true; |
// Disable Iter.AllowOverlap if the preferred register is one of these |
// pre-colored unhandled overlapping ranges. |
- if (Iter.AllowOverlap && RegAlias == Iter.PreferReg) { |
+ if (Iter.AllowOverlap && RegNumT(RegAlias) == Iter.PreferReg) { |
Iter.AllowOverlap = false; |
dumpDisableOverlap(Func, Item, "PrecoloredUnhandled"); |
} |
@@ -618,13 +620,13 @@ void LinearScan::filterFreeWithPrecoloredRanges(IterationState &Iter) { |
} |
void LinearScan::allocatePrecoloredRegister(Variable *Cur) { |
- int32_t RegNum = Cur->getRegNum(); |
+ RegNumT RegNum = Cur->getRegNum(); |
// RegNumTmp should have already been set above. |
assert(Cur->getRegNumTmp() == RegNum); |
dumpLiveRangeTrace("Precoloring ", Cur); |
Active.push_back(Cur); |
const llvm::SmallBitVector &Aliases = *RegAliases[RegNum]; |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
assert(RegUses[RegAlias] >= 0); |
++RegUses[RegAlias]; |
@@ -638,7 +640,7 @@ void LinearScan::allocatePreferredRegister(IterationState &Iter) { |
Iter.Cur->setRegNumTmp(Iter.PreferReg); |
dumpLiveRangeTrace("Preferring ", Iter.Cur); |
const llvm::SmallBitVector &Aliases = *RegAliases[Iter.PreferReg]; |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
assert(RegUses[RegAlias] >= 0); |
++RegUses[RegAlias]; |
@@ -647,7 +649,7 @@ void LinearScan::allocatePreferredRegister(IterationState &Iter) { |
} |
void LinearScan::allocateFreeRegister(IterationState &Iter, bool Filtered) { |
- const int32_t RegNum = |
+ const RegNumT RegNum = |
Filtered ? Iter.Free.find_first() : Iter.FreeUnfiltered.find_first(); |
Iter.Cur->setRegNumTmp(RegNum); |
if (Filtered) |
@@ -655,7 +657,7 @@ void LinearScan::allocateFreeRegister(IterationState &Iter, bool Filtered) { |
else |
dumpLiveRangeTrace("Allocating X ", Iter.Cur); |
const llvm::SmallBitVector &Aliases = *RegAliases[RegNum]; |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
assert(RegUses[RegAlias] >= 0); |
++RegUses[RegAlias]; |
@@ -673,7 +675,7 @@ void LinearScan::handleNoFreeRegisters(IterationState &Iter) { |
// should we decide to pick any of them, then we would incur that many |
// memory accesses. |
RegWeight W = Item->getWeight(Func); |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
Iter.Weights[RegAlias].addWeight(W); |
} |
@@ -685,7 +687,7 @@ void LinearScan::handleNoFreeRegisters(IterationState &Iter) { |
assert(Item->hasRegTmp()); |
const llvm::SmallBitVector &Aliases = *RegAliases[Item->getRegNumTmp()]; |
RegWeight W = Item->getWeight(Func); |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
Iter.Weights[RegAlias].addWeight(W); |
} |
@@ -742,16 +744,16 @@ void LinearScan::handleNoFreeRegisters(IterationState &Iter) { |
for (SizeT I = Active.size(); I > 0; --I) { |
const SizeT Index = I - 1; |
Variable *Item = Active[Index]; |
- int32_t RegNum = Item->getRegNumTmp(); |
+ RegNumT RegNum = Item->getRegNumTmp(); |
if (Aliases[RegNum]) { |
dumpLiveRangeTrace("Evicting A ", Item); |
const llvm::SmallBitVector &Aliases = *RegAliases[RegNum]; |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
--RegUses[RegAlias]; |
assert(RegUses[RegAlias] >= 0); |
} |
- Item->setRegNumTmp(Variable::NoRegister); |
+ Item->setRegNumTmp(RegNumT::NoRegister); |
moveItem(Active, Index, Handled); |
Evicted.push_back(Item); |
} |
@@ -769,14 +771,14 @@ void LinearScan::handleNoFreeRegisters(IterationState &Iter) { |
// instructions. |
if (Aliases[Item->getRegNumTmp()] && Item->rangeOverlaps(Iter.Cur)) { |
dumpLiveRangeTrace("Evicting I ", Item); |
- Item->setRegNumTmp(Variable::NoRegister); |
+ Item->setRegNumTmp(RegNumT::NoRegister); |
moveItem(Inactive, Index, Handled); |
Evicted.push_back(Item); |
} |
} |
// Assign the register to Cur. |
Iter.Cur->setRegNumTmp(MinWeightIndex); |
- for (int32_t RegAlias = Aliases.find_first(); RegAlias >= 0; |
+ for (int RegAlias = Aliases.find_first(); RegAlias >= 0; |
RegAlias = Aliases.find_next(RegAlias)) { |
assert(RegUses[RegAlias] >= 0); |
++RegUses[RegAlias]; |
@@ -789,7 +791,7 @@ void LinearScan::assignFinalRegisters( |
const llvm::SmallBitVector &RegMaskFull, |
const llvm::SmallBitVector &PreDefinedRegisters, bool Randomized) { |
const size_t NumRegisters = RegMaskFull.size(); |
- llvm::SmallVector<int32_t, REGS_SIZE> Permutation(NumRegisters); |
+ llvm::SmallVector<RegNumT, REGS_SIZE> Permutation(NumRegisters); |
if (Randomized) { |
// Create a random number generator for regalloc randomization. Merge |
// function's sequence and Kind value as the Salt. Because regAlloc() is |
@@ -805,8 +807,8 @@ void LinearScan::assignFinalRegisters( |
// Finish up by setting RegNum = RegNumTmp (or a random permutation thereof) |
// for each Variable. |
for (Variable *Item : Handled) { |
- int32_t RegNum = Item->getRegNumTmp(); |
- int32_t AssignedRegNum = RegNum; |
+ RegNumT RegNum = Item->getRegNumTmp(); |
+ RegNumT AssignedRegNum = RegNum; |
if (Randomized && Item->hasRegTmp() && !Item->hasReg()) { |
AssignedRegNum = Permutation[RegNum]; |
@@ -917,7 +919,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull, |
if (Iter.AllowOverlap) { |
const llvm::SmallBitVector &Aliases = *RegAliases[Iter.PreferReg]; |
for (const Variable *Item : Active) { |
- int32_t RegNum = Item->getRegNumTmp(); |
+ RegNumT RegNum = Item->getRegNumTmp(); |
if (Item != Iter.Prefer && Aliases[RegNum] && |
overlapsDefs(Func, Iter.Cur, Item)) { |
Iter.AllowOverlap = false; |
@@ -943,7 +945,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull, |
for (int i = KillsMask.find_first(); i != -1; |
i = KillsMask.find_next(i)) { |
Iter.Weights[i].setWeight(RegWeight::Inf); |
- if (Iter.PreferReg == i) |
+ if (Iter.PreferReg == RegNumT(i)) |
Iter.AllowOverlap = false; |
} |
} |
@@ -951,12 +953,11 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull, |
// Print info about physical register availability. |
if (BuildDefs::dump() && Verbose) { |
Ostream &Str = Ctx->getStrDump(); |
- for (SizeT i = 0; i < Iter.RegMask.size(); ++i) { |
- if (Iter.RegMaskUnfiltered[i]) { |
- Str << Target->getRegName(i, Iter.Cur->getType()) |
- << "(U=" << RegUses[i] << ",F=" << Iter.Free[i] |
- << ",P=" << Iter.PrecoloredUnhandledMask[i] << ") "; |
- } |
+ for (int i = Iter.RegMaskUnfiltered.find_first(); i != -1; |
+ i = Iter.RegMaskUnfiltered.find_next(i)) { |
Eric Holk
2016/02/08 19:37:09
A lot of the changes in this file seem kind of ind
Jim Stichnoth
2016/02/09 19:33:39
True - while tracking down all the changes, I also
Eric Holk
2016/02/10 01:11:30
Yeah, that's fine with me. It's a pain to split up
|
+ Str << Target->getRegName(i, Iter.Cur->getType()) << "(U=" << RegUses[i] |
+ << ",F=" << Iter.Free[i] << ",P=" << Iter.PrecoloredUnhandledMask[i] |
+ << ") "; |
} |
Str << "\n"; |
} |