Reason to use different address space in gollvm

172 views
Skip to first unread message

Kavindu Gimhan Zoysa

unread,
Jun 28, 2021, 5:39:58 AM6/28/21
to golang-nuts
Hi all,

Can you please explain the reason to use different address space when GC is enabled as shown in the below line?


Thank you,
Kavindu

Than McIntosh

unread,
Jun 29, 2021, 8:52:14 AM6/29/21
to Kavindu Gimhan Zoysa, golang-nuts

Thanks, Than


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d95934ca-4488-4071-8c07-bb33122be387n%40googlegroups.com.

Kavindu Gimhan Zoysa

unread,
Jul 5, 2021, 3:08:13 AM7/5/21
to golang-nuts
Hi,

Regarding address spaces, I saw that there is a pass to remove address space casts. But if I generate IR using `llvm-goc -dump-ir -enable-gc=1 test.go` for the following go file, I still can see the addrspacecast instruction. What is the reason to see that addrspacecast? I feel that pass is not running. Can you help me to understand this problem?


package main

func main() {
   _ = stackIt2()
}
//go:noinline
func stackIt2() *int {
   y := 2
   res := y * 2
   return &res
}

Thank you,
Kavindu

Than McIntosh

unread,
Jul 7, 2021, 11:01:12 AM7/7/21
to Kavindu Gimhan Zoysa, golang-nuts
Hi again,

Sorry for the delay, I have been offline for a while.


You wrote:
>Regarding address spaces, I saw that there is a pass to remove address space casts. But if I generate IR using `llvm-goc -dump-ir -enable-gc=1 test.go` for the following go file, I still can see the addrspacecast instruction. What is the reason to see that addrspacecast? I feel that pass is not running. Can you help me to understand this problem?

A couple of things on this.

First, the "-dump-ir" option to llvm-goc shows the LLVM IR after the front end and bridge are done with creating it -- at this point no LLVM passes will have been run, so you would not expect to see any address space casts removed.  Probably what you want here is "-emit-llvm", which will show LLVM IR after all the various module and function passes have run (before the switch to machine-dependent IR). Example:

 $ llvm-goc -S -emit-llvm -enable-gc=1 test.go
 $ cat test.ll
 ...
 $

A second thing is that the cast-removal pass you mention isn't removing every cast, only casts on initialized global variables fed with constants. If you look at this source code

https://go.googlesource.com/gollvm/+/38bada572789a19cf881201c923e6b56ed32ae53/passes/RemoveAddrSpace.cpp#95

you can see that it's visiting only initialized globals. If you want to examples of cast removal, try running your compile on a larger and more interesting test case, like

  https://golang.org/test/method5.go

In general if you are unsure about whether a pass is running and/or what the effects of the pass are, there are developer options you can try (note: available only in a pure debug build) that can show you more. Example:

 # Dump LLVM IR before a pass
 $ ./bin/llvm-goc -O2 -c -emit-llvm -S -enable-gc=1 -mllvm -print-before=remove-addrspacecast test.go 1> before.dump.txt 2>&1

 # Dump LLVM IR after a pass
 $ ./bin/llvm-goc -O2 -c -emit-llvm -S -enable-gc=1 -mllvm -print-after=remove-addrspacecast test.go 1> after.dump.txt 2>&1

Hope this helps.

Thanks, Than

Kavindu Gimhan Zoysa

unread,
Jul 9, 2021, 2:46:58 AM7/9/21
to golang-nuts
Hi Than,

Thank you a lot for sharing this valuable information. It helps me a lot to understand this.

Thank you,
Kavindu

Reply all
Reply to author
Forward
0 new messages