LLVM: include/llvm/IR/PassManagerImpl.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_IR_PASSMANAGERIMPL_H

16#define LLVM_IR_PASSMANAGERIMPL_H

17

24

25namespace llvm {

26

27template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>

29 IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs) {

32 IRUnitT &IR;

34

35 public:

37 : PI(PI), IR(IR) {}

38

40

42 OS << "Running pass \"";

44 Pass->printPipeline(OS, [this](StringRef ClassName) {

47 });

48 else

49 OS << "unknown";

50 OS << "\" on ";

52 OS << "\n";

53 }

54 };

55

57

58

59

60

61

64 AM, IR, std::tuple<ExtraArgTs...>(ExtraArgs...));

65

66 StackTraceEntry Entry(PI, IR);

68 Entry.setPass(&*Pass);

69

70

71

72

74 continue;

75

77

78

79

80 AM.invalidate(IR, PassPA);

81

82

83

85

86

87

89 }

90

91

92

93

94

96

97 return PA;

98}

99

100template <typename IRUnitT, typename... ExtraArgTs>

102

103template <typename IRUnitT, typename... ExtraArgTs>

106

107template <typename IRUnitT, typename... ExtraArgTs>

110 default;

111

112template <typename IRUnitT, typename... ExtraArgTs>

113inline void

117 PI->runAnalysesCleared(Name);

118

119 auto ResultsListI = AnalysisResultLists.find(&IR);

120 if (ResultsListI == AnalysisResultLists.end())

121 return;

122

123 for (auto &IDAndResult : ResultsListI->second)

124 AnalysisResults.erase({IDAndResult.first, &IR});

125

126

127 AnalysisResultLists.erase(ResultsListI);

128}

129

130template <typename IRUnitT, typename... ExtraArgTs>

131inline typename AnalysisManager<IRUnitT, ExtraArgTs...>::ResultConceptT &

132AnalysisManager<IRUnitT, ExtraArgTs...>::getResultImpl(

134 auto [RI, Inserted] = AnalysisResults.try_emplace(std::make_pair(ID, &IR));

135

136

137

138 if (Inserted) {

139 auto &P = this->lookUpPass(ID);

140

143 PI = getResult(IR, ExtraArgs...);

145 }

146

147 AnalysisResultListT &ResultList = AnalysisResultLists[&IR];

148 ResultList.emplace_back(ID, P.run(IR, *this, ExtraArgs...));

149

151

152

153

154 RI = AnalysisResults.find({ID, &IR});

155 assert(RI != AnalysisResults.end() && "we just inserted it!");

156

157 RI->second = std::prev(ResultList.end());

158 }

159

160 return *RI->second->second;

161}

162

163template <typename IRUnitT, typename... ExtraArgTs>

166

168 return;

169

170

171

173 Invalidator Inv(IsResultInvalidated, AnalysisResults);

174 AnalysisResultListT &ResultsList = AnalysisResultLists[&IR];

175 for (auto &AnalysisResultPair : ResultsList) {

176

177

178

179

181 auto &Result = *AnalysisResultPair.second;

182

183 auto IMapI = IsResultInvalidated.find(ID);

184 if (IMapI != IsResultInvalidated.end())

185

186 continue;

187

188

189

190

191

192

193 bool Inserted =

194 IsResultInvalidated.insert({ID, Result.invalidate(IR, PA, Inv)}).second;

195 (void)Inserted;

196 assert(Inserted && "Should never have already inserted this ID, likely "

197 "indicates a cycle!");

198 }

199

200

201 if (!IsResultInvalidated.empty()) {

202 for (auto I = ResultsList.begin(), E = ResultsList.end(); I != E;) {

204 if (!IsResultInvalidated.lookup(ID)) {

205 ++I;

206 continue;

207 }

208

211

212 I = ResultsList.erase(I);

213 AnalysisResults.erase({ID, &IR});

214 }

215 }

216

217 if (ResultsList.empty())

218 AnalysisResultLists.erase(&IR);

219}

220}

221

222#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

This header defines various interfaces for pass management in LLVM.

Legalize the Machine IR a function s Machine IR

This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...

static const char PassName[]

This templated class represents "all analyses that operate over " (e....

API to communicate dependencies between analyses during invalidation.

A container for analyses that lazily runs them and caches their results.

AnalysisManager()

Construct an empty analysis manager.

void clear()

Clear all analysis results cached by this AnalysisManager.

AnalysisManager & operator=(AnalysisManager &&)

void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)

Invalidate cached analyses for an IR unit.

Definition PassManagerImpl.h:164

PassT::Result * getCachedResult(IRUnitT &IR) const

Get the cached result of an analysis pass for a given IR unit.

ValueT lookup(const_arg_type_t< KeyT > Val) const

lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...

iterator find(const_arg_type_t< KeyT > Val)

std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)

This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...

void runBeforeAnalysis(const PassT &Analysis, const IRUnitT &IR) const

BeforeAnalysis instrumentation point - takes Analysis instance to be executed and constant reference ...

void runAnalysisInvalidated(const PassT &Analysis, const IRUnitT &IR) const

AnalysisInvalidated instrumentation point - takes Analysis instance that has just been invalidated an...

StringRef getPassNameForClassName(StringRef ClassName) const

Get the pass name for a given pass class name.

void runAfterPass(const PassT &Pass, const IRUnitT &IR, const PreservedAnalyses &PA) const

AfterPass instrumentation point - takes Pass instance that has just been executed and constant refere...

void runAfterAnalysis(const PassT &Analysis, const IRUnitT &IR) const

AfterAnalysis instrumentation point - takes Analysis instance that has just been executed and constan...

bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const

BeforePass instrumentation point - takes Pass instance to be executed and constant reference to IR it...

std::vector< std::unique_ptr< PassConceptT > > Passes

detail::PassConcept< IRUnitT, AnalysisManagerT, ExtraArgTs... > PassConceptT

PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)

Run all of the passes in this manager over the given unit of IR.

Definition PassManagerImpl.h:28

Pass interface - Implemented by all 'passes'.

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

bool allAnalysesInSetPreserved() const

Directly test whether a set of analyses is preserved.

PreservedAnalyses & preserveSet()

Mark an analysis set as preserved.

void intersect(const PreservedAnalyses &Arg)

Intersect this set with another in place.

PrettyStackTraceEntry - This class is used to represent a frame of the "pretty" stack trace that is d...

StringRef - Represent a constant reference to a string, i.e.

This class implements an extremely fast bulk output stream that can only output to a stream.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

PassT::Result getAnalysisResult(AnalysisManager< IRUnitT, AnalysisArgTs... > &AM, IRUnitT &IR, std::tuple< MainArgTs... > Args)

Helper for partial unpacking of extra arguments in getAnalysisResult.

This is an optimization pass for GlobalISel generic memory operations.

void printIRUnitNameForStackTrace(raw_ostream &OS, const IRUnitT &IR)

static AnalysisKey * ID()

A special type used by analysis passes to provide an address that identifies that particular analysis...