all: add type parameter to CreateLoad
This is needed for LLVM 15.
Этот коммит содержится в:
родитель
6bc6de8f82
коммит
7b6a9fab42
13 изменённых файлов: 48 добавлений и 36 удалений
|
@ -56,7 +56,7 @@ func (b *builder) createAtomicOp(name string) llvm.Value {
|
||||||
return swapped
|
return swapped
|
||||||
case "LoadInt32", "LoadInt64", "LoadUint32", "LoadUint64", "LoadUintptr", "LoadPointer":
|
case "LoadInt32", "LoadInt64", "LoadUint32", "LoadUint64", "LoadUintptr", "LoadPointer":
|
||||||
ptr := b.getValue(b.fn.Params[0])
|
ptr := b.getValue(b.fn.Params[0])
|
||||||
val := b.CreateLoad(ptr, "")
|
val := b.CreateLoad(b.getLLVMType(b.fn.Signature.Results().At(0).Type()), ptr, "")
|
||||||
val.SetOrdering(llvm.AtomicOrderingSequentiallyConsistent)
|
val.SetOrdering(llvm.AtomicOrderingSequentiallyConsistent)
|
||||||
val.SetAlignment(b.targetData.PrefTypeAlignment(val.Type())) // required
|
val.SetAlignment(b.targetData.PrefTypeAlignment(val.Type())) // required
|
||||||
return val
|
return val
|
||||||
|
|
|
@ -84,7 +84,7 @@ func (b *builder) createChanRecv(unop *ssa.UnOp) llvm.Value {
|
||||||
if isZeroSize {
|
if isZeroSize {
|
||||||
received = llvm.ConstNull(valueType)
|
received = llvm.ConstNull(valueType)
|
||||||
} else {
|
} else {
|
||||||
received = b.CreateLoad(valueAlloca, "chan.received")
|
received = b.CreateLoad(valueType, valueAlloca, "chan.received")
|
||||||
b.emitLifetimeEnd(valueAllocaCast, valueAllocaSize)
|
b.emitLifetimeEnd(valueAllocaCast, valueAllocaSize)
|
||||||
}
|
}
|
||||||
b.emitLifetimeEnd(channelBlockedListAllocaCast, channelBlockedListAllocaSize)
|
b.emitLifetimeEnd(channelBlockedListAllocaCast, channelBlockedListAllocaSize)
|
||||||
|
@ -264,8 +264,8 @@ func (b *builder) getChanSelectResult(expr *ssa.Extract) llvm.Value {
|
||||||
// receive can proceed at a time) so we'll get that alloca, bitcast
|
// receive can proceed at a time) so we'll get that alloca, bitcast
|
||||||
// it to the correct type, and dereference it.
|
// it to the correct type, and dereference it.
|
||||||
recvbuf := b.selectRecvBuf[expr.Tuple.(*ssa.Select)]
|
recvbuf := b.selectRecvBuf[expr.Tuple.(*ssa.Select)]
|
||||||
typ := llvm.PointerType(b.getLLVMType(expr.Type()), 0)
|
typ := b.getLLVMType(expr.Type())
|
||||||
ptr := b.CreateBitCast(recvbuf, typ, "")
|
ptr := b.CreateBitCast(recvbuf, llvm.PointerType(typ, 0), "")
|
||||||
return b.CreateLoad(ptr, "")
|
return b.CreateLoad(typ, ptr, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1931,11 +1931,12 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) {
|
||||||
|
|
||||||
// Can't load directly from array (as index is non-constant), so have to
|
// Can't load directly from array (as index is non-constant), so have to
|
||||||
// do it using an alloca+gep+load.
|
// do it using an alloca+gep+load.
|
||||||
alloca, allocaPtr, allocaSize := b.createTemporaryAlloca(array.Type(), "index.alloca")
|
arrayType := array.Type()
|
||||||
|
alloca, allocaPtr, allocaSize := b.createTemporaryAlloca(arrayType, "index.alloca")
|
||||||
b.CreateStore(array, alloca)
|
b.CreateStore(array, alloca)
|
||||||
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
||||||
ptr := b.CreateInBoundsGEP(alloca, []llvm.Value{zero, index}, "index.gep")
|
ptr := b.CreateInBoundsGEP(alloca, []llvm.Value{zero, index}, "index.gep")
|
||||||
result := b.CreateLoad(ptr, "index.load")
|
result := b.CreateLoad(arrayType.ElementType(), ptr, "index.load")
|
||||||
b.emitLifetimeEnd(allocaPtr, allocaSize)
|
b.emitLifetimeEnd(allocaPtr, allocaSize)
|
||||||
return result, nil
|
return result, nil
|
||||||
case *ssa.IndexAddr:
|
case *ssa.IndexAddr:
|
||||||
|
@ -2012,7 +2013,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) {
|
||||||
// Lookup byte
|
// Lookup byte
|
||||||
buf := b.CreateExtractValue(value, 0, "")
|
buf := b.CreateExtractValue(value, 0, "")
|
||||||
bufPtr := b.CreateInBoundsGEP(buf, []llvm.Value{index}, "")
|
bufPtr := b.CreateInBoundsGEP(buf, []llvm.Value{index}, "")
|
||||||
return b.CreateLoad(bufPtr, ""), nil
|
return b.CreateLoad(b.ctx.Int8Type(), bufPtr, ""), nil
|
||||||
case *types.Map:
|
case *types.Map:
|
||||||
valueType := expr.Type()
|
valueType := expr.Type()
|
||||||
if expr.CommaOk {
|
if expr.CommaOk {
|
||||||
|
@ -3076,10 +3077,10 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) {
|
||||||
return llvm.Value{}, b.makeError(unop.Pos(), "todo: unknown type for negate: "+unop.X.Type().Underlying().String())
|
return llvm.Value{}, b.makeError(unop.Pos(), "todo: unknown type for negate: "+unop.X.Type().Underlying().String())
|
||||||
}
|
}
|
||||||
case token.MUL: // *x, dereference pointer
|
case token.MUL: // *x, dereference pointer
|
||||||
unop.X.Type().Underlying().(*types.Pointer).Elem()
|
valueType := b.getLLVMType(unop.X.Type().Underlying().(*types.Pointer).Elem())
|
||||||
if b.targetData.TypeAllocSize(x.Type().ElementType()) == 0 {
|
if b.targetData.TypeAllocSize(x.Type().ElementType()) == 0 {
|
||||||
// zero-length data
|
// zero-length data
|
||||||
return llvm.ConstNull(x.Type().ElementType()), nil
|
return llvm.ConstNull(valueType), nil
|
||||||
} else if strings.HasSuffix(unop.X.String(), "$funcaddr") {
|
} else if strings.HasSuffix(unop.X.String(), "$funcaddr") {
|
||||||
// CGo function pointer. The cgo part has rewritten CGo function
|
// CGo function pointer. The cgo part has rewritten CGo function
|
||||||
// pointers as stub global variables of the form:
|
// pointers as stub global variables of the form:
|
||||||
|
@ -3094,7 +3095,7 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) {
|
||||||
return b.CreateBitCast(fn, b.i8ptrType, ""), nil
|
return b.CreateBitCast(fn, b.i8ptrType, ""), nil
|
||||||
} else {
|
} else {
|
||||||
b.createNilCheck(unop.X, x, "deref")
|
b.createNilCheck(unop.X, x, "deref")
|
||||||
load := b.CreateLoad(x, "")
|
load := b.CreateLoad(valueType, x, "")
|
||||||
return load, nil
|
return load, nil
|
||||||
}
|
}
|
||||||
case token.XOR: // ^x, toggle all bits in integer
|
case token.XOR: // ^x, toggle all bits in integer
|
||||||
|
|
|
@ -249,7 +249,8 @@ func isInLoop(start *ssa.BasicBlock) bool {
|
||||||
func (b *builder) createDefer(instr *ssa.Defer) {
|
func (b *builder) createDefer(instr *ssa.Defer) {
|
||||||
// The pointer to the previous defer struct, which we will replace to
|
// The pointer to the previous defer struct, which we will replace to
|
||||||
// make a linked list.
|
// make a linked list.
|
||||||
next := b.CreateLoad(b.deferPtr, "defer.next")
|
deferType := llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0)
|
||||||
|
next := b.CreateLoad(deferType, b.deferPtr, "defer.next")
|
||||||
|
|
||||||
var values []llvm.Value
|
var values []llvm.Value
|
||||||
valueTypes := []llvm.Type{b.uintptrType, next.Type()}
|
valueTypes := []llvm.Type{b.uintptrType, next.Type()}
|
||||||
|
@ -406,6 +407,8 @@ func (b *builder) createDefer(instr *ssa.Defer) {
|
||||||
|
|
||||||
// createRunDefers emits code to run all deferred functions.
|
// createRunDefers emits code to run all deferred functions.
|
||||||
func (b *builder) createRunDefers() {
|
func (b *builder) createRunDefers() {
|
||||||
|
deferType := llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0)
|
||||||
|
|
||||||
// Add a loop like the following:
|
// Add a loop like the following:
|
||||||
// for stack != nil {
|
// for stack != nil {
|
||||||
// _stack := stack
|
// _stack := stack
|
||||||
|
@ -431,7 +434,7 @@ func (b *builder) createRunDefers() {
|
||||||
// Create loop head:
|
// Create loop head:
|
||||||
// for stack != nil {
|
// for stack != nil {
|
||||||
b.SetInsertPointAtEnd(loophead)
|
b.SetInsertPointAtEnd(loophead)
|
||||||
deferData := b.CreateLoad(b.deferPtr, "")
|
deferData := b.CreateLoad(deferType, b.deferPtr, "")
|
||||||
stackIsNil := b.CreateICmp(llvm.IntEQ, deferData, llvm.ConstPointerNull(deferData.Type()), "stackIsNil")
|
stackIsNil := b.CreateICmp(llvm.IntEQ, deferData, llvm.ConstPointerNull(deferData.Type()), "stackIsNil")
|
||||||
b.CreateCondBr(stackIsNil, end, loop)
|
b.CreateCondBr(stackIsNil, end, loop)
|
||||||
|
|
||||||
|
@ -444,13 +447,13 @@ func (b *builder) createRunDefers() {
|
||||||
llvm.ConstInt(b.ctx.Int32Type(), 0, false),
|
llvm.ConstInt(b.ctx.Int32Type(), 0, false),
|
||||||
llvm.ConstInt(b.ctx.Int32Type(), 1, false), // .next field
|
llvm.ConstInt(b.ctx.Int32Type(), 1, false), // .next field
|
||||||
}, "stack.next.gep")
|
}, "stack.next.gep")
|
||||||
nextStack := b.CreateLoad(nextStackGEP, "stack.next")
|
nextStack := b.CreateLoad(deferType, nextStackGEP, "stack.next")
|
||||||
b.CreateStore(nextStack, b.deferPtr)
|
b.CreateStore(nextStack, b.deferPtr)
|
||||||
gep := b.CreateInBoundsGEP(deferData, []llvm.Value{
|
gep := b.CreateInBoundsGEP(deferData, []llvm.Value{
|
||||||
llvm.ConstInt(b.ctx.Int32Type(), 0, false),
|
llvm.ConstInt(b.ctx.Int32Type(), 0, false),
|
||||||
llvm.ConstInt(b.ctx.Int32Type(), 0, false), // .callback field
|
llvm.ConstInt(b.ctx.Int32Type(), 0, false), // .callback field
|
||||||
}, "callback.gep")
|
}, "callback.gep")
|
||||||
callback := b.CreateLoad(gep, "callback")
|
callback := b.CreateLoad(b.uintptrType, gep, "callback")
|
||||||
sw := b.CreateSwitch(callback, unreachable, len(b.allDeferFuncs))
|
sw := b.CreateSwitch(callback, unreachable, len(b.allDeferFuncs))
|
||||||
|
|
||||||
for i, callback := range b.allDeferFuncs {
|
for i, callback := range b.allDeferFuncs {
|
||||||
|
@ -487,7 +490,7 @@ func (b *builder) createRunDefers() {
|
||||||
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
||||||
for i := 2; i < len(valueTypes); i++ {
|
for i := 2; i < len(valueTypes); i++ {
|
||||||
gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "gep")
|
gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "gep")
|
||||||
forwardParam := b.CreateLoad(gep, "param")
|
forwardParam := b.CreateLoad(valueTypes[i], gep, "param")
|
||||||
forwardParams = append(forwardParams, forwardParam)
|
forwardParams = append(forwardParams, forwardParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +539,7 @@ func (b *builder) createRunDefers() {
|
||||||
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
||||||
for i := range getParams(callback.Signature) {
|
for i := range getParams(callback.Signature) {
|
||||||
gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep")
|
gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep")
|
||||||
forwardParam := b.CreateLoad(gep, "param")
|
forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param")
|
||||||
forwardParams = append(forwardParams, forwardParam)
|
forwardParams = append(forwardParams, forwardParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,7 +572,7 @@ func (b *builder) createRunDefers() {
|
||||||
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
||||||
for i := 2; i < len(valueTypes); i++ {
|
for i := 2; i < len(valueTypes); i++ {
|
||||||
gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "")
|
gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i), false)}, "")
|
||||||
forwardParam := b.CreateLoad(gep, "param")
|
forwardParam := b.CreateLoad(valueTypes[i], gep, "param")
|
||||||
forwardParams = append(forwardParams, forwardParam)
|
forwardParams = append(forwardParams, forwardParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,7 +599,7 @@ func (b *builder) createRunDefers() {
|
||||||
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
||||||
for i := 0; i < params.Len(); i++ {
|
for i := 0; i < params.Len(); i++ {
|
||||||
gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep")
|
gep := b.CreateInBoundsGEP(deferredCallPtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep")
|
||||||
forwardParam := b.CreateLoad(gep, "param")
|
forwardParam := b.CreateLoad(valueTypes[i+2], gep, "param")
|
||||||
argValues = append(argValues, forwardParam)
|
argValues = append(argValues, forwardParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, prefix string, needs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load value (the *i8) from the alloca.
|
// Load value (the *i8) from the alloca.
|
||||||
result := builder.CreateLoad(packedAlloc, "")
|
result := builder.CreateLoad(i8ptrType, packedAlloc, "")
|
||||||
|
|
||||||
// End the lifetime of the alloca, to help the optimizer.
|
// End the lifetime of the alloca, to help the optimizer.
|
||||||
packedPtr := builder.CreateBitCast(packedAlloc, i8ptrType, "")
|
packedPtr := builder.CreateBitCast(packedAlloc, i8ptrType, "")
|
||||||
|
@ -171,7 +171,7 @@ func EmitPointerUnpack(builder llvm.Builder, mod llvm.Module, ptr llvm.Value, va
|
||||||
llvm.ConstInt(ctx.Int32Type(), uint64(i), false),
|
llvm.ConstInt(ctx.Int32Type(), uint64(i), false),
|
||||||
}
|
}
|
||||||
gep := builder.CreateInBoundsGEP(packedAlloc, indices, "")
|
gep := builder.CreateInBoundsGEP(packedAlloc, indices, "")
|
||||||
values[i] = builder.CreateLoad(gep, "")
|
values[i] = builder.CreateLoad(valueType, gep, "")
|
||||||
}
|
}
|
||||||
if !packedRawAlloc.IsNil() {
|
if !packedRawAlloc.IsNil() {
|
||||||
allocPtr := builder.CreateBitCast(packedRawAlloc, i8ptrType, "")
|
allocPtr := builder.CreateBitCast(packedRawAlloc, i8ptrType, "")
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (b *builder) createMapLookup(keyType, valueType types.Type, m, key llvm.Val
|
||||||
|
|
||||||
// Load the resulting value from the hashmap. The value is set to the zero
|
// Load the resulting value from the hashmap. The value is set to the zero
|
||||||
// value if the key doesn't exist in the hashmap.
|
// value if the key doesn't exist in the hashmap.
|
||||||
mapValue := b.CreateLoad(mapValueAlloca, "")
|
mapValue := b.CreateLoad(llvmValueType, mapValueAlloca, "")
|
||||||
b.emitLifetimeEnd(mapValuePtr, mapValueAllocaSize)
|
b.emitLifetimeEnd(mapValuePtr, mapValueAllocaSize)
|
||||||
|
|
||||||
if commaOk {
|
if commaOk {
|
||||||
|
@ -217,8 +217,8 @@ func (b *builder) createMapIteratorNext(rangeVal ssa.Value, llvmRangeVal, it llv
|
||||||
mapKeyAlloca, mapKeyPtr, mapKeySize := b.createTemporaryAlloca(llvmStoredKeyType, "range.key")
|
mapKeyAlloca, mapKeyPtr, mapKeySize := b.createTemporaryAlloca(llvmStoredKeyType, "range.key")
|
||||||
mapValueAlloca, mapValuePtr, mapValueSize := b.createTemporaryAlloca(llvmValueType, "range.value")
|
mapValueAlloca, mapValuePtr, mapValueSize := b.createTemporaryAlloca(llvmValueType, "range.value")
|
||||||
ok := b.createRuntimeCall("hashmapNext", []llvm.Value{llvmRangeVal, it, mapKeyPtr, mapValuePtr}, "range.next")
|
ok := b.createRuntimeCall("hashmapNext", []llvm.Value{llvmRangeVal, it, mapKeyPtr, mapValuePtr}, "range.next")
|
||||||
mapKey := b.CreateLoad(mapKeyAlloca, "")
|
mapKey := b.CreateLoad(llvmStoredKeyType, mapKeyAlloca, "")
|
||||||
mapValue := b.CreateLoad(mapValueAlloca, "")
|
mapValue := b.CreateLoad(llvmValueType, mapValueAlloca, "")
|
||||||
|
|
||||||
if isKeyStoredAsInterface {
|
if isKeyStoredAsInterface {
|
||||||
// The key is stored as an interface but it isn't of interface type.
|
// The key is stored as an interface but it isn't of interface type.
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
|
import "go/types"
|
||||||
|
|
||||||
// This file implements volatile loads/stores in runtime/volatile.LoadT and
|
// This file implements volatile loads/stores in runtime/volatile.LoadT and
|
||||||
// runtime/volatile.StoreT as compiler builtins.
|
// runtime/volatile.StoreT as compiler builtins.
|
||||||
|
|
||||||
|
@ -9,7 +11,8 @@ func (b *builder) createVolatileLoad() {
|
||||||
b.createFunctionStart(true)
|
b.createFunctionStart(true)
|
||||||
addr := b.getValue(b.fn.Params[0])
|
addr := b.getValue(b.fn.Params[0])
|
||||||
b.createNilCheck(b.fn.Params[0], addr, "deref")
|
b.createNilCheck(b.fn.Params[0], addr, "deref")
|
||||||
val := b.CreateLoad(addr, "")
|
valType := b.getLLVMType(b.fn.Params[0].Type().(*types.Pointer).Elem())
|
||||||
|
val := b.CreateLoad(valType, addr, "")
|
||||||
val.SetVolatile(true)
|
val.SetVolatile(true)
|
||||||
b.CreateRet(val)
|
b.CreateRet(val)
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -17,7 +17,7 @@ require (
|
||||||
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261
|
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261
|
||||||
golang.org/x/tools v0.1.11
|
golang.org/x/tools v0.1.11
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636
|
tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -64,5 +64,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636 h1:JxtI6P/lyWHAcs/4QJWeWIbh4HntxPFONMVWvx7wf8Y=
|
tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6 h1:bJYUpmJrVm7Uluxh80qSivfeU3d9D4JNg5oJ+h9U+xc=
|
||||||
tinygo.org/x/go-llvm v0.0.0-20220921144613-dcf4836fe636/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0=
|
tinygo.org/x/go-llvm v0.0.0-20220921144624-6c125b0aeda6/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0=
|
||||||
|
|
|
@ -983,7 +983,7 @@ func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, me
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return r.errorAt(inst, err)
|
return r.errorAt(inst, err)
|
||||||
}
|
}
|
||||||
result = r.builder.CreateLoad(operands[0], inst.name)
|
result = r.builder.CreateLoad(inst.llvmInst.Type(), operands[0], inst.name)
|
||||||
if inst.llvmInst.IsVolatile() {
|
if inst.llvmInst.IsVolatile() {
|
||||||
result.SetVolatile(true)
|
result.SetVolatile(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ func MakeGCStackSlots(mod llvm.Module) bool {
|
||||||
builder.CreateStore(initialStackObject, stackObject)
|
builder.CreateStore(initialStackObject, stackObject)
|
||||||
|
|
||||||
// Update stack start.
|
// Update stack start.
|
||||||
parent := builder.CreateLoad(stackChainStart, "")
|
parent := builder.CreateLoad(stackChainStartType, stackChainStart, "")
|
||||||
gep := builder.CreateGEP(stackObject, []llvm.Value{
|
gep := builder.CreateGEP(stackObject, []llvm.Value{
|
||||||
llvm.ConstInt(ctx.Int32Type(), 0, false),
|
llvm.ConstInt(ctx.Int32Type(), 0, false),
|
||||||
llvm.ConstInt(ctx.Int32Type(), 0, false),
|
llvm.ConstInt(ctx.Int32Type(), 0, false),
|
||||||
|
|
|
@ -34,6 +34,11 @@ func CreateStackSizeLoads(mod llvm.Module, config *compileopts.Config) []string
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx := mod.Context()
|
||||||
|
targetData := llvm.NewTargetData(mod.DataLayout())
|
||||||
|
defer targetData.Dispose()
|
||||||
|
uintptrType := ctx.IntType(targetData.PointerSize() * 8)
|
||||||
|
|
||||||
// Create the new global with stack sizes, that will be put in a new section
|
// Create the new global with stack sizes, that will be put in a new section
|
||||||
// just for itself.
|
// just for itself.
|
||||||
stackSizesGlobalType := llvm.ArrayType(functions[0].Type(), len(functions))
|
stackSizesGlobalType := llvm.ArrayType(functions[0].Type(), len(functions))
|
||||||
|
@ -50,16 +55,16 @@ func CreateStackSizeLoads(mod llvm.Module, config *compileopts.Config) []string
|
||||||
appendToUsedGlobals(mod, append([]llvm.Value{stackSizesGlobal}, functionValues...)...)
|
appendToUsedGlobals(mod, append([]llvm.Value{stackSizesGlobal}, functionValues...)...)
|
||||||
|
|
||||||
// Replace the calls with loads from the new global with stack sizes.
|
// Replace the calls with loads from the new global with stack sizes.
|
||||||
irbuilder := mod.Context().NewBuilder()
|
irbuilder := ctx.NewBuilder()
|
||||||
defer irbuilder.Dispose()
|
defer irbuilder.Dispose()
|
||||||
for i, function := range functions {
|
for i, function := range functions {
|
||||||
for _, use := range functionMap[function] {
|
for _, use := range functionMap[function] {
|
||||||
ptr := llvm.ConstGEP(stackSizesGlobal, []llvm.Value{
|
ptr := llvm.ConstGEP(stackSizesGlobal, []llvm.Value{
|
||||||
llvm.ConstInt(mod.Context().Int32Type(), 0, false),
|
llvm.ConstInt(ctx.Int32Type(), 0, false),
|
||||||
llvm.ConstInt(mod.Context().Int32Type(), uint64(i), false),
|
llvm.ConstInt(ctx.Int32Type(), uint64(i), false),
|
||||||
})
|
})
|
||||||
irbuilder.SetInsertPointBefore(use)
|
irbuilder.SetInsertPointBefore(use)
|
||||||
stacksize := irbuilder.CreateLoad(ptr, "stacksize")
|
stacksize := irbuilder.CreateLoad(uintptrType, ptr, "stacksize")
|
||||||
use.ReplaceAllUsesWith(stacksize)
|
use.ReplaceAllUsesWith(stacksize)
|
||||||
use.EraseFromParentAsInstruction()
|
use.EraseFromParentAsInstruction()
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error {
|
||||||
// where the return value should be stored, instead of using
|
// where the return value should be stored, instead of using
|
||||||
// the regular return value.
|
// the regular return value.
|
||||||
builder.CreateCall(externalFnType, externalFn, callParams, callName)
|
builder.CreateCall(externalFnType, externalFn, callParams, callName)
|
||||||
returnValue := builder.CreateLoad(retvalAlloca, "retval")
|
returnValue := builder.CreateLoad(int64Type, retvalAlloca, "retval")
|
||||||
call.ReplaceAllUsesWith(returnValue)
|
call.ReplaceAllUsesWith(returnValue)
|
||||||
call.EraseFromParentAsInstruction()
|
call.EraseFromParentAsInstruction()
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,7 +152,7 @@ func ExternalInt64AsPtr(mod llvm.Module, config *compileopts.Config) error {
|
||||||
for i, origParam := range fn.Params() {
|
for i, origParam := range fn.Params() {
|
||||||
paramValue := externalFn.Param(i)
|
paramValue := externalFn.Param(i)
|
||||||
if origParam.Type() == int64Type {
|
if origParam.Type() == int64Type {
|
||||||
paramValue = builder.CreateLoad(paramValue, "i64")
|
paramValue = builder.CreateLoad(int64Type, paramValue, "i64")
|
||||||
}
|
}
|
||||||
callParams = append(callParams, paramValue)
|
callParams = append(callParams, paramValue)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче