[llvm-dev] Accessing the associated LLVM IR Instruction for an SDNode used in instruction selection (back end)

Alex Susu via llvm-dev llvm-dev at lists.llvm.org
Fri Oct 21 04:57:58 PDT 2016


   Hello.
     I would like to access the LLVM IR Instruction from which an SDNode (from 
SelectionDAG) originates. For this I have modified:
       - llvm/lib/CodeGen/SelectionDAGISel.cpp, SelectionDAGISel::SelectBasicBlock(), 
namely I put SDB->clear() at the beginning of the method in order to avoid clearing 
NodeMap after creating the initial SelectionDAG from LLVM IR, since I want to access it 
after that;
       - llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h - added an accessor for the 
private NodeMap object relating LLVM IR Instructions to generated SDNodes:
         public:
           // Alex: added a getter for NodeMap
           DenseMap<const Value*, SDValue> &getNodeMap() {
               return NodeMap;
           }

     A small problem is that it seems that when I access the NodeMap in 
[Target]DAGToDAGISel::Select(SDNode *Node) method (part of subclass of SelectionDAGISel), 
the NodeMap contains quite a few SDNodes tagged as <<Deleted Node!>> (for the nodes that 
were already selected).
     But the current SDNode, given as parameter to Select() is valid and we can search for 
it in NodeMap in order to find the LLVM IR Instruction (llvm::Value, more exactly) that 
generated it.
     As a side question, is there a better modality to find the key associated to a value 
in a DenseMap object than to iterate through all of DenseMap's elements (I could not find 
anything better at http://llvm.org/docs/doxygen/html/classllvm_1_1DenseMapBase.html)?

     Could you please tell me if there is a better modality to retrieve the LLVM IR 
Instruction from which an SDNode originates?

   Thank you,
     Alex


More information about the llvm-dev mailing list