internal/cabi: transformFuncBody check AttrWidthType(2)
This commit is contained in:
@@ -369,12 +369,13 @@ func (p *Transformer) transformFuncBody(m llvm.Module, ctx llvm.Context, info *F
|
|||||||
// store %typ %1, ptr %2, align 4
|
// store %typ %1, ptr %2, align 4
|
||||||
nv = b.CreateLoad(ti.Type, params[index], "")
|
nv = b.CreateLoad(ti.Type, params[index], "")
|
||||||
// replace %0 to %2
|
// replace %0 to %2
|
||||||
replaceParamAlloc(fn.Param(i), params[index])
|
replaceAllocaInstrs(fn.Param(i), params[index])
|
||||||
case AttrWidthType:
|
case AttrWidthType:
|
||||||
iptr := llvm.CreateAlloca(b, ti.Type1)
|
iptr := llvm.CreateAlloca(b, ti.Type1)
|
||||||
b.CreateStore(params[index], iptr)
|
b.CreateStore(params[index], iptr)
|
||||||
ptr := b.CreateBitCast(iptr, llvm.PointerType(ti.Type, 0), "")
|
ptr := b.CreateBitCast(iptr, llvm.PointerType(ti.Type, 0), "")
|
||||||
nv = b.CreateLoad(ti.Type, ptr, "")
|
nv = b.CreateLoad(ti.Type, ptr, "")
|
||||||
|
replaceAllocaInstrs(fn.Param(i), ptr)
|
||||||
case AttrWidthType2:
|
case AttrWidthType2:
|
||||||
typ := llvm.StructType([]llvm.Type{ti.Type1, ti.Type2}, false)
|
typ := llvm.StructType([]llvm.Type{ti.Type1, ti.Type2}, false)
|
||||||
iptr := llvm.CreateAlloca(b, typ)
|
iptr := llvm.CreateAlloca(b, typ)
|
||||||
@@ -383,6 +384,7 @@ func (p *Transformer) transformFuncBody(m llvm.Module, ctx llvm.Context, info *F
|
|||||||
b.CreateStore(params[index], b.CreateStructGEP(typ, iptr, 1, ""))
|
b.CreateStore(params[index], b.CreateStructGEP(typ, iptr, 1, ""))
|
||||||
ptr := b.CreateBitCast(iptr, llvm.PointerType(ti.Type, 0), "")
|
ptr := b.CreateBitCast(iptr, llvm.PointerType(ti.Type, 0), "")
|
||||||
nv = b.CreateLoad(ti.Type, ptr, "")
|
nv = b.CreateLoad(ti.Type, ptr, "")
|
||||||
|
replaceAllocaInstrs(fn.Param(i), ptr)
|
||||||
case AttrExtract:
|
case AttrExtract:
|
||||||
nsubs := ti.Type.StructElementTypesCount()
|
nsubs := ti.Type.StructElementTypesCount()
|
||||||
nv = llvm.Undef(ti.Type)
|
nv = llvm.Undef(ti.Type)
|
||||||
@@ -431,10 +433,15 @@ func (p *Transformer) transformFuncBody(m llvm.Module, ctx llvm.Context, info *F
|
|||||||
}
|
}
|
||||||
rv = b.CreateRetVoid()
|
rv = b.CreateRetVoid()
|
||||||
case AttrWidthType, AttrWidthType2:
|
case AttrWidthType, AttrWidthType2:
|
||||||
ptr := llvm.CreateAlloca(b, info.Return.Type)
|
if load := ret.IsALoadInst(); !load.IsNil() {
|
||||||
b.CreateStore(ret, ptr)
|
iptr := b.CreateBitCast(ret.Operand(0), llvm.PointerType(nft.ReturnType(), 0), "")
|
||||||
iptr := b.CreateBitCast(ptr, llvm.PointerType(nft.ReturnType(), 0), "")
|
rv = b.CreateRet(b.CreateLoad(nft.ReturnType(), iptr, ""))
|
||||||
rv = b.CreateRet(b.CreateLoad(nft.ReturnType(), iptr, ""))
|
} else {
|
||||||
|
ptr := llvm.CreateAlloca(b, info.Return.Type)
|
||||||
|
b.CreateStore(ret, ptr)
|
||||||
|
iptr := b.CreateBitCast(ptr, llvm.PointerType(nft.ReturnType(), 0), "")
|
||||||
|
rv = b.CreateRet(b.CreateLoad(nft.ReturnType(), iptr, ""))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
instr.ReplaceAllUsesWith(rv)
|
instr.ReplaceAllUsesWith(rv)
|
||||||
instr.EraseFromParentAsInstruction()
|
instr.EraseFromParentAsInstruction()
|
||||||
@@ -679,7 +686,7 @@ func (p *Transformer) getMemcpy(m llvm.Module, ctx llvm.Context) llvm.Value {
|
|||||||
return memcpy
|
return memcpy
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceParamAlloc(param llvm.Value, nv llvm.Value) {
|
func replaceAllocaInstrs(param llvm.Value, nv llvm.Value) {
|
||||||
u := param.FirstUse()
|
u := param.FirstUse()
|
||||||
var storeInstrs []llvm.Value
|
var storeInstrs []llvm.Value
|
||||||
for !u.IsNil() {
|
for !u.IsNil() {
|
||||||
|
|||||||
Reference in New Issue
Block a user