2 * Copyright 2011 Christoph Bumiller
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #include "codegen/nv50_ir.h"
24 #include "codegen/nv50_ir_build_util.h"
28 class NVC0LegalizeSSA
: public Pass
31 virtual bool visit(BasicBlock
*);
32 virtual bool visit(Function
*);
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
*);
43 class NVC0LegalizePostRA
: public Pass
46 NVC0LegalizePostRA(const Program
*);
49 virtual bool visit(Function
*);
50 virtual bool visit(BasicBlock
*);
52 void replaceZero(Instruction
*);
53 bool tryReplaceContWithBra(BasicBlock
*);
54 void propagateJoin(BasicBlock
*);
58 TexUse(Instruction
*use
, const Instruction
*tex
, bool after
)
59 : insn(use
), tex(tex
), after(after
), level(-1) { }
61 const Instruction
*tex
; // or split / mov
68 Limits(int min
, int max
) : min(min
), max(max
) { }
71 bool insertTextureBarriers(Function
*);
72 inline bool insnDominatedBy(const Instruction
*, const Instruction
*) const;
73 void findFirstUses(Instruction
*texi
, std::list
<TexUse
> &uses
);
74 void findFirstUsesBB(int minGPR
, int maxGPR
, Instruction
*start
,
75 const Instruction
*texi
, std::list
<TexUse
> &uses
,
76 unordered_set
<const BasicBlock
*> &visited
);
77 void addTexUse(std::list
<TexUse
>&, Instruction
*, const Instruction
*);
78 const Instruction
*recurseDef(const Instruction
*);
84 const bool needTexBar
;
87 class NVC0LoweringPass
: public Pass
90 NVC0LoweringPass(Program
*);
93 bool handleRDSV(Instruction
*);
94 bool handleWRSV(Instruction
*);
95 bool handleEXPORT(Instruction
*);
96 bool handleOUT(Instruction
*);
97 bool handleDIV(Instruction
*);
98 bool handleMOD(Instruction
*);
99 bool handleSQRT(Instruction
*);
100 bool handlePOW(Instruction
*);
101 bool handleTEX(TexInstruction
*);
102 bool handleTXD(TexInstruction
*);
103 bool handleTXQ(TexInstruction
*);
104 virtual bool handleManualTXD(TexInstruction
*);
105 bool handleTXLQ(TexInstruction
*);
106 bool handleSUQ(TexInstruction
*);
107 bool handleATOM(Instruction
*);
108 bool handleCasExch(Instruction
*, bool needCctl
);
109 void handleSurfaceOpGM107(TexInstruction
*);
110 void handleSurfaceOpNVE4(TexInstruction
*);
111 void handleSurfaceOpNVC0(TexInstruction
*);
112 void handleSharedATOM(Instruction
*);
113 void handleSharedATOMNVE4(Instruction
*);
114 void handleLDST(Instruction
*);
115 bool handleBUFQ(Instruction
*);
117 void checkPredicate(Instruction
*);
119 virtual bool visit(Instruction
*);
122 virtual bool visit(Function
*);
123 virtual bool visit(BasicBlock
*);
125 void readTessCoord(LValue
*dst
, int c
);
127 Value
*loadResInfo32(Value
*ptr
, uint32_t off
, uint16_t base
);
128 Value
*loadResInfo64(Value
*ptr
, uint32_t off
, uint16_t base
);
129 Value
*loadResLength32(Value
*ptr
, uint32_t off
, uint16_t base
);
130 Value
*loadSuInfo32(Value
*ptr
, int slot
, uint32_t off
);
131 Value
*loadBufInfo64(Value
*ptr
, uint32_t off
);
132 Value
*loadBufLength32(Value
*ptr
, uint32_t off
);
133 Value
*loadUboInfo64(Value
*ptr
, uint32_t off
);
134 Value
*loadUboLength32(Value
*ptr
, uint32_t off
);
135 Value
*loadMsInfo32(Value
*ptr
, uint32_t off
);
136 Value
*loadTexHandle(Value
*ptr
, unsigned int slot
);
138 void adjustCoordinatesMS(TexInstruction
*);
139 void processSurfaceCoordsGM107(TexInstruction
*);
140 void processSurfaceCoordsNVE4(TexInstruction
*);
141 void processSurfaceCoordsNVC0(TexInstruction
*);
142 void convertSurfaceFormat(TexInstruction
*);
148 const Target
*const targ
;
151 LValue
*gpEmitAddress
;
154 } // namespace nv50_ir