compiler: move ApplyFunctionSections to transform package

This commit is contained in:
Ayke van Laethem
2020-03-18 20:32:46 +01:00
committed by Ron Evans
parent 945ff4d160
commit b6314fa6ab
6 changed files with 51 additions and 14 deletions
+20
View File
@@ -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)
}
}