Questions about code and compilation.

85 views
Skip to first unread message

wyn...@cs.unc.edu

unread,
Mar 23, 2016, 6:06:21 PM3/23/16
to llgo-dev
Firstly, I've installed Ccache, but it still takes quite a while to compile llgo when I make changes to it. Is there a way to speed up compilation. I've used make -j install.

Secondly, I'm trying to detect a particular function type in order to compile to IR with a different kind of function call that doesn't save anything to the stack. Do you have any advice to narrow down what the type of the function is? not just the return type/parameters. Also how do I change the CCallConv of the function in irgen/call.go?

Thank you for all your help!
Willem

Andrew Wilkins

unread,
Mar 23, 2016, 7:09:23 PM3/23/16
to llgo...@googlegroups.com
On Thu, 24 Mar 2016 at 06:06 <wyn...@cs.unc.edu> wrote:
Firstly,  I've installed Ccache, but it still takes quite a while to compile llgo when I make changes to it.  Is there a way to speed up compilation.  I've  used make -j install.

If you're making changes to LLVM or Clang as well, you could try using Ninja. For llgo, I think most of the slow-down is in having to re-run configure/make for the vendored projects - not sure what you can do without radically changing the build.

Secondly, I'm trying to detect a particular function type in order to compile to IR with a different kind of function call that doesn't save anything to the stack.  Do you have any advice to narrow down what the type of the function is? not just the return type/parameters.  Also how do I change the CCallConv of the function in irgen/call.go?

You can get at the go/types.Signature (https://golang.org/pkg/go/types/#Signature) for functions when translating to LLVM IR. I expect that would have what you need. If not, can you be a little bit more specific about what you want to filter on? 

It's been a while, but I think you want to use "llvm.Value.SetSetInstructionCallConv" to set the calling convention at the call site. Bear in mind that you also need to consider the C ABI requirements, which is what the "typinfo.call" and "typinfo.invoke" calls in irgen/call.go are all about.

Thank you for all your help!
Willem

--
You received this message because you are subscribed to the Google Groups "llgo-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to llgo-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Willem Neal Wyndham

unread,
Mar 23, 2016, 7:17:45 PM3/23/16
to llgo-dev
Thanks for the reply.  I looked at using *types.Named because the function I wanted to filter is a named type. From there I'm just comparing the string of the name.  Not the best, but it'll do.

As for changing the function call to IR,  I'm not sure which value to use that function with nor how to make sure I meet the C ABI requirements.  Could you explain that a little more?

Thanks again for all of your help!
Willem

Andrew Wilkins

unread,
Mar 23, 2016, 7:54:51 PM3/23/16
to llgo...@googlegroups.com
On Thu, 24 Mar 2016 at 07:17 Willem Neal Wyndham <wyn...@cs.unc.edu> wrote:
Thanks for the reply.  I looked at using *types.Named because the function I wanted to filter is a named type. From there I'm just comparing the string of the name.  Not the best, but it'll do.

You can use Named.Underlying() to get the underlying Signature in that case. All types have an Underlying method, so you don't need to check for Named specifically. For a type without an underlying type, Underlying will be the identity function.

As for changing the function call to IR,  I'm not sure which value to use that function with nor how to make sure I meet the C ABI requirements.  Could you explain that a little more?

IIRC, you'll want to set the calling convention on the result of Create{Call,Invoke}. For most function calls, these are in cabi.go (functionTypeInfo.{call,invoke}).

As for C ABI: you'll already be breaking compatibility by changing the calling convention. The code in cabi.go will set up the IR-level function types and function calls such that they conform to the platform's C ABI, which may affect what you're trying to achieve. For example, if a struct is returned from a function, that ends up going into an "sret" parameter, not a result, and stack space will be allocated for it in the caller.

That may be a bit vague still. If you can provide more information on what you're trying to achieve, I might be able to provide more specific advice.

Cheers,
Andrew

wille...@gmail.com

unread,
Mar 24, 2016, 12:23:00 AM3/24/16
to llgo-dev
Currently I have a monadic loop such that a function each iteration is set equal to the same function but given the state as an input.

i.e. f = f(s)

so since the only parameter that is passed to each function is s we don't need to make real function calls that save state, but rather I would like the functions to be sown together.

If I understand your explanation correctly, I don't think what I want will break it. Since f is a function which "returns" the next function it will be jumps between void functions.

I've had one compilers course but it was in java for a very simple virtual machine. I'm excited to learn more about llvm.

I would like also to learn more about making functional languages and my application is similar to tail end recursion detection. I was reading about the different function calls in IR and some were meant for it, but were missing in the enum in llvm go bindngs. Is there no way for me to add that to llvm go?

I have more questions, but please let me know if you need more explanation.

Thank you again for your amazing help!
Willem

Andrew Wilkins

unread,
Mar 24, 2016, 1:57:23 AM3/24/16
to llgo...@googlegroups.com
On Thu, 24 Mar 2016 at 12:23 <wille...@gmail.com> wrote:
Currently I have a monadic loop such that a function each iteration is set equal to the same function but given the state as an input.

i.e.  f = f(s)

so since the only parameter that is passed to each function is s we don't need to make real function calls that save state, but rather I would like the functions to be sown together.

If I understand your explanation correctly, I don't think what I want will break it.  Since f is a function which "returns" the next function it will be jumps between void functions.

I've had one compilers course but it was in java for a very simple virtual machine.  I'm excited to learn more about llvm.

One more than me :)
 
I would like also to learn more about making functional languages and my application is similar to tail end recursion detection. I was reading about the different function calls in IR and some were meant for it, but were missing in the enum in llvm go bindngs.  Is there no way for me to add that to llvm go?

OK, so you can mark a call as "tail" using https://godoc.org/llvm.org/llvm/bindings/go/llvm#Value.SetTailCall. You would call this on the result of Create{Call,Invoke}.

However, tail-calls are explicitly disabled: http://llvm.org/klaus/llgo/blob/master/irgen/compiler.go#L-157. IIRC, this is to stop confusing the panic/recover logic. Something to be aware of - I don't recall the details, so can't say more on that.
Reply all
Reply to author
Forward
0 new messages