[StackMap] Rename variables to be more consistent. NFC.

Rename a few variables and use auto for long iterator names.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241822 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Juergen Ributzka 2015-07-09 17:11:11 +00:00
parent 9ba87b84ab
commit fd5ef9d20c
2 changed files with 50 additions and 50 deletions

View File

@ -138,29 +138,31 @@ public:
Constant, Constant,
ConstantIndex ConstantIndex
}; };
LocationType LocType; LocationType Type;
unsigned Size; unsigned Size;
unsigned Reg; unsigned Reg;
int64_t Offset; int64_t Offset;
Location() : LocType(Unprocessed), Size(0), Reg(0), Offset(0) {} Location() : Type(Unprocessed), Size(0), Reg(0), Offset(0) {}
Location(LocationType LocType, unsigned Size, unsigned Reg, int64_t Offset) Location(LocationType Type, unsigned Size, unsigned Reg, int64_t Offset)
: LocType(LocType), Size(Size), Reg(Reg), Offset(Offset) {} : Type(Type), Size(Size), Reg(Reg), Offset(Offset) {}
}; };
struct LiveOutReg { struct LiveOutReg {
unsigned short Reg; unsigned short Reg;
unsigned short RegNo; unsigned short DwarfRegNum;
unsigned short Size; unsigned short Size;
LiveOutReg() : Reg(0), RegNo(0), Size(0) {}
LiveOutReg(unsigned short Reg, unsigned short RegNo, unsigned short Size)
: Reg(Reg), RegNo(RegNo), Size(Size) {}
void MarkInvalid() { Reg = 0; } void MarkInvalid() { Reg = 0; }
// Only sort by the dwarf register number. // Only sort by the dwarf register number.
bool operator<(const LiveOutReg &LO) const { return RegNo < LO.RegNo; } bool operator<(const LiveOutReg &LO) const {
return DwarfRegNum < LO.DwarfRegNum;
}
static bool IsInvalid(const LiveOutReg &LO) { return LO.Reg == 0; } static bool IsInvalid(const LiveOutReg &LO) { return LO.Reg == 0; }
LiveOutReg() : Reg(0), DwarfRegNum(0), Size(0) {}
LiveOutReg(unsigned short Reg, unsigned short DwarfRegNum,
unsigned short Size)
: Reg(Reg), DwarfRegNum(DwarfRegNum), Size(Size) {}
}; };
// OpTypes are used to encode information about the following logical // OpTypes are used to encode information about the following logical

View File

@ -76,12 +76,12 @@ StackMaps::StackMaps(AsmPrinter &AP) : AP(AP) {
/// Go up the super-register chain until we hit a valid dwarf register number. /// Go up the super-register chain until we hit a valid dwarf register number.
static unsigned getDwarfRegNum(unsigned Reg, const TargetRegisterInfo *TRI) { static unsigned getDwarfRegNum(unsigned Reg, const TargetRegisterInfo *TRI) {
int RegNo = TRI->getDwarfRegNum(Reg, false); int RegNum = TRI->getDwarfRegNum(Reg, false);
for (MCSuperRegIterator SR(Reg, TRI); SR.isValid() && RegNo < 0; ++SR) for (MCSuperRegIterator SR(Reg, TRI); SR.isValid() && RegNum < 0; ++SR)
RegNo = TRI->getDwarfRegNum(*SR, false); RegNum = TRI->getDwarfRegNum(*SR, false);
assert(RegNo >= 0 && "Invalid Dwarf register number."); assert(RegNum >= 0 && "Invalid Dwarf register number.");
return (unsigned)RegNo; return (unsigned)RegNum;
} }
MachineInstr::const_mop_iterator MachineInstr::const_mop_iterator
@ -138,13 +138,13 @@ StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI,
assert(!MOI->getSubReg() && "Physical subreg still around."); assert(!MOI->getSubReg() && "Physical subreg still around.");
unsigned Offset = 0; unsigned Offset = 0;
unsigned RegNo = getDwarfRegNum(MOI->getReg(), TRI); unsigned DwarfRegNum = getDwarfRegNum(MOI->getReg(), TRI);
unsigned LLVMRegNo = TRI->getLLVMRegNum(RegNo, false); unsigned LLVMRegNum = TRI->getLLVMRegNum(DwarfRegNum, false);
unsigned SubRegIdx = TRI->getSubRegIndex(LLVMRegNo, MOI->getReg()); unsigned SubRegIdx = TRI->getSubRegIndex(LLVMRegNum, MOI->getReg());
if (SubRegIdx) if (SubRegIdx)
Offset = TRI->getSubRegIdxOffset(SubRegIdx); Offset = TRI->getSubRegIdxOffset(SubRegIdx);
Locs.push_back(Location(Location::Register, RC->getSize(), RegNo, Offset)); Locs.emplace_back(Location::Register, RC->getSize(), DwarfRegNum, Offset);
return ++MOI; return ++MOI;
} }
@ -165,10 +165,10 @@ void StackMaps::print(raw_ostream &OS) {
OS << WSMP << "callsite " << CSI.ID << "\n"; OS << WSMP << "callsite " << CSI.ID << "\n";
OS << WSMP << " has " << CSLocs.size() << " locations\n"; OS << WSMP << " has " << CSLocs.size() << " locations\n";
unsigned OperIdx = 0; unsigned Idx = 0;
for (const auto &Loc : CSLocs) { for (const auto &Loc : CSLocs) {
OS << WSMP << " Loc " << OperIdx << ": "; OS << WSMP << "\t\tLoc " << Idx << ": ";
switch (Loc.LocType) { switch (Loc.Type) {
case Location::Unprocessed: case Location::Unprocessed:
OS << "<Unprocessed operand>"; OS << "<Unprocessed operand>";
break; break;
@ -203,23 +203,23 @@ void StackMaps::print(raw_ostream &OS) {
OS << "Constant Index " << Loc.Offset; OS << "Constant Index " << Loc.Offset;
break; break;
} }
OS << " [encoding: .byte " << Loc.LocType << ", .byte " << Loc.Size OS << "\t[encoding: .byte " << Loc.Type << ", .byte " << Loc.Size
<< ", .short " << Loc.Reg << ", .int " << Loc.Offset << "]\n"; << ", .short " << Loc.Reg << ", .int " << Loc.Offset << "]\n";
OperIdx++; Idx++;
} }
OS << WSMP << " has " << LiveOuts.size() << " live-out registers\n"; OS << WSMP << "\thas " << LiveOuts.size() << " live-out registers\n";
OperIdx = 0; Idx = 0;
for (const auto &LO : LiveOuts) { for (const auto &LO : LiveOuts) {
OS << WSMP << " LO " << OperIdx << ": "; OS << WSMP << "\t\tLO " << Idx << ": ";
if (TRI) if (TRI)
OS << TRI->getName(LO.Reg); OS << TRI->getName(LO.Reg);
else else
OS << LO.Reg; OS << LO.Reg;
OS << " [encoding: .short " << LO.RegNo << ", .byte 0, .byte " OS << "\t[encoding: .short " << LO.DwarfRegNum << ", .byte 0, .byte "
<< LO.Size << "]\n"; << LO.Size << "]\n";
OperIdx++; Idx++;
} }
} }
} }
@ -227,9 +227,9 @@ void StackMaps::print(raw_ostream &OS) {
/// Create a live-out register record for the given register Reg. /// Create a live-out register record for the given register Reg.
StackMaps::LiveOutReg StackMaps::LiveOutReg
StackMaps::createLiveOutReg(unsigned Reg, const TargetRegisterInfo *TRI) const { StackMaps::createLiveOutReg(unsigned Reg, const TargetRegisterInfo *TRI) const {
unsigned RegNo = getDwarfRegNum(Reg, TRI); unsigned DwarfRegNum = getDwarfRegNum(Reg, TRI);
unsigned Size = TRI->getMinimalPhysRegClass(Reg)->getSize(); unsigned Size = TRI->getMinimalPhysRegClass(Reg)->getSize();
return LiveOutReg(Reg, RegNo, Size); return LiveOutReg(Reg, DwarfRegNum, Size);
} }
/// Parse the register live-out mask and return a vector of live-out registers /// Parse the register live-out mask and return a vector of live-out registers
@ -252,7 +252,7 @@ StackMaps::parseRegisterLiveOutMask(const uint32_t *Mask) const {
for (LiveOutVec::iterator I = LiveOuts.begin(), E = LiveOuts.end(); I != E; for (LiveOutVec::iterator I = LiveOuts.begin(), E = LiveOuts.end(); I != E;
++I) { ++I) {
for (LiveOutVec::iterator II = std::next(I); II != E; ++II) { for (LiveOutVec::iterator II = std::next(I); II != E; ++II) {
if (I->RegNo != II->RegNo) { if (I->DwarfRegNum != II->DwarfRegNum) {
// Skip all the now invalid entries. // Skip all the now invalid entries.
I = --II; I = --II;
break; break;
@ -293,24 +293,23 @@ void StackMaps::recordStackMapOpers(const MachineInstr &MI, uint64_t ID,
} }
// Move large constants into the constant pool. // Move large constants into the constant pool.
for (LocationVec::iterator I = Locations.begin(), E = Locations.end(); I != E; for (auto &Loc : Locations) {
++I) {
// Constants are encoded as sign-extended integers. // Constants are encoded as sign-extended integers.
// -1 is directly encoded as .long 0xFFFFFFFF with no constant pool. // -1 is directly encoded as .long 0xFFFFFFFF with no constant pool.
if (I->LocType == Location::Constant && !isInt<32>(I->Offset)) { if (Loc.Type == Location::Constant && !isInt<32>(Loc.Offset)) {
I->LocType = Location::ConstantIndex; Loc.Type = Location::ConstantIndex;
// ConstPool is intentionally a MapVector of 'uint64_t's (as // ConstPool is intentionally a MapVector of 'uint64_t's (as
// opposed to 'int64_t's). We should never be in a situation // opposed to 'int64_t's). We should never be in a situation
// where we have to insert either the tombstone or the empty // where we have to insert either the tombstone or the empty
// keys into a map, and for a DenseMap<uint64_t, T> these are // keys into a map, and for a DenseMap<uint64_t, T> these are
// (uint64_t)0 and (uint64_t)-1. They can be and are // (uint64_t)0 and (uint64_t)-1. They can be and are
// represented using 32 bit integers. // represented using 32 bit integers.
assert((uint64_t)Loc.Offset != DenseMapInfo<uint64_t>::getEmptyKey() &&
assert((uint64_t)I->Offset != DenseMapInfo<uint64_t>::getEmptyKey() && (uint64_t)Loc.Offset !=
(uint64_t)I->Offset != DenseMapInfo<uint64_t>::getTombstoneKey() && DenseMapInfo<uint64_t>::getTombstoneKey() &&
"empty and tombstone keys should fit in 32 bits!"); "empty and tombstone keys should fit in 32 bits!");
auto Result = ConstPool.insert(std::make_pair(I->Offset, I->Offset)); auto Result = ConstPool.insert(std::make_pair(Loc.Offset, Loc.Offset));
I->Offset = Result.first - ConstPool.begin(); Loc.Offset = Result.first - ConstPool.begin();
} }
} }
@ -326,10 +325,10 @@ void StackMaps::recordStackMapOpers(const MachineInstr &MI, uint64_t ID,
// Record the stack size of the current function. // Record the stack size of the current function.
const MachineFrameInfo *MFI = AP.MF->getFrameInfo(); const MachineFrameInfo *MFI = AP.MF->getFrameInfo();
const TargetRegisterInfo *RegInfo = AP.MF->getSubtarget().getRegisterInfo(); const TargetRegisterInfo *RegInfo = AP.MF->getSubtarget().getRegisterInfo();
const bool DynamicFrameSize = bool HasDynamicFrameSize =
MFI->hasVarSizedObjects() || RegInfo->needsStackRealignment(*(AP.MF)); MFI->hasVarSizedObjects() || RegInfo->needsStackRealignment(*(AP.MF));
FnStackSize[AP.CurrentFnSym] = FnStackSize[AP.CurrentFnSym] =
DynamicFrameSize ? UINT64_MAX : MFI->getStackSize(); HasDynamicFrameSize ? UINT64_MAX : MFI->getStackSize();
} }
void StackMaps::recordStackMap(const MachineInstr &MI) { void StackMaps::recordStackMap(const MachineInstr &MI) {
@ -346,18 +345,17 @@ void StackMaps::recordPatchPoint(const MachineInstr &MI) {
PatchPointOpers opers(&MI); PatchPointOpers opers(&MI);
int64_t ID = opers.getMetaOper(PatchPointOpers::IDPos).getImm(); int64_t ID = opers.getMetaOper(PatchPointOpers::IDPos).getImm();
MachineInstr::const_mop_iterator MOI = auto MOI = std::next(MI.operands_begin(), opers.getStackMapStartIdx());
std::next(MI.operands_begin(), opers.getStackMapStartIdx());
recordStackMapOpers(MI, ID, MOI, MI.operands_end(), recordStackMapOpers(MI, ID, MOI, MI.operands_end(),
opers.isAnyReg() && opers.hasDef()); opers.isAnyReg() && opers.hasDef());
#ifndef NDEBUG #ifndef NDEBUG
// verify anyregcc // verify anyregcc
LocationVec &Locations = CSInfos.back().Locations; auto &Locations = CSInfos.back().Locations;
if (opers.isAnyReg()) { if (opers.isAnyReg()) {
unsigned NArgs = opers.getMetaOper(PatchPointOpers::NArgPos).getImm(); unsigned NArgs = opers.getMetaOper(PatchPointOpers::NArgPos).getImm();
for (unsigned i = 0, e = (opers.hasDef() ? NArgs + 1 : NArgs); i != e; ++i) for (unsigned i = 0, e = (opers.hasDef() ? NArgs + 1 : NArgs); i != e; ++i)
assert(Locations[i].LocType == Location::Register && assert(Locations[i].Type == Location::Register &&
"anyreg arg must be in reg."); "anyreg arg must be in reg.");
} }
#endif #endif
@ -423,7 +421,7 @@ void StackMaps::emitFunctionFrameRecords(MCStreamer &OS) {
void StackMaps::emitConstantPoolEntries(MCStreamer &OS) { void StackMaps::emitConstantPoolEntries(MCStreamer &OS) {
// Constant pool entries. // Constant pool entries.
DEBUG(dbgs() << WSMP << "constants:\n"); DEBUG(dbgs() << WSMP << "constants:\n");
for (auto ConstEntry : ConstPool) { for (const auto &ConstEntry : ConstPool) {
DEBUG(dbgs() << WSMP << ConstEntry.second << '\n'); DEBUG(dbgs() << WSMP << ConstEntry.second << '\n');
OS.EmitIntValue(ConstEntry.second, 8); OS.EmitIntValue(ConstEntry.second, 8);
} }
@ -488,7 +486,7 @@ void StackMaps::emitCallsiteEntries(MCStreamer &OS) {
OS.EmitIntValue(CSLocs.size(), 2); OS.EmitIntValue(CSLocs.size(), 2);
for (const auto &Loc : CSLocs) { for (const auto &Loc : CSLocs) {
OS.EmitIntValue(Loc.LocType, 1); OS.EmitIntValue(Loc.Type, 1);
OS.EmitIntValue(Loc.Size, 1); OS.EmitIntValue(Loc.Size, 1);
OS.EmitIntValue(Loc.Reg, 2); OS.EmitIntValue(Loc.Reg, 2);
OS.EmitIntValue(Loc.Offset, 4); OS.EmitIntValue(Loc.Offset, 4);
@ -499,7 +497,7 @@ void StackMaps::emitCallsiteEntries(MCStreamer &OS) {
OS.EmitIntValue(LiveOuts.size(), 2); OS.EmitIntValue(LiveOuts.size(), 2);
for (const auto &LO : LiveOuts) { for (const auto &LO : LiveOuts) {
OS.EmitIntValue(LO.RegNo, 2); OS.EmitIntValue(LO.DwarfRegNum, 2);
OS.EmitIntValue(0, 1); OS.EmitIntValue(0, 1);
OS.EmitIntValue(LO.Size, 1); OS.EmitIntValue(LO.Size, 1);
} }