compiler: remove leftover code after refactor
A few functions were duplicated during the refactor. They can now be deleted.
Этот коммит содержится в:
родитель
315b028317
коммит
8ef921e028
4 изменённых файлов: 0 добавлений и 118 удалений
|
@ -1,8 +1,6 @@
|
||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"golang.org/x/tools/go/ssa"
|
|
||||||
"tinygo.org/x/go-llvm"
|
"tinygo.org/x/go-llvm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,24 +11,6 @@ import (
|
||||||
// a struct contains more fields, it is passed as a struct without expanding.
|
// a struct contains more fields, it is passed as a struct without expanding.
|
||||||
const MaxFieldsPerParam = 3
|
const MaxFieldsPerParam = 3
|
||||||
|
|
||||||
// Shortcut: create a call to runtime.<fnName> with the given arguments.
|
|
||||||
func (c *Compiler) createRuntimeCall(fnName string, args []llvm.Value, name string) llvm.Value {
|
|
||||||
runtimePkg := c.ir.Program.ImportedPackage("runtime")
|
|
||||||
member := runtimePkg.Members[fnName]
|
|
||||||
if member == nil {
|
|
||||||
panic("trying to call runtime." + fnName)
|
|
||||||
}
|
|
||||||
fn := c.ir.GetFunction(member.(*ssa.Function))
|
|
||||||
if fn.LLVMFn.IsNil() {
|
|
||||||
panic(fmt.Errorf("function %s does not appear in LLVM IR", fnName))
|
|
||||||
}
|
|
||||||
if !fn.IsExported() {
|
|
||||||
args = append(args, llvm.Undef(c.i8ptrType)) // unused context parameter
|
|
||||||
args = append(args, llvm.ConstPointerNull(c.i8ptrType)) // coroutine handle
|
|
||||||
}
|
|
||||||
return c.createCall(fn.LLVMFn, args, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// createCall creates a new call to runtime.<fnName> with the given arguments.
|
// createCall creates a new call to runtime.<fnName> with the given arguments.
|
||||||
func (b *builder) createRuntimeCall(fnName string, args []llvm.Value, name string) llvm.Value {
|
func (b *builder) createRuntimeCall(fnName string, args []llvm.Value, name string) llvm.Value {
|
||||||
fullName := "runtime." + fnName
|
fullName := "runtime." + fnName
|
||||||
|
@ -43,16 +23,6 @@ func (b *builder) createRuntimeCall(fnName string, args []llvm.Value, name strin
|
||||||
return b.createCall(fn, args, name)
|
return b.createCall(fn, args, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a call to the given function with the arguments possibly expanded.
|
|
||||||
func (c *Compiler) createCall(fn llvm.Value, args []llvm.Value, name string) llvm.Value {
|
|
||||||
expanded := make([]llvm.Value, 0, len(args))
|
|
||||||
for _, arg := range args {
|
|
||||||
fragments := c.expandFormalParam(arg)
|
|
||||||
expanded = append(expanded, fragments...)
|
|
||||||
}
|
|
||||||
return c.builder.CreateCall(fn, expanded, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// createCall creates a call to the given function with the arguments possibly
|
// createCall creates a call to the given function with the arguments possibly
|
||||||
// expanded.
|
// expanded.
|
||||||
func (b *builder) createCall(fn llvm.Value, args []llvm.Value, name string) llvm.Value {
|
func (b *builder) createCall(fn llvm.Value, args []llvm.Value, name string) llvm.Value {
|
||||||
|
@ -102,27 +72,6 @@ func (b *builder) expandFormalParamOffsets(t llvm.Type) []uint64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equivalent of expandFormalParamType for parameter values.
|
|
||||||
func (c *Compiler) expandFormalParam(v llvm.Value) []llvm.Value {
|
|
||||||
switch v.Type().TypeKind() {
|
|
||||||
case llvm.StructTypeKind:
|
|
||||||
fieldTypes := flattenAggregateType(v.Type())
|
|
||||||
if len(fieldTypes) <= MaxFieldsPerParam {
|
|
||||||
fields := c.flattenAggregate(v)
|
|
||||||
if len(fields) != len(fieldTypes) {
|
|
||||||
panic("type and value param lowering don't match")
|
|
||||||
}
|
|
||||||
return fields
|
|
||||||
} else {
|
|
||||||
// failed to lower
|
|
||||||
return []llvm.Value{v}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// TODO: split small arrays
|
|
||||||
return []llvm.Value{v}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// expandFormalParam splits a formal param value into pieces, so it can be
|
// expandFormalParam splits a formal param value into pieces, so it can be
|
||||||
// passed directly as part of a function call. For example, it splits up small
|
// passed directly as part of a function call. For example, it splits up small
|
||||||
// structs into individual fields. It is the equivalent of expandFormalParamType
|
// structs into individual fields. It is the equivalent of expandFormalParamType
|
||||||
|
@ -187,23 +136,6 @@ func (c *compilerContext) flattenAggregateTypeOffsets(t llvm.Type) []uint64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Break down a struct into its elementary types for argument passing. The value
|
|
||||||
// equivalent of flattenAggregateType
|
|
||||||
func (c *Compiler) flattenAggregate(v llvm.Value) []llvm.Value {
|
|
||||||
switch v.Type().TypeKind() {
|
|
||||||
case llvm.StructTypeKind:
|
|
||||||
fields := make([]llvm.Value, 0, v.Type().StructElementTypesCount())
|
|
||||||
for i := range v.Type().StructElementTypes() {
|
|
||||||
subfield := c.builder.CreateExtractValue(v, i, "")
|
|
||||||
subfields := c.flattenAggregate(subfield)
|
|
||||||
fields = append(fields, subfields...)
|
|
||||||
}
|
|
||||||
return fields
|
|
||||||
default:
|
|
||||||
return []llvm.Value{v}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// flattenAggregate breaks down a struct into its elementary values for argument
|
// flattenAggregate breaks down a struct into its elementary values for argument
|
||||||
// passing. It is the value equivalent of flattenAggregateType
|
// passing. It is the value equivalent of flattenAggregateType
|
||||||
func (b *builder) flattenAggregate(v llvm.Value) []llvm.Value {
|
func (b *builder) flattenAggregate(v llvm.Value) []llvm.Value {
|
||||||
|
|
|
@ -11,12 +11,6 @@ import (
|
||||||
"tinygo.org/x/go-llvm"
|
"tinygo.org/x/go-llvm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// createFuncValue creates a function value from a raw function pointer with no
|
|
||||||
// context.
|
|
||||||
func (c *Compiler) createFuncValue(funcPtr, context llvm.Value, sig *types.Signature) llvm.Value {
|
|
||||||
return c.compilerContext.createFuncValue(c.builder, funcPtr, context, sig)
|
|
||||||
}
|
|
||||||
|
|
||||||
// createFuncValue creates a function value from a raw function pointer with no
|
// createFuncValue creates a function value from a raw function pointer with no
|
||||||
// context.
|
// context.
|
||||||
func (b *builder) createFuncValue(funcPtr, context llvm.Value, sig *types.Signature) llvm.Value {
|
func (b *builder) createFuncValue(funcPtr, context llvm.Value, sig *types.Signature) llvm.Value {
|
||||||
|
@ -57,12 +51,6 @@ func (c *compilerContext) createFuncValue(builder llvm.Builder, funcPtr, context
|
||||||
return funcValue
|
return funcValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractFuncScalar returns some scalar that can be used in comparisons. It is
|
|
||||||
// a cheap operation.
|
|
||||||
func (c *Compiler) extractFuncScalar(funcValue llvm.Value) llvm.Value {
|
|
||||||
return c.builder.CreateExtractValue(funcValue, 1, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// extractFuncScalar returns some scalar that can be used in comparisons. It is
|
// extractFuncScalar returns some scalar that can be used in comparisons. It is
|
||||||
// a cheap operation.
|
// a cheap operation.
|
||||||
func (b *builder) extractFuncScalar(funcValue llvm.Value) llvm.Value {
|
func (b *builder) extractFuncScalar(funcValue llvm.Value) llvm.Value {
|
||||||
|
|
|
@ -72,15 +72,6 @@ func (b *builder) trackValue(value llvm.Value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// trackPointer creates a call to runtime.trackPointer, bitcasting the poitner
|
|
||||||
// first if needed. The input value must be of LLVM pointer type.
|
|
||||||
func (c *Compiler) trackPointer(value llvm.Value) {
|
|
||||||
if value.Type() != c.i8ptrType {
|
|
||||||
value = c.builder.CreateBitCast(value, c.i8ptrType, "")
|
|
||||||
}
|
|
||||||
c.createRuntimeCall("trackPointer", []llvm.Value{value}, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// trackPointer creates a call to runtime.trackPointer, bitcasting the poitner
|
// trackPointer creates a call to runtime.trackPointer, bitcasting the poitner
|
||||||
// first if needed. The input value must be of LLVM pointer type.
|
// first if needed. The input value must be of LLVM pointer type.
|
||||||
func (b *builder) trackPointer(value llvm.Value) {
|
func (b *builder) trackPointer(value llvm.Value) {
|
||||||
|
|
|
@ -23,16 +23,6 @@ func getUses(value llvm.Value) []llvm.Value {
|
||||||
return uses
|
return uses
|
||||||
}
|
}
|
||||||
|
|
||||||
// createTemporaryAlloca creates a new alloca in the entry block and adds
|
|
||||||
// lifetime start infromation in the IR signalling that the alloca won't be used
|
|
||||||
// before this point.
|
|
||||||
//
|
|
||||||
// This is useful for creating temporary allocas for intrinsics. Don't forget to
|
|
||||||
// end the lifetime using emitLifetimeEnd after you're done with it.
|
|
||||||
func (c *Compiler) createTemporaryAlloca(t llvm.Type, name string) (alloca, bitcast, size llvm.Value) {
|
|
||||||
return llvmutil.CreateTemporaryAlloca(c.builder, c.mod, t, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// createTemporaryAlloca creates a new alloca in the entry block and adds
|
// createTemporaryAlloca creates a new alloca in the entry block and adds
|
||||||
// lifetime start infromation in the IR signalling that the alloca won't be used
|
// lifetime start infromation in the IR signalling that the alloca won't be used
|
||||||
// before this point.
|
// before this point.
|
||||||
|
@ -43,13 +33,6 @@ func (b *builder) createTemporaryAlloca(t llvm.Type, name string) (alloca, bitca
|
||||||
return llvmutil.CreateTemporaryAlloca(b.Builder, b.mod, t, name)
|
return llvmutil.CreateTemporaryAlloca(b.Builder, b.mod, t, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// emitLifetimeEnd signals the end of an (alloca) lifetime by calling the
|
|
||||||
// llvm.lifetime.end intrinsic. It is commonly used together with
|
|
||||||
// createTemporaryAlloca.
|
|
||||||
func (c *Compiler) emitLifetimeEnd(ptr, size llvm.Value) {
|
|
||||||
llvmutil.EmitLifetimeEnd(c.builder, c.mod, ptr, size)
|
|
||||||
}
|
|
||||||
|
|
||||||
// emitLifetimeEnd signals the end of an (alloca) lifetime by calling the
|
// emitLifetimeEnd signals the end of an (alloca) lifetime by calling the
|
||||||
// llvm.lifetime.end intrinsic. It is commonly used together with
|
// llvm.lifetime.end intrinsic. It is commonly used together with
|
||||||
// createTemporaryAlloca.
|
// createTemporaryAlloca.
|
||||||
|
@ -57,13 +40,6 @@ func (b *builder) emitLifetimeEnd(ptr, size llvm.Value) {
|
||||||
llvmutil.EmitLifetimeEnd(b.Builder, b.mod, ptr, size)
|
llvmutil.EmitLifetimeEnd(b.Builder, b.mod, ptr, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
// emitPointerPack packs the list of values into a single pointer value using
|
|
||||||
// bitcasts, or else allocates a value on the heap if it cannot be packed in the
|
|
||||||
// pointer value directly. It returns the pointer with the packed data.
|
|
||||||
func (c *Compiler) emitPointerPack(values []llvm.Value) llvm.Value {
|
|
||||||
return llvmutil.EmitPointerPack(c.builder, c.mod, c.Config, values)
|
|
||||||
}
|
|
||||||
|
|
||||||
// emitPointerPack packs the list of values into a single pointer value using
|
// emitPointerPack packs the list of values into a single pointer value using
|
||||||
// bitcasts, or else allocates a value on the heap if it cannot be packed in the
|
// bitcasts, or else allocates a value on the heap if it cannot be packed in the
|
||||||
// pointer value directly. It returns the pointer with the packed data.
|
// pointer value directly. It returns the pointer with the packed data.
|
||||||
|
@ -71,11 +47,6 @@ func (b *builder) emitPointerPack(values []llvm.Value) llvm.Value {
|
||||||
return llvmutil.EmitPointerPack(b.Builder, b.mod, b.Config, values)
|
return llvmutil.EmitPointerPack(b.Builder, b.mod, b.Config, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
// emitPointerUnpack extracts a list of values packed using emitPointerPack.
|
|
||||||
func (c *Compiler) emitPointerUnpack(ptr llvm.Value, valueTypes []llvm.Type) []llvm.Value {
|
|
||||||
return llvmutil.EmitPointerUnpack(c.builder, c.mod, ptr, valueTypes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// emitPointerUnpack extracts a list of values packed using emitPointerPack.
|
// emitPointerUnpack extracts a list of values packed using emitPointerPack.
|
||||||
func (b *builder) emitPointerUnpack(ptr llvm.Value, valueTypes []llvm.Type) []llvm.Value {
|
func (b *builder) emitPointerUnpack(ptr llvm.Value, valueTypes []llvm.Type) []llvm.Value {
|
||||||
return llvmutil.EmitPointerUnpack(b.Builder, b.mod, ptr, valueTypes)
|
return llvmutil.EmitPointerUnpack(b.Builder, b.mod, ptr, valueTypes)
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче