Home | History | Annotate | Download | only in optimizing
      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 "optimization.h"
     21 
     22 namespace 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  */
     48 class ConstructorFenceRedundancyElimination : public HOptimization {
     49  public:
     50   ConstructorFenceRedundancyElimination(HGraph* graph,
     51                                         OptimizingCompilerStats* stats,
     52                                         const char* name = kCFREPassName)
     53       : HOptimization(graph, name, stats) {}
     54 
     55   void Run() OVERRIDE;
     56 
     57   static constexpr const char* kCFREPassName = "constructor_fence_redundancy_elimination";
     58 
     59  private:
     60   DISALLOW_COPY_AND_ASSIGN(ConstructorFenceRedundancyElimination);
     61 };
     62 
     63 }  // namespace art
     64 
     65 #endif  // ART_COMPILER_OPTIMIZING_CONSTRUCTOR_FENCE_REDUNDANCY_ELIMINATION_H_
     66