Home | History | Annotate | Download | only in optimizing
      1 /*
      2  * Copyright (C) 2014 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_OPTIMIZATION_H_
     18 #define ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_
     19 
     20 #include "base/arena_object.h"
     21 #include "nodes.h"
     22 #include "optimizing_compiler_stats.h"
     23 
     24 namespace art {
     25 
     26 /**
     27  * Abstraction to implement an optimization pass.
     28  */
     29 class HOptimization : public ArenaObject<kArenaAllocOptimization> {
     30  public:
     31   HOptimization(HGraph* graph,
     32                 const char* pass_name,
     33                 OptimizingCompilerStats* stats = nullptr)
     34       : graph_(graph),
     35         stats_(stats),
     36         pass_name_(pass_name) {}
     37 
     38   virtual ~HOptimization() {}
     39 
     40   // Return the name of the pass. Pass names for a single HOptimization should be of form
     41   // <optimization_name> or <optimization_name>$<pass_name> for common <optimization_name> prefix.
     42   // Example: 'instruction_simplifier', 'instruction_simplifier$after_bce',
     43   // 'instruction_simplifier$before_codegen'.
     44   const char* GetPassName() const { return pass_name_; }
     45 
     46   // Perform the analysis itself.
     47   virtual void Run() = 0;
     48 
     49  protected:
     50   void MaybeRecordStat(MethodCompilationStat compilation_stat, size_t count = 1) const;
     51 
     52   HGraph* const graph_;
     53   // Used to record stats about the optimization.
     54   OptimizingCompilerStats* const stats_;
     55 
     56  private:
     57   // Optimization pass name.
     58   const char* pass_name_;
     59 
     60   DISALLOW_COPY_AND_ASSIGN(HOptimization);
     61 };
     62 
     63 }  // namespace art
     64 
     65 #endif  // ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_
     66