llvm.org GIT mirror llvm / 536a88a
When creating MCAsmBackend pass the CPU string as well. In X86AsmBackend store this and use it to not emit long nops when the CPU is geode which doesnt support them. Fixes PR11212. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164132 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Divacky 8 years ago
13 changed file(s) with 75 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
9292 CodeGenOpt::Level OL);
9393 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
9494 MCStreamer &Streamer);
95 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
95 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
96 StringRef TT,
97 StringRef CPU);
9698 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
9799 const MCRegisterInfo &MRI,
98100 const MCAsmInfo &MAI);
351353 /// createMCAsmBackend - Create a target specific assembly parser.
352354 ///
353355 /// \param Triple The target triple string.
354 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
356 MCAsmBackend *createMCAsmBackend(StringRef Triple, StringRef CPU) const {
355357 if (!MCAsmBackendCtorFn)
356358 return 0;
357 return MCAsmBackendCtorFn(*this, Triple);
359 return MCAsmBackendCtorFn(*this, Triple, CPU);
358360 }
359361
360362 /// createMCAsmLexer - Create a target specific assembly lexer.
10611063 }
10621064
10631065 private:
1064 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1065 return new MCAsmBackendImpl(T, Triple);
1066 static MCAsmBackend *Allocator(const Target &T, StringRef Triple,
1067 StringRef CPU) {
1068 return new MCAsmBackendImpl(T, Triple, CPU);
10661069 }
10671070 };
10681071
171171 const MCSubtargetInfo &STI = getSubtarget();
172172 MCE = getTarget().createMCCodeEmitter(*getInstrInfo(), MRI, STI,
173173 *Context);
174 MAB = getTarget().createMCAsmBackend(getTargetTriple());
174 MAB = getTarget().createMCAsmBackend(getTargetTriple(), TargetCPU);
175175 }
176176
177177 MCStreamer *S = getTarget().createAsmStreamer(*Context, Out,
190190 // emission fails.
191191 MCCodeEmitter *MCE = getTarget().createMCCodeEmitter(*getInstrInfo(), MRI,
192192 STI, *Context);
193 MCAsmBackend *MAB = getTarget().createMCAsmBackend(getTargetTriple());
193 MCAsmBackend *MAB = getTarget().createMCAsmBackend(getTargetTriple(), TargetCPU);
194194 if (MCE == 0 || MAB == 0)
195195 return true;
196196
265265 const MCSubtargetInfo &STI = getSubtarget();
266266 MCCodeEmitter *MCE = getTarget().createMCCodeEmitter(*getInstrInfo(), MRI,
267267 STI, *Ctx);
268 MCAsmBackend *MAB = getTarget().createMCAsmBackend(getTargetTriple());
268 MCAsmBackend *MAB = getTarget().createMCAsmBackend(getTargetTriple(), TargetCPU);
269269 if (MCE == 0 || MAB == 0)
270270 return true;
271271
673673
674674 } // end anonymous namespace
675675
676 MCAsmBackend *llvm::createARMAsmBackend(const Target &T, StringRef TT) {
676 MCAsmBackend *llvm::createARMAsmBackend(const Target &T, StringRef TT, StringRef CPU) {
677677 Triple TheTriple(TT);
678678
679679 if (TheTriple.isOSDarwin()) {
4545 const MCSubtargetInfo &STI,
4646 MCContext &Ctx);
4747
48 MCAsmBackend *createARMAsmBackend(const Target &T, StringRef TT);
48 MCAsmBackend *createARMAsmBackend(const Target &T, StringRef TT, StringRef CPU);
4949
5050 /// createARMELFObjectWriter - Construct an ELF Mach-O object writer.
5151 MCObjectWriter *createARMELFObjectWriter(raw_ostream &OS,
155155 }
156156 } // end anonymous namespace
157157
158 MCAsmBackend *llvm::createMBlazeAsmBackend(const Target &T, StringRef TT) {
158 MCAsmBackend *llvm::createMBlazeAsmBackend(const Target &T, StringRef TT,
159 StringRef CPU) {
159160 Triple TheTriple(TT);
160161
161162 if (TheTriple.isOSDarwin())
3434 const MCSubtargetInfo &STI,
3535 MCContext &Ctx);
3636
37 MCAsmBackend *createMBlazeAsmBackend(const Target &T, StringRef TT);
37 MCAsmBackend *createMBlazeAsmBackend(const Target &T, StringRef TT,
38 StringRef CPU);
3839
3940 MCObjectWriter *createMBlazeELFObjectWriter(raw_ostream &OS, uint8_t OSABI);
4041 } // End llvm namespace
243243 } // namespace
244244
245245 // MCAsmBackend
246 MCAsmBackend *llvm::createMipsAsmBackendEL32(const Target &T, StringRef TT) {
246 MCAsmBackend *llvm::createMipsAsmBackendEL32(const Target &T, StringRef TT,
247 StringRef CPU) {
247248 return new MipsAsmBackend(T, Triple(TT).getOS(),
248249 /*IsLittle*/true, /*Is64Bit*/false);
249250 }
250251
251 MCAsmBackend *llvm::createMipsAsmBackendEB32(const Target &T, StringRef TT) {
252 MCAsmBackend *llvm::createMipsAsmBackendEB32(const Target &T, StringRef TT,
253 StringRef CPU) {
252254 return new MipsAsmBackend(T, Triple(TT).getOS(),
253255 /*IsLittle*/false, /*Is64Bit*/false);
254256 }
255257
256 MCAsmBackend *llvm::createMipsAsmBackendEL64(const Target &T, StringRef TT) {
258 MCAsmBackend *llvm::createMipsAsmBackendEL64(const Target &T, StringRef TT,
259 StringRef CPU) {
257260 return new MipsAsmBackend(T, Triple(TT).getOS(),
258261 /*IsLittle*/true, /*Is64Bit*/true);
259262 }
260263
261 MCAsmBackend *llvm::createMipsAsmBackendEB64(const Target &T, StringRef TT) {
264 MCAsmBackend *llvm::createMipsAsmBackendEB64(const Target &T, StringRef TT,
265 StringRef CPU) {
262266 return new MipsAsmBackend(T, Triple(TT).getOS(),
263267 /*IsLittle*/false, /*Is64Bit*/true);
264268 }
4141 const MCSubtargetInfo &STI,
4242 MCContext &Ctx);
4343
44 MCAsmBackend *createMipsAsmBackendEB32(const Target &T, StringRef TT);
45 MCAsmBackend *createMipsAsmBackendEL32(const Target &T, StringRef TT);
46 MCAsmBackend *createMipsAsmBackendEB64(const Target &T, StringRef TT);
47 MCAsmBackend *createMipsAsmBackendEL64(const Target &T, StringRef TT);
44 MCAsmBackend *createMipsAsmBackendEB32(const Target &T, StringRef TT,
45 StringRef CPU);
46 MCAsmBackend *createMipsAsmBackendEL32(const Target &T, StringRef TT,
47 StringRef CPU);
48 MCAsmBackend *createMipsAsmBackendEB64(const Target &T, StringRef TT,
49 StringRef CPU);
50 MCAsmBackend *createMipsAsmBackendEL64(const Target &T, StringRef TT,
51 StringRef CPU);
4852
4953 MCObjectWriter *createMipsELFObjectWriter(raw_ostream &OS,
5054 uint8_t OSABI,
180180
181181
182182
183 MCAsmBackend *llvm::createPPCAsmBackend(const Target &T, StringRef TT) {
183 MCAsmBackend *llvm::createPPCAsmBackend(const Target &T, StringRef TT, StringRef CPU) {
184184 if (Triple(TT).isOSDarwin())
185185 return new DarwinPPCAsmBackend(T);
186186
3535 const MCSubtargetInfo &STI,
3636 MCContext &Ctx);
3737
38 MCAsmBackend *createPPCAsmBackend(const Target &T, StringRef TT);
38 MCAsmBackend *createPPCAsmBackend(const Target &T, StringRef TT, StringRef CPU);
3939
4040 /// createPPCELFObjectWriter - Construct an PPC ELF object writer.
4141 MCObjectWriter *createPPCELFObjectWriter(raw_ostream &OS,
6565 };
6666
6767 class X86AsmBackend : public MCAsmBackend {
68 public:
69 X86AsmBackend(const Target &T)
70 : MCAsmBackend() {}
68 StringRef CPU;
69 public:
70 X86AsmBackend(const Target &T, StringRef _CPU)
71 : MCAsmBackend(), CPU(_CPU) {}
7172
7273 unsigned getNumFixupKinds() const {
7374 return X86::NumTargetFixupKinds;
304305 {0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
305306 };
306307
308 // This CPU doesnt support long nops. If needed add more.
309 if (CPU == "geode") {
310 for (uint64_t i = 0; i < Count; ++i)
311 OW->Write8(0x90);
312 return true;
313 }
314
307315 // Write an optimal sequence for the first 15 bytes.
308316 const uint64_t OptimalCount = (Count < 16) ? Count : 15;
309317 const uint64_t Prefixes = OptimalCount <= 10 ? 0 : OptimalCount - 10;
326334 class ELFX86AsmBackend : public X86AsmBackend {
327335 public:
328336 uint8_t OSABI;
329 ELFX86AsmBackend(const Target &T, uint8_t _OSABI)
330 : X86AsmBackend(T), OSABI(_OSABI) {
337 ELFX86AsmBackend(const Target &T, uint8_t _OSABI, StringRef CPU)
338 : X86AsmBackend(T, CPU), OSABI(_OSABI) {
331339 HasReliableSymbolDifference = true;
332340 }
333341
339347
340348 class ELFX86_32AsmBackend : public ELFX86AsmBackend {
341349 public:
342 ELFX86_32AsmBackend(const Target &T, uint8_t OSABI)
343 : ELFX86AsmBackend(T, OSABI) {}
350 ELFX86_32AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU)
351 : ELFX86AsmBackend(T, OSABI, CPU) {}
344352
345353 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
346354 return createX86ELFObjectWriter(OS, /*Is64Bit*/ false, OSABI);
349357
350358 class ELFX86_64AsmBackend : public ELFX86AsmBackend {
351359 public:
352 ELFX86_64AsmBackend(const Target &T, uint8_t OSABI)
353 : ELFX86AsmBackend(T, OSABI) {}
360 ELFX86_64AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU)
361 : ELFX86AsmBackend(T, OSABI, CPU) {}
354362
355363 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
356364 return createX86ELFObjectWriter(OS, /*Is64Bit*/ true, OSABI);
361369 bool Is64Bit;
362370
363371 public:
364 WindowsX86AsmBackend(const Target &T, bool is64Bit)
365 : X86AsmBackend(T)
372 WindowsX86AsmBackend(const Target &T, bool is64Bit, StringRef CPU)
373 : X86AsmBackend(T, CPU)
366374 , Is64Bit(is64Bit) {
367375 }
368376
373381
374382 class DarwinX86AsmBackend : public X86AsmBackend {
375383 public:
376 DarwinX86AsmBackend(const Target &T)
377 : X86AsmBackend(T) { }
384 DarwinX86AsmBackend(const Target &T, StringRef CPU)
385 : X86AsmBackend(T, CPU) { }
378386 };
379387
380388 class DarwinX86_32AsmBackend : public DarwinX86AsmBackend {
381389 public:
382 DarwinX86_32AsmBackend(const Target &T)
383 : DarwinX86AsmBackend(T) {}
390 DarwinX86_32AsmBackend(const Target &T, StringRef CPU)
391 : DarwinX86AsmBackend(T, CPU) {}
384392
385393 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
386394 return createX86MachObjectWriter(OS, /*Is64Bit=*/false,
391399
392400 class DarwinX86_64AsmBackend : public DarwinX86AsmBackend {
393401 public:
394 DarwinX86_64AsmBackend(const Target &T)
395 : DarwinX86AsmBackend(T) {
402 DarwinX86_64AsmBackend(const Target &T, StringRef CPU)
403 : DarwinX86AsmBackend(T, CPU) {
396404 HasReliableSymbolDifference = true;
397405 }
398406
438446
439447 } // end anonymous namespace
440448
441 MCAsmBackend *llvm::createX86_32AsmBackend(const Target &T, StringRef TT) {
449 MCAsmBackend *llvm::createX86_32AsmBackend(const Target &T, StringRef TT, StringRef CPU) {
442450 Triple TheTriple(TT);
443451
444452 if (TheTriple.isOSDarwin() || TheTriple.getEnvironment() == Triple::MachO)
445 return new DarwinX86_32AsmBackend(T);
453 return new DarwinX86_32AsmBackend(T, CPU);
446454
447455 if (TheTriple.isOSWindows())
448 return new WindowsX86AsmBackend(T, false);
456 return new WindowsX86AsmBackend(T, false, CPU);
449457
450458 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
451 return new ELFX86_32AsmBackend(T, OSABI);
452 }
453
454 MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T, StringRef TT) {
459 return new ELFX86_32AsmBackend(T, OSABI, CPU);
460 }
461
462 MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T, StringRef TT, StringRef CPU) {
455463 Triple TheTriple(TT);
456464
457465 if (TheTriple.isOSDarwin() || TheTriple.getEnvironment() == Triple::MachO)
458 return new DarwinX86_64AsmBackend(T);
466 return new DarwinX86_64AsmBackend(T, CPU);
459467
460468 if (TheTriple.isOSWindows())
461 return new WindowsX86AsmBackend(T, true);
469 return new WindowsX86AsmBackend(T, true, CPU);
462470
463471 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
464 return new ELFX86_64AsmBackend(T, OSABI);
465 }
472 return new ELFX86_64AsmBackend(T, OSABI, CPU);
473 }
7979 const MCSubtargetInfo &STI,
8080 MCContext &Ctx);
8181
82 MCAsmBackend *createX86_32AsmBackend(const Target &T, StringRef TT);
83 MCAsmBackend *createX86_64AsmBackend(const Target &T, StringRef TT);
82 MCAsmBackend *createX86_32AsmBackend(const Target &T, StringRef TT, StringRef CPU);
83 MCAsmBackend *createX86_64AsmBackend(const Target &T, StringRef TT, StringRef CPU);
8484
8585 /// createX86MachObjectWriter - Construct an X86 Mach-O object writer.
8686 MCObjectWriter *createX86MachObjectWriter(raw_ostream &OS,
408408 MCAsmBackend *MAB = 0;
409409 if (ShowEncoding) {
410410 CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx);
411 MAB = TheTarget->createMCAsmBackend(TripleName);
411 MAB = TheTarget->createMCAsmBackend(TripleName, MCPU);
412412 }
413413 Str.reset(TheTarget->createAsmStreamer(Ctx, FOS, /*asmverbose*/true,
414414 /*useLoc*/ true,
421421 } else {
422422 assert(FileType == OFT_ObjectFile && "Invalid file type!");
423423 MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx);
424 MCAsmBackend *MAB = TheTarget->createMCAsmBackend(TripleName);
424 MCAsmBackend *MAB = TheTarget->createMCAsmBackend(TripleName, MCPU);
425425 Str.reset(TheTarget->createMCObjectStreamer(TripleName, Ctx, *MAB,
426426 FOS, CE, RelaxAll,
427427 NoExecStack));