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 PANDA_REG_ACC_ALLOC_H 17 #define PANDA_REG_ACC_ALLOC_H 18 19 #include "optimizer/ir/graph.h" 20 #include "optimizer/pass.h" 21 #include "compiler_options.h" 22 23 namespace ark::bytecodeopt { 24 25 class PANDA_PUBLIC_API RegAccAlloc : public compiler::Optimization { 26 using Optimization::Optimization; 27 28 public: RegAccAlloc(compiler::Graph * graph)29 explicit RegAccAlloc(compiler::Graph *graph) : compiler::Optimization(graph), accMarker_(graph->NewMarker()) {}; 30 31 ~RegAccAlloc() override = default; 32 NO_COPY_SEMANTIC(RegAccAlloc); 33 NO_MOVE_SEMANTIC(RegAccAlloc); 34 IsEnable()35 bool IsEnable() const override 36 { 37 return compiler::g_options.IsCompilerRegAccAlloc(); 38 } 39 GetPassName()40 const char *GetPassName() const override 41 { 42 return "RegAccAlloc"; 43 } 44 45 bool RunImpl() override; 46 47 private: 48 bool IsPhiOptimizable(compiler::Inst *phi) const; 49 bool IsAccRead(compiler::Inst *inst) const; 50 bool IsAccWrite(compiler::Inst *inst) const; 51 52 bool CanUserReadAcc(compiler::Inst *inst, compiler::Inst *user) const; 53 bool IsPhiAccReady(compiler::Inst *phi) const; 54 void MarkPhiInstructions() const; 55 void MarkInstructions(); 56 void MarkInstruction(compiler::Inst *inst); 57 void ClearAccForInstAndUsers(compiler::Inst *inst); 58 void SetNeedLda(compiler::Inst *inst, bool need); 59 bool CanIntrinsicReadAcc(compiler::IntrinsicInst *inst) const; 60 61 compiler::Marker accMarker_ {0}; 62 }; 63 64 } // namespace ark::bytecodeopt 65 66 #endif // PANDA_REG_ACC_ALLOC_H 67