[llvm] 33b69b9 - [YamlMF] Serialize EntryValueObjects
Felipe de Azevedo Piovezan via llvm-commits
llvm-commits at lists.llvm.org
Thu May 11 07:20:29 PDT 2023
Author: Felipe de Azevedo Piovezan
Date: 2023-05-11T10:20:05-04:00
New Revision: 33b69b97565cf19f8e11173fd851e56ce07656f0
URL: https://github.com/llvm/llvm-project/commit/33b69b97565cf19f8e11173fd851e56ce07656f0
DIFF: https://github.com/llvm/llvm-project/commit/33b69b97565cf19f8e11173fd851e56ce07656f0.diff
LOG: [YamlMF] Serialize EntryValueObjects
This commit implements the serialization and deserialization of the Machine
Function's EntryValueObjects.
Depends on D149879, D149778
Differential Revision: https://reviews.llvm.org/D149880
Added:
llvm/test/CodeGen/MIR/AArch64/entry_values.mir
Modified:
llvm/include/llvm/CodeGen/MIRYamlMapping.h
llvm/include/llvm/CodeGen/MachineFunction.h
llvm/lib/CodeGen/MIRParser/MIRParser.cpp
llvm/lib/CodeGen/MIRPrinter.cpp
llvm/test/CodeGen/PowerPC/unreachable-mbb-jtreference-elimination.ll
llvm/test/DebugInfo/X86/empty-metadata-dbg-declare.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MIRYamlMapping.h b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
index 80557e0feb77f..16e773c186418 100644
--- a/llvm/include/llvm/CodeGen/MIRYamlMapping.h
+++ b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
@@ -304,6 +304,30 @@ template <> struct MappingTraits<MachineStackObject> {
static const bool flow = true;
};
+/// Serializable representation of the MCRegister variant of
+/// MachineFunction::VariableDbgInfo.
+struct EntryValueObject {
+ StringValue EntryValueRegister;
+ StringValue DebugVar;
+ StringValue DebugExpr;
+ StringValue DebugLoc;
+ bool operator==(const EntryValueObject &Other) const {
+ return EntryValueRegister == Other.EntryValueRegister &&
+ DebugVar == Other.DebugVar && DebugExpr == Other.DebugExpr &&
+ DebugLoc == Other.DebugLoc;
+ }
+};
+
+template <> struct MappingTraits<EntryValueObject> {
+ static void mapping(yaml::IO &YamlIO, EntryValueObject &Object) {
+ YamlIO.mapRequired("entry-value-register", Object.EntryValueRegister);
+ YamlIO.mapRequired("debug-info-variable", Object.DebugVar);
+ YamlIO.mapRequired("debug-info-expression", Object.DebugExpr);
+ YamlIO.mapRequired("debug-info-location", Object.DebugLoc);
+ }
+ static const bool flow = true;
+};
+
/// Serializable representation of the fixed stack object from the
/// MachineFrameInfo class.
struct FixedMachineStackObject {
@@ -572,6 +596,7 @@ template <> struct MappingTraits<MachineJumpTable::Entry> {
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineFunctionLiveIn)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::VirtualRegisterDefinition)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineStackObject)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::EntryValueObject)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::FixedMachineStackObject)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::CallSiteInfo)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineConstantPoolValue)
@@ -716,6 +741,7 @@ struct MachineFunction {
// Frame information
MachineFrameInfo FrameInfo;
std::vector<FixedMachineStackObject> FixedStackObjects;
+ std::vector<EntryValueObject> EntryValueObjects;
std::vector<MachineStackObject> StackObjects;
std::vector<MachineConstantPoolValue> Constants; /// Constant pool.
std::unique_ptr<MachineFunctionInfo> MachineFuncInfo;
@@ -760,6 +786,8 @@ template <> struct MappingTraits<MachineFunction> {
std::vector<FixedMachineStackObject>());
YamlIO.mapOptional("stack", MF.StackObjects,
std::vector<MachineStackObject>());
+ YamlIO.mapOptional("entry_values", MF.EntryValueObjects,
+ std::vector<EntryValueObject>());
YamlIO.mapOptional("callSites", MF.CallSitesInfo,
std::vector<CallSiteInfo>());
YamlIO.mapOptional("debugValueSubstitutions", MF.DebugValueSubstitutions,
diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index 619f7ccf59331..09f9ff60f9550 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -1297,6 +1297,14 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
});
}
+ /// Returns the collection of variables for which we have debug info and that
+ /// have been assigned an entry value register.
+ auto getEntryValueVariableDbgInfo() const {
+ return make_filter_range(getVariableDbgInfo(), [](const auto &VarInfo) {
+ return VarInfo.inEntryValueRegister();
+ });
+ }
+
/// Start tracking the arguments passed to the call \p CallI.
void addCallArgsForwardingRegs(const MachineInstr *CallI,
CallSiteInfoImpl &&CallInfo) {
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index 5488824306261..a271ebf18ac64 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -803,6 +803,24 @@ bool MIRParserImpl::initializeFrameInfo(PerFunctionMIParsingState &PFS,
return true;
}
+ for (const auto &Object : YamlMF.EntryValueObjects) {
+ SMDiagnostic Error;
+ Register Reg;
+ if (parseNamedRegisterReference(PFS, Reg, Object.EntryValueRegister.Value,
+ Error))
+ return error(Error, Object.EntryValueRegister.SourceRange);
+ if (!Reg.isPhysical())
+ return error(Object.EntryValueRegister.SourceRange.Start,
+ "Expected physical register for entry value field");
+ std::optional<VarExprLoc> MaybeInfo = parseVarExprLoc(
+ PFS, Object.DebugVar, Object.DebugExpr, Object.DebugLoc);
+ if (!MaybeInfo)
+ return true;
+ if (MaybeInfo->DIVar || MaybeInfo->DIExpr || MaybeInfo->DILoc)
+ PFS.MF.setVariableDbgInfo(MaybeInfo->DIVar, MaybeInfo->DIExpr,
+ Reg.asMCReg(), MaybeInfo->DILoc);
+ }
+
// Initialize the ordinary frame objects.
for (const auto &Object : YamlMF.StackObjects) {
int ObjectIdx;
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index 8326d83f00573..8b68b1e0273a4 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -119,6 +119,9 @@ class MIRPrinter {
const MachineJumpTableInfo &JTI);
void convertStackObjects(yaml::MachineFunction &YMF,
const MachineFunction &MF, ModuleSlotTracker &MST);
+ void convertEntryValueObjects(yaml::MachineFunction &YMF,
+ const MachineFunction &MF,
+ ModuleSlotTracker &MST);
void convertCallSiteObjects(yaml::MachineFunction &YMF,
const MachineFunction &MF,
ModuleSlotTracker &MST);
@@ -221,6 +224,7 @@ void MIRPrinter::print(const MachineFunction &MF) {
MST.incorporateFunction(MF.getFunction());
convert(MST, YamlMF.FrameInfo, MF.getFrameInfo());
convertStackObjects(YamlMF, MF, MST);
+ convertEntryValueObjects(YamlMF, MF, MST);
convertCallSiteObjects(YamlMF, MF, MST);
for (const auto &Sub : MF.DebugValueSubstitutions) {
const auto &SubSrc = Sub.Src;
@@ -373,6 +377,19 @@ void MIRPrinter::convert(ModuleSlotTracker &MST,
}
}
+void MIRPrinter::convertEntryValueObjects(yaml::MachineFunction &YMF,
+ const MachineFunction &MF,
+ ModuleSlotTracker &MST) {
+ const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
+ for (const MachineFunction::VariableDbgInfo &DebugVar :
+ MF.getEntryValueVariableDbgInfo()) {
+ yaml::EntryValueObject &Obj = YMF.EntryValueObjects.emplace_back();
+ printStackObjectDbgInfo(DebugVar, Obj, MST);
+ MCRegister EntryValReg = DebugVar.getEntryValueRegister();
+ printRegMIR(EntryValReg, Obj.EntryValueRegister, TRI);
+ }
+}
+
void MIRPrinter::convertStackObjects(yaml::MachineFunction &YMF,
const MachineFunction &MF,
ModuleSlotTracker &MST) {
diff --git a/llvm/test/CodeGen/MIR/AArch64/entry_values.mir b/llvm/test/CodeGen/MIR/AArch64/entry_values.mir
new file mode 100644
index 0000000000000..10571c4db0d75
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/AArch64/entry_values.mir
@@ -0,0 +1,39 @@
+# RUN: llc -mtriple=aarch64 -run-pass none -o - %s | FileCheck %s
+
+# This test ensures that the MIR parser parses machine entry_value properties
+# correctly.
+
+--- |
+
+ define void @foo(ptr swiftasync %arg) !dbg !4 {
+ call void @llvm.dbg.declare(metadata ptr %arg, metadata !9, metadata !DIExpression(DW_OP_LLVM_entry_value, 1)), !dbg !10
+ ret void
+ }
+
+ declare void @llvm.dbg.declare(metadata, metadata, metadata)
+ !llvm.module.flags = !{!0, !1}
+ !llvm.dbg.cu = !{!2}
+ !0 = !{i32 7, !"Dwarf Version", i32 4}
+ !1 = !{i32 2, !"Debug Info Version", i32 3}
+ !2 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !3, runtimeVersion: 0, emissionKind: FullDebug)
+ !3 = !DIFile(filename: "blah", directory: "")
+ !4 = distinct !DISubprogram(linkageName: "foo", scope: null, file: !3, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !6)
+ !5 = !DISubroutineType(types: null)
+ !6 = !{!7, !9}
+ !7 = !DILocalVariable(name: "k1", scope: !4, file: !3, line: 7, type: !8)
+ !8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Klass")
+ !9 = !DILocalVariable(name: "k2", scope: !4, file: !3, line: 7, type: !8)
+ !10 = !DILocation(line: 6, scope: !4)
+
+...
+---
+name: foo
+entry_values:
+ - { entry-value-register: '$x22', debug-info-variable: '!9', debug-info-expression: '!DIExpression(DW_OP_LLVM_entry_value, 1)',
+ debug-info-location: '!10' }
+# CHECK: entry_values:
+# CHECK: - { entry-value-register: '$x22', debug-info-variable: '![[#]]', debug-info-expression: '!DIExpression(DW_OP_LLVM_entry_value, 1)',
+# CHECK: debug-info-location: '![[#]]' }
+body: |
+ bb.1:
+...
diff --git a/llvm/test/CodeGen/PowerPC/unreachable-mbb-jtreference-elimination.ll b/llvm/test/CodeGen/PowerPC/unreachable-mbb-jtreference-elimination.ll
index 3ed05594ae12e..65f0b053ab021 100644
--- a/llvm/test/CodeGen/PowerPC/unreachable-mbb-jtreference-elimination.ll
+++ b/llvm/test/CodeGen/PowerPC/unreachable-mbb-jtreference-elimination.ll
@@ -4,6 +4,7 @@
define dso_local void @foo() #0 {
; CHECK-LABEL: fixedStack:
; CHECK-NEXT: stack: []
+; CHECK-NEXT: entry_values: []
; CHECK-NEXT: callSites: []
; CHECK-NEXT: debugValueSubstitutions: []
; CHECK-NEXT: constants: []
diff --git a/llvm/test/DebugInfo/X86/empty-metadata-dbg-declare.ll b/llvm/test/DebugInfo/X86/empty-metadata-dbg-declare.ll
index f3c14fa15f986..8ae4e7b183e9a 100644
--- a/llvm/test/DebugInfo/X86/empty-metadata-dbg-declare.ll
+++ b/llvm/test/DebugInfo/X86/empty-metadata-dbg-declare.ll
@@ -10,7 +10,7 @@
; CHECK-NEXT: stack-id: default, callee-saved-register: '', callee-saved-restored: true,
; CHECK-NEXT: debug-info-variable: '![[f]]', debug-info-expression: '!DIExpression()',
; CHECK-NEXT: debug-info-location: '{{.+}}' }
-; CHECK-NEXT: callSites:
+; CHECK-NEXT: entry_values:
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list