OLD | NEW |
1 //===-- MipsAsmPrinter.cpp - Mips LLVM assembly writer --------------------===// | 1 //===-- MipsAsmPrinter.cpp - Mips LLVM assembly writer --------------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file contains a printer that converts from our internal representation | 10 // This file contains a printer that converts from our internal representation |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 case MipsSubtarget::N64: return "abi64"; | 204 case MipsSubtarget::N64: return "abi64"; |
205 case MipsSubtarget::EABI: return "eabi32"; // TODO: handle eabi64 | 205 case MipsSubtarget::EABI: return "eabi32"; // TODO: handle eabi64 |
206 default: break; | 206 default: break; |
207 } | 207 } |
208 | 208 |
209 llvm_unreachable("Unknown Mips ABI"); | 209 llvm_unreachable("Unknown Mips ABI"); |
210 return NULL; | 210 return NULL; |
211 } | 211 } |
212 | 212 |
213 void MipsAsmPrinter::EmitFunctionEntryLabel() { | 213 void MipsAsmPrinter::EmitFunctionEntryLabel() { |
| 214 // @LOCALMOD-START |
| 215 // make sure function entry is aligned. We use XmagicX as our basis |
| 216 // for alignment decisions (c.f. assembler sfi macros). |
| 217 int alignment = MF->getAlignment(); |
| 218 if (alignment < 4) alignment = 4; |
| 219 EmitAlignment(alignment); |
| 220 if (Subtarget->isTargetNaCl() && OutStreamer.hasRawTextSupport()) { |
| 221 OutStreamer.EmitRawText(StringRef("\t.set XmagicX, .\n")); |
| 222 } |
| 223 // @LOCALMOD-END |
| 224 |
214 OutStreamer.EmitRawText("\t.ent\t" + Twine(CurrentFnSym->getName())); | 225 OutStreamer.EmitRawText("\t.ent\t" + Twine(CurrentFnSym->getName())); |
215 OutStreamer.EmitLabel(CurrentFnSym); | 226 OutStreamer.EmitLabel(CurrentFnSym); |
216 } | 227 } |
217 | 228 |
218 /// EmitFunctionBodyStart - Targets can override this to emit stuff before | 229 /// EmitFunctionBodyStart - Targets can override this to emit stuff before |
219 /// the first basic block in the function. | 230 /// the first basic block in the function. |
220 void MipsAsmPrinter::EmitFunctionBodyStart() { | 231 void MipsAsmPrinter::EmitFunctionBodyStart() { |
221 emitFrameDirective(); | 232 emitFrameDirective(); |
222 | 233 |
223 SmallString<128> Str; | 234 SmallString<128> Str; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 return; | 418 return; |
408 } | 419 } |
409 | 420 |
410 void MipsAsmPrinter:: | 421 void MipsAsmPrinter:: |
411 printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O, | 422 printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O, |
412 const char *Modifier) { | 423 const char *Modifier) { |
413 const MachineOperand& MO = MI->getOperand(opNum); | 424 const MachineOperand& MO = MI->getOperand(opNum); |
414 O << Mips::MipsFCCToString((Mips::CondCode)MO.getImm()); | 425 O << Mips::MipsFCCToString((Mips::CondCode)MO.getImm()); |
415 } | 426 } |
416 | 427 |
| 428 // @LOCALMOD-START |
| 429 extern void EmitMipsSFIHeaders(raw_ostream &O); |
| 430 // @LOCALMOD-END |
| 431 |
417 void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) { | 432 void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) { |
418 // FIXME: Use SwitchSection. | 433 // FIXME: Use SwitchSection. |
419 | 434 |
420 // Tell the assembler which ABI we are using | 435 // Tell the assembler which ABI we are using |
421 OutStreamer.EmitRawText("\t.section .mdebug." + Twine(getCurrentABIString())); | 436 OutStreamer.EmitRawText("\t.section .mdebug." + Twine(getCurrentABIString())); |
422 | 437 |
423 // TODO: handle O64 ABI | 438 // TODO: handle O64 ABI |
424 if (Subtarget->isABI_EABI()) { | 439 if (Subtarget->isABI_EABI()) { |
425 if (Subtarget->isGP32bit()) | 440 if (Subtarget->isGP32bit()) |
426 OutStreamer.EmitRawText(StringRef("\t.section .gcc_compiled_long32")); | 441 OutStreamer.EmitRawText(StringRef("\t.section .gcc_compiled_long32")); |
427 else | 442 else |
428 OutStreamer.EmitRawText(StringRef("\t.section .gcc_compiled_long64")); | 443 OutStreamer.EmitRawText(StringRef("\t.section .gcc_compiled_long64")); |
429 } | 444 } |
430 | 445 |
431 // return to previous section | 446 // return to previous section |
432 OutStreamer.EmitRawText(StringRef("\t.previous")); | 447 OutStreamer.EmitRawText(StringRef("\t.previous")); |
| 448 |
| 449 // @LOCALMOD-START |
| 450 if (Subtarget->isTargetNaCl() && OutStreamer.hasRawTextSupport()) { |
| 451 std::string str; |
| 452 raw_string_ostream OS(str); |
| 453 EmitMipsSFIHeaders(OS); |
| 454 OutStreamer.EmitRawText(StringRef(OS.str())); |
| 455 } |
| 456 // @LOCALMOD-END |
433 } | 457 } |
434 | 458 |
| 459 // @LOCALMOD-START |
| 460 unsigned MipsAsmPrinter::GetTargetLabelAlign(const MachineInstr *MI) const { |
| 461 if (Subtarget->isTargetNaCl()) { |
| 462 switch (MI->getOpcode()) { |
| 463 default: return 0; |
| 464 // These labels may indicate an indirect entry point that is |
| 465 // externally reachable and hence must be bundle aligned. |
| 466 // Note: these labels appear to be always at basic block beginnings |
| 467 // so it may be possible to simply set the MBB alignment. |
| 468 // However, it is unclear whether this always holds. |
| 469 case TargetOpcode::EH_LABEL: |
| 470 case TargetOpcode::GC_LABEL: |
| 471 return 4; |
| 472 } |
| 473 } |
| 474 return 0; |
| 475 } |
| 476 // @LOCALMOD-END |
| 477 |
435 MachineLocation | 478 MachineLocation |
436 MipsAsmPrinter::getDebugValueLocation(const MachineInstr *MI) const { | 479 MipsAsmPrinter::getDebugValueLocation(const MachineInstr *MI) const { |
437 // Handles frame addresses emitted in MipsInstrInfo::emitFrameIndexDebugValue. | 480 // Handles frame addresses emitted in MipsInstrInfo::emitFrameIndexDebugValue. |
438 assert(MI->getNumOperands() == 4 && "Invalid no. of machine operands!"); | 481 assert(MI->getNumOperands() == 4 && "Invalid no. of machine operands!"); |
439 assert(MI->getOperand(0).isReg() && MI->getOperand(1).isImm() && | 482 assert(MI->getOperand(0).isReg() && MI->getOperand(1).isImm() && |
440 "Unexpected MachineOperand types"); | 483 "Unexpected MachineOperand types"); |
441 return MachineLocation(MI->getOperand(0).getReg(), | 484 return MachineLocation(MI->getOperand(0).getReg(), |
442 MI->getOperand(1).getImm()); | 485 MI->getOperand(1).getImm()); |
443 } | 486 } |
444 | 487 |
445 void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI, | 488 void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI, |
446 raw_ostream &OS) { | 489 raw_ostream &OS) { |
447 // TODO: implement | 490 // TODO: implement |
448 } | 491 } |
449 | 492 |
450 // Force static initialization. | 493 // Force static initialization. |
451 extern "C" void LLVMInitializeMipsAsmPrinter() { | 494 extern "C" void LLVMInitializeMipsAsmPrinter() { |
452 RegisterAsmPrinter<MipsAsmPrinter> X(TheMipsTarget); | 495 RegisterAsmPrinter<MipsAsmPrinter> X(TheMipsTarget); |
453 RegisterAsmPrinter<MipsAsmPrinter> Y(TheMipselTarget); | 496 RegisterAsmPrinter<MipsAsmPrinter> Y(TheMipselTarget); |
454 RegisterAsmPrinter<MipsAsmPrinter> A(TheMips64Target); | 497 RegisterAsmPrinter<MipsAsmPrinter> A(TheMips64Target); |
455 RegisterAsmPrinter<MipsAsmPrinter> B(TheMips64elTarget); | 498 RegisterAsmPrinter<MipsAsmPrinter> B(TheMips64elTarget); |
456 } | 499 } |
OLD | NEW |