126a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray/*
226a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project
326a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray *
426a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
526a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * you may not use this file except in compliance with the License.
626a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * You may obtain a copy of the License at
726a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray *
826a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
926a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray *
1026a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
1126a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
1226a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1326a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * See the License for the specific language governing permissions and
1426a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * limitations under the License.
1526a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray */
1626a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
1726a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray#ifndef ART_COMPILER_OPTIMIZING_PREPARE_FOR_REGISTER_ALLOCATION_H_
1826a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray#define ART_COMPILER_OPTIMIZING_PREPARE_FOR_REGISTER_ALLOCATION_H_
1926a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
2026a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray#include "nodes.h"
2126a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
2226a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffraynamespace art {
2326a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
2426a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray/**
2526a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * A simplification pass over the graph before doing register allocation.
2626a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * For example it changes uses of null checks and bounds checks to the original
2726a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray * objects, to avoid creating a live range for these checks.
2826a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray */
29360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffrayclass PrepareForRegisterAllocation : public HGraphDelegateVisitor {
3026a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray public:
31360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray  explicit PrepareForRegisterAllocation(HGraph* graph) : HGraphDelegateVisitor(graph) {}
3226a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
3326a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  void Run();
3426a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
35700347e9bc6c2ed29046e0c13122a5ad57d2fc51Mingyao Yang  static constexpr const char* kPrepareForRegisterAllocationPassName =
36700347e9bc6c2ed29046e0c13122a5ad57d2fc51Mingyao Yang      "prepare_for_register_allocation";
37700347e9bc6c2ed29046e0c13122a5ad57d2fc51Mingyao Yang
3826a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray private:
392ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames  void VisitNullCheck(HNullCheck* check) OVERRIDE;
402ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames  void VisitDivZeroCheck(HDivZeroCheck* check) OVERRIDE;
412ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames  void VisitBoundsCheck(HBoundsCheck* check) OVERRIDE;
422ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames  void VisitBoundType(HBoundType* bound_type) OVERRIDE;
43b133ec6c39b4c953ed815ec731b0270f0d8f0ed9Roland Levillain  void VisitArraySet(HArraySet* instruction) OVERRIDE;
442ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames  void VisitClinitCheck(HClinitCheck* check) OVERRIDE;
452ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames  void VisitCondition(HCondition* condition) OVERRIDE;
464c0eb42259d790fddcd9978b66328dbb3ab65615Roland Levillain  void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE;
47729645a937eb9f04a311b3c22471dcf3ebe9bcecNicolas Geoffray  void VisitNewInstance(HNewInstance* instruction) OVERRIDE;
4826a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
49b3e773eea39a156b3eacf915ba84e3af1a5c14faDavid Brazdil  bool CanMoveClinitCheck(HInstruction* input, HInstruction* user) const;
50b3e773eea39a156b3eacf915ba84e3af1a5c14faDavid Brazdil  bool CanEmitConditionAt(HCondition* condition, HInstruction* user) const;
51fbb184a1c6df22d9302b32b55206396c8278edcfVladimir Marko
5226a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(PrepareForRegisterAllocation);
5326a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray};
5426a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
5526a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray}  // namespace art
5626a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
5726a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray#endif  // ART_COMPILER_OPTIMIZING_PREPARE_FOR_REGISTER_ALLOCATION_H_
58