• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "emit.h"
17 
18 namespace maplebe {
19 using namespace maple;
20 
21 uint32 VregInfo::virtualRegCount = kBaseVirtualRegNO;
22 uint32 VregInfo::maxRegCount = 0;
23 std::vector<VirtualRegNode> VregInfo::vRegTable;
24 std::unordered_map<regno_t, RegOperand *> VregInfo::vRegOperandTable;
25 /*  There are two builders, cgfunc builder (original code selector) and irbuilder (abstract).
26  *  This is to prevent conflict between the two for VregInfo as for arm64 both co-exists.
27  *  When switching to irbuilder completely, then this bool can go away.
28  */
29 bool VregInfo::initialized = false;
30 
SetTarget(CG & target)31 void Globals::SetTarget(CG &target)
32 {
33     cg = &target;
34 }
GetTarget() const35 const CG *Globals::GetTarget() const
36 {
37     DEBUG_ASSERT(cg, " set target info please ");
38     return cg;
39 }
40 
41 CGFunc *CG::currentCGFunction = nullptr;
42 std::map<MIRFunction *, std::pair<LabelIdx, LabelIdx>> CG::funcWrapLabels;
43 
~CG()44 CG::~CG()
45 {
46     Emit([](Emitter *emitter) {
47         emitter->CloseOutput();
48     });
49     delete memPool;
50     memPool = nullptr;
51     mirModule = nullptr;
52     emitters.clear();
53     currentCGFunction = nullptr;
54     dbgTraceEnter = nullptr;
55     dbgTraceExit = nullptr;
56     dbgFuncProfile = nullptr;
57 }
58 
EmitAllEmitters(const std::function<void (Emitter *)> & cb) const59 void CG::EmitAllEmitters(const std::function<void(Emitter *)>& cb) const
60 {
61     DEBUG_ASSERT(!emitters.empty(), "Emitter were not set");
62     DEBUG_ASSERT(emitters.size() <= 2U, "Emitters number isn't correct");
63     for (auto emitter: emitters) {
64         cb(emitter);
65     }
66 }
67 
EmitAsmEmitters(const std::function<void (Emitter *)> & cb) const68 void CG::EmitAsmEmitters(const std::function<void(Emitter *)>& cb) const
69 {
70     if (emitters.size() == 2U) {
71         cb(emitters[1]);
72     }
73 }
74 
EmitObjEmitters(const std::function<void (Emitter *)> & cb) const75 void CG::EmitObjEmitters(const std::function<void(Emitter *)>& cb) const
76 {
77     DEBUG_ASSERT(!emitters.empty(), "ObjEmmiter wasn't set");
78     cb(emitters[0]);
79 }
80 
81 } /* namespace maplebe */
82