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, @@ -329,6 +332,9 @@ report_fatal_error("-mno-odd-spreg requires the O32 ABI"); CurrentFn = nullptr; + + UseOptionDirPic = false; + IsOptionDirPicEnabled = false; } MCAsmParser &getParser() const { return Parser; } @@ -378,6 +384,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; } @@ -3168,6 +3181,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)) { @@ -3179,6 +3196,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)) {