• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "ecmascript/compiler/escape_analysis_editor.h"
17 
18 namespace panda::ecmascript::kungfu {
19 
VisitFinishAllocate(GateRef gate)20 GateRef EscapeAnalysisEditor::VisitFinishAllocate(GateRef gate)
21 {
22     GateRef depend = acc_.GetDep(gate);
23     if (acc_.GetOpCode(gate) == OpCode::START_ALLOCATE) {
24         visitor_->RelaxStateAndDepend(gate);
25         visitor_->RelaxStateAndDepend(depend);
26     }
27     return Circuit::NullGate();
28 }
29 
VisitGate(GateRef gate)30 GateRef EscapeAnalysisEditor::VisitGate(GateRef gate)
31 {
32     GateRef replacement = result_->TryGetReplacement(gate);
33     if (replacement != Circuit::NullGate()) {
34         if (replacement == circuit_->DeadGate()) {
35             visitor_->RelaxStateAndDepend(gate);
36             return replacement;
37         }
38         if (isTraced_) {
39             LOG_COMPILER(INFO) << "[escape analysis editor] replace " << acc_.GetId(gate) <<
40                                   " with " << acc_.GetId(replacement);
41         }
42         return replacement;
43     }
44     auto opcode = acc_.GetOpCode(gate);
45     switch (opcode) {
46         case OpCode::FINISH_ALLOCATE:
47             return VisitFinishAllocate(gate);
48         default:
49             break;
50     }
51     return Circuit::NullGate();
52 }
53 
54 }