blob: d4d3959658e7d2c3ec883e3d497d9f0b6f7f1f10 [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"
Tom Stellard28d13a42015-05-12 17:13:02 +000019#include "llvm/CodeGen/LiveIntervalAnalysis.h"
20#include "llvm/CodeGen/MachineFunctionPass.h"
Tom Stellard28d13a42015-05-12 17:13:02 +000021#include "llvm/CodeGen/MachineRegisterInfo.h"
Tom Stellard28d13a42015-05-12 17:13:02 +000022
23using namespace llvm;
24
25#define DEBUG_TYPE "si-fix-cf-live-intervals"
26
27namespace {
28
29class SIFixControlFlowLiveIntervals : public MachineFunctionPass {
30public:
31 static char ID;
32
33public:
34 SIFixControlFlowLiveIntervals() : MachineFunctionPass(ID) {
35 initializeSIFixControlFlowLiveIntervalsPass(*PassRegistry::getPassRegistry());
36 }
37
38 bool runOnMachineFunction(MachineFunction &MF) override;
39
Mehdi Amini117296c2016-10-01 02:56:57 +000040 StringRef getPassName() const override { return "SI Fix CF Live Intervals"; }
Tom Stellard28d13a42015-05-12 17:13:02 +000041
42 void getAnalysisUsage(AnalysisUsage &AU) const override {
43 AU.addRequired<LiveIntervals>();
44 AU.setPreservesAll();
45 MachineFunctionPass::getAnalysisUsage(AU);
46 }
47};
48
49} // End anonymous namespace.
50
51INITIALIZE_PASS_BEGIN(SIFixControlFlowLiveIntervals, DEBUG_TYPE,
52 "SI Fix CF Live Intervals", false, false)
53INITIALIZE_PASS_DEPENDENCY(LiveIntervals)
54INITIALIZE_PASS_END(SIFixControlFlowLiveIntervals, DEBUG_TYPE,
55 "SI Fix CF Live Intervals", false, false)
56
57char SIFixControlFlowLiveIntervals::ID = 0;
58
59char &llvm::SIFixControlFlowLiveIntervalsID = SIFixControlFlowLiveIntervals::ID;
60
61FunctionPass *llvm::createSIFixControlFlowLiveIntervalsPass() {
62 return new SIFixControlFlowLiveIntervals();
63}
64
65bool SIFixControlFlowLiveIntervals::runOnMachineFunction(MachineFunction &MF) {
66 LiveIntervals *LIS = &getAnalysis<LiveIntervals>();
67
68 for (const MachineBasicBlock &MBB : MF) {
69 for (const MachineInstr &MI : MBB) {
70 switch (MI.getOpcode()) {
71 case AMDGPU::SI_IF:
72 case AMDGPU::SI_ELSE:
Matt Arsenault48d70cb2016-07-09 17:18:39 +000073 case AMDGPU::SI_BREAK:
Tom Stellard28d13a42015-05-12 17:13:02 +000074 case AMDGPU::SI_IF_BREAK:
75 case AMDGPU::SI_ELSE_BREAK:
76 case AMDGPU::SI_END_CF: {
77 unsigned Reg = MI.getOperand(0).getReg();
78 LIS->getInterval(Reg).markNotSpillable();
79 break;
80 }
81 default:
82 break;
83 }
84 }
85 }
86
87 return false;
88}