1 /* 2 * Copyright 2011 Christoph Bumiller 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 #include "codegen/nv50_ir.h" 24 #include "codegen/nv50_ir_build_util.h" 25 26 namespace nv50_ir { 27 28 class NVC0LegalizeSSA : public Pass 29 { 30 private: 31 virtual bool visit(BasicBlock *); 32 virtual bool visit(Function *); 33 34 // we want to insert calls to the builtin library only after optimization 35 void handleDIV(Instruction *); // integer division, modulus 36 void handleRCPRSQ(Instruction *); // double precision float recip/rsqrt 37 void handleFTZ(Instruction *); 38 void handleSET(CmpInstruction *); 39 void handleTEXLOD(TexInstruction *); 40 void handleShift(Instruction *); 41 42 protected: 43 BuildUtil bld; 44 }; 45 46 class NVC0LegalizePostRA : public Pass 47 { 48 public: 49 NVC0LegalizePostRA(const Program *); 50 51 private: 52 virtual bool visit(Function *); 53 virtual bool visit(BasicBlock *); 54 55 void replaceZero(Instruction *); 56 bool tryReplaceContWithBra(BasicBlock *); 57 void propagateJoin(BasicBlock *); 58 59 struct TexUse 60 { TexUseTexUse61 TexUse(Instruction *use, const Instruction *tex, bool after) 62 : insn(use), tex(tex), after(after), level(-1) { } 63 Instruction *insn; 64 const Instruction *tex; // or split / mov 65 bool after; 66 int level; 67 }; 68 struct Limits 69 { LimitsLimits70 Limits() { } LimitsLimits71 Limits(int min, int max) : min(min), max(max) { } 72 int min, max; 73 }; 74 bool insertTextureBarriers(Function *); 75 inline bool insnDominatedBy(const Instruction *, const Instruction *) const; 76 void findFirstUses(Instruction *texi, std::list<TexUse> &uses); 77 void findFirstUsesBB(int minGPR, int maxGPR, Instruction *start, 78 const Instruction *texi, std::list<TexUse> &uses, 79 unordered_set<const BasicBlock *> &visited); 80 void addTexUse(std::list<TexUse>&, Instruction *, const Instruction *); 81 const Instruction *recurseDef(const Instruction *); 82 83 private: 84 LValue *rZero; 85 LValue *carry; 86 LValue *pOne; 87 const bool needTexBar; 88 }; 89 90 class NVC0LoweringPass : public Pass 91 { 92 public: 93 NVC0LoweringPass(Program *); 94 95 protected: 96 bool handleRDSV(Instruction *); 97 bool handleWRSV(Instruction *); 98 bool handleEXPORT(Instruction *); 99 bool handleOUT(Instruction *); 100 bool handleDIV(Instruction *); 101 bool handleMOD(Instruction *); 102 bool handleSQRT(Instruction *); 103 bool handlePOW(Instruction *); 104 bool handleTEX(TexInstruction *); 105 bool handleTXD(TexInstruction *); 106 bool handleTXQ(TexInstruction *); 107 virtual bool handleManualTXD(TexInstruction *); 108 bool handleTXLQ(TexInstruction *); 109 bool handleSUQ(TexInstruction *); 110 bool handleATOM(Instruction *); 111 bool handleCasExch(Instruction *, bool needCctl); 112 void handleSurfaceOpGM107(TexInstruction *); 113 void handleSurfaceOpNVE4(TexInstruction *); 114 void handleSurfaceOpNVC0(TexInstruction *); 115 void handleSharedATOM(Instruction *); 116 void handleSharedATOMNVE4(Instruction *); 117 void handleLDST(Instruction *); 118 bool handleBUFQ(Instruction *); 119 120 void checkPredicate(Instruction *); 121 122 virtual bool visit(Instruction *); 123 124 private: 125 virtual bool visit(Function *); 126 virtual bool visit(BasicBlock *); 127 128 void readTessCoord(LValue *dst, int c); 129 130 Value *loadResInfo32(Value *ptr, uint32_t off, uint16_t base); 131 Value *loadResInfo64(Value *ptr, uint32_t off, uint16_t base); 132 Value *loadResLength32(Value *ptr, uint32_t off, uint16_t base); 133 Value *loadSuInfo32(Value *ptr, int slot, uint32_t off, bool bindless); 134 Value *loadBufInfo64(Value *ptr, uint32_t off); 135 Value *loadBufLength32(Value *ptr, uint32_t off); 136 Value *loadUboInfo64(Value *ptr, uint32_t off); 137 Value *loadUboLength32(Value *ptr, uint32_t off); 138 Value *loadMsInfo32(Value *ptr, uint32_t off); 139 Value *loadTexHandle(Value *ptr, unsigned int slot); 140 141 void adjustCoordinatesMS(TexInstruction *); 142 void processSurfaceCoordsGM107(TexInstruction *); 143 void processSurfaceCoordsNVE4(TexInstruction *); 144 void processSurfaceCoordsNVC0(TexInstruction *); 145 void convertSurfaceFormat(TexInstruction *); 146 147 protected: 148 BuildUtil bld; 149 150 private: 151 const Target *const targ; 152 153 Symbol *gMemBase; 154 LValue *gpEmitAddress; 155 }; 156 157 } // namespace nv50_ir 158