compiler: move ApplyFunctionSections to transform package
Этот коммит содержится в:
родитель
945ff4d160
коммит
b6314fa6ab
6 изменённых файлов: 51 добавлений и 14 удалений
|
@ -53,7 +53,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(stri
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.GOOS() != "darwin" {
|
if config.GOOS() != "darwin" {
|
||||||
c.ApplyFunctionSections() // -ffunction-sections
|
transform.ApplyFunctionSections(c.Module()) // -ffunction-sections
|
||||||
}
|
}
|
||||||
|
|
||||||
// Browsers cannot handle external functions that have type i64 because it
|
// Browsers cannot handle external functions that have type i64 because it
|
||||||
|
|
|
@ -2585,19 +2585,6 @@ func (c *Compiler) Verify() error {
|
||||||
return llvm.VerifyModule(c.mod, llvm.PrintMessageAction)
|
return llvm.VerifyModule(c.mod, llvm.PrintMessageAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Compiler) ApplyFunctionSections() {
|
|
||||||
// Put every function in a separate section. This makes it possible for the
|
|
||||||
// linker to remove dead code (-ffunction-sections).
|
|
||||||
llvmFn := c.mod.FirstFunction()
|
|
||||||
for !llvmFn.IsNil() {
|
|
||||||
if !llvmFn.IsDeclaration() {
|
|
||||||
name := llvmFn.Name()
|
|
||||||
llvmFn.SetSection(".text." + name)
|
|
||||||
}
|
|
||||||
llvmFn = llvm.NextFunction(llvmFn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Turn all global constants into global variables. This works around a
|
// Turn all global constants into global variables. This works around a
|
||||||
// limitation on Harvard architectures (e.g. AVR), where constant and
|
// limitation on Harvard architectures (e.g. AVR), where constant and
|
||||||
// non-constant pointers point to a different address space.
|
// non-constant pointers point to a different address space.
|
||||||
|
|
20
transform/globals.go
Обычный файл
20
transform/globals.go
Обычный файл
|
@ -0,0 +1,20 @@
|
||||||
|
package transform
|
||||||
|
|
||||||
|
import "tinygo.org/x/go-llvm"
|
||||||
|
|
||||||
|
// This file implements small transformations on globals (functions and global
|
||||||
|
// variables) for specific ABIs/architectures.
|
||||||
|
|
||||||
|
// ApplyFunctionSections puts every function in a separate section. This makes
|
||||||
|
// it possible for the linker to remove dead code. It is the equivalent of
|
||||||
|
// passing -ffunction-sections to a C compiler.
|
||||||
|
func ApplyFunctionSections(mod llvm.Module) {
|
||||||
|
llvmFn := mod.FirstFunction()
|
||||||
|
for !llvmFn.IsNil() {
|
||||||
|
if !llvmFn.IsDeclaration() {
|
||||||
|
name := llvmFn.Name()
|
||||||
|
llvmFn.SetSection(".text." + name)
|
||||||
|
}
|
||||||
|
llvmFn = llvm.NextFunction(llvmFn)
|
||||||
|
}
|
||||||
|
}
|
14
transform/globals_test.go
Обычный файл
14
transform/globals_test.go
Обычный файл
|
@ -0,0 +1,14 @@
|
||||||
|
package transform
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"tinygo.org/x/go-llvm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestApplyFunctionSections(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
testTransform(t, "testdata/globals-function-sections", func(mod llvm.Module) {
|
||||||
|
ApplyFunctionSections(mod)
|
||||||
|
})
|
||||||
|
}
|
8
transform/testdata/globals-function-sections.ll
предоставленный
Обычный файл
8
transform/testdata/globals-function-sections.ll
предоставленный
Обычный файл
|
@ -0,0 +1,8 @@
|
||||||
|
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
|
||||||
|
target triple = "armv7em-none-eabi"
|
||||||
|
|
||||||
|
declare void @foo()
|
||||||
|
|
||||||
|
define void @bar() {
|
||||||
|
ret void
|
||||||
|
}
|
8
transform/testdata/globals-function-sections.out.ll
предоставленный
Обычный файл
8
transform/testdata/globals-function-sections.out.ll
предоставленный
Обычный файл
|
@ -0,0 +1,8 @@
|
||||||
|
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
|
||||||
|
target triple = "armv7em-none-eabi"
|
||||||
|
|
||||||
|
declare void @foo()
|
||||||
|
|
||||||
|
define void @bar() section ".text.bar" {
|
||||||
|
ret void
|
||||||
|
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче