diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h --- a/llvm/include/llvm/CodeGen/SelectionDAG.h +++ b/llvm/include/llvm/CodeGen/SelectionDAG.h @@ -267,6 +267,9 @@ /// Tracks dbg_value and dbg_label information through SDISel. SDDbgInfo *DbgInfo; + /// Save nodes with heapallocsite metadata. + DenseMap CodeViewHeapAllocSites; + uint16_t NextPersistentId = 0; public: @@ -1626,6 +1629,18 @@ isConstantFPBuildVectorOrConstantFP(N); } + void addHeapAllocSite(const SDNode* Node, MDNode* MD) { + CodeViewHeapAllocSites.insert({Node, MD}); + } + + /// Return the HeapAllocSite type associated with the SDNode, if it exists. + MDNode *getHeapAllocSite(const SDNode* Node) { + if (CodeViewHeapAllocSites.find(Node) == CodeViewHeapAllocSites.end()) + return nullptr; + return CodeViewHeapAllocSites[Node]; + } + + private: void InsertNode(SDNode *N); bool RemoveNodeFromCSEMaps(SDNode *N); diff --git a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp --- a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp @@ -903,6 +903,10 @@ // Remember the source order of the inserted instruction. if (HasDbg) ProcessSourceNode(N, DAG, Emitter, VRBaseMap, Orders, Seen, NewInsn); + + if (MDNode* MD = DAG->getHeapAllocSite(N)) + MF.addCodeViewHeapAllocSite(NewInsn, MD); + GluedNodes.pop_back(); } auto NewInsn = @@ -911,6 +915,8 @@ if (HasDbg) ProcessSourceNode(SU->getNode(), DAG, Emitter, VRBaseMap, Orders, Seen, NewInsn); + if (MDNode* MD = DAG->getHeapAllocSite(SU->getNode())) + MF.addCodeViewHeapAllocSite(NewInsn, MD); } // Insert all the dbg_values which have not already been inserted in source diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -4095,6 +4095,11 @@ } InFlag = Chain.getValue(1); + // Save heapallocsite metadata. + if (CLI.CS && CLI.CS->getMetadata("heapallocsite")) + CLI.DAG.addHeapAllocSite(Chain.getNode(), + CLI.CS->getMetadata("heapallocsite")); + // Create the CALLSEQ_END node. unsigned NumBytesForCalleeToPop; if (X86::isCalleePop(CallConv, Is64Bit, isVarArg, diff --git a/llvm/test/CodeGen/X86/label-heapallocsite.ll b/llvm/test/CodeGen/X86/label-heapallocsite.ll --- a/llvm/test/CodeGen/X86/label-heapallocsite.ll +++ b/llvm/test/CodeGen/X86/label-heapallocsite.ll @@ -1,5 +1,5 @@ +; RUN: llc < %s | FileCheck %s ; RUN: llc -O0 < %s | FileCheck %s -; FIXME: Add test for llc with optimizations once it is implemented. ; Source to regenerate: ; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \