mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 22:13:39 +00:00
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.
This commit is contained in:
+5
-6
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+4
-15
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user