xref: /aosp_15_r20/external/llvm/lib/Target/AMDGPU/SIFixControlFlowLiveIntervals.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- SIFixControlFlowLiveIntervals.cpp - Fix CF live intervals ---------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker /// \file
11*9880d681SAndroid Build Coastguard Worker /// \brief Spilling of EXEC masks used for control flow messes up control flow
12*9880d681SAndroid Build Coastguard Worker /// lowering, so mark all live intervals associated with CF instructions as
13*9880d681SAndroid Build Coastguard Worker /// non-spillable.
14*9880d681SAndroid Build Coastguard Worker ///
15*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker #include "AMDGPU.h"
18*9880d681SAndroid Build Coastguard Worker #include "SIInstrInfo.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/LiveIntervalAnalysis.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunctionPass.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineRegisterInfo.h"
22*9880d681SAndroid Build Coastguard Worker 
23*9880d681SAndroid Build Coastguard Worker using namespace llvm;
24*9880d681SAndroid Build Coastguard Worker 
25*9880d681SAndroid Build Coastguard Worker #define DEBUG_TYPE "si-fix-cf-live-intervals"
26*9880d681SAndroid Build Coastguard Worker 
27*9880d681SAndroid Build Coastguard Worker namespace {
28*9880d681SAndroid Build Coastguard Worker 
29*9880d681SAndroid Build Coastguard Worker class SIFixControlFlowLiveIntervals : public MachineFunctionPass {
30*9880d681SAndroid Build Coastguard Worker public:
31*9880d681SAndroid Build Coastguard Worker   static char ID;
32*9880d681SAndroid Build Coastguard Worker 
33*9880d681SAndroid Build Coastguard Worker public:
SIFixControlFlowLiveIntervals()34*9880d681SAndroid Build Coastguard Worker   SIFixControlFlowLiveIntervals() : MachineFunctionPass(ID) {
35*9880d681SAndroid Build Coastguard Worker     initializeSIFixControlFlowLiveIntervalsPass(*PassRegistry::getPassRegistry());
36*9880d681SAndroid Build Coastguard Worker   }
37*9880d681SAndroid Build Coastguard Worker 
38*9880d681SAndroid Build Coastguard Worker   bool runOnMachineFunction(MachineFunction &MF) override;
39*9880d681SAndroid Build Coastguard Worker 
getPassName() const40*9880d681SAndroid Build Coastguard Worker   const char *getPassName() const override {
41*9880d681SAndroid Build Coastguard Worker     return "SI Fix CF Live Intervals";
42*9880d681SAndroid Build Coastguard Worker   }
43*9880d681SAndroid Build Coastguard Worker 
getAnalysisUsage(AnalysisUsage & AU) const44*9880d681SAndroid Build Coastguard Worker   void getAnalysisUsage(AnalysisUsage &AU) const override {
45*9880d681SAndroid Build Coastguard Worker     AU.addRequired<LiveIntervals>();
46*9880d681SAndroid Build Coastguard Worker     AU.setPreservesAll();
47*9880d681SAndroid Build Coastguard Worker     MachineFunctionPass::getAnalysisUsage(AU);
48*9880d681SAndroid Build Coastguard Worker   }
49*9880d681SAndroid Build Coastguard Worker };
50*9880d681SAndroid Build Coastguard Worker 
51*9880d681SAndroid Build Coastguard Worker } // End anonymous namespace.
52*9880d681SAndroid Build Coastguard Worker 
53*9880d681SAndroid Build Coastguard Worker INITIALIZE_PASS_BEGIN(SIFixControlFlowLiveIntervals, DEBUG_TYPE,
54*9880d681SAndroid Build Coastguard Worker                       "SI Fix CF Live Intervals", false, false)
55*9880d681SAndroid Build Coastguard Worker INITIALIZE_PASS_DEPENDENCY(LiveIntervals)
56*9880d681SAndroid Build Coastguard Worker INITIALIZE_PASS_END(SIFixControlFlowLiveIntervals, DEBUG_TYPE,
57*9880d681SAndroid Build Coastguard Worker                     "SI Fix CF Live Intervals", false, false)
58*9880d681SAndroid Build Coastguard Worker 
59*9880d681SAndroid Build Coastguard Worker char SIFixControlFlowLiveIntervals::ID = 0;
60*9880d681SAndroid Build Coastguard Worker 
61*9880d681SAndroid Build Coastguard Worker char &llvm::SIFixControlFlowLiveIntervalsID = SIFixControlFlowLiveIntervals::ID;
62*9880d681SAndroid Build Coastguard Worker 
createSIFixControlFlowLiveIntervalsPass()63*9880d681SAndroid Build Coastguard Worker FunctionPass *llvm::createSIFixControlFlowLiveIntervalsPass() {
64*9880d681SAndroid Build Coastguard Worker   return new SIFixControlFlowLiveIntervals();
65*9880d681SAndroid Build Coastguard Worker }
66*9880d681SAndroid Build Coastguard Worker 
runOnMachineFunction(MachineFunction & MF)67*9880d681SAndroid Build Coastguard Worker bool SIFixControlFlowLiveIntervals::runOnMachineFunction(MachineFunction &MF) {
68*9880d681SAndroid Build Coastguard Worker   LiveIntervals *LIS = &getAnalysis<LiveIntervals>();
69*9880d681SAndroid Build Coastguard Worker 
70*9880d681SAndroid Build Coastguard Worker   for (const MachineBasicBlock &MBB : MF) {
71*9880d681SAndroid Build Coastguard Worker     for (const MachineInstr &MI : MBB) {
72*9880d681SAndroid Build Coastguard Worker       switch (MI.getOpcode()) {
73*9880d681SAndroid Build Coastguard Worker         case AMDGPU::SI_IF:
74*9880d681SAndroid Build Coastguard Worker         case AMDGPU::SI_ELSE:
75*9880d681SAndroid Build Coastguard Worker         case AMDGPU::SI_BREAK:
76*9880d681SAndroid Build Coastguard Worker         case AMDGPU::SI_IF_BREAK:
77*9880d681SAndroid Build Coastguard Worker         case AMDGPU::SI_ELSE_BREAK:
78*9880d681SAndroid Build Coastguard Worker         case AMDGPU::SI_END_CF: {
79*9880d681SAndroid Build Coastguard Worker           unsigned Reg = MI.getOperand(0).getReg();
80*9880d681SAndroid Build Coastguard Worker           LIS->getInterval(Reg).markNotSpillable();
81*9880d681SAndroid Build Coastguard Worker           break;
82*9880d681SAndroid Build Coastguard Worker         }
83*9880d681SAndroid Build Coastguard Worker         default:
84*9880d681SAndroid Build Coastguard Worker           break;
85*9880d681SAndroid Build Coastguard Worker       }
86*9880d681SAndroid Build Coastguard Worker     }
87*9880d681SAndroid Build Coastguard Worker   }
88*9880d681SAndroid Build Coastguard Worker 
89*9880d681SAndroid Build Coastguard Worker   return false;
90*9880d681SAndroid Build Coastguard Worker }
91