Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / bolt / lib / Passes / DataflowInfoManager.cpp
blob321e3acb0efa7f8148a00f4afda0ecd69d5133dc
1 //===- bolt/Passes/DataflowInfoManager.cpp --------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the DataflowInfoManager class.
11 //===----------------------------------------------------------------------===//
13 #include "bolt/Passes/DataflowInfoManager.h"
15 namespace llvm {
16 namespace bolt {
18 ReachingDefOrUse</*Def=*/true> &DataflowInfoManager::getReachingDefs() {
19 if (RD)
20 return *RD;
21 assert(RA && "RegAnalysis required");
22 RD.reset(new ReachingDefOrUse<true>(*RA, BF, std::nullopt, AllocatorId));
23 RD->run();
24 return *RD;
27 void DataflowInfoManager::invalidateReachingDefs() { RD.reset(nullptr); }
29 ReachingDefOrUse</*Def=*/false> &DataflowInfoManager::getReachingUses() {
30 if (RU)
31 return *RU;
32 assert(RA && "RegAnalysis required");
33 RU.reset(new ReachingDefOrUse<false>(*RA, BF, std::nullopt, AllocatorId));
34 RU->run();
35 return *RU;
38 void DataflowInfoManager::invalidateReachingUses() { RU.reset(nullptr); }
40 LivenessAnalysis &DataflowInfoManager::getLivenessAnalysis() {
41 if (LA)
42 return *LA;
43 assert(RA && "RegAnalysis required");
44 LA.reset(new LivenessAnalysis(*RA, BF, AllocatorId));
45 LA->run();
46 return *LA;
49 void DataflowInfoManager::invalidateLivenessAnalysis() { LA.reset(nullptr); }
51 StackReachingUses &DataflowInfoManager::getStackReachingUses() {
52 if (SRU)
53 return *SRU;
54 assert(FA && "FrameAnalysis required");
55 SRU.reset(new StackReachingUses(*FA, BF, AllocatorId));
56 SRU->run();
57 return *SRU;
60 void DataflowInfoManager::invalidateStackReachingUses() { SRU.reset(nullptr); }
62 DominatorAnalysis<false> &DataflowInfoManager::getDominatorAnalysis() {
63 if (DA)
64 return *DA;
65 DA.reset(new DominatorAnalysis<false>(BF, AllocatorId));
66 DA->run();
67 return *DA;
70 void DataflowInfoManager::invalidateDominatorAnalysis() { DA.reset(nullptr); }
72 DominatorAnalysis<true> &DataflowInfoManager::getPostDominatorAnalysis() {
73 if (PDA)
74 return *PDA;
75 PDA.reset(new DominatorAnalysis<true>(BF, AllocatorId));
76 PDA->run();
77 return *PDA;
80 void DataflowInfoManager::invalidatePostDominatorAnalysis() {
81 PDA.reset(nullptr);
84 StackPointerTracking &DataflowInfoManager::getStackPointerTracking() {
85 if (SPT)
86 return *SPT;
87 SPT.reset(new StackPointerTracking(BF, AllocatorId));
88 SPT->run();
89 return *SPT;
92 void DataflowInfoManager::invalidateStackPointerTracking() {
93 invalidateStackAllocationAnalysis();
94 SPT.reset(nullptr);
97 ReachingInsns<false> &DataflowInfoManager::getReachingInsns() {
98 if (RI)
99 return *RI;
100 RI.reset(new ReachingInsns<false>(BF, AllocatorId));
101 RI->run();
102 return *RI;
105 void DataflowInfoManager::invalidateReachingInsns() { RI.reset(nullptr); }
107 ReachingInsns<true> &DataflowInfoManager::getReachingInsnsBackwards() {
108 if (RIB)
109 return *RIB;
110 RIB.reset(new ReachingInsns<true>(BF, AllocatorId));
111 RIB->run();
112 return *RIB;
115 void DataflowInfoManager::invalidateReachingInsnsBackwards() {
116 RIB.reset(nullptr);
119 StackAllocationAnalysis &DataflowInfoManager::getStackAllocationAnalysis() {
120 if (SAA)
121 return *SAA;
122 SAA.reset(
123 new StackAllocationAnalysis(BF, getStackPointerTracking(), AllocatorId));
124 SAA->run();
125 return *SAA;
128 void DataflowInfoManager::invalidateStackAllocationAnalysis() {
129 SAA.reset(nullptr);
132 std::unordered_map<const MCInst *, BinaryBasicBlock *> &
133 DataflowInfoManager::getInsnToBBMap() {
134 if (InsnToBB)
135 return *InsnToBB;
136 InsnToBB.reset(new std::unordered_map<const MCInst *, BinaryBasicBlock *>());
137 for (BinaryBasicBlock &BB : BF) {
138 for (MCInst &Inst : BB)
139 (*InsnToBB)[&Inst] = &BB;
141 return *InsnToBB;
144 void DataflowInfoManager::invalidateInsnToBBMap() { InsnToBB.reset(nullptr); }
146 void DataflowInfoManager::invalidateAll() {
147 invalidateReachingDefs();
148 invalidateReachingUses();
149 invalidateLivenessAnalysis();
150 invalidateStackReachingUses();
151 invalidateDominatorAnalysis();
152 invalidatePostDominatorAnalysis();
153 invalidateStackPointerTracking();
154 invalidateReachingInsns();
155 invalidateReachingInsnsBackwards();
156 invalidateStackAllocationAnalysis();
157 invalidateInsnToBBMap();
160 } // end namespace bolt
161 } // end namespace llvm