blob: e3b1ed9409dfca2a483fcdb06c64a58ff9adc0b0 [file] [log] [blame]
Chris Dewhurst4f7cac32016-05-23 10:56:36 +00001//===------- LeonPasses.h - Define passes specific to LEON ----------------===//
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//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_SPARC_LEON_PASSES_H
14#define LLVM_LIB_TARGET_SPARC_LEON_PASSES_H
15
Chris Dewhurst4f7cac32016-05-23 10:56:36 +000016#include "llvm/CodeGen/MachineBasicBlock.h"
Chris Dewhurst2bad85c2016-06-27 14:19:19 +000017#include "llvm/CodeGen/MachineFunctionPass.h"
18#include "llvm/CodeGen/Passes.h"
Chris Dewhurst4f7cac32016-05-23 10:56:36 +000019
20#include "Sparc.h"
21#include "SparcSubtarget.h"
22
Benjamin Kramer797fb962016-05-27 10:06:27 +000023namespace llvm {
24class LLVM_LIBRARY_VISIBILITY LEONMachineFunctionPass
25 : public MachineFunctionPass {
Chris Dewhurst4f7cac32016-05-23 10:56:36 +000026protected:
27 const SparcSubtarget *Subtarget;
Chris Dewhurst0c1e0022016-06-19 11:03:28 +000028 const int LAST_OPERAND = -1;
29
Chris Dewhurst2bad85c2016-06-27 14:19:19 +000030 // this vector holds free registers that we allocate in groups for some of the
31 // LEON passes
32 std::vector<int> UsedRegisters;
Chris Dewhurst4f7cac32016-05-23 10:56:36 +000033
34protected:
Chris Dewhurst2bad85c2016-06-27 14:19:19 +000035 LEONMachineFunctionPass(TargetMachine &tm, char &ID);
36 LEONMachineFunctionPass(char &ID);
Chris Dewhurst0c1e0022016-06-19 11:03:28 +000037
Chris Dewhurst2bad85c2016-06-27 14:19:19 +000038 int GetRegIndexForOperand(MachineInstr &MI, int OperandIndex);
39 void clearUsedRegisterList() { UsedRegisters.clear(); }
40
41 void markRegisterUsed(int registerIndex) {
42 UsedRegisters.push_back(registerIndex);
43 }
44 int getUnusedFPRegister(MachineRegisterInfo &MRI);
Chris Dewhurst4f7cac32016-05-23 10:56:36 +000045};
46
Chris Dewhurst3202f062016-07-08 15:33:56 +000047class LLVM_LIBRARY_VISIBILITY ReplaceSDIV : public LEONMachineFunctionPass {
Chris Dewhurst4f7cac32016-05-23 10:56:36 +000048public:
49 static char ID;
50
Chris Dewhurst3202f062016-07-08 15:33:56 +000051 ReplaceSDIV();
52 ReplaceSDIV(TargetMachine &tm);
Chris Dewhurst2bad85c2016-06-27 14:19:19 +000053 bool runOnMachineFunction(MachineFunction &MF) override;
Chris Dewhurst4f7cac32016-05-23 10:56:36 +000054
55 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +000056 return "ReplaceSDIV: Leon erratum fix: do not emit SDIV, but emit SDIVCC "
Chris Dewhurst3202f062016-07-08 15:33:56 +000057 "instead";
58 }
59};
60
61class LLVM_LIBRARY_VISIBILITY FixCALL : public LEONMachineFunctionPass {
62public:
63 static char ID;
64
65 FixCALL(TargetMachine &tm);
66 bool runOnMachineFunction(MachineFunction &MF) override;
67
68 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +000069 return "FixCALL: Leon erratum fix: restrict the size of the immediate "
Chris Dewhurst3202f062016-07-08 15:33:56 +000070 "operand of the CALL instruction to 20 bits";
71 }
72};
73
Chris Dewhurst829f8ef2016-08-12 09:34:26 +000074class LLVM_LIBRARY_VISIBILITY RestoreExecAddress : public LEONMachineFunctionPass {
75public:
76 static char ID;
77
78 RestoreExecAddress(TargetMachine &tm);
79 bool runOnMachineFunction(MachineFunction& MF) override;
80
81 const char *getPassName() const override {
82 return "RestoreExecAddress: Leon erratum fix: ensure execution "
83 "address is restored for bad floating point trap handlers.";
84 }
85};
86
Chris Dewhurst3202f062016-07-08 15:33:56 +000087class LLVM_LIBRARY_VISIBILITY IgnoreZeroFlag : public LEONMachineFunctionPass {
88public:
89 static char ID;
90
91 IgnoreZeroFlag(TargetMachine &tm);
92 bool runOnMachineFunction(MachineFunction &MF) override;
93
94 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +000095 return "IgnoreZeroFlag: Leon erratum fix: do not rely on the zero bit "
Chris Dewhurst3202f062016-07-08 15:33:56 +000096 "flag on a divide overflow for SDIVCC and UDIVCC";
97 }
98};
99
Chris Dewhurst829f8ef2016-08-12 09:34:26 +0000100class LLVM_LIBRARY_VISIBILITY FillDataCache : public LEONMachineFunctionPass {
101public:
102 static char ID;
103 static bool CacheFilled;
104
105 FillDataCache(TargetMachine &tm);
106 bool runOnMachineFunction(MachineFunction& MF) override;
107
108 const char *getPassName() const override {
109 return "FillDataCache: Leon erratum fix: fill data cache with values at application startup";
110 }
111};
112
Chris Dewhurst3202f062016-07-08 15:33:56 +0000113class LLVM_LIBRARY_VISIBILITY InsertNOPDoublePrecision
114 : public LEONMachineFunctionPass {
115public:
116 static char ID;
117
118 InsertNOPDoublePrecision(TargetMachine &tm);
119 bool runOnMachineFunction(MachineFunction &MF) override;
120
121 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +0000122 return "InsertNOPDoublePrecision: Leon erratum fix: insert a NOP before "
Chris Dewhurst3202f062016-07-08 15:33:56 +0000123 "the double precision floating point instruction";
Chris Dewhurst4f7cac32016-05-23 10:56:36 +0000124 }
125};
Chris Dewhurst0c1e0022016-06-19 11:03:28 +0000126
127class LLVM_LIBRARY_VISIBILITY FixFSMULD : public LEONMachineFunctionPass {
128public:
129 static char ID;
130
131 FixFSMULD(TargetMachine &tm);
Chris Dewhurst2bad85c2016-06-27 14:19:19 +0000132 bool runOnMachineFunction(MachineFunction &MF) override;
Chris Dewhurst0c1e0022016-06-19 11:03:28 +0000133
134 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +0000135 return "FixFSMULD: Leon erratum fix: do not utilize FSMULD";
Chris Dewhurst0c1e0022016-06-19 11:03:28 +0000136 }
137};
138
139class LLVM_LIBRARY_VISIBILITY ReplaceFMULS : public LEONMachineFunctionPass {
140public:
141 static char ID;
142
143 ReplaceFMULS(TargetMachine &tm);
Chris Dewhurst2bad85c2016-06-27 14:19:19 +0000144 bool runOnMachineFunction(MachineFunction &MF) override;
Chris Dewhurst0c1e0022016-06-19 11:03:28 +0000145
146 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +0000147 return "ReplaceFMULS: Leon erratum fix: Replace FMULS instruction with a "
Chris Dewhurst2bad85c2016-06-27 14:19:19 +0000148 "routine using conversions/double precision operations to replace "
149 "FMULS";
Chris Dewhurst0c1e0022016-06-19 11:03:28 +0000150 }
151};
152
Chris Dewhurst3202f062016-07-08 15:33:56 +0000153class LLVM_LIBRARY_VISIBILITY PreventRoundChange
154 : public LEONMachineFunctionPass {
155public:
156 static char ID;
157
158 PreventRoundChange(TargetMachine &tm);
159 bool runOnMachineFunction(MachineFunction &MF) override;
160
161 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +0000162 return "PreventRoundChange: Leon erratum fix: prevent any rounding mode "
Chris Dewhurst3202f062016-07-08 15:33:56 +0000163 "change request: use only the round-to-nearest rounding mode";
164 }
165};
166
Chris Dewhurst0c1e0022016-06-19 11:03:28 +0000167class LLVM_LIBRARY_VISIBILITY FixAllFDIVSQRT : public LEONMachineFunctionPass {
168public:
169 static char ID;
170
171 FixAllFDIVSQRT(TargetMachine &tm);
Chris Dewhurst2bad85c2016-06-27 14:19:19 +0000172 bool runOnMachineFunction(MachineFunction &MF) override;
Chris Dewhurst0c1e0022016-06-19 11:03:28 +0000173
174 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +0000175 return "FixAllFDIVSQRT: Leon erratum fix: Fix FDIVS/FDIVD/FSQRTS/FSQRTD "
Chris Dewhurst2bad85c2016-06-27 14:19:19 +0000176 "instructions with NOPs and floating-point store";
Chris Dewhurst0c1e0022016-06-19 11:03:28 +0000177 }
178};
Chris Dewhurst3202f062016-07-08 15:33:56 +0000179
180class LLVM_LIBRARY_VISIBILITY InsertNOPLoad : public LEONMachineFunctionPass {
181public:
182 static char ID;
183
184 InsertNOPLoad(TargetMachine &tm);
185 bool runOnMachineFunction(MachineFunction &MF) override;
186
187 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +0000188 return "InsertNOPLoad: Leon erratum fix: Insert a NOP instruction after "
Chris Dewhurst3202f062016-07-08 15:33:56 +0000189 "every single-cycle load instruction when the next instruction is "
190 "another load/store instruction";
191 }
192};
193
Chris Dewhurst3202f062016-07-08 15:33:56 +0000194class LLVM_LIBRARY_VISIBILITY InsertNOPsLoadStore
195 : public LEONMachineFunctionPass {
196public:
197 static char ID;
198
199 InsertNOPsLoadStore(TargetMachine &tm);
200 bool runOnMachineFunction(MachineFunction &MF) override;
201
202 const char *getPassName() const override {
Chris Dewhurst829f8ef2016-08-12 09:34:26 +0000203 return "InsertNOPsLoadStore: Leon Erratum Fix: Insert NOPs between "
Chris Dewhurst3202f062016-07-08 15:33:56 +0000204 "single-precision loads and the store, so the number of "
205 "instructions between is 4";
206 }
207};
208} // namespace lllvm
Chris Dewhurst4f7cac32016-05-23 10:56:36 +0000209
Chris Dewhurst5047f242016-06-27 14:35:07 +0000210#endif // LLVM_LIB_TARGET_SPARC_LEON_PASSES_H