blob: 367d9f21a0a6c243555163cef623984a91176b3a [file] [log] [blame]
Igor Murashkindd018df2017-08-09 10:38:31 -07001/*
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 "optimization.h"
21
22namespace art {
23
24/*
25 * Constructor Fence Redundancy Elimination (CFRE).
26 *
27 * A local optimization pass that merges redundant constructor fences
28 * together within the same basic block.
29 *
30 * Abbreviations:
31 * - CF: Constructor Fence
32 * - CFS: Constructor Fence Set
33 * - CFTargets: The unique set of the inputs of all the instructions in CFS.
34 *
35 * Given any CFS = { CF(x), CF(y), CF(z), ... }, define CFTargets = { x, y, z, ... }.
36 * - Publish(R) must not exist for any R in CFTargets if this Publish(R) is between any CF in CFS.
37 * - This type of Publish(R) is called an "interesting publish".
38 *
39 * A Publish(R) is considered any instruction at which the reference to "R"
40 * may escape (e.g. invoke, store, return, etc) to another thread.
41 *
42 * Starting at the beginning of the block:
43 * - Find the largest contiguous CFS.
44 * - If we see an interesting publish, merge all instructions in CFS into a single CF(CFTargets).
45 * - Repeat until the block is fully visited.
46 * - At the end of the block, merge all instructions in CFS into a single CF(CFTargets).
47 */
48class ConstructorFenceRedundancyElimination : public HOptimization {
49 public:
50 ConstructorFenceRedundancyElimination(HGraph* graph,
Aart Bik2ca10eb2017-11-15 15:17:53 -080051 OptimizingCompilerStats* stats,
52 const char* name = kCFREPassName)
53 : HOptimization(graph, name, stats) {}
Igor Murashkindd018df2017-08-09 10:38:31 -070054
Aart Bik24773202018-04-26 10:28:51 -070055 bool Run() OVERRIDE;
Igor Murashkindd018df2017-08-09 10:38:31 -070056
Aart Bik2ca10eb2017-11-15 15:17:53 -080057 static constexpr const char* kCFREPassName = "constructor_fence_redundancy_elimination";
Igor Murashkindd018df2017-08-09 10:38:31 -070058
59 private:
60 DISALLOW_COPY_AND_ASSIGN(ConstructorFenceRedundancyElimination);
61};
62
63} // namespace art
64
65#endif // ART_COMPILER_OPTIMIZING_CONSTRUCTOR_FENCE_REDUNDANCY_ELIMINATION_H_