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

Quentin Colombet via llvm-dev llvm-dev at lists.llvm.org
Fri Oct 21 14:29:46 PDT 2016


Hi Alex,

Out of curiosity, what is your use case for that?

Generally speaking I would recommend against doing that. When the SDBuilder is done, I would expect the SDNodes to not query anything outside of the SD layer. We are not here now, though.

Cheers,
-Quentin
> On Oct 21, 2016, at 4:57 AM, Alex Susu via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
>  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
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



More information about the llvm-dev mailing list