Polly 23.0.0git
ScopHelper.h
Go to the documentation of this file.
1//===------ Support/ScopHelper.h -- Some Helper Functions for Scop. -------===//
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// Small functions that help with LLVM-IR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef POLLY_SUPPORT_IRHELPER_H
14#define POLLY_SUPPORT_IRHELPER_H
15
16#include "llvm/ADT/SetVector.h"
17#include "llvm/Analysis/ScalarEvolution.h"
18#include "llvm/IR/Instructions.h"
19#include "llvm/IR/IntrinsicInst.h"
20#include "llvm/IR/ValueHandle.h"
22#include <optional>
23
24namespace llvm {
25class LoopInfo;
26class Loop;
27class ScalarEvolution;
28class SCEV;
29class Region;
30class Pass;
31class DominatorTree;
32class RegionInfo;
33class RegionNode;
34} // namespace llvm
35
36namespace polly {
37class Scop;
38class ScopStmt;
39
40/// Same as llvm/Analysis/ScalarEvolutionExpressions.h
41using LoopToScevMapT = llvm::DenseMap<const llvm::Loop *, llvm::SCEVUse>;
42
43/// Enumeration of assumptions Polly can take.
56
57/// Enum to distinguish between assumptions and restrictions.
59
60/// Helper struct to remember assumptions.
61struct Assumption {
62 /// The kind of the assumption (e.g., WRAPPING).
64
65 /// Flag to distinguish assumptions and restrictions.
67
68 /// The valid/invalid context if this is an assumption/restriction.
70
71 /// The location that caused this assumption.
72 llvm::DebugLoc Loc;
73
74 /// An optional block whose domain can simplify the assumption.
75 llvm::BasicBlock *BB;
76
77 // Whether the assumption must be checked at runtime.
79};
80
81using RecordedAssumptionsTy = llvm::SmallVector<Assumption, 8>;
82
83/// Record an assumption for later addition to the assumed context.
84///
85/// This function will add the assumption to the RecordedAssumptions. This
86/// collection will be added (@see addAssumption) to the assumed context once
87/// all parameters are known and the context is fully built.
88///
89/// @param RecordedAssumption container which keeps all recorded assumptions.
90/// @param Kind The assumption kind describing the underlying cause.
91/// @param Set The relations between parameters that are assumed to hold.
92/// @param Loc The location in the source that caused this assumption.
93/// @param Sign Enum to indicate if the assumptions in @p Set are positive
94/// (needed/assumptions) or negative (invalid/restrictions).
95/// @param BB The block in which this assumption was taken. If it is
96/// set, the domain of that block will be used to simplify the
97/// actual assumption in @p Set once it is added. This is useful
98/// if the assumption was created prior to the domain.
99/// @param RTC Does the assumption require a runtime check?
100void recordAssumption(RecordedAssumptionsTy *RecordedAssumptions,
101 AssumptionKind Kind, isl::set Set, llvm::DebugLoc Loc,
102 AssumptionSign Sign, llvm::BasicBlock *BB = nullptr,
103 bool RTC = true);
104
105/// Type to remap values.
106using ValueMapT = llvm::DenseMap<llvm::AssertingVH<llvm::Value>,
107 llvm::AssertingVH<llvm::Value>>;
108
109/// Type for a set of invariant loads.
110using InvariantLoadsSetTy = llvm::SetVector<llvm::AssertingVH<llvm::LoadInst>>;
111
112/// Set type for parameters.
113using ParameterSetTy = llvm::SetVector<const llvm::SCEV *>;
114
115/// Set of loops (used to remember loops in non-affine subregions).
116using BoxedLoopsSetTy = llvm::SetVector<const llvm::Loop *>;
117
118/// Utility proxy to wrap the common members of LoadInst and StoreInst.
119///
120/// This works like the LLVM utility class CallSite, ie. it forwards all calls
121/// to either a LoadInst, StoreInst, MemIntrinsic or MemTransferInst.
122/// It is similar to LLVM's utility classes IntrinsicInst, MemIntrinsic,
123/// MemTransferInst, etc. in that it offers a common interface, but does not act
124/// as a fake base class.
125/// It is similar to StringRef and ArrayRef in that it holds a pointer to the
126/// referenced object and should be passed by-value as it is small enough.
127///
128/// This proxy can either represent a LoadInst instance, a StoreInst instance,
129/// a MemIntrinsic instance (memset, memmove, memcpy), a CallInst instance or a
130/// nullptr (only creatable using the default constructor); never an Instruction
131/// that is neither of the above mentioned. When representing a nullptr, only
132/// the following methods are defined:
133/// isNull(), isInstruction(), isLoad(), isStore(), ..., isMemTransferInst(),
134/// operator bool(), operator!()
135///
136/// The functions isa, cast, cast_or_null, dyn_cast are modeled to resemble
137/// those from llvm/Support/Casting.h. Partial template function specialization
138/// is currently not supported in C++ such that those cannot be used directly.
139/// (llvm::isa could, but then llvm:cast etc. would not have the expected
140/// behavior)
141class MemAccInst final {
142private:
143 llvm::Instruction *I;
144
145public:
146 MemAccInst() : I(nullptr) {}
147 MemAccInst(const MemAccInst &Inst) : I(Inst.I) {}
148 /* implicit */ MemAccInst(llvm::LoadInst &LI) : I(&LI) {}
149 /* implicit */ MemAccInst(llvm::LoadInst *LI) : I(LI) {}
150 /* implicit */ MemAccInst(llvm::StoreInst &SI) : I(&SI) {}
151 /* implicit */ MemAccInst(llvm::StoreInst *SI) : I(SI) {}
152 /* implicit */ MemAccInst(llvm::MemIntrinsic *MI) : I(MI) {}
153 /* implicit */ MemAccInst(llvm::CallInst *CI) : I(CI) {}
154 explicit MemAccInst(llvm::Instruction &I) : I(&I) { assert(isa(I)); }
155 explicit MemAccInst(llvm::Instruction *I) : I(I) { assert(isa(I)); }
156
157 static bool isa(const llvm::Value &V) {
158 return llvm::isa<llvm::LoadInst>(V) || llvm::isa<llvm::StoreInst>(V) ||
159 llvm::isa<llvm::CallInst>(V) || llvm::isa<llvm::MemIntrinsic>(V);
160 }
161 static bool isa(const llvm::Value *V) {
162 return llvm::isa<llvm::LoadInst>(V) || llvm::isa<llvm::StoreInst>(V) ||
163 llvm::isa<llvm::CallInst>(V) || llvm::isa<llvm::MemIntrinsic>(V);
164 }
165 static MemAccInst cast(llvm::Value &V) {
166 return MemAccInst(llvm::cast<llvm::Instruction>(V));
167 }
168 static MemAccInst cast(llvm::Value *V) {
169 return MemAccInst(llvm::cast<llvm::Instruction>(V));
170 }
171 static MemAccInst cast_or_null(llvm::Value &V) {
172 return MemAccInst(llvm::cast<llvm::Instruction>(V));
173 }
174 static MemAccInst cast_or_null(llvm::Value *V) {
175 if (!V)
176 return MemAccInst();
177 return MemAccInst(llvm::cast<llvm::Instruction>(V));
178 }
179 static MemAccInst dyn_cast(llvm::Value &V) {
180 if (isa(V))
181 return MemAccInst(llvm::cast<llvm::Instruction>(V));
182 return MemAccInst();
183 }
184 static MemAccInst dyn_cast(llvm::Value *V) {
185 assert(V);
186 if (isa(V))
187 return MemAccInst(llvm::cast<llvm::Instruction>(V));
188 return MemAccInst();
189 }
190
192 I = Inst.I;
193 return *this;
194 }
195 MemAccInst &operator=(llvm::LoadInst &LI) {
196 I = &LI;
197 return *this;
198 }
199 MemAccInst &operator=(llvm::LoadInst *LI) {
200 I = LI;
201 return *this;
202 }
203 MemAccInst &operator=(llvm::StoreInst &SI) {
204 I = &SI;
205 return *this;
206 }
207 MemAccInst &operator=(llvm::StoreInst *SI) {
208 I = SI;
209 return *this;
210 }
211 MemAccInst &operator=(llvm::MemIntrinsic &MI) {
212 I = &MI;
213 return *this;
214 }
215 MemAccInst &operator=(llvm::MemIntrinsic *MI) {
216 I = MI;
217 return *this;
218 }
219 MemAccInst &operator=(llvm::CallInst &CI) {
220 I = &CI;
221 return *this;
222 }
223 MemAccInst &operator=(llvm::CallInst *CI) {
224 I = CI;
225 return *this;
226 }
227
228 llvm::Instruction *get() const {
229 assert(I && "Unexpected nullptr!");
230 return I;
231 }
232 operator llvm::Instruction *() const { return asInstruction(); }
233 llvm::Instruction *operator->() const { return get(); }
234
235 explicit operator bool() const { return isInstruction(); }
236 bool operator!() const { return isNull(); }
237
238 llvm::Value *getValueOperand() const {
239 if (isLoad())
240 return asLoad();
241 if (isStore())
242 return asStore()->getValueOperand();
243 if (isMemIntrinsic())
244 return nullptr;
245 if (isCallInst())
246 return nullptr;
247 llvm_unreachable("Operation not supported on nullptr");
248 }
249 llvm::Value *getPointerOperand() const {
250 if (isLoad())
251 return asLoad()->getPointerOperand();
252 if (isStore())
253 return asStore()->getPointerOperand();
254 if (isMemIntrinsic())
255 return asMemIntrinsic()->getRawDest();
256 if (isCallInst())
257 return nullptr;
258 llvm_unreachable("Operation not supported on nullptr");
259 }
260 bool isVolatile() const {
261 if (isLoad())
262 return asLoad()->isVolatile();
263 if (isStore())
264 return asStore()->isVolatile();
265 if (isMemIntrinsic())
266 return asMemIntrinsic()->isVolatile();
267 if (isCallInst())
268 return false;
269 llvm_unreachable("Operation not supported on nullptr");
270 }
271 bool isSimple() const {
272 if (isLoad())
273 return asLoad()->isSimple();
274 if (isStore())
275 return asStore()->isSimple();
276 if (isMemIntrinsic())
277 return !asMemIntrinsic()->isVolatile();
278 if (isCallInst())
279 return true;
280 llvm_unreachable("Operation not supported on nullptr");
281 }
282 llvm::AtomicOrdering getOrdering() const {
283 if (isLoad())
284 return asLoad()->getOrdering();
285 if (isStore())
286 return asStore()->getOrdering();
287 if (isMemIntrinsic())
288 return llvm::AtomicOrdering::NotAtomic;
289 if (isCallInst())
290 return llvm::AtomicOrdering::NotAtomic;
291 llvm_unreachable("Operation not supported on nullptr");
292 }
293 bool isUnordered() const {
294 if (isLoad())
295 return asLoad()->isUnordered();
296 if (isStore())
297 return asStore()->isUnordered();
298 // Copied from the Load/Store implementation of isUnordered:
299 if (isMemIntrinsic())
300 return !asMemIntrinsic()->isVolatile();
301 if (isCallInst())
302 return true;
303 llvm_unreachable("Operation not supported on nullptr");
304 }
305
306 bool isNull() const { return !I; }
307 bool isInstruction() const { return I; }
308
309 llvm::Instruction *asInstruction() const { return I; }
310
311 bool isLoad() const { return I && llvm::isa<llvm::LoadInst>(I); }
312 bool isStore() const { return I && llvm::isa<llvm::StoreInst>(I); }
313 bool isCallInst() const { return I && llvm::isa<llvm::CallInst>(I); }
314 bool isMemIntrinsic() const { return I && llvm::isa<llvm::MemIntrinsic>(I); }
315 bool isMemSetInst() const { return I && llvm::isa<llvm::MemSetInst>(I); }
316 bool isMemTransferInst() const {
317 return I && llvm::isa<llvm::MemTransferInst>(I);
318 }
319
320 llvm::LoadInst *asLoad() const { return llvm::cast<llvm::LoadInst>(I); }
321 llvm::StoreInst *asStore() const { return llvm::cast<llvm::StoreInst>(I); }
322 llvm::CallInst *asCallInst() const { return llvm::cast<llvm::CallInst>(I); }
323 llvm::MemIntrinsic *asMemIntrinsic() const {
324 return llvm::cast<llvm::MemIntrinsic>(I);
325 }
326 llvm::MemSetInst *asMemSetInst() const {
327 return llvm::cast<llvm::MemSetInst>(I);
328 }
329 llvm::MemTransferInst *asMemTransferInst() const {
330 return llvm::cast<llvm::MemTransferInst>(I);
331 }
332};
333} // namespace polly
334
335namespace llvm {
336/// Specialize simplify_type for MemAccInst to enable dyn_cast and cast
337/// from a MemAccInst object.
338template <> struct simplify_type<polly::MemAccInst> {
339 typedef Instruction *SimpleType;
343};
344} // namespace llvm
345
346namespace polly {
347
348/// Simplify the region to have a single unconditional entry edge and a
349/// single exit edge.
350///
351/// Although this function allows DT and RI to be null, regions only work
352/// properly if the DominatorTree (for Region::contains) and RegionInfo are kept
353/// up-to-date.
354///
355/// @param R The region to be simplified
356/// @param DT DominatorTree to be updated.
357/// @param LI LoopInfo to be updated.
358/// @param RI RegionInfo to be updated.
359void simplifyRegion(llvm::Region *R, llvm::DominatorTree *DT,
360 llvm::LoopInfo *LI, llvm::RegionInfo *RI);
361
362/// Split the entry block of a function to store the newly inserted
363/// allocations outside of all Scops.
364///
365/// @param DT DominatorTree to be updated.
366/// @param LI LoopInfo to be updated.
367/// @param RI RegionInfo to be updated.
368void splitEntryBlockForAlloca(llvm::BasicBlock *EntryBlock,
369 llvm::DominatorTree *DT, llvm::LoopInfo *LI,
370 llvm::RegionInfo *RI);
371
372/// Wrapper for SCEVExpander extended to all Polly features.
373///
374/// This wrapper will internally call the SCEVExpander but also makes sure that
375/// all additional features not represented in SCEV (e.g., SDiv/SRem are not
376/// black boxes but can be part of the function) will be expanded correctly.
377///
378/// The parameters are the same as for the creation of a SCEVExpander as well
379/// as the call to SCEVExpander::expandCodeFor:
380///
381/// @param S The current Scop.
382/// @param SE The Scalar Evolution pass used by @p S.
383/// @param GenFn The function to generate code in. Can be the same as @p SE.
384/// @param GenSE The Scalar Evolution pass for @p GenFn.
385/// @param DL The module data layout.
386/// @param Name The suffix added to the new instruction names.
387/// @param E The expression for which code is actually generated.
388/// @param Ty The type of the resulting code.
389/// @param IP The insertion point for the new code.
390/// @param VMap A remapping of values used in @p E.
391/// @param LoopMap A remapping of loops used in @p E.
392/// @param RTCBB The last block of the RTC. Used to insert loop-invariant
393/// instructions in rare cases.
394llvm::Value *expandCodeFor(Scop &S, llvm::ScalarEvolution &SE,
395 llvm::Function *GenFn, llvm::ScalarEvolution &GenSE,
396 const llvm::DataLayout &DL, const char *Name,
397 const llvm::SCEV *E, llvm::Type *Ty,
398 llvm::BasicBlock::iterator IP, ValueMapT *VMap,
399 LoopToScevMapT *LoopMap, llvm::BasicBlock *RTCBB);
400
401/// Return the condition for the terminator @p TI.
402///
403/// For unconditional branches the "i1 true" condition will be returned.
404///
405/// @param TI The terminator to get the condition from.
406///
407/// @return The condition of @p TI and nullptr if none could be extracted.
408llvm::Value *getConditionFromTerminator(llvm::Instruction *TI);
409
410/// Get the smallest loop that contains @p S but is not in @p S.
411llvm::Loop *getLoopSurroundingScop(Scop &S, llvm::LoopInfo &LI);
412
413/// Get the number of blocks in @p L.
414///
415/// The number of blocks in a loop are the number of basic blocks actually
416/// belonging to the loop, as well as all single basic blocks that the loop
417/// exits to and which terminate in an unreachable instruction. We do not
418/// allow such basic blocks in the exit of a scop, hence they belong to the
419/// scop and represent run-time conditions which we want to model and
420/// subsequently speculate away.
421///
422/// @see getRegionNodeLoop for additional details.
423unsigned getNumBlocksInLoop(llvm::Loop *L);
424
425/// Get the number of blocks in @p RN.
426unsigned getNumBlocksInRegionNode(llvm::RegionNode *RN);
427
428/// Return the smallest loop surrounding @p RN.
429llvm::Loop *getRegionNodeLoop(llvm::RegionNode *RN, llvm::LoopInfo &LI);
430
431/// Check if @p LInst can be hoisted in @p R.
432///
433/// @param LInst The load to check.
434/// @param R The analyzed region.
435/// @param LI The loop info.
436/// @param SE The scalar evolution analysis.
437/// @param DT The dominator tree of the function.
438/// @param KnownInvariantLoads The invariant load set.
439///
440/// @return True if @p LInst can be hoisted in @p R.
441bool isHoistableLoad(llvm::LoadInst *LInst, llvm::Region &R, llvm::LoopInfo &LI,
442 llvm::ScalarEvolution &SE, const llvm::DominatorTree &DT,
443 const InvariantLoadsSetTy &KnownInvariantLoads);
444
445/// Return true iff @p V is an intrinsic that we ignore during code
446/// generation.
447bool isIgnoredIntrinsic(const llvm::Value *V);
448
449/// Check whether a value an be synthesized by the code generator.
450///
451/// Some value will be recalculated only from information that is code generated
452/// from the polyhedral representation. For such instructions we do not need to
453/// ensure that their operands are available during code generation.
454///
455/// @param V The value to check.
456/// @param S The current SCoP.
457/// @param SE The scalar evolution database.
458/// @param Scope Location where the value would by synthesized.
459/// @return If the instruction I can be regenerated from its
460/// scalar evolution representation, return true,
461/// otherwise return false.
462bool canSynthesize(const llvm::Value *V, const Scop &S,
463 llvm::ScalarEvolution *SE, llvm::Loop *Scope);
464
465/// Return the block in which a value is used.
466///
467/// For normal instructions, this is the instruction's parent block. For PHI
468/// nodes, this is the incoming block of that use, because this is where the
469/// operand must be defined (i.e. its definition dominates this block).
470/// Non-instructions do not use operands at a specific point such that in this
471/// case this function returns nullptr.
472llvm::BasicBlock *getUseBlock(const llvm::Use &U);
473
474// If the loop is nonaffine/boxed, return the first non-boxed surrounding loop
475// for Polly. If the loop is affine, return the loop itself.
476//
477// @param L Pointer to the Loop object to analyze.
478// @param LI Reference to the LoopInfo.
479// @param BoxedLoops Set of Boxed Loops we get from the SCoP.
480llvm::Loop *getFirstNonBoxedLoopFor(llvm::Loop *L, llvm::LoopInfo &LI,
481 const BoxedLoopsSetTy &BoxedLoops);
482
483// If the Basic Block belongs to a loop that is nonaffine/boxed, return the
484// first non-boxed surrounding loop for Polly. If the loop is affine, return
485// the loop itself.
486//
487// @param BB Pointer to the Basic Block to analyze.
488// @param LI Reference to the LoopInfo.
489// @param BoxedLoops Set of Boxed Loops we get from the SCoP.
490llvm::Loop *getFirstNonBoxedLoopFor(llvm::BasicBlock *BB, llvm::LoopInfo &LI,
491 const BoxedLoopsSetTy &BoxedLoops);
492
493/// Is the given instruction a call to a debug function?
494///
495/// A debug function can be used to insert output in Polly-optimized code which
496/// normally does not allow function calls with side-effects. For instance, a
497/// printf can be inserted to check whether a value still has the expected value
498/// after Polly generated code:
499///
500/// int sum = 0;
501/// for (int i = 0; i < 16; i+=1) {
502/// sum += i;
503/// printf("The value of sum at i=%d is %d\n", sum, i);
504/// }
505bool isDebugCall(llvm::Instruction *Inst);
506
507/// Does the statement contain a call to a debug function?
508///
509/// Such a statement must not be removed, even if has no side-effects.
510bool hasDebugCall(ScopStmt *Stmt);
511
512/// Find a property value in a LoopID.
513///
514/// Generally, a property MDNode has the format
515///
516/// !{ !"Name", value }
517///
518/// In which case the value is returned.
519///
520/// If the property is just
521///
522/// !{ !"Name" }
523///
524/// Then `nullptr` is set to mark the property is existing, but does not carry
525/// any value. If the property does not exist, `std::nullopt` is returned.
526std::optional<llvm::Metadata *> findMetadataOperand(llvm::MDNode *LoopMD,
527 llvm::StringRef Name);
528
529/// Find a boolean property value in a LoopID. The value not being defined is
530/// interpreted as a false value.
531bool getBooleanLoopAttribute(llvm::MDNode *LoopID, llvm::StringRef Name);
532
533/// Find an integers property value in a LoopID.
534std::optional<int> getOptionalIntLoopAttribute(llvm::MDNode *LoopID,
535 llvm::StringRef Name);
536
537/// Does the loop's LoopID contain a 'llvm.loop.disable_heuristics' property?
538///
539/// This is equivalent to llvm::hasDisableAllTransformsHint(Loop*), but
540/// including the LoopUtils.h header indirectly also declares llvm::MemoryAccess
541/// which clashes with polly::MemoryAccess. Declaring this alias here avoid
542/// having to include LoopUtils.h in other files.
543bool hasDisableAllTransformsHint(llvm::Loop *L);
544bool hasDisableAllTransformsHint(llvm::MDNode *LoopID);
545
546/// Represent the attributes of a loop.
547struct BandAttr {
548 /// LoopID which stores the properties of the loop, such as transformations to
549 /// apply and the metadata of followup-loops.
550 ///
551 /// Cannot be used to identify a loop. Two different loops can have the same
552 /// metadata.
553 llvm::MDNode *Metadata = nullptr;
554
555 /// The LoopInfo reference for this loop.
556 ///
557 /// Only loops from the original IR are represented by LoopInfo. Loops that
558 /// were generated by Polly are not tracked by LoopInfo.
559 llvm::Loop *OriginalLoop = nullptr;
560};
561
562/// Get an isl::id representing a loop.
563///
564/// This takes the ownership of the BandAttr and will be free'd when the
565/// returned isl::Id is free'd.
567
568/// Create an isl::id that identifies an original loop.
569///
570/// Return nullptr if the loop does not need a BandAttr (i.e. has no
571/// properties);
572///
573/// This creates a BandAttr which must be unique per loop and therefore this
574/// must not be called multiple times on the same loop as their id would be
575/// different.
577
578/// Is @p Id representing a loop?
579///
580/// Such ids contain a polly::BandAttr as its user pointer.
581bool isLoopAttr(const isl::id &Id);
582
583/// Return the BandAttr of a loop's isl::id.
584BandAttr *getLoopAttr(const isl::id &Id);
585
586} // namespace polly
587#endif
Utility proxy to wrap the common members of LoadInst and StoreInst.
Definition ScopHelper.h:141
llvm::Instruction * asInstruction() const
Definition ScopHelper.h:309
bool isMemIntrinsic() const
Definition ScopHelper.h:314
MemAccInst(llvm::LoadInst *LI)
Definition ScopHelper.h:149
static MemAccInst cast_or_null(llvm::Value &V)
Definition ScopHelper.h:171
MemAccInst & operator=(llvm::MemIntrinsic *MI)
Definition ScopHelper.h:215
llvm::MemSetInst * asMemSetInst() const
Definition ScopHelper.h:326
static bool isa(const llvm::Value *V)
Definition ScopHelper.h:161
static MemAccInst dyn_cast(llvm::Value *V)
Definition ScopHelper.h:184
llvm::CallInst * asCallInst() const
Definition ScopHelper.h:322
MemAccInst(llvm::StoreInst *SI)
Definition ScopHelper.h:151
MemAccInst & operator=(llvm::CallInst *CI)
Definition ScopHelper.h:223
llvm::StoreInst * asStore() const
Definition ScopHelper.h:321
MemAccInst(llvm::MemIntrinsic *MI)
Definition ScopHelper.h:152
llvm::Instruction * get() const
Definition ScopHelper.h:228
llvm::MemTransferInst * asMemTransferInst() const
Definition ScopHelper.h:329
llvm::LoadInst * asLoad() const
Definition ScopHelper.h:320
bool isVolatile() const
Definition ScopHelper.h:260
MemAccInst & operator=(llvm::StoreInst *SI)
Definition ScopHelper.h:207
MemAccInst(llvm::Instruction &I)
Definition ScopHelper.h:154
static MemAccInst cast(llvm::Value *V)
Definition ScopHelper.h:168
llvm::AtomicOrdering getOrdering() const
Definition ScopHelper.h:282
llvm::Instruction * operator->() const
Definition ScopHelper.h:233
llvm::Value * getValueOperand() const
Definition ScopHelper.h:238
MemAccInst & operator=(llvm::CallInst &CI)
Definition ScopHelper.h:219
bool isLoad() const
Definition ScopHelper.h:311
MemAccInst(const MemAccInst &Inst)
Definition ScopHelper.h:147
static MemAccInst dyn_cast(llvm::Value &V)
Definition ScopHelper.h:179
MemAccInst & operator=(llvm::LoadInst &LI)
Definition ScopHelper.h:195
bool isUnordered() const
Definition ScopHelper.h:293
bool isNull() const
Definition ScopHelper.h:306
MemAccInst(llvm::LoadInst &LI)
Definition ScopHelper.h:148
bool isCallInst() const
Definition ScopHelper.h:313
bool operator!() const
Definition ScopHelper.h:236
MemAccInst & operator=(llvm::StoreInst &SI)
Definition ScopHelper.h:203
bool isMemTransferInst() const
Definition ScopHelper.h:316
llvm::MemIntrinsic * asMemIntrinsic() const
Definition ScopHelper.h:323
MemAccInst & operator=(llvm::LoadInst *LI)
Definition ScopHelper.h:199
static MemAccInst cast(llvm::Value &V)
Definition ScopHelper.h:165
MemAccInst & operator=(const MemAccInst &Inst)
Definition ScopHelper.h:191
MemAccInst(llvm::Instruction *I)
Definition ScopHelper.h:155
MemAccInst & operator=(llvm::MemIntrinsic &MI)
Definition ScopHelper.h:211
static bool isa(const llvm::Value &V)
Definition ScopHelper.h:157
bool isStore() const
Definition ScopHelper.h:312
llvm::Instruction * I
Definition ScopHelper.h:143
static MemAccInst cast_or_null(llvm::Value *V)
Definition ScopHelper.h:174
bool isMemSetInst() const
Definition ScopHelper.h:315
bool isSimple() const
Definition ScopHelper.h:271
MemAccInst(llvm::CallInst *CI)
Definition ScopHelper.h:153
llvm::Value * getPointerOperand() const
Definition ScopHelper.h:249
bool isInstruction() const
Definition ScopHelper.h:307
MemAccInst(llvm::StoreInst &SI)
Definition ScopHelper.h:150
Statement of the Scop.
Definition ScopInfo.h:1135
Static Control Part.
Definition ScopInfo.h:1625
#define S(TYPE, NAME)
#define assert(exp)
llvm::Loop * getRegionNodeLoop(llvm::RegionNode *RN, llvm::LoopInfo &LI)
Return the smallest loop surrounding RN.
llvm::Value * getConditionFromTerminator(llvm::Instruction *TI)
Return the condition for the terminator TI.
bool isLoopAttr(const isl::id &Id)
Is Id representing a loop?
std::optional< llvm::Metadata * > findMetadataOperand(llvm::MDNode *LoopMD, llvm::StringRef Name)
Find a property value in a LoopID.
llvm::SetVector< llvm::AssertingVH< llvm::LoadInst > > InvariantLoadsSetTy
Type for a set of invariant loads.
Definition ScopHelper.h:110
llvm::SetVector< const llvm::SCEV * > ParameterSetTy
Set type for parameters.
Definition ScopHelper.h:113
llvm::Value * expandCodeFor(Scop &S, llvm::ScalarEvolution &SE, llvm::Function *GenFn, llvm::ScalarEvolution &GenSE, const llvm::DataLayout &DL, const char *Name, const llvm::SCEV *E, llvm::Type *Ty, llvm::BasicBlock::iterator IP, ValueMapT *VMap, LoopToScevMapT *LoopMap, llvm::BasicBlock *RTCBB)
Wrapper for SCEVExpander extended to all Polly features.
unsigned getNumBlocksInRegionNode(llvm::RegionNode *RN)
Get the number of blocks in RN.
llvm::Loop * getFirstNonBoxedLoopFor(llvm::Loop *L, llvm::LoopInfo &LI, const BoxedLoopsSetTy &BoxedLoops)
AssumptionSign
Enum to distinguish between assumptions and restrictions.
Definition ScopHelper.h:58
@ AS_RESTRICTION
Definition ScopHelper.h:58
@ AS_ASSUMPTION
Definition ScopHelper.h:58
void splitEntryBlockForAlloca(llvm::BasicBlock *EntryBlock, llvm::DominatorTree *DT, llvm::LoopInfo *LI, llvm::RegionInfo *RI)
Split the entry block of a function to store the newly inserted allocations outside of all Scops.
bool hasDisableAllTransformsHint(llvm::Loop *L)
Does the loop's LoopID contain a 'llvm.loop.disable_heuristics' property?
std::optional< int > getOptionalIntLoopAttribute(llvm::MDNode *LoopID, llvm::StringRef Name)
Find an integers property value in a LoopID.
bool isDebugCall(llvm::Instruction *Inst)
Is the given instruction a call to a debug function?
bool hasDebugCall(ScopStmt *Stmt)
Does the statement contain a call to a debug function?
BandAttr * getLoopAttr(const isl::id &Id)
Return the BandAttr of a loop's isl::id.
llvm::BasicBlock * getUseBlock(const llvm::Use &U)
Return the block in which a value is used.
llvm::Loop * getLoopSurroundingScop(Scop &S, llvm::LoopInfo &LI)
Get the smallest loop that contains S but is not in S.
void recordAssumption(RecordedAssumptionsTy *RecordedAssumptions, AssumptionKind Kind, isl::set Set, llvm::DebugLoc Loc, AssumptionSign Sign, llvm::BasicBlock *BB=nullptr, bool RTC=true)
Record an assumption for later addition to the assumed context.
llvm::DenseMap< const llvm::Loop *, llvm::SCEVUse > LoopToScevMapT
Same as llvm/Analysis/ScalarEvolutionExpressions.h.
Definition ScopHelper.h:41
isl::id getIslLoopAttr(isl::ctx Ctx, BandAttr *Attr)
Get an isl::id representing a loop.
llvm::SetVector< const llvm::Loop * > BoxedLoopsSetTy
Set of loops (used to remember loops in non-affine subregions).
Definition ScopHelper.h:116
bool isHoistableLoad(llvm::LoadInst *LInst, llvm::Region &R, llvm::LoopInfo &LI, llvm::ScalarEvolution &SE, const llvm::DominatorTree &DT, const InvariantLoadsSetTy &KnownInvariantLoads)
Check if LInst can be hoisted in R.
isl::id createIslLoopAttr(isl::ctx Ctx, llvm::Loop *L)
Create an isl::id that identifies an original loop.
llvm::SmallVector< Assumption, 8 > RecordedAssumptionsTy
Definition ScopHelper.h:81
llvm::DenseMap< llvm::AssertingVH< llvm::Value >, llvm::AssertingVH< llvm::Value > > ValueMapT
Type to remap values.
Definition ScopHelper.h:106
AssumptionKind
Enumeration of assumptions Polly can take.
Definition ScopHelper.h:44
@ WRAPPING
Definition ScopHelper.h:47
@ INFINITELOOP
Definition ScopHelper.h:52
@ ERRORBLOCK
Definition ScopHelper.h:50
@ INVARIANTLOAD
Definition ScopHelper.h:53
@ COMPLEXITY
Definition ScopHelper.h:51
@ ALIASING
Definition ScopHelper.h:45
@ PROFITABLE
Definition ScopHelper.h:49
@ INBOUNDS
Definition ScopHelper.h:46
@ DELINEARIZATION
Definition ScopHelper.h:54
@ UNSIGNED
Definition ScopHelper.h:48
bool isIgnoredIntrinsic(const llvm::Value *V)
Return true iff V is an intrinsic that we ignore during code generation.
void simplifyRegion(llvm::Region *R, llvm::DominatorTree *DT, llvm::LoopInfo *LI, llvm::RegionInfo *RI)
Simplify the region to have a single unconditional entry edge and a single exit edge.
bool canSynthesize(const llvm::Value *V, const Scop &S, llvm::ScalarEvolution *SE, llvm::Loop *Scope)
Check whether a value an be synthesized by the code generator.
bool getBooleanLoopAttribute(llvm::MDNode *LoopID, llvm::StringRef Name)
Find a boolean property value in a LoopID.
unsigned getNumBlocksInLoop(llvm::Loop *L)
Get the number of blocks in L.
static SimpleType getSimplifiedValue(polly::MemAccInst &I)
Definition ScopHelper.h:340
Helper struct to remember assumptions.
Definition ScopHelper.h:61
llvm::DebugLoc Loc
The location that caused this assumption.
Definition ScopHelper.h:72
AssumptionKind Kind
The kind of the assumption (e.g., WRAPPING).
Definition ScopHelper.h:63
llvm::BasicBlock * BB
An optional block whose domain can simplify the assumption.
Definition ScopHelper.h:75
AssumptionSign Sign
Flag to distinguish assumptions and restrictions.
Definition ScopHelper.h:66
isl::set Set
The valid/invalid context if this is an assumption/restriction.
Definition ScopHelper.h:69
Represent the attributes of a loop.
Definition ScopHelper.h:547
llvm::MDNode * Metadata
LoopID which stores the properties of the loop, such as transformations to apply and the metadata of ...
Definition ScopHelper.h:553
llvm::Loop * OriginalLoop
The LoopInfo reference for this loop.
Definition ScopHelper.h:559
static TupleKindPtr Ctx