Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp =================================================================== --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -10,6 +10,7 @@ #include "MCTargetDesc/MipsMCExpr.h" #include "MCTargetDesc/MipsMCTargetDesc.h" #include "MipsRegisterInfo.h" +#include "MipsTargetObjectFile.h" #include "MipsTargetStreamer.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/StringSwitch.h" @@ -101,6 +102,8 @@ // nullptr, which indicates that no function is currently // selected. This usually happens after an '.end func' // directive. + bool UseOptionDirPic; + bool IsOptionDirPicEnabled; // Print a warning along with its fix-it message at the given range. void printWarningWithFixIt(const Twine &Msg, const Twine &FixMsg, @@ -333,6 +336,9 @@ report_fatal_error("-mno-odd-spreg requires the O32 ABI"); CurrentFn = nullptr; + + UseOptionDirPic = false; + IsOptionDirPicEnabled = false; } MCAsmParser &getParser() const { return Parser; } @@ -382,6 +388,13 @@ bool hasDSPR2() const { return (STI.getFeatureBits() & Mips::FeatureDSPR2); } bool hasMSA() const { return (STI.getFeatureBits() & Mips::FeatureMSA); } + bool inPicMode() { + if (UseOptionDirPic) + return IsOptionDirPicEnabled; + + return getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_; + } + bool inMips16Mode() const { return STI.getFeatureBits() & Mips::FeatureMips16; } @@ -3289,6 +3302,10 @@ StringRef Option = Tok.getIdentifier(); if (Option == "pic0") { + // MipsAsmParser needs to know whether the current PIC mode gets overriden. + UseOptionDirPic = true; + IsOptionDirPicEnabled = false; + getTargetStreamer().emitDirectiveOptionPic0(); Parser.Lex(); if (Parser.getTok().isNot(AsmToken::EndOfStatement)) { @@ -3300,6 +3317,10 @@ } if (Option == "pic2") { + // MipsAsmParser needs to know whether the current PIC mode gets overriden. + UseOptionDirPic = true; + IsOptionDirPicEnabled = true; + getTargetStreamer().emitDirectiveOptionPic2(); Parser.Lex(); if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {