@@ -70,7 +70,6 @@ STATISTIC(NumTwoAddressInstrs, "Number of two-address instructions");
70
70
STATISTIC (NumCommuted , " Number of instructions commuted to coalesce" );
71
71
STATISTIC (NumAggrCommuted , " Number of instructions aggressively commuted" );
72
72
STATISTIC (NumConvertedTo3Addr, " Number of instructions promoted to 3-address" );
73
- STATISTIC (Num3AddrSunk, " Number of 3-address instructions sunk" );
74
73
STATISTIC (NumReSchedUps, " Number of instructions re-scheduled up" );
75
74
STATISTIC (NumReSchedDowns, " Number of instructions re-scheduled down" );
76
75
@@ -109,10 +108,6 @@ class TwoAddressInstructionPass : public MachineFunctionPass {
109
108
// Set of already processed instructions in the current block.
110
109
SmallPtrSet<MachineInstr*, 8 > Processed;
111
110
112
- // Set of instructions converted to three-address by target and then sunk
113
- // down current basic block.
114
- SmallPtrSet<MachineInstr*, 8 > SunkInstrs;
115
-
116
111
// A map from virtual registers to physical registers which are likely targets
117
112
// to be coalesced to due to copies from physical registers to virtual
118
113
// registers. e.g. v1024 = move r0.
@@ -123,9 +118,6 @@ class TwoAddressInstructionPass : public MachineFunctionPass {
123
118
// registers. e.g. r1 = move v1024.
124
119
DenseMap<unsigned , unsigned > DstRegMap;
125
120
126
- bool sink3AddrInstruction (MachineInstr *MI, unsigned Reg,
127
- MachineBasicBlock::iterator OldPos);
128
-
129
121
bool isRevCopyChain (unsigned FromReg, unsigned ToReg, int Maxlen);
130
122
131
123
bool noUseAfterLastDef (unsigned Reg, unsigned Dist, unsigned &LastDef);
@@ -209,136 +201,6 @@ INITIALIZE_PASS_END(TwoAddressInstructionPass, DEBUG_TYPE,
209
201
210
202
static bool isPlainlyKilled(MachineInstr *MI, unsigned Reg, LiveIntervals *LIS);
211
203
212
- // / A two-address instruction has been converted to a three-address instruction
213
- // / to avoid clobbering a register. Try to sink it past the instruction that
214
- // / would kill the above mentioned register to reduce register pressure.
215
- bool TwoAddressInstructionPass::
216
- sink3AddrInstruction (MachineInstr *MI, unsigned SavedReg,
217
- MachineBasicBlock::iterator OldPos) {
218
- // FIXME: Shouldn't we be trying to do this before we three-addressify the
219
- // instruction? After this transformation is done, we no longer need
220
- // the instruction to be in three-address form.
221
-
222
- // Check if it's safe to move this instruction.
223
- bool SeenStore = true ; // Be conservative.
224
- if (!MI->isSafeToMove (AA, SeenStore))
225
- return false ;
226
-
227
- unsigned DefReg = 0 ;
228
- SmallSet<unsigned , 4 > UseRegs;
229
-
230
- for (const MachineOperand &MO : MI->operands ()) {
231
- if (!MO.isReg ())
232
- continue ;
233
- Register MOReg = MO.getReg ();
234
- if (!MOReg)
235
- continue ;
236
- if (MO.isUse () && MOReg != SavedReg)
237
- UseRegs.insert (MO.getReg ());
238
- if (!MO.isDef ())
239
- continue ;
240
- if (MO.isImplicit ())
241
- // Don't try to move it if it implicitly defines a register.
242
- return false ;
243
- if (DefReg)
244
- // For now, don't move any instructions that define multiple registers.
245
- return false ;
246
- DefReg = MO.getReg ();
247
- }
248
-
249
- // Find the instruction that kills SavedReg.
250
- MachineInstr *KillMI = nullptr ;
251
- if (LIS) {
252
- LiveInterval &LI = LIS->getInterval (SavedReg);
253
- assert (LI.end () != LI.begin () &&
254
- " Reg should not have empty live interval." );
255
-
256
- SlotIndex MBBEndIdx = LIS->getMBBEndIdx (MBB).getPrevSlot ();
257
- LiveInterval::const_iterator I = LI.find (MBBEndIdx);
258
- if (I != LI.end () && I->start < MBBEndIdx)
259
- return false ;
260
-
261
- --I;
262
- KillMI = LIS->getInstructionFromIndex (I->end );
263
- }
264
- if (!KillMI) {
265
- for (MachineOperand &UseMO : MRI->use_nodbg_operands (SavedReg)) {
266
- if (!UseMO.isKill ())
267
- continue ;
268
- KillMI = UseMO.getParent ();
269
- break ;
270
- }
271
- }
272
-
273
- // If we find the instruction that kills SavedReg, and it is in an
274
- // appropriate location, we can try to sink the current instruction
275
- // past it.
276
- if (!KillMI || KillMI->getParent () != MBB || KillMI == MI ||
277
- MachineBasicBlock::iterator (KillMI) == OldPos || KillMI->isTerminator ())
278
- return false ;
279
-
280
- // If any of the definitions are used by another instruction between the
281
- // position and the kill use, then it's not safe to sink it.
282
- //
283
- // FIXME: This can be sped up if there is an easy way to query whether an
284
- // instruction is before or after another instruction. Then we can use
285
- // MachineRegisterInfo def / use instead.
286
- MachineOperand *KillMO = nullptr ;
287
- MachineBasicBlock::iterator KillPos = KillMI;
288
- ++KillPos;
289
-
290
- unsigned NumVisited = 0 ;
291
- for (MachineInstr &OtherMI : make_range (std::next (OldPos), KillPos)) {
292
- // Debug instructions cannot be counted against the limit.
293
- if (OtherMI.isDebugInstr ())
294
- continue ;
295
- if (NumVisited > 30 ) // FIXME: Arbitrary limit to reduce compile time cost.
296
- return false ;
297
- ++NumVisited;
298
- for (unsigned i = 0 , e = OtherMI.getNumOperands (); i != e; ++i) {
299
- MachineOperand &MO = OtherMI.getOperand (i);
300
- if (!MO.isReg ())
301
- continue ;
302
- Register MOReg = MO.getReg ();
303
- if (!MOReg)
304
- continue ;
305
- if (DefReg == MOReg)
306
- return false ;
307
-
308
- if (MO.isKill () || (LIS && isPlainlyKilled (&OtherMI, MOReg, LIS))) {
309
- if (&OtherMI == KillMI && MOReg == SavedReg)
310
- // Save the operand that kills the register. We want to unset the kill
311
- // marker if we can sink MI past it.
312
- KillMO = &MO;
313
- else if (UseRegs.count (MOReg))
314
- // One of the uses is killed before the destination.
315
- return false ;
316
- }
317
- }
318
- }
319
- assert (KillMO && " Didn't find kill" );
320
-
321
- if (!LIS) {
322
- // Update kill and LV information.
323
- KillMO->setIsKill (false );
324
- KillMO = MI->findRegisterUseOperand (SavedReg, false , TRI);
325
- KillMO->setIsKill (true );
326
-
327
- if (LV)
328
- LV->replaceKillInstruction (SavedReg, *KillMI, *MI);
329
- }
330
-
331
- // Move instruction to its destination.
332
- MBB->remove (MI);
333
- MBB->insert (KillPos, MI);
334
-
335
- if (LIS)
336
- LIS->handleMove (*MI);
337
-
338
- ++Num3AddrSunk;
339
- return true ;
340
- }
341
-
342
204
// / Return the MachineInstr* if it is the single def of the Reg in current BB.
343
205
static MachineInstr *getSingleDef (unsigned Reg, MachineBasicBlock *BB,
344
206
const MachineRegisterInfo *MRI) {
@@ -740,26 +602,15 @@ TwoAddressInstructionPass::convertInstTo3Addr(MachineBasicBlock::iterator &mi,
740
602
741
603
LLVM_DEBUG (dbgs () << " 2addr: CONVERTING 2-ADDR: " << *mi);
742
604
LLVM_DEBUG (dbgs () << " 2addr: TO 3-ADDR: " << *NewMI);
743
- bool Sunk = false ;
744
605
745
606
if (LIS)
746
607
LIS->ReplaceMachineInstrInMaps (*mi, *NewMI);
747
608
748
- if (NewMI->findRegisterUseOperand (RegB, false , TRI))
749
- // FIXME: Temporary workaround. If the new instruction doesn't
750
- // uses RegB, convertToThreeAddress must have created more
751
- // then one instruction.
752
- Sunk = sink3AddrInstruction (NewMI, RegB, mi);
753
-
754
609
MBB->erase (mi); // Nuke the old inst.
755
610
756
- if (!Sunk) {
757
- DistanceMap.insert (std::make_pair (NewMI, Dist));
758
- mi = NewMI;
759
- nmi = std::next (mi);
760
- }
761
- else
762
- SunkInstrs.insert (NewMI);
611
+ DistanceMap.insert (std::make_pair (NewMI, Dist));
612
+ mi = NewMI;
613
+ nmi = std::next (mi);
763
614
764
615
// Update source and destination register maps.
765
616
SrcRegMap.erase (RegA);
@@ -1700,13 +1551,11 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &Func) {
1700
1551
SrcRegMap.clear ();
1701
1552
DstRegMap.clear ();
1702
1553
Processed.clear ();
1703
- SunkInstrs.clear ();
1704
1554
for (MachineBasicBlock::iterator mi = MBB->begin (), me = MBB->end ();
1705
1555
mi != me; ) {
1706
1556
MachineBasicBlock::iterator nmi = std::next (mi);
1707
- // Don't revisit an instruction previously converted by target. It may
1708
- // contain undef register operands (%noreg), which are not handled.
1709
- if (mi->isDebugInstr () || SunkInstrs.count (&*mi)) {
1557
+ // Skip debug instructions.
1558
+ if (mi->isDebugInstr ()) {
1710
1559
mi = nmi;
1711
1560
continue ;
1712
1561
}
0 commit comments