Skip to content

Commit 8ef921e

Browse files
aykevldeadprogram
authored andcommitted
compiler: remove leftover code after refactor
A few functions were duplicated during the refactor. They can now be deleted.
1 parent 315b028 commit 8ef921e

File tree

4 files changed

+0
-118
lines changed

4 files changed

+0
-118
lines changed

compiler/calls.go

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package compiler
22

33
import (
4-
"fmt"
5-
"golang.org/x/tools/go/ssa"
64
"tinygo.org/x/go-llvm"
75
)
86

@@ -13,24 +11,6 @@ import (
1311
// a struct contains more fields, it is passed as a struct without expanding.
1412
const MaxFieldsPerParam = 3
1513

16-
// Shortcut: create a call to runtime.<fnName> with the given arguments.
17-
func (c *Compiler) createRuntimeCall(fnName string, args []llvm.Value, name string) llvm.Value {
18-
runtimePkg := c.ir.Program.ImportedPackage("runtime")
19-
member := runtimePkg.Members[fnName]
20-
if member == nil {
21-
panic("trying to call runtime." + fnName)
22-
}
23-
fn := c.ir.GetFunction(member.(*ssa.Function))
24-
if fn.LLVMFn.IsNil() {
25-
panic(fmt.Errorf("function %s does not appear in LLVM IR", fnName))
26-
}
27-
if !fn.IsExported() {
28-
args = append(args, llvm.Undef(c.i8ptrType)) // unused context parameter
29-
args = append(args, llvm.ConstPointerNull(c.i8ptrType)) // coroutine handle
30-
}
31-
return c.createCall(fn.LLVMFn, args, name)
32-
}
33-
3414
// createCall creates a new call to runtime.<fnName> with the given arguments.
3515
func (b *builder) createRuntimeCall(fnName string, args []llvm.Value, name string) llvm.Value {
3616
fullName := "runtime." + fnName
@@ -43,16 +23,6 @@ func (b *builder) createRuntimeCall(fnName string, args []llvm.Value, name strin
4323
return b.createCall(fn, args, name)
4424
}
4525

46-
// Create a call to the given function with the arguments possibly expanded.
47-
func (c *Compiler) createCall(fn llvm.Value, args []llvm.Value, name string) llvm.Value {
48-
expanded := make([]llvm.Value, 0, len(args))
49-
for _, arg := range args {
50-
fragments := c.expandFormalParam(arg)
51-
expanded = append(expanded, fragments...)
52-
}
53-
return c.builder.CreateCall(fn, expanded, name)
54-
}
55-
5626
// createCall creates a call to the given function with the arguments possibly
5727
// expanded.
5828
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 {
10272
}
10373
}
10474

105-
// Equivalent of expandFormalParamType for parameter values.
106-
func (c *Compiler) expandFormalParam(v llvm.Value) []llvm.Value {
107-
switch v.Type().TypeKind() {
108-
case llvm.StructTypeKind:
109-
fieldTypes := flattenAggregateType(v.Type())
110-
if len(fieldTypes) <= MaxFieldsPerParam {
111-
fields := c.flattenAggregate(v)
112-
if len(fields) != len(fieldTypes) {
113-
panic("type and value param lowering don't match")
114-
}
115-
return fields
116-
} else {
117-
// failed to lower
118-
return []llvm.Value{v}
119-
}
120-
default:
121-
// TODO: split small arrays
122-
return []llvm.Value{v}
123-
}
124-
}
125-
12675
// expandFormalParam splits a formal param value into pieces, so it can be
12776
// passed directly as part of a function call. For example, it splits up small
12877
// structs into individual fields. It is the equivalent of expandFormalParamType
@@ -187,23 +136,6 @@ func (c *compilerContext) flattenAggregateTypeOffsets(t llvm.Type) []uint64 {
187136
}
188137
}
189138

190-
// Break down a struct into its elementary types for argument passing. The value
191-
// equivalent of flattenAggregateType
192-
func (c *Compiler) flattenAggregate(v llvm.Value) []llvm.Value {
193-
switch v.Type().TypeKind() {
194-
case llvm.StructTypeKind:
195-
fields := make([]llvm.Value, 0, v.Type().StructElementTypesCount())
196-
for i := range v.Type().StructElementTypes() {
197-
subfield := c.builder.CreateExtractValue(v, i, "")
198-
subfields := c.flattenAggregate(subfield)
199-
fields = append(fields, subfields...)
200-
}
201-
return fields
202-
default:
203-
return []llvm.Value{v}
204-
}
205-
}
206-
207139
// flattenAggregate breaks down a struct into its elementary values for argument
208140
// passing. It is the value equivalent of flattenAggregateType
209141
func (b *builder) flattenAggregate(v llvm.Value) []llvm.Value {

compiler/func.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import (
1111
"tinygo.org/x/go-llvm"
1212
)
1313

14-
// createFuncValue creates a function value from a raw function pointer with no
15-
// context.
16-
func (c *Compiler) createFuncValue(funcPtr, context llvm.Value, sig *types.Signature) llvm.Value {
17-
return c.compilerContext.createFuncValue(c.builder, funcPtr, context, sig)
18-
}
19-
2014
// createFuncValue creates a function value from a raw function pointer with no
2115
// context.
2216
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
5751
return funcValue
5852
}
5953

60-
// extractFuncScalar returns some scalar that can be used in comparisons. It is
61-
// a cheap operation.
62-
func (c *Compiler) extractFuncScalar(funcValue llvm.Value) llvm.Value {
63-
return c.builder.CreateExtractValue(funcValue, 1, "")
64-
}
65-
6654
// extractFuncScalar returns some scalar that can be used in comparisons. It is
6755
// a cheap operation.
6856
func (b *builder) extractFuncScalar(funcValue llvm.Value) llvm.Value {

compiler/gc.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,6 @@ func (b *builder) trackValue(value llvm.Value) {
7272
}
7373
}
7474

75-
// trackPointer creates a call to runtime.trackPointer, bitcasting the poitner
76-
// first if needed. The input value must be of LLVM pointer type.
77-
func (c *Compiler) trackPointer(value llvm.Value) {
78-
if value.Type() != c.i8ptrType {
79-
value = c.builder.CreateBitCast(value, c.i8ptrType, "")
80-
}
81-
c.createRuntimeCall("trackPointer", []llvm.Value{value}, "")
82-
}
83-
8475
// trackPointer creates a call to runtime.trackPointer, bitcasting the poitner
8576
// first if needed. The input value must be of LLVM pointer type.
8677
func (b *builder) trackPointer(value llvm.Value) {

compiler/llvm.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ func getUses(value llvm.Value) []llvm.Value {
2323
return uses
2424
}
2525

26-
// createTemporaryAlloca creates a new alloca in the entry block and adds
27-
// lifetime start infromation in the IR signalling that the alloca won't be used
28-
// before this point.
29-
//
30-
// This is useful for creating temporary allocas for intrinsics. Don't forget to
31-
// end the lifetime using emitLifetimeEnd after you're done with it.
32-
func (c *Compiler) createTemporaryAlloca(t llvm.Type, name string) (alloca, bitcast, size llvm.Value) {
33-
return llvmutil.CreateTemporaryAlloca(c.builder, c.mod, t, name)
34-
}
35-
3626
// createTemporaryAlloca creates a new alloca in the entry block and adds
3727
// lifetime start infromation in the IR signalling that the alloca won't be used
3828
// before this point.
@@ -43,39 +33,20 @@ func (b *builder) createTemporaryAlloca(t llvm.Type, name string) (alloca, bitca
4333
return llvmutil.CreateTemporaryAlloca(b.Builder, b.mod, t, name)
4434
}
4535

46-
// emitLifetimeEnd signals the end of an (alloca) lifetime by calling the
47-
// llvm.lifetime.end intrinsic. It is commonly used together with
48-
// createTemporaryAlloca.
49-
func (c *Compiler) emitLifetimeEnd(ptr, size llvm.Value) {
50-
llvmutil.EmitLifetimeEnd(c.builder, c.mod, ptr, size)
51-
}
52-
5336
// emitLifetimeEnd signals the end of an (alloca) lifetime by calling the
5437
// llvm.lifetime.end intrinsic. It is commonly used together with
5538
// createTemporaryAlloca.
5639
func (b *builder) emitLifetimeEnd(ptr, size llvm.Value) {
5740
llvmutil.EmitLifetimeEnd(b.Builder, b.mod, ptr, size)
5841
}
5942

60-
// emitPointerPack packs the list of values into a single pointer value using
61-
// bitcasts, or else allocates a value on the heap if it cannot be packed in the
62-
// pointer value directly. It returns the pointer with the packed data.
63-
func (c *Compiler) emitPointerPack(values []llvm.Value) llvm.Value {
64-
return llvmutil.EmitPointerPack(c.builder, c.mod, c.Config, values)
65-
}
66-
6743
// emitPointerPack packs the list of values into a single pointer value using
6844
// bitcasts, or else allocates a value on the heap if it cannot be packed in the
6945
// pointer value directly. It returns the pointer with the packed data.
7046
func (b *builder) emitPointerPack(values []llvm.Value) llvm.Value {
7147
return llvmutil.EmitPointerPack(b.Builder, b.mod, b.Config, values)
7248
}
7349

74-
// emitPointerUnpack extracts a list of values packed using emitPointerPack.
75-
func (c *Compiler) emitPointerUnpack(ptr llvm.Value, valueTypes []llvm.Type) []llvm.Value {
76-
return llvmutil.EmitPointerUnpack(c.builder, c.mod, ptr, valueTypes)
77-
}
78-
7950
// emitPointerUnpack extracts a list of values packed using emitPointerPack.
8051
func (b *builder) emitPointerUnpack(ptr llvm.Value, valueTypes []llvm.Type) []llvm.Value {
8152
return llvmutil.EmitPointerUnpack(b.Builder, b.mod, ptr, valueTypes)

0 commit comments

Comments
 (0)