compiler: add the //go:noinline pragma

This is directly useful to avoid some unsafety around runtime.alloc and
should be useful in general.

This pragma has the same form as in the main Go compiler:
https://github.com/golang/go/issues/12312
This commit is contained in:
Ayke van Laethem
2019-07-07 15:51:52 +02:00
committed by Ron Evans
parent c66d979ba3
commit 7ed6b45149
3 changed files with 11 additions and 0 deletions
+4
View File
@@ -865,6 +865,10 @@ func (c *Compiler) parseFunc(frame *Frame) {
// Add LLVM inline hint to functions with //go:inline pragma.
inline := c.ctx.CreateEnumAttribute(llvm.AttributeKindID("inlinehint"), 0)
frame.fn.LLVMFn.AddFunctionAttr(inline)
case ir.InlineNone:
// Add LLVM attribute to always avoid inlining this function.
noinline := c.ctx.CreateEnumAttribute(llvm.AttributeKindID("noinline"), 0)
frame.fn.LLVMFn.AddFunctionAttr(noinline)
}
// Add debug info, if needed.