summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2019-08-11 11:19:39 +0800
committerJohn Hodge <tpg@ucc.asn.au>2019-08-11 11:19:39 +0800
commitfdc99699ea2ba7d27270b89619695c389dd6b2b1 (patch)
tree1a93d2a57d387b14068a3487cbce3a6c83d930a8
parente4d2fa3a40bd804da8caa01e731489ce8eea5a64 (diff)
downloadmrust-fdc99699ea2ba7d27270b89619695c389dd6b2b1.tar.gz
Notes - Some newer optimisation ideas/notes
-rw-r--r--Notes/MIR-Optimisations.md36
1 files changed, 29 insertions, 7 deletions
diff --git a/Notes/MIR-Optimisations.md b/Notes/MIR-Optimisations.md
index d20828ed..baa737eb 100644
--- a/Notes/MIR-Optimisations.md
+++ b/Notes/MIR-Optimisations.md
@@ -206,11 +206,33 @@ Purpose: Remove borrows generated by method calls that have been inlined
Overview
--------
-- Detect potential replacements:
- - Find borrows of locals
- - If destination of borrow is used directly (not via a deref), skip
- - If the destination is re-assigned, skip
- - Note, this should be able to tell if the re-assignment would be able to
- invalidate the previous statements
-- Replace all dereference usages of the destination with the original.
+- Find locals that are only assigned once, and only ever used via a deref
+ operation.
+ - Allow drops to use the destination by value
+- If the assignment was a Borrow RValue, continue
+- Iterate forward, replacing usage of the value with the original source while:
+ - The source isn't invalidated
+ - The number of replacements is less than the number of known usage sites
+- If the original borrow itself contained a deref of a local, update that
+ local's usage count.
+- If all usage sites were updated, erase the original borrow
+
+
+Borrow Elimination 2
+====================
+Purpose: Remove borrows of borrows that are never used again
+Overview
+--------
+- Find assign-once/use-once locals (ignoring drop)
+- If the source is a borrow of a deref of a local/argument, continue
+- If the source inner value is of the same type as the local, continue
+ - I.e. we're not re-borrowing a `&mut` as `&`
+- If the variable's type is not `&` (i.e. it's &mut or &uniq)
+ - Check the usage count for the source value, and only continue is this is
+ the only usage site of the source
+ - Ideally: This would only check forwards, but that's hard
+- If the variable's type is `&`, check the path between assignment and usage
+ for invalidation.
+- If no invalidation found, replace usage with inner of assignment and erase
+ assignment.