Skip to content

Commit 6691f4c

Browse files
committed
compiler: compile all functions/methods, remove SimpleDCE
This is important because once we move to compiling packages independently, SimpleDCE can't work anymore. Instead we'll have to compile all parts of a package and cache that for later reuse.
1 parent 1128a38 commit 6691f4c

File tree

11 files changed

+489
-593
lines changed

11 files changed

+489
-593
lines changed

compiler/asserts.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
// slice. This is required by the Go language spec: an index out of bounds must
1717
// cause a panic.
1818
func (b *builder) createLookupBoundsCheck(arrayLen, index llvm.Value, indexType types.Type) {
19-
if b.fn.IsNoBounds() {
19+
if b.info.nobounds {
2020
// The //go:nobounds pragma was added to the function to avoid bounds
2121
// checking.
2222
return
@@ -48,7 +48,7 @@ func (b *builder) createLookupBoundsCheck(arrayLen, index llvm.Value, indexType
4848
// biggest possible slice capacity, 'low' means len and 'high' means cap. The
4949
// logic is the same in both cases.
5050
func (b *builder) createSliceBoundsCheck(capacity, low, high, max llvm.Value, lowType, highType, maxType *types.Basic) {
51-
if b.fn.IsNoBounds() {
51+
if b.info.nobounds {
5252
// The //go:nobounds pragma was added to the function to avoid bounds
5353
// checking.
5454
return
@@ -104,7 +104,7 @@ func (b *builder) createSliceBoundsCheck(capacity, low, high, max llvm.Value, lo
104104
// createChanBoundsCheck creates a bounds check before creating a new channel to
105105
// check that the value is not too big for runtime.chanMake.
106106
func (b *builder) createChanBoundsCheck(elementSize uint64, bufSize llvm.Value, bufSizeType *types.Basic, pos token.Pos) {
107-
if b.fn.IsNoBounds() {
107+
if b.info.nobounds {
108108
// The //go:nobounds pragma was added to the function to avoid bounds
109109
// checking.
110110
return
@@ -189,7 +189,7 @@ func (b *builder) createNilCheck(inst ssa.Value, ptr llvm.Value, blockPrefix str
189189
// createNegativeShiftCheck creates an assertion that panics if the given shift value is negative.
190190
// This function assumes that the shift value is signed.
191191
func (b *builder) createNegativeShiftCheck(shift llvm.Value) {
192-
if b.fn.IsNoBounds() {
192+
if b.info.nobounds {
193193
// Function disabled bounds checking - skip shift check.
194194
return
195195
}
@@ -212,8 +212,8 @@ func (b *builder) createRuntimeAssert(assert llvm.Value, blockPrefix, assertFunc
212212
}
213213
}
214214

215-
faultBlock := b.ctx.AddBasicBlock(b.fn.LLVMFn, blockPrefix+".throw")
216-
nextBlock := b.ctx.AddBasicBlock(b.fn.LLVMFn, blockPrefix+".next")
215+
faultBlock := b.ctx.AddBasicBlock(b.llvmFn, blockPrefix+".throw")
216+
nextBlock := b.ctx.AddBasicBlock(b.llvmFn, blockPrefix+".next")
217217
b.blockExits[b.currentBlock] = nextBlock // adjust outgoing block for phi nodes
218218

219219
// Now branch to the out-of-bounds or the regular block.

compiler/calls.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"go/types"
55
"strconv"
66

7+
"golang.org/x/tools/go/ssa"
78
"tinygo.org/x/go-llvm"
89
)
910

@@ -34,14 +35,14 @@ const (
3435

3536
// createCall creates a new call to runtime.<fnName> with the given arguments.
3637
func (b *builder) createRuntimeCall(fnName string, args []llvm.Value, name string) llvm.Value {
37-
fullName := "runtime." + fnName
38-
fn := b.mod.NamedFunction(fullName)
39-
if fn.IsNil() {
40-
panic("trying to call non-existent function: " + fullName)
38+
fn := b.ir.Program.ImportedPackage("runtime").Members[fnName].(*ssa.Function)
39+
llvmFn := b.getFunction(fn)
40+
if llvmFn.IsNil() {
41+
panic("trying to call non-existent function: " + fn.RelString(nil))
4142
}
4243
args = append(args, llvm.Undef(b.i8ptrType)) // unused context parameter
4344
args = append(args, llvm.ConstPointerNull(b.i8ptrType)) // coroutine handle
44-
return b.createCall(fn, args, name)
45+
return b.createCall(llvmFn, args, name)
4546
}
4647

4748
// createCall creates a call to the given function with the arguments possibly

0 commit comments

Comments
 (0)