[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
Mon Oct 24 03:11:27 PDT 2016


   Hello.
     Quentin, retrieving the LLVM IR instruction from which an SDNode originates is useful 
during the instruction selection phase. For example, I need to recover the LLVM IR 
variable which is used to fill an entire vector with the ISD::BUILD_VECTOR 
target-independent SDNode  .
     From the recovered LLVM IR variable I can walk on the use-def-chains in order to get 
the most complete definition of this variable (in terms of the input program variables), 
which is something I can't do at the level of SelectionDAGs (because, for example, actual 
function arguments don't appear in the DAG).

   Best regards,
     Alex


On 10/22/2016 12:29 AM, Quentin Colombet wrote:
> 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