Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 3c733ea

Browse files
committed
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
1 parent dfa550a commit 3c733ea

File tree

8 files changed

+67
-61
lines changed

8 files changed

+67
-61
lines changed

include/llvm/MC/MCStreamer.h

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class MCTargetStreamer {
7171
public:
7272
virtual ~MCTargetStreamer();
7373
void setStreamer(MCStreamer *S) { Streamer = S; }
74+
75+
// Allow a target to add behavior to the EmitLabel of MCStreamer.
76+
virtual void emitLabel(MCSymbol *Symbol);
7477
};
7578

7679
// FIXME: declared here because it is used from

lib/MC/MCStreamer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using namespace llvm;
2424

2525
// Pin the vtables to this file.
2626
MCTargetStreamer::~MCTargetStreamer() {}
27+
void MCTargetStreamer::emitLabel(MCSymbol *Symbol) {}
2728
void ARMTargetStreamer::anchor() {}
2829

2930
MCStreamer::MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer)
@@ -214,6 +215,10 @@ void MCStreamer::EmitLabel(MCSymbol *Symbol) {
214215
assert(getCurrentSection().first && "Cannot emit before setting section!");
215216
AssignSection(Symbol, getCurrentSection().first);
216217
LastSymbol = Symbol;
218+
219+
MCTargetStreamer *TS = getTargetStreamer();
220+
if (TS)
221+
TS->emitLabel(Symbol);
217222
}
218223

219224
void MCStreamer::EmitDebugLabel(MCSymbol *Symbol) {

lib/Target/Mips/AsmParser/MipsAsmParser.cpp

+5-28
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ class MipsAsmParser : public MCTargetAsmParser {
194194

195195
bool isEvaluated(const MCExpr *Expr);
196196
bool parseDirectiveSet();
197-
bool parseDirectiveMipsHackStocg();
198197
bool parseDirectiveMipsHackELFFlags();
199198
bool parseDirectiveOption();
200199

@@ -2388,7 +2387,11 @@ bool MipsAsmParser::parseDirectiveSet() {
23882387
Parser.eatToEndOfStatement();
23892388
return false;
23902389
} else if (Tok.getString() == "nomicromips") {
2391-
// Ignore this directive for now.
2390+
getTargetStreamer().emitDirectiveSetNoMicroMips();
2391+
Parser.eatToEndOfStatement();
2392+
return false;
2393+
} else if (Tok.getString() == "micromips") {
2394+
getTargetStreamer().emitDirectiveSetMicroMips();
23922395
Parser.eatToEndOfStatement();
23932396
return false;
23942397
} else {
@@ -2400,29 +2403,6 @@ bool MipsAsmParser::parseDirectiveSet() {
24002403
return true;
24012404
}
24022405

2403-
bool MipsAsmParser::parseDirectiveMipsHackStocg() {
2404-
MCAsmParser &Parser = getParser();
2405-
StringRef Name;
2406-
if (Parser.parseIdentifier(Name))
2407-
reportParseError("expected identifier");
2408-
2409-
MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
2410-
if (getLexer().isNot(AsmToken::Comma)) {
2411-
TokError("unexpected token");
2412-
return false;
2413-
}
2414-
Lex();
2415-
2416-
int64_t Flags = 0;
2417-
if (Parser.parseAbsoluteExpression(Flags)) {
2418-
TokError("unexpected token");
2419-
return false;
2420-
}
2421-
2422-
getTargetStreamer().emitMipsHackSTOCG(Sym, Flags);
2423-
return false;
2424-
}
2425-
24262406
bool MipsAsmParser::parseDirectiveMipsHackELFFlags() {
24272407
int64_t Flags = 0;
24282408
if (Parser.parseAbsoluteExpression(Flags)) {
@@ -2552,9 +2532,6 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
25522532
return false;
25532533
}
25542534

2555-
if (IDVal == ".mips_hack_stocg")
2556-
return parseDirectiveMipsHackStocg();
2557-
25582535
if (IDVal == ".mips_hack_elf_flags")
25592536
return parseDirectiveMipsHackELFFlags();
25602537

lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp

+23-15
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ void MipsTargetAsmStreamer::emitMipsHackELFFlags(unsigned Flags) {
3838
OS.write_hex(Flags);
3939
OS << '\n';
4040
}
41-
void MipsTargetAsmStreamer::emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) {
42-
if (!PrintHackDirectives)
43-
return;
4441

45-
OS << "\t.mips_hack_stocg ";
46-
OS << Sym->getName();
47-
OS << ", ";
48-
OS << Val;
49-
OS << '\n';
42+
void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
43+
OS << "\t.set\tmicromips\n";
44+
}
45+
46+
void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
47+
OS << "\t.set\tnomicromips\n";
5048
}
49+
5150
void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
5251
void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
5352
OS << "\t.option\tpic0\n";
@@ -56,6 +55,15 @@ void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
5655
// This part is for ELF object output.
5756
MipsTargetELFStreamer::MipsTargetELFStreamer() {}
5857

58+
void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
59+
MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Symbol);
60+
// The "other" values are stored in the last 6 bits of the second byte
61+
// The traditional defines for STO values assume the full byte and thus
62+
// the shift to pack it.
63+
if (isMicroMipsEnabled())
64+
MCELF::setOther(Data, ELF::STO_MIPS_MICROMIPS >> 2);
65+
}
66+
5967
MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
6068
return static_cast<MCELFStreamer &>(*Streamer);
6169
}
@@ -65,14 +73,14 @@ void MipsTargetELFStreamer::emitMipsHackELFFlags(unsigned Flags) {
6573
MCA.setELFHeaderEFlags(Flags);
6674
}
6775

68-
// Set a symbol's STO flags.
69-
void MipsTargetELFStreamer::emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) {
70-
MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Sym);
71-
// The "other" values are stored in the last 6 bits of the second byte
72-
// The traditional defines for STO values assume the full byte and thus
73-
// the shift to pack it.
74-
MCELF::setOther(Data, Val >> 2);
76+
void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
77+
MicroMipsEnabled = true;
78+
}
79+
80+
void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
81+
MicroMipsEnabled = false;
7582
}
83+
7684
void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
7785
MCAssembler &MCA = getStreamer().getAssembler();
7886
unsigned Flags = MCA.getELFHeaderEFlags();

lib/Target/Mips/MipsAsmPrinter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ const char *MipsAsmPrinter::getCurrentABIString() const {
265265
}
266266

267267
void MipsAsmPrinter::EmitFunctionEntryLabel() {
268+
if (Subtarget->inMicroMipsMode())
269+
getTargetStreamer().emitDirectiveSetMicroMips();
270+
268271
if (OutStreamer.hasRawTextSupport()) {
269272
if (Subtarget->inMips16Mode())
270273
OutStreamer.EmitRawText(StringRef("\t.set\tmips16"));
@@ -275,9 +278,6 @@ void MipsAsmPrinter::EmitFunctionEntryLabel() {
275278
OutStreamer.EmitRawText("\t.ent\t" + Twine(CurrentFnSym->getName()));
276279
}
277280

278-
if (Subtarget->inMicroMipsMode())
279-
getTargetStreamer().emitMipsHackSTOCG(CurrentFnSym,
280-
(unsigned)ELF::STO_MIPS_MICROMIPS);
281281
OutStreamer.EmitLabel(CurrentFnSym);
282282
}
283283

lib/Target/Mips/MipsTargetStreamer.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class MipsTargetStreamer : public MCTargetStreamer {
1919

2020
public:
2121
virtual void emitMipsHackELFFlags(unsigned Flags) = 0;
22-
virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) = 0;
22+
virtual void emitDirectiveSetMicroMips() = 0;
23+
virtual void emitDirectiveSetNoMicroMips() = 0;
2324
virtual void emitDirectiveAbiCalls() = 0;
2425
virtual void emitDirectiveOptionPic0() = 0;
2526
};
@@ -31,19 +32,26 @@ class MipsTargetAsmStreamer : public MipsTargetStreamer {
3132
public:
3233
MipsTargetAsmStreamer(formatted_raw_ostream &OS);
3334
virtual void emitMipsHackELFFlags(unsigned Flags);
34-
virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val);
35+
virtual void emitDirectiveSetMicroMips();
36+
virtual void emitDirectiveSetNoMicroMips();
3537
virtual void emitDirectiveAbiCalls();
3638
virtual void emitDirectiveOptionPic0();
3739
};
3840

3941
// This part is for ELF object output
4042
class MipsTargetELFStreamer : public MipsTargetStreamer {
43+
bool MicroMipsEnabled;
4144
public:
45+
bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
4246
MCELFStreamer &getStreamer();
4347
MipsTargetELFStreamer();
48+
49+
virtual void emitLabel(MCSymbol *Symbol) LLVM_OVERRIDE;
50+
4451
// FIXME: emitMipsHackELFFlags() will be removed from this class.
4552
virtual void emitMipsHackELFFlags(unsigned Flags);
46-
virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val);
53+
virtual void emitDirectiveSetMicroMips();
54+
virtual void emitDirectiveSetNoMicroMips();
4755
virtual void emitDirectiveAbiCalls();
4856
virtual void emitDirectiveOptionPic0();
4957
};

test/MC/Mips/elf_st_other.ll

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ entry:
88
ret i32 0
99
}
1010

11-
; CHECK: .mips_hack_stocg main, 128
11+
; CHECK: .set micromips
12+
; CHECK: main:

test/MC/Mips/elf_st_other.s

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux %s -o -| llvm-readobj -t | FileCheck %s
22

3-
.text
4-
.globl main
5-
.align 2
6-
.type main,@function
7-
.set nomips16 # @main
8-
.ent main
9-
.mips_hack_stocg main, 128
10-
main:
11-
12-
// CHECK: Name: main
13-
// CHECK: Other: 128
3+
4+
.globl f1
5+
.set micromips
6+
f1:
7+
nop
8+
9+
.globl f2
10+
.set nomicromips
11+
f2:
12+
nop
13+
14+
// CHECK-LABEL: Name: f1
15+
// CHECK: Other: 128
16+
// CHECK-LABEL: Name: f2
17+
// CHECK: Other: 0

0 commit comments

Comments
 (0)