Commit 60d1be21 authored by Daniel Sanders's avatar Daniel Sanders
Browse files

Merging r224425:

------------------------------------------------------------------------
r224425 | tomatabacu | 2014-12-17 10:56:16 +0000 (Wed, 17 Dec 2014) | 17 lines

[mips] Set GCC-compatible MIPS asssembler options before inline asm blocks.

Summary:
When generating MIPS assembly, LLVM always overrides the default assembler options by emitting the '.set noreorder', '.set nomacro' and '.set noat' directives,
while GCC uses the default options if an assembly-level function contains inline assembly code.

This becomes a problem when the code generated by LLVM is interleaved with inline assembly which assumes GCC-like assembler options (from Linux, for example).

This patch fixes these conflicts by setting the appropriate assembler options at the beginning of an inline asm block and popping them at the end.

Reviewers: dsanders

Reviewed By: dsanders

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6637
------------------------------------------------------------------------

llvm-svn: 232083
parent af61ee82
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -461,6 +461,10 @@ public:
                                     unsigned AsmVariant, const char *ExtraCode,
                                     raw_ostream &OS);

  /// Let the target do anything it needs to do before emitting inlineasm.
  /// \p StartInfo - the subtarget info before parsing inline asm
  virtual void emitInlineAsmStart(const MCSubtargetInfo &StartInfo) const;

  /// Let the target do anything it needs to do after emitting inlineasm.
  /// This callback can be used restore the original mode in case the
  /// inlineasm contains directives to switch modes.
+4 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode,
  assert(MCAI && "No MCAsmInfo");
  if (!MCAI->useIntegratedAssembler() &&
      !OutStreamer.isIntegratedAssemblerRequired()) {
    emitInlineAsmStart(TM.getSubtarget<MCSubtargetInfo>());
    OutStreamer.EmitRawText(Str);
    emitInlineAsmEnd(TM.getSubtarget<MCSubtargetInfo>(), nullptr);
    return;
@@ -147,6 +148,7 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode,
  Parser->setAssemblerDialect(Dialect);
  Parser->setTargetParser(*TAP.get());

  emitInlineAsmStart(STIOrig);
  // Don't implicitly switch to the text section before the asm.
  int Res = Parser->Run(/*NoInitialTextSection*/ true,
                        /*NoFinalize*/ true);
@@ -561,5 +563,7 @@ bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
  return true;
}

void AsmPrinter::emitInlineAsmStart(const MCSubtargetInfo &StartInfo) const {}

void AsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
                                  const MCSubtargetInfo *EndInfo) const {}
+0 −2
Original line number Diff line number Diff line
@@ -458,7 +458,6 @@ static void createFPFnStub(Function *F, Module *M, FPParamVariant PV,
  FStub->setSection(SectionName);
  BasicBlock *BB = BasicBlock::Create(Context, "entry", FStub);
  InlineAsmHelper IAH(Context, BB);
  IAH.Out(" .set  macro");
  if (PicMode) {
    IAH.Out(".set noreorder");
    IAH.Out(".cpload  $$25");
@@ -467,7 +466,6 @@ static void createFPFnStub(Function *F, Module *M, FPParamVariant PV,
    IAH.Out("la $$25," + LocalName);
  }
  else {
    IAH.Out(".set reorder");
    IAH.Out("la $$25," + Name);
  }
  swapFPIntParams(PV, M, IAH, LE, false);
+18 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ using namespace llvm;

#define DEBUG_TYPE "mips-asm-printer"

MipsTargetStreamer &MipsAsmPrinter::getTargetStreamer() {
MipsTargetStreamer &MipsAsmPrinter::getTargetStreamer() const {
  return static_cast<MipsTargetStreamer &>(*OutStreamer.getTargetStreamer());
}

@@ -721,6 +721,23 @@ void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {
                                                    Subtarget->isABI_O32());
}

void MipsAsmPrinter::emitInlineAsmStart(
    const MCSubtargetInfo &StartInfo) const {
  MipsTargetStreamer &TS = getTargetStreamer();

  TS.emitDirectiveSetPush();
  TS.emitDirectiveSetAt();
  TS.emitDirectiveSetMacro();
  TS.emitDirectiveSetReorder();
  OutStreamer.AddBlankLine();
}

void MipsAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
                                      const MCSubtargetInfo *EndInfo) const {
  OutStreamer.AddBlankLine();
  getTargetStreamer().emitDirectiveSetPop();
}

void MipsAsmPrinter::EmitJal(MCSymbol *Symbol) {
  MCInst I;
  I.setOpcode(Mips::JAL);
+6 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class Module;
class raw_ostream;

class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
  MipsTargetStreamer &getTargetStreamer();
  MipsTargetStreamer &getTargetStreamer() const;

  void EmitInstrWithMacroNoAT(const MachineInstr *MI);

@@ -60,6 +60,11 @@ private:
  std::map<const char *, const llvm::Mips16HardFloatInfo::FuncSignature *>
  StubsNeeded;

  void emitInlineAsmStart(const MCSubtargetInfo &StartInfo) const override;

  void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
                        const MCSubtargetInfo *EndInfo) const override;

  void EmitJal(MCSymbol *Symbol);

  void EmitInstrReg(unsigned Opcode, unsigned Reg);
Loading