LLVM: lib/Transforms/Scalar/LoopPassManager.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

15

16using namespace llvm;

17

18

19

24

26 ? runWithLoopNestPasses(L, AM, AR, U)

27 : runWithoutLoopNestPasses(L, AM, AR, U);

28

29

30

31

32

33

34

35

37

38 return PA;

39}

40

44 MapClassName2PassName) {

45 assert(LoopPasses.size() + LoopNestPasses.size() == IsLoopNestPass.size());

46

47 unsigned IdxLP = 0, IdxLNP = 0;

48 for (unsigned Idx = 0, Size = IsLoopNestPass.size(); Idx != Size; ++Idx) {

49 if (IsLoopNestPass[Idx]) {

50 auto *P = LoopNestPasses[IdxLNP++].get();

51 P->printPipeline(OS, MapClassName2PassName);

52 } else {

53 auto *P = LoopPasses[IdxLP++].get();

54 P->printPipeline(OS, MapClassName2PassName);

55 }

56 if (Idx + 1 < Size)

57 OS << ',';

58 }

59}

60

61

67 "Loop-nest passes should only run on top-level loops.");

69

70

71

72 PassInstrumentation PI = AM.getResult(L, AR);

73

74 unsigned LoopPassIndex = 0, LoopNestPassIndex = 0;

75

76

77

78

79

80 std::unique_ptr LoopNestPtr;

81 bool IsLoopNestPtrValid = false;

82 Loop *OuterMostLoop = &L;

83

84 for (size_t I = 0, E = IsLoopNestPass.size(); I != E; ++I) {

85 std::optional PassPA;

86 if (!IsLoopNestPass[I]) {

87

88 auto &Pass = LoopPasses[LoopPassIndex++];

89 PassPA = runSinglePass(L, Pass, AM, AR, U, PI);

90 } else {

91

92 auto &Pass = LoopNestPasses[LoopNestPassIndex++];

93

94

95

96

97

98

99

100 if (!IsLoopNestPtrValid || U.isLoopNestChanged()) {

101 while (auto *ParentLoop = OuterMostLoop->getParentLoop())

102 OuterMostLoop = ParentLoop;

104 IsLoopNestPtrValid = true;

105 U.markLoopNestChanged(false);

106 }

107

108 PassPA = runSinglePass(*LoopNestPtr, Pass, AM, AR, U, PI);

109 }

110

111

112

113

114 if (!PassPA)

115 continue;

116

117

118 if (U.skipCurrentLoop()) {

119 PA.intersect(std::move(*PassPA));

120 break;

121 }

122

123

124

125 AM.invalidate(IsLoopNestPass[I] ? *OuterMostLoop : L, *PassPA);

126

127

128

129 PA.intersect(std::move(*PassPA));

130

131

132 IsLoopNestPtrValid &= PassPA->getChecker().preserved();

133

134

135

136

137 U.setParentLoop((IsLoopNestPass[I] ? *OuterMostLoop : L).getParentLoop());

138 }

139 return PA;

140}

141

142

143

144

150

151

152

153 PassInstrumentation PI = AM.getResult(L, AR);

154 for (auto &Pass : LoopPasses) {

155 std::optional PassPA =

156 runSinglePass(L, Pass, AM, AR, U, PI);

157

158

159

160

161 if (!PassPA)

162 continue;

163

164

165 if (U.skipCurrentLoop()) {

166 PA.intersect(std::move(*PassPA));

167 break;

168 }

169

170

171

173

174

175

176 PA.intersect(std::move(*PassPA));

177

178

179

180

181 U.setParentLoop(L.getParentLoop());

182 }

183 return PA;

184}

185

188 OS << (UseMemorySSA ? "loop-mssa(" : "loop(");

189 Pass->printPipeline(OS, MapClassName2PassName);

190 OS << ')';

191}

192

195

196

197

198

200

202

203

205 PA = LoopCanonicalizationFPM.run(F, AM);

207 }

208

209

211

212

214 return PA;

215

216

226 MSSA};

227

228

229

230

231

232

233 auto &LAMFP = AM.getResult(F);

234 if (UseMemorySSA)

235 LAMFP.markMSSAUsed();

237

238

240

241

242

244

245

246

247 if (!LoopNestMode) {

249 } else {

250 for (Loop *L : LI)

252 }

253

254#ifndef NDEBUG

257 return;

260 const Loop *L = LPtr ? *LPtr : nullptr;

261 assert(L && "Loop should be valid for printing");

262

263

264 L->verifyLoop();

265 assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) &&

266 "Loops must remain in LCSSA form!");

267 });

268#endif

269

270 do {

272 assert(!(LoopNestMode && L->getParentLoop()) &&

273 "L should be a top-level loop in loop-nest mode.");

274

275

276 Updater.CurrentL = L;

277 Updater.SkipCurrentLoop = false;

278

279#if LLVM_ENABLE_ABI_BREAKING_CHECKS

280

281 Updater.ParentL = L->getParentLoop();

282#endif

283

284

285

287 continue;

288

290

291

294 else

296

299 "that does not preserve MemorySSA");

300

301#ifndef NDEBUG

302

311#endif

312

313

315

316

317

318 LAM.invalidate(*L, PassPA);

319

320

321

322 PA.intersect(std::move(PassPA));

323 } while (!Worklist.empty());

324

325#ifndef NDEBUG

327#endif

328

329

330

331

332

334 PA.preserve();

335

339 if (UseMemorySSA)

341 return PA;

342}

343

346 : OS(OS), Banner(Banner) {}

347

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

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

Legalize the Machine IR a function s Machine IR

This header provides classes for managing a pipeline of passes over loops in LLVM IR.

print mir2vec MIR2Vec Vocabulary Printer Pass

This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...

This pass exposes codegen information to IR-level passes.

A manager for alias analyses.

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

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

Invalidate cached analyses for an IR unit.

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

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

A function analysis which provides an AssumptionCache.

Analysis pass which computes a DominatorTree.

bool verify(VerificationLevel VL=VerificationLevel::Full) const

verify - checks if the tree is correct.

LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)

Definition LoopPassManager.cpp:186

LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)

Runs the loop passes across every loop in the function.

Definition LoopPassManager.cpp:193

This class provides an interface for updating the loop pass manager based on mutations to the loop ne...

bool skipCurrentLoop() const

This can be queried by loop passes which run other loop passes (like pass managers) to know whether t...

Analysis pass that exposes the LoopInfo for a function.

LoopT * getParentLoop() const

Return the parent loop if it exists or nullptr for top level loops.

void verify(const DominatorTreeBase< BlockT, false > &DomTree) const

static std::unique_ptr< LoopNest > getLoopNest(Loop &Root, ScalarEvolution &SE)

Construct a LoopNest object.

Represents a single loop in the control flow graph.

An analysis that produces MemorySSA for a function.

Encapsulates MemorySSA, including all data associated with memory accesses.

LLVM_ABI void verifyMemorySSA(VerificationLevel=VerificationLevel::Fast) const

Verify that MemorySSA is self consistent (IE definitions dominate all uses, uses appear in the right ...

Pseudo-analysis pass that exposes the PassInstrumentation to pass managers.

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

void runAfterPassInvalidated(const PassT &Pass, const PreservedAnalyses &PA) const

AfterPassInvalidated instrumentation point - takes Pass instance that has just been executed.

void pushBeforeNonSkippedPassCallback(CallableT C)

void popBeforeNonSkippedPassCallback()

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...

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

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

Manages a sequence of passes over a particular unit of IR.

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.

PreservedAnalyses & preserveSet()

Mark an analysis set as preserved.

void intersect(const PreservedAnalyses &Arg)

Intersect this set with another in place.

PreservedAnalysisChecker getChecker() const

Build a checker for this PreservedAnalyses and the specified analysis type.

LLVM_ABI PrintLoopPass()

Definition LoopPassManager.cpp:344

LLVM_ABI PreservedAnalyses run(Loop &L, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &)

Definition LoopPassManager.cpp:348

bool empty() const

Determine if the PriorityWorklist is empty or not.

bool insert(const T &X)

Insert a new element into the PriorityWorklist.

Analysis pass that exposes the ScalarEvolution for a function.

LLVM_ABI void verify() const

A version of PriorityWorklist that selects small size optimized data structures for the vector and ma...

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

Analysis pass providing the TargetTransformInfo.

Analysis pass providing the TargetLibraryInfo.

An efficient, type-erasing, non-owning reference to a callable.

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

This is an optimization pass for GlobalISel generic memory operations.

T any_cast(const Any &Value)

AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager

The loop analysis manager.

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

LLVM_TEMPLATE_ABI void appendLoopsToWorklist(RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)

Utility that implements appending of loops onto a worklist given a range.

LLVM_ABI bool isSpecialPass(StringRef PassID, const std::vector< StringRef > &Specials)

LLVM_ABI bool VerifyLoopInfo

Enable verification of loop info.

LLVM_ABI bool VerifyMemorySSA

Enables verification of MemorySSA.

LLVM_ABI void printLoop(const Loop &L, raw_ostream &OS, const std::string &Banner="")

Function to print a loop's contents as LLVM's text IR assembly.

LLVM_ABI bool VerifyDomInfo

Enables verification of dominator trees.

AnalysisManager< Function > FunctionAnalysisManager

Convenience typedef for the Function analysis manager.

LLVM_ABI void reportFatalUsageError(Error Err)

Report a fatal error that does not indicate a bug in LLVM.

The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...