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:
Ayke van Laethem
2021-11-07 15:33:44 +01:00
committed by Ron Evans
parent 78fec3719f
commit cf640290a3
6 changed files with 23 additions and 7 deletions
+1 -2
View File
@@ -3,7 +3,6 @@ package transform_test
import (
"testing"
"github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm"
)
@@ -11,7 +10,7 @@ import (
func TestInterfaceLowering(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/interface", func(mod llvm.Module) {
err := transform.LowerInterfaces(mod, &compileopts.Config{Options: &compileopts.Options{Opt: "2"}})
err := transform.LowerInterfaces(mod, defaultTestConfig)
if err != nil {
t.Error(err)
}