2 #ifndef __NV50_IR_BUILD_UTIL__
3 #define __NV50_IR_BUILD_UTIL__
12 inline void setProgram(Program
*);
13 inline Program
*getProgram() const { return prog
; }
14 inline Function
*getFunction() const { return func
; }
16 // keeps inserting at head/tail of block
17 inline void setPosition(BasicBlock
*, bool tail
);
18 // position advances only if @after is true
19 inline void setPosition(Instruction
*, bool after
);
21 inline BasicBlock
*getBB() { return bb
; }
23 inline void insert(Instruction
*);
24 inline void remove(Instruction
*i
) { assert(i
->bb
== bb
); bb
->remove(i
); }
26 inline LValue
*getScratch(int size
= 4);
27 inline LValue
*getSSA(int size
= 4); // scratch value for a single assignment
29 inline Instruction
*mkOp(operation
, DataType
, Value
*);
30 Instruction
*mkOp1(operation
, DataType
, Value
*, Value
*);
31 Instruction
*mkOp2(operation
, DataType
, Value
*, Value
*, Value
*);
32 Instruction
*mkOp3(operation
, DataType
, Value
*, Value
*, Value
*, Value
*);
34 LValue
*mkOp1v(operation
, DataType
, Value
*, Value
*);
35 LValue
*mkOp2v(operation
, DataType
, Value
*, Value
*, Value
*);
36 LValue
*mkOp3v(operation
, DataType
, Value
*, Value
*, Value
*, Value
*);
38 LValue
*mkLoad(DataType
, Symbol
*, Value
*ptr
);
39 Instruction
*mkStore(operation
, DataType
, Symbol
*, Value
*ptr
, Value
*val
);
41 Instruction
*mkMov(Value
*, Value
*, DataType
= TYPE_U32
);
42 Instruction
*mkMovToReg(int id
, Value
*);
43 Instruction
*mkMovFromReg(Value
*, int id
);
45 Instruction
*mkFetch(Value
*, DataType
, DataFile
, int32_t offset
,
46 Value
*attrRel
, Value
*primRel
);
48 Instruction
*mkCvt(operation
, DataType
, Value
*, DataType
, Value
*);
49 Instruction
*mkCmp(operation
, CondCode
, DataType
,
51 Value
*, Value
*, Value
* = NULL
);
52 Instruction
*mkTex(operation
, TexTarget
, uint8_t tic
, uint8_t tsc
,
53 Value
**def
, Value
**src
);
54 Instruction
*mkQuadop(uint8_t qop
, Value
*, uint8_t l
, Value
*, Value
*);
56 FlowInstruction
*mkFlow(operation
, BasicBlock
*target
,
57 CondCode
, Value
*pred
);
59 Instruction
*mkSelect(Value
*pred
, Value
*dst
, Value
*trSrc
, Value
*flSrc
);
61 void mkClobber(DataFile file
, uint32_t regMask
, int regUnitLog2
);
63 ImmediateValue
*mkImm(float);
64 ImmediateValue
*mkImm(uint32_t);
65 ImmediateValue
*mkImm(uint64_t);
67 ImmediateValue
*mkImm(int i
) { return mkImm((uint32_t)i
); }
69 Value
*loadImm(Value
*dst
, float);
70 Value
*loadImm(Value
*dst
, uint32_t);
71 Value
*loadImm(Value
*dst
, uint64_t);
73 Value
*loadImm(Value
*dst
, int i
) { return loadImm(dst
, (uint32_t)i
); }
79 DataArray(BuildUtil
*);
82 inline void setParent(BuildUtil
*bld
) { assert(!up
); up
= bld
; }
84 void setup(uint32_t base
, int len
, int vecDim
, int size
,
85 DataFile
, int8_t fileIndex
= 0);
87 inline bool exists(unsigned int i
, unsigned int c
);
89 Value
*load(int i
, int c
, Value
*ptr
);
90 void store(int i
, int c
, Value
*ptr
, Value
*value
);
91 Value
*acquire(int i
, int c
);
94 Symbol
*mkSymbol(int i
, int c
, Symbol
*base
);
103 uint8_t eltSize
; // in bytes
113 Symbol
*mkSymbol(DataFile file
, int8_t fileIndex
,
114 DataType ty
, uint32_t baseAddress
);
116 Symbol
*mkSysVal(SVSemantic svName
, uint32_t svIndex
);
119 void addImmediate(ImmediateValue
*);
120 inline unsigned int u32Hash(uint32_t);
129 #define NV50_IR_BUILD_IMM_HT_SIZE 256
131 ImmediateValue
*imms
[NV50_IR_BUILD_IMM_HT_SIZE
];
132 unsigned int immCount
;
135 unsigned int BuildUtil::u32Hash(uint32_t u
)
137 return (u
% 273) % NV50_IR_BUILD_IMM_HT_SIZE
;
140 void BuildUtil::setProgram(Program
*program
)
146 BuildUtil::setPosition(BasicBlock
*block
, bool atTail
)
149 prog
= bb
->getProgram();
150 func
= bb
->getFunction();
156 BuildUtil::setPosition(Instruction
*i
, bool after
)
159 prog
= bb
->getProgram();
160 func
= bb
->getFunction();
167 BuildUtil::getScratch(int size
)
169 LValue
*lval
= new_LValue(func
, FILE_GPR
);
171 lval
->reg
.size
= size
;
176 BuildUtil::getSSA(int size
)
178 LValue
*lval
= new_LValue(func
, FILE_GPR
);
181 lval
->reg
.size
= size
;
185 void BuildUtil::insert(Instruction
*i
)
188 tail
? bb
->insertTail(i
) : bb
->insertHead(i
);
191 bb
->insertAfter(pos
, i
);
194 bb
->insertBefore(pos
, i
);
200 BuildUtil::mkOp(operation op
, DataType ty
, Value
*dst
)
202 Instruction
*insn
= new_Instruction(func
, op
, ty
);
203 insn
->setDef(0, dst
);
205 if (op
== OP_DISCARD
|| op
== OP_EXIT
||
207 op
== OP_QUADON
|| op
== OP_QUADPOP
||
208 op
== OP_EMIT
|| op
== OP_RESTART
)
214 BuildUtil::mkOp1v(operation op
, DataType ty
, Value
*dst
, Value
*src
)
216 mkOp1(op
, ty
, dst
, src
);
217 return dst
->asLValue();
221 BuildUtil::mkOp2v(operation op
, DataType ty
, Value
*dst
,
222 Value
*src0
, Value
*src1
)
224 mkOp2(op
, ty
, dst
, src0
, src1
);
225 return dst
->asLValue();
229 BuildUtil::mkOp3v(operation op
, DataType ty
, Value
*dst
,
230 Value
*src0
, Value
*src1
, Value
*src2
)
232 mkOp3(op
, ty
, dst
, src0
, src1
, src2
);
233 return dst
->asLValue();
237 BuildUtil::DataArray::exists(unsigned int i
, unsigned int c
)
239 assert(i
< arrayLen
&& c
< vecDim
);
240 return !regOnly
|| values
[i
* vecDim
+ c
];
243 } // namespace nv50_ir
245 #endif // __NV50_IR_BUILD_UTIL_H__