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 
20 #include "base/macros.h"
21 #include "optimization.h"
22 
23 namespace art HIDDEN {
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,
52                                         OptimizingCompilerStats* stats,
53                                         const char* name = kCFREPassName)
HOptimization(graph,name,stats)54       : HOptimization(graph, name, stats) {}
55 
56   bool Run() override;
57 
58   static constexpr const char* kCFREPassName = "constructor_fence_redundancy_elimination";
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_
67