aboutsummaryrefslogtreecommitdiffhomepage
path: root/interp
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-09-18 17:54:29 +0200
committerAyke <[email protected]>2023-10-01 18:32:15 +0200
commit1da1abe3147796aa56a5486ed6f07afdd88d8234 (patch)
tree256e56c96855bb27e67834a9586bac510ccff910 /interp
parentc9721197d5adb70a5086ecd320a1e3745bcaacc7 (diff)
downloadtinygo-1da1abe3147796aa56a5486ed6f07afdd88d8234.tar.gz
tinygo-1da1abe3147796aa56a5486ed6f07afdd88d8234.zip
all: remove LLVM 14 support
This is a big change: apart from removing LLVM 14 it also removes typed pointer support (which was only fully supported in LLVM up to version 14). This removes about 200 lines of code, but more importantly removes a ton of special cases for LLVM 14.
Diffstat (limited to 'interp')
-rw-r--r--interp/interp.go11
-rw-r--r--interp/interpreter.go12
-rw-r--r--interp/memory.go19
3 files changed, 9 insertions, 33 deletions
diff --git a/interp/interp.go b/interp/interp.go
index 7833dfe93..63a664920 100644
--- a/interp/interp.go
+++ b/interp/interp.go
@@ -21,7 +21,7 @@ type runner struct {
targetData llvm.TargetData
builder llvm.Builder
pointerSize uint32 // cached pointer size from the TargetData
- i8ptrType llvm.Type // often used type so created in advance
+ dataPtrType llvm.Type // often used type so created in advance
uintptrType llvm.Type // equivalent to uintptr in Go
maxAlign int // maximum alignment of an object, alignment of runtime.alloc() result
debug bool // log debug messages
@@ -46,9 +46,9 @@ func newRunner(mod llvm.Module, timeout time.Duration, debug bool) *runner {
timeout: timeout,
}
r.pointerSize = uint32(r.targetData.PointerSize())
- r.i8ptrType = llvm.PointerType(mod.Context().Int8Type(), 0)
+ r.dataPtrType = llvm.PointerType(mod.Context().Int8Type(), 0)
r.uintptrType = mod.Context().IntType(r.targetData.PointerSize() * 8)
- r.maxAlign = r.targetData.PrefTypeAlignment(r.i8ptrType) // assume pointers are maximally aligned (this is not always the case)
+ r.maxAlign = r.targetData.PrefTypeAlignment(r.dataPtrType) // assume pointers are maximally aligned (this is not always the case)
return &r
}
@@ -126,7 +126,7 @@ func Run(mod llvm.Module, timeout time.Duration, debug bool) error {
mem.revert()
// Create a call to the package initializer (which was
// previously deleted).
- i8undef := llvm.Undef(r.i8ptrType)
+ i8undef := llvm.Undef(r.dataPtrType)
r.builder.CreateCall(fn.GlobalValueType(), fn, []llvm.Value{i8undef}, "")
// Make sure that any globals touched by the package
// initializer, won't be accessed by later package initializers.
@@ -174,8 +174,7 @@ func Run(mod llvm.Module, timeout time.Duration, debug bool) error {
newGlobal.SetLinkage(obj.llvmGlobal.Linkage())
newGlobal.SetAlignment(obj.llvmGlobal.Alignment())
// TODO: copy debug info, unnamed_addr, ...
- bitcast := llvm.ConstBitCast(newGlobal, obj.llvmGlobal.Type())
- obj.llvmGlobal.ReplaceAllUsesWith(bitcast)
+ obj.llvmGlobal.ReplaceAllUsesWith(newGlobal)
name := obj.llvmGlobal.Name()
obj.llvmGlobal.EraseFromParentAsGlobal()
newGlobal.SetName(name)
diff --git a/interp/interpreter.go b/interp/interpreter.go
index 3150aca93..24f5e9e85 100644
--- a/interp/interpreter.go
+++ b/interp/interpreter.go
@@ -1046,15 +1046,3 @@ func intPredicateString(predicate llvm.IntPredicate) string {
return "cmp?"
}
}
-
-// Strip some pointer casts. This is probably unnecessary once support for
-// LLVM 14 (non-opaque pointers) is dropped.
-func stripPointerCasts(value llvm.Value) llvm.Value {
- if !value.IsAConstantExpr().IsNil() {
- switch value.Opcode() {
- case llvm.GetElementPtr, llvm.BitCast:
- return stripPointerCasts(value.Operand(0))
- }
- }
- return value
-}
diff --git a/interp/memory.go b/interp/memory.go
index 2065bcdf5..356ffa512 100644
--- a/interp/memory.go
+++ b/interp/memory.go
@@ -658,20 +658,11 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val
if v.offset() != 0 {
// If there is an offset, make sure to use a GEP to index into the
// pointer.
- // Cast to an i8* first (if needed) for easy indexing.
- if llvmValue.Type() != mem.r.i8ptrType {
- llvmValue = llvm.ConstBitCast(llvmValue, mem.r.i8ptrType)
- }
llvmValue = llvm.ConstInBoundsGEP(mem.r.mod.Context().Int8Type(), llvmValue, []llvm.Value{
llvm.ConstInt(mem.r.mod.Context().Int32Type(), uint64(v.offset()), false),
})
}
- // If a particular LLVM pointer type is requested, cast to it.
- if !llvmType.IsNil() && llvmType != llvmValue.Type() {
- llvmValue = llvm.ConstBitCast(llvmValue, llvmType)
- }
-
return llvmValue, nil
}
@@ -872,7 +863,7 @@ func (v rawValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Value,
if err != nil {
panic(err)
}
- if checks && mem.r.targetData.TypeAllocSize(llvmType) != mem.r.targetData.TypeAllocSize(mem.r.i8ptrType) {
+ if checks && mem.r.targetData.TypeAllocSize(llvmType) != mem.r.targetData.TypeAllocSize(mem.r.dataPtrType) {
// Probably trying to serialize a pointer to a byte array,
// perhaps as a result of rawLLVMValue() in a previous interp
// run.
@@ -954,8 +945,6 @@ func (v rawValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Value,
// Because go-llvm doesn't have addrspacecast at the moment,
// do it indirectly with a ptrtoint/inttoptr pair.
llvmValue = llvm.ConstIntToPtr(llvm.ConstPtrToInt(llvmValue, mem.r.uintptrType), llvmType)
- } else {
- llvmValue = llvm.ConstBitCast(llvmValue, llvmType)
}
}
return llvmValue, nil
@@ -1256,7 +1245,7 @@ func (r *runner) getValue(llvmValue llvm.Value) value {
// For details on this format, see src/runtime/gc_precise.go.
func (r *runner) readObjectLayout(layoutValue value) (uint64, *big.Int) {
pointerSize := layoutValue.len(r)
- if checks && uint64(pointerSize) != r.targetData.TypeAllocSize(r.i8ptrType) {
+ if checks && uint64(pointerSize) != r.targetData.TypeAllocSize(r.dataPtrType) {
panic("inconsistent pointer size")
}
@@ -1331,12 +1320,12 @@ func (r *runner) getLLVMTypeFromLayout(layoutValue value) llvm.Type {
// Create the LLVM type.
pointerSize := layoutValue.len(r)
- pointerAlignment := r.targetData.PrefTypeAlignment(r.i8ptrType)
+ pointerAlignment := r.targetData.PrefTypeAlignment(r.dataPtrType)
var fields []llvm.Type
for i := 0; i < int(objectSizeWords); {
if bitmap.Bit(i) != 0 {
// Pointer field.
- fields = append(fields, r.i8ptrType)
+ fields = append(fields, r.dataPtrType)
i += int(pointerSize / uint32(pointerAlignment))
} else {
// Byte/word field.