mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 13:33:39 +00:00
compiler: move OptimizeStringToBytes to transform package
Unfortunately, while doing this I found that it doesn't actually apply in any real-world programs (tested with `make smoketest`), apparently because nil pointer checking messes with the functionattrs pass. I hope to fix that after moving to LLVM 9, which has an optimization that makes nil pointer checking easier to implement.
This commit is contained in:
committed by
Ron Evans
parent
cea0d9f864
commit
65beddafe8
@@ -32,3 +32,24 @@ func hasFlag(call, param llvm.Value, kind string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// isReadOnly returns true if the given value (which must be of pointer type) is
|
||||
// never stored to, and false if this cannot be proven.
|
||||
func isReadOnly(value llvm.Value) bool {
|
||||
uses := getUses(value)
|
||||
for _, use := range uses {
|
||||
if !use.IsAGetElementPtrInst().IsNil() {
|
||||
if !isReadOnly(use) {
|
||||
return false
|
||||
}
|
||||
} else if !use.IsACallInst().IsNil() {
|
||||
if !hasFlag(use, value, "readonly") {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
// Unknown instruction, might not be readonly.
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user