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.
10//
11//===----------------------------------------------------------------------===//
12
13#include "bolt/Passes/DataflowInfoManager.h"
14
15namespace llvm {
16namespace bolt {
17
18ReachingDefOrUse</*Def=*/true> &DataflowInfoManager::getReachingDefs() {
19 if (RD)
20 return *RD;
21 assert(RA && "RegAnalysis required");
22 RD.reset(p: new ReachingDefOrUse<true>(*RA, BF, std::nullopt, AllocatorId));
23 RD->run();
24 return *RD;
25}
26
27void DataflowInfoManager::invalidateReachingDefs() { RD.reset(p: nullptr); }
28
29ReachingDefOrUse</*Def=*/false> &DataflowInfoManager::getReachingUses() {
30 if (RU)
31 return *RU;
32 assert(RA && "RegAnalysis required");
33 RU.reset(p: new ReachingDefOrUse<false>(*RA, BF, std::nullopt, AllocatorId));
34 RU->run();
35 return *RU;
36}
37
38void DataflowInfoManager::invalidateReachingUses() { RU.reset(p: nullptr); }
39
40LivenessAnalysis &DataflowInfoManager::getLivenessAnalysis() {
41 if (LA)
42 return *LA;
43 assert(RA && "RegAnalysis required");
44 LA.reset(p: new LivenessAnalysis(*RA, BF, AllocatorId));
45 LA->run();
46 return *LA;
47}
48
49void DataflowInfoManager::invalidateLivenessAnalysis() { LA.reset(p: nullptr); }
50
51StackReachingUses &DataflowInfoManager::getStackReachingUses() {
52 if (SRU)
53 return *SRU;
54 assert(FA && "FrameAnalysis required");
55 SRU.reset(p: new StackReachingUses(*FA, BF, AllocatorId));
56 SRU->run();
57 return *SRU;
58}
59
60void DataflowInfoManager::invalidateStackReachingUses() { SRU.reset(p: nullptr); }
61
62DominatorAnalysis<false> &DataflowInfoManager::getDominatorAnalysis() {
63 if (DA)
64 return *DA;
65 DA.reset(p: new DominatorAnalysis<false>(BF, AllocatorId));
66 DA->run();
67 return *DA;
68}
69
70void DataflowInfoManager::invalidateDominatorAnalysis() { DA.reset(p: nullptr); }
71
72DominatorAnalysis<true> &DataflowInfoManager::getPostDominatorAnalysis() {
73 if (PDA)
74 return *PDA;
75 PDA.reset(p: new DominatorAnalysis<true>(BF, AllocatorId));
76 PDA->run();
77 return *PDA;
78}
79
80void DataflowInfoManager::invalidatePostDominatorAnalysis() {
81 PDA.reset(p: nullptr);
82}
83
84StackPointerTracking &DataflowInfoManager::getStackPointerTracking() {
85 if (SPT)
86 return *SPT;
87 SPT.reset(p: new StackPointerTracking(BF, AllocatorId));
88 SPT->run();
89 return *SPT;
90}
91
92void DataflowInfoManager::invalidateStackPointerTracking() {
93 invalidateStackAllocationAnalysis();
94 SPT.reset(p: nullptr);
95}
96
97ReachingInsns<false> &DataflowInfoManager::getReachingInsns() {
98 if (RI)
99 return *RI;
100 RI.reset(p: new ReachingInsns<false>(BF, AllocatorId));
101 RI->run();
102 return *RI;
103}
104
105void DataflowInfoManager::invalidateReachingInsns() { RI.reset(p: nullptr); }
106
107ReachingInsns<true> &DataflowInfoManager::getReachingInsnsBackwards() {
108 if (RIB)
109 return *RIB;
110 RIB.reset(p: new ReachingInsns<true>(BF, AllocatorId));
111 RIB->run();
112 return *RIB;
113}
114
115void DataflowInfoManager::invalidateReachingInsnsBackwards() {
116 RIB.reset(p: nullptr);
117}
118
119StackAllocationAnalysis &DataflowInfoManager::getStackAllocationAnalysis() {
120 if (SAA)
121 return *SAA;
122 SAA.reset(
123 p: new StackAllocationAnalysis(BF, getStackPointerTracking(), AllocatorId));
124 SAA->run();
125 return *SAA;
126}
127
128void DataflowInfoManager::invalidateStackAllocationAnalysis() {
129 SAA.reset(p: nullptr);
130}
131
132std::unordered_map<const MCInst *, BinaryBasicBlock *> &
133DataflowInfoManager::getInsnToBBMap() {
134 if (InsnToBB)
135 return *InsnToBB;
136 InsnToBB.reset(p: new std::unordered_map<const MCInst *, BinaryBasicBlock *>());
137 for (BinaryBasicBlock &BB : BF) {
138 for (MCInst &Inst : BB)
139 (*InsnToBB)[&Inst] = &BB;
140 }
141 return *InsnToBB;
142}
143
144void DataflowInfoManager::invalidateInsnToBBMap() { InsnToBB.reset(p: nullptr); }
145
146void DataflowInfoManager::invalidateAll() {
147 invalidateReachingDefs();
148 invalidateReachingUses();
149 invalidateLivenessAnalysis();
150 invalidateStackReachingUses();
151 invalidateDominatorAnalysis();
152 invalidatePostDominatorAnalysis();
153 invalidateStackPointerTracking();
154 invalidateReachingInsns();
155 invalidateReachingInsnsBackwards();
156 invalidateStackAllocationAnalysis();
157 invalidateInsnToBBMap();
158}
159
160} // end namespace bolt
161} // end namespace llvm
162

source code of bolt/lib/Passes/DataflowInfoManager.cpp