compiler: move ReplacePanicsWithTrap pass to transforms

This moves the transformation pass to the right location, and adds tests
to see that it actually works correctly.
This commit is contained in:
Ayke van Laethem
2019-11-16 13:07:50 +01:00
committed by Ayke
parent f49e69b02a
commit 172efc26a7
5 changed files with 91 additions and 20 deletions
+1 -20
View File
@@ -20,7 +20,7 @@ func (c *Compiler) Optimize(optLevel, sizeLevel int, inlinerThreshold uint) erro
builder.AddCoroutinePassesToExtensionPoints()
if c.PanicStrategy() == "trap" {
c.replacePanicsWithTrap() // -panic=trap
transform.ReplacePanicsWithTrap(c.mod) // -panic=trap
}
// run a check of all of our code
@@ -147,22 +147,3 @@ func (c *Compiler) Optimize(optLevel, sizeLevel int, inlinerThreshold uint) erro
return nil
}
// Replace panic calls with calls to llvm.trap, to reduce code size. This is the
// -panic=trap intrinsic.
func (c *Compiler) replacePanicsWithTrap() {
trap := c.mod.NamedFunction("llvm.trap")
for _, name := range []string{"runtime._panic", "runtime.runtimePanic"} {
fn := c.mod.NamedFunction(name)
if fn.IsNil() {
continue
}
for _, use := range getUses(fn) {
if use.IsACallInst().IsNil() || use.CalledValue() != fn {
panic("expected use of a panic function to be a call")
}
c.builder.SetInsertPointBefore(use)
c.builder.CreateCall(trap, nil, "")
}
}
}