mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 10:43:29 +00:00
Optimize/eliminate bounds checking
TODO: do better at it by tracking min/max values of integers. The
following straightforward code doesn't have its bounds checks removed:
for _, n := range slice {
println(n)
}
This commit is contained in:
@@ -35,8 +35,9 @@ type Program struct {
|
||||
type Function struct {
|
||||
fn *ssa.Function
|
||||
llvmFn llvm.Value
|
||||
linkName string
|
||||
blocking bool
|
||||
linkName string // go:linkname pragma
|
||||
nobounds bool // go:nobounds pragma
|
||||
blocking bool // calculated by AnalyseBlockingRecursive
|
||||
flag bool // used by dead code elimination
|
||||
addressTaken bool // used as function pointer, calculated by AnalyseFunctionPointers
|
||||
parents []*Function // calculated by AnalyseCallgraph
|
||||
@@ -169,6 +170,14 @@ func (f *Function) parsePragmas() {
|
||||
if hasUnsafeImport(f.fn.Pkg.Pkg) {
|
||||
f.linkName = parts[2]
|
||||
}
|
||||
case "//go:nobounds":
|
||||
// Skip bounds checking in this function. Useful for some
|
||||
// runtime functions.
|
||||
// This is somewhat dangerous and thus only imported in packages
|
||||
// that import unsafe.
|
||||
if hasUnsafeImport(f.fn.Pkg.Pkg) {
|
||||
f.nobounds = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user