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 #if TARGAARCH64
17 #include "aarch64_strldr.h"
18 #elif TARGRISCV64
19 #include "riscv64_strldr.h"
20 #endif
21 #if TARGARM32
22 #include "arm32_strldr.h"
23 #endif
24 #include "reaching.h"
25 #include "cg.h"
26 #include "optimize_common.h"
27
28 namespace maplebe {
29 using namespace maple;
30 #define SCHD_DUMP_NEWPM CG_DEBUG_FUNC(f)
PhaseRun(maplebe::CGFunc & f)31 bool CgStoreLoadOpt::PhaseRun(maplebe::CGFunc &f)
32 {
33 if (SCHD_DUMP_NEWPM) {
34 DotGenerator::GenerateDot("storeloadopt", f, f.GetMirModule());
35 }
36 ReachingDefinition *reachingDef = nullptr;
37 if (Globals::GetInstance()->GetOptimLevel() >= CGOptions::kLevel2) {
38 reachingDef = GET_ANALYSIS(CgReachingDefinition, f);
39 }
40 if (reachingDef == nullptr || !f.GetRDStatus()) {
41 GetAnalysisInfoHook()->ForceEraseAnalysisPhase(f.GetUniqueID(), &CgReachingDefinition::id);
42 return false;
43 }
44 auto *loopInfo = GET_ANALYSIS(CgLoopAnalysis, f);
45 StoreLoadOpt *storeLoadOpt = nullptr;
46 #if TARGAARCH64 || TARGRISCV64
47 storeLoadOpt = GetPhaseMemPool()->New<AArch64StoreLoadOpt>(f, *GetPhaseMemPool(), *loopInfo);
48 #endif
49 #if TARGARM32
50 storeLoadOpt = GetPhaseMemPool()->New<Arm32StoreLoadOpt>(f, *GetPhaseMemPool());
51 #endif
52 storeLoadOpt->Run();
53 return true;
54 }
GetAnalysisDependence(maple::AnalysisDep & aDep) const55 void CgStoreLoadOpt::GetAnalysisDependence(maple::AnalysisDep &aDep) const
56 {
57 aDep.AddRequired<CgReachingDefinition>();
58 aDep.AddRequired<CgLoopAnalysis>();
59 aDep.SetPreservedAll();
60 }
61 MAPLE_TRANSFORM_PHASE_REGISTER_CANSKIP(CgStoreLoadOpt, storeloadopt)
62 } /* namespace maplebe */
63