Chris Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 1 | //===------- 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 Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 18 | #include "llvm/CodeGen/Passes.h" |
Chris Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 19 | |
| 20 | #include "Sparc.h" |
| 21 | #include "SparcSubtarget.h" |
| 22 | |
Benjamin Kramer | 797fb96 | 2016-05-27 10:06:27 +0000 | [diff] [blame] | 23 | namespace llvm { |
| 24 | class LLVM_LIBRARY_VISIBILITY LEONMachineFunctionPass |
| 25 | : public MachineFunctionPass { |
Chris Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 26 | protected: |
| 27 | const SparcSubtarget *Subtarget; |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 28 | const int LAST_OPERAND = -1; |
| 29 | |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 30 | // this vector holds free registers that we allocate in groups for some of the |
| 31 | // LEON passes |
| 32 | std::vector<int> UsedRegisters; |
Chris Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 33 | |
| 34 | protected: |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 35 | LEONMachineFunctionPass(TargetMachine &tm, char &ID); |
| 36 | LEONMachineFunctionPass(char &ID); |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 37 | |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 38 | 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 Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 47 | class LLVM_LIBRARY_VISIBILITY ReplaceSDIV : public LEONMachineFunctionPass { |
Chris Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 48 | public: |
| 49 | static char ID; |
| 50 | |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 51 | ReplaceSDIV(); |
| 52 | ReplaceSDIV(TargetMachine &tm); |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 53 | bool runOnMachineFunction(MachineFunction &MF) override; |
Chris Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 54 | |
| 55 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 56 | return "ReplaceSDIV: Leon erratum fix: do not emit SDIV, but emit SDIVCC " |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 57 | "instead"; |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | class LLVM_LIBRARY_VISIBILITY FixCALL : public LEONMachineFunctionPass { |
| 62 | public: |
| 63 | static char ID; |
| 64 | |
| 65 | FixCALL(TargetMachine &tm); |
| 66 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 67 | |
| 68 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 69 | return "FixCALL: Leon erratum fix: restrict the size of the immediate " |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 70 | "operand of the CALL instruction to 20 bits"; |
| 71 | } |
| 72 | }; |
| 73 | |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 74 | class LLVM_LIBRARY_VISIBILITY RestoreExecAddress : public LEONMachineFunctionPass { |
| 75 | public: |
| 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 Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 87 | class LLVM_LIBRARY_VISIBILITY IgnoreZeroFlag : public LEONMachineFunctionPass { |
| 88 | public: |
| 89 | static char ID; |
| 90 | |
| 91 | IgnoreZeroFlag(TargetMachine &tm); |
| 92 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 93 | |
| 94 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 95 | return "IgnoreZeroFlag: Leon erratum fix: do not rely on the zero bit " |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 96 | "flag on a divide overflow for SDIVCC and UDIVCC"; |
| 97 | } |
| 98 | }; |
| 99 | |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 100 | class LLVM_LIBRARY_VISIBILITY FillDataCache : public LEONMachineFunctionPass { |
| 101 | public: |
| 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 Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 113 | class LLVM_LIBRARY_VISIBILITY InsertNOPDoublePrecision |
| 114 | : public LEONMachineFunctionPass { |
| 115 | public: |
| 116 | static char ID; |
| 117 | |
| 118 | InsertNOPDoublePrecision(TargetMachine &tm); |
| 119 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 120 | |
| 121 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 122 | return "InsertNOPDoublePrecision: Leon erratum fix: insert a NOP before " |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 123 | "the double precision floating point instruction"; |
Chris Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 124 | } |
| 125 | }; |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 126 | |
| 127 | class LLVM_LIBRARY_VISIBILITY FixFSMULD : public LEONMachineFunctionPass { |
| 128 | public: |
| 129 | static char ID; |
| 130 | |
| 131 | FixFSMULD(TargetMachine &tm); |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 132 | bool runOnMachineFunction(MachineFunction &MF) override; |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 133 | |
| 134 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 135 | return "FixFSMULD: Leon erratum fix: do not utilize FSMULD"; |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 136 | } |
| 137 | }; |
| 138 | |
| 139 | class LLVM_LIBRARY_VISIBILITY ReplaceFMULS : public LEONMachineFunctionPass { |
| 140 | public: |
| 141 | static char ID; |
| 142 | |
| 143 | ReplaceFMULS(TargetMachine &tm); |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 144 | bool runOnMachineFunction(MachineFunction &MF) override; |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 145 | |
| 146 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 147 | return "ReplaceFMULS: Leon erratum fix: Replace FMULS instruction with a " |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 148 | "routine using conversions/double precision operations to replace " |
| 149 | "FMULS"; |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 150 | } |
| 151 | }; |
| 152 | |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 153 | class LLVM_LIBRARY_VISIBILITY PreventRoundChange |
| 154 | : public LEONMachineFunctionPass { |
| 155 | public: |
| 156 | static char ID; |
| 157 | |
| 158 | PreventRoundChange(TargetMachine &tm); |
| 159 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 160 | |
| 161 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 162 | return "PreventRoundChange: Leon erratum fix: prevent any rounding mode " |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 163 | "change request: use only the round-to-nearest rounding mode"; |
| 164 | } |
| 165 | }; |
| 166 | |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 167 | class LLVM_LIBRARY_VISIBILITY FixAllFDIVSQRT : public LEONMachineFunctionPass { |
| 168 | public: |
| 169 | static char ID; |
| 170 | |
| 171 | FixAllFDIVSQRT(TargetMachine &tm); |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 172 | bool runOnMachineFunction(MachineFunction &MF) override; |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 173 | |
| 174 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 175 | return "FixAllFDIVSQRT: Leon erratum fix: Fix FDIVS/FDIVD/FSQRTS/FSQRTD " |
Chris Dewhurst | 2bad85c | 2016-06-27 14:19:19 +0000 | [diff] [blame] | 176 | "instructions with NOPs and floating-point store"; |
Chris Dewhurst | 0c1e002 | 2016-06-19 11:03:28 +0000 | [diff] [blame] | 177 | } |
| 178 | }; |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 179 | |
| 180 | class LLVM_LIBRARY_VISIBILITY InsertNOPLoad : public LEONMachineFunctionPass { |
| 181 | public: |
| 182 | static char ID; |
| 183 | |
| 184 | InsertNOPLoad(TargetMachine &tm); |
| 185 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 186 | |
| 187 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 188 | return "InsertNOPLoad: Leon erratum fix: Insert a NOP instruction after " |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 189 | "every single-cycle load instruction when the next instruction is " |
| 190 | "another load/store instruction"; |
| 191 | } |
| 192 | }; |
| 193 | |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 194 | class LLVM_LIBRARY_VISIBILITY InsertNOPsLoadStore |
| 195 | : public LEONMachineFunctionPass { |
| 196 | public: |
| 197 | static char ID; |
| 198 | |
| 199 | InsertNOPsLoadStore(TargetMachine &tm); |
| 200 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 201 | |
| 202 | const char *getPassName() const override { |
Chris Dewhurst | 829f8ef | 2016-08-12 09:34:26 +0000 | [diff] [blame] | 203 | return "InsertNOPsLoadStore: Leon Erratum Fix: Insert NOPs between " |
Chris Dewhurst | 3202f06 | 2016-07-08 15:33:56 +0000 | [diff] [blame] | 204 | "single-precision loads and the store, so the number of " |
| 205 | "instructions between is 4"; |
| 206 | } |
| 207 | }; |
| 208 | } // namespace lllvm |
Chris Dewhurst | 4f7cac3 | 2016-05-23 10:56:36 +0000 | [diff] [blame] | 209 | |
Chris Dewhurst | 5047f24 | 2016-06-27 14:35:07 +0000 | [diff] [blame] | 210 | #endif // LLVM_LIB_TARGET_SPARC_LEON_PASSES_H |