• 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 "label_creation.h"
17 #include "cgfunc.h"
18 #include "cg.h"
19 #include "debug_info.h"
20 
21 namespace maplebe {
22 using namespace maple;
23 
Run()24 void LabelCreation::Run()
25 {
26     CreateStartEndLabel();
27 }
28 
CreateStartEndLabel()29 void LabelCreation::CreateStartEndLabel()
30 {
31     DEBUG_ASSERT(cgFunc != nullptr, "expect a cgfunc before CreateStartEndLabel");
32     LabelIdx startLblIdx = cgFunc->CreateLabel();
33     MIRBuilder *mirBuilder = cgFunc->GetFunction().GetModule()->GetMIRBuilder();
34     DEBUG_ASSERT(mirBuilder != nullptr, "get mirbuilder failed in CreateStartEndLabel");
35     LabelNode *startLabel = mirBuilder->CreateStmtLabel(startLblIdx);
36     cgFunc->SetStartLabel(*startLabel);
37     cgFunc->GetFunction().GetBody()->InsertFirst(startLabel);
38     LabelIdx endLblIdx = cgFunc->CreateLabel();
39     LabelNode *endLabel = mirBuilder->CreateStmtLabel(endLblIdx);
40     cgFunc->SetEndLabel(*endLabel);
41     cgFunc->GetFunction().GetBody()->InsertLast(endLabel);
42     DEBUG_ASSERT(cgFunc->GetFunction().GetBody()->GetLast() == endLabel, "last stmt must be a endLabel");
43     MIRFunction *func = &cgFunc->GetFunction();
44     CG *cg = cgFunc->GetCG();
45     if (cg->GetCGOptions().WithDwarf()) {
46         DebugInfo *di = cg->GetMIRModule()->GetDbgInfo();
47         DBGDie *fdie = di->GetDie(func);
48         fdie->SetAttr(DW_AT_low_pc, startLblIdx);
49         fdie->SetAttr(DW_AT_high_pc, endLblIdx);
50     }
51     /* add start/end labels into the static map table in class cg */
52     if (!CG::IsInFuncWrapLabels(func)) {
53         CG::SetFuncWrapLabels(func, std::make_pair(startLblIdx, endLblIdx));
54     }
55 }
56 
PhaseRun(maplebe::CGFunc & f)57 bool CgCreateLabel::PhaseRun(maplebe::CGFunc &f)
58 {
59     MemPool *memPool = GetPhaseMemPool();
60     LabelCreation *labelCreate = memPool->New<LabelCreation>(f);
61     labelCreate->Run();
62     return false;
63 }
64 } /* namespace maplebe */
65