@@ -39,6 +39,19 @@ MCCodeEmitter *llvm::createPPCMCCodeEmitter(const MCInstrInfo &MCII,
39
39
return new PPCMCCodeEmitter (MCII, Ctx);
40
40
}
41
41
42
+ static void addFixup (SmallVectorImpl<MCFixup> &Fixups, uint32_t Offset,
43
+ const MCExpr *Value, uint16_t Kind) {
44
+ bool PCRel = false ;
45
+ switch (Kind) {
46
+ case PPC::fixup_ppc_br24:
47
+ case PPC::fixup_ppc_br24_notoc:
48
+ case PPC::fixup_ppc_brcond14:
49
+ case PPC::fixup_ppc_pcrel34:
50
+ PCRel = true ;
51
+ }
52
+ Fixups.push_back (MCFixup::create (Offset, Value, Kind, PCRel));
53
+ }
54
+
42
55
unsigned PPCMCCodeEmitter::
43
56
getDirectBrEncoding (const MCInst &MI, unsigned OpNo,
44
57
SmallVectorImpl<MCFixup> &Fixups,
@@ -49,10 +62,9 @@ getDirectBrEncoding(const MCInst &MI, unsigned OpNo,
49
62
return getMachineOpValue (MI, MO, Fixups, STI);
50
63
51
64
// Add a fixup for the branch target.
52
- Fixups.push_back (MCFixup::create (0 , MO.getExpr (),
53
- (isNoTOCCallInstr (MI)
54
- ? (MCFixupKind)PPC::fixup_ppc_br24_notoc
55
- : (MCFixupKind)PPC::fixup_ppc_br24)));
65
+ addFixup (
66
+ Fixups, 0 , MO.getExpr (),
67
+ (isNoTOCCallInstr (MI) ? PPC::fixup_ppc_br24_notoc : PPC::fixup_ppc_br24));
56
68
return 0 ;
57
69
}
58
70
@@ -157,8 +169,7 @@ unsigned PPCMCCodeEmitter::getCondBrEncoding(const MCInst &MI, unsigned OpNo,
157
169
if (MO.isReg () || MO.isImm ()) return getMachineOpValue (MI, MO, Fixups, STI);
158
170
159
171
// Add a fixup for the branch target.
160
- Fixups.push_back (MCFixup::create (0 , MO.getExpr (),
161
- (MCFixupKind)PPC::fixup_ppc_brcond14));
172
+ addFixup (Fixups, 0 , MO.getExpr (), PPC::fixup_ppc_brcond14);
162
173
return 0 ;
163
174
}
164
175
@@ -170,8 +181,7 @@ getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo,
170
181
if (MO.isReg () || MO.isImm ()) return getMachineOpValue (MI, MO, Fixups, STI);
171
182
172
183
// Add a fixup for the branch target.
173
- Fixups.push_back (MCFixup::create (0 , MO.getExpr (),
174
- (MCFixupKind)PPC::fixup_ppc_br24abs));
184
+ addFixup (Fixups, 0 , MO.getExpr (), PPC::fixup_ppc_br24abs);
175
185
return 0 ;
176
186
}
177
187
@@ -183,8 +193,7 @@ getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo,
183
193
if (MO.isReg () || MO.isImm ()) return getMachineOpValue (MI, MO, Fixups, STI);
184
194
185
195
// Add a fixup for the branch target.
186
- Fixups.push_back (MCFixup::create (0 , MO.getExpr (),
187
- (MCFixupKind)PPC::fixup_ppc_brcond14abs));
196
+ addFixup (Fixups, 0 , MO.getExpr (), PPC::fixup_ppc_brcond14abs);
188
197
return 0 ;
189
198
}
190
199
@@ -205,8 +214,7 @@ unsigned PPCMCCodeEmitter::getImm16Encoding(const MCInst &MI, unsigned OpNo,
205
214
if (MO.isReg () || MO.isImm ()) return getMachineOpValue (MI, MO, Fixups, STI);
206
215
207
216
// Add a fixup for the immediate field.
208
- Fixups.push_back (MCFixup::create (IsLittleEndian? 0 : 2 , MO.getExpr (),
209
- (MCFixupKind)PPC::fixup_ppc_half16));
217
+ addFixup (Fixups, IsLittleEndian ? 0 : 2 , MO.getExpr (), PPC::fixup_ppc_half16);
210
218
return 0 ;
211
219
}
212
220
@@ -220,7 +228,7 @@ uint64_t PPCMCCodeEmitter::getImm34Encoding(const MCInst &MI, unsigned OpNo,
220
228
return getMachineOpValue (MI, MO, Fixups, STI);
221
229
222
230
// Add a fixup for the immediate field.
223
- Fixups. push_back ( MCFixup::create ( 0 , MO.getExpr (), Fixup) );
231
+ addFixup (Fixups, 0 , MO.getExpr (), Fixup);
224
232
return 0 ;
225
233
}
226
234
@@ -248,8 +256,7 @@ unsigned PPCMCCodeEmitter::getDispRIEncoding(const MCInst &MI, unsigned OpNo,
248
256
return getMachineOpValue (MI, MO, Fixups, STI) & 0xFFFF ;
249
257
250
258
// Add a fixup for the displacement field.
251
- Fixups.push_back (MCFixup::create (IsLittleEndian? 0 : 2 , MO.getExpr (),
252
- (MCFixupKind)PPC::fixup_ppc_half16));
259
+ addFixup (Fixups, IsLittleEndian ? 0 : 2 , MO.getExpr (), PPC::fixup_ppc_half16);
253
260
return 0 ;
254
261
}
255
262
@@ -262,8 +269,8 @@ PPCMCCodeEmitter::getDispRIXEncoding(const MCInst &MI, unsigned OpNo,
262
269
return ((getMachineOpValue (MI, MO, Fixups, STI) >> 2 ) & 0x3FFF );
263
270
264
271
// Add a fixup for the displacement field.
265
- Fixups. push_back ( MCFixup::create ( IsLittleEndian? 0 : 2 , MO.getExpr (),
266
- (MCFixupKind) PPC::fixup_ppc_half16ds) );
272
+ addFixup (Fixups, IsLittleEndian ? 0 : 2 , MO.getExpr (),
273
+ PPC::fixup_ppc_half16ds);
267
274
return 0 ;
268
275
}
269
276
@@ -279,8 +286,8 @@ PPCMCCodeEmitter::getDispRIX16Encoding(const MCInst &MI, unsigned OpNo,
279
286
}
280
287
281
288
// Otherwise add a fixup for the displacement field.
282
- Fixups. push_back ( MCFixup::create ( IsLittleEndian ? 0 : 2 , MO.getExpr (),
283
- (MCFixupKind) PPC::fixup_ppc_half16dq) );
289
+ addFixup (Fixups, IsLittleEndian ? 0 : 2 , MO.getExpr (),
290
+ PPC::fixup_ppc_half16dq);
284
291
return 0 ;
285
292
}
286
293
@@ -335,9 +342,7 @@ PPCMCCodeEmitter::getDispRI34PCRelEncoding(const MCInst &MI, unsigned OpNo,
335
342
" specifier must be S_PCREL, S_GOT_PCREL, S_GOT_TLSGD_PCREL, "
336
343
" S_GOT_TLSLD_PCREL, or S_GOT_TPREL_PCREL" );
337
344
// Generate the fixup for the relocation.
338
- Fixups.push_back (
339
- MCFixup::create (0 , Expr,
340
- static_cast <MCFixupKind>(PPC::fixup_ppc_pcrel34)));
345
+ addFixup (Fixups, 0 , Expr, PPC::fixup_ppc_pcrel34);
341
346
// Put zero in the location of the immediate. The linker will fill in the
342
347
// correct value based on the relocation.
343
348
return 0 ;
@@ -369,9 +374,7 @@ PPCMCCodeEmitter::getDispRI34PCRelEncoding(const MCInst &MI, unsigned OpNo,
369
374
getSpecifier (SRE) == PPC::S_GOT_PCREL) &&
370
375
" VariantKind must be VK_PCREL or VK_GOT_PCREL" );
371
376
// Generate the fixup for the relocation.
372
- Fixups.push_back (
373
- MCFixup::create (0 , Expr,
374
- static_cast <MCFixupKind>(PPC::fixup_ppc_pcrel34)));
377
+ addFixup (Fixups, 0 , Expr, PPC::fixup_ppc_pcrel34);
375
378
// Put zero in the location of the immediate. The linker will fill in the
376
379
// correct value based on the relocation.
377
380
return 0 ;
@@ -431,8 +434,7 @@ unsigned PPCMCCodeEmitter::getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
431
434
const MCExpr *Expr = MO.getExpr ();
432
435
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(Expr);
433
436
bool IsPCRel = getSpecifier (SRE) == PPC::S_TLS_PCREL;
434
- Fixups.push_back (MCFixup::create (IsPCRel ? 1 : 0 , Expr,
435
- (MCFixupKind)PPC::fixup_ppc_nofixup));
437
+ addFixup (Fixups, IsPCRel ? 1 : 0 , Expr, PPC::fixup_ppc_nofixup);
436
438
const Triple &TT = STI.getTargetTriple ();
437
439
bool isPPC64 = TT.isPPC64 ();
438
440
return CTX.getRegisterInfo ()->getEncodingValue (isPPC64 ? PPC::X13 : PPC::R2);
@@ -445,8 +447,7 @@ unsigned PPCMCCodeEmitter::getTLSCallEncoding(const MCInst &MI, unsigned OpNo,
445
447
// (__tls_get_addr), which we create via getDirectBrEncoding as usual,
446
448
// and one for the TLSGD or TLSLD symbol, which is emitted here.
447
449
const MCOperand &MO = MI.getOperand (OpNo+1 );
448
- Fixups.push_back (MCFixup::create (0 , MO.getExpr (),
449
- (MCFixupKind)PPC::fixup_ppc_nofixup));
450
+ addFixup (Fixups, 0 , MO.getExpr (), PPC::fixup_ppc_nofixup);
450
451
return getDirectBrEncoding (MI, OpNo, Fixups, STI);
451
452
}
452
453
0 commit comments