Skip to content

Commit

Permalink
This reverts commit r200064 and r200051.
Browse files Browse the repository at this point in the history
r200064 depends on r200051.

r200051 is broken: I tries to replace .mips_hack_elf_flags, which is a good
thing, but what it replaces it with is even worse.

The new emitMipsELFFlags it adds corresponds to no assembly directive, is not
marked as a hack and is not even printed to the .s file.

The patch also introduces more uses of hasRawTextSupport.

The correct way to remove .mips_hack_elf_flags is to have the mips target
streamer handle the default flags (and command line options). That way the
same code path is used for asm and obj. The streamer interface should *really*
correspond to what is printed in the .s file.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200078 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Jan 25, 2014
1 parent 754b83a commit 86b535b
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 206 deletions.
59 changes: 15 additions & 44 deletions lib/Target/Mips/AsmParser/MipsAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCTargetAsmParser.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/ADT/APInt.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/TargetRegistry.h"

Expand Down Expand Up @@ -197,6 +194,7 @@ class MipsAsmParser : public MCTargetAsmParser {

bool isEvaluated(const MCExpr *Expr);
bool parseDirectiveSet();
bool parseDirectiveMipsHackELFFlags();
bool parseDirectiveOption();

bool parseSetAtDirective();
Expand Down Expand Up @@ -259,17 +257,13 @@ class MipsAsmParser : public MCTargetAsmParser {
// Example: INSERT.B $w0[n], $1 => 16 > n >= 0
bool validateMSAIndex(int Val, int RegKind);

// Set ELF flags based on defaults and commandline arguments.
void processInitialEFlags();

public:
MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
const MCInstrInfo &MII)
: MCTargetAsmParser(), STI(sti), Parser(parser),
hasConsumedDollar(false) {
// Initialize the set of available features.
setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
processInitialEFlags();
}

MCAsmParser &getParser() const { return Parser; }
Expand Down Expand Up @@ -2435,6 +2429,17 @@ bool MipsAsmParser::parseDirectiveSet() {
return true;
}

bool MipsAsmParser::parseDirectiveMipsHackELFFlags() {
int64_t Flags = 0;
if (Parser.parseAbsoluteExpression(Flags)) {
TokError("unexpected token");
return false;
}

getTargetStreamer().emitMipsHackELFFlags(Flags);
return false;
}

/// parseDirectiveWord
/// ::= .word [ expression (, expression)* ]
bool MipsAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Expand Down Expand Up @@ -2553,6 +2558,9 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
return false;
}

if (IDVal == ".mips_hack_elf_flags")
return parseDirectiveMipsHackELFFlags();

if (IDVal == ".option")
return parseDirectiveOption();

Expand All @@ -2569,43 +2577,6 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
return true;
}

void MipsAsmParser::processInitialEFlags() {
// Start will a clean slate.
unsigned EFlags = 0;
unsigned FeatureBits = STI.getFeatureBits();

// Default settings
EFlags |= ELF::EF_MIPS_NOREORDER | ELF::EF_MIPS_PIC | ELF::EF_MIPS_ABI_O32;

// ISA
if (FeatureBits & Mips::FeatureMips64r2) {
EFlags |= ELF::EF_MIPS_ARCH_64R2;
EFlags &= ~ELF::EF_MIPS_ABI_O32;
} else if (FeatureBits & Mips::FeatureMips64) {
EFlags |= ELF::EF_MIPS_ARCH_64;
EFlags &= ~ELF::EF_MIPS_ABI_O32;
} else if (FeatureBits & Mips::FeatureMips32r2)
EFlags |= ELF::EF_MIPS_ARCH_32R2;
else if (FeatureBits & Mips::FeatureMips32)
EFlags |= ELF::EF_MIPS_ARCH_32;
else if (FeatureBits & Mips::FeatureO32)
EFlags |= ELF::EF_MIPS_ABI_O32; // This is really a zero

// ASE
if (FeatureBits & Mips::FeatureMicroMips)
EFlags |= ELF::EF_MIPS_MICROMIPS;
else if (FeatureBits & Mips::FeatureMips16)
EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;

// ABI
// TODO: n32/eabi

// Linkage model
// TODO: pic/cpic/static

getTargetStreamer().emitMipsELFFlags(EFlags);
}

extern "C" void LLVMInitializeMipsAsmParser() {
RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);
Expand Down
14 changes: 12 additions & 2 deletions lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@

using namespace llvm;

static cl::opt<bool> PrintHackDirectives("print-hack-directives",
cl::init(false), cl::Hidden);

// Pin vtable to this file.
void MipsTargetStreamer::anchor() {}

MipsTargetAsmStreamer::MipsTargetAsmStreamer(formatted_raw_ostream &OS)
: OS(OS) {}

void MipsTargetAsmStreamer::emitMipsELFFlags(unsigned Flags) { return; }
void MipsTargetAsmStreamer::emitMipsHackELFFlags(unsigned Flags) {
if (!PrintHackDirectives)
return;

OS << "\t.mips_hack_elf_flags 0x";
OS.write_hex(Flags);
OS << '\n';
}

void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
OS << "\t.set\tmicromips\n";
Expand Down Expand Up @@ -75,7 +85,7 @@ MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
return static_cast<MCELFStreamer &>(*Streamer);
}

void MipsTargetELFStreamer::emitMipsELFFlags(unsigned Flags) {
void MipsTargetELFStreamer::emitMipsHackELFFlags(unsigned Flags) {
MCAssembler &MCA = getStreamer().getAssembler();
MCA.setELFHeaderEFlags(Flags);
}
Expand Down
26 changes: 12 additions & 14 deletions lib/Target/Mips/MipsAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void MipsAsmPrinter::EmitInstruction(const MachineInstr *MI) {
return;
}


MachineBasicBlock::const_instr_iterator I = MI;
MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end();

Expand Down Expand Up @@ -633,57 +634,54 @@ void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {

}

void MipsAsmPrinter::processInitialEFlags() {
// Not having this check would work too, but would have us chew through
// code that it doesn't use for RawText.
if (OutStreamer.hasRawTextSupport())
return;

static void emitELFHeaderFlagsCG(MipsTargetStreamer &TargetStreamer,
const MipsSubtarget &Subtarget) {
// Update e_header flags
unsigned EFlags = 0;

// TODO: Need to add -mabicalls and -mno-abicalls flags.
// Currently we assume that -mabicalls is the default.
EFlags |= ELF::EF_MIPS_CPIC;

if (Subtarget->inMips16Mode())
if (Subtarget.inMips16Mode())
EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;
else
EFlags |= ELF::EF_MIPS_NOREORDER;

// Architecture
if (Subtarget->hasMips64r2())
if (Subtarget.hasMips64r2())
EFlags |= ELF::EF_MIPS_ARCH_64R2;
else if (Subtarget->hasMips64())
else if (Subtarget.hasMips64())
EFlags |= ELF::EF_MIPS_ARCH_64;
else if (Subtarget->hasMips32r2())
else if (Subtarget.hasMips32r2())
EFlags |= ELF::EF_MIPS_ARCH_32R2;
else
EFlags |= ELF::EF_MIPS_ARCH_32;

if (Subtarget->inMicroMipsMode())
if (Subtarget.inMicroMipsMode())
EFlags |= ELF::EF_MIPS_MICROMIPS;

// ABI
if (Subtarget->isABI_O32())
if (Subtarget.isABI_O32())
EFlags |= ELF::EF_MIPS_ABI_O32;

// Relocation Model
Reloc::Model RM = Subtarget->getRelocationModel();
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");

getTargetStreamer().emitMipsELFFlags(EFlags);
TargetStreamer.emitMipsHackELFFlags(EFlags);
}

void MipsAsmPrinter::EmitEndOfAsmFile(Module &M) {
// Emit Mips ELF register info
Subtarget->getMReginfo().emitMipsReginfoSectionCG(
OutStreamer, getObjFileLowering(), *Subtarget);
emitELFHeaderFlagsCG(getTargetStreamer(), *Subtarget);
}

void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
Expand Down
6 changes: 0 additions & 6 deletions lib/Target/Mips/MipsAsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
/// pool entries so we can properly mark them as data regions.
bool InConstantPool;

// If object output, set initial eflags.
// This includes both default and commandline flags that affect the output
// ELF header flags.
void processInitialEFlags();

public:

Expand All @@ -65,7 +61,6 @@ class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
: AsmPrinter(TM, Streamer), MCP(0), InConstantPool(false),
MCInstLowering(*this) {
Subtarget = &TM.getSubtarget<MipsSubtarget>();
processInitialEFlags();
}

virtual const char *getPassName() const {
Expand Down Expand Up @@ -108,7 +103,6 @@ class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
void EmitStartOfAsmFile(Module &M);
void EmitEndOfAsmFile(Module &M);
void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);

};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Target/Mips/MipsTargetStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MipsTargetStreamer : public MCTargetStreamer {
virtual void anchor();

public:
virtual void emitMipsELFFlags(unsigned Flags) = 0;
virtual void emitMipsHackELFFlags(unsigned Flags) = 0;
virtual void emitDirectiveSetMicroMips() = 0;
virtual void emitDirectiveSetNoMicroMips() = 0;
virtual void emitDirectiveSetMips16() = 0;
Expand All @@ -34,7 +34,7 @@ class MipsTargetAsmStreamer : public MipsTargetStreamer {

public:
MipsTargetAsmStreamer(formatted_raw_ostream &OS);
virtual void emitMipsELFFlags(unsigned Flags);
virtual void emitMipsHackELFFlags(unsigned Flags);
virtual void emitDirectiveSetMicroMips();
virtual void emitDirectiveSetNoMicroMips();
virtual void emitDirectiveSetMips16();
Expand All @@ -56,7 +56,7 @@ class MipsTargetELFStreamer : public MipsTargetStreamer {
virtual void emitLabel(MCSymbol *Symbol) LLVM_OVERRIDE;

// FIXME: emitMipsHackELFFlags() will be removed from this class.
virtual void emitMipsELFFlags(unsigned Flags);
virtual void emitMipsHackELFFlags(unsigned Flags);
virtual void emitDirectiveSetMicroMips();
virtual void emitDirectiveSetNoMicroMips();
virtual void emitDirectiveSetMips16();
Expand Down
121 changes: 0 additions & 121 deletions test/CodeGen/Mips/elf_eflags.ll

This file was deleted.

Loading

0 comments on commit 86b535b

Please sign in to comment.