@@ -34,7 +34,7 @@ using namespace llvm;
34
34
35
35
#define DEBUG_TYPE " machine-ssaupdater"
36
36
37
- using AvailableValsTy = DenseMap<MachineBasicBlock *, unsigned >;
37
+ using AvailableValsTy = DenseMap<MachineBasicBlock *, Register >;
38
38
39
39
static AvailableValsTy &getAvailableVals (void *AV) {
40
40
return *static_cast <AvailableValsTy*>(AV);
@@ -51,7 +51,7 @@ MachineSSAUpdater::~MachineSSAUpdater() {
51
51
52
52
// / Initialize - Reset this object to get ready for a new set of SSA
53
53
// / updates. ProtoValue is the value used to name PHI nodes.
54
- void MachineSSAUpdater::Initialize (unsigned V) {
54
+ void MachineSSAUpdater::Initialize (Register V) {
55
55
if (!AV)
56
56
AV = new AvailableValsTy ();
57
57
else
@@ -69,25 +69,25 @@ bool MachineSSAUpdater::HasValueForBlock(MachineBasicBlock *BB) const {
69
69
70
70
// / AddAvailableValue - Indicate that a rewritten value is available in the
71
71
// / specified block with the specified value.
72
- void MachineSSAUpdater::AddAvailableValue (MachineBasicBlock *BB, unsigned V) {
72
+ void MachineSSAUpdater::AddAvailableValue (MachineBasicBlock *BB, Register V) {
73
73
getAvailableVals (AV)[BB] = V;
74
74
}
75
75
76
76
// / GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
77
77
// / live at the end of the specified block.
78
- unsigned MachineSSAUpdater::GetValueAtEndOfBlock (MachineBasicBlock *BB) {
78
+ Register MachineSSAUpdater::GetValueAtEndOfBlock (MachineBasicBlock *BB) {
79
79
return GetValueAtEndOfBlockInternal (BB);
80
80
}
81
81
82
82
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) {
85
85
if (BB->empty ())
86
- return 0 ;
86
+ return Register () ;
87
87
88
88
MachineBasicBlock::iterator I = BB->begin ();
89
89
if (!I->isPHI ())
90
- return 0 ;
90
+ return Register () ;
91
91
92
92
AvailableValsTy AVals;
93
93
for (unsigned i = 0 , e = PredValues.size (); i != e; ++i)
@@ -106,7 +106,7 @@ unsigned LookForIdenticalPHI(MachineBasicBlock *BB,
106
106
return I->getOperand (0 ).getReg ();
107
107
++I;
108
108
}
109
- return 0 ;
109
+ return Register () ;
110
110
}
111
111
112
112
// / InsertNewDef - Insert an empty PHI or IMPLICIT_DEF instruction which define
@@ -140,7 +140,7 @@ MachineInstrBuilder InsertNewDef(unsigned Opcode,
140
140
// / their respective blocks. However, the use of X happens in the *middle* of
141
141
// / a block. Because of this, we need to insert a new PHI node in SomeBB to
142
142
// / 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) {
144
144
// If there is no definition of the renamed variable in this block, just use
145
145
// GetValueAtEndOfBlock to do our work.
146
146
if (!HasValueForBlock (BB))
@@ -157,30 +157,30 @@ unsigned MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB) {
157
157
158
158
// Otherwise, we have the hard case. Get the live-in values for each
159
159
// predecessor.
160
- SmallVector<std::pair<MachineBasicBlock*, unsigned >, 8 > PredValues;
161
- unsigned SingularValue = 0 ;
160
+ SmallVector<std::pair<MachineBasicBlock*, Register >, 8 > PredValues;
161
+ Register SingularValue;
162
162
163
163
bool isFirstPred = true ;
164
164
for (MachineBasicBlock::pred_iterator PI = BB->pred_begin (),
165
165
E = BB->pred_end (); PI != E; ++PI) {
166
166
MachineBasicBlock *PredBB = *PI;
167
- unsigned PredVal = GetValueAtEndOfBlockInternal (PredBB);
167
+ Register PredVal = GetValueAtEndOfBlockInternal (PredBB);
168
168
PredValues.push_back (std::make_pair (PredBB, PredVal));
169
169
170
170
// Compute SingularValue.
171
171
if (isFirstPred) {
172
172
SingularValue = PredVal;
173
173
isFirstPred = false ;
174
174
} else if (PredVal != SingularValue)
175
- SingularValue = 0 ;
175
+ SingularValue = Register () ;
176
176
}
177
177
178
178
// Otherwise, if all the merged values are the same, just use it.
179
- if (SingularValue != 0 )
179
+ if (SingularValue)
180
180
return SingularValue;
181
181
182
182
// If an identical PHI is already in BB, just reuse it.
183
- unsigned DupPHI = LookForIdenticalPHI (BB, PredValues);
183
+ Register DupPHI = LookForIdenticalPHI (BB, PredValues);
184
184
if (DupPHI)
185
185
return DupPHI;
186
186
@@ -222,7 +222,7 @@ MachineBasicBlock *findCorrespondingPred(const MachineInstr *MI,
222
222
// / which use their value in the corresponding predecessor.
223
223
void MachineSSAUpdater::RewriteUse (MachineOperand &U) {
224
224
MachineInstr *UseMI = U.getParent ();
225
- unsigned NewVR = 0 ;
225
+ Register NewVR;
226
226
if (UseMI->isPHI ()) {
227
227
MachineBasicBlock *SourceBB = findCorrespondingPred (UseMI, &U);
228
228
NewVR = GetValueAtEndOfBlockInternal (SourceBB);
@@ -241,7 +241,7 @@ template<>
241
241
class SSAUpdaterTraits <MachineSSAUpdater> {
242
242
public:
243
243
using BlkT = MachineBasicBlock;
244
- using ValT = unsigned ;
244
+ using ValT = Register ;
245
245
using PhiT = MachineInstr;
246
246
using BlkSucc_iterator = MachineBasicBlock::succ_iterator;
247
247
@@ -288,7 +288,7 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
288
288
289
289
// / GetUndefVal - Create an IMPLICIT_DEF instruction with a new register.
290
290
// / Add it into the specified block and return the register.
291
- static unsigned GetUndefVal (MachineBasicBlock *BB,
291
+ static Register GetUndefVal (MachineBasicBlock *BB,
292
292
MachineSSAUpdater *Updater) {
293
293
// Insert an implicit_def to represent an undef value.
294
294
MachineInstr *NewDef = InsertNewDef (TargetOpcode::IMPLICIT_DEF,
@@ -300,7 +300,7 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
300
300
301
301
// / CreateEmptyPHI - Create a PHI instruction that defines a new register.
302
302
// / 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,
304
304
MachineSSAUpdater *Updater) {
305
305
MachineBasicBlock::iterator Loc = BB->empty () ? BB->end () : BB->begin ();
306
306
MachineInstr *PHI = InsertNewDef (TargetOpcode::PHI, BB, Loc,
@@ -311,7 +311,7 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
311
311
312
312
// / AddPHIOperand - Add the specified value as an operand of the PHI for
313
313
// / the specified predecessor block.
314
- static void AddPHIOperand (MachineInstr *PHI, unsigned Val,
314
+ static void AddPHIOperand (MachineInstr *PHI, Register Val,
315
315
MachineBasicBlock *Pred) {
316
316
MachineInstrBuilder (*Pred->getParent (), PHI).addReg (Val).addMBB (Pred);
317
317
}
@@ -325,13 +325,13 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
325
325
326
326
// / ValueIsPHI - Check if the instruction that defines the specified register
327
327
// / is a PHI instruction.
328
- static MachineInstr *ValueIsPHI (unsigned Val, MachineSSAUpdater *Updater) {
328
+ static MachineInstr *ValueIsPHI (Register Val, MachineSSAUpdater *Updater) {
329
329
return InstrIsPHI (Updater->MRI ->getVRegDef (Val));
330
330
}
331
331
332
332
// / ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source
333
333
// / operands, i.e., it was just added.
334
- static MachineInstr *ValueIsNewPHI (unsigned Val, MachineSSAUpdater *Updater) {
334
+ static MachineInstr *ValueIsNewPHI (Register Val, MachineSSAUpdater *Updater) {
335
335
MachineInstr *PHI = ValueIsPHI (Val, Updater);
336
336
if (PHI && PHI->getNumOperands () <= 1 )
337
337
return PHI;
@@ -340,7 +340,7 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
340
340
341
341
// / GetPHIValue - For the specified PHI instruction, return the register
342
342
// / that it defines.
343
- static unsigned GetPHIValue (MachineInstr *PHI) {
343
+ static Register GetPHIValue (MachineInstr *PHI) {
344
344
return PHI->getOperand (0 ).getReg ();
345
345
}
346
346
};
@@ -351,9 +351,9 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
351
351
// / for the specified BB and if so, return it. If not, construct SSA form by
352
352
// / first calculating the required placement of PHIs and then inserting new
353
353
// / PHIs where needed.
354
- unsigned MachineSSAUpdater::GetValueAtEndOfBlockInternal (MachineBasicBlock *BB){
354
+ Register MachineSSAUpdater::GetValueAtEndOfBlockInternal (MachineBasicBlock *BB){
355
355
AvailableValsTy &AvailableVals = getAvailableVals (AV);
356
- if (unsigned V = AvailableVals[BB])
356
+ if (Register V = AvailableVals[BB])
357
357
return V;
358
358
359
359
SSAUpdaterImpl<MachineSSAUpdater> Impl (this , &AvailableVals, InsertedPHIs);
0 commit comments