1 //===-- SIFixControlFlowLiveIntervals.cpp - Fix CF live intervals ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Spilling of EXEC masks used for control flow messes up control flow
12 /// lowering, so mark all live intervals associated with CF instructions as
15 //===----------------------------------------------------------------------===//
18 #include "SIInstrInfo.h"
19 #include "SIRegisterInfo.h"
20 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
21 #include "llvm/CodeGen/MachineFunctionPass.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachinePostDominators.h"
24 #include "llvm/CodeGen/MachineRegisterInfo.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/raw_ostream.h"
27 #include "llvm/Target/TargetMachine.h"
31 #define DEBUG_TYPE "si-fix-cf-live-intervals"
35 class SIFixControlFlowLiveIntervals : public MachineFunctionPass {
40 SIFixControlFlowLiveIntervals() : MachineFunctionPass(ID) {
41 initializeSIFixControlFlowLiveIntervalsPass(*PassRegistry::getPassRegistry());
44 bool runOnMachineFunction(MachineFunction &MF) override;
46 const char *getPassName() const override {
47 return "SI Fix CF Live Intervals";
50 void getAnalysisUsage(AnalysisUsage &AU) const override {
51 AU.addRequired<LiveIntervals>();
53 MachineFunctionPass::getAnalysisUsage(AU);
57 } // End anonymous namespace.
59 INITIALIZE_PASS_BEGIN(SIFixControlFlowLiveIntervals, DEBUG_TYPE,
60 "SI Fix CF Live Intervals", false, false)
61 INITIALIZE_PASS_DEPENDENCY(LiveIntervals)
62 INITIALIZE_PASS_END(SIFixControlFlowLiveIntervals, DEBUG_TYPE,
63 "SI Fix CF Live Intervals", false, false)
65 char SIFixControlFlowLiveIntervals::ID = 0;
67 char &llvm::SIFixControlFlowLiveIntervalsID = SIFixControlFlowLiveIntervals::ID;
69 FunctionPass *llvm::createSIFixControlFlowLiveIntervalsPass() {
70 return new SIFixControlFlowLiveIntervals();
73 bool SIFixControlFlowLiveIntervals::runOnMachineFunction(MachineFunction &MF) {
74 LiveIntervals *LIS = &getAnalysis<LiveIntervals>();
76 for (const MachineBasicBlock &MBB : MF) {
77 for (const MachineInstr &MI : MBB) {
78 switch (MI.getOpcode()) {
81 case AMDGPU::SI_BREAK:
82 case AMDGPU::SI_IF_BREAK:
83 case AMDGPU::SI_ELSE_BREAK:
84 case AMDGPU::SI_END_CF: {
85 unsigned Reg = MI.getOperand(0).getReg();
86 LIS->getInterval(Reg).markNotSpillable();