[llvm-dev] Understanding TargetLowering::LowerCall

137 views
Skip to first unread message

Zhang via llvm-dev

unread,
Mar 22, 2021, 3:36:56 AM3/22/21
to llvm-dev
For CallSites that contains a GlobalValue as one of the arguments, where exactly does the lowering from GlobalAddress to iPTR took place?.

I'm assuming it should be handled in TargetLowering::LowerCall where target-dependent DAG Nodes got created depending on CCValAssign::isRegLoc() but from my testing it seems like isRegLoc() is true even for GlobalAddress arguments.

What am I misunderstanding here?


Zhang



Tim Northover via llvm-dev

unread,
Mar 22, 2021, 5:57:35 AM3/22/21
to Zhang, llvm-dev
On Mon, 22 Mar 2021 at 07:36, Zhang via llvm-dev
<llvm...@lists.llvm.org> wrote:
> For CallSites that contains a GlobalValue as one of the arguments, where exactly does the lowering from GlobalAddress to iPTR took place?.

It's generally no different for a callsite than any other GlobalValue
user. The generic SelectionDAGBuilder code will create a GlobalAddress
SDNode with iPTR type because the type of a GlobalValue is actually a
pointer to the type of the underlying object.

The call lowering code will get this iPTR node, and may well decide to
pass it to the callee in a register.

As for the GlobalAddress node, that goes through normal lowering to a
target-specific instruction sequence to materialize the address of the
global object. Often this is via custom C++ in LegalizeDAG (i.e.
`setOperationAction(ISD::GlobalValue, MVT::i64, Custom)`).

Cheers.

Tim.
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

jeniffer lesley via llvm-dev

unread,
Mar 22, 2021, 7:48:27 AM3/22/21
to Tim Northover, llvm-dev
Hi Tim, 
I had similar problem a couple of weeks ago but I somehow circumvented it. However, I dont understand much from the description. Can you please provide some example of backend which does this? probably what functions in X86 backend handle this lowering? If I look at the code I will be able to understand more clearly.

Tim Northover via llvm-dev

unread,
Mar 22, 2021, 9:34:12 AM3/22/21
to jeniffer lesley, llvm-dev
On Mon, 22 Mar 2021 at 11:48, jeniffer lesley <jeniffe...@gmail.com> wrote:
> I had similar problem a couple of weeks ago but I somehow circumvented it. However, I dont understand much from the description. Can you please provide some example of backend which does this? probably what functions in X86 backend handle this lowering? If I look at the code I will be able to understand more clearly.

On X86 it's X86TargetLowering::LowerGlobalOrExternal.

Zhang via llvm-dev

unread,
Mar 22, 2021, 11:58:09 PM3/22/21
to Tim Northover, llvm-dev
Thanks Tim.
One more thing I'm still not quite clear is how to differ GlobalAddress from registers when selection instructions.
Say the Initial DAG is :
```
load<(dereferenceable load 4 from @gv)> t0, TargetGlobalAddress:i64<i32* @gv> 0, undef:i64
```

And in our ISA we have:
```
LOAD_RM reg1,reg2 which basically means reg1 = *reg2
```

However when I use [(set (i32 GP32:$dst),(load GP64:$reg))] as the pattern for this ISA. the aforementioned DAGNode got matched as well.
How do I prevent such nodes from being matched since in our ISA GlobalAddress requires custom lowering
 
 
------------------ Original ------------------
From:  "Tim Northover"<t.p.no...@gmail.com>;
Date:  Mon, Mar 22, 2021 05:57 PM
To:  "Zhang"<ad...@mayuyu.io>;
Cc:  "llvm-dev"<llvm...@lists.llvm.org>;
Subject:  Re: [llvm-dev] Understanding TargetLowering::LowerCall

Tim Northover via llvm-dev

unread,
Mar 23, 2021, 3:25:49 PM3/23/21
to Zhang, llvm-dev
On Tue, 23 Mar 2021 at 03:58, Zhang <ad...@mayuyu.io> wrote:
> Say the Initial DAG is :
> ```
> load<(dereferenceable load 4 from @gv)> t0, TargetGlobalAddress:i64<i32* @gv> 0, undef:i64
> ```

The initial DAG shouldn't have a *Target*GlobalAddress. That's an
already-selected machine node and so it won't be further processed by
instruction selection. So you probably need to find whatever code you
have that's turning the original GlobalAddress into a
TargetGlobalAddress and modify that to actually insert the correct
instructions too.

Cheers.

Tim

Reply all
Reply to author
Forward
0 new messages