1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef COMPILER_OPTIMIZER_OPTIMIZATIONS_ADJUST_ARRAY_REFS_H 17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_ADJUST_ARRAY_REFS_H 18 19 #include "optimizer/pass.h" 20 #include "optimizer/ir/basicblock.h" 21 #include "compiler_options.h" 22 23 namespace panda::compiler { 24 class AdjustRefs : public Optimization { 25 public: 26 explicit AdjustRefs(Graph *graph); 27 28 NO_MOVE_SEMANTIC(AdjustRefs); 29 NO_COPY_SEMANTIC(AdjustRefs); 30 ~AdjustRefs() override = default; 31 32 bool RunImpl() override; IsEnable()33 bool IsEnable() const override 34 { 35 return options.IsCompilerAdjustRefs(); 36 } 37 GetPassName()38 const char *GetPassName() const override 39 { 40 return "AdjustRefs"; 41 } 42 43 private: 44 void ProcessArrayUses(); 45 void WalkChainDown(Inst *inst, Inst *head); 46 void ProcessChain(Inst *head); 47 ArenaVector<Inst *> GetHeads(); 48 49 ArenaUnorderedSet<Inst *> defs_; 50 ArenaUnorderedSet<Inst *> workset_; 51 ArenaMultiMap<Inst *, Inst *> chains_; 52 Loop *loop_ = {nullptr}; 53 bool added_ = {false}; 54 }; 55 } // namespace panda::compiler 56 57 #endif 58