From cdfa0166bd4bea0e760b83dd6708bfcee18c6360 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sat, 3 Aug 2024 20:51:43 +0800 Subject: [PATCH] ssa: make block with label name for debug readable --- cl/compile.go | 2 +- ssa/decl.go | 12 +++++++----- ssa/eh.go | 4 ++-- ssa/stmt_builder.go | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cl/compile.go b/cl/compile.go index cd3acbfd..cadc8a8d 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -318,7 +318,7 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do modPtr := pkg.PyNewModVar(modName, true).Expr mod := b.Load(modPtr) cond := b.BinOp(token.NEQ, mod, prog.Nil(mod.Type)) - newBlk := fn.MakeBlock() + newBlk := fn.MakeBlock("") b.If(cond, jumpTo, newBlk) b.SetBlockEx(newBlk, llssa.AtEnd, false) b.Store(modPtr, b.PyImportMod(modPath)) diff --git a/ssa/decl.go b/ssa/decl.go index 89128409..6bdde0fd 100644 --- a/ssa/decl.go +++ b/ssa/decl.go @@ -293,13 +293,15 @@ func (p Function) MakeBlocks(nblk int) []BasicBlock { p.blks = make([]BasicBlock, 0, nblk) } for i := 0; i < nblk; i++ { - p.addBlock(n + i) + p.addBlock(n+i, "") } return p.blks[n:] } -func (p Function) addBlock(idx int) BasicBlock { - label := "_llgo_" + strconv.Itoa(idx) +func (p Function) addBlock(idx int, label string) BasicBlock { + if label == "" { + label = "_llgo_" + strconv.Itoa(idx) + } blk := llvm.AddBasicBlock(p.impl, label) ret := &aBasicBlock{blk, blk, p, idx} p.blks = append(p.blks, ret) @@ -307,8 +309,8 @@ func (p Function) addBlock(idx int) BasicBlock { } // MakeBlock creates a new basic block for the function. -func (p Function) MakeBlock() BasicBlock { - return p.addBlock(len(p.blks)) +func (p Function) MakeBlock(label string) BasicBlock { + return p.addBlock(len(p.blks), label) } // Block returns the ith basic block of the function. diff --git a/ssa/eh.go b/ssa/eh.go index dfbfcb89..4aff254c 100644 --- a/ssa/eh.go +++ b/ssa/eh.go @@ -162,7 +162,7 @@ func (b Builder) getDefer(kind DoAction) *aDefer { czero := prog.IntVal(0, prog.CInt()) retval := b.Sigsetjmp(jb, czero) if kind != DeferAlways { - rundBlk = self.MakeBlock() + rundBlk = self.MakeBlock("") } else { blks = self.MakeBlocks(2) next, rundBlk = blks[0], blks[1] @@ -228,7 +228,7 @@ func (b Builder) Defer(kind DoAction, fn Expr, args ...Expr) { // RunDefers emits instructions to run deferred instructions. func (b Builder) RunDefers() { self := b.getDefer(DeferInCond) - blk := b.Func.MakeBlock() + blk := b.Func.MakeBlock("") self.runsNext = append(self.runsNext, blk) b.Store(self.rundPtr, blk.Addr()) diff --git a/ssa/stmt_builder.go b/ssa/stmt_builder.go index f837c3fd..15546ccc 100644 --- a/ssa/stmt_builder.go +++ b/ssa/stmt_builder.go @@ -94,7 +94,7 @@ func (b Builder) setBlockMoveLast(blk BasicBlock) (next BasicBlock) { impl := b.impl - next = b.Func.MakeBlock() + next = b.Func.MakeBlock("") impl.SetInsertPointAtEnd(next.last) impl.Insert(last)