From 1f2af7d848c41537bd6acacee1d5b98debb9a895 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Mon, 17 Sep 2018 15:14:04 +0200 Subject: [PATCH] compiler: do not remove dead globals These were not removed when they contain data, and will be removed by LLVM anyway. --- ir.go | 1 - passes.go | 20 +------------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/ir.go b/ir.go index 52ec5326..bb99be90 100644 --- a/ir.go +++ b/ir.go @@ -50,7 +50,6 @@ type Function struct { type Global struct { g *ssa.Global llvmGlobal llvm.Value - flag bool // used by dead code elimination initializer Value } diff --git a/passes.go b/passes.go index cedfce3c..5a1a67af 100644 --- a/passes.go +++ b/passes.go @@ -254,13 +254,10 @@ func (p *Program) AnalyseGoCalls() { // Simple pass that removes dead code. This pass makes later analysis passes // more useful. func (p *Program) SimpleDCE() { - // Unmark all functions and globals. + // Unmark all functions. for _, f := range p.Functions { f.flag = false } - for _, f := range p.Globals { - f.flag = false - } // Initial set of live functions. Include main.main, *.init and runtime.* // functions. @@ -316,10 +313,6 @@ func (p *Program) SimpleDCE() { f.flag = true worklist = append(worklist, operand) } - case *ssa.Global: - // TODO: globals that reference other globals - global := p.GetGlobal(operand) - global.flag = true } } } @@ -336,17 +329,6 @@ func (p *Program) SimpleDCE() { } } p.Functions = livefunctions - - // Remove unmarked globals. - liveglobals := []*Global{} - for _, g := range p.Globals { - if g.flag { - liveglobals = append(liveglobals, g) - } else { - delete(p.globalMap, g.g) - } - } - p.Globals = liveglobals } // Whether this function needs a scheduler.