175be28332b278cff9039b54bfb228ac72f539cccRoland Levillain/*
275be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * Copyright (C) 2014 The Android Open Source Project
375be28332b278cff9039b54bfb228ac72f539cccRoland Levillain *
475be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * Licensed under the Apache License, Version 2.0 (the "License");
575be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * you may not use this file except in compliance with the License.
675be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * You may obtain a copy of the License at
775be28332b278cff9039b54bfb228ac72f539cccRoland Levillain *
875be28332b278cff9039b54bfb228ac72f539cccRoland Levillain *      http://www.apache.org/licenses/LICENSE-2.0
975be28332b278cff9039b54bfb228ac72f539cccRoland Levillain *
1075be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * Unless required by applicable law or agreed to in writing, software
1175be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * distributed under the License is distributed on an "AS IS" BASIS,
1275be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1375be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * See the License for the specific language governing permissions and
1475be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * limitations under the License.
1575be28332b278cff9039b54bfb228ac72f539cccRoland Levillain */
1675be28332b278cff9039b54bfb228ac72f539cccRoland Levillain
1775be28332b278cff9039b54bfb228ac72f539cccRoland Levillain#ifndef ART_COMPILER_OPTIMIZING_CONSTANT_FOLDING_H_
1875be28332b278cff9039b54bfb228ac72f539cccRoland Levillain#define ART_COMPILER_OPTIMIZING_CONSTANT_FOLDING_H_
1975be28332b278cff9039b54bfb228ac72f539cccRoland Levillain
2075be28332b278cff9039b54bfb228ac72f539cccRoland Levillain#include "nodes.h"
2175be28332b278cff9039b54bfb228ac72f539cccRoland Levillain#include "optimization.h"
2275be28332b278cff9039b54bfb228ac72f539cccRoland Levillain
2375be28332b278cff9039b54bfb228ac72f539cccRoland Levillainnamespace art {
2475be28332b278cff9039b54bfb228ac72f539cccRoland Levillain
2575be28332b278cff9039b54bfb228ac72f539cccRoland Levillain/**
2675be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * Optimization pass performing a simple constant-expression
2775be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * evaluation on the SSA form.
2875be28332b278cff9039b54bfb228ac72f539cccRoland Levillain *
291252e976b972231a84b36e4bb73cf513bb7799d1Roland Levillain * Note that graph simplifications producing a constant should be
301252e976b972231a84b36e4bb73cf513bb7799d1Roland Levillain * implemented in art::HConstantFolding, while graph simplifications
311252e976b972231a84b36e4bb73cf513bb7799d1Roland Levillain * not producing constants should be implemented in
321252e976b972231a84b36e4bb73cf513bb7799d1Roland Levillain * art::InstructionSimplifier.  (This convention is a choice that was
331252e976b972231a84b36e4bb73cf513bb7799d1Roland Levillain * made during the development of these parts of the compiler and is
341252e976b972231a84b36e4bb73cf513bb7799d1Roland Levillain * not bound by any technical requirement.)
351252e976b972231a84b36e4bb73cf513bb7799d1Roland Levillain *
3675be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * This class is named art::HConstantFolding to avoid name
3775be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * clashes with the art::ConstantPropagation class defined in
3875be28332b278cff9039b54bfb228ac72f539cccRoland Levillain * compiler/dex/post_opt_passes.h.
3975be28332b278cff9039b54bfb228ac72f539cccRoland Levillain */
4075be28332b278cff9039b54bfb228ac72f539cccRoland Levillainclass HConstantFolding : public HOptimization {
4175be28332b278cff9039b54bfb228ac72f539cccRoland Levillain public:
4238e9e8046ea2196284bdb4638771c31108a30a4aJean-Philippe Halimi  HConstantFolding(HGraph* graph, const char* name = kConstantFoldingPassName)
43e34648dec914453f7e8b6c517dd272823319cd6dNicolas Geoffray      : HOptimization(graph, name) {}
4475be28332b278cff9039b54bfb228ac72f539cccRoland Levillain
455e6916cea259897baaca019c5c7a5d05746306edNicolas Geoffray  void Run() OVERRIDE;
4675be28332b278cff9039b54bfb228ac72f539cccRoland Levillain
4775be28332b278cff9039b54bfb228ac72f539cccRoland Levillain  static constexpr const char* kConstantFoldingPassName = "constant_folding";
4875be28332b278cff9039b54bfb228ac72f539cccRoland Levillain
4975be28332b278cff9039b54bfb228ac72f539cccRoland Levillain private:
5075be28332b278cff9039b54bfb228ac72f539cccRoland Levillain  DISALLOW_COPY_AND_ASSIGN(HConstantFolding);
5175be28332b278cff9039b54bfb228ac72f539cccRoland Levillain};
5275be28332b278cff9039b54bfb228ac72f539cccRoland Levillain
5375be28332b278cff9039b54bfb228ac72f539cccRoland Levillain}  // namespace art
5475be28332b278cff9039b54bfb228ac72f539cccRoland Levillain
5575be28332b278cff9039b54bfb228ac72f539cccRoland Levillain#endif  // ART_COMPILER_OPTIMIZING_CONSTANT_FOLDING_H_
56