blob: e04b98617199c3b8f7862bffd962f9c162411822 [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
Vladimír Marko434d9682022-11-04 14:04:17 +000020#include "base/macros.h"
Igor Murashkindd018df2017-08-09 10:38:31 -070021#include "optimization.h"
22
Vladimír Marko434d9682022-11-04 14:04:17 +000023namespace art HIDDEN {
Igor Murashkindd018df2017-08-09 10:38:31 -070024
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 */
49class ConstructorFenceRedundancyElimination : public HOptimization {
50 public:
51 ConstructorFenceRedundancyElimination(HGraph* graph,
Aart Bik2ca10eb2017-11-15 15:17:53 -080052 OptimizingCompilerStats* stats,
53 const char* name = kCFREPassName)
54 : HOptimization(graph, name, stats) {}
Igor Murashkindd018df2017-08-09 10:38:31 -070055
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010056 bool Run() override;
Igor Murashkindd018df2017-08-09 10:38:31 -070057
Aart Bik2ca10eb2017-11-15 15:17:53 -080058 static constexpr const char* kCFREPassName = "constructor_fence_redundancy_elimination";
Igor Murashkindd018df2017-08-09 10:38:31 -070059
60 private:
61 DISALLOW_COPY_AND_ASSIGN(ConstructorFenceRedundancyElimination);
62};
63
64} // namespace art
65
66#endif // ART_COMPILER_OPTIMIZING_CONSTRUCTOR_FENCE_REDUNDANCY_ELIMINATION_H_