summaryrefslogtreecommitdiff
path: root/compiler/optimizing/dead_code_elimination.h
diff options
context:
space:
mode:
author Santiago Aboy Solanes <solanes@google.com> 2022-11-10 10:26:31 +0000
committer Santiago Aboy Solanes <solanes@google.com> 2022-11-23 10:44:45 +0000
commitb2d364d0eee1d6df4b49e3a7d5b3c4c11af3b3ca (patch)
tree710badc4b3252213bd2d19f0fcca09f20ba01e2a /compiler/optimizing/dead_code_elimination.h
parent316fe63e68a83db41540650101e0597b36853529 (diff)
Remove tries which don't contain throwing instructions
If nothing can throw within a TryBoundary, we are safe to eliminate it. We were already doing this at the builder stage, but this CL takes care of subsequent passes (e.g. we might remove DivZeroCheck instructions which means that now we know we can't throw). Sometimes this means we are able to eliminate catch blocks which brings some code size improvements. Locally on a Pixel 5 compiling with `speed`: * AGSA -684K (0.2%) * services.jar -100K (0.2%) * SystemUIGoogle -88K (0.3%) Bug: 229249867 Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Change-Id: I36d5880be99c1f1109c94266b1be583de8d6cf72
Diffstat (limited to 'compiler/optimizing/dead_code_elimination.h')
-rw-r--r--compiler/optimizing/dead_code_elimination.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/compiler/optimizing/dead_code_elimination.h b/compiler/optimizing/dead_code_elimination.h
index a3e993c1d7..873e13f244 100644
--- a/compiler/optimizing/dead_code_elimination.h
+++ b/compiler/optimizing/dead_code_elimination.h
@@ -46,6 +46,26 @@ class HDeadCodeElimination : public HOptimization {
bool SimplifyIfs();
void ConnectSuccessiveBlocks();
+ // Helper struct to eliminate tries.
+ struct TryBelongingInformation;
+ // Disconnects `block`'s handlers and update its `TryBoundary` instruction to a `Goto`.
+ // Sets `any_handler_in_loop` to true if any handler is currently a loop to later update the loop
+ // information if needed.
+ void DisconnectHandlersAndUpdateTryBoundary(HBasicBlock* block,
+ /* out */ bool* any_handler_in_loop);
+ // Returns true iff the try doesn't contain throwing instructions.
+ bool CanPerformTryRemoval(const TryBelongingInformation& try_belonging_info);
+ // Removes the try by disconnecting all try entries and exits from their handlers. Also updates
+ // the graph in the case that a `TryBoundary` instruction of kind `exit` has the Exit block as
+ // its successor.
+ void RemoveTry(HBasicBlock* try_entry,
+ const TryBelongingInformation& try_belonging_info,
+ bool* any_catch_in_loop);
+ // Checks which tries (if any) are currently in the graph, coalesces the different try entries
+ // that are referencing the same try, and removes the tries which don't contain any throwing
+ // instructions.
+ bool RemoveUnneededTries();
+
DISALLOW_COPY_AND_ASSIGN(HDeadCodeElimination);
};