Browse Source
compiler: do not remove dead globals
These were not removed when they contain data, and will be removed by
LLVM anyway.
pull/13/head
Ayke van Laethem
6 years ago
No known key found for this signature in database
GPG Key ID: E97FF5335DFDFDED
2 changed files with
1 additions and
20 deletions
-
ir.go
-
passes.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 |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -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.
|
|
|
|