Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding llvm SelectionDAG

Tags:

llvm-ir

For a simple llvm IR as:

define i32 @test(i32 %X, i32 %Y) {
    %Z = udiv i32 %X, %Y
    ret i32 %Z
  }

the SelectionDAG graph is more complex than I thought:

image of SelectionDAG graph

Why is CopyFromReg needed, why not connect vreg0 and vreg1 to udiv directly?

How should I read the graph, from EntryToken to GraphRoot or the opposite direction?

like image 551
user3382012 Avatar asked Mar 05 '14 05:03

user3382012


1 Answers

Function arguments are calling convention specific and they are lowered in the construction process of SelectionDAG (SelectionDAGISel::SelectAllBasicBlocks calls SelectionDAGISel::LowerArguments), the architecture specific LowerArguments usually creates CopyFromReg to represent the arguments in virtual register as SDValue and chain the CopyFromReg to SelectionDAG.

The extra CopyFromReg is attached to maintain the Chain to EntryToken, and store other information which is designed not to be part of RegisterSDNode, like DebugLoc.

Here is an example that CopyFromReg is not attached (blue dotted arrows are missing):

enter image description here

like image 182
Thomson Avatar answered Sep 18 '22 09:09

Thomson