diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
| commit | 344a3780b2e33f6ca763666c380202b18aab72a3 (patch) | |
| tree | f0b203ee6eb71d7fdd792373e3c81eb18d6934dd /llvm/lib/CodeGen/MIRParser/MIRParser.cpp | |
| parent | b60736ec1405bb0a8dd40989f67ef4c93da068ab (diff) | |
vendor/llvm-project/llvmorg-13-init-16847-g88e66fa60ae5vendor/llvm-project/llvmorg-12.0.1-rc2-0-ge7dac564cd0evendor/llvm-project/llvmorg-12.0.1-0-gfed41342a82f
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser/MIRParser.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp index ffa9aeb21edb..d77104752880 100644 --- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -51,9 +51,9 @@ namespace llvm { /// file. class MIRParserImpl { SourceMgr SM; + LLVMContext &Context; yaml::Input In; StringRef Filename; - LLVMContext &Context; SlotMapping IRSlots; std::unique_ptr<PerTargetMIParsingState> Target; @@ -143,6 +143,10 @@ public: bool initializeJumpTableInfo(PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI); + bool parseMachineMetadataNodes(PerFunctionMIParsingState &PFS, + MachineFunction &MF, + const yaml::MachineFunction &YMF); + private: bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, const yaml::StringValue &Source); @@ -151,6 +155,9 @@ private: MachineBasicBlock *&MBB, const yaml::StringValue &Source); + bool parseMachineMetadata(PerFunctionMIParsingState &PFS, + const yaml::StringValue &Source); + /// Return a MIR diagnostic converted from an MI string diagnostic. SMDiagnostic diagFromMIStringDiag(const SMDiagnostic &Error, SMRange SourceRange); @@ -176,10 +183,11 @@ MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename, LLVMContext &Context, std::function<void(Function &)> Callback) : SM(), + Context(Context), In(SM.getMemoryBuffer(SM.AddNewSourceBuffer(std::move(Contents), SMLoc())) ->getBuffer(), nullptr, handleYAMLDiag, this), - Filename(Filename), Context(Context), ProcessIRFunction(Callback) { + Filename(Filename), ProcessIRFunction(Callback) { In.setContext(&In); } @@ -417,8 +425,8 @@ void MIRParserImpl::setupDebugValueTracking( // Load any substitutions. for (auto &Sub : YamlMF.DebugValueSubstitutions) { - MF.makeDebugValueSubstitution(std::make_pair(Sub.SrcInst, Sub.SrcOp), - std::make_pair(Sub.DstInst, Sub.DstOp)); + MF.makeDebugValueSubstitution({Sub.SrcInst, Sub.SrcOp}, + {Sub.DstInst, Sub.DstOp}, Sub.Subreg); } } @@ -456,6 +464,9 @@ MIRParserImpl::initializeMachineFunction(const yaml::MachineFunction &YamlMF, if (initializeConstantPool(PFS, *ConstantPool, YamlMF)) return true; } + if (!YamlMF.MachineMetadataNodes.empty() && + parseMachineMetadataNodes(PFS, MF, YamlMF)) + return true; StringRef BlockStr = YamlMF.Body.Value.Value; SMDiagnostic Error; @@ -646,10 +657,9 @@ bool MIRParserImpl::setupRegisterInfo(const PerFunctionMIParsingState &PFS, } }; - for (auto I = PFS.VRegInfosNamed.begin(), E = PFS.VRegInfosNamed.end(); - I != E; I++) { - const VRegInfo &Info = *I->second; - populateVRegInfo(Info, Twine(I->first())); + for (const auto &P : PFS.VRegInfosNamed) { + const VRegInfo &Info = *P.second; + populateVRegInfo(Info, Twine(P.first())); } for (auto P : PFS.VRegInfos) { @@ -700,6 +710,7 @@ bool MIRParserImpl::initializeFrameInfo(PerFunctionMIParsingState &PFS, MFI.setHasOpaqueSPAdjustment(YamlMFI.HasOpaqueSPAdjustment); MFI.setHasVAStart(YamlMFI.HasVAStart); MFI.setHasMustTailInVarArgFunc(YamlMFI.HasMustTailInVarArgFunc); + MFI.setHasTailCall(YamlMFI.HasTailCall); MFI.setLocalFrameSize(YamlMFI.LocalFrameSize); if (!YamlMFI.SavePoint.Value.empty()) { MachineBasicBlock *MBB = nullptr; @@ -919,6 +930,29 @@ bool MIRParserImpl::parseMBBReference(PerFunctionMIParsingState &PFS, return false; } +bool MIRParserImpl::parseMachineMetadata(PerFunctionMIParsingState &PFS, + const yaml::StringValue &Source) { + SMDiagnostic Error; + if (llvm::parseMachineMetadata(PFS, Source.Value, Source.SourceRange, Error)) + return error(Error, Source.SourceRange); + return false; +} + +bool MIRParserImpl::parseMachineMetadataNodes( + PerFunctionMIParsingState &PFS, MachineFunction &MF, + const yaml::MachineFunction &YMF) { + for (auto &MDS : YMF.MachineMetadataNodes) { + if (parseMachineMetadata(PFS, MDS)) + return true; + } + // Report missing definitions from forward referenced nodes. + if (!PFS.MachineForwardRefMDNodes.empty()) + return error(PFS.MachineForwardRefMDNodes.begin()->second.second, + "use of undefined metadata '!" + + Twine(PFS.MachineForwardRefMDNodes.begin()->first) + "'"); + return false; +} + SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error, SMRange SourceRange) { assert(SourceRange.isValid() && "Invalid source range"); @@ -983,7 +1017,7 @@ bool MIRParser::parseMachineFunctions(Module &M, MachineModuleInfo &MMI) { std::unique_ptr<MIRParser> llvm::createMIRParserFromFile( StringRef Filename, SMDiagnostic &Error, LLVMContext &Context, std::function<void(Function &)> ProcessIRFunction) { - auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename); + auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true); if (std::error_code EC = FileOrErr.getError()) { Error = SMDiagnostic(Filename, SourceMgr::DK_Error, "Could not open input file: " + EC.message()); |
