blob: 5fe8d19426dd74efb3c213c3c5a6681df22393e5 [file] [log] [blame]
Tom Stellard28d13a42015-05-12 17:13:02 +00001//===-- SIFixControlFlowLiveIntervals.cpp - Fix CF live intervals ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file
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
13/// non-spillable.
14///
15//===----------------------------------------------------------------------===//
16
17#include "AMDGPU.h"
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"
28
29using namespace llvm;
30
31#define DEBUG_TYPE "si-fix-cf-live-intervals"
32
33namespace {
34
35class SIFixControlFlowLiveIntervals : public MachineFunctionPass {
36public:
37 static char ID;
38
39public:
40 SIFixControlFlowLiveIntervals() : MachineFunctionPass(ID) {
41 initializeSIFixControlFlowLiveIntervalsPass(*PassRegistry::getPassRegistry());
42 }
43
44 bool runOnMachineFunction(MachineFunction &MF) override;
45
46 const char *getPassName() const override {
47 return "SI Fix CF Live Intervals";
48 }
49
50 void getAnalysisUsage(AnalysisUsage &AU) const override {
51 AU.addRequired<LiveIntervals>();
52 AU.setPreservesAll();
53 MachineFunctionPass::getAnalysisUsage(AU);
54 }
55};
56
57} // End anonymous namespace.
58
59INITIALIZE_PASS_BEGIN(SIFixControlFlowLiveIntervals, DEBUG_TYPE,
60 "SI Fix CF Live Intervals", false, false)
61INITIALIZE_PASS_DEPENDENCY(LiveIntervals)
62INITIALIZE_PASS_END(SIFixControlFlowLiveIntervals, DEBUG_TYPE,
63 "SI Fix CF Live Intervals", false, false)
64
65char SIFixControlFlowLiveIntervals::ID = 0;
66
67char &llvm::SIFixControlFlowLiveIntervalsID = SIFixControlFlowLiveIntervals::ID;
68
69FunctionPass *llvm::createSIFixControlFlowLiveIntervalsPass() {
70 return new SIFixControlFlowLiveIntervals();
71}
72
73bool SIFixControlFlowLiveIntervals::runOnMachineFunction(MachineFunction &MF) {
74 LiveIntervals *LIS = &getAnalysis<LiveIntervals>();
75
76 for (const MachineBasicBlock &MBB : MF) {
77 for (const MachineInstr &MI : MBB) {
78 switch (MI.getOpcode()) {
79 case AMDGPU::SI_IF:
80 case AMDGPU::SI_ELSE:
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();
87 break;
88 }
89 default:
90 break;
91 }
92 }
93 }
94
95 return false;
96}