mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 15:33:40 +00:00
compiler: add "target-cpu" and "target-features" attributes
This matches Clang, and with that, it adds support for inlining between
Go and C because LLVM only allows inlining if the "target-cpu" and
"target-features" string attributes match.
For example, take a look at the following code:
// int add(int a, int b) {
// return a + b;
// }
import "C"
func main() {
println(C.add(3, 5))
}
The 'add' function is not inlined into the main function before this
commit, but after it, it can be inlined and trivially be optimized to
`println(8)`.
This commit is contained in:
committed by
Ron Evans
parent
78fec3719f
commit
cf640290a3
@@ -23,7 +23,7 @@ import (
|
||||
// Version of the compiler pacakge. Must be incremented each time the compiler
|
||||
// package changes in a way that affects the generated LLVM module.
|
||||
// This version is independent of the TinyGo version number.
|
||||
const Version = 24 // last change: add layout param to runtime.alloc calls
|
||||
const Version = 25 // last change: add "target-cpu" and "target-features" attributes
|
||||
|
||||
func init() {
|
||||
llvm.InitializeAllTargets()
|
||||
|
||||
@@ -346,6 +346,12 @@ func (c *compilerContext) addStandardDeclaredAttributes(llvmFn llvm.Value) {
|
||||
attr := c.ctx.CreateEnumAttribute(kind, 0)
|
||||
llvmFn.AddFunctionAttr(attr)
|
||||
}
|
||||
if c.CPU != "" {
|
||||
llvmFn.AddFunctionAttr(c.ctx.CreateStringAttribute("target-cpu", c.CPU))
|
||||
}
|
||||
if c.Features != "" {
|
||||
llvmFn.AddFunctionAttr(c.ctx.CreateStringAttribute("target-features", c.Features))
|
||||
}
|
||||
}
|
||||
|
||||
// addStandardDefinedAttributes adds the set of attributes that are added to
|
||||
|
||||
Reference in New Issue
Block a user