[llvm] r173884 - This patch implements runtime Mips specific

David Blaikie dblaikie at gmail.com
Tue Jan 29 18:57:01 PST 2013


On Tue, Jan 29, 2013 at 6:16 PM, Jack Carter <jcarter at mips.com> wrote:
> Author: jacksprat
> Date: Tue Jan 29 20:16:36 2013
> New Revision: 173884
>
> URL: http://llvm.org/viewvc/llvm-project?rev=173884&view=rev
> Log:
> This patch implements runtime Mips specific
> setting of ELF header e_flags.
>
> Contributer: Jack Carter
>
>
> Added:
>     llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
>     llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
>     llvm/trunk/test/MC/Mips/elf_eflags.ll
> Modified:
>     llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp
>     llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
>     llvm/trunk/lib/Target/Mips/MipsSubtarget.cpp
>     llvm/trunk/lib/Target/Mips/MipsSubtarget.h
>
> Added: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp?rev=173884&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp (added)
> +++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp Tue Jan 29 20:16:36 2013
> @@ -0,0 +1,61 @@
> +//===-- MipsELFStreamer.cpp - MipsELFStreamer ---------------------------===//
> +//
> +//                       The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===-------------------------------------------------------------------===//
> +#include "MCTargetDesc/MipsELFStreamer.h"
> +#include "MipsSubtarget.h"
> +#include "llvm/MC/MCAssembler.h"
> +#include "llvm/Support/ELF.h"
> +#include "llvm/Support/ErrorHandling.h"
> +
> +namespace llvm {
> +
> +  MCELFStreamer* createMipsELFStreamer(MCContext &Context, MCAsmBackend &TAB,
> +                                       raw_ostream &OS, MCCodeEmitter *Emitter,
> +                                       bool RelaxAll, bool NoExecStack) {
> +    MipsELFStreamer *S = new MipsELFStreamer(Context, TAB, OS, Emitter,
> +                                             RelaxAll, NoExecStack);
> +    return S;
> +  }
> +
> +  // For llc. Set a group of ELF header flags
> +  void
> +  MipsELFStreamer::emitELFHeaderFlagsCG(const MipsSubtarget &Subtarget) {
> +
> +    if (hasRawTextSupport())
> +      return;
> +
> +    // Update e_header flags
> +    MCAssembler& MCA = getAssembler();
> +    unsigned EFlags = MCA.getELFHeaderEFlags();
> +
> +    EFlags |= ELF::EF_MIPS_NOREORDER;
> +
> +    // Architecture
> +    if (Subtarget.hasMips64r2())
> +      EFlags |= ELF::EF_MIPS_ARCH_64R2;
> +    else if (Subtarget.hasMips64())
> +      EFlags |= ELF::EF_MIPS_ARCH_64;
> +    else if (Subtarget.hasMips32r2())
> +      EFlags |= ELF::EF_MIPS_ARCH_32R2;
> +    else
> +      EFlags |= ELF::EF_MIPS_ARCH_32;
> +
> +    // Relocation Model
> +    Reloc::Model RM = Subtarget.getRelocationModel();
> +    if (RM == Reloc::PIC_ || RM == Reloc::Default)
> +      EFlags |= ELF::EF_MIPS_PIC;
> +    else if (RM == Reloc::Static)
> +      ; // Do nothing for Reloc::Static
> +    else
> +      llvm_unreachable("Unsupported relocation model for e_flags");
> +
> +    MCA.setELFHeaderEFlags(EFlags);
> +
> +
> +  }
> +}
>
> Added: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h?rev=173884&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h (added)
> +++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h Tue Jan 29 20:16:36 2013
> @@ -0,0 +1,37 @@
> +//=== MipsELFStreamer.h - MipsELFStreamer ------------------------------===//
> +//
> +//                    The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENCE.TXT for details.
> +//
> +//===-------------------------------------------------------------------===//
> +#ifndef MIPSELFSTREAMER_H_
> +#define MIPSELFSTREAMER_H_
> +
> +#include "llvm/MC/MCELFStreamer.h"
> +
> +namespace llvm {
> +class MipsSubtarget;
> +
> +class MipsELFStreamer : public MCELFStreamer {
> +private:
> +  unsigned EFlags;

This member variable is unused. I've removed it in r173887 to clean up
the Clang -Werror build.

> +public:
> +  MipsELFStreamer(MCContext &Context, MCAsmBackend &TAB,
> +                  raw_ostream &OS, MCCodeEmitter *Emitter,
> +                  bool RelaxAll, bool NoExecStack)
> +    : MCELFStreamer(Context, TAB, OS, Emitter), EFlags(0) {
> +  }
> +
> +  ~MipsELFStreamer() {}
> +  void emitELFHeaderFlagsCG(const MipsSubtarget &Subtarget);
> +//  void emitELFHeaderFlagCG(unsigned Val);
> +};
> +
> +  MCELFStreamer* createMipsELFStreamer(MCContext &Context, MCAsmBackend &TAB,
> +                                       raw_ostream &OS, MCCodeEmitter *Emitter,
> +                                       bool RelaxAll, bool NoExecStack);
> +}
> +
> +#endif /* MIPSELFSTREAMER_H_ */
>
> Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp?rev=173884&r1=173883&r2=173884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp (original)
> +++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp Tue Jan 29 20:16:36 2013
> @@ -11,6 +11,7 @@
>  //
>  //===----------------------------------------------------------------------===//
>
> +#include "MCTargetDesc/MipsELFStreamer.h"
>  #include "MipsMCTargetDesc.h"
>  #include "InstPrinter/MipsInstPrinter.h"
>  #include "MipsMCAsmInfo.h"
> @@ -131,7 +132,7 @@ static MCStreamer *createMCStreamer(cons
>                                      bool NoExecStack) {
>    Triple TheTriple(TT);
>
> -  return createELFStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll, NoExecStack);
> +  return createMipsELFStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll, NoExecStack);
>  }
>
>  extern "C" void LLVMInitializeMipsTargetMC() {
>
> Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=173884&r1=173883&r2=173884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Tue Jan 29 20:16:36 2013
> @@ -15,6 +15,7 @@
>  #define DEBUG_TYPE "mips-asm-printer"
>  #include "InstPrinter/MipsInstPrinter.h"
>  #include "MCTargetDesc/MipsBaseInfo.h"
> +#include "MCTargetDesc/MipsELFStreamer.h"
>  #include "Mips.h"
>  #include "MipsAsmPrinter.h"
>  #include "MipsInstrInfo.h"
> @@ -545,9 +546,13 @@ void MipsAsmPrinter::EmitStartOfAsmFile(
>
>  void MipsAsmPrinter::EmitEndOfAsmFile(Module &M) {
>
> +  if (OutStreamer.hasRawTextSupport()) return;
> +
>    // Emit Mips ELF register info
>    Subtarget->getMReginfo().emitMipsReginfoSectionCG(
>               OutStreamer, getObjFileLowering(), *Subtarget);
> +  MipsELFStreamer & MES = static_cast<MipsELFStreamer &>(OutStreamer);
> +  MES.emitELFHeaderFlagsCG(*Subtarget);
>  }
>
>  MachineLocation
>
> Modified: llvm/trunk/lib/Target/Mips/MipsSubtarget.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsSubtarget.cpp?rev=173884&r1=173883&r2=173884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MipsSubtarget.cpp (original)
> +++ llvm/trunk/lib/Target/Mips/MipsSubtarget.cpp Tue Jan 29 20:16:36 2013
> @@ -26,13 +26,13 @@ void MipsSubtarget::anchor() { }
>
>  MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
>                               const std::string &FS, bool little,
> -                             Reloc::Model RM) :
> +                             Reloc::Model _RM) :
>    MipsGenSubtargetInfo(TT, CPU, FS),
>    MipsArchVersion(Mips32), MipsABI(UnknownABI), IsLittle(little),
>    IsSingleFloat(false), IsFP64bit(false), IsGP64bit(false), HasVFPU(false),
>    IsLinux(true), HasSEInReg(false), HasCondMov(false), HasSwap(false),
>    HasBitCount(false), HasFPIdx(false),
> -  InMips16Mode(false), HasDSP(false), HasDSPR2(false), IsAndroid(false)
> +  InMips16Mode(false), HasDSP(false), HasDSPR2(false), IsAndroid(false), RM(_RM)
>  {
>    std::string CPUName = CPU;
>    if (CPUName.empty())
>
> Modified: llvm/trunk/lib/Target/Mips/MipsSubtarget.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsSubtarget.h?rev=173884&r1=173883&r2=173884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MipsSubtarget.h (original)
> +++ llvm/trunk/lib/Target/Mips/MipsSubtarget.h Tue Jan 29 20:16:36 2013
> @@ -100,6 +100,9 @@ protected:
>    // The instance to the register info section object
>    MipsReginfo MRI;
>
> +  // Relocation Model
> +  Reloc::Model RM;
> +
>  public:
>    virtual bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
>                                       AntiDepBreakMode& Mode,
> @@ -152,6 +155,9 @@ public:
>
>    // Grab MipsRegInfo object
>    const MipsReginfo &getMReginfo() const { return MRI; }
> +
> +  // Grab relocation model
> +  Reloc::Model getRelocationModel() const {return RM;}
>  };
>  } // End llvm namespace
>
>
> Added: llvm/trunk/test/MC/Mips/elf_eflags.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/elf_eflags.ll?rev=173884&view=auto
> ==============================================================================
> --- llvm/trunk/test/MC/Mips/elf_eflags.ll (added)
> +++ llvm/trunk/test/MC/Mips/elf_eflags.ll Tue Jan 29 20:16:36 2013
> @@ -0,0 +1,55 @@
> +; This tests ELF EFLAGS setting with direct object.
> +; When the assembler is ready a .s file for it will
> +; be created.
> +
> +; Non-shared (static) is the absence of pic and or cpic.
> +
> +; EF_MIPS_NOREORDER (0x00000001) is always on by default currently
> +; EF_MIPS_PIC (0x00000002)
> +; EF_MIPS_CPIC (0x00000004) - not tested yet
> +; EF_MIPS_ABI2 (0x00000020) - n32 not tested yet
> +; EF_MIPS_ARCH_32 (0x50000000)
> +; EF_MIPS_ARCH_64 (0x60000000)
> +; EF_MIPS_ARCH_32R2 (0x70000000)
> +; EF_MIPS_ARCH_64R2 (0x80000000)
> +
> +; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips32 -relocation-model=static %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE32 %s
> +; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips32 %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE32_PIC %s
> +; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips32r2 -relocation-model=static %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE32R2 %s
> +; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips32r2 %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE32R2_PIC %s
> +
> +; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips64 -relocation-model=static %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE64 %s
> +; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips64 %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE64_PIC %s
> +; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips64r2 -relocation-model=static %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE64R2 %s
> +; RUN: llc -filetype=obj -mtriple mipsel-unknown-linux -mcpu=mips64r2 %s -o - | elf-dump --dump-section-data  | FileCheck -check-prefix=CHECK-BE64R2_PIC %s
> +
> +
> +; 32(R1) bit with NO_REORDER and static
> +; CHECK-BE32: ('e_flags', 0x50000001)
> +;
> +; 32(R1) bit with NO_REORDER and PIC
> +; CHECK-BE32_PIC: ('e_flags', 0x50000003)
> +;
> +; 32R2 bit with NO_REORDER and static
> +; CHECK-BE32R2: ('e_flags', 0x70000001)
> +;
> +; 32R2 bit with NO_REORDER and PIC
> +; CHECK-BE32R2_PIC: ('e_flags', 0x70000003)
> +;
> +; 64(R1) bit with NO_REORDER and static
> +; CHECK-BE64: ('e_flags', 0x60000001)
> +;
> +; 64(R1) bit with NO_REORDER and PIC
> +; CHECK-BE64_PIC: ('e_flags', 0x60000003)
> +;
> +; 64R2 bit with NO_REORDER and static
> +; CHECK-BE64R2: ('e_flags', 0x80000001)
> +;
> +; 64R2 bit with NO_REORDER and PIC
> +; CHECK-BE64R2_PIC: ('e_flags', 0x80000003)
> +;
> +
> +define i32 @main() nounwind {
> +entry:
> +  ret i32 0
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list