summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-01-14 04:25:13 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-01-14 04:25:13 +0000
commit3c733ea0649665b81947de596d410a5c4f42f5f4 (patch)
tree5ca3a0eb19cf878d00fbd4cb086834685b00a4be
parentdfa550a1761a85417d0e42c8cd17cd08e753388b (diff)
downloadllvm-3c733ea0649665b81947de596d410a5c4f42f5f4.tar.gz
llvm-3c733ea0649665b81947de596d410a5c4f42f5f4.tar.bz2
llvm-3c733ea0649665b81947de596d410a5c4f42f5f4.tar.xz
Replace .mips_hack_stocg with ".set micromips" and ".set nomicromips".
This matches what gnu as does and implementing this is easier than arguing about it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199181 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/MC/MCStreamer.h3
-rw-r--r--lib/MC/MCStreamer.cpp5
-rw-r--r--lib/Target/Mips/AsmParser/MipsAsmParser.cpp33
-rw-r--r--lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp38
-rw-r--r--lib/Target/Mips/MipsAsmPrinter.cpp6
-rw-r--r--lib/Target/Mips/MipsTargetStreamer.h14
-rw-r--r--test/MC/Mips/elf_st_other.ll3
-rw-r--r--test/MC/Mips/elf_st_other.s26
8 files changed, 67 insertions, 61 deletions
diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h
index ad6a4086e1..fb94f9d5ff 100644
--- a/include/llvm/MC/MCStreamer.h
+++ b/include/llvm/MC/MCStreamer.h
@@ -71,6 +71,9 @@ protected:
public:
virtual ~MCTargetStreamer();
void setStreamer(MCStreamer *S) { Streamer = S; }
+
+ // Allow a target to add behavior to the EmitLabel of MCStreamer.
+ virtual void emitLabel(MCSymbol *Symbol);
};
// FIXME: declared here because it is used from
diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp
index 22e1d47b00..7cf1ffa95e 100644
--- a/lib/MC/MCStreamer.cpp
+++ b/lib/MC/MCStreamer.cpp
@@ -24,6 +24,7 @@ using namespace llvm;
// Pin the vtables to this file.
MCTargetStreamer::~MCTargetStreamer() {}
+void MCTargetStreamer::emitLabel(MCSymbol *Symbol) {}
void ARMTargetStreamer::anchor() {}
MCStreamer::MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer)
@@ -214,6 +215,10 @@ void MCStreamer::EmitLabel(MCSymbol *Symbol) {
assert(getCurrentSection().first && "Cannot emit before setting section!");
AssignSection(Symbol, getCurrentSection().first);
LastSymbol = Symbol;
+
+ MCTargetStreamer *TS = getTargetStreamer();
+ if (TS)
+ TS->emitLabel(Symbol);
}
void MCStreamer::EmitDebugLabel(MCSymbol *Symbol) {
diff --git a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index 90150b89e9..31ece464bb 100644
--- a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -194,7 +194,6 @@ class MipsAsmParser : public MCTargetAsmParser {
bool isEvaluated(const MCExpr *Expr);
bool parseDirectiveSet();
- bool parseDirectiveMipsHackStocg();
bool parseDirectiveMipsHackELFFlags();
bool parseDirectiveOption();
@@ -2388,7 +2387,11 @@ bool MipsAsmParser::parseDirectiveSet() {
Parser.eatToEndOfStatement();
return false;
} else if (Tok.getString() == "nomicromips") {
- // Ignore this directive for now.
+ getTargetStreamer().emitDirectiveSetNoMicroMips();
+ Parser.eatToEndOfStatement();
+ return false;
+ } else if (Tok.getString() == "micromips") {
+ getTargetStreamer().emitDirectiveSetMicroMips();
Parser.eatToEndOfStatement();
return false;
} else {
@@ -2400,29 +2403,6 @@ bool MipsAsmParser::parseDirectiveSet() {
return true;
}
-bool MipsAsmParser::parseDirectiveMipsHackStocg() {
- MCAsmParser &Parser = getParser();
- StringRef Name;
- if (Parser.parseIdentifier(Name))
- reportParseError("expected identifier");
-
- MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
- if (getLexer().isNot(AsmToken::Comma)) {
- TokError("unexpected token");
- return false;
- }
- Lex();
-
- int64_t Flags = 0;
- if (Parser.parseAbsoluteExpression(Flags)) {
- TokError("unexpected token");
- return false;
- }
-
- getTargetStreamer().emitMipsHackSTOCG(Sym, Flags);
- return false;
-}
-
bool MipsAsmParser::parseDirectiveMipsHackELFFlags() {
int64_t Flags = 0;
if (Parser.parseAbsoluteExpression(Flags)) {
@@ -2552,9 +2532,6 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
return false;
}
- if (IDVal == ".mips_hack_stocg")
- return parseDirectiveMipsHackStocg();
-
if (IDVal == ".mips_hack_elf_flags")
return parseDirectiveMipsHackELFFlags();
diff --git a/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
index 16203a0dcb..48af1a71ca 100644
--- a/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
+++ b/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
@@ -38,16 +38,15 @@ void MipsTargetAsmStreamer::emitMipsHackELFFlags(unsigned Flags) {
OS.write_hex(Flags);
OS << '\n';
}
-void MipsTargetAsmStreamer::emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) {
- if (!PrintHackDirectives)
- return;
- OS << "\t.mips_hack_stocg ";
- OS << Sym->getName();
- OS << ", ";
- OS << Val;
- OS << '\n';
+void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
+ OS << "\t.set\tmicromips\n";
+}
+
+void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
+ OS << "\t.set\tnomicromips\n";
}
+
void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
OS << "\t.option\tpic0\n";
@@ -56,6 +55,15 @@ void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
// This part is for ELF object output.
MipsTargetELFStreamer::MipsTargetELFStreamer() {}
+void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
+ MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Symbol);
+ // The "other" values are stored in the last 6 bits of the second byte
+ // The traditional defines for STO values assume the full byte and thus
+ // the shift to pack it.
+ if (isMicroMipsEnabled())
+ MCELF::setOther(Data, ELF::STO_MIPS_MICROMIPS >> 2);
+}
+
MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
return static_cast<MCELFStreamer &>(*Streamer);
}
@@ -65,14 +73,14 @@ void MipsTargetELFStreamer::emitMipsHackELFFlags(unsigned Flags) {
MCA.setELFHeaderEFlags(Flags);
}
-// Set a symbol's STO flags.
-void MipsTargetELFStreamer::emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) {
- MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Sym);
- // The "other" values are stored in the last 6 bits of the second byte
- // The traditional defines for STO values assume the full byte and thus
- // the shift to pack it.
- MCELF::setOther(Data, Val >> 2);
+void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
+ MicroMipsEnabled = true;
+}
+
+void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
+ MicroMipsEnabled = false;
}
+
void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
MCAssembler &MCA = getStreamer().getAssembler();
unsigned Flags = MCA.getELFHeaderEFlags();
diff --git a/lib/Target/Mips/MipsAsmPrinter.cpp b/lib/Target/Mips/MipsAsmPrinter.cpp
index f89085de89..2bd6df7fd3 100644
--- a/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -265,6 +265,9 @@ const char *MipsAsmPrinter::getCurrentABIString() const {
}
void MipsAsmPrinter::EmitFunctionEntryLabel() {
+ if (Subtarget->inMicroMipsMode())
+ getTargetStreamer().emitDirectiveSetMicroMips();
+
if (OutStreamer.hasRawTextSupport()) {
if (Subtarget->inMips16Mode())
OutStreamer.EmitRawText(StringRef("\t.set\tmips16"));
@@ -275,9 +278,6 @@ void MipsAsmPrinter::EmitFunctionEntryLabel() {
OutStreamer.EmitRawText("\t.ent\t" + Twine(CurrentFnSym->getName()));
}
- if (Subtarget->inMicroMipsMode())
- getTargetStreamer().emitMipsHackSTOCG(CurrentFnSym,
- (unsigned)ELF::STO_MIPS_MICROMIPS);
OutStreamer.EmitLabel(CurrentFnSym);
}
diff --git a/lib/Target/Mips/MipsTargetStreamer.h b/lib/Target/Mips/MipsTargetStreamer.h
index 8c53cb5bc2..4d1dd0090d 100644
--- a/lib/Target/Mips/MipsTargetStreamer.h
+++ b/lib/Target/Mips/MipsTargetStreamer.h
@@ -19,7 +19,8 @@ class MipsTargetStreamer : public MCTargetStreamer {
public:
virtual void emitMipsHackELFFlags(unsigned Flags) = 0;
- virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) = 0;
+ virtual void emitDirectiveSetMicroMips() = 0;
+ virtual void emitDirectiveSetNoMicroMips() = 0;
virtual void emitDirectiveAbiCalls() = 0;
virtual void emitDirectiveOptionPic0() = 0;
};
@@ -31,19 +32,26 @@ class MipsTargetAsmStreamer : public MipsTargetStreamer {
public:
MipsTargetAsmStreamer(formatted_raw_ostream &OS);
virtual void emitMipsHackELFFlags(unsigned Flags);
- virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val);
+ virtual void emitDirectiveSetMicroMips();
+ virtual void emitDirectiveSetNoMicroMips();
virtual void emitDirectiveAbiCalls();
virtual void emitDirectiveOptionPic0();
};
// This part is for ELF object output
class MipsTargetELFStreamer : public MipsTargetStreamer {
+ bool MicroMipsEnabled;
public:
+ bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
MCELFStreamer &getStreamer();
MipsTargetELFStreamer();
+
+ virtual void emitLabel(MCSymbol *Symbol) LLVM_OVERRIDE;
+
// FIXME: emitMipsHackELFFlags() will be removed from this class.
virtual void emitMipsHackELFFlags(unsigned Flags);
- virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val);
+ virtual void emitDirectiveSetMicroMips();
+ virtual void emitDirectiveSetNoMicroMips();
virtual void emitDirectiveAbiCalls();
virtual void emitDirectiveOptionPic0();
};
diff --git a/test/MC/Mips/elf_st_other.ll b/test/MC/Mips/elf_st_other.ll
index 31294c88f8..68cad48ffd 100644
--- a/test/MC/Mips/elf_st_other.ll
+++ b/test/MC/Mips/elf_st_other.ll
@@ -8,4 +8,5 @@ entry:
ret i32 0
}
-; CHECK: .mips_hack_stocg main, 128
+; CHECK: .set micromips
+; CHECK: main:
diff --git a/test/MC/Mips/elf_st_other.s b/test/MC/Mips/elf_st_other.s
index 2d63288779..eb685c3760 100644
--- a/test/MC/Mips/elf_st_other.s
+++ b/test/MC/Mips/elf_st_other.s
@@ -1,13 +1,17 @@
// RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux %s -o -| llvm-readobj -t | FileCheck %s
- .text
- .globl main
- .align 2
- .type main,@function
- .set nomips16 # @main
- .ent main
- .mips_hack_stocg main, 128
-main:
-
-// CHECK: Name: main
-// CHECK: Other: 128
+
+.globl f1
+.set micromips
+f1:
+ nop
+
+.globl f2
+.set nomicromips
+f2:
+ nop
+
+// CHECK-LABEL: Name: f1
+// CHECK: Other: 128
+// CHECK-LABEL: Name: f2
+// CHECK: Other: 0