diff options
author | Ayke van Laethem <[email protected]> | 2022-09-20 23:26:49 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2022-10-19 22:23:19 +0200 |
commit | 09ec846c9f3204837ae0695077f6e1359c545fe9 (patch) | |
tree | 127038e48ef68270bc4bafbc16c700328a13d8c0 /compiler | |
parent | f57cffce2d47f7c2b3c9ec1ddd1f077f0830d435 (diff) | |
download | tinygo-09ec846c9f3204837ae0695077f6e1359c545fe9.tar.gz tinygo-09ec846c9f3204837ae0695077f6e1359c545fe9.zip |
all: replace llvm.Const* calls with builder.Create* calls
A number of llvm.Const* functions (in particular extractvalue and
insertvalue) were removed in LLVM 15, so we have to use a builder
instead. This builder will create the same constant values, it simply
uses a different API.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/asserts.go | 2 | ||||
-rw-r--r-- | compiler/compiler.go | 23 | ||||
-rw-r--r-- | compiler/interface.go | 20 | ||||
-rw-r--r-- | compiler/interrupt.go | 8 | ||||
-rw-r--r-- | compiler/llvm.go | 2 |
5 files changed, 33 insertions, 22 deletions
diff --git a/compiler/asserts.go b/compiler/asserts.go index 8d9efdde7..2a5265e93 100644 --- a/compiler/asserts.go +++ b/compiler/asserts.go @@ -145,7 +145,7 @@ func (b *builder) createChanBoundsCheck(elementSize uint64, bufSize llvm.Value, } // Make the maxBufSize actually the maximum allowed value (in number of // elements in the channel buffer). - maxBufSize = llvm.ConstUDiv(maxBufSize, llvm.ConstInt(b.uintptrType, elementSize, false)) + maxBufSize = b.CreateUDiv(maxBufSize, llvm.ConstInt(b.uintptrType, elementSize, false), "") // Make sure maxBufSize has the same type as bufSize. if maxBufSize.Type() != bufSize.Type() { diff --git a/compiler/compiler.go b/compiler/compiler.go index c93b2e563..3d29628cd 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -63,6 +63,7 @@ type compilerContext struct { DumpSSA bool mod llvm.Module ctx llvm.Context + builder llvm.Builder // only used for constant operations dibuilder *llvm.DIBuilder cu llvm.Metadata difiles map[string]llvm.Metadata @@ -98,6 +99,7 @@ func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *C } c.ctx = llvm.NewContext() + c.builder = c.ctx.NewBuilder() c.mod = c.ctx.NewModule(moduleName) c.mod.SetTarget(config.Triple) c.mod.SetDataLayout(c.targetData.String()) @@ -126,6 +128,12 @@ func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *C return c } +// Dispose everything related to the context, _except_ for the IR module (and +// the associated context). +func (c *compilerContext) dispose() { + c.builder.Dispose() +} + // builder contains all information relevant to build a single function. type builder struct { *compilerContext @@ -256,6 +264,7 @@ func Sizes(machine llvm.TargetMachine) types.Sizes { // CompilePackage compiles a single package to a LLVM module. func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package, machine llvm.TargetMachine, config *Config, dumpSSA bool) (llvm.Module, []error) { c := newCompilerContext(moduleName, machine, config, dumpSSA) + defer c.dispose() c.packageDir = pkg.OriginalDir() c.embedGlobals = pkg.EmbedGlobals c.pkg = pkg.Pkg @@ -972,10 +981,10 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu for _, file := range allFiles { fileStruct := llvm.ConstNull(embedFileStructType) name := c.createConst(ssa.NewConst(constant.MakeString(file.Name), types.Typ[types.String])) - fileStruct = llvm.ConstInsertValue(fileStruct, name, []uint32{0}) // "name" field + fileStruct = c.builder.CreateInsertValue(fileStruct, name, 0, "") // "name" field if file.Hash != "" { data := c.getEmbedFileString(file) - fileStruct = llvm.ConstInsertValue(fileStruct, data, []uint32{1}) // "data" field + fileStruct = c.builder.CreateInsertValue(fileStruct, data, 1, "") // "data" field } fileStructs = append(fileStructs, fileStruct) } @@ -1006,7 +1015,7 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu // Define the embed.FS struct. It has only one field: the files (as a // *[]embed.file). globalInitializer := llvm.ConstNull(c.getLLVMType(member.Type().(*types.Pointer).Elem())) - globalInitializer = llvm.ConstInsertValue(globalInitializer, sliceGlobal, []uint32{0}) + globalInitializer = c.builder.CreateInsertValue(globalInitializer, sliceGlobal, 0, "") global.SetInitializer(globalInitializer) global.SetVisibility(llvm.HiddenVisibility) global.SetAlignment(c.targetData.ABITypeAlignment(globalInitializer.Type())) @@ -2757,15 +2766,15 @@ func (c *compilerContext) createConst(expr *ssa.Const) llvm.Value { r := c.createConst(ssa.NewConst(constant.Real(expr.Value), types.Typ[types.Float32])) i := c.createConst(ssa.NewConst(constant.Imag(expr.Value), types.Typ[types.Float32])) cplx := llvm.Undef(c.ctx.StructType([]llvm.Type{c.ctx.FloatType(), c.ctx.FloatType()}, false)) - cplx = llvm.ConstInsertValue(cplx, r, []uint32{0}) - cplx = llvm.ConstInsertValue(cplx, i, []uint32{1}) + cplx = c.builder.CreateInsertValue(cplx, r, 0, "") + cplx = c.builder.CreateInsertValue(cplx, i, 1, "") return cplx } else if typ.Kind() == types.Complex128 { r := c.createConst(ssa.NewConst(constant.Real(expr.Value), types.Typ[types.Float64])) i := c.createConst(ssa.NewConst(constant.Imag(expr.Value), types.Typ[types.Float64])) cplx := llvm.Undef(c.ctx.StructType([]llvm.Type{c.ctx.DoubleType(), c.ctx.DoubleType()}, false)) - cplx = llvm.ConstInsertValue(cplx, r, []uint32{0}) - cplx = llvm.ConstInsertValue(cplx, i, []uint32{1}) + cplx = c.builder.CreateInsertValue(cplx, r, 0, "") + cplx = c.builder.CreateInsertValue(cplx, i, 1, "") return cplx } else { panic("unknown constant of basic type: " + expr.String()) diff --git a/compiler/interface.go b/compiler/interface.go index acb474f5c..106c327a8 100644 --- a/compiler/interface.go +++ b/compiler/interface.go @@ -88,20 +88,20 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value { } globalValue := llvm.ConstNull(global.Type().ElementType()) if !references.IsNil() { - globalValue = llvm.ConstInsertValue(globalValue, references, []uint32{0}) + globalValue = c.builder.CreateInsertValue(globalValue, references, 0, "") } if length != 0 { lengthValue := llvm.ConstInt(c.uintptrType, uint64(length), false) - globalValue = llvm.ConstInsertValue(globalValue, lengthValue, []uint32{1}) + globalValue = c.builder.CreateInsertValue(globalValue, lengthValue, 1, "") } if !methodSet.IsNil() { - globalValue = llvm.ConstInsertValue(globalValue, methodSet, []uint32{2}) + globalValue = c.builder.CreateInsertValue(globalValue, methodSet, 2, "") } if !ptrTo.IsNil() { - globalValue = llvm.ConstInsertValue(globalValue, ptrTo, []uint32{3}) + globalValue = c.builder.CreateInsertValue(globalValue, ptrTo, 3, "") } if !typeAssert.IsNil() { - globalValue = llvm.ConstInsertValue(globalValue, typeAssert, []uint32{4}) + globalValue = c.builder.CreateInsertValue(globalValue, typeAssert, 4, "") } global.SetInitializer(globalValue) global.SetLinkage(llvm.LinkOnceODRLinkage) @@ -121,7 +121,7 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { structGlobalValue := llvm.ConstNull(structGlobalType) for i := 0; i < typ.NumFields(); i++ { fieldGlobalValue := llvm.ConstNull(runtimeStructField) - fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), []uint32{0}) + fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), 0, "") fieldNameType, fieldName := c.makeGlobalArray([]byte(typ.Field(i).Name()), "reflect/types.structFieldName", c.ctx.Int8Type()) fieldName.SetLinkage(llvm.PrivateLinkage) fieldName.SetUnnamedAddr(true) @@ -129,7 +129,7 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { llvm.ConstInt(c.ctx.Int32Type(), 0, false), llvm.ConstInt(c.ctx.Int32Type(), 0, false), }) - fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldName, []uint32{1}) + fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, fieldName, 1, "") if typ.Tag(i) != "" { fieldTagType, fieldTag := c.makeGlobalArray([]byte(typ.Tag(i)), "reflect/types.structFieldTag", c.ctx.Int8Type()) fieldTag.SetLinkage(llvm.PrivateLinkage) @@ -138,13 +138,13 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { llvm.ConstInt(c.ctx.Int32Type(), 0, false), llvm.ConstInt(c.ctx.Int32Type(), 0, false), }) - fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldTag, []uint32{2}) + fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, fieldTag, 2, "") } if typ.Field(i).Embedded() { fieldEmbedded := llvm.ConstInt(c.ctx.Int1Type(), 1, false) - fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldEmbedded, []uint32{3}) + fieldGlobalValue = c.builder.CreateInsertValue(fieldGlobalValue, fieldEmbedded, 3, "") } - structGlobalValue = llvm.ConstInsertValue(structGlobalValue, fieldGlobalValue, []uint32{uint32(i)}) + structGlobalValue = c.builder.CreateInsertValue(structGlobalValue, fieldGlobalValue, i, "") } structGlobal.SetInitializer(structGlobalValue) structGlobal.SetUnnamedAddr(true) diff --git a/compiler/interrupt.go b/compiler/interrupt.go index 45c7d0748..c1f7d69f2 100644 --- a/compiler/interrupt.go +++ b/compiler/interrupt.go @@ -49,9 +49,11 @@ func (b *builder) createInterruptGlobal(instr *ssa.CallCommon) (llvm.Value, erro global.SetGlobalConstant(true) global.SetUnnamedAddr(true) initializer := llvm.ConstNull(globalLLVMType) - initializer = llvm.ConstInsertValue(initializer, funcContext, []uint32{0}) - initializer = llvm.ConstInsertValue(initializer, funcPtr, []uint32{1}) - initializer = llvm.ConstInsertValue(initializer, llvm.ConstInt(b.intType, uint64(id.Int64()), true), []uint32{2, 0}) + initializer = b.CreateInsertValue(initializer, funcContext, 0, "") + initializer = b.CreateInsertValue(initializer, funcPtr, 1, "") + initializer = b.CreateInsertValue(initializer, llvm.ConstNamedStruct(globalLLVMType.StructElementTypes()[2], []llvm.Value{ + llvm.ConstInt(b.intType, uint64(id.Int64()), true), + }), 2, "") global.SetInitializer(initializer) // Add debug info to the interrupt global. diff --git a/compiler/llvm.go b/compiler/llvm.go index 686d4d2b3..8b80869bf 100644 --- a/compiler/llvm.go +++ b/compiler/llvm.go @@ -70,7 +70,7 @@ func (c *compilerContext) makeGlobalArray(buf []byte, name string, elementType l value := llvm.Undef(globalType) for i := 0; i < len(buf); i++ { ch := uint64(buf[i]) - value = llvm.ConstInsertValue(value, llvm.ConstInt(elementType, ch, false), []uint32{uint32(i)}) + value = c.builder.CreateInsertValue(value, llvm.ConstInt(elementType, ch, false), i, "") } global.SetInitializer(value) return globalType, global |