================
@@ -251,12 +259,92 @@ static void prettyPrintResources(raw_ostream &OS, const
DXILResourceMap &DRM,
OS << ";\n";
}
+namespace {
+class DXILAssemblyAnnotationWriter : public llvm::AssemblyAnnotationWriter {
+private:
+ ModuleSlotTracker &MST;
+ AbstractSlotTrackerStorage &STS;
+ const DXILDebugInfoMap &DI;
+
+public:
+ DXILAssemblyAnnotationWriter(ModuleSlotTracker &MST,
+ AbstractSlotTrackerStorage &STS,
+ const DXILDebugInfoMap &DI)
+ : MST(MST), STS(STS), DI(DI) {}
+
+ void emitMDNodeAnnot(const MDNode *N, formatted_raw_ostream &os) override {
+ if (const Metadata *NewMD = DI.MDReplace.lookup(N)) {
+ if (const auto *NewN = dyn_cast<MDNode>(NewMD))
+ if (STS.getMetadataSlot(NewN) == -1)
+ STS.createMetadataSlot(NewN);
+
+ os << "; DXIL: ";
+ N->printAsOperand(os, MST);
+ os << ": to be replaced by: ";
+ NewMD->printAsOperand(os, MST);
+ os << "\n";
+ return;
+ }
+
+ if (const Metadata *ExtraMD = DI.MDExtra.lookup(N)) {
+ if (const auto *ExtraN = dyn_cast<MDNode>(ExtraMD))
+ if (STS.getMetadataSlot(ExtraN) == -1)
+ STS.createMetadataSlot(ExtraN);
+
+ os << "; DXIL: ";
+ N->printAsOperand(os, MST);
+ os << ": additional data: ";
+ ExtraMD->printAsOperand(os, MST);
+ os << "\n";
+ return;
+ }
+ }
+};
+} // namespace
+
+static void prettyPrint(raw_ostream &OS, Module &M, const DXILResourceMap &DRM,
+ DXILResourceTypeMap &DRTM) {
+ formatted_raw_ostream FOS(OS);
+
+ prettyPrintResources(FOS, DRM, DRTM);
+
+ DXILDebugInfoMap DI = DXILDebugInfoPass::run(M);
+
+ ModuleSlotTracker MST(&M);
+ AbstractSlotTrackerStorage *STS = nullptr;
+ unsigned NextMetadataSlot = 0;
+ MST.setProcessHook(
+ [&](AbstractSlotTrackerStorage *STS_, const Module *, bool) {
+ STS = STS_;
+ NextMetadataSlot = STS->getNextMetadataSlot();
+ });
+ // Force initialisation. ModuleSlotTracker does not have a dedicated function
+ // for this so trigger it through a dummy print.
+ MDNode::get(M.getContext(), {})->print(llvm::nulls(), MST);
+ assert(STS && "Slot tracker storage should have been initialised");
+
+ DXILAssemblyAnnotationWriter DAAW(MST, *STS, DI);
+ M.print(FOS, &DAAW);
+
+ ModuleSlotTracker::MachineMDNodeListType MDNodes;
+ MST.collectMDNodes(MDNodes, NextMetadataSlot, ~0u);
+ std::sort(
+ MDNodes.begin(), MDNodes.end(),
+ [](std::pair<unsigned, const MDNode *> &A,
+ std::pair<unsigned, const MDNode *> &B) { return A.first < B.first;
});
----------------
hvdijk wrote:
I actually had `auto` initially but removed it based on your review comment on
the other PR that `auto` should be avoided where the types are not obvious, and
here in my opinion the type is not obvious. Definitely agreed on the `const`
though.
https://github.com/llvm/llvm-project/pull/198318
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits