Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 1 | //===-- SIWholeQuadMode.cpp - enter and suspend whole quad mode -----------===// |
| 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 This pass adds instructions to enable whole quad mode for pixel |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 12 | /// shaders, and whole wavefront mode for all programs. |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 13 | /// |
| 14 | /// Whole quad mode is required for derivative computations, but it interferes |
| 15 | /// with shader side effects (stores and atomics). This pass is run on the |
| 16 | /// scheduled machine IR but before register coalescing, so that machine SSA is |
| 17 | /// available for analysis. It ensures that WQM is enabled when necessary, but |
| 18 | /// disabled around stores and atomics. |
| 19 | /// |
| 20 | /// When necessary, this pass creates a function prolog |
| 21 | /// |
| 22 | /// S_MOV_B64 LiveMask, EXEC |
| 23 | /// S_WQM_B64 EXEC, EXEC |
| 24 | /// |
| 25 | /// to enter WQM at the top of the function and surrounds blocks of Exact |
| 26 | /// instructions by |
| 27 | /// |
| 28 | /// S_AND_SAVEEXEC_B64 Tmp, LiveMask |
| 29 | /// ... |
| 30 | /// S_MOV_B64 EXEC, Tmp |
| 31 | /// |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 32 | /// We also compute when a sequence of instructions requires Whole Wavefront |
| 33 | /// Mode (WWM) and insert instructions to save and restore it: |
| 34 | /// |
| 35 | /// S_OR_SAVEEXEC_B64 Tmp, -1 |
| 36 | /// ... |
| 37 | /// S_MOV_B64 EXEC, Tmp |
| 38 | /// |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 39 | /// In order to avoid excessive switching during sequences of Exact |
| 40 | /// instructions, the pass first analyzes which instructions must be run in WQM |
| 41 | /// (aka which instructions produce values that lead to derivative |
| 42 | /// computations). |
| 43 | /// |
| 44 | /// Basic blocks are always exited in WQM as long as some successor needs WQM. |
| 45 | /// |
| 46 | /// There is room for improvement given better control flow analysis: |
| 47 | /// |
| 48 | /// (1) at the top level (outside of control flow statements, and as long as |
| 49 | /// kill hasn't been used), one SGPR can be saved by recovering WQM from |
| 50 | /// the LiveMask (this is implemented for the entry block). |
| 51 | /// |
| 52 | /// (2) when entire regions (e.g. if-else blocks or entire loops) only |
| 53 | /// consist of exact and don't-care instructions, the switch only has to |
| 54 | /// be done at the entry and exit points rather than potentially in each |
| 55 | /// block of the region. |
| 56 | /// |
| 57 | //===----------------------------------------------------------------------===// |
| 58 | |
| 59 | #include "AMDGPU.h" |
| 60 | #include "AMDGPUSubtarget.h" |
| 61 | #include "SIInstrInfo.h" |
| 62 | #include "SIMachineFunctionInfo.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 63 | #include "llvm/ADT/DenseMap.h" |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 64 | #include "llvm/ADT/PostOrderIterator.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 65 | #include "llvm/ADT/SmallVector.h" |
| 66 | #include "llvm/ADT/StringRef.h" |
| 67 | #include "llvm/CodeGen/LiveInterval.h" |
Matthias Braun | f842297 | 2017-12-13 02:51:04 +0000 | [diff] [blame] | 68 | #include "llvm/CodeGen/LiveIntervals.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 69 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 70 | #include "llvm/CodeGen/MachineFunction.h" |
| 71 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 72 | #include "llvm/CodeGen/MachineInstr.h" |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 73 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 74 | #include "llvm/CodeGen/MachineOperand.h" |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 75 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 76 | #include "llvm/CodeGen/SlotIndexes.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 77 | #include "llvm/CodeGen/TargetRegisterInfo.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 78 | #include "llvm/IR/CallingConv.h" |
| 79 | #include "llvm/IR/DebugLoc.h" |
| 80 | #include "llvm/MC/MCRegisterInfo.h" |
| 81 | #include "llvm/Pass.h" |
| 82 | #include "llvm/Support/Debug.h" |
| 83 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 84 | #include <cassert> |
| 85 | #include <vector> |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 86 | |
| 87 | using namespace llvm; |
| 88 | |
| 89 | #define DEBUG_TYPE "si-wqm" |
| 90 | |
| 91 | namespace { |
| 92 | |
| 93 | enum { |
| 94 | StateWQM = 0x1, |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 95 | StateWWM = 0x2, |
| 96 | StateExact = 0x4, |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 99 | struct PrintState { |
| 100 | public: |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 101 | int State; |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 102 | |
| 103 | explicit PrintState(int State) : State(State) {} |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
Eric Christopher | 3148a1b | 2017-11-16 03:18:15 +0000 | [diff] [blame] | 106 | #ifndef NDEBUG |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 107 | static raw_ostream &operator<<(raw_ostream &OS, const PrintState &PS) { |
| 108 | if (PS.State & StateWQM) |
| 109 | OS << "WQM"; |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 110 | if (PS.State & StateWWM) { |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 111 | if (PS.State & StateWQM) |
| 112 | OS << '|'; |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 113 | OS << "WWM"; |
| 114 | } |
| 115 | if (PS.State & StateExact) { |
| 116 | if (PS.State & (StateWQM | StateWWM)) |
| 117 | OS << '|'; |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 118 | OS << "Exact"; |
| 119 | } |
| 120 | |
| 121 | return OS; |
| 122 | } |
Eric Christopher | 3148a1b | 2017-11-16 03:18:15 +0000 | [diff] [blame] | 123 | #endif |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 124 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 125 | struct InstrInfo { |
| 126 | char Needs = 0; |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 127 | char Disabled = 0; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 128 | char OutNeeds = 0; |
| 129 | }; |
| 130 | |
| 131 | struct BlockInfo { |
| 132 | char Needs = 0; |
| 133 | char InNeeds = 0; |
| 134 | char OutNeeds = 0; |
| 135 | }; |
| 136 | |
| 137 | struct WorkItem { |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 138 | MachineBasicBlock *MBB = nullptr; |
| 139 | MachineInstr *MI = nullptr; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 140 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 141 | WorkItem() = default; |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 142 | WorkItem(MachineBasicBlock *MBB) : MBB(MBB) {} |
| 143 | WorkItem(MachineInstr *MI) : MI(MI) {} |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | class SIWholeQuadMode : public MachineFunctionPass { |
| 147 | private: |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 148 | CallingConv::ID CallingConv; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 149 | const SIInstrInfo *TII; |
| 150 | const SIRegisterInfo *TRI; |
| 151 | MachineRegisterInfo *MRI; |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 152 | LiveIntervals *LIS; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 153 | |
| 154 | DenseMap<const MachineInstr *, InstrInfo> Instructions; |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 155 | DenseMap<MachineBasicBlock *, BlockInfo> Blocks; |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 156 | SmallVector<MachineInstr *, 1> LiveMaskQueries; |
Connor Abbott | 8c217d0 | 2017-08-04 18:36:49 +0000 | [diff] [blame] | 157 | SmallVector<MachineInstr *, 4> LowerToCopyInstrs; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 158 | |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 159 | void printInfo(); |
| 160 | |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 161 | void markInstruction(MachineInstr &MI, char Flag, |
| 162 | std::vector<WorkItem> &Worklist); |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 163 | void markInstructionUses(const MachineInstr &MI, char Flag, |
| 164 | std::vector<WorkItem> &Worklist); |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 165 | char scanInstructions(MachineFunction &MF, std::vector<WorkItem> &Worklist); |
| 166 | void propagateInstruction(MachineInstr &MI, std::vector<WorkItem> &Worklist); |
| 167 | void propagateBlock(MachineBasicBlock &MBB, std::vector<WorkItem> &Worklist); |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 168 | char analyzeFunction(MachineFunction &MF); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 169 | |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 170 | bool requiresCorrectState(const MachineInstr &MI) const; |
| 171 | |
| 172 | MachineBasicBlock::iterator saveSCC(MachineBasicBlock &MBB, |
| 173 | MachineBasicBlock::iterator Before); |
| 174 | MachineBasicBlock::iterator |
| 175 | prepareInsertion(MachineBasicBlock &MBB, MachineBasicBlock::iterator First, |
| 176 | MachineBasicBlock::iterator Last, bool PreferLast, |
| 177 | bool SaveSCC); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 178 | void toExact(MachineBasicBlock &MBB, MachineBasicBlock::iterator Before, |
| 179 | unsigned SaveWQM, unsigned LiveMaskReg); |
| 180 | void toWQM(MachineBasicBlock &MBB, MachineBasicBlock::iterator Before, |
| 181 | unsigned SavedWQM); |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 182 | void toWWM(MachineBasicBlock &MBB, MachineBasicBlock::iterator Before, |
| 183 | unsigned SaveOrig); |
| 184 | void fromWWM(MachineBasicBlock &MBB, MachineBasicBlock::iterator Before, |
| 185 | unsigned SavedOrig); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 186 | void processBlock(MachineBasicBlock &MBB, unsigned LiveMaskReg, bool isEntry); |
| 187 | |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 188 | void lowerLiveMaskQueries(unsigned LiveMaskReg); |
Connor Abbott | 8c217d0 | 2017-08-04 18:36:49 +0000 | [diff] [blame] | 189 | void lowerCopyInstrs(); |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 190 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 191 | public: |
| 192 | static char ID; |
| 193 | |
| 194 | SIWholeQuadMode() : |
| 195 | MachineFunctionPass(ID) { } |
| 196 | |
| 197 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 198 | |
Mehdi Amini | 117296c | 2016-10-01 02:56:57 +0000 | [diff] [blame] | 199 | StringRef getPassName() const override { return "SI Whole Quad Mode"; } |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 200 | |
| 201 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 202 | AU.addRequired<LiveIntervals>(); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 203 | AU.setPreservesCFG(); |
| 204 | MachineFunctionPass::getAnalysisUsage(AU); |
| 205 | } |
| 206 | }; |
| 207 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 208 | } // end anonymous namespace |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 209 | |
| 210 | char SIWholeQuadMode::ID = 0; |
| 211 | |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 212 | INITIALIZE_PASS_BEGIN(SIWholeQuadMode, DEBUG_TYPE, "SI Whole Quad Mode", false, |
| 213 | false) |
| 214 | INITIALIZE_PASS_DEPENDENCY(LiveIntervals) |
| 215 | INITIALIZE_PASS_END(SIWholeQuadMode, DEBUG_TYPE, "SI Whole Quad Mode", false, |
| 216 | false) |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 217 | |
| 218 | char &llvm::SIWholeQuadModeID = SIWholeQuadMode::ID; |
| 219 | |
| 220 | FunctionPass *llvm::createSIWholeQuadModePass() { |
| 221 | return new SIWholeQuadMode; |
| 222 | } |
| 223 | |
Eric Christopher | 3148a1b | 2017-11-16 03:18:15 +0000 | [diff] [blame] | 224 | #ifndef NDEBUG |
Eric Christopher | 6348188 | 2017-11-16 03:25:02 +0000 | [diff] [blame] | 225 | LLVM_DUMP_METHOD void SIWholeQuadMode::printInfo() { |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 226 | for (const auto &BII : Blocks) { |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 227 | dbgs() << "\n" |
| 228 | << printMBBReference(*BII.first) << ":\n" |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 229 | << " InNeeds = " << PrintState(BII.second.InNeeds) |
| 230 | << ", Needs = " << PrintState(BII.second.Needs) |
| 231 | << ", OutNeeds = " << PrintState(BII.second.OutNeeds) << "\n\n"; |
| 232 | |
| 233 | for (const MachineInstr &MI : *BII.first) { |
| 234 | auto III = Instructions.find(&MI); |
| 235 | if (III == Instructions.end()) |
| 236 | continue; |
| 237 | |
| 238 | dbgs() << " " << MI << " Needs = " << PrintState(III->second.Needs) |
| 239 | << ", OutNeeds = " << PrintState(III->second.OutNeeds) << '\n'; |
| 240 | } |
| 241 | } |
| 242 | } |
Eric Christopher | 3148a1b | 2017-11-16 03:18:15 +0000 | [diff] [blame] | 243 | #endif |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 244 | |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 245 | void SIWholeQuadMode::markInstruction(MachineInstr &MI, char Flag, |
| 246 | std::vector<WorkItem> &Worklist) { |
| 247 | InstrInfo &II = Instructions[&MI]; |
| 248 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 249 | assert(!(Flag & StateExact) && Flag != 0); |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 250 | |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 251 | // Remove any disabled states from the flag. The user that required it gets |
| 252 | // an undefined value in the helper lanes. For example, this can happen if |
| 253 | // the result of an atomic is used by instruction that requires WQM, where |
| 254 | // ignoring the request for WQM is correct as per the relevant specs. |
| 255 | Flag &= ~II.Disabled; |
| 256 | |
| 257 | // Ignore if the flag is already encompassed by the existing needs, or we |
| 258 | // just disabled everything. |
| 259 | if ((II.Needs & Flag) == Flag) |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 260 | return; |
| 261 | |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 262 | II.Needs |= Flag; |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 263 | Worklist.push_back(&MI); |
| 264 | } |
| 265 | |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 266 | /// Mark all instructions defining the uses in \p MI with \p Flag. |
| 267 | void SIWholeQuadMode::markInstructionUses(const MachineInstr &MI, char Flag, |
| 268 | std::vector<WorkItem> &Worklist) { |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 269 | for (const MachineOperand &Use : MI.uses()) { |
| 270 | if (!Use.isReg() || !Use.isUse()) |
| 271 | continue; |
| 272 | |
| 273 | unsigned Reg = Use.getReg(); |
| 274 | |
| 275 | // Handle physical registers that we need to track; this is mostly relevant |
| 276 | // for VCC, which can appear as the (implicit) input of a uniform branch, |
| 277 | // e.g. when a loop counter is stored in a VGPR. |
| 278 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) { |
| 279 | if (Reg == AMDGPU::EXEC) |
| 280 | continue; |
| 281 | |
| 282 | for (MCRegUnitIterator RegUnit(Reg, TRI); RegUnit.isValid(); ++RegUnit) { |
| 283 | LiveRange &LR = LIS->getRegUnit(*RegUnit); |
| 284 | const VNInfo *Value = LR.Query(LIS->getInstructionIndex(MI)).valueIn(); |
| 285 | if (!Value) |
| 286 | continue; |
| 287 | |
| 288 | // Since we're in machine SSA, we do not need to track physical |
| 289 | // registers across basic blocks. |
| 290 | if (Value->isPHIDef()) |
| 291 | continue; |
| 292 | |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 293 | markInstruction(*LIS->getInstructionFromIndex(Value->def), Flag, |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 294 | Worklist); |
| 295 | } |
| 296 | |
| 297 | continue; |
| 298 | } |
| 299 | |
| 300 | for (MachineInstr &DefMI : MRI->def_instructions(Use.getReg())) |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 301 | markInstruction(DefMI, Flag, Worklist); |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 305 | // Scan instructions to determine which ones require an Exact execmask and |
| 306 | // which ones seed WQM requirements. |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 307 | char SIWholeQuadMode::scanInstructions(MachineFunction &MF, |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 308 | std::vector<WorkItem> &Worklist) { |
| 309 | char GlobalFlags = 0; |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 310 | bool WQMOutputs = MF.getFunction().hasFnAttribute("amdgpu-ps-wqm-outputs"); |
Connor Abbott | 66b9bd6 | 2017-08-04 18:36:54 +0000 | [diff] [blame] | 311 | SmallVector<MachineInstr *, 4> SetInactiveInstrs; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 312 | |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 313 | // We need to visit the basic blocks in reverse post-order so that we visit |
| 314 | // defs before uses, in particular so that we don't accidentally mark an |
| 315 | // instruction as needing e.g. WQM before visiting it and realizing it needs |
| 316 | // WQM disabled. |
| 317 | ReversePostOrderTraversal<MachineFunction *> RPOT(&MF); |
| 318 | for (auto BI = RPOT.begin(), BE = RPOT.end(); BI != BE; ++BI) { |
| 319 | MachineBasicBlock &MBB = **BI; |
| 320 | BlockInfo &BBI = Blocks[&MBB]; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 321 | |
| 322 | for (auto II = MBB.begin(), IE = MBB.end(); II != IE; ++II) { |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 323 | MachineInstr &MI = *II; |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 324 | InstrInfo &III = Instructions[&MI]; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 325 | unsigned Opcode = MI.getOpcode(); |
Nicolai Haehnle | c00e03b | 2016-06-07 21:37:17 +0000 | [diff] [blame] | 326 | char Flags = 0; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 327 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 328 | if (TII->isDS(Opcode) && CallingConv == CallingConv::AMDGPU_PS) { |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 329 | Flags = StateWQM; |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 330 | } else if (TII->isWQM(Opcode)) { |
| 331 | // Sampling instructions don't need to produce results for all pixels |
| 332 | // in a quad, they just require all inputs of a quad to have been |
| 333 | // computed for derivatives. |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 334 | markInstructionUses(MI, StateWQM, Worklist); |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 335 | GlobalFlags |= StateWQM; |
| 336 | continue; |
Connor Abbott | 8c217d0 | 2017-08-04 18:36:49 +0000 | [diff] [blame] | 337 | } else if (Opcode == AMDGPU::WQM) { |
| 338 | // The WQM intrinsic requires its output to have all the helper lanes |
| 339 | // correct, so we need it to be in WQM. |
| 340 | Flags = StateWQM; |
| 341 | LowerToCopyInstrs.push_back(&MI); |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 342 | } else if (Opcode == AMDGPU::WWM) { |
| 343 | // The WWM intrinsic doesn't make the same guarantee, and plus it needs |
| 344 | // to be executed in WQM or Exact so that its copy doesn't clobber |
| 345 | // inactive lanes. |
| 346 | markInstructionUses(MI, StateWWM, Worklist); |
| 347 | GlobalFlags |= StateWWM; |
| 348 | LowerToCopyInstrs.push_back(&MI); |
| 349 | continue; |
Connor Abbott | 66b9bd6 | 2017-08-04 18:36:54 +0000 | [diff] [blame] | 350 | } else if (Opcode == AMDGPU::V_SET_INACTIVE_B32 || |
| 351 | Opcode == AMDGPU::V_SET_INACTIVE_B64) { |
| 352 | III.Disabled = StateWWM; |
| 353 | MachineOperand &Inactive = MI.getOperand(2); |
| 354 | if (Inactive.isReg()) { |
| 355 | if (Inactive.isUndef()) { |
| 356 | LowerToCopyInstrs.push_back(&MI); |
| 357 | } else { |
| 358 | unsigned Reg = Inactive.getReg(); |
| 359 | if (TargetRegisterInfo::isVirtualRegister(Reg)) { |
| 360 | for (MachineInstr &DefMI : MRI->def_instructions(Reg)) |
| 361 | markInstruction(DefMI, StateWWM, Worklist); |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | SetInactiveInstrs.push_back(&MI); |
| 366 | continue; |
Nicolai Haehnle | 8a482b3 | 2016-08-02 19:31:14 +0000 | [diff] [blame] | 367 | } else if (TII->isDisableWQM(MI)) { |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 368 | BBI.Needs |= StateExact; |
| 369 | if (!(BBI.InNeeds & StateExact)) { |
| 370 | BBI.InNeeds |= StateExact; |
| 371 | Worklist.push_back(&MBB); |
| 372 | } |
| 373 | GlobalFlags |= StateExact; |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 374 | III.Disabled = StateWQM | StateWWM; |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 375 | continue; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 376 | } else { |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 377 | if (Opcode == AMDGPU::SI_PS_LIVE) { |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 378 | LiveMaskQueries.push_back(&MI); |
Nicolai Haehnle | c00e03b | 2016-06-07 21:37:17 +0000 | [diff] [blame] | 379 | } else if (WQMOutputs) { |
| 380 | // The function is in machine SSA form, which means that physical |
| 381 | // VGPRs correspond to shader inputs and outputs. Inputs are |
| 382 | // only used, outputs are only defined. |
| 383 | for (const MachineOperand &MO : MI.defs()) { |
| 384 | if (!MO.isReg()) |
| 385 | continue; |
| 386 | |
| 387 | unsigned Reg = MO.getReg(); |
| 388 | |
| 389 | if (!TRI->isVirtualRegister(Reg) && |
| 390 | TRI->hasVGPRs(TRI->getPhysRegClass(Reg))) { |
| 391 | Flags = StateWQM; |
| 392 | break; |
| 393 | } |
| 394 | } |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Nicolai Haehnle | c00e03b | 2016-06-07 21:37:17 +0000 | [diff] [blame] | 397 | if (!Flags) |
| 398 | continue; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 401 | markInstruction(MI, Flags, Worklist); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 402 | GlobalFlags |= Flags; |
| 403 | } |
| 404 | } |
| 405 | |
Connor Abbott | 66b9bd6 | 2017-08-04 18:36:54 +0000 | [diff] [blame] | 406 | // Mark sure that any SET_INACTIVE instructions are computed in WQM if WQM is |
| 407 | // ever used anywhere in the function. This implements the corresponding |
| 408 | // semantics of @llvm.amdgcn.set.inactive. |
| 409 | if (GlobalFlags & StateWQM) { |
| 410 | for (MachineInstr *MI : SetInactiveInstrs) |
| 411 | markInstruction(*MI, StateWQM, Worklist); |
| 412 | } |
| 413 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 414 | return GlobalFlags; |
| 415 | } |
| 416 | |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 417 | void SIWholeQuadMode::propagateInstruction(MachineInstr &MI, |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 418 | std::vector<WorkItem>& Worklist) { |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 419 | MachineBasicBlock *MBB = MI.getParent(); |
Nicolai Haehnle | 0a33abd | 2016-03-21 22:54:02 +0000 | [diff] [blame] | 420 | InstrInfo II = Instructions[&MI]; // take a copy to prevent dangling references |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 421 | BlockInfo &BI = Blocks[MBB]; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 422 | |
Nicolai Haehnle | 8a482b3 | 2016-08-02 19:31:14 +0000 | [diff] [blame] | 423 | // Control flow-type instructions and stores to temporary memory that are |
| 424 | // followed by WQM computations must themselves be in WQM. |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 425 | if ((II.OutNeeds & StateWQM) && !(II.Disabled & StateWQM) && |
Nicolai Haehnle | 8a482b3 | 2016-08-02 19:31:14 +0000 | [diff] [blame] | 426 | (MI.isTerminator() || (TII->usesVM_CNT(MI) && MI.mayStore()))) { |
Nicolai Haehnle | 0a33abd | 2016-03-21 22:54:02 +0000 | [diff] [blame] | 427 | Instructions[&MI].Needs = StateWQM; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 428 | II.Needs = StateWQM; |
Nicolai Haehnle | 0a33abd | 2016-03-21 22:54:02 +0000 | [diff] [blame] | 429 | } |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 430 | |
| 431 | // Propagate to block level |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 432 | if (II.Needs & StateWQM) { |
| 433 | BI.Needs |= StateWQM; |
| 434 | if (!(BI.InNeeds & StateWQM)) { |
| 435 | BI.InNeeds |= StateWQM; |
| 436 | Worklist.push_back(MBB); |
| 437 | } |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | // Propagate backwards within block |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 441 | if (MachineInstr *PrevMI = MI.getPrevNode()) { |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 442 | char InNeeds = (II.Needs & ~StateWWM) | II.OutNeeds; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 443 | if (!PrevMI->isPHI()) { |
| 444 | InstrInfo &PrevII = Instructions[PrevMI]; |
| 445 | if ((PrevII.OutNeeds | InNeeds) != PrevII.OutNeeds) { |
| 446 | PrevII.OutNeeds |= InNeeds; |
| 447 | Worklist.push_back(PrevMI); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | // Propagate WQM flag to instruction inputs |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 453 | assert(!(II.Needs & StateExact)); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 454 | |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 455 | if (II.Needs != 0) |
| 456 | markInstructionUses(MI, II.Needs, Worklist); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 459 | void SIWholeQuadMode::propagateBlock(MachineBasicBlock &MBB, |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 460 | std::vector<WorkItem>& Worklist) { |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 461 | BlockInfo BI = Blocks[&MBB]; // Make a copy to prevent dangling references. |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 462 | |
| 463 | // Propagate through instructions |
| 464 | if (!MBB.empty()) { |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 465 | MachineInstr *LastMI = &*MBB.rbegin(); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 466 | InstrInfo &LastII = Instructions[LastMI]; |
| 467 | if ((LastII.OutNeeds | BI.OutNeeds) != LastII.OutNeeds) { |
| 468 | LastII.OutNeeds |= BI.OutNeeds; |
| 469 | Worklist.push_back(LastMI); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | // Predecessor blocks must provide for our WQM/Exact needs. |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 474 | for (MachineBasicBlock *Pred : MBB.predecessors()) { |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 475 | BlockInfo &PredBI = Blocks[Pred]; |
| 476 | if ((PredBI.OutNeeds | BI.InNeeds) == PredBI.OutNeeds) |
| 477 | continue; |
| 478 | |
| 479 | PredBI.OutNeeds |= BI.InNeeds; |
| 480 | PredBI.InNeeds |= BI.InNeeds; |
| 481 | Worklist.push_back(Pred); |
| 482 | } |
| 483 | |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 484 | // All successors must be prepared to accept the same set of WQM/Exact data. |
| 485 | for (MachineBasicBlock *Succ : MBB.successors()) { |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 486 | BlockInfo &SuccBI = Blocks[Succ]; |
| 487 | if ((SuccBI.InNeeds | BI.OutNeeds) == SuccBI.InNeeds) |
| 488 | continue; |
| 489 | |
| 490 | SuccBI.InNeeds |= BI.OutNeeds; |
| 491 | Worklist.push_back(Succ); |
| 492 | } |
| 493 | } |
| 494 | |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 495 | char SIWholeQuadMode::analyzeFunction(MachineFunction &MF) { |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 496 | std::vector<WorkItem> Worklist; |
| 497 | char GlobalFlags = scanInstructions(MF, Worklist); |
| 498 | |
| 499 | while (!Worklist.empty()) { |
| 500 | WorkItem WI = Worklist.back(); |
| 501 | Worklist.pop_back(); |
| 502 | |
| 503 | if (WI.MI) |
| 504 | propagateInstruction(*WI.MI, Worklist); |
| 505 | else |
| 506 | propagateBlock(*WI.MBB, Worklist); |
| 507 | } |
| 508 | |
| 509 | return GlobalFlags; |
| 510 | } |
| 511 | |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 512 | /// Whether \p MI really requires the exec state computed during analysis. |
| 513 | /// |
| 514 | /// Scalar instructions must occasionally be marked WQM for correct propagation |
| 515 | /// (e.g. thread masks leading up to branches), but when it comes to actual |
| 516 | /// execution, they don't care about EXEC. |
| 517 | bool SIWholeQuadMode::requiresCorrectState(const MachineInstr &MI) const { |
| 518 | if (MI.isTerminator()) |
| 519 | return true; |
| 520 | |
| 521 | // Skip instructions that are not affected by EXEC |
| 522 | if (TII->isScalarUnit(MI)) |
| 523 | return false; |
| 524 | |
| 525 | // Generic instructions such as COPY will either disappear by register |
| 526 | // coalescing or be lowered to SALU or VALU instructions. |
| 527 | if (MI.isTransient()) { |
| 528 | if (MI.getNumExplicitOperands() >= 1) { |
| 529 | const MachineOperand &Op = MI.getOperand(0); |
| 530 | if (Op.isReg()) { |
| 531 | if (TRI->isSGPRReg(*MRI, Op.getReg())) { |
| 532 | // SGPR instructions are not affected by EXEC |
| 533 | return false; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | return true; |
| 540 | } |
| 541 | |
| 542 | MachineBasicBlock::iterator |
| 543 | SIWholeQuadMode::saveSCC(MachineBasicBlock &MBB, |
| 544 | MachineBasicBlock::iterator Before) { |
Marek Olsak | 79c0587 | 2016-11-25 17:37:09 +0000 | [diff] [blame] | 545 | unsigned SaveReg = MRI->createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass); |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 546 | |
| 547 | MachineInstr *Save = |
| 548 | BuildMI(MBB, Before, DebugLoc(), TII->get(AMDGPU::COPY), SaveReg) |
| 549 | .addReg(AMDGPU::SCC); |
| 550 | MachineInstr *Restore = |
| 551 | BuildMI(MBB, Before, DebugLoc(), TII->get(AMDGPU::COPY), AMDGPU::SCC) |
| 552 | .addReg(SaveReg); |
| 553 | |
| 554 | LIS->InsertMachineInstrInMaps(*Save); |
| 555 | LIS->InsertMachineInstrInMaps(*Restore); |
| 556 | LIS->createAndComputeVirtRegInterval(SaveReg); |
| 557 | |
| 558 | return Restore; |
| 559 | } |
| 560 | |
| 561 | // Return an iterator in the (inclusive) range [First, Last] at which |
| 562 | // instructions can be safely inserted, keeping in mind that some of the |
| 563 | // instructions we want to add necessarily clobber SCC. |
| 564 | MachineBasicBlock::iterator SIWholeQuadMode::prepareInsertion( |
| 565 | MachineBasicBlock &MBB, MachineBasicBlock::iterator First, |
| 566 | MachineBasicBlock::iterator Last, bool PreferLast, bool SaveSCC) { |
| 567 | if (!SaveSCC) |
| 568 | return PreferLast ? Last : First; |
| 569 | |
| 570 | LiveRange &LR = LIS->getRegUnit(*MCRegUnitIterator(AMDGPU::SCC, TRI)); |
| 571 | auto MBBE = MBB.end(); |
| 572 | SlotIndex FirstIdx = First != MBBE ? LIS->getInstructionIndex(*First) |
| 573 | : LIS->getMBBEndIdx(&MBB); |
| 574 | SlotIndex LastIdx = |
| 575 | Last != MBBE ? LIS->getInstructionIndex(*Last) : LIS->getMBBEndIdx(&MBB); |
| 576 | SlotIndex Idx = PreferLast ? LastIdx : FirstIdx; |
| 577 | const LiveRange::Segment *S; |
| 578 | |
| 579 | for (;;) { |
| 580 | S = LR.getSegmentContaining(Idx); |
| 581 | if (!S) |
| 582 | break; |
| 583 | |
| 584 | if (PreferLast) { |
| 585 | SlotIndex Next = S->start.getBaseIndex(); |
| 586 | if (Next < FirstIdx) |
| 587 | break; |
| 588 | Idx = Next; |
| 589 | } else { |
| 590 | SlotIndex Next = S->end.getNextIndex().getBaseIndex(); |
| 591 | if (Next > LastIdx) |
| 592 | break; |
| 593 | Idx = Next; |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | MachineBasicBlock::iterator MBBI; |
| 598 | |
| 599 | if (MachineInstr *MI = LIS->getInstructionFromIndex(Idx)) |
| 600 | MBBI = MI; |
| 601 | else { |
| 602 | assert(Idx == LIS->getMBBEndIdx(&MBB)); |
| 603 | MBBI = MBB.end(); |
| 604 | } |
| 605 | |
| 606 | if (S) |
| 607 | MBBI = saveSCC(MBB, MBBI); |
| 608 | |
| 609 | return MBBI; |
| 610 | } |
| 611 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 612 | void SIWholeQuadMode::toExact(MachineBasicBlock &MBB, |
| 613 | MachineBasicBlock::iterator Before, |
Nicolai Haehnle | a56e6b6 | 2016-03-21 20:39:24 +0000 | [diff] [blame] | 614 | unsigned SaveWQM, unsigned LiveMaskReg) { |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 615 | MachineInstr *MI; |
| 616 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 617 | if (SaveWQM) { |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 618 | MI = BuildMI(MBB, Before, DebugLoc(), TII->get(AMDGPU::S_AND_SAVEEXEC_B64), |
| 619 | SaveWQM) |
| 620 | .addReg(LiveMaskReg); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 621 | } else { |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 622 | MI = BuildMI(MBB, Before, DebugLoc(), TII->get(AMDGPU::S_AND_B64), |
| 623 | AMDGPU::EXEC) |
| 624 | .addReg(AMDGPU::EXEC) |
| 625 | .addReg(LiveMaskReg); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 626 | } |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 627 | |
| 628 | LIS->InsertMachineInstrInMaps(*MI); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | void SIWholeQuadMode::toWQM(MachineBasicBlock &MBB, |
| 632 | MachineBasicBlock::iterator Before, |
Nicolai Haehnle | a56e6b6 | 2016-03-21 20:39:24 +0000 | [diff] [blame] | 633 | unsigned SavedWQM) { |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 634 | MachineInstr *MI; |
| 635 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 636 | if (SavedWQM) { |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 637 | MI = BuildMI(MBB, Before, DebugLoc(), TII->get(AMDGPU::COPY), AMDGPU::EXEC) |
| 638 | .addReg(SavedWQM); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 639 | } else { |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 640 | MI = BuildMI(MBB, Before, DebugLoc(), TII->get(AMDGPU::S_WQM_B64), |
| 641 | AMDGPU::EXEC) |
| 642 | .addReg(AMDGPU::EXEC); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 643 | } |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 644 | |
| 645 | LIS->InsertMachineInstrInMaps(*MI); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 648 | void SIWholeQuadMode::toWWM(MachineBasicBlock &MBB, |
| 649 | MachineBasicBlock::iterator Before, |
| 650 | unsigned SaveOrig) { |
| 651 | MachineInstr *MI; |
| 652 | |
| 653 | assert(SaveOrig); |
| 654 | MI = BuildMI(MBB, Before, DebugLoc(), TII->get(AMDGPU::S_OR_SAVEEXEC_B64), |
| 655 | SaveOrig) |
| 656 | .addImm(-1); |
| 657 | LIS->InsertMachineInstrInMaps(*MI); |
| 658 | } |
| 659 | |
| 660 | void SIWholeQuadMode::fromWWM(MachineBasicBlock &MBB, |
| 661 | MachineBasicBlock::iterator Before, |
| 662 | unsigned SavedOrig) { |
| 663 | MachineInstr *MI; |
| 664 | |
| 665 | assert(SavedOrig); |
| 666 | MI = BuildMI(MBB, Before, DebugLoc(), TII->get(AMDGPU::EXIT_WWM), AMDGPU::EXEC) |
| 667 | .addReg(SavedOrig); |
| 668 | LIS->InsertMachineInstrInMaps(*MI); |
| 669 | } |
| 670 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 671 | void SIWholeQuadMode::processBlock(MachineBasicBlock &MBB, unsigned LiveMaskReg, |
| 672 | bool isEntry) { |
| 673 | auto BII = Blocks.find(&MBB); |
| 674 | if (BII == Blocks.end()) |
| 675 | return; |
| 676 | |
| 677 | const BlockInfo &BI = BII->second; |
| 678 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 679 | // This is a non-entry block that is WQM throughout, so no need to do |
| 680 | // anything. |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 681 | if (!isEntry && BI.Needs == StateWQM && BI.OutNeeds != StateExact) |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 682 | return; |
| 683 | |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 684 | DEBUG(dbgs() << "\nProcessing block " << printMBBReference(MBB) << ":\n"); |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 685 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 686 | unsigned SavedWQMReg = 0; |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 687 | unsigned SavedNonWWMReg = 0; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 688 | bool WQMFromExec = isEntry; |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 689 | char State = (isEntry || !(BI.InNeeds & StateWQM)) ? StateExact : StateWQM; |
| 690 | char NonWWMState = 0; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 691 | |
| 692 | auto II = MBB.getFirstNonPHI(), IE = MBB.end(); |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 693 | if (isEntry) |
| 694 | ++II; // Skip the instruction that saves LiveMask |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 695 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 696 | // This stores the first instruction where it's safe to switch from WQM to |
| 697 | // Exact or vice versa. |
| 698 | MachineBasicBlock::iterator FirstWQM = IE; |
| 699 | |
| 700 | // This stores the first instruction where it's safe to switch from WWM to |
| 701 | // Exact/WQM or to switch to WWM. It must always be the same as, or after, |
| 702 | // FirstWQM since if it's safe to switch to/from WWM, it must be safe to |
| 703 | // switch to/from WQM as well. |
| 704 | MachineBasicBlock::iterator FirstWWM = IE; |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 705 | for (;;) { |
| 706 | MachineBasicBlock::iterator Next = II; |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 707 | char Needs = StateExact | StateWQM; // WWM is disabled by default |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 708 | char OutNeeds = 0; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 709 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 710 | if (FirstWQM == IE) |
| 711 | FirstWQM = II; |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 712 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 713 | if (FirstWWM == IE) |
| 714 | FirstWWM = II; |
| 715 | |
| 716 | // First, figure out the allowed states (Needs) based on the propagated |
| 717 | // flags. |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 718 | if (II != IE) { |
| 719 | MachineInstr &MI = *II; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 720 | |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 721 | if (requiresCorrectState(MI)) { |
| 722 | auto III = Instructions.find(&MI); |
| 723 | if (III != Instructions.end()) { |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 724 | if (III->second.Needs & StateWWM) |
| 725 | Needs = StateWWM; |
| 726 | else if (III->second.Needs & StateWQM) |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 727 | Needs = StateWQM; |
| 728 | else |
| 729 | Needs &= ~III->second.Disabled; |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 730 | OutNeeds = III->second.OutNeeds; |
| 731 | } |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 732 | } else { |
| 733 | // If the instruction doesn't actually need a correct EXEC, then we can |
| 734 | // safely leave WWM enabled. |
| 735 | Needs = StateExact | StateWQM | StateWWM; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 738 | if (MI.isTerminator() && OutNeeds == StateExact) |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 739 | Needs = StateExact; |
| 740 | |
| 741 | if (MI.getOpcode() == AMDGPU::SI_ELSE && BI.OutNeeds == StateExact) |
| 742 | MI.getOperand(3).setImm(1); |
| 743 | |
| 744 | ++Next; |
| 745 | } else { |
| 746 | // End of basic block |
| 747 | if (BI.OutNeeds & StateWQM) |
| 748 | Needs = StateWQM; |
| 749 | else if (BI.OutNeeds == StateExact) |
| 750 | Needs = StateExact; |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 751 | else |
| 752 | Needs = StateWQM | StateExact; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 753 | } |
Nicolai Haehnle | 3b57200 | 2016-07-28 11:39:24 +0000 | [diff] [blame] | 754 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 755 | // Now, transition if necessary. |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 756 | if (!(Needs & State)) { |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 757 | MachineBasicBlock::iterator First; |
| 758 | if (State == StateWWM || Needs == StateWWM) { |
| 759 | // We must switch to or from WWM |
| 760 | First = FirstWWM; |
| 761 | } else { |
| 762 | // We only need to switch to/from WQM, so we can use FirstWQM |
| 763 | First = FirstWQM; |
| 764 | } |
| 765 | |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 766 | MachineBasicBlock::iterator Before = |
| 767 | prepareInsertion(MBB, First, II, Needs == StateWQM, |
| 768 | Needs == StateExact || WQMFromExec); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 769 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 770 | if (State == StateWWM) { |
| 771 | assert(SavedNonWWMReg); |
| 772 | fromWWM(MBB, Before, SavedNonWWMReg); |
| 773 | State = NonWWMState; |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 776 | if (Needs == StateWWM) { |
| 777 | NonWWMState = State; |
| 778 | SavedNonWWMReg = MRI->createVirtualRegister(&AMDGPU::SReg_64RegClass); |
| 779 | toWWM(MBB, Before, SavedNonWWMReg); |
| 780 | State = StateWWM; |
| 781 | } else { |
| 782 | if (State == StateWQM && (Needs & StateExact) && !(Needs & StateWQM)) { |
| 783 | if (!WQMFromExec && (OutNeeds & StateWQM)) |
| 784 | SavedWQMReg = MRI->createVirtualRegister(&AMDGPU::SReg_64RegClass); |
| 785 | |
| 786 | toExact(MBB, Before, SavedWQMReg, LiveMaskReg); |
| 787 | State = StateExact; |
| 788 | } else if (State == StateExact && (Needs & StateWQM) && |
| 789 | !(Needs & StateExact)) { |
| 790 | assert(WQMFromExec == (SavedWQMReg == 0)); |
| 791 | |
| 792 | toWQM(MBB, Before, SavedWQMReg); |
| 793 | |
| 794 | if (SavedWQMReg) { |
| 795 | LIS->createAndComputeVirtRegInterval(SavedWQMReg); |
| 796 | SavedWQMReg = 0; |
| 797 | } |
| 798 | State = StateWQM; |
| 799 | } else { |
| 800 | // We can get here if we transitioned from WWM to a non-WWM state that |
| 801 | // already matches our needs, but we shouldn't need to do anything. |
| 802 | assert(Needs & State); |
| 803 | } |
| 804 | } |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 807 | if (Needs != (StateExact | StateWQM | StateWWM)) { |
| 808 | if (Needs != (StateExact | StateWQM)) |
| 809 | FirstWQM = IE; |
| 810 | FirstWWM = IE; |
| 811 | } |
Connor Abbott | de068fe | 2017-08-04 18:36:50 +0000 | [diff] [blame] | 812 | |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 813 | if (II == IE) |
| 814 | break; |
| 815 | II = Next; |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 819 | void SIWholeQuadMode::lowerLiveMaskQueries(unsigned LiveMaskReg) { |
| 820 | for (MachineInstr *MI : LiveMaskQueries) { |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 821 | const DebugLoc &DL = MI->getDebugLoc(); |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 822 | unsigned Dest = MI->getOperand(0).getReg(); |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 823 | MachineInstr *Copy = |
| 824 | BuildMI(*MI->getParent(), MI, DL, TII->get(AMDGPU::COPY), Dest) |
| 825 | .addReg(LiveMaskReg); |
| 826 | |
| 827 | LIS->ReplaceMachineInstrInMaps(*MI, *Copy); |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 828 | MI->eraseFromParent(); |
| 829 | } |
| 830 | } |
| 831 | |
Connor Abbott | 8c217d0 | 2017-08-04 18:36:49 +0000 | [diff] [blame] | 832 | void SIWholeQuadMode::lowerCopyInstrs() { |
Connor Abbott | 66b9bd6 | 2017-08-04 18:36:54 +0000 | [diff] [blame] | 833 | for (MachineInstr *MI : LowerToCopyInstrs) { |
| 834 | for (unsigned i = MI->getNumExplicitOperands() - 1; i > 1; i--) |
| 835 | MI->RemoveOperand(i); |
Connor Abbott | 8c217d0 | 2017-08-04 18:36:49 +0000 | [diff] [blame] | 836 | MI->setDesc(TII->get(AMDGPU::COPY)); |
Connor Abbott | 66b9bd6 | 2017-08-04 18:36:54 +0000 | [diff] [blame] | 837 | } |
Connor Abbott | 8c217d0 | 2017-08-04 18:36:49 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 840 | bool SIWholeQuadMode::runOnMachineFunction(MachineFunction &MF) { |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 841 | Instructions.clear(); |
| 842 | Blocks.clear(); |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 843 | LiveMaskQueries.clear(); |
Connor Abbott | 8c217d0 | 2017-08-04 18:36:49 +0000 | [diff] [blame] | 844 | LowerToCopyInstrs.clear(); |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 845 | CallingConv = MF.getFunction().getCallingConv(); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 846 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 847 | const SISubtarget &ST = MF.getSubtarget<SISubtarget>(); |
| 848 | |
| 849 | TII = ST.getInstrInfo(); |
| 850 | TRI = &TII->getRegisterInfo(); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 851 | MRI = &MF.getRegInfo(); |
Nicolai Haehnle | bef0e90 | 2016-08-02 19:17:37 +0000 | [diff] [blame] | 852 | LIS = &getAnalysis<LiveIntervals>(); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 853 | |
| 854 | char GlobalFlags = analyzeFunction(MF); |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 855 | unsigned LiveMaskReg = 0; |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 856 | if (!(GlobalFlags & StateWQM)) { |
| 857 | lowerLiveMaskQueries(AMDGPU::EXEC); |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 858 | if (!(GlobalFlags & StateWWM)) |
| 859 | return !LiveMaskQueries.empty(); |
| 860 | } else { |
| 861 | // Store a copy of the original live mask when required |
Duncan P. N. Exon Smith | 4d29511 | 2016-07-08 19:16:05 +0000 | [diff] [blame] | 862 | MachineBasicBlock &Entry = MF.front(); |
| 863 | MachineBasicBlock::iterator EntryMI = Entry.getFirstNonPHI(); |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 864 | |
Duncan P. N. Exon Smith | 4d29511 | 2016-07-08 19:16:05 +0000 | [diff] [blame] | 865 | if (GlobalFlags & StateExact || !LiveMaskQueries.empty()) { |
| 866 | LiveMaskReg = MRI->createVirtualRegister(&AMDGPU::SReg_64RegClass); |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 867 | MachineInstr *MI = BuildMI(Entry, EntryMI, DebugLoc(), |
| 868 | TII->get(AMDGPU::COPY), LiveMaskReg) |
| 869 | .addReg(AMDGPU::EXEC); |
| 870 | LIS->InsertMachineInstrInMaps(*MI); |
Duncan P. N. Exon Smith | 4d29511 | 2016-07-08 19:16:05 +0000 | [diff] [blame] | 871 | } |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 872 | |
Connor Abbott | 92638ab | 2017-08-04 18:36:52 +0000 | [diff] [blame] | 873 | lowerLiveMaskQueries(LiveMaskReg); |
| 874 | |
Duncan P. N. Exon Smith | 4d29511 | 2016-07-08 19:16:05 +0000 | [diff] [blame] | 875 | if (GlobalFlags == StateWQM) { |
| 876 | // For a shader that needs only WQM, we can just set it once. |
| 877 | BuildMI(Entry, EntryMI, DebugLoc(), TII->get(AMDGPU::S_WQM_B64), |
| 878 | AMDGPU::EXEC) |
| 879 | .addReg(AMDGPU::EXEC); |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 880 | |
Connor Abbott | 8c217d0 | 2017-08-04 18:36:49 +0000 | [diff] [blame] | 881 | lowerCopyInstrs(); |
Duncan P. N. Exon Smith | 4d29511 | 2016-07-08 19:16:05 +0000 | [diff] [blame] | 882 | // EntryMI may become invalid here |
| 883 | return true; |
| 884 | } |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Nicolai Haehnle | 3bba6a8 | 2016-09-03 12:26:38 +0000 | [diff] [blame] | 887 | DEBUG(printInfo()); |
| 888 | |
Connor Abbott | 8c217d0 | 2017-08-04 18:36:49 +0000 | [diff] [blame] | 889 | lowerCopyInstrs(); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 890 | |
Nicolai Haehnle | b0c9748 | 2016-04-22 04:04:08 +0000 | [diff] [blame] | 891 | // Handle the general case |
Matt Arsenault | 8dff86d | 2016-07-13 05:55:15 +0000 | [diff] [blame] | 892 | for (auto BII : Blocks) |
| 893 | processBlock(*BII.first, LiveMaskReg, BII.first == &*MF.begin()); |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 894 | |
Nicolai Haehnle | e58e0e3 | 2016-09-12 16:25:20 +0000 | [diff] [blame] | 895 | // Physical registers like SCC aren't tracked by default anyway, so just |
| 896 | // removing the ranges we computed is the simplest option for maintaining |
| 897 | // the analysis results. |
| 898 | LIS->removeRegUnit(*MCRegUnitIterator(AMDGPU::SCC, TRI)); |
| 899 | |
Nicolai Haehnle | 213e87f | 2016-03-21 20:28:33 +0000 | [diff] [blame] | 900 | return true; |
| 901 | } |