Skip to content

Commit 7bd2be4

Browse files
committed
[SelectionDAG] Use Register and MCRegister. NFC
Add operators to Register to supporting adding an offset to get another Register.
1 parent 0301580 commit 7bd2be4

18 files changed

+75
-57
lines changed

llvm/include/llvm/CodeGen/FunctionLoweringInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ class FunctionLoweringInfo {
180180
/// be updated after processing the current basic block.
181181
/// TODO: This isn't per-function state, it's per-basic-block state. But
182182
/// there's no other convenient place for it to live right now.
183-
std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
183+
std::vector<std::pair<MachineInstr*, Register>> PHINodesToUpdate;
184184
unsigned OrigNumPHINodesToUpdate;
185185

186186
/// If the current MBB is a landing pad, the exception pointer and exception
187187
/// selector registers are copied into these virtual registers by
188188
/// SelectionDAGISel::PrepareEHLandingPad().
189-
unsigned ExceptionPointerVirtReg, ExceptionSelectorVirtReg;
189+
Register ExceptionPointerVirtReg, ExceptionSelectorVirtReg;
190190

191191
/// The current call site index being processed, if any. 0 if none.
192192
unsigned CurCallSite = 0;

llvm/include/llvm/CodeGen/Register.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ class Register {
134134
constexpr bool operator!=(MCPhysReg Other) const {
135135
return Reg != unsigned(Other);
136136
}
137+
138+
/// Operators to move from one register to another nearby register by adding
139+
/// an offset.
140+
Register &operator++() {
141+
assert(isValid());
142+
++Reg;
143+
return *this;
144+
}
145+
146+
Register operator++(int) {
147+
Register R(*this);
148+
++(*this);
149+
return R;
150+
}
151+
152+
Register &operator+=(unsigned RHS) {
153+
assert(isValid());
154+
Reg += RHS;
155+
return *this;
156+
}
137157
};
138158

139159
// Provide DenseMapInfo for Register

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ class SelectionDAG {
17671767

17681768
/// Creates a VReg SDDbgValue node.
17691769
SDDbgValue *getVRegDbgValue(DIVariable *Var, DIExpression *Expr,
1770-
unsigned VReg, bool IsIndirect,
1770+
Register VReg, bool IsIndirect,
17711771
const DebugLoc &DL, unsigned O);
17721772

17731773
/// Creates a SDDbgValue node from a list of locations.

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4523,7 +4523,7 @@ class TargetLowering : public TargetLoweringBase {
45234523
virtual bool checkForPhysRegDependency(SDNode *Def, SDNode *User, unsigned Op,
45244524
const TargetRegisterInfo *TRI,
45254525
const TargetInstrInfo *TII,
4526-
unsigned &PhysReg, int &Cost) const {
4526+
MCRegister &PhysReg, int &Cost) const {
45274527
return false;
45284528
}
45294529

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ bool FastISel::handlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB) {
23042304
FuncInfo.PHINodesToUpdate.resize(FuncInfo.OrigNumPHINodesToUpdate);
23052305
return false;
23062306
}
2307-
FuncInfo.PHINodesToUpdate.push_back(std::make_pair(&*MBBI++, Reg));
2307+
FuncInfo.PHINodesToUpdate.emplace_back(&*MBBI++, Reg);
23082308
MIMD = {};
23092309
}
23102310
}

llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
295295
continue;
296296

297297
DebugLoc DL = PN.getDebugLoc();
298-
unsigned PHIReg = ValueMap[&PN];
298+
Register PHIReg = ValueMap[&PN];
299299
assert(PHIReg && "PHI node does not have an assigned virtual register!");
300300

301301
SmallVector<EVT, 4> ValueVTs;
@@ -578,7 +578,7 @@ FunctionLoweringInfo::getValueFromVirtualReg(Register Vreg) {
578578
ValueVTs.clear();
579579
ComputeValueVTs(*TLI, Fn->getDataLayout(),
580580
P.first->getType(), ValueVTs);
581-
unsigned Reg = P.second;
581+
Register Reg = P.second;
582582
for (EVT VT : ValueVTs) {
583583
unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
584584
for (unsigned i = 0, e = NumRegisters; i != e; ++i)

llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ InstrEmitter::EmitDbgInstrRef(SDDbgValue *SD,
827827
//
828828
// i.e., point the instruction at the vreg, and patch it up later in
829829
// MachineFunction::finalizeDebugInstrRefs.
830-
auto AddVRegOp = [&](unsigned VReg) {
830+
auto AddVRegOp = [&](Register VReg) {
831831
MOs.push_back(MachineOperand::CreateReg(
832832
/* Reg */ VReg, /* isDef */ false, /* isImp */ false,
833833
/* isKill */ false, /* isDead */ false,
@@ -840,7 +840,7 @@ InstrEmitter::EmitDbgInstrRef(SDDbgValue *SD,
840840

841841
// Try to find both the defined register and the instruction defining it.
842842
MachineInstr *DefMI = nullptr;
843-
unsigned VReg;
843+
Register VReg;
844844

845845
if (DbgOperand.getKind() == SDDbgOperand::VREG) {
846846
VReg = DbgOperand.getVReg();

llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
1414
#define LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
1515

16+
#include "llvm/CodeGen/Register.h"
1617
#include "llvm/IR/DebugLoc.h"
1718
#include "llvm/Support/Allocator.h"
1819
#include "llvm/Support/DataTypes.h"
@@ -63,7 +64,7 @@ class SDDbgOperand {
6364
}
6465

6566
/// Returns the Virtual Register for a VReg
66-
unsigned getVReg() const {
67+
Register getVReg() const {
6768
assert(kind == VREG);
6869
return u.VReg;
6970
}
@@ -74,8 +75,8 @@ class SDDbgOperand {
7475
static SDDbgOperand fromFrameIdx(unsigned FrameIdx) {
7576
return SDDbgOperand(FrameIdx, FRAMEIX);
7677
}
77-
static SDDbgOperand fromVReg(unsigned VReg) {
78-
return SDDbgOperand(VReg, VREG);
78+
static SDDbgOperand fromVReg(Register VReg) {
79+
return SDDbgOperand(VReg.id(), VREG);
7980
}
8081
static SDDbgOperand fromConst(const Value *Const) {
8182
return SDDbgOperand(Const);

llvm/lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static MVT getPhysicalRegisterVT(SDNode *N, unsigned Reg,
436436

437437
/// CheckForLiveRegDef - Return true and update live register vector if the
438438
/// specified register def of the specified SUnit clobbers any "live" registers.
439-
static bool CheckForLiveRegDef(SUnit *SU, unsigned Reg,
439+
static bool CheckForLiveRegDef(SUnit *SU, MCRegister Reg,
440440
std::vector<SUnit *> &LiveRegDefs,
441441
SmallSet<unsigned, 4> &RegAdded,
442442
SmallVectorImpl<unsigned> &LRegs,
@@ -501,8 +501,8 @@ bool ScheduleDAGFast::DelayForLiveRegsBottomUp(SUnit *SU,
501501
F.isClobberKind()) {
502502
// Check for def of register or earlyclobber register.
503503
for (; NumVals; --NumVals, ++i) {
504-
unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
505-
if (Register::isPhysicalRegister(Reg))
504+
Register Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
505+
if (Reg.isPhysical())
506506
CheckForLiveRegDef(SU, Reg, LiveRegDefs, RegAdded, LRegs, TRI);
507507
}
508508
} else

llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ static MVT getPhysicalRegisterVT(SDNode *N, unsigned Reg,
12921292

12931293
/// CheckForLiveRegDef - Return true and update live register vector if the
12941294
/// specified register def of the specified SUnit clobbers any "live" registers.
1295-
static void CheckForLiveRegDef(SUnit *SU, unsigned Reg, SUnit **LiveRegDefs,
1295+
static void CheckForLiveRegDef(SUnit *SU, MCRegister Reg, SUnit **LiveRegDefs,
12961296
SmallSet<unsigned, 4> &RegAdded,
12971297
SmallVectorImpl<unsigned> &LRegs,
12981298
const TargetRegisterInfo *TRI,

0 commit comments

Comments
 (0)