1 /* 2 * Copyright (c) 2023-2024 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 ark::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 g_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(BasicBlock *bb, Inst *startFrom, Inst *head); 46 void ProcessChain(Inst *head); 47 void ProcessIndex(Inst *mem); 48 void InsertMem(Inst *org, Inst *base, Inst *index, uint8_t scale); 49 Inst *InsertPointerArithmetic(Inst *input, uint64_t imm, Inst *insertBefore, uint32_t pc, bool isAdd); 50 51 void GetHeads(); 52 53 InstVector defs_; 54 InstVector workset_; 55 InstVector heads_; 56 InstVector instsToReplace_; 57 Marker blockEntered_ {}; 58 Marker blockProcessed_ {}; 59 Marker worksetMarker_ {}; 60 Loop *loop_ = {nullptr}; 61 bool added_ = {false}; 62 }; 63 } // namespace ark::compiler 64 65 #endif 66