================
@@ -1226,26 +1223,37 @@ 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) {
+ std::string Definitions;
for (const auto &MDS : YMF.MachineMetadataNodes) {
- if (parseMachineMetadata(PFS, MDS))
- return true;
+ Definitions.append(MDS.Value);
+ Definitions.push_back('\n');
}
- // 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) + "'");
+
+ SlotMapping Slots = PFS.IRSlots;
+ SMDiagnostic Error;
+ if (parseMetadataDefinitions(Definitions, Error,
+ *MF.getFunction().getParent(), Slots)) {
+ unsigned Line = std::max(Error.getLineNo(), 1);
+ unsigned Index =
+ std::min<unsigned>(Line - 1, YMF.MachineMetadataNodes.size() - 1);
+ const yaml::StringValue &Source = YMF.MachineMetadataNodes[Index];
+ if (Line > YMF.MachineMetadataNodes.size()) {
+ const char *Start = Source.SourceRange.Start.getPointer();
+ const char *End = Source.SourceRange.End.getPointer();
+ SMLoc Loc = Source.SourceRange.End;
+ if (Start < End && (*Start == '\'' || *Start == '"'))
+ Loc = SMLoc::getFromPointer(End - 1);
+ return error(Loc, Error.getMessage());
+ }
+ return error(Error, Source.SourceRange);
+ }
+
+ for (auto &[ID, MD] : Slots.MetadataNodes)
+ if (PFS.IRSlots.MetadataNodes.find(ID) == PFS.IRSlots.MetadataNodes.end())
+ PFS.MachineMetadataNodes.try_emplace(ID, MD);
----------------
yxsamliu wrote:
This code is now split into #219612, where the parser changes can be reviewed
separately. Resolving this thread here.
https://github.com/llvm/llvm-project/pull/216838
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits