runtime: StringCat; llgo/ssa: aggregateValue

This commit is contained in:
xushiwei
2024-05-02 12:39:25 +08:00
parent 75d513a78a
commit 9cf122c31a
4 changed files with 71 additions and 89 deletions

View File

@@ -55,8 +55,7 @@ func (v Expr) Do(b Builder) Expr {
return vt.t.(delayExprTy)()
case vkPhisExpr:
e := vt.t.(*phisExprTy)
// TODO(xsw): to check CreateAggregateRet is correct or not
return Expr{b.impl.CreateAggregateRet(e.phis), e.Type}
return b.aggregateValue(e.Type, e.phis...)
}
return v
}
@@ -460,6 +459,20 @@ func (b Builder) Store(ptr, val Expr) Builder {
return b
}
// aggregateValue yields the value of the aggregate X with the fields
func (b Builder) aggregateValue(t Type, flds ...llvm.Value) Expr {
if debugInstr {
log.Printf("AggregateValue %v, %v\n", t, flds)
}
impl := b.impl
tll := t.ll
ptr := llvm.CreateAlloca(impl, tll)
for i, fld := range flds {
impl.CreateStore(fld, llvm.CreateStructGEP(impl, tll, ptr, i))
}
return Expr{llvm.CreateLoad(b.impl, tll, ptr), t}
}
// The FieldAddr instruction yields the address of Field of *struct X.
//
// The field is identified by its index within the field list of the