phisExpr as an AggregateVal
This commit is contained in:
@@ -517,7 +517,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
|
|||||||
val := p.compileValue(b, v.Value)
|
val := p.compileValue(b, v.Value)
|
||||||
b.MapUpdate(m, key, val)
|
b.MapUpdate(m, key, val)
|
||||||
case *ssa.Panic:
|
case *ssa.Panic:
|
||||||
arg := p.compileValue(b, v.X).Do()
|
arg := p.compileValue(b, v.X).Do(b)
|
||||||
b.Panic(arg)
|
b.Panic(arg)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("compileInstr: unknown instr - %T\n", instr))
|
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
|
n := len(vals) - hasVArg
|
||||||
ret := make([]llssa.Expr, n)
|
ret := make([]llssa.Expr, n)
|
||||||
for i := 0; i < n; i++ {
|
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 {
|
if hasVArg > 0 {
|
||||||
ret = p.compileVArg(ret, b, vals[n])
|
ret = p.compileVArg(ret, b, vals[n])
|
||||||
|
|||||||
16
ssa/expr.go
16
ssa/expr.go
@@ -49,12 +49,13 @@ func (v Expr) TypeOf() types.Type {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Do evaluates the delay expression and returns the result.
|
// 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 {
|
switch vt := v.Type; vt.kind {
|
||||||
case vkDelayExpr:
|
case vkDelayExpr:
|
||||||
return vt.t.(delayExprTy)()
|
return vt.t.(delayExprTy)()
|
||||||
case vkPhisExpr:
|
case vkPhisExpr:
|
||||||
panic("unreachable")
|
e := vt.t.(*phisExprTy)
|
||||||
|
return Expr{b.impl.CreateAggregateRet(e.phis), e.Type}
|
||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
@@ -80,6 +81,7 @@ func (p delayExprTy) String() string {
|
|||||||
|
|
||||||
type phisExprTy struct {
|
type phisExprTy struct {
|
||||||
phis []llvm.Value
|
phis []llvm.Value
|
||||||
|
Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p phisExprTy) Underlying() types.Type {
|
func (p phisExprTy) Underlying() types.Type {
|
||||||
@@ -90,8 +92,8 @@ func (p phisExprTy) String() string {
|
|||||||
return "phisExpr"
|
return "phisExpr"
|
||||||
}
|
}
|
||||||
|
|
||||||
func phisExpr(phis []llvm.Value) Expr {
|
func phisExpr(t Type, phis []llvm.Value) Expr {
|
||||||
return Expr{Type: &aType{t: &phisExprTy{phis}, kind: vkPhisExpr}}
|
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)
|
p.impl.AddIncoming(vs, bs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
phis := p.t.(*phisExprTy).phis
|
e := p.t.(*phisExprTy)
|
||||||
for i, phi := range phis {
|
for i, phi := range e.phis {
|
||||||
flds := fieldValues(b.impl, vals, i)
|
flds := fieldValues(b.impl, vals, i)
|
||||||
phi.AddIncoming(flds, bs)
|
phi.AddIncoming(flds, bs)
|
||||||
}
|
}
|
||||||
@@ -408,7 +410,7 @@ func (b Builder) Phi(t Type) Phi {
|
|||||||
phis := make([]llvm.Value, 2)
|
phis := make([]llvm.Value, 2)
|
||||||
phis[0] = llvm.CreatePHI(impl, prog.tyVoidPtr())
|
phis[0] = llvm.CreatePHI(impl, prog.tyVoidPtr())
|
||||||
phis[1] = llvm.CreatePHI(impl, prog.tyInt())
|
phis[1] = llvm.CreatePHI(impl, prog.tyInt())
|
||||||
return Phi{phisExpr(phis)}
|
return Phi{phisExpr(t, phis)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
phi := llvm.CreatePHI(impl, t.ll)
|
phi := llvm.CreatePHI(impl, t.ll)
|
||||||
|
|||||||
Reference in New Issue
Block a user