llvm.org GIT mirror llvm / 48dc37b
AMDGPU/SI: Correctly encode constant expressions Summary: We we have an MCConstantExpr, we can encode it directly into the instruction instead of emitting fixups. Reviewers: artem.tamazov, vpykhtin, SamWot, nhaustov, arsenm Subscribers: arsenm, llvm-commits, kzhuravl Differential Revision: http://reviews.llvm.org/D21236 Change-Id: I88b3edf288d48e65c5d705fc4850d281f8e36948 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272750 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 4 years ago
2 changed file(s) with 35 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
161161
162162 uint32_t SIMCCodeEmitter::getLitEncoding(const MCOperand &MO,
163163 unsigned OpSize) const {
164 if (MO.isExpr())
165 return 255;
166
167 assert(!MO.isFPImm());
168
169 if (!MO.isImm())
170 return ~0;
164
165 int64_t Imm;
166 if (MO.isExpr()) {
167 const MCConstantExpr *C = dyn_cast(MO.getExpr());
168 if (!C)
169 return 255;
170
171 Imm = C->getValue();
172 } else {
173
174 assert(!MO.isFPImm());
175
176 if (!MO.isImm())
177 return ~0;
178
179 Imm = MO.getImm();
180 }
171181
172182 if (OpSize == 4)
173 return getLit32Encoding(static_cast(MO.getImm()));
183 return getLit32Encoding(static_cast(Imm));
174184
175185 assert(OpSize == 8);
176186
177 return getLit64Encoding(static_cast(MO.getImm()));
187 return getLit64Encoding(static_cast(Imm));
178188 }
179189
180190 void SIMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
212222
213223 if (Op.isImm())
214224 Imm = Op.getImm();
215 else if (!Op.isExpr()) // Exprs will be replaced with a fixup value.
225 else if (Op.isExpr()) {
226 if (const MCConstantExpr *C = dyn_cast(Op.getExpr()))
227 Imm = C->getValue();
228
229 } else if (!Op.isExpr()) // Exprs will be replaced with a fixup value.
216230 llvm_unreachable("Must be immediate or expr");
217231
218232 for (unsigned j = 0; j < 4; j++) {
246260 if (MO.isReg())
247261 return MRI.getEncodingValue(MO.getReg());
248262
249 if (MO.isExpr()) {
263 if (MO.isExpr() && MO.getExpr()->getKind() != MCExpr::Constant) {
250264 const MCSymbolRefExpr *Expr = dyn_cast(MO.getExpr());
251265 MCFixupKind Kind;
252266 if (Expr && Expr->getSymbol().isExternal())
2828 s_addc_u32 s1, s1, 0
2929 // VI: s_add_u32 s0, s0, global+4
3030 // VI: s_addc_u32 s1, s1, 0
31
32 // Use a computed expression that results in an inline immediate.
33 .set foo, 4
34 s_mov_b32 s0, foo+2
35 // VI: s_mov_b32 s0, 6 ; encoding: [0x86,0x00,0x80,0xbe]
36
37 // Use a computed expression that results in a non-inline immediate.
38 .set foo, 512
39 s_mov_b32 s0, foo+2
40 // VI: s_mov_b32 s0, 514 ; encoding: [0xff,0x00,0x80,0xbe,0x02,0x02,0x00,0x00]