Skip to content

ssa: removes the deadcode on BasicBlock #2231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 5 additions & 31 deletions internal/engine/wazevo/ssa/basic_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,12 @@ type BasicBlock interface {
// ReturnBlock returns ture if this block represents the function return.
ReturnBlock() bool

// FormatHeader returns the debug string of this block, not including instruction.
FormatHeader(b Builder) string

// Valid is true if this block is still valid even after optimizations.
Valid() bool

// Sealed is true if this block has been sealed.
Sealed() bool

// BeginPredIterator returns the first predecessor of this block.
BeginPredIterator() BasicBlock

// NextPredIterator returns the next predecessor of this block.
NextPredIterator() BasicBlock

// Preds returns the number of predecessors of this block.
Preds() int

Expand All @@ -90,10 +81,9 @@ type (
rootInstr, currentInstr *Instruction
// params are Values that represent parameters to a basicBlock.
// Each parameter can be considered as an output of PHI instruction in traditional SSA.
params []Value
predIter int
preds []basicBlockPredecessorInfo
success []*basicBlock
params []Value
preds []basicBlockPredecessorInfo
success []*basicBlock
// singlePred is the alias to preds[0] for fast lookup, and only set after Seal is called.
singlePred *basicBlock
// lastDefinitions maps Variable to its last definition in this block.
Expand Down Expand Up @@ -240,22 +230,6 @@ func (bb *basicBlock) NumPreds() int {
return len(bb.preds)
}

// BeginPredIterator implements BasicBlock.BeginPredIterator.
func (bb *basicBlock) BeginPredIterator() BasicBlock {
bb.predIter = 0
return bb.NextPredIterator()
}

// NextPredIterator implements BasicBlock.NextPredIterator.
func (bb *basicBlock) NextPredIterator() BasicBlock {
if bb.predIter >= len(bb.preds) {
return nil
}
pred := bb.preds[bb.predIter].blk
bb.predIter++
return pred
}

// Preds implements BasicBlock.Preds.
func (bb *basicBlock) Preds() int {
return len(bb.preds)
Expand Down Expand Up @@ -327,8 +301,8 @@ func (bb *basicBlock) addPred(blk BasicBlock, branch *Instruction) {
pred.success = append(pred.success, bb)
}

// FormatHeader implements BasicBlock.FormatHeader.
func (bb *basicBlock) FormatHeader(b Builder) string {
// formatHeader returns the string representation of the header of the basicBlock.
func (bb *basicBlock) formatHeader(b Builder) string {
ps := make([]string, len(bb.params))
for i, p := range bb.params {
ps[i] = p.formatWithType(b)
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/wazevo/ssa/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (b *builder) Format() string {
}
for bb := iterBegin(); bb != nil; bb = iterNext() {
str.WriteByte('\n')
str.WriteString(bb.FormatHeader(b))
str.WriteString(bb.formatHeader(b))
str.WriteByte('\n')

for cur := bb.Root(); cur != nil; cur = cur.Next() {
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/wazevo/ssa/pass_blk_layouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func passLayoutBlocks(b *builder) {
if wazevoapi.SSAValidationEnabled {
for _, trampoline := range trampolines {
if _, ok := b.blkVisited[trampoline]; !ok {
panic("BUG: trampoline block not inserted: " + trampoline.FormatHeader(b))
panic("BUG: trampoline block not inserted: " + trampoline.formatHeader(b))
}
trampoline.validate(b)
}
Expand Down
Loading