diff options
author | Daniel Sanders <daniel.sanders@imgtec.com> | 2014-07-10 13:38:23 +0000 |
---|---|---|
committer | Daniel Sanders <daniel.sanders@imgtec.com> | 2014-07-10 13:38:23 +0000 |
commit | 7e527423f54f413ae304900ee4b3ef4a17cd4fb1 (patch) | |
tree | cf77e01985054a64bd2715c0ff8f203cadac4511 /llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | |
parent | cad431c122ea678344ac465c5bce626720dcc94e (diff) | |
download | bcm5719-llvm-7e527423f54f413ae304900ee4b3ef4a17cd4fb1.tar.gz bcm5719-llvm-7e527423f54f413ae304900ee4b3ef4a17cd4fb1.zip |
[mips] Add support for -modd-spreg/-mno-odd-spreg
Summary:
When -mno-odd-spreg is in effect, 32-bit floating point values are not
permitted in odd FPU registers. The option also prohibits 32-bit and 64-bit
floating point comparison results from being written to odd registers.
This option has three purposes:
* It allows support for certain MIPS implementations such as loongson-3a that
do not allow the use of odd registers for single precision arithmetic.
* When using -mfpxx, -mno-odd-spreg is the default and this allows us to
statically check that code is compliant with the O32 FPXX ABI since mtc1/mfc1
instructions to/from odd registers are guaranteed not to appear for any
reason. Once this has been established, the user can then re-enable
-modd-spreg to regain the use of all 32 single-precision registers.
* When using -mfp64 and -mno-odd-spreg together, an O32 extension named
O32 FP64A is used as the ABI. This is intended to provide almost all
functionality of an FR=1 processor but can also be executed on a FR=0 core
with the assistance of a hardware compatibility mode which emulates FR=0
behaviour on an FR=1 processor.
* Added '.module oddspreg' and '.module nooddspreg' each of which update
the .MIPS.abiflags section appropriately
* Moved setFpABI() call inside emitDirectiveModuleFP() so that the caller
doesn't have to remember to do it.
* MipsABIFlags now calculates the flags1 and flags2 member on demand rather
than trying to maintain them in the same format they will be emitted in.
There is one portion of the -mfp64 and -mno-odd-spreg combination that is not
implemented yet. Moves to/from odd-numbered double-precision registers must not
use mtc1. I will fix this in a follow-up.
Differential Revision: http://reviews.llvm.org/D4383
llvm-svn: 212717
Diffstat (limited to 'llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp')
-rw-r--r-- | llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 108 |
1 files changed, 77 insertions, 31 deletions
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 44f18a8d1cb..0c06be8c7d9 100644 --- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -165,7 +165,8 @@ class MipsAsmParser : public MCTargetAsmParser { bool parseDirectiveGpDWord(); bool parseDirectiveModule(); bool parseDirectiveModuleFP(); - bool parseFpABIValue(Val_GNU_MIPS_ABI &FpABI, StringRef Directive); + bool parseFpABIValue(MipsABIFlagsSection::FpABIKind &FpABI, + StringRef Directive); MCSymbolRefExpr::VariantKind getVariantKind(StringRef Symbol); @@ -235,6 +236,9 @@ public: ((STI.getFeatureBits() & Mips::FeatureEABI) != 0) + ((STI.getFeatureBits() & Mips::FeatureN32) != 0) + ((STI.getFeatureBits() & Mips::FeatureN64) != 0)) == 1); + + if (!isABI_O32() && !allowOddSPReg() != 0) + report_fatal_error("-mno-odd-spreg requires the O32 ABI"); } MCAsmParser &getParser() const { return Parser; } @@ -250,6 +254,10 @@ public: bool isABI_O32() const { return STI.getFeatureBits() & Mips::FeatureO32; } bool isABI_FPXX() const { return false; } // TODO: add check for FeatureXX + bool allowOddSPReg() const { + return !(STI.getFeatureBits() & Mips::FeatureNoOddSPReg); + } + bool inMicroMipsMode() const { return STI.getFeatureBits() & Mips::FeatureMicroMips; } @@ -563,6 +571,10 @@ public: void addFGR32AsmRegOperands(MCInst &Inst, unsigned N) const { assert(N == 1 && "Invalid number of operands!"); Inst.addOperand(MCOperand::CreateReg(getFGR32Reg())); + // FIXME: We ought to do this for -integrated-as without -via-file-asm too. + if (!AsmParser.allowOddSPReg() && RegIdx.Index & 1) + AsmParser.Error(StartLoc, "-mno-odd-spreg prohibits the use of odd FPU " + "registers"); } void addFGRH32AsmRegOperands(MCInst &Inst, unsigned N) const { @@ -2444,7 +2456,7 @@ bool MipsAsmParser::parseSetNoMips16Directive() { } bool MipsAsmParser::parseSetFpDirective() { - Val_GNU_MIPS_ABI FpAbiVal; + MipsABIFlagsSection::FpABIKind FpAbiVal; // Line can be: .set fp=32 // .set fp=xx // .set fp=64 @@ -2464,7 +2476,7 @@ bool MipsAsmParser::parseSetFpDirective() { reportParseError("unexpected token in statement"); return false; } - getTargetStreamer().emitDirectiveSetFp(FpAbiVal, isABI_O32()); + getTargetStreamer().emitDirectiveSetFp(FpAbiVal); Parser.Lex(); // Consume the EndOfStatement. return false; } @@ -2784,29 +2796,73 @@ bool MipsAsmParser::parseDirectiveOption() { return false; } +/// parseDirectiveModule +/// ::= .module oddspreg +/// ::= .module nooddspreg +/// ::= .module fp=value bool MipsAsmParser::parseDirectiveModule() { - // Line can be: .module fp=32 - // .module fp=xx - // .module fp=64 + MCAsmLexer &Lexer = getLexer(); + SMLoc L = Lexer.getLoc(); + if (!getTargetStreamer().getCanHaveModuleDir()) { // TODO : get a better message. reportParseError(".module directive must appear before any code"); return false; } - AsmToken Tok = Parser.getTok(); - if (Tok.isNot(AsmToken::Identifier) && Tok.getString() != "fp") { - reportParseError("unexpected token in .module directive, 'fp' expected"); - return false; + + if (Lexer.is(AsmToken::Identifier)) { + StringRef Option = Parser.getTok().getString(); + Parser.Lex(); + + if (Option == "oddspreg") { + getTargetStreamer().emitDirectiveModuleOddSPReg(true, isABI_O32()); + clearFeatureBits(Mips::FeatureNoOddSPReg, "nooddspreg"); + + if (getLexer().isNot(AsmToken::EndOfStatement)) { + reportParseError("Expected end of statement"); + return false; + } + + return false; + } else if (Option == "nooddspreg") { + if (!isABI_O32()) { + Error(L, "'.module nooddspreg' requires the O32 ABI"); + return false; + } + + getTargetStreamer().emitDirectiveModuleOddSPReg(false, isABI_O32()); + setFeatureBits(Mips::FeatureNoOddSPReg, "nooddspreg"); + + if (getLexer().isNot(AsmToken::EndOfStatement)) { + reportParseError("Expected end of statement"); + return false; + } + + return false; + } else if (Option == "fp") { + return parseDirectiveModuleFP(); + } + + return Error(L, "'" + Twine(Option) + "' is not a valid .module option."); } - Parser.Lex(); // Eat fp token - Tok = Parser.getTok(); - if (Tok.isNot(AsmToken::Equal)) { + + return false; +} + +/// parseDirectiveModuleFP +/// ::= =32 +/// ::= =xx +/// ::= =64 +bool MipsAsmParser::parseDirectiveModuleFP() { + MCAsmLexer &Lexer = getLexer(); + + if (Lexer.isNot(AsmToken::Equal)) { reportParseError("unexpected token in statement"); return false; } Parser.Lex(); // Eat '=' token. - Val_GNU_MIPS_ABI FpABI; + MipsABIFlagsSection::FpABIKind FpABI; if (!parseFpABIValue(FpABI, ".module")) return false; @@ -2817,11 +2873,11 @@ bool MipsAsmParser::parseDirectiveModule() { // Emit appropriate flags. getTargetStreamer().emitDirectiveModuleFP(FpABI, isABI_O32()); - + Parser.Lex(); // Consume the EndOfStatement. return false; } -bool MipsAsmParser::parseFpABIValue(Val_GNU_MIPS_ABI &FpABI, +bool MipsAsmParser::parseFpABIValue(MipsABIFlagsSection::FpABIKind &FpABI, StringRef Directive) { MCAsmLexer &Lexer = getLexer(); @@ -2839,7 +2895,7 @@ bool MipsAsmParser::parseFpABIValue(Val_GNU_MIPS_ABI &FpABI, return false; } - FpABI = MipsABIFlagsSection::Val_GNU_MIPS_ABI_FP_XX; + FpABI = MipsABIFlagsSection::FpABIKind::XX; return true; } @@ -2858,21 +2914,11 @@ bool MipsAsmParser::parseFpABIValue(Val_GNU_MIPS_ABI &FpABI, return false; } - FpABI = MipsABIFlagsSection::Val_GNU_MIPS_ABI_FP_DOUBLE; - return true; - } else { - if (isABI_N32() || isABI_N64()) { - FpABI = MipsABIFlagsSection::Val_GNU_MIPS_ABI_FP_DOUBLE; - return true; - } + FpABI = MipsABIFlagsSection::FpABIKind::S32; + } else + FpABI = MipsABIFlagsSection::FpABIKind::S64; - if (isABI_O32()) { - FpABI = MipsABIFlagsSection::Val_GNU_MIPS_ABI_FP_64; - return true; - } - - llvm_unreachable("Unknown ABI"); - } + return true; } return false; |