From fbb1f89ab33d8e9b903d6f0b5bfee24d5f7243cf Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 2 May 2024 07:56:52 +0800 Subject: [PATCH] phisExpr as an AggregateVal --- cl/compile.go | 4 ++-- ssa/expr.go | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cl/compile.go b/cl/compile.go index c8b4ded9..8f67a0cb 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -517,7 +517,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) { val := p.compileValue(b, v.Value) b.MapUpdate(m, key, val) case *ssa.Panic: - arg := p.compileValue(b, v.X).Do() + arg := p.compileValue(b, v.X).Do(b) b.Panic(arg) default: panic(fmt.Sprintf("compileInstr: unknown instr - %T\n", instr)) @@ -574,7 +574,7 @@ func (p *context) compileValues(b llssa.Builder, vals []ssa.Value, hasVArg int) n := len(vals) - hasVArg ret := make([]llssa.Expr, n) for i := 0; i < n; i++ { - ret[i] = p.compileValue(b, vals[i]).Do() + ret[i] = p.compileValue(b, vals[i]).Do(b) } if hasVArg > 0 { ret = p.compileVArg(ret, b, vals[n]) diff --git a/ssa/expr.go b/ssa/expr.go index ef607af1..495259fc 100644 --- a/ssa/expr.go +++ b/ssa/expr.go @@ -49,12 +49,13 @@ func (v Expr) TypeOf() types.Type { */ // Do evaluates the delay expression and returns the result. -func (v Expr) Do() Expr { +func (v Expr) Do(b Builder) Expr { switch vt := v.Type; vt.kind { case vkDelayExpr: return vt.t.(delayExprTy)() case vkPhisExpr: - panic("unreachable") + e := vt.t.(*phisExprTy) + return Expr{b.impl.CreateAggregateRet(e.phis), e.Type} } return v } @@ -80,6 +81,7 @@ func (p delayExprTy) String() string { type phisExprTy struct { phis []llvm.Value + Type } func (p phisExprTy) Underlying() types.Type { @@ -90,8 +92,8 @@ func (p phisExprTy) String() string { return "phisExpr" } -func phisExpr(phis []llvm.Value) Expr { - return Expr{Type: &aType{t: &phisExprTy{phis}, kind: vkPhisExpr}} +func phisExpr(t Type, phis []llvm.Value) Expr { + return Expr{Type: &aType{t: &phisExprTy{phis, t}, kind: vkPhisExpr}} } // ----------------------------------------------------------------------------- @@ -389,8 +391,8 @@ func (p Phi) AddIncoming(b Builder, vals []Expr, bblks []BasicBlock) { p.impl.AddIncoming(vs, bs) return } - phis := p.t.(*phisExprTy).phis - for i, phi := range phis { + e := p.t.(*phisExprTy) + for i, phi := range e.phis { flds := fieldValues(b.impl, vals, i) phi.AddIncoming(flds, bs) } @@ -408,7 +410,7 @@ func (b Builder) Phi(t Type) Phi { phis := make([]llvm.Value, 2) phis[0] = llvm.CreatePHI(impl, prog.tyVoidPtr()) phis[1] = llvm.CreatePHI(impl, prog.tyInt()) - return Phi{phisExpr(phis)} + return Phi{phisExpr(t, phis)} } } phi := llvm.CreatePHI(impl, t.ll)