Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_CONSTRUCTOR_FENCE_REDUNDANCY_ELIMINATION_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_CONSTRUCTOR_FENCE_REDUNDANCY_ELIMINATION_H_ |
| 19 | |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 20 | #include "base/macros.h" |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 21 | #include "optimization.h" |
| 22 | |
Vladimír Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 23 | namespace art HIDDEN { |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * Constructor Fence Redundancy Elimination (CFRE). |
| 27 | * |
| 28 | * A local optimization pass that merges redundant constructor fences |
| 29 | * together within the same basic block. |
| 30 | * |
| 31 | * Abbreviations: |
| 32 | * - CF: Constructor Fence |
| 33 | * - CFS: Constructor Fence Set |
| 34 | * - CFTargets: The unique set of the inputs of all the instructions in CFS. |
| 35 | * |
| 36 | * Given any CFS = { CF(x), CF(y), CF(z), ... }, define CFTargets = { x, y, z, ... }. |
| 37 | * - Publish(R) must not exist for any R in CFTargets if this Publish(R) is between any CF in CFS. |
| 38 | * - This type of Publish(R) is called an "interesting publish". |
| 39 | * |
| 40 | * A Publish(R) is considered any instruction at which the reference to "R" |
| 41 | * may escape (e.g. invoke, store, return, etc) to another thread. |
| 42 | * |
| 43 | * Starting at the beginning of the block: |
| 44 | * - Find the largest contiguous CFS. |
| 45 | * - If we see an interesting publish, merge all instructions in CFS into a single CF(CFTargets). |
| 46 | * - Repeat until the block is fully visited. |
| 47 | * - At the end of the block, merge all instructions in CFS into a single CF(CFTargets). |
| 48 | */ |
| 49 | class ConstructorFenceRedundancyElimination : public HOptimization { |
| 50 | public: |
| 51 | ConstructorFenceRedundancyElimination(HGraph* graph, |
Aart Bik | 2ca10eb | 2017-11-15 15:17:53 -0800 | [diff] [blame] | 52 | OptimizingCompilerStats* stats, |
| 53 | const char* name = kCFREPassName) |
| 54 | : HOptimization(graph, name, stats) {} |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 55 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 56 | bool Run() override; |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 57 | |
Aart Bik | 2ca10eb | 2017-11-15 15:17:53 -0800 | [diff] [blame] | 58 | static constexpr const char* kCFREPassName = "constructor_fence_redundancy_elimination"; |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | DISALLOW_COPY_AND_ASSIGN(ConstructorFenceRedundancyElimination); |
| 62 | }; |
| 63 | |
| 64 | } // namespace art |
| 65 | |
| 66 | #endif // ART_COMPILER_OPTIMIZING_CONSTRUCTOR_FENCE_REDUNDANCY_ELIMINATION_H_ |