16
16
#include " AMDGPU.h"
17
17
#include " GCNSubtarget.h"
18
18
#include " llvm/CodeGen/LiveStacks.h"
19
+ #include " llvm/CodeGen/LiveIntervals.h"
19
20
#include " llvm/CodeGen/MachineOperand.h"
20
21
21
22
using namespace llvm ;
@@ -27,6 +28,7 @@ namespace {
27
28
class AMDGPUMarkLastScratchLoad : public MachineFunctionPass {
28
29
private:
29
30
LiveStacks *LS = nullptr ;
31
+ LiveIntervals *LIS = nullptr ;
30
32
SlotIndexes *SI = nullptr ;
31
33
const SIInstrInfo *SII = nullptr ;
32
34
@@ -41,6 +43,7 @@ class AMDGPUMarkLastScratchLoad : public MachineFunctionPass {
41
43
42
44
void getAnalysisUsage (AnalysisUsage &AU) const override {
43
45
AU.addRequired <SlotIndexes>();
46
+ AU.addRequired <LiveIntervals>();
44
47
AU.addRequired <LiveStacks>();
45
48
AU.setPreservesAll ();
46
49
MachineFunctionPass::getAnalysisUsage (AU);
@@ -62,8 +65,10 @@ bool AMDGPUMarkLastScratchLoad::runOnMachineFunction(MachineFunction &MF) {
62
65
return false ;
63
66
64
67
LS = &getAnalysis<LiveStacks>();
68
+ LIS = &getAnalysis<LiveIntervals>();
65
69
SI = &getAnalysis<SlotIndexes>();
66
70
SII = ST.getInstrInfo ();
71
+ SlotIndexes &Slots = *LIS->getSlotIndexes ();
67
72
68
73
const unsigned NumSlots = LS->getNumIntervals ();
69
74
if (NumSlots == 0 ) {
@@ -87,12 +92,14 @@ bool AMDGPUMarkLastScratchLoad::runOnMachineFunction(MachineFunction &MF) {
87
92
MachineInstr *LastLoad = nullptr ;
88
93
89
94
MachineInstr *MISegmentEnd = SI->getInstructionFromIndex (Segment.end );
95
+
96
+ // If there is no instruction at this slot because it was deleted take the
97
+ // instruction from the next slot.
90
98
if (!MISegmentEnd) {
91
- // FIXME: The start and end can refer to deleted instructions. We should
92
- // be able to handle this more gracefully by finding the closest real
93
- // instructions.
94
- continue ;
99
+ SlotIndex NextSlot = Slots.getNextNonNullIndex (Segment.end );
100
+ MISegmentEnd = SI->getInstructionFromIndex (NextSlot);
95
101
}
102
+
96
103
MachineInstr *MISegmentStart = SI->getInstructionFromIndex (Segment.start );
97
104
MachineBasicBlock *BB = MISegmentEnd->getParent ();
98
105
0 commit comments