LLVM 20.0.0git
LoopRotation.cpp
Go to the documentation of this file.
1//===- LoopRotation.cpp - Loop Rotation Pass ------------------------------===//
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 Loop Rotation Pass.
10//
11//===----------------------------------------------------------------------===//
12
27#include <optional>
28using namespace llvm;
29
30#define DEBUG_TYPE "loop-rotate"
31
33 "rotation-max-header-size", cl::init(16), cl::Hidden,
34 cl::desc("The default maximum header size for automatic loop rotation"));
35
37 "rotation-prepare-for-lto", cl::init(false), cl::Hidden,
38 cl::desc("Run loop-rotation in the prepare-for-lto stage. This option "
39 "should be used for testing only."));
40
41LoopRotatePass::LoopRotatePass(bool EnableHeaderDuplication, bool PrepareForLTO)
42 : EnableHeaderDuplication(EnableHeaderDuplication),
43 PrepareForLTO(PrepareForLTO) {}
44
46 raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
47 static_cast<PassInfoMixin<LoopRotatePass> *>(this)->printPipeline(
48 OS, MapClassName2PassName);
49 OS << "<";
50 if (!EnableHeaderDuplication)
51 OS << "no-";
52 OS << "header-duplication;";
53
54 if (!PrepareForLTO)
55 OS << "no-";
56 OS << "prepare-for-lto";
57 OS << ">";
58}
59
62 LPMUpdater &) {
63 // Vectorization requires loop-rotation. Use default threshold for loops the
64 // user explicitly marked for vectorization, even when header duplication is
65 // disabled.
66 int Threshold =
67 (EnableHeaderDuplication && !L.getHeader()->getParent()->hasMinSize()) ||
70 : 0;
71 const DataLayout &DL = L.getHeader()->getDataLayout();
73
74 std::optional<MemorySSAUpdater> MSSAU;
75 if (AR.MSSA)
76 MSSAU = MemorySSAUpdater(AR.MSSA);
77 bool Changed = LoopRotation(&L, &AR.LI, &AR.TTI, &AR.AC, &AR.DT, &AR.SE,
78 MSSAU ? &*MSSAU : nullptr, SQ, false, Threshold,
79 false, PrepareForLTO || PrepareForLTOOption);
80
81 if (!Changed)
83
84 if (AR.MSSA && VerifyMemorySSA)
86
88 if (AR.MSSA)
89 PA.preserve<MemorySSAAnalysis>();
90 return PA;
91}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< unsigned > DefaultRotationThreshold("rotation-max-header-size", cl::init(16), cl::Hidden, cl::desc("The default maximum header size for automatic loop rotation"))
static cl::opt< bool > PrepareForLTOOption("rotation-prepare-for-lto", cl::init(false), cl::Hidden, cl::desc("Run loop-rotation in the prepare-for-lto stage. This option " "should be used for testing only."))
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
raw_pwrite_stream & OS
This pass exposes codegen information to IR-level passes.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
LoopRotatePass(bool EnableHeaderDuplication=true, bool PrepareForLTO=false)
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
An analysis that produces MemorySSA for a function.
Definition: MemorySSA.h:928
void verifyMemorySSA(VerificationLevel=VerificationLevel::Fast) const
Verify that MemorySSA is self consistent (IE definitions dominate all uses, uses appear in the right ...
Definition: MemorySSA.cpp:1905
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
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.
Definition: raw_ostream.h:52
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
TransformationMode hasVectorizeTransformation(const Loop *L)
Definition: LoopUtils.cpp:391
bool VerifyMemorySSA
Enables verification of MemorySSA.
Definition: MemorySSA.cpp:84
@ TM_ForcedByUser
The transformation was directed by the user, e.g.
Definition: LoopUtils.h:294
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
const SimplifyQuery getBestSimplifyQuery(Pass &, Function &)
bool LoopRotation(Loop *L, LoopInfo *LI, const TargetTransformInfo *TTI, AssumptionCache *AC, DominatorTree *DT, ScalarEvolution *SE, MemorySSAUpdater *MSSAU, const SimplifyQuery &SQ, bool RotationOnly, unsigned Threshold, bool IsUtilMode, bool PrepareForLTO=false)
Convert a loop into a loop with bottom test.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69