transform

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2020 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package transform contains transformation passes for the TinyGo compiler. These transformation passes may be optimization passes or lowering passes.

Optimization passes transform the IR in such a way that they increase the performance of the generated code and/or help the LLVM optimizer better do its job by simplifying the IR. This usually means that certain TinyGo-specific runtime calls are removed or replaced with something simpler if that is a valid operation.

Lowering passes are usually required to run. One example is the interface lowering pass, which replaces stub runtime calls to get an interface method with the method implementation (either a direct call or a thunk).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddGlobalsBitmap added in v0.10.0

func AddGlobalsBitmap(mod llvm.Module) bool

AddGlobalsBitmap performs a few related functions. It is needed for scanning globals on platforms where the .data/.bss section is not easily accessible by the GC, and thus all globals that contain pointers must be made reachable by the GC in some other way.

First, it scans all globals, and bundles all globals that contain a pointer into one large global (updating all uses in the process). Then it creates a bitmap (bit vector) to locate all the pointers in this large global. This bitmap allows the GC to know in advance where exactly all the pointers live in the large globals bundle, to avoid false positives.

func ExternalInt64AsPtr added in v0.12.0

func ExternalInt64AsPtr(mod llvm.Module) error

ExternalInt64AsPtr converts i64 parameters in externally-visible functions to values passed by reference (*i64), to work around the lack of 64-bit integers in JavaScript (commonly used together with WebAssembly). Once that's resolved, this pass may be avoided. For more details: https://github.com/WebAssembly/design/issues/1172

This pass can be enabled/disabled with the -wasm-abi flag, and is enabled by default as of december 2019.

func LowerFuncValues added in v0.11.0

func LowerFuncValues(mod llvm.Module)

LowerFuncValues lowers the runtime.funcValueWithSignature type and runtime.getFuncPtr function to their final form.

func LowerInterfaces added in v0.10.0

func LowerInterfaces(mod llvm.Module)

LowerInterfaces lowers all intermediate interface calls and globals that are emitted by the compiler as higher-level intrinsics. They need some lowering before LLVM can work on them. This is done so that a few cleanup passes can run before assigning the final type codes.

func LowerInterrupts added in v0.12.0

func LowerInterrupts(mod llvm.Module) []error

LowerInterrupts creates interrupt handlers for the interrupts created by runtime/interrupt.New.

The operation is as follows. The compiler creates the following during IR generation:

  • calls to runtime/interrupt.Register that map interrupt IDs to ISR names.
  • runtime/interrupt.handle objects that store the (constant) interrupt ID and interrupt handler func value.

This pass then creates the specially named interrupt handler names that simply call the registered handlers. This might seem like it causes extra overhead, but in fact inlining and const propagation will eliminate most if not all of that.

func MakeGCStackSlots added in v0.10.0

func MakeGCStackSlots(mod llvm.Module) bool

MakeGCStackSlots converts all calls to runtime.trackPointer to explicit stores to stack slots that are scannable by the GC.

func OptimizeAllocs

func OptimizeAllocs(mod llvm.Module)

OptimizeAllocs tries to replace heap allocations with stack allocations whenever possible. It relies on the LLVM 'nocapture' flag for interprocedural escape analysis, and within a function looks whether an allocation can escape to the heap.

func OptimizeMaps

func OptimizeMaps(mod llvm.Module)

OptimizeMaps eliminates created but unused maps.

In the future, this should statically allocate created but never modified maps. This has not yet been implemented, however.

func OptimizeStringToBytes added in v0.9.0

func OptimizeStringToBytes(mod llvm.Module)

OptimizeStringToBytes transforms runtime.stringToBytes(...) calls into const []byte slices whenever possible. This optimizes the following pattern:

w.Write([]byte("foo"))

where Write does not store to the slice.

func ReplacePanicsWithTrap added in v0.10.0

func ReplacePanicsWithTrap(mod llvm.Module)

ReplacePanicsWithTrap replaces each call to panic (or similar functions) with calls to llvm.trap, to reduce code size. This is the -panic=trap command-line option.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL