Skip to content

Commit c42cc7f

Browse files
committed
CodeGen: Use Register in MachineSSAUpdater
1 parent d2e498b commit c42cc7f

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

llvm/include/llvm/CodeGen/MachineSSAUpdater.h

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

16+
#include "llvm/CodeGen/Register.h"
17+
1618
namespace llvm {
1719

1820
class MachineBasicBlock;
@@ -35,11 +37,11 @@ class MachineSSAUpdater {
3537
private:
3638
/// AvailableVals - This keeps track of which value to use on a per-block
3739
/// basis. When we insert PHI nodes, we keep track of them here.
38-
//typedef DenseMap<MachineBasicBlock*, unsigned > AvailableValsTy;
40+
//typedef DenseMap<MachineBasicBlock*, Register> AvailableValsTy;
3941
void *AV = nullptr;
4042

4143
/// VR - Current virtual register whose uses are being updated.
42-
unsigned VR;
44+
Register VR;
4345

4446
/// VRC - Register class of the current virtual register.
4547
const TargetRegisterClass *VRC;
@@ -62,19 +64,19 @@ class MachineSSAUpdater {
6264

6365
/// Initialize - Reset this object to get ready for a new set of SSA
6466
/// updates.
65-
void Initialize(unsigned V);
67+
void Initialize(Register V);
6668

6769
/// AddAvailableValue - Indicate that a rewritten value is available at the
6870
/// end of the specified block with the specified value.
69-
void AddAvailableValue(MachineBasicBlock *BB, unsigned V);
71+
void AddAvailableValue(MachineBasicBlock *BB, Register V);
7072

7173
/// HasValueForBlock - Return true if the MachineSSAUpdater already has a
7274
/// value for the specified block.
7375
bool HasValueForBlock(MachineBasicBlock *BB) const;
7476

7577
/// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
7678
/// live at the end of the specified block.
77-
unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB);
79+
Register GetValueAtEndOfBlock(MachineBasicBlock *BB);
7880

7981
/// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
8082
/// is live in the middle of the specified block.
@@ -94,7 +96,7 @@ class MachineSSAUpdater {
9496
/// their respective blocks. However, the use of X happens in the *middle* of
9597
/// a block. Because of this, we need to insert a new PHI node in SomeBB to
9698
/// merge the appropriate values, and this value isn't live out of the block.
97-
unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB);
99+
Register GetValueInMiddleOfBlock(MachineBasicBlock *BB);
98100

99101
/// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes,
100102
/// which use their value in the corresponding predecessor. Note that this
@@ -104,7 +106,7 @@ class MachineSSAUpdater {
104106
void RewriteUse(MachineOperand &U);
105107

106108
private:
107-
unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
109+
Register GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
108110
};
109111

110112
} // end namespace llvm

llvm/lib/CodeGen/MachineSSAUpdater.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using namespace llvm;
3434

3535
#define DEBUG_TYPE "machine-ssaupdater"
3636

37-
using AvailableValsTy = DenseMap<MachineBasicBlock *, unsigned>;
37+
using AvailableValsTy = DenseMap<MachineBasicBlock *, Register>;
3838

3939
static AvailableValsTy &getAvailableVals(void *AV) {
4040
return *static_cast<AvailableValsTy*>(AV);
@@ -51,7 +51,7 @@ MachineSSAUpdater::~MachineSSAUpdater() {
5151

5252
/// Initialize - Reset this object to get ready for a new set of SSA
5353
/// updates. ProtoValue is the value used to name PHI nodes.
54-
void MachineSSAUpdater::Initialize(unsigned V) {
54+
void MachineSSAUpdater::Initialize(Register V) {
5555
if (!AV)
5656
AV = new AvailableValsTy();
5757
else
@@ -69,25 +69,25 @@ bool MachineSSAUpdater::HasValueForBlock(MachineBasicBlock *BB) const {
6969

7070
/// AddAvailableValue - Indicate that a rewritten value is available in the
7171
/// specified block with the specified value.
72-
void MachineSSAUpdater::AddAvailableValue(MachineBasicBlock *BB, unsigned V) {
72+
void MachineSSAUpdater::AddAvailableValue(MachineBasicBlock *BB, Register V) {
7373
getAvailableVals(AV)[BB] = V;
7474
}
7575

7676
/// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
7777
/// live at the end of the specified block.
78-
unsigned MachineSSAUpdater::GetValueAtEndOfBlock(MachineBasicBlock *BB) {
78+
Register MachineSSAUpdater::GetValueAtEndOfBlock(MachineBasicBlock *BB) {
7979
return GetValueAtEndOfBlockInternal(BB);
8080
}
8181

8282
static
83-
unsigned LookForIdenticalPHI(MachineBasicBlock *BB,
84-
SmallVectorImpl<std::pair<MachineBasicBlock *, unsigned>> &PredValues) {
83+
Register LookForIdenticalPHI(MachineBasicBlock *BB,
84+
SmallVectorImpl<std::pair<MachineBasicBlock *, Register>> &PredValues) {
8585
if (BB->empty())
86-
return 0;
86+
return Register();
8787

8888
MachineBasicBlock::iterator I = BB->begin();
8989
if (!I->isPHI())
90-
return 0;
90+
return Register();
9191

9292
AvailableValsTy AVals;
9393
for (unsigned i = 0, e = PredValues.size(); i != e; ++i)
@@ -106,7 +106,7 @@ unsigned LookForIdenticalPHI(MachineBasicBlock *BB,
106106
return I->getOperand(0).getReg();
107107
++I;
108108
}
109-
return 0;
109+
return Register();
110110
}
111111

112112
/// InsertNewDef - Insert an empty PHI or IMPLICIT_DEF instruction which define
@@ -140,7 +140,7 @@ MachineInstrBuilder InsertNewDef(unsigned Opcode,
140140
/// their respective blocks. However, the use of X happens in the *middle* of
141141
/// a block. Because of this, we need to insert a new PHI node in SomeBB to
142142
/// merge the appropriate values, and this value isn't live out of the block.
143-
unsigned MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB) {
143+
Register MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB) {
144144
// If there is no definition of the renamed variable in this block, just use
145145
// GetValueAtEndOfBlock to do our work.
146146
if (!HasValueForBlock(BB))
@@ -157,30 +157,30 @@ unsigned MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB) {
157157

158158
// Otherwise, we have the hard case. Get the live-in values for each
159159
// predecessor.
160-
SmallVector<std::pair<MachineBasicBlock*, unsigned>, 8> PredValues;
161-
unsigned SingularValue = 0;
160+
SmallVector<std::pair<MachineBasicBlock*, Register>, 8> PredValues;
161+
Register SingularValue;
162162

163163
bool isFirstPred = true;
164164
for (MachineBasicBlock::pred_iterator PI = BB->pred_begin(),
165165
E = BB->pred_end(); PI != E; ++PI) {
166166
MachineBasicBlock *PredBB = *PI;
167-
unsigned PredVal = GetValueAtEndOfBlockInternal(PredBB);
167+
Register PredVal = GetValueAtEndOfBlockInternal(PredBB);
168168
PredValues.push_back(std::make_pair(PredBB, PredVal));
169169

170170
// Compute SingularValue.
171171
if (isFirstPred) {
172172
SingularValue = PredVal;
173173
isFirstPred = false;
174174
} else if (PredVal != SingularValue)
175-
SingularValue = 0;
175+
SingularValue = Register();
176176
}
177177

178178
// Otherwise, if all the merged values are the same, just use it.
179-
if (SingularValue != 0)
179+
if (SingularValue)
180180
return SingularValue;
181181

182182
// If an identical PHI is already in BB, just reuse it.
183-
unsigned DupPHI = LookForIdenticalPHI(BB, PredValues);
183+
Register DupPHI = LookForIdenticalPHI(BB, PredValues);
184184
if (DupPHI)
185185
return DupPHI;
186186

@@ -222,7 +222,7 @@ MachineBasicBlock *findCorrespondingPred(const MachineInstr *MI,
222222
/// which use their value in the corresponding predecessor.
223223
void MachineSSAUpdater::RewriteUse(MachineOperand &U) {
224224
MachineInstr *UseMI = U.getParent();
225-
unsigned NewVR = 0;
225+
Register NewVR;
226226
if (UseMI->isPHI()) {
227227
MachineBasicBlock *SourceBB = findCorrespondingPred(UseMI, &U);
228228
NewVR = GetValueAtEndOfBlockInternal(SourceBB);
@@ -241,7 +241,7 @@ template<>
241241
class SSAUpdaterTraits<MachineSSAUpdater> {
242242
public:
243243
using BlkT = MachineBasicBlock;
244-
using ValT = unsigned;
244+
using ValT = Register;
245245
using PhiT = MachineInstr;
246246
using BlkSucc_iterator = MachineBasicBlock::succ_iterator;
247247

@@ -288,7 +288,7 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
288288

289289
/// GetUndefVal - Create an IMPLICIT_DEF instruction with a new register.
290290
/// Add it into the specified block and return the register.
291-
static unsigned GetUndefVal(MachineBasicBlock *BB,
291+
static Register GetUndefVal(MachineBasicBlock *BB,
292292
MachineSSAUpdater *Updater) {
293293
// Insert an implicit_def to represent an undef value.
294294
MachineInstr *NewDef = InsertNewDef(TargetOpcode::IMPLICIT_DEF,
@@ -300,7 +300,7 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
300300

301301
/// CreateEmptyPHI - Create a PHI instruction that defines a new register.
302302
/// Add it into the specified block and return the register.
303-
static unsigned CreateEmptyPHI(MachineBasicBlock *BB, unsigned NumPreds,
303+
static Register CreateEmptyPHI(MachineBasicBlock *BB, unsigned NumPreds,
304304
MachineSSAUpdater *Updater) {
305305
MachineBasicBlock::iterator Loc = BB->empty() ? BB->end() : BB->begin();
306306
MachineInstr *PHI = InsertNewDef(TargetOpcode::PHI, BB, Loc,
@@ -311,7 +311,7 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
311311

312312
/// AddPHIOperand - Add the specified value as an operand of the PHI for
313313
/// the specified predecessor block.
314-
static void AddPHIOperand(MachineInstr *PHI, unsigned Val,
314+
static void AddPHIOperand(MachineInstr *PHI, Register Val,
315315
MachineBasicBlock *Pred) {
316316
MachineInstrBuilder(*Pred->getParent(), PHI).addReg(Val).addMBB(Pred);
317317
}
@@ -325,13 +325,13 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
325325

326326
/// ValueIsPHI - Check if the instruction that defines the specified register
327327
/// is a PHI instruction.
328-
static MachineInstr *ValueIsPHI(unsigned Val, MachineSSAUpdater *Updater) {
328+
static MachineInstr *ValueIsPHI(Register Val, MachineSSAUpdater *Updater) {
329329
return InstrIsPHI(Updater->MRI->getVRegDef(Val));
330330
}
331331

332332
/// ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source
333333
/// operands, i.e., it was just added.
334-
static MachineInstr *ValueIsNewPHI(unsigned Val, MachineSSAUpdater *Updater) {
334+
static MachineInstr *ValueIsNewPHI(Register Val, MachineSSAUpdater *Updater) {
335335
MachineInstr *PHI = ValueIsPHI(Val, Updater);
336336
if (PHI && PHI->getNumOperands() <= 1)
337337
return PHI;
@@ -340,7 +340,7 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
340340

341341
/// GetPHIValue - For the specified PHI instruction, return the register
342342
/// that it defines.
343-
static unsigned GetPHIValue(MachineInstr *PHI) {
343+
static Register GetPHIValue(MachineInstr *PHI) {
344344
return PHI->getOperand(0).getReg();
345345
}
346346
};
@@ -351,9 +351,9 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
351351
/// for the specified BB and if so, return it. If not, construct SSA form by
352352
/// first calculating the required placement of PHIs and then inserting new
353353
/// PHIs where needed.
354-
unsigned MachineSSAUpdater::GetValueAtEndOfBlockInternal(MachineBasicBlock *BB){
354+
Register MachineSSAUpdater::GetValueAtEndOfBlockInternal(MachineBasicBlock *BB){
355355
AvailableValsTy &AvailableVals = getAvailableVals(AV);
356-
if (unsigned V = AvailableVals[BB])
356+
if (Register V = AvailableVals[BB])
357357
return V;
358358

359359
SSAUpdaterImpl<MachineSSAUpdater> Impl(this, &AvailableVals, InsertedPHIs);

0 commit comments

Comments
 (0)