LLVM  17.0.0git
OMPIRBuilder.h
Go to the documentation of this file.
1 //===- IR/OpenMPIRBuilder.h - OpenMP encoding builder for LLVM IR - C++ -*-===//
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 defines the OpenMPIRBuilder class and helpers used as a convenient
10 // way to create LLVM instructions for OpenMP directives.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
15 #define LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
16 
19 #include "llvm/IR/DebugLoc.h"
20 #include "llvm/IR/IRBuilder.h"
21 #include "llvm/Support/Allocator.h"
22 #include <forward_list>
23 #include <map>
24 #include <optional>
25 
26 namespace llvm {
27 class CanonicalLoopInfo;
28 struct TargetRegionEntryInfo;
29 class OffloadEntriesInfoManager;
30 
31 /// Move the instruction after an InsertPoint to the beginning of another
32 /// BasicBlock.
33 ///
34 /// The instructions after \p IP are moved to the beginning of \p New which must
35 /// not have any PHINodes. If \p CreateBranch is true, a branch instruction to
36 /// \p New will be added such that there is no semantic change. Otherwise, the
37 /// \p IP insert block remains degenerate and it is up to the caller to insert a
38 /// terminator.
39 void spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New,
40  bool CreateBranch);
41 
42 /// Splice a BasicBlock at an IRBuilder's current insertion point. Its new
43 /// insert location will stick to after the instruction before the insertion
44 /// point (instead of moving with the instruction the InsertPoint stores
45 /// internally).
46 void spliceBB(IRBuilder<> &Builder, BasicBlock *New, bool CreateBranch);
47 
48 /// Split a BasicBlock at an InsertPoint, even if the block is degenerate
49 /// (missing the terminator).
50 ///
51 /// llvm::SplitBasicBlock and BasicBlock::splitBasicBlock require a well-formed
52 /// BasicBlock. \p Name is used for the new successor block. If \p CreateBranch
53 /// is true, a branch to the new successor will new created such that
54 /// semantically there is no change; otherwise the block of the insertion point
55 /// remains degenerate and it is the caller's responsibility to insert a
56 /// terminator. Returns the new successor block.
57 BasicBlock *splitBB(IRBuilderBase::InsertPoint IP, bool CreateBranch,
58  llvm::Twine Name = {});
59 
60 /// Split a BasicBlock at \p Builder's insertion point, even if the block is
61 /// degenerate (missing the terminator). Its new insert location will stick to
62 /// after the instruction before the insertion point (instead of moving with the
63 /// instruction the InsertPoint stores internally).
64 BasicBlock *splitBB(IRBuilderBase &Builder, bool CreateBranch,
65  llvm::Twine Name = {});
66 
67 /// Split a BasicBlock at \p Builder's insertion point, even if the block is
68 /// degenerate (missing the terminator). Its new insert location will stick to
69 /// after the instruction before the insertion point (instead of moving with the
70 /// instruction the InsertPoint stores internally).
71 BasicBlock *splitBB(IRBuilder<> &Builder, bool CreateBranch, llvm::Twine Name);
72 
73 /// Like splitBB, but reuses the current block's name for the new name.
74 BasicBlock *splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
75  llvm::Twine Suffix = ".split");
76 
77 /// Captures attributes that affect generating LLVM-IR using the
78 /// OpenMPIRBuilder and related classes. Note that not all attributes are
79 /// required for all classes or functions. In some use cases the configuration
80 /// is not necessary at all, because because the only functions that are called
81 /// are ones that are not dependent on the configuration.
83 public:
84  /// Flag for specifying if the compilation is done for embedded device code
85  /// or host code.
86  std::optional<bool> IsEmbedded;
87 
88  /// Flag for specifying if the compilation is done for an offloading target,
89  /// like GPU.
90  std::optional<bool> IsTargetCodegen;
91 
92  /// Flag for specifying weather a requires unified_shared_memory
93  /// directive is present or not.
94  std::optional<bool> HasRequiresUnifiedSharedMemory;
95 
96  // Flag for specifying if offloading is mandatory.
97  std::optional<bool> OpenMPOffloadMandatory;
98 
99  /// First separator used between the initial two parts of a name.
100  std::optional<StringRef> FirstSeparator;
101  /// Separator used between all of the rest consecutive parts of s name
102  std::optional<StringRef> Separator;
103 
111 
112  // Getters functions that assert if the required values are not present.
113  bool isEmbedded() const {
114  assert(IsEmbedded.has_value() && "IsEmbedded is not set");
115  return *IsEmbedded;
116  }
117 
118  bool isTargetCodegen() const {
119  assert(IsTargetCodegen.has_value() && "IsTargetCodegen is not set");
120  return *IsTargetCodegen;
121  }
122 
125  "HasUnifiedSharedMemory is not set");
127  }
128 
129  bool openMPOffloadMandatory() const {
130  assert(OpenMPOffloadMandatory.has_value() &&
131  "OpenMPOffloadMandatory is not set");
132  return *OpenMPOffloadMandatory;
133  }
134  // Returns the FirstSeparator if set, otherwise use the default
135  // separator depending on isTargetCodegen
137  if (FirstSeparator.has_value())
138  return *FirstSeparator;
139  if (isTargetCodegen())
140  return "_";
141  return ".";
142  }
143 
144  // Returns the Separator if set, otherwise use the default
145  // separator depending on isTargetCodegen
147  if (Separator.has_value())
148  return *Separator;
149  if (isTargetCodegen())
150  return "$";
151  return ".";
152  }
153 
158  }
161 };
162 
163 /// An interface to create LLVM-IR for OpenMP directives.
164 ///
165 /// Each OpenMP directive has a corresponding public generator method.
167 public:
168  /// Create a new OpenMPIRBuilder operating on the given module \p M. This will
169  /// not have an effect on \p M (see initialize)
170  OpenMPIRBuilder(Module &M) : M(M), Builder(M.getContext()) {}
172 
173  /// Initialize the internal state, this will put structures types and
174  /// potentially other helpers into the underlying module. Must be called
175  /// before any other method and only once!
176  void initialize();
177 
179 
180  /// Finalize the underlying module, e.g., by outlining regions.
181  /// \param Fn The function to be finalized. If not used,
182  /// all functions are finalized.
183  void finalize(Function *Fn = nullptr);
184 
185  /// Add attributes known for \p FnID to \p Fn.
187 
188  /// Type used throughout for insertion points.
190 
191  /// Get the create a name using the platform specific separators.
192  /// \param Parts parts of the final name that needs separation
193  /// The created name has a first separator between the first and second part
194  /// and a second separator between all other parts.
195  /// E.g. with FirstSeparator "$" and Separator "." and
196  /// parts: "p1", "p2", "p3", "p4"
197  /// The resulting name is "p1$p2.p3.p4"
198  /// The separators are retrieved from the OpenMPIRBuilderConfig.
199  std::string createPlatformSpecificName(ArrayRef<StringRef> Parts) const;
200 
201  /// Callback type for variable finalization (think destructors).
202  ///
203  /// \param CodeGenIP is the insertion point at which the finalization code
204  /// should be placed.
205  ///
206  /// A finalize callback knows about all objects that need finalization, e.g.
207  /// destruction, when the scope of the currently generated construct is left
208  /// at the time, and location, the callback is invoked.
210 
212  /// The finalization callback provided by the last in-flight invocation of
213  /// createXXXX for the directive of kind DK.
215 
216  /// The directive kind of the innermost directive that has an associated
217  /// region which might require finalization when it is left.
218  omp::Directive DK;
219 
220  /// Flag to indicate if the directive is cancellable.
222  };
223 
224  /// Push a finalization callback on the finalization stack.
225  ///
226  /// NOTE: Temporary solution until Clang CG is gone.
228  FinalizationStack.push_back(FI);
229  }
230 
231  /// Pop the last finalization callback from the finalization stack.
232  ///
233  /// NOTE: Temporary solution until Clang CG is gone.
234  void popFinalizationCB() { FinalizationStack.pop_back(); }
235 
236  /// Callback type for body (=inner region) code generation
237  ///
238  /// The callback takes code locations as arguments, each describing a
239  /// location where additional instructions can be inserted.
240  ///
241  /// The CodeGenIP may be in the middle of a basic block or point to the end of
242  /// it. The basic block may have a terminator or be degenerate. The callback
243  /// function may just insert instructions at that position, but also split the
244  /// block (without the Before argument of BasicBlock::splitBasicBlock such
245  /// that the identify of the split predecessor block is preserved) and insert
246  /// additional control flow, including branches that do not lead back to what
247  /// follows the CodeGenIP. Note that since the callback is allowed to split
248  /// the block, callers must assume that InsertPoints to positions in the
249  /// BasicBlock after CodeGenIP including CodeGenIP itself are invalidated. If
250  /// such InsertPoints need to be preserved, it can split the block itself
251  /// before calling the callback.
252  ///
253  /// AllocaIP and CodeGenIP must not point to the same position.
254  ///
255  /// \param AllocaIP is the insertion point at which new alloca instructions
256  /// should be placed. The BasicBlock it is pointing to must
257  /// not be split.
258  /// \param CodeGenIP is the insertion point at which the body code should be
259  /// placed.
260  using BodyGenCallbackTy =
261  function_ref<void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
262 
263  // This is created primarily for sections construct as llvm::function_ref
264  // (BodyGenCallbackTy) is not storable (as described in the comments of
265  // function_ref class - function_ref contains non-ownable reference
266  // to the callable.
268  std::function<void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
269 
270  /// Callback type for loop body code generation.
271  ///
272  /// \param CodeGenIP is the insertion point where the loop's body code must be
273  /// placed. This will be a dedicated BasicBlock with a
274  /// conditional branch from the loop condition check and
275  /// terminated with an unconditional branch to the loop
276  /// latch.
277  /// \param IndVar is the induction variable usable at the insertion point.
278  using LoopBodyGenCallbackTy =
279  function_ref<void(InsertPointTy CodeGenIP, Value *IndVar)>;
280 
281  /// Callback type for variable privatization (think copy & default
282  /// constructor).
283  ///
284  /// \param AllocaIP is the insertion point at which new alloca instructions
285  /// should be placed.
286  /// \param CodeGenIP is the insertion point at which the privatization code
287  /// should be placed.
288  /// \param Original The value being copied/created, should not be used in the
289  /// generated IR.
290  /// \param Inner The equivalent of \p Original that should be used in the
291  /// generated IR; this is equal to \p Original if the value is
292  /// a pointer and can thus be passed directly, otherwise it is
293  /// an equivalent but different value.
294  /// \param ReplVal The replacement value, thus a copy or new created version
295  /// of \p Inner.
296  ///
297  /// \returns The new insertion point where code generation continues and
298  /// \p ReplVal the replacement value.
300  InsertPointTy AllocaIP, InsertPointTy CodeGenIP, Value &Original,
301  Value &Inner, Value *&ReplVal)>;
302 
303  /// Description of a LLVM-IR insertion point (IP) and a debug/source location
304  /// (filename, line, column, ...).
307  : IP(IRB.saveIP()), DL(IRB.getCurrentDebugLocation()) {}
310  : IP(IP), DL(DL) {}
313  };
314 
315  /// Emitter methods for OpenMP directives.
316  ///
317  ///{
318 
319  /// Generator for '#omp barrier'
320  ///
321  /// \param Loc The location where the barrier directive was encountered.
322  /// \param DK The kind of directive that caused the barrier.
323  /// \param ForceSimpleCall Flag to force a simple (=non-cancellation) barrier.
324  /// \param CheckCancelFlag Flag to indicate a cancel barrier return value
325  /// should be checked and acted upon.
326  ///
327  /// \returns The insertion point after the barrier.
328  InsertPointTy createBarrier(const LocationDescription &Loc, omp::Directive DK,
329  bool ForceSimpleCall = false,
330  bool CheckCancelFlag = true);
331 
332  /// Generator for '#omp cancel'
333  ///
334  /// \param Loc The location where the directive was encountered.
335  /// \param IfCondition The evaluated 'if' clause expression, if any.
336  /// \param CanceledDirective The kind of directive that is cancled.
337  ///
338  /// \returns The insertion point after the barrier.
339  InsertPointTy createCancel(const LocationDescription &Loc, Value *IfCondition,
340  omp::Directive CanceledDirective);
341 
342  /// Generator for '#omp parallel'
343  ///
344  /// \param Loc The insert and source location description.
345  /// \param AllocaIP The insertion points to be used for alloca instructions.
346  /// \param BodyGenCB Callback that will generate the region code.
347  /// \param PrivCB Callback to copy a given variable (think copy constructor).
348  /// \param FiniCB Callback to finalize variable copies.
349  /// \param IfCondition The evaluated 'if' clause expression, if any.
350  /// \param NumThreads The evaluated 'num_threads' clause expression, if any.
351  /// \param ProcBind The value of the 'proc_bind' clause (see ProcBindKind).
352  /// \param IsCancellable Flag to indicate a cancellable parallel region.
353  ///
354  /// \returns The insertion position *after* the parallel.
356  createParallel(const LocationDescription &Loc, InsertPointTy AllocaIP,
357  BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
358  FinalizeCallbackTy FiniCB, Value *IfCondition,
359  Value *NumThreads, omp::ProcBindKind ProcBind,
360  bool IsCancellable);
361 
362  /// Generator for the control flow structure of an OpenMP canonical loop.
363  ///
364  /// This generator operates on the logical iteration space of the loop, i.e.
365  /// the caller only has to provide a loop trip count of the loop as defined by
366  /// base language semantics. The trip count is interpreted as an unsigned
367  /// integer. The induction variable passed to \p BodyGenCB will be of the same
368  /// type and run from 0 to \p TripCount - 1. It is up to the callback to
369  /// convert the logical iteration variable to the loop counter variable in the
370  /// loop body.
371  ///
372  /// \param Loc The insert and source location description. The insert
373  /// location can be between two instructions or the end of a
374  /// degenerate block (e.g. a BB under construction).
375  /// \param BodyGenCB Callback that will generate the loop body code.
376  /// \param TripCount Number of iterations the loop body is executed.
377  /// \param Name Base name used to derive BB and instruction names.
378  ///
379  /// \returns An object representing the created control flow structure which
380  /// can be used for loop-associated directives.
382  LoopBodyGenCallbackTy BodyGenCB,
383  Value *TripCount,
384  const Twine &Name = "loop");
385 
386  /// Generator for the control flow structure of an OpenMP canonical loop.
387  ///
388  /// Instead of a logical iteration space, this allows specifying user-defined
389  /// loop counter values using increment, upper- and lower bounds. To
390  /// disambiguate the terminology when counting downwards, instead of lower
391  /// bounds we use \p Start for the loop counter value in the first body
392  /// iteration.
393  ///
394  /// Consider the following limitations:
395  ///
396  /// * A loop counter space over all integer values of its bit-width cannot be
397  /// represented. E.g using uint8_t, its loop trip count of 256 cannot be
398  /// stored into an 8 bit integer):
399  ///
400  /// DO I = 0, 255, 1
401  ///
402  /// * Unsigned wrapping is only supported when wrapping only "once"; E.g.
403  /// effectively counting downwards:
404  ///
405  /// for (uint8_t i = 100u; i > 0; i += 127u)
406  ///
407  ///
408  /// TODO: May need to add additional parameters to represent:
409  ///
410  /// * Allow representing downcounting with unsigned integers.
411  ///
412  /// * Sign of the step and the comparison operator might disagree:
413  ///
414  /// for (int i = 0; i < 42; i -= 1u)
415  ///
416  //
417  /// \param Loc The insert and source location description.
418  /// \param BodyGenCB Callback that will generate the loop body code.
419  /// \param Start Value of the loop counter for the first iterations.
420  /// \param Stop Loop counter values past this will stop the loop.
421  /// \param Step Loop counter increment after each iteration; negative
422  /// means counting down.
423  /// \param IsSigned Whether Start, Stop and Step are signed integers.
424  /// \param InclusiveStop Whether \p Stop itself is a valid value for the loop
425  /// counter.
426  /// \param ComputeIP Insertion point for instructions computing the trip
427  /// count. Can be used to ensure the trip count is available
428  /// at the outermost loop of a loop nest. If not set,
429  /// defaults to the preheader of the generated loop.
430  /// \param Name Base name used to derive BB and instruction names.
431  ///
432  /// \returns An object representing the created control flow structure which
433  /// can be used for loop-associated directives.
435  LoopBodyGenCallbackTy BodyGenCB,
436  Value *Start, Value *Stop, Value *Step,
437  bool IsSigned, bool InclusiveStop,
438  InsertPointTy ComputeIP = {},
439  const Twine &Name = "loop");
440 
441  /// Collapse a loop nest into a single loop.
442  ///
443  /// Merges loops of a loop nest into a single CanonicalLoopNest representation
444  /// that has the same number of innermost loop iterations as the origin loop
445  /// nest. The induction variables of the input loops are derived from the
446  /// collapsed loop's induction variable. This is intended to be used to
447  /// implement OpenMP's collapse clause. Before applying a directive,
448  /// collapseLoops normalizes a loop nest to contain only a single loop and the
449  /// directive's implementation does not need to handle multiple loops itself.
450  /// This does not remove the need to handle all loop nest handling by
451  /// directives, such as the ordered(<n>) clause or the simd schedule-clause
452  /// modifier of the worksharing-loop directive.
453  ///
454  /// Example:
455  /// \code
456  /// for (int i = 0; i < 7; ++i) // Canonical loop "i"
457  /// for (int j = 0; j < 9; ++j) // Canonical loop "j"
458  /// body(i, j);
459  /// \endcode
460  ///
461  /// After collapsing with Loops={i,j}, the loop is changed to
462  /// \code
463  /// for (int ij = 0; ij < 63; ++ij) {
464  /// int i = ij / 9;
465  /// int j = ij % 9;
466  /// body(i, j);
467  /// }
468  /// \endcode
469  ///
470  /// In the current implementation, the following limitations apply:
471  ///
472  /// * All input loops have an induction variable of the same type.
473  ///
474  /// * The collapsed loop will have the same trip count integer type as the
475  /// input loops. Therefore it is possible that the collapsed loop cannot
476  /// represent all iterations of the input loops. For instance, assuming a
477  /// 32 bit integer type, and two input loops both iterating 2^16 times, the
478  /// theoretical trip count of the collapsed loop would be 2^32 iteration,
479  /// which cannot be represented in an 32-bit integer. Behavior is undefined
480  /// in this case.
481  ///
482  /// * The trip counts of every input loop must be available at \p ComputeIP.
483  /// Non-rectangular loops are not yet supported.
484  ///
485  /// * At each nest level, code between a surrounding loop and its nested loop
486  /// is hoisted into the loop body, and such code will be executed more
487  /// often than before collapsing (or not at all if any inner loop iteration
488  /// has a trip count of 0). This is permitted by the OpenMP specification.
489  ///
490  /// \param DL Debug location for instructions added for collapsing,
491  /// such as instructions to compute/derive the input loop's
492  /// induction variables.
493  /// \param Loops Loops in the loop nest to collapse. Loops are specified
494  /// from outermost-to-innermost and every control flow of a
495  /// loop's body must pass through its directly nested loop.
496  /// \param ComputeIP Where additional instruction that compute the collapsed
497  /// trip count. If not set, defaults to before the generated
498  /// loop.
499  ///
500  /// \returns The CanonicalLoopInfo object representing the collapsed loop.
503  InsertPointTy ComputeIP);
504 
505  /// Get the default alignment value for given target
506  ///
507  /// \param TargetTriple Target triple
508  /// \param Features StringMap which describes extra CPU features
509  static unsigned getOpenMPDefaultSimdAlign(const Triple &TargetTriple,
510  const StringMap<bool> &Features);
511 
512 private:
513  /// Modifies the canonical loop to be a statically-scheduled workshare loop.
514  ///
515  /// This takes a \p LoopInfo representing a canonical loop, such as the one
516  /// created by \p createCanonicalLoop and emits additional instructions to
517  /// turn it into a workshare loop. In particular, it calls to an OpenMP
518  /// runtime function in the preheader to obtain the loop bounds to be used in
519  /// the current thread, updates the relevant instructions in the canonical
520  /// loop and calls to an OpenMP runtime finalization function after the loop.
521  ///
522  /// \param DL Debug location for instructions added for the
523  /// workshare-loop construct itself.
524  /// \param CLI A descriptor of the canonical loop to workshare.
525  /// \param AllocaIP An insertion point for Alloca instructions usable in the
526  /// preheader of the loop.
527  /// \param NeedsBarrier Indicates whether a barrier must be inserted after
528  /// the loop.
529  ///
530  /// \returns Point where to insert code after the workshare construct.
531  InsertPointTy applyStaticWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI,
532  InsertPointTy AllocaIP,
533  bool NeedsBarrier);
534 
535  /// Modifies the canonical loop a statically-scheduled workshare loop with a
536  /// user-specified chunk size.
537  ///
538  /// \param DL Debug location for instructions added for the
539  /// workshare-loop construct itself.
540  /// \param CLI A descriptor of the canonical loop to workshare.
541  /// \param AllocaIP An insertion point for Alloca instructions usable in
542  /// the preheader of the loop.
543  /// \param NeedsBarrier Indicates whether a barrier must be inserted after the
544  /// loop.
545  /// \param ChunkSize The user-specified chunk size.
546  ///
547  /// \returns Point where to insert code after the workshare construct.
548  InsertPointTy applyStaticChunkedWorkshareLoop(DebugLoc DL,
549  CanonicalLoopInfo *CLI,
550  InsertPointTy AllocaIP,
551  bool NeedsBarrier,
552  Value *ChunkSize);
553 
554  /// Modifies the canonical loop to be a dynamically-scheduled workshare loop.
555  ///
556  /// This takes a \p LoopInfo representing a canonical loop, such as the one
557  /// created by \p createCanonicalLoop and emits additional instructions to
558  /// turn it into a workshare loop. In particular, it calls to an OpenMP
559  /// runtime function in the preheader to obtain, and then in each iteration
560  /// to update the loop counter.
561  ///
562  /// \param DL Debug location for instructions added for the
563  /// workshare-loop construct itself.
564  /// \param CLI A descriptor of the canonical loop to workshare.
565  /// \param AllocaIP An insertion point for Alloca instructions usable in the
566  /// preheader of the loop.
567  /// \param SchedType Type of scheduling to be passed to the init function.
568  /// \param NeedsBarrier Indicates whether a barrier must be insterted after
569  /// the loop.
570  /// \param Chunk The size of loop chunk considered as a unit when
571  /// scheduling. If \p nullptr, defaults to 1.
572  ///
573  /// \returns Point where to insert code after the workshare construct.
574  InsertPointTy applyDynamicWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI,
575  InsertPointTy AllocaIP,
576  omp::OMPScheduleType SchedType,
577  bool NeedsBarrier,
578  Value *Chunk = nullptr);
579 
580  /// Create alternative version of the loop to support if clause
581  ///
582  /// OpenMP if clause can require to generate second loop. This loop
583  /// will be executed when if clause condition is not met. createIfVersion
584  /// adds branch instruction to the copied loop if \p ifCond is not met.
585  ///
586  /// \param Loop Original loop which should be versioned.
587  /// \param IfCond Value which corresponds to if clause condition
588  /// \param VMap Value to value map to define relation between
589  /// original and copied loop values and loop blocks.
590  /// \param NamePrefix Optional name prefix for if.then if.else blocks.
591  void createIfVersion(CanonicalLoopInfo *Loop, Value *IfCond,
592  ValueToValueMapTy &VMap, const Twine &NamePrefix = "");
593 
594 public:
595  /// Modifies the canonical loop to be a workshare loop.
596  ///
597  /// This takes a \p LoopInfo representing a canonical loop, such as the one
598  /// created by \p createCanonicalLoop and emits additional instructions to
599  /// turn it into a workshare loop. In particular, it calls to an OpenMP
600  /// runtime function in the preheader to obtain the loop bounds to be used in
601  /// the current thread, updates the relevant instructions in the canonical
602  /// loop and calls to an OpenMP runtime finalization function after the loop.
603  ///
604  /// The concrete transformation is done by applyStaticWorkshareLoop,
605  /// applyStaticChunkedWorkshareLoop, or applyDynamicWorkshareLoop, depending
606  /// on the value of \p SchedKind and \p ChunkSize.
607  ///
608  /// \param DL Debug location for instructions added for the
609  /// workshare-loop construct itself.
610  /// \param CLI A descriptor of the canonical loop to workshare.
611  /// \param AllocaIP An insertion point for Alloca instructions usable in the
612  /// preheader of the loop.
613  /// \param NeedsBarrier Indicates whether a barrier must be insterted after
614  /// the loop.
615  /// \param SchedKind Scheduling algorithm to use.
616  /// \param ChunkSize The chunk size for the inner loop.
617  /// \param HasSimdModifier Whether the simd modifier is present in the
618  /// schedule clause.
619  /// \param HasMonotonicModifier Whether the monotonic modifier is present in
620  /// the schedule clause.
621  /// \param HasNonmonotonicModifier Whether the nonmonotonic modifier is
622  /// present in the schedule clause.
623  /// \param HasOrderedClause Whether the (parameterless) ordered clause is
624  /// present.
625  ///
626  /// \returns Point where to insert code after the workshare construct.
628  DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
629  bool NeedsBarrier,
630  llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default,
631  Value *ChunkSize = nullptr, bool HasSimdModifier = false,
632  bool HasMonotonicModifier = false, bool HasNonmonotonicModifier = false,
633  bool HasOrderedClause = false);
634 
635  /// Tile a loop nest.
636  ///
637  /// Tiles the loops of \p Loops by the tile sizes in \p TileSizes. Loops in
638  /// \p/ Loops must be perfectly nested, from outermost to innermost loop
639  /// (i.e. Loops.front() is the outermost loop). The trip count llvm::Value
640  /// of every loop and every tile sizes must be usable in the outermost
641  /// loop's preheader. This implies that the loop nest is rectangular.
642  ///
643  /// Example:
644  /// \code
645  /// for (int i = 0; i < 15; ++i) // Canonical loop "i"
646  /// for (int j = 0; j < 14; ++j) // Canonical loop "j"
647  /// body(i, j);
648  /// \endcode
649  ///
650  /// After tiling with Loops={i,j} and TileSizes={5,7}, the loop is changed to
651  /// \code
652  /// for (int i1 = 0; i1 < 3; ++i1)
653  /// for (int j1 = 0; j1 < 2; ++j1)
654  /// for (int i2 = 0; i2 < 5; ++i2)
655  /// for (int j2 = 0; j2 < 7; ++j2)
656  /// body(i1*3+i2, j1*3+j2);
657  /// \endcode
658  ///
659  /// The returned vector are the loops {i1,j1,i2,j2}. The loops i1 and j1 are
660  /// referred to the floor, and the loops i2 and j2 are the tiles. Tiling also
661  /// handles non-constant trip counts, non-constant tile sizes and trip counts
662  /// that are not multiples of the tile size. In the latter case the tile loop
663  /// of the last floor-loop iteration will have fewer iterations than specified
664  /// as its tile size.
665  ///
666  ///
667  /// @param DL Debug location for instructions added by tiling, for
668  /// instance the floor- and tile trip count computation.
669  /// @param Loops Loops to tile. The CanonicalLoopInfo objects are
670  /// invalidated by this method, i.e. should not used after
671  /// tiling.
672  /// @param TileSizes For each loop in \p Loops, the tile size for that
673  /// dimensions.
674  ///
675  /// \returns A list of generated loops. Contains twice as many loops as the
676  /// input loop nest; the first half are the floor loops and the
677  /// second half are the tile loops.
678  std::vector<CanonicalLoopInfo *>
680  ArrayRef<Value *> TileSizes);
681 
682  /// Fully unroll a loop.
683  ///
684  /// Instead of unrolling the loop immediately (and duplicating its body
685  /// instructions), it is deferred to LLVM's LoopUnrollPass by adding loop
686  /// metadata.
687  ///
688  /// \param DL Debug location for instructions added by unrolling.
689  /// \param Loop The loop to unroll. The loop will be invalidated.
691 
692  /// Fully or partially unroll a loop. How the loop is unrolled is determined
693  /// using LLVM's LoopUnrollPass.
694  ///
695  /// \param DL Debug location for instructions added by unrolling.
696  /// \param Loop The loop to unroll. The loop will be invalidated.
698 
699  /// Partially unroll a loop.
700  ///
701  /// The CanonicalLoopInfo of the unrolled loop for use with chained
702  /// loop-associated directive can be requested using \p UnrolledCLI. Not
703  /// needing the CanonicalLoopInfo allows more efficient code generation by
704  /// deferring the actual unrolling to the LoopUnrollPass using loop metadata.
705  /// A loop-associated directive applied to the unrolled loop needs to know the
706  /// new trip count which means that if using a heuristically determined unroll
707  /// factor (\p Factor == 0), that factor must be computed immediately. We are
708  /// using the same logic as the LoopUnrollPass to derived the unroll factor,
709  /// but which assumes that some canonicalization has taken place (e.g.
710  /// Mem2Reg, LICM, GVN, Inlining, etc.). That is, the heuristic will perform
711  /// better when the unrolled loop's CanonicalLoopInfo is not needed.
712  ///
713  /// \param DL Debug location for instructions added by unrolling.
714  /// \param Loop The loop to unroll. The loop will be invalidated.
715  /// \param Factor The factor to unroll the loop by. A factor of 0
716  /// indicates that a heuristic should be used to determine
717  /// the unroll-factor.
718  /// \param UnrolledCLI If non-null, receives the CanonicalLoopInfo of the
719  /// partially unrolled loop. Otherwise, uses loop metadata
720  /// to defer unrolling to the LoopUnrollPass.
721  void unrollLoopPartial(DebugLoc DL, CanonicalLoopInfo *Loop, int32_t Factor,
722  CanonicalLoopInfo **UnrolledCLI);
723 
724  /// Add metadata to simd-ize a loop. If IfCond is not nullptr, the loop
725  /// is cloned. The metadata which prevents vectorization is added to
726  /// to the cloned loop. The cloned loop is executed when ifCond is evaluated
727  /// to false.
728  ///
729  /// \param Loop The loop to simd-ize.
730  /// \param AlignedVars The map which containts pairs of the pointer
731  /// and its corresponding alignment.
732  /// \param IfCond The value which corresponds to the if clause
733  /// condition.
734  /// \param Order The enum to map order clause.
735  /// \param Simdlen The Simdlen length to apply to the simd loop.
736  /// \param Safelen The Safelen length to apply to the simd loop.
738  MapVector<Value *, Value *> AlignedVars, Value *IfCond,
739  omp::OrderKind Order, ConstantInt *Simdlen,
740  ConstantInt *Safelen);
741 
742  /// Generator for '#omp flush'
743  ///
744  /// \param Loc The location where the flush directive was encountered
745  void createFlush(const LocationDescription &Loc);
746 
747  /// Generator for '#omp taskwait'
748  ///
749  /// \param Loc The location where the taskwait directive was encountered.
750  void createTaskwait(const LocationDescription &Loc);
751 
752  /// Generator for '#omp taskyield'
753  ///
754  /// \param Loc The location where the taskyield directive was encountered.
755  void createTaskyield(const LocationDescription &Loc);
756 
757  /// A struct to pack the relevant information for an OpenMP depend clause.
758  struct DependData {
762  explicit DependData() = default;
764  Value *DepVal)
766  };
767 
768  /// Generator for `#omp task`
769  ///
770  /// \param Loc The location where the task construct was encountered.
771  /// \param AllocaIP The insertion point to be used for alloca instructions.
772  /// \param BodyGenCB Callback that will generate the region code.
773  /// \param Tied True if the task is tied, false if the task is untied.
774  /// \param Final i1 value which is `true` if the task is final, `false` if the
775  /// task is not final.
776  /// \param IfCondition i1 value. If it evaluates to `false`, an undeferred
777  /// task is generated, and the encountering thread must
778  /// suspend the current task region, for which execution
779  /// cannot be resumed until execution of the structured
780  /// block that is associated with the generated task is
781  /// completed.
782  InsertPointTy createTask(const LocationDescription &Loc,
783  InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB,
784  bool Tied = true, Value *Final = nullptr,
785  Value *IfCondition = nullptr,
786  SmallVector<DependData> Dependencies = {});
787 
788  /// Generator for the taskgroup construct
789  ///
790  /// \param Loc The location where the taskgroup construct was encountered.
791  /// \param AllocaIP The insertion point to be used for alloca instructions.
792  /// \param BodyGenCB Callback that will generate the region code.
793  InsertPointTy createTaskgroup(const LocationDescription &Loc,
794  InsertPointTy AllocaIP,
795  BodyGenCallbackTy BodyGenCB);
796 
797  /// Functions used to generate reductions. Such functions take two Values
798  /// representing LHS and RHS of the reduction, respectively, and a reference
799  /// to the value that is updated to refer to the reduction result.
800  using ReductionGenTy =
802 
803  /// Functions used to generate atomic reductions. Such functions take two
804  /// Values representing pointers to LHS and RHS of the reduction, as well as
805  /// the element type of these pointers. They are expected to atomically
806  /// update the LHS to the reduced value.
807  using AtomicReductionGenTy =
809 
810  /// Information about an OpenMP reduction.
811  struct ReductionInfo {
818  assert(cast<PointerType>(Variable->getType())
819  ->isOpaqueOrPointeeTypeMatches(ElementType) && "Invalid elem type");
820  }
821 
822  /// Reduction element type, must match pointee type of variable.
824 
825  /// Reduction variable of pointer type.
827 
828  /// Thread-private partial reduction variable.
830 
831  /// Callback for generating the reduction body. The IR produced by this will
832  /// be used to combine two values in a thread-safe context, e.g., under
833  /// lock or within the same thread, and therefore need not be atomic.
835 
836  /// Callback for generating the atomic reduction body, may be null. The IR
837  /// produced by this will be used to atomically combine two values during
838  /// reduction. If null, the implementation will use the non-atomic version
839  /// along with the appropriate synchronization mechanisms.
841  };
842 
843  // TODO: provide atomic and non-atomic reduction generators for reduction
844  // operators defined by the OpenMP specification.
845 
846  /// Generator for '#omp reduction'.
847  ///
848  /// Emits the IR instructing the runtime to perform the specific kind of
849  /// reductions. Expects reduction variables to have been privatized and
850  /// initialized to reduction-neutral values separately. Emits the calls to
851  /// runtime functions as well as the reduction function and the basic blocks
852  /// performing the reduction atomically and non-atomically.
853  ///
854  /// The code emitted for the following:
855  ///
856  /// \code
857  /// type var_1;
858  /// type var_2;
859  /// #pragma omp <directive> reduction(reduction-op:var_1,var_2)
860  /// /* body */;
861  /// \endcode
862  ///
863  /// corresponds to the following sketch.
864  ///
865  /// \code
866  /// void _outlined_par() {
867  /// // N is the number of different reductions.
868  /// void *red_array[] = {privatized_var_1, privatized_var_2, ...};
869  /// switch(__kmpc_reduce(..., N, /*size of data in red array*/, red_array,
870  /// _omp_reduction_func,
871  /// _gomp_critical_user.reduction.var)) {
872  /// case 1: {
873  /// var_1 = var_1 <reduction-op> privatized_var_1;
874  /// var_2 = var_2 <reduction-op> privatized_var_2;
875  /// // ...
876  /// __kmpc_end_reduce(...);
877  /// break;
878  /// }
879  /// case 2: {
880  /// _Atomic<ReductionOp>(var_1, privatized_var_1);
881  /// _Atomic<ReductionOp>(var_2, privatized_var_2);
882  /// // ...
883  /// break;
884  /// }
885  /// default: break;
886  /// }
887  /// }
888  ///
889  /// void _omp_reduction_func(void **lhs, void **rhs) {
890  /// *(type *)lhs[0] = *(type *)lhs[0] <reduction-op> *(type *)rhs[0];
891  /// *(type *)lhs[1] = *(type *)lhs[1] <reduction-op> *(type *)rhs[1];
892  /// // ...
893  /// }
894  /// \endcode
895  ///
896  /// \param Loc The location where the reduction was
897  /// encountered. Must be within the associate
898  /// directive and after the last local access to the
899  /// reduction variables.
900  /// \param AllocaIP An insertion point suitable for allocas usable
901  /// in reductions.
902  /// \param ReductionInfos A list of info on each reduction variable.
903  /// \param IsNoWait A flag set if the reduction is marked as nowait.
905  InsertPointTy AllocaIP,
906  ArrayRef<ReductionInfo> ReductionInfos,
907  bool IsNoWait = false);
908 
909  ///}
910 
911  /// Return the insertion point used by the underlying IRBuilder.
913 
914  /// Update the internal location to \p Loc.
916  Builder.restoreIP(Loc.IP);
918  return Loc.IP.getBlock() != nullptr;
919  }
920 
921  /// Return the function declaration for the runtime function with \p FnID.
923  omp::RuntimeFunction FnID);
924 
926 
927  /// Return the (LLVM-IR) string describing the source location \p LocStr.
928  Constant *getOrCreateSrcLocStr(StringRef LocStr, uint32_t &SrcLocStrSize);
929 
930  /// Return the (LLVM-IR) string describing the default source location.
932 
933  /// Return the (LLVM-IR) string describing the source location identified by
934  /// the arguments.
935  Constant *getOrCreateSrcLocStr(StringRef FunctionName, StringRef FileName,
936  unsigned Line, unsigned Column,
937  uint32_t &SrcLocStrSize);
938 
939  /// Return the (LLVM-IR) string describing the DebugLoc \p DL. Use \p F as
940  /// fallback if \p DL does not specify the function name.
942  Function *F = nullptr);
943 
944  /// Return the (LLVM-IR) string describing the source location \p Loc.
945  Constant *getOrCreateSrcLocStr(const LocationDescription &Loc,
946  uint32_t &SrcLocStrSize);
947 
948  /// Return an ident_t* encoding the source location \p SrcLocStr and \p Flags.
949  /// TODO: Create a enum class for the Reserve2Flags
950  Constant *getOrCreateIdent(Constant *SrcLocStr, uint32_t SrcLocStrSize,
951  omp::IdentFlag Flags = omp::IdentFlag(0),
952  unsigned Reserve2Flags = 0);
953 
954  /// Create a hidden global flag \p Name in the module with initial value \p
955  /// Value.
956  GlobalValue *createGlobalFlag(unsigned Value, StringRef Name);
957 
958  /// Create an offloading section struct used to register this global at
959  /// runtime.
960  ///
961  /// Type struct __tgt_offload_entry{
962  /// void *addr; // Pointer to the offload entry info.
963  /// // (function or global)
964  /// char *name; // Name of the function or global.
965  /// size_t size; // Size of the entry info (0 if it a function).
966  /// int32_t flags;
967  /// int32_t reserved;
968  /// };
969  ///
970  /// \param Addr The pointer to the global being registered.
971  /// \param Name The symbol name associated with the global.
972  /// \param Size The size in bytes of the global (0 for functions).
973  /// \param Flags Flags associated with the entry.
974  /// \param SectionName The section this entry will be placed at.
976  int32_t Flags,
977  StringRef SectionName = "omp_offloading_entries");
978 
979  /// Generate control flow and cleanup for cancellation.
980  ///
981  /// \param CancelFlag Flag indicating if the cancellation is performed.
982  /// \param CanceledDirective The kind of directive that is cancled.
983  /// \param ExitCB Extra code to be generated in the exit block.
984  void emitCancelationCheckImpl(Value *CancelFlag,
985  omp::Directive CanceledDirective,
986  FinalizeCallbackTy ExitCB = {});
987 
988  /// Generate a target region entry call.
989  ///
990  /// \param Loc The location at which the request originated and is fulfilled.
991  /// \param Return Return value of the created function returned by reference.
992  /// \param DeviceID Identifier for the device via the 'device' clause.
993  /// \param NumTeams Numer of teams for the region via the 'num_teams' clause
994  /// or 0 if unspecified and -1 if there is no 'teams' clause.
995  /// \param NumThreads Number of threads via the 'thread_limit' clause.
996  /// \param HostPtr Pointer to the host-side pointer of the target kernel.
997  /// \param KernelArgs Array of arguments to the kernel.
998  InsertPointTy emitTargetKernel(const LocationDescription &Loc, Value *&Return,
999  Value *Ident, Value *DeviceID, Value *NumTeams,
1000  Value *NumThreads, Value *HostPtr,
1001  ArrayRef<Value *> KernelArgs);
1002 
1003  /// Generate a barrier runtime call.
1004  ///
1005  /// \param Loc The location at which the request originated and is fulfilled.
1006  /// \param DK The directive which caused the barrier
1007  /// \param ForceSimpleCall Flag to force a simple (=non-cancellation) barrier.
1008  /// \param CheckCancelFlag Flag to indicate a cancel barrier return value
1009  /// should be checked and acted upon.
1010  ///
1011  /// \returns The insertion point after the barrier.
1012  InsertPointTy emitBarrierImpl(const LocationDescription &Loc,
1013  omp::Directive DK, bool ForceSimpleCall,
1014  bool CheckCancelFlag);
1015 
1016  /// Generate a flush runtime call.
1017  ///
1018  /// \param Loc The location at which the request originated and is fulfilled.
1019  void emitFlush(const LocationDescription &Loc);
1020 
1021  /// The finalization stack made up of finalize callbacks currently in-flight,
1022  /// wrapped into FinalizationInfo objects that reference also the finalization
1023  /// target block and the kind of cancellable directive.
1025 
1026  /// Return true if the last entry in the finalization stack is of kind \p DK
1027  /// and cancellable.
1028  bool isLastFinalizationInfoCancellable(omp::Directive DK) {
1029  return !FinalizationStack.empty() &&
1030  FinalizationStack.back().IsCancellable &&
1031  FinalizationStack.back().DK == DK;
1032  }
1033 
1034  /// Generate a taskwait runtime call.
1035  ///
1036  /// \param Loc The location at which the request originated and is fulfilled.
1037  void emitTaskwaitImpl(const LocationDescription &Loc);
1038 
1039  /// Generate a taskyield runtime call.
1040  ///
1041  /// \param Loc The location at which the request originated and is fulfilled.
1042  void emitTaskyieldImpl(const LocationDescription &Loc);
1043 
1044  /// Return the current thread ID.
1045  ///
1046  /// \param Ident The ident (ident_t*) describing the query origin.
1047  Value *getOrCreateThreadID(Value *Ident);
1048 
1049  /// The OpenMPIRBuilder Configuration
1051 
1052  /// The underlying LLVM-IR module
1054 
1055  /// The LLVM-IR Builder used to create IR.
1057 
1058  /// Map to remember source location strings
1060 
1061  /// Map to remember existing ident_t*.
1063 
1064  /// Helper that contains information about regions we need to outline
1065  /// during finalization.
1066  struct OutlineInfo {
1071 
1072  /// Collect all blocks in between EntryBB and ExitBB in both the given
1073  /// vector and set.
1075  SmallVectorImpl<BasicBlock *> &BlockVector);
1076 
1077  /// Return the function that contains the region to be outlined.
1078  Function *getFunction() const { return EntryBB->getParent(); }
1079  };
1080 
1081  /// Collection of regions that need to be outlined during finalization.
1083 
1084  /// Collection of owned canonical loop objects that eventually need to be
1085  /// free'd.
1086  std::forward_list<CanonicalLoopInfo> LoopInfos;
1087 
1088  /// Add a new region that will be outlined later.
1089  void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
1090 
1091  /// An ordered map of auto-generated variables to their unique names.
1092  /// It stores variables with the following names: 1) ".gomp_critical_user_" +
1093  /// <critical_section_name> + ".var" for "omp critical" directives; 2)
1094  /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
1095  /// variables.
1097 
1098  /// Create the global variable holding the offload mappings information.
1100  std::string VarName);
1101 
1102  /// Create the global variable holding the offload names information.
1103  GlobalVariable *
1105  std::string VarName);
1106 
1107  struct MapperAllocas {
1108  AllocaInst *ArgsBase = nullptr;
1109  AllocaInst *Args = nullptr;
1110  AllocaInst *ArgSizes = nullptr;
1111  };
1112 
1113  /// Create the allocas instruction used in call to mapper functions.
1114  void createMapperAllocas(const LocationDescription &Loc,
1115  InsertPointTy AllocaIP, unsigned NumOperands,
1116  struct MapperAllocas &MapperAllocas);
1117 
1118  /// Create the call for the target mapper function.
1119  /// \param Loc The source location description.
1120  /// \param MapperFunc Function to be called.
1121  /// \param SrcLocInfo Source location information global.
1122  /// \param MaptypesArg The argument types.
1123  /// \param MapnamesArg The argument names.
1124  /// \param MapperAllocas The AllocaInst used for the call.
1125  /// \param DeviceID Device ID for the call.
1126  /// \param NumOperands Number of operands in the call.
1127  void emitMapperCall(const LocationDescription &Loc, Function *MapperFunc,
1128  Value *SrcLocInfo, Value *MaptypesArg, Value *MapnamesArg,
1129  struct MapperAllocas &MapperAllocas, int64_t DeviceID,
1130  unsigned NumOperands);
1131 
1132  /// Container for the arguments used to pass data to the runtime library.
1134  explicit TargetDataRTArgs() {}
1135  /// The array of base pointer passed to the runtime library.
1137  /// The array of section pointers passed to the runtime library.
1138  Value *PointersArray = nullptr;
1139  /// The array of sizes passed to the runtime library.
1140  Value *SizesArray = nullptr;
1141  /// The array of map types passed to the runtime library for the beginning
1142  /// of the region or for the entire region if there are no separate map
1143  /// types for the region end.
1144  Value *MapTypesArray = nullptr;
1145  /// The array of map types passed to the runtime library for the end of the
1146  /// region, or nullptr if there are no separate map types for the region
1147  /// end.
1149  /// The array of user-defined mappers passed to the runtime library.
1150  Value *MappersArray = nullptr;
1151  /// The array of original declaration names of mapped pointers sent to the
1152  /// runtime library for debugging
1153  Value *MapNamesArray = nullptr;
1154  };
1155 
1156  /// Struct that keeps the information that should be kept throughout
1157  /// a 'target data' region.
1159  /// Set to true if device pointer information have to be obtained.
1160  bool RequiresDevicePointerInfo = false;
1161  /// Set to true if Clang emits separate runtime calls for the beginning and
1162  /// end of the region. These calls might have separate map type arrays.
1163  bool SeparateBeginEndCalls = false;
1164 
1165  public:
1167 
1168  /// Indicate whether any user-defined mapper exists.
1169  bool HasMapper = false;
1170  /// The total number of pointers passed to the runtime library.
1171  unsigned NumberOfPtrs = 0u;
1172 
1173  explicit TargetDataInfo() {}
1174  explicit TargetDataInfo(bool RequiresDevicePointerInfo,
1175  bool SeparateBeginEndCalls)
1176  : RequiresDevicePointerInfo(RequiresDevicePointerInfo),
1177  SeparateBeginEndCalls(SeparateBeginEndCalls) {}
1178  /// Clear information about the data arrays.
1181  HasMapper = false;
1182  NumberOfPtrs = 0u;
1183  }
1184  /// Return true if the current target data information has valid arrays.
1185  bool isValid() {
1189  }
1190  bool requiresDevicePointerInfo() { return RequiresDevicePointerInfo; }
1191  bool separateBeginEndCalls() { return SeparateBeginEndCalls; }
1192  };
1193 
1194  /// Emit the arguments to be passed to the runtime library based on the
1195  /// arrays of base pointers, pointers, sizes, map types, and mappers. If
1196  /// ForEndCall, emit map types to be passed for the end of the region instead
1197  /// of the beginning.
1201  bool EmitDebug = false,
1202  bool ForEndCall = false);
1203 
1204  /// Creates offloading entry for the provided entry ID \a ID, address \a
1205  /// Addr, size \a Size, and flags \a Flags.
1207  int32_t Flags, GlobalValue::LinkageTypes);
1208 
1209  /// The kind of errors that can occur when emitting the offload entries and
1210  /// metadata.
1215  };
1216 
1217  /// Callback function type
1220 
1221  // Emit the offloading entries and metadata so that the device codegen side
1222  // can easily figure out what to emit. The produced metadata looks like
1223  // this:
1224  //
1225  // !omp_offload.info = !{!1, ...}
1226  //
1227  // We only generate metadata for function that contain target regions.
1230  EmitMetadataErrorReportFunctionTy &ErrorReportFunction);
1231 
1232 public:
1233  /// Generator for __kmpc_copyprivate
1234  ///
1235  /// \param Loc The source location description.
1236  /// \param BufSize Number of elements in the buffer.
1237  /// \param CpyBuf List of pointers to data to be copied.
1238  /// \param CpyFn function to call for copying data.
1239  /// \param DidIt flag variable; 1 for 'single' thread, 0 otherwise.
1240  ///
1241  /// \return The insertion position *after* the CopyPrivate call.
1242 
1244  llvm::Value *BufSize, llvm::Value *CpyBuf,
1245  llvm::Value *CpyFn, llvm::Value *DidIt);
1246 
1247  /// Generator for '#omp single'
1248  ///
1249  /// \param Loc The source location description.
1250  /// \param BodyGenCB Callback that will generate the region code.
1251  /// \param FiniCB Callback to finalize variable copies.
1252  /// \param IsNowait If false, a barrier is emitted.
1253  /// \param DidIt Local variable used as a flag to indicate 'single' thread
1254  ///
1255  /// \returns The insertion position *after* the single call.
1257  BodyGenCallbackTy BodyGenCB,
1258  FinalizeCallbackTy FiniCB, bool IsNowait,
1259  llvm::Value *DidIt);
1260 
1261  /// Generator for '#omp master'
1262  ///
1263  /// \param Loc The insert and source location description.
1264  /// \param BodyGenCB Callback that will generate the region code.
1265  /// \param FiniCB Callback to finalize variable copies.
1266  ///
1267  /// \returns The insertion position *after* the master.
1269  BodyGenCallbackTy BodyGenCB,
1270  FinalizeCallbackTy FiniCB);
1271 
1272  /// Generator for '#omp masked'
1273  ///
1274  /// \param Loc The insert and source location description.
1275  /// \param BodyGenCB Callback that will generate the region code.
1276  /// \param FiniCB Callback to finialize variable copies.
1277  ///
1278  /// \returns The insertion position *after* the masked.
1280  BodyGenCallbackTy BodyGenCB,
1281  FinalizeCallbackTy FiniCB, Value *Filter);
1282 
1283  /// Generator for '#omp critical'
1284  ///
1285  /// \param Loc The insert and source location description.
1286  /// \param BodyGenCB Callback that will generate the region body code.
1287  /// \param FiniCB Callback to finalize variable copies.
1288  /// \param CriticalName name of the lock used by the critical directive
1289  /// \param HintInst Hint Instruction for hint clause associated with critical
1290  ///
1291  /// \returns The insertion position *after* the critical.
1293  BodyGenCallbackTy BodyGenCB,
1294  FinalizeCallbackTy FiniCB,
1295  StringRef CriticalName, Value *HintInst);
1296 
1297  /// Generator for '#omp ordered depend (source | sink)'
1298  ///
1299  /// \param Loc The insert and source location description.
1300  /// \param AllocaIP The insertion point to be used for alloca instructions.
1301  /// \param NumLoops The number of loops in depend clause.
1302  /// \param StoreValues The value will be stored in vector address.
1303  /// \param Name The name of alloca instruction.
1304  /// \param IsDependSource If true, depend source; otherwise, depend sink.
1305  ///
1306  /// \return The insertion position *after* the ordered.
1308  InsertPointTy AllocaIP, unsigned NumLoops,
1309  ArrayRef<llvm::Value *> StoreValues,
1310  const Twine &Name, bool IsDependSource);
1311 
1312  /// Generator for '#omp ordered [threads | simd]'
1313  ///
1314  /// \param Loc The insert and source location description.
1315  /// \param BodyGenCB Callback that will generate the region code.
1316  /// \param FiniCB Callback to finalize variable copies.
1317  /// \param IsThreads If true, with threads clause or without clause;
1318  /// otherwise, with simd clause;
1319  ///
1320  /// \returns The insertion position *after* the ordered.
1322  BodyGenCallbackTy BodyGenCB,
1323  FinalizeCallbackTy FiniCB,
1324  bool IsThreads);
1325 
1326  /// Generator for '#omp sections'
1327  ///
1328  /// \param Loc The insert and source location description.
1329  /// \param AllocaIP The insertion points to be used for alloca instructions.
1330  /// \param SectionCBs Callbacks that will generate body of each section.
1331  /// \param PrivCB Callback to copy a given variable (think copy constructor).
1332  /// \param FiniCB Callback to finalize variable copies.
1333  /// \param IsCancellable Flag to indicate a cancellable parallel region.
1334  /// \param IsNowait If true, barrier - to ensure all sections are executed
1335  /// before moving forward will not be generated.
1336  /// \returns The insertion position *after* the sections.
1338  InsertPointTy AllocaIP,
1340  PrivatizeCallbackTy PrivCB,
1341  FinalizeCallbackTy FiniCB, bool IsCancellable,
1342  bool IsNowait);
1343 
1344  /// Generator for '#omp section'
1345  ///
1346  /// \param Loc The insert and source location description.
1347  /// \param BodyGenCB Callback that will generate the region body code.
1348  /// \param FiniCB Callback to finalize variable copies.
1349  /// \returns The insertion position *after* the section.
1351  BodyGenCallbackTy BodyGenCB,
1352  FinalizeCallbackTy FiniCB);
1353 
1354  /// Generate conditional branch and relevant BasicBlocks through which private
1355  /// threads copy the 'copyin' variables from Master copy to threadprivate
1356  /// copies.
1357  ///
1358  /// \param IP insertion block for copyin conditional
1359  /// \param MasterVarPtr a pointer to the master variable
1360  /// \param PrivateVarPtr a pointer to the threadprivate variable
1361  /// \param IntPtrTy Pointer size type
1362  /// \param BranchtoEnd Create a branch between the copyin.not.master blocks
1363  // and copy.in.end block
1364  ///
1365  /// \returns The insertion point where copying operation to be emitted.
1367  Value *PrivateAddr,
1368  llvm::IntegerType *IntPtrTy,
1369  bool BranchtoEnd = true);
1370 
1371  /// Create a runtime call for kmpc_Alloc
1372  ///
1373  /// \param Loc The insert and source location description.
1374  /// \param Size Size of allocated memory space
1375  /// \param Allocator Allocator information instruction
1376  /// \param Name Name of call Instruction for OMP_alloc
1377  ///
1378  /// \returns CallInst to the OMP_Alloc call
1379  CallInst *createOMPAlloc(const LocationDescription &Loc, Value *Size,
1380  Value *Allocator, std::string Name = "");
1381 
1382  /// Create a runtime call for kmpc_free
1383  ///
1384  /// \param Loc The insert and source location description.
1385  /// \param Addr Address of memory space to be freed
1386  /// \param Allocator Allocator information instruction
1387  /// \param Name Name of call Instruction for OMP_Free
1388  ///
1389  /// \returns CallInst to the OMP_Free call
1391  Value *Allocator, std::string Name = "");
1392 
1393  /// Create a runtime call for kmpc_threadprivate_cached
1394  ///
1395  /// \param Loc The insert and source location description.
1396  /// \param Pointer pointer to data to be cached
1397  /// \param Size size of data to be cached
1398  /// \param Name Name of call Instruction for callinst
1399  ///
1400  /// \returns CallInst to the thread private cache call.
1402  llvm::Value *Pointer,
1403  llvm::ConstantInt *Size,
1404  const llvm::Twine &Name = Twine(""));
1405 
1406  /// Create a runtime call for __tgt_interop_init
1407  ///
1408  /// \param Loc The insert and source location description.
1409  /// \param InteropVar variable to be allocated
1410  /// \param InteropType type of interop operation
1411  /// \param Device devide to which offloading will occur
1412  /// \param NumDependences number of dependence variables
1413  /// \param DependenceAddress pointer to dependence variables
1414  /// \param HaveNowaitClause does nowait clause exist
1415  ///
1416  /// \returns CallInst to the __tgt_interop_init call
1418  Value *InteropVar,
1419  omp::OMPInteropType InteropType, Value *Device,
1420  Value *NumDependences,
1421  Value *DependenceAddress,
1422  bool HaveNowaitClause);
1423 
1424  /// Create a runtime call for __tgt_interop_destroy
1425  ///
1426  /// \param Loc The insert and source location description.
1427  /// \param InteropVar variable to be allocated
1428  /// \param Device devide to which offloading will occur
1429  /// \param NumDependences number of dependence variables
1430  /// \param DependenceAddress pointer to dependence variables
1431  /// \param HaveNowaitClause does nowait clause exist
1432  ///
1433  /// \returns CallInst to the __tgt_interop_destroy call
1435  Value *InteropVar, Value *Device,
1436  Value *NumDependences,
1437  Value *DependenceAddress,
1438  bool HaveNowaitClause);
1439 
1440  /// Create a runtime call for __tgt_interop_use
1441  ///
1442  /// \param Loc The insert and source location description.
1443  /// \param InteropVar variable to be allocated
1444  /// \param Device devide to which offloading will occur
1445  /// \param NumDependences number of dependence variables
1446  /// \param DependenceAddress pointer to dependence variables
1447  /// \param HaveNowaitClause does nowait clause exist
1448  ///
1449  /// \returns CallInst to the __tgt_interop_use call
1451  Value *InteropVar, Value *Device,
1452  Value *NumDependences, Value *DependenceAddress,
1453  bool HaveNowaitClause);
1454 
1455  /// The `omp target` interface
1456  ///
1457  /// For more information about the usage of this interface,
1458  /// \see openmp/libomptarget/deviceRTLs/common/include/target.h
1459  ///
1460  ///{
1461 
1462  /// Create a runtime call for kmpc_target_init
1463  ///
1464  /// \param Loc The insert and source location description.
1465  /// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
1466  InsertPointTy createTargetInit(const LocationDescription &Loc, bool IsSPMD);
1467 
1468  /// Create a runtime call for kmpc_target_deinit
1469  ///
1470  /// \param Loc The insert and source location description.
1471  /// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
1472  void createTargetDeinit(const LocationDescription &Loc, bool IsSPMD);
1473 
1474  ///}
1475 
1476 private:
1477  // Sets the function attributes expected for the outlined function
1478  void setOutlinedTargetRegionFunctionAttributes(Function *OutlinedFn,
1479  int32_t NumTeams,
1480  int32_t NumThreads);
1481 
1482  // Creates the function ID/Address for the given outlined function.
1483  // In the case of an embedded device function the address of the function is
1484  // used, in the case of a non-offload function a constant is created.
1485  Constant *createOutlinedFunctionID(Function *OutlinedFn,
1486  StringRef EntryFnIDName);
1487 
1488  // Creates the region entry address for the outlined function
1489  Constant *createTargetRegionEntryAddr(Function *OutlinedFunction,
1490  StringRef EntryFnName);
1491 
1492 public:
1493  /// Functions used to generate a function with the given name.
1495 
1496  /// Create a unique name for the entry function using the source location
1497  /// information of the current target region. The name will be something like:
1498  ///
1499  /// __omp_offloading_DD_FFFF_PP_lBB[_CC]
1500  ///
1501  /// where DD_FFFF is an ID unique to the file (device and file IDs), PP is the
1502  /// mangled name of the function that encloses the target region and BB is the
1503  /// line number of the target region. CC is a count added when more than one
1504  /// region is located at the same location.
1505  ///
1506  /// If this target outline function is not an offload entry, we don't need to
1507  /// register it. This may happen if it is guarded by an if clause that is
1508  /// false at compile time, or no target archs have been specified.
1509  ///
1510  /// The created target region ID is used by the runtime library to identify
1511  /// the current target region, so it only has to be unique and not
1512  /// necessarily point to anything. It could be the pointer to the outlined
1513  /// function that implements the target region, but we aren't using that so
1514  /// that the compiler doesn't need to keep that, and could therefore inline
1515  /// the host function if proven worthwhile during optimization. In the other
1516  /// hand, if emitting code for the device, the ID has to be the function
1517  /// address so that it can retrieved from the offloading entry and launched
1518  /// by the runtime library. We also mark the outlined function to have
1519  /// external linkage in case we are emitting code for the device, because
1520  /// these functions will be entry points to the device.
1521  ///
1522  /// \param InfoManager The info manager keeping track of the offload entries
1523  /// \param EntryInfo The entry information about the function
1524  /// \param GenerateFunctionCallback The callback function to generate the code
1525  /// \param NumTeams Number default teams
1526  /// \param NumThreads Number default threads
1527  /// \param OutlinedFunction Pointer to the outlined function
1528  /// \param EntryFnIDName Name of the ID o be created
1530  TargetRegionEntryInfo &EntryInfo,
1531  FunctionGenCallback &GenerateFunctionCallback,
1532  int32_t NumTeams, int32_t NumThreads,
1533  bool IsOffloadEntry, Function *&OutlinedFn,
1534  Constant *&OutlinedFnID);
1535 
1536  /// Registers the given function and sets up the attribtues of the function
1537  /// Returns the FunctionID.
1538  ///
1539  /// \param InfoManager The info manager keeping track of the offload entries
1540  /// \param EntryInfo The entry information about the function
1541  /// \param OutlinedFunction Pointer to the outlined function
1542  /// \param EntryFnName Name of the outlined function
1543  /// \param EntryFnIDName Name of the ID o be created
1544  /// \param NumTeams Number default teams
1545  /// \param NumThreads Number default threads
1547  TargetRegionEntryInfo &EntryInfo,
1548  Function *OutlinedFunction,
1549  StringRef EntryFnName,
1550  StringRef EntryFnIDName,
1551  int32_t NumTeams, int32_t NumThreads);
1552 
1553  /// Declarations for LLVM-IR types (simple, array, function and structure) are
1554  /// generated below. Their names are defined and used in OpenMPKinds.def. Here
1555  /// we provide the declarations, the initializeTypes function will provide the
1556  /// values.
1557  ///
1558  ///{
1559 #define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
1560 #define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
1561  ArrayType *VarName##Ty = nullptr; \
1562  PointerType *VarName##PtrTy = nullptr;
1563 #define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
1564  FunctionType *VarName = nullptr; \
1565  PointerType *VarName##Ptr = nullptr;
1566 #define OMP_STRUCT_TYPE(VarName, StrName, ...) \
1567  StructType *VarName = nullptr; \
1568  PointerType *VarName##Ptr = nullptr;
1569 #include "llvm/Frontend/OpenMP/OMPKinds.def"
1570 
1571  ///}
1572 
1573 private:
1574  /// Create all simple and struct types exposed by the runtime and remember
1575  /// the llvm::PointerTypes of them for easy access later.
1576  void initializeTypes(Module &M);
1577 
1578  /// Common interface for generating entry calls for OMP Directives.
1579  /// if the directive has a region/body, It will set the insertion
1580  /// point to the body
1581  ///
1582  /// \param OMPD Directive to generate entry blocks for
1583  /// \param EntryCall Call to the entry OMP Runtime Function
1584  /// \param ExitBB block where the region ends.
1585  /// \param Conditional indicate if the entry call result will be used
1586  /// to evaluate a conditional of whether a thread will execute
1587  /// body code or not.
1588  ///
1589  /// \return The insertion position in exit block
1590  InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD, Value *EntryCall,
1591  BasicBlock *ExitBB,
1592  bool Conditional = false);
1593 
1594  /// Common interface to finalize the region
1595  ///
1596  /// \param OMPD Directive to generate exiting code for
1597  /// \param FinIP Insertion point for emitting Finalization code and exit call
1598  /// \param ExitCall Call to the ending OMP Runtime Function
1599  /// \param HasFinalize indicate if the directive will require finalization
1600  /// and has a finalization callback in the stack that
1601  /// should be called.
1602  ///
1603  /// \return The insertion position in exit block
1604  InsertPointTy emitCommonDirectiveExit(omp::Directive OMPD,
1605  InsertPointTy FinIP,
1606  Instruction *ExitCall,
1607  bool HasFinalize = true);
1608 
1609  /// Common Interface to generate OMP inlined regions
1610  ///
1611  /// \param OMPD Directive to generate inlined region for
1612  /// \param EntryCall Call to the entry OMP Runtime Function
1613  /// \param ExitCall Call to the ending OMP Runtime Function
1614  /// \param BodyGenCB Body code generation callback.
1615  /// \param FiniCB Finalization Callback. Will be called when finalizing region
1616  /// \param Conditional indicate if the entry call result will be used
1617  /// to evaluate a conditional of whether a thread will execute
1618  /// body code or not.
1619  /// \param HasFinalize indicate if the directive will require finalization
1620  /// and has a finalization callback in the stack that
1621  /// should be called.
1622  /// \param IsCancellable if HasFinalize is set to true, indicate if the
1623  /// the directive should be cancellable.
1624  /// \return The insertion point after the region
1625 
1627  EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
1628  Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
1629  FinalizeCallbackTy FiniCB, bool Conditional = false,
1630  bool HasFinalize = true, bool IsCancellable = false);
1631 
1632  /// Get the platform-specific name separator.
1633  /// \param Parts different parts of the final name that needs separation
1634  /// \param FirstSeparator First separator used between the initial two
1635  /// parts of the name.
1636  /// \param Separator separator used between all of the rest consecutive
1637  /// parts of the name
1638  static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
1639  StringRef FirstSeparator,
1640  StringRef Separator);
1641 
1642  /// Returns corresponding lock object for the specified critical region
1643  /// name. If the lock object does not exist it is created, otherwise the
1644  /// reference to the existing copy is returned.
1645  /// \param CriticalName Name of the critical region.
1646  ///
1647  Value *getOMPCriticalRegionLock(StringRef CriticalName);
1648 
1649  /// Callback type for Atomic Expression update
1650  /// ex:
1651  /// \code{.cpp}
1652  /// unsigned x = 0;
1653  /// #pragma omp atomic update
1654  /// x = Expr(x_old); //Expr() is any legal operation
1655  /// \endcode
1656  ///
1657  /// \param XOld the value of the atomic memory address to use for update
1658  /// \param IRB reference to the IRBuilder to use
1659  ///
1660  /// \returns Value to update X to.
1661  using AtomicUpdateCallbackTy =
1662  const function_ref<Value *(Value *XOld, IRBuilder<> &IRB)>;
1663 
1664 private:
1665  enum AtomicKind { Read, Write, Update, Capture, Compare };
1666 
1667  /// Determine whether to emit flush or not
1668  ///
1669  /// \param Loc The insert and source location description.
1670  /// \param AO The required atomic ordering
1671  /// \param AK The OpenMP atomic operation kind used.
1672  ///
1673  /// \returns wether a flush was emitted or not
1674  bool checkAndEmitFlushAfterAtomic(const LocationDescription &Loc,
1675  AtomicOrdering AO, AtomicKind AK);
1676 
1677  /// Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X
1678  /// For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X)
1679  /// Only Scalar data types.
1680  ///
1681  /// \param AllocaIP The insertion point to be used for alloca
1682  /// instructions.
1683  /// \param X The target atomic pointer to be updated
1684  /// \param XElemTy The element type of the atomic pointer.
1685  /// \param Expr The value to update X with.
1686  /// \param AO Atomic ordering of the generated atomic
1687  /// instructions.
1688  /// \param RMWOp The binary operation used for update. If
1689  /// operation is not supported by atomicRMW,
1690  /// or belong to {FADD, FSUB, BAD_BINOP}.
1691  /// Then a `cmpExch` based atomic will be generated.
1692  /// \param UpdateOp Code generator for complex expressions that cannot be
1693  /// expressed through atomicrmw instruction.
1694  /// \param VolatileX true if \a X volatile?
1695  /// \param IsXBinopExpr true if \a X is Left H.S. in Right H.S. part of the
1696  /// update expression, false otherwise.
1697  /// (e.g. true for X = X BinOp Expr)
1698  ///
1699  /// \returns A pair of the old value of X before the update, and the value
1700  /// used for the update.
1701  std::pair<Value *, Value *>
1702  emitAtomicUpdate(InsertPointTy AllocaIP, Value *X, Type *XElemTy, Value *Expr,
1704  AtomicUpdateCallbackTy &UpdateOp, bool VolatileX,
1705  bool IsXBinopExpr);
1706 
1707  /// Emit the binary op. described by \p RMWOp, using \p Src1 and \p Src2 .
1708  ///
1709  /// \Return The instruction
1710  Value *emitRMWOpAsInstruction(Value *Src1, Value *Src2,
1711  AtomicRMWInst::BinOp RMWOp);
1712 
1713 public:
1714  /// a struct to pack relevant information while generating atomic Ops
1715  struct AtomicOpValue {
1716  Value *Var = nullptr;
1717  Type *ElemTy = nullptr;
1718  bool IsSigned = false;
1719  bool IsVolatile = false;
1720  };
1721 
1722  /// Emit atomic Read for : V = X --- Only Scalar data types.
1723  ///
1724  /// \param Loc The insert and source location description.
1725  /// \param X The target pointer to be atomically read
1726  /// \param V Memory address where to store atomically read
1727  /// value
1728  /// \param AO Atomic ordering of the generated atomic
1729  /// instructions.
1730  ///
1731  /// \return Insertion point after generated atomic read IR.
1734  AtomicOrdering AO);
1735 
1736  /// Emit atomic write for : X = Expr --- Only Scalar data types.
1737  ///
1738  /// \param Loc The insert and source location description.
1739  /// \param X The target pointer to be atomically written to
1740  /// \param Expr The value to store.
1741  /// \param AO Atomic ordering of the generated atomic
1742  /// instructions.
1743  ///
1744  /// \return Insertion point after generated atomic Write IR.
1746  AtomicOpValue &X, Value *Expr,
1747  AtomicOrdering AO);
1748 
1749  /// Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X
1750  /// For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X)
1751  /// Only Scalar data types.
1752  ///
1753  /// \param Loc The insert and source location description.
1754  /// \param AllocaIP The insertion point to be used for alloca instructions.
1755  /// \param X The target atomic pointer to be updated
1756  /// \param Expr The value to update X with.
1757  /// \param AO Atomic ordering of the generated atomic instructions.
1758  /// \param RMWOp The binary operation used for update. If operation
1759  /// is not supported by atomicRMW, or belong to
1760  /// {FADD, FSUB, BAD_BINOP}. Then a `cmpExch` based
1761  /// atomic will be generated.
1762  /// \param UpdateOp Code generator for complex expressions that cannot be
1763  /// expressed through atomicrmw instruction.
1764  /// \param IsXBinopExpr true if \a X is Left H.S. in Right H.S. part of the
1765  /// update expression, false otherwise.
1766  /// (e.g. true for X = X BinOp Expr)
1767  ///
1768  /// \return Insertion point after generated atomic update IR.
1770  InsertPointTy AllocaIP, AtomicOpValue &X,
1771  Value *Expr, AtomicOrdering AO,
1772  AtomicRMWInst::BinOp RMWOp,
1773  AtomicUpdateCallbackTy &UpdateOp,
1774  bool IsXBinopExpr);
1775 
1776  /// Emit atomic update for constructs: --- Only Scalar data types
1777  /// V = X; X = X BinOp Expr ,
1778  /// X = X BinOp Expr; V = X,
1779  /// V = X; X = Expr BinOp X,
1780  /// X = Expr BinOp X; V = X,
1781  /// V = X; X = UpdateOp(X),
1782  /// X = UpdateOp(X); V = X,
1783  ///
1784  /// \param Loc The insert and source location description.
1785  /// \param AllocaIP The insertion point to be used for alloca instructions.
1786  /// \param X The target atomic pointer to be updated
1787  /// \param V Memory address where to store captured value
1788  /// \param Expr The value to update X with.
1789  /// \param AO Atomic ordering of the generated atomic instructions
1790  /// \param RMWOp The binary operation used for update. If
1791  /// operation is not supported by atomicRMW, or belong to
1792  /// {FADD, FSUB, BAD_BINOP}. Then a cmpExch based
1793  /// atomic will be generated.
1794  /// \param UpdateOp Code generator for complex expressions that cannot be
1795  /// expressed through atomicrmw instruction.
1796  /// \param UpdateExpr true if X is an in place update of the form
1797  /// X = X BinOp Expr or X = Expr BinOp X
1798  /// \param IsXBinopExpr true if X is Left H.S. in Right H.S. part of the
1799  /// update expression, false otherwise.
1800  /// (e.g. true for X = X BinOp Expr)
1801  /// \param IsPostfixUpdate true if original value of 'x' must be stored in
1802  /// 'v', not an updated one.
1803  ///
1804  /// \return Insertion point after generated atomic capture IR.
1807  AtomicOpValue &X, AtomicOpValue &V, Value *Expr,
1809  AtomicUpdateCallbackTy &UpdateOp, bool UpdateExpr,
1810  bool IsPostfixUpdate, bool IsXBinopExpr);
1811 
1812  /// Emit atomic compare for constructs: --- Only scalar data types
1813  /// cond-expr-stmt:
1814  /// x = x ordop expr ? expr : x;
1815  /// x = expr ordop x ? expr : x;
1816  /// x = x == e ? d : x;
1817  /// x = e == x ? d : x; (this one is not in the spec)
1818  /// cond-update-stmt:
1819  /// if (x ordop expr) { x = expr; }
1820  /// if (expr ordop x) { x = expr; }
1821  /// if (x == e) { x = d; }
1822  /// if (e == x) { x = d; } (this one is not in the spec)
1823  /// conditional-update-capture-atomic:
1824  /// v = x; cond-update-stmt; (IsPostfixUpdate=true, IsFailOnly=false)
1825  /// cond-update-stmt; v = x; (IsPostfixUpdate=false, IsFailOnly=false)
1826  /// if (x == e) { x = d; } else { v = x; } (IsPostfixUpdate=false,
1827  /// IsFailOnly=true)
1828  /// r = x == e; if (r) { x = d; } (IsPostfixUpdate=false, IsFailOnly=false)
1829  /// r = x == e; if (r) { x = d; } else { v = x; } (IsPostfixUpdate=false,
1830  /// IsFailOnly=true)
1831  ///
1832  /// \param Loc The insert and source location description.
1833  /// \param X The target atomic pointer to be updated.
1834  /// \param V Memory address where to store captured value (for
1835  /// compare capture only).
1836  /// \param R Memory address where to store comparison result
1837  /// (for compare capture with '==' only).
1838  /// \param E The expected value ('e') for forms that use an
1839  /// equality comparison or an expression ('expr') for
1840  /// forms that use 'ordop' (logically an atomic maximum or
1841  /// minimum).
1842  /// \param D The desired value for forms that use an equality
1843  /// comparison. If forms that use 'ordop', it should be
1844  /// \p nullptr.
1845  /// \param AO Atomic ordering of the generated atomic instructions.
1846  /// \param Op Atomic compare operation. It can only be ==, <, or >.
1847  /// \param IsXBinopExpr True if the conditional statement is in the form where
1848  /// x is on LHS. It only matters for < or >.
1849  /// \param IsPostfixUpdate True if original value of 'x' must be stored in
1850  /// 'v', not an updated one (for compare capture
1851  /// only).
1852  /// \param IsFailOnly True if the original value of 'x' is stored to 'v'
1853  /// only when the comparison fails. This is only valid for
1854  /// the case the comparison is '=='.
1855  ///
1856  /// \return Insertion point after generated atomic capture IR.
1861  bool IsXBinopExpr, bool IsPostfixUpdate, bool IsFailOnly);
1862 
1863  /// Create the control flow structure of a canonical OpenMP loop.
1864  ///
1865  /// The emitted loop will be disconnected, i.e. no edge to the loop's
1866  /// preheader and no terminator in the AfterBB. The OpenMPIRBuilder's
1867  /// IRBuilder location is not preserved.
1868  ///
1869  /// \param DL DebugLoc used for the instructions in the skeleton.
1870  /// \param TripCount Value to be used for the trip count.
1871  /// \param F Function in which to insert the BasicBlocks.
1872  /// \param PreInsertBefore Where to insert BBs that execute before the body,
1873  /// typically the body itself.
1874  /// \param PostInsertBefore Where to insert BBs that execute after the body.
1875  /// \param Name Base name used to derive BB
1876  /// and instruction names.
1877  ///
1878  /// \returns The CanonicalLoopInfo that represents the emitted loop.
1880  Function *F,
1881  BasicBlock *PreInsertBefore,
1882  BasicBlock *PostInsertBefore,
1883  const Twine &Name = {});
1884  /// OMP Offload Info Metadata name string
1885  const std::string ompOffloadInfoName = "omp_offload.info";
1886 
1887  /// Loads all the offload entries information from the host IR
1888  /// metadata. This function is only meant to be used with device code
1889  /// generation.
1890  ///
1891  /// \param M Module to load Metadata info from. Module passed maybe
1892  /// loaded from bitcode file, i.e, different from OpenMPIRBuilder::M module.
1893  /// \param OffloadEntriesInfoManager Initialize Offload Entry information.
1894  void
1897 
1898  /// Gets (if variable with the given name already exist) or creates
1899  /// internal global variable with the specified Name. The created variable has
1900  /// linkage CommonLinkage by default and is initialized by null value.
1901  /// \param Ty Type of the global variable. If it is exist already the type
1902  /// must be the same.
1903  /// \param Name Name of the variable.
1905  unsigned AddressSpace = 0);
1906 };
1907 
1908 /// Data structure to contain the information needed to uniquely identify
1909 /// a target entry.
1911  std::string ParentName;
1912  unsigned DeviceID;
1913  unsigned FileID;
1914  unsigned Line;
1915  unsigned Count;
1916 
1918  : ParentName(""), DeviceID(0), FileID(0), Line(0), Count(0) {}
1920  unsigned FileID, unsigned Line, unsigned Count = 0)
1922  Count(Count) {}
1923 
1926  unsigned DeviceID, unsigned FileID,
1927  unsigned Line, unsigned Count);
1928 
1930  return std::make_tuple(ParentName, DeviceID, FileID, Line, Count) <
1931  std::make_tuple(RHS.ParentName, RHS.DeviceID, RHS.FileID, RHS.Line,
1932  RHS.Count);
1933  }
1934 };
1935 
1936 /// Class that manages information about offload code regions and data
1938  /// Number of entries registered so far.
1939  OpenMPIRBuilderConfig Config;
1940  unsigned OffloadingEntriesNum = 0;
1941 
1942 public:
1943  void setConfig(OpenMPIRBuilderConfig C) { Config = C; }
1944 
1945  /// Base class of the entries info.
1947  public:
1948  /// Kind of a given entry.
1949  enum OffloadingEntryInfoKinds : unsigned {
1950  /// Entry is a target region.
1952  /// Entry is a declare target variable.
1954  /// Invalid entry info.
1956  };
1957 
1958  protected:
1959  OffloadEntryInfo() = delete;
1960  explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {}
1961  explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
1962  uint32_t Flags)
1963  : Flags(Flags), Order(Order), Kind(Kind) {}
1964  ~OffloadEntryInfo() = default;
1965 
1966  public:
1967  bool isValid() const { return Order != ~0u; }
1968  unsigned getOrder() const { return Order; }
1969  OffloadingEntryInfoKinds getKind() const { return Kind; }
1970  uint32_t getFlags() const { return Flags; }
1971  void setFlags(uint32_t NewFlags) { Flags = NewFlags; }
1972  Constant *getAddress() const { return cast_or_null<Constant>(Addr); }
1974  assert(!Addr.pointsToAliveValue() && "Address has been set before!");
1975  Addr = V;
1976  }
1977  static bool classof(const OffloadEntryInfo *Info) { return true; }
1978 
1979  private:
1980  /// Address of the entity that has to be mapped for offloading.
1981  WeakTrackingVH Addr;
1982 
1983  /// Flags associated with the device global.
1984  uint32_t Flags = 0u;
1985 
1986  /// Order this entry was emitted.
1987  unsigned Order = ~0u;
1988 
1990  };
1991 
1992  /// Return true if a there are no entries defined.
1993  bool empty() const;
1994  /// Return number of entries defined so far.
1995  unsigned size() const { return OffloadingEntriesNum; }
1996 
1998 
1999  //
2000  // Target region entries related.
2001  //
2002 
2003  /// Kind of the target registry entry.
2005  /// Mark the entry as target region.
2007  /// Mark the entry as a global constructor.
2009  /// Mark the entry as a global destructor.
2011  };
2012 
2013  /// Target region entries info.
2015  /// Address that can be used as the ID of the entry.
2016  Constant *ID = nullptr;
2017 
2018  public:
2021  explicit OffloadEntryInfoTargetRegion(unsigned Order, Constant *Addr,
2022  Constant *ID,
2025  ID(ID) {
2026  setAddress(Addr);
2027  }
2028 
2029  Constant *getID() const { return ID; }
2030  void setID(Constant *V) {
2031  assert(!ID && "ID has been set before!");
2032  ID = V;
2033  }
2034  static bool classof(const OffloadEntryInfo *Info) {
2035  return Info->getKind() == OffloadingEntryInfoTargetRegion;
2036  }
2037  };
2038 
2039  /// Initialize target region entry.
2040  /// This is ONLY needed for DEVICE compilation.
2042  unsigned Order);
2043  /// Register target region entry.
2045  Constant *Addr, Constant *ID,
2046  OMPTargetRegionEntryKind Flags);
2047  /// Return true if a target region entry with the provided information
2048  /// exists.
2050  bool IgnoreAddressId = false) const;
2051 
2052  // Return the Name based on \a EntryInfo using the next available Count.
2054  const TargetRegionEntryInfo &EntryInfo);
2055 
2056  /// brief Applies action \a Action on all registered entries.
2057  typedef function_ref<void(const TargetRegionEntryInfo &EntryInfo,
2058  const OffloadEntryInfoTargetRegion &)>
2060  void
2062 
2063  //
2064  // Device global variable entries related.
2065  //
2066 
2067  /// Kind of the global variable entry..
2069  /// Mark the entry as a to declare target.
2071  /// Mark the entry as a to declare target link.
2073  };
2074 
2075  /// Device global variable entries info.
2077  /// Type of the global variable.
2078  int64_t VarSize;
2079  GlobalValue::LinkageTypes Linkage;
2080 
2081  public:
2084  explicit OffloadEntryInfoDeviceGlobalVar(unsigned Order,
2087  explicit OffloadEntryInfoDeviceGlobalVar(unsigned Order, Constant *Addr,
2088  int64_t VarSize,
2090  GlobalValue::LinkageTypes Linkage)
2092  VarSize(VarSize), Linkage(Linkage) {
2093  setAddress(Addr);
2094  }
2095 
2096  int64_t getVarSize() const { return VarSize; }
2097  void setVarSize(int64_t Size) { VarSize = Size; }
2098  GlobalValue::LinkageTypes getLinkage() const { return Linkage; }
2100  static bool classof(const OffloadEntryInfo *Info) {
2101  return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
2102  }
2103  };
2104 
2105  /// Initialize device global variable entry.
2106  /// This is ONLY used for DEVICE compilation.
2109  unsigned Order);
2110 
2111  /// Register device global variable entry.
2113  int64_t VarSize,
2115  GlobalValue::LinkageTypes Linkage);
2116  /// Checks if the variable with the given name has been registered already.
2118  return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
2119  }
2120  /// Applies action \a Action on all registered entries.
2121  typedef function_ref<void(StringRef, const OffloadEntryInfoDeviceGlobalVar &)>
2124  const OffloadDeviceGlobalVarEntryInfoActTy &Action);
2125 
2126 private:
2127  /// Return the count of entries at a particular source location.
2128  unsigned
2129  getTargetRegionEntryInfoCount(const TargetRegionEntryInfo &EntryInfo) const;
2130 
2131  /// Update the count of entries at a particular source location.
2132  void
2133  incrementTargetRegionEntryInfoCount(const TargetRegionEntryInfo &EntryInfo);
2134 
2135  static TargetRegionEntryInfo
2136  getTargetRegionEntryCountKey(const TargetRegionEntryInfo &EntryInfo) {
2137  return TargetRegionEntryInfo(EntryInfo.ParentName, EntryInfo.DeviceID,
2138  EntryInfo.FileID, EntryInfo.Line, 0);
2139  }
2140 
2141  // Count of entries at a location.
2142  std::map<TargetRegionEntryInfo, unsigned> OffloadEntriesTargetRegionCount;
2143 
2144  // Storage for target region entries kind.
2145  typedef std::map<TargetRegionEntryInfo, OffloadEntryInfoTargetRegion>
2146  OffloadEntriesTargetRegionTy;
2147  OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
2148  /// Storage for device global variable entries kind. The storage is to be
2149  /// indexed by mangled name.
2151  OffloadEntriesDeviceGlobalVarTy;
2152  OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
2153 };
2154 
2155 /// Class to represented the control flow structure of an OpenMP canonical loop.
2156 ///
2157 /// The control-flow structure is standardized for easy consumption by
2158 /// directives associated with loops. For instance, the worksharing-loop
2159 /// construct may change this control flow such that each loop iteration is
2160 /// executed on only one thread. The constraints of a canonical loop in brief
2161 /// are:
2162 ///
2163 /// * The number of loop iterations must have been computed before entering the
2164 /// loop.
2165 ///
2166 /// * Has an (unsigned) logical induction variable that starts at zero and
2167 /// increments by one.
2168 ///
2169 /// * The loop's CFG itself has no side-effects. The OpenMP specification
2170 /// itself allows side-effects, but the order in which they happen, including
2171 /// how often or whether at all, is unspecified. We expect that the frontend
2172 /// will emit those side-effect instructions somewhere (e.g. before the loop)
2173 /// such that the CanonicalLoopInfo itself can be side-effect free.
2174 ///
2175 /// Keep in mind that CanonicalLoopInfo is meant to only describe a repeated
2176 /// execution of a loop body that satifies these constraints. It does NOT
2177 /// represent arbitrary SESE regions that happen to contain a loop. Do not use
2178 /// CanonicalLoopInfo for such purposes.
2179 ///
2180 /// The control flow can be described as follows:
2181 ///
2182 /// Preheader
2183 /// |
2184 /// /-> Header
2185 /// | |
2186 /// | Cond---\
2187 /// | | |
2188 /// | Body |
2189 /// | | | |
2190 /// | <...> |
2191 /// | | | |
2192 /// \--Latch |
2193 /// |
2194 /// Exit
2195 /// |
2196 /// After
2197 ///
2198 /// The loop is thought to start at PreheaderIP (at the Preheader's terminator,
2199 /// including) and end at AfterIP (at the After's first instruction, excluding).
2200 /// That is, instructions in the Preheader and After blocks (except the
2201 /// Preheader's terminator) are out of CanonicalLoopInfo's control and may have
2202 /// side-effects. Typically, the Preheader is used to compute the loop's trip
2203 /// count. The instructions from BodyIP (at the Body block's first instruction,
2204 /// excluding) until the Latch are also considered outside CanonicalLoopInfo's
2205 /// control and thus can have side-effects. The body block is the single entry
2206 /// point into the loop body, which may contain arbitrary control flow as long
2207 /// as all control paths eventually branch to the Latch block.
2208 ///
2209 /// TODO: Consider adding another standardized BasicBlock between Body CFG and
2210 /// Latch to guarantee that there is only a single edge to the latch. It would
2211 /// make loop transformations easier to not needing to consider multiple
2212 /// predecessors of the latch (See redirectAllPredecessorsTo) and would give us
2213 /// an equivalant to PreheaderIP, AfterIP and BodyIP for inserting code that
2214 /// executes after each body iteration.
2215 ///
2216 /// There must be no loop-carried dependencies through llvm::Values. This is
2217 /// equivalant to that the Latch has no PHINode and the Header's only PHINode is
2218 /// for the induction variable.
2219 ///
2220 /// All code in Header, Cond, Latch and Exit (plus the terminator of the
2221 /// Preheader) are CanonicalLoopInfo's responsibility and their build-up checked
2222 /// by assertOK(). They are expected to not be modified unless explicitly
2223 /// modifying the CanonicalLoopInfo through a methods that applies a OpenMP
2224 /// loop-associated construct such as applyWorkshareLoop, tileLoops, unrollLoop,
2225 /// etc. These methods usually invalidate the CanonicalLoopInfo and re-use its
2226 /// basic blocks. After invalidation, the CanonicalLoopInfo must not be used
2227 /// anymore as its underlying control flow may not exist anymore.
2228 /// Loop-transformation methods such as tileLoops, collapseLoops and unrollLoop
2229 /// may also return a new CanonicalLoopInfo that can be passed to other
2230 /// loop-associated construct implementing methods. These loop-transforming
2231 /// methods may either create a new CanonicalLoopInfo usually using
2232 /// createLoopSkeleton and invalidate the input CanonicalLoopInfo, or reuse and
2233 /// modify one of the input CanonicalLoopInfo and return it as representing the
2234 /// modified loop. What is done is an implementation detail of
2235 /// transformation-implementing method and callers should always assume that the
2236 /// CanonicalLoopInfo passed to it is invalidated and a new object is returned.
2237 /// Returned CanonicalLoopInfo have the same structure and guarantees as the one
2238 /// created by createCanonicalLoop, such that transforming methods do not have
2239 /// to special case where the CanonicalLoopInfo originated from.
2240 ///
2241 /// Generally, methods consuming CanonicalLoopInfo do not need an
2242 /// OpenMPIRBuilder::InsertPointTy as argument, but use the locations of the
2243 /// CanonicalLoopInfo to insert new or modify existing instructions. Unless
2244 /// documented otherwise, methods consuming CanonicalLoopInfo do not invalidate
2245 /// any InsertPoint that is outside CanonicalLoopInfo's control. Specifically,
2246 /// any InsertPoint in the Preheader, After or Block can still be used after
2247 /// calling such a method.
2248 ///
2249 /// TODO: Provide mechanisms for exception handling and cancellation points.
2250 ///
2251 /// Defined outside OpenMPIRBuilder because nested classes cannot be
2252 /// forward-declared, e.g. to avoid having to include the entire OMPIRBuilder.h.
2254  friend class OpenMPIRBuilder;
2255 
2256 private:
2257  BasicBlock *Header = nullptr;
2258  BasicBlock *Cond = nullptr;
2259  BasicBlock *Latch = nullptr;
2260  BasicBlock *Exit = nullptr;
2261 
2262  /// Add the control blocks of this loop to \p BBs.
2263  ///
2264  /// This does not include any block from the body, including the one returned
2265  /// by getBody().
2266  ///
2267  /// FIXME: This currently includes the Preheader and After blocks even though
2268  /// their content is (mostly) not under CanonicalLoopInfo's control.
2269  /// Re-evaluated whether this makes sense.
2270  void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
2271 
2272  /// Sets the number of loop iterations to the given value. This value must be
2273  /// valid in the condition block (i.e., defined in the preheader) and is
2274  /// interpreted as an unsigned integer.
2275  void setTripCount(Value *TripCount);
2276 
2277  /// Replace all uses of the canonical induction variable in the loop body with
2278  /// a new one.
2279  ///
2280  /// The intended use case is to update the induction variable for an updated
2281  /// iteration space such that it can stay normalized in the 0...tripcount-1
2282  /// range.
2283  ///
2284  /// The \p Updater is called with the (presumable updated) current normalized
2285  /// induction variable and is expected to return the value that uses of the
2286  /// pre-updated induction values should use instead, typically dependent on
2287  /// the new induction variable. This is a lambda (instead of e.g. just passing
2288  /// the new value) to be able to distinguish the uses of the pre-updated
2289  /// induction variable and uses of the induction varible to compute the
2290  /// updated induction variable value.
2291  void mapIndVar(llvm::function_ref<Value *(Instruction *)> Updater);
2292 
2293 public:
2294  /// Returns whether this object currently represents the IR of a loop. If
2295  /// returning false, it may have been consumed by a loop transformation or not
2296  /// been intialized. Do not use in this case;
2297  bool isValid() const { return Header; }
2298 
2299  /// The preheader ensures that there is only a single edge entering the loop.
2300  /// Code that must be execute before any loop iteration can be emitted here,
2301  /// such as computing the loop trip count and begin lifetime markers. Code in
2302  /// the preheader is not considered part of the canonical loop.
2303  BasicBlock *getPreheader() const;
2304 
2305  /// The header is the entry for each iteration. In the canonical control flow,
2306  /// it only contains the PHINode for the induction variable.
2308  assert(isValid() && "Requires a valid canonical loop");
2309  return Header;
2310  }
2311 
2312  /// The condition block computes whether there is another loop iteration. If
2313  /// yes, branches to the body; otherwise to the exit block.
2314  BasicBlock *getCond() const {
2315  assert(isValid() && "Requires a valid canonical loop");
2316  return Cond;
2317  }
2318 
2319  /// The body block is the single entry for a loop iteration and not controlled
2320  /// by CanonicalLoopInfo. It can contain arbitrary control flow but must
2321  /// eventually branch to the \p Latch block.
2322  BasicBlock *getBody() const {
2323  assert(isValid() && "Requires a valid canonical loop");
2324  return cast<BranchInst>(Cond->getTerminator())->getSuccessor(0);
2325  }
2326 
2327  /// Reaching the latch indicates the end of the loop body code. In the
2328  /// canonical control flow, it only contains the increment of the induction
2329  /// variable.
2331  assert(isValid() && "Requires a valid canonical loop");
2332  return Latch;
2333  }
2334 
2335  /// Reaching the exit indicates no more iterations are being executed.
2336  BasicBlock *getExit() const {
2337  assert(isValid() && "Requires a valid canonical loop");
2338  return Exit;
2339  }
2340 
2341  /// The after block is intended for clean-up code such as lifetime end
2342  /// markers. It is separate from the exit block to ensure, analogous to the
2343  /// preheader, it having just a single entry edge and being free from PHI
2344  /// nodes should there be multiple loop exits (such as from break
2345  /// statements/cancellations).
2347  assert(isValid() && "Requires a valid canonical loop");
2348  return Exit->getSingleSuccessor();
2349  }
2350 
2351  /// Returns the llvm::Value containing the number of loop iterations. It must
2352  /// be valid in the preheader and always interpreted as an unsigned integer of
2353  /// any bit-width.
2354  Value *getTripCount() const {
2355  assert(isValid() && "Requires a valid canonical loop");
2356  Instruction *CmpI = &Cond->front();
2357  assert(isa<CmpInst>(CmpI) && "First inst must compare IV with TripCount");
2358  return CmpI->getOperand(1);
2359  }
2360 
2361  /// Returns the instruction representing the current logical induction
2362  /// variable. Always unsigned, always starting at 0 with an increment of one.
2364  assert(isValid() && "Requires a valid canonical loop");
2365  Instruction *IndVarPHI = &Header->front();
2366  assert(isa<PHINode>(IndVarPHI) && "First inst must be the IV PHI");
2367  return IndVarPHI;
2368  }
2369 
2370  /// Return the type of the induction variable (and the trip count).
2371  Type *getIndVarType() const {
2372  assert(isValid() && "Requires a valid canonical loop");
2373  return getIndVar()->getType();
2374  }
2375 
2376  /// Return the insertion point for user code before the loop.
2378  assert(isValid() && "Requires a valid canonical loop");
2379  BasicBlock *Preheader = getPreheader();
2380  return {Preheader, std::prev(Preheader->end())};
2381  };
2382 
2383  /// Return the insertion point for user code in the body.
2385  assert(isValid() && "Requires a valid canonical loop");
2386  BasicBlock *Body = getBody();
2387  return {Body, Body->begin()};
2388  };
2389 
2390  /// Return the insertion point for user code after the loop.
2392  assert(isValid() && "Requires a valid canonical loop");
2393  BasicBlock *After = getAfter();
2394  return {After, After->begin()};
2395  };
2396 
2398  assert(isValid() && "Requires a valid canonical loop");
2399  return Header->getParent();
2400  }
2401 
2402  /// Consistency self-check.
2403  void assertOK() const;
2404 
2405  /// Invalidate this loop. That is, the underlying IR does not fulfill the
2406  /// requirements of an OpenMP canonical loop anymore.
2407  void invalidate();
2408 };
2409 
2410 } // end namespace llvm
2411 
2412 #endif // LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
llvm::OffloadEntriesInfoManager::OffloadEntryInfoDeviceGlobalVar::OffloadEntryInfoDeviceGlobalVar
OffloadEntryInfoDeviceGlobalVar(unsigned Order, OMPTargetGlobalVarEntryKind Flags)
Definition: OMPIRBuilder.h:2084
llvm::OpenMPIRBuilderConfig::setIsTargetCodegen
void setIsTargetCodegen(bool Value)
Definition: OMPIRBuilder.h:155
llvm::CanonicalLoopInfo::getPreheaderIP
OpenMPIRBuilder::InsertPointTy getPreheaderIP() const
Return the insertion point for user code before the loop.
Definition: OMPIRBuilder.h:2377
llvm::OpenMPIRBuilder::createCachedThreadPrivate
CallInst * createCachedThreadPrivate(const LocationDescription &Loc, llvm::Value *Pointer, llvm::ConstantInt *Size, const llvm::Twine &Name=Twine(""))
Create a runtime call for kmpc_threadprivate_cached.
Definition: OMPIRBuilder.cpp:3867
llvm::BasicBlock::end
iterator end()
Definition: BasicBlock.h:316
llvm::IRBuilderBase::restoreIP
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
Definition: IRBuilder.h:275
llvm::OpenMPIRBuilderConfig::firstSeparator
StringRef firstSeparator() const
Definition: OMPIRBuilder.h:136
llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryKind
OMPTargetRegionEntryKind
Kind of the target registry entry.
Definition: OMPIRBuilder.h:2004
llvm::OpenMPIRBuilder::LocationDescription
Description of a LLVM-IR insertion point (IP) and a debug/source location (filename,...
Definition: OMPIRBuilder.h:305
llvm::OpenMPIRBuilder::TargetDataRTArgs::MapNamesArray
Value * MapNamesArray
The array of original declaration names of mapped pointers sent to the runtime library for debugging.
Definition: OMPIRBuilder.h:1153
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::OffloadEntryInfo
OffloadEntryInfo()=delete
llvm::OpenMPIRBuilder::OutlineInfo::ExitBB
BasicBlock * ExitBB
Definition: OMPIRBuilder.h:1069
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::OpenMPIRBuilder::DependData
A struct to pack the relevant information for an OpenMP depend clause.
Definition: OMPIRBuilder.h:758
llvm::OpenMPIRBuilder::createSection
InsertPointTy createSection(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB)
Generator for '#omp section'.
Definition: OMPIRBuilder.cpp:1674
llvm::TargetRegionEntryInfo::DeviceID
unsigned DeviceID
Definition: OMPIRBuilder.h:1912
llvm::OpenMPIRBuilder::createCritical
InsertPointTy createCritical(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, StringRef CriticalName, Value *HintInst)
Generator for '#omp critical'.
Definition: OMPIRBuilder.cpp:3478
llvm::CanonicalLoopInfo::getAfter
BasicBlock * getAfter() const
The after block is intended for clean-up code such as lifetime end markers.
Definition: OMPIRBuilder.h:2346
llvm::WeakTrackingVH
Value handle that is nullable, but tries to track the Value.
Definition: ValueHandle.h:204
llvm::TargetRegionEntryInfo::Count
unsigned Count
Definition: OMPIRBuilder.h:1915
llvm::OpenMPIRBuilder::OutlineInfo::ExcludeArgsFromAggregate
SmallVector< Value *, 2 > ExcludeArgsFromAggregate
Definition: OMPIRBuilder.h:1070
llvm::OpenMPIRBuilderConfig::HasRequiresUnifiedSharedMemory
std::optional< bool > HasRequiresUnifiedSharedMemory
Flag for specifying weather a requires unified_shared_memory directive is present or not.
Definition: OMPIRBuilder.h:94
llvm::TargetRegionEntryInfo::TargetRegionEntryInfo
TargetRegionEntryInfo(StringRef ParentName, unsigned DeviceID, unsigned FileID, unsigned Line, unsigned Count=0)
Definition: OMPIRBuilder.h:1919
llvm::OpenMPIRBuilderConfig::isTargetCodegen
bool isTargetCodegen() const
Definition: OMPIRBuilder.h:118
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:112
llvm::OffloadEntriesInfoManager::getTargetRegionEntryFnName
void getTargetRegionEntryFnName(SmallVectorImpl< char > &Name, const TargetRegionEntryInfo &EntryInfo)
Definition: OMPIRBuilder.cpp:4968
llvm::OpenMPIRBuilder::createLoopSkeleton
CanonicalLoopInfo * createLoopSkeleton(DebugLoc DL, Value *TripCount, Function *F, BasicBlock *PreInsertBefore, BasicBlock *PostInsertBefore, const Twine &Name={})
Create the control flow structure of a canonical OpenMP loop.
Definition: OMPIRBuilder.cpp:1933
llvm::CanonicalLoopInfo::getPreheader
BasicBlock * getPreheader() const
The preheader ensures that there is only a single edge entering the loop.
Definition: OMPIRBuilder.cpp:5168
llvm::OpenMPIRBuilder::pushFinalizationCB
void pushFinalizationCB(const FinalizationInfo &FI)
Push a finalization callback on the finalization stack.
Definition: OMPIRBuilder.h:227
MemorySSAUpdater.h
llvm::Function
Definition: Function.h:59
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:547
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::getAddress
Constant * getAddress() const
Definition: OMPIRBuilder.h:1972
llvm::OffloadEntriesInfoManager::OffloadEntryInfoDeviceGlobalVar::classof
static bool classof(const OffloadEntryInfo *Info)
Definition: OMPIRBuilder.h:2100
llvm::OpenMPIRBuilder::createOMPInteropUse
CallInst * createOMPInteropUse(const LocationDescription &Loc, Value *InteropVar, Value *Device, Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause)
Create a runtime call for __tgt_interop_use.
Definition: OMPIRBuilder.cpp:3839
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::OffloadingEntryInfoTargetRegion
@ OffloadingEntryInfoTargetRegion
Entry is a target region.
Definition: OMPIRBuilder.h:1951
Loops
Hexagon Hardware Loops
Definition: HexagonHardwareLoops.cpp:374
llvm::OffloadEntriesInfoManager::registerDeviceGlobalVarEntryInfo
void registerDeviceGlobalVarEntryInfo(StringRef VarName, Constant *Addr, int64_t VarSize, OMPTargetGlobalVarEntryKind Flags, GlobalValue::LinkageTypes Linkage)
Register device global variable entry.
Definition: OMPIRBuilder.cpp:5116
llvm::AtomicRMWInst::BinOp
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:730
llvm::OpenMPIRBuilderConfig
Captures attributes that affect generating LLVM-IR using the OpenMPIRBuilder and related classes.
Definition: OMPIRBuilder.h:82
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::OpenMPIRBuilder::tileLoops
std::vector< CanonicalLoopInfo * > tileLoops(DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, ArrayRef< Value * > TileSizes)
Tile a loop nest.
Definition: OMPIRBuilder.cpp:2741
llvm::OpenMPIRBuilder::ompOffloadInfoName
const std::string ompOffloadInfoName
OMP Offload Info Metadata name string.
Definition: OMPIRBuilder.h:1885
llvm::OpenMPIRBuilder::EmitMetadataErrorReportFunctionTy
std::function< void(EmitMetadataErrorKind, TargetRegionEntryInfo)> EmitMetadataErrorReportFunctionTy
Callback function type.
Definition: OMPIRBuilder.h:1219
llvm::OpenMPIRBuilder::DependData::DependData
DependData()=default
llvm::OpenMPIRBuilder::InsertPointTy
IRBuilder<>::InsertPoint InsertPointTy
Type used throughout for insertion points.
Definition: OMPIRBuilder.h:189
llvm::IRBuilder<>
llvm::OpenMPIRBuilder::EMIT_MD_TARGET_REGION_ERROR
@ EMIT_MD_TARGET_REGION_ERROR
Definition: OMPIRBuilder.h:1212
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::OpenMPIRBuilder::getOrCreateThreadID
Value * getOrCreateThreadID(Value *Ident)
Return the current thread ID.
Definition: OMPIRBuilder.cpp:662
Allocator.h
llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryCtor
@ OMPTargetRegionEntryCtor
Mark the entry as a global constructor.
Definition: OMPIRBuilder.h:2008
llvm::OpenMPIRBuilder::createAtomicUpdate
InsertPointTy createAtomicUpdate(const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &X, Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp, bool IsXBinopExpr)
Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X For complex Operations: X = ...
Definition: OMPIRBuilder.cpp:4341
llvm::TargetRegionEntryInfo::getTargetRegionEntryFnName
static void getTargetRegionEntryFnName(SmallVectorImpl< char > &Name, StringRef ParentName, unsigned DeviceID, unsigned FileID, unsigned Line, unsigned Count)
Definition: OMPIRBuilder.cpp:4958
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::tgtok::VarName
@ VarName
Definition: TGLexer.h:72
llvm::OpenMPIRBuilder::FinalizationInfo::IsCancellable
bool IsCancellable
Flag to indicate if the directive is cancellable.
Definition: OMPIRBuilder.h:221
llvm::OffloadEntriesInfoManager::empty
bool empty() const
Return true if a there are no entries defined.
Definition: OMPIRBuilder.cpp:5025
llvm::OpenMPIRBuilderConfig::openMPOffloadMandatory
bool openMPOffloadMandatory() const
Definition: OMPIRBuilder.h:129
llvm::X86AS::FS
@ FS
Definition: X86.h:201
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::OpenMPIRBuilder::TargetDataInfo::TargetDataInfo
TargetDataInfo()
Definition: OMPIRBuilder.h:1173
llvm::OpenMPIRBuilder::StorableBodyGenCallbackTy
std::function< void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)> StorableBodyGenCallbackTy
Definition: OMPIRBuilder.h:268
llvm::OpenMPIRBuilder::AtomicOpValue
a struct to pack relevant information while generating atomic Ops
Definition: OMPIRBuilder.h:1715
llvm::OpenMPIRBuilder::FinalizationInfo::FiniCB
FinalizeCallbackTy FiniCB
The finalization callback provided by the last in-flight invocation of createXXXX for the directive o...
Definition: OMPIRBuilder.h:214
llvm::CanonicalLoopInfo::getAfterIP
OpenMPIRBuilder::InsertPointTy getAfterIP() const
Return the insertion point for user code after the loop.
Definition: OMPIRBuilder.h:2391
llvm::OffloadEntriesInfoManager::initializeTargetRegionEntryInfo
void initializeTargetRegionEntryInfo(const TargetRegionEntryInfo &EntryInfo, unsigned Order)
Initialize target region entry.
Definition: OMPIRBuilder.cpp:5046
llvm::BasicBlock::getSingleSuccessor
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:314
llvm::OpenMPIRBuilder::DependData::DependData
DependData(omp::RTLDependenceKindTy DepKind, Type *DepValueType, Value *DepVal)
Definition: OMPIRBuilder.h:763
llvm::spliceBB
void spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New, bool CreateBranch)
Move the instruction after an InsertPoint to the beginning of another BasicBlock.
Definition: OMPIRBuilder.cpp:258
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::getOrder
unsigned getOrder() const
Definition: OMPIRBuilder.h:1968
llvm::OpenMPIRBuilder::createTargetInit
InsertPointTy createTargetInit(const LocationDescription &Loc, bool IsSPMD)
The omp target interface.
Definition: OMPIRBuilder.cpp:3888
llvm::OpenMPIRBuilder::createSingle
InsertPointTy createSingle(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, bool IsNowait, llvm::Value *DidIt)
Generator for '#omp single'.
Definition: OMPIRBuilder.cpp:3436
llvm::MapVector
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:37
llvm::OpenMPIRBuilderConfig::isEmbedded
bool isEmbedded() const
Definition: OMPIRBuilder.h:113
llvm::OpenMPIRBuilder::ReductionInfo::Variable
Value * Variable
Reduction variable of pointer type.
Definition: OMPIRBuilder.h:826
llvm::OpenMPIRBuilder::FinalizeCallbackTy
std::function< void(InsertPointTy CodeGenIP)> FinalizeCallbackTy
Callback type for variable finalization (think destructors).
Definition: OMPIRBuilder.h:209
llvm::CanonicalLoopInfo::getFunction
Function * getFunction() const
Definition: OMPIRBuilder.h:2397
llvm::OpenMPIRBuilder::TargetDataRTArgs
Container for the arguments used to pass data to the runtime library.
Definition: OMPIRBuilder.h:1133
llvm::OpenMPIRBuilder::AtomicOpValue::Var
Value * Var
Definition: OMPIRBuilder.h:1716
llvm::OffloadEntriesInfoManager::OffloadEntriesInfoManager
OffloadEntriesInfoManager()
Definition: OMPIRBuilder.h:1997
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::OpenMPIRBuilder::DependData::DepValueType
Type * DepValueType
Definition: OMPIRBuilder.h:760
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
llvm::OffloadEntriesInfoManager::size
unsigned size() const
Return number of entries defined so far.
Definition: OMPIRBuilder.h:1995
llvm::OffloadEntriesInfoManager::OffloadEntryInfoDeviceGlobalVar::setLinkage
void setLinkage(GlobalValue::LinkageTypes LT)
Definition: OMPIRBuilder.h:2099
llvm::OpenMPIRBuilder::emitTaskyieldImpl
void emitTaskyieldImpl(const LocationDescription &Loc)
Generate a taskyield runtime call.
Definition: OMPIRBuilder.cpp:1264
llvm::OpenMPIRBuilder::getOpenMPDefaultSimdAlign
static unsigned getOpenMPDefaultSimdAlign(const Triple &TargetTriple, const StringMap< bool > &Features)
Get the default alignment value for given target.
Definition: OMPIRBuilder.cpp:3057
llvm::OpenMPIRBuilder::createReductions
InsertPointTy createReductions(const LocationDescription &Loc, InsertPointTy AllocaIP, ArrayRef< ReductionInfo > ReductionInfos, bool IsNoWait=false)
Generator for '#omp reduction'.
Definition: OMPIRBuilder.cpp:1720
llvm::omp::RTLDependenceKindTy::DepUnknown
@ DepUnknown
llvm::OpenMPIRBuilder::collapseLoops
CanonicalLoopInfo * collapseLoops(DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, InsertPointTy ComputeIP)
Collapse a loop nest into a single loop.
Definition: OMPIRBuilder.cpp:2613
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::OpenMPIRBuilderConfig::OpenMPOffloadMandatory
std::optional< bool > OpenMPOffloadMandatory
Definition: OMPIRBuilder.h:97
llvm::CanonicalLoopInfo::getIndVar
Instruction * getIndVar() const
Returns the instruction representing the current logical induction variable.
Definition: OMPIRBuilder.h:2363
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::AArch64CC::LT
@ LT
Definition: AArch64BaseInfo.h:266
llvm::OpenMPIRBuilder::createOrderedDepend
InsertPointTy createOrderedDepend(const LocationDescription &Loc, InsertPointTy AllocaIP, unsigned NumLoops, ArrayRef< llvm::Value * > StoreValues, const Twine &Name, bool IsDependSource)
Generator for '#omp ordered depend (source | sink)'.
Definition: OMPIRBuilder.cpp:3513
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::getFlags
uint32_t getFlags() const
Definition: OMPIRBuilder.h:1970
Mappings
Inject TLI Mappings
Definition: InjectTLIMappings.cpp:171
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
llvm::OffloadEntriesInfoManager
Class that manages information about offload code regions and data.
Definition: OMPIRBuilder.h:1937
llvm::omp::OMPInteropType
OMPInteropType
Definition: OMPConstants.h:253
llvm::OpenMPIRBuilder::popFinalizationCB
void popFinalizationCB()
Pop the last finalization callback from the finalization stack.
Definition: OMPIRBuilder.h:234
llvm::OpenMPIRBuilder::TargetDataRTArgs::BasePointersArray
Value * BasePointersArray
The array of base pointer passed to the runtime library.
Definition: OMPIRBuilder.h:1136
llvm::OffloadEntriesInfoManager::hasTargetRegionEntryInfo
bool hasTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo, bool IgnoreAddressId=false) const
Return true if a target region entry with the provided information exists.
Definition: OMPIRBuilder.cpp:5086
llvm::OffloadEntriesInfoManager::OMPTargetGlobalVarEntryLink
@ OMPTargetGlobalVarEntryLink
Mark the entry as a to declare target link.
Definition: OMPIRBuilder.h:2072
llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion::OffloadEntryInfoTargetRegion
OffloadEntryInfoTargetRegion()
Definition: OMPIRBuilder.h:2019
llvm::OpenMPIRBuilder::TargetDataRTArgs::MappersArray
Value * MappersArray
The array of user-defined mappers passed to the runtime library.
Definition: OMPIRBuilder.h:1150
llvm::OpenMPIRBuilder::applySimd
void applySimd(CanonicalLoopInfo *Loop, MapVector< Value *, Value * > AlignedVars, Value *IfCond, omp::OrderKind Order, ConstantInt *Simdlen, ConstantInt *Safelen)
Add metadata to simd-ize a loop.
Definition: OMPIRBuilder.cpp:3073
llvm::OpenMPIRBuilder::emitMapperCall
void emitMapperCall(const LocationDescription &Loc, Function *MapperFunc, Value *SrcLocInfo, Value *MaptypesArg, Value *MapnamesArg, struct MapperAllocas &MapperAllocas, int64_t DeviceID, unsigned NumOperands)
Create the call for the target mapper function.
Definition: OMPIRBuilder.cpp:4120
llvm::OpenMPIRBuilder::emitOffloadingArraysArgument
void emitOffloadingArraysArgument(IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs, OpenMPIRBuilder::TargetDataInfo &Info, bool EmitDebug=false, bool ForEndCall=false)
Emit the arguments to be passed to the runtime library based on the arrays of base pointers,...
Definition: OMPIRBuilder.cpp:4146
llvm::OpenMPIRBuilder::M
Module & M
The underlying LLVM-IR module.
Definition: OMPIRBuilder.h:1053
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::CanonicalLoopInfo::assertOK
void assertOK() const
Consistency self-check.
Definition: OMPIRBuilder.cpp:5222
llvm::CanonicalLoopInfo::getCond
BasicBlock * getCond() const
The condition block computes whether there is another loop iteration.
Definition: OMPIRBuilder.h:2314
llvm::OpenMPIRBuilder
An interface to create LLVM-IR for OpenMP directives.
Definition: OMPIRBuilder.h:166
llvm::OpenMPIRBuilder::OutlineInfos
SmallVector< OutlineInfo, 16 > OutlineInfos
Collection of regions that need to be outlined during finalization.
Definition: OMPIRBuilder.h:1082
llvm::OpenMPIRBuilder::createOMPFree
CallInst * createOMPFree(const LocationDescription &Loc, Value *Addr, Value *Allocator, std::string Name="")
Create a runtime call for kmpc_free.
Definition: OMPIRBuilder.cpp:3768
llvm::OpenMPIRBuilderConfig::hasRequiresUnifiedSharedMemory
bool hasRequiresUnifiedSharedMemory() const
Definition: OMPIRBuilder.h:123
llvm::OffloadEntriesInfoManager::OffloadEntryInfoDeviceGlobalVar
Device global variable entries info.
Definition: OMPIRBuilder.h:2076
llvm::OffloadEntriesInfoManager::setConfig
void setConfig(OpenMPIRBuilderConfig C)
Definition: OMPIRBuilder.h:1943
llvm::OpenMPIRBuilder::getOrCreateDefaultSrcLocStr
Constant * getOrCreateDefaultSrcLocStr(uint32_t &SrcLocStrSize)
Return the (LLVM-IR) string describing the default source location.
Definition: OMPIRBuilder.cpp:634
llvm::OpenMPIRBuilder::emitOffloadingEntry
void emitOffloadingEntry(Constant *Addr, StringRef Name, uint64_t Size, int32_t Flags, StringRef SectionName="omp_offloading_entries")
Create an offloading section struct used to register this global at runtime.
Definition: OMPIRBuilder.cpp:777
llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion::classof
static bool classof(const OffloadEntryInfo *Info)
Definition: OMPIRBuilder.h:2034
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::BasicBlock::begin
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:314
llvm::OpenMPIRBuilder::createMapperAllocas
void createMapperAllocas(const LocationDescription &Loc, InsertPointTy AllocaIP, unsigned NumOperands, struct MapperAllocas &MapperAllocas)
Create the allocas instruction used in call to mapper functions.
Definition: OMPIRBuilder.cpp:4101
llvm::OpenMPIRBuilder::createTask
InsertPointTy createTask(const LocationDescription &Loc, InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB, bool Tied=true, Value *Final=nullptr, Value *IfCondition=nullptr, SmallVector< DependData > Dependencies={})
Generator for #omp task
Definition: OMPIRBuilder.cpp:1283
llvm::OpenMPIRBuilder::TargetDataInfo::NumberOfPtrs
unsigned NumberOfPtrs
The total number of pointers passed to the runtime library.
Definition: OMPIRBuilder.h:1171
llvm::OpenMPIRBuilder::createBarrier
InsertPointTy createBarrier(const LocationDescription &Loc, omp::Directive DK, bool ForceSimpleCall=false, bool CheckCancelFlag=true)
Emitter methods for OpenMP directives.
Definition: OMPIRBuilder.cpp:669
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::OffloadingEntryInfoKinds
OffloadingEntryInfoKinds
Kind of a given entry.
Definition: OMPIRBuilder.h:1949
llvm::OpenMPIRBuilder::createAtomicRead
InsertPointTy createAtomicRead(const LocationDescription &Loc, AtomicOpValue &X, AtomicOpValue &V, AtomicOrdering AO)
Emit atomic Read for : V = X — Only Scalar data types.
Definition: OMPIRBuilder.cpp:4266
llvm::OpenMPIRBuilder::TargetDataInfo::clearArrayInfo
void clearArrayInfo()
Clear information about the data arrays.
Definition: OMPIRBuilder.h:1179
llvm::OffloadEntriesInfoManager::OffloadEntryInfoDeviceGlobalVar::getVarSize
int64_t getVarSize() const
Definition: OMPIRBuilder.h:2096
llvm::TargetRegionEntryInfo::operator<
bool operator<(const TargetRegionEntryInfo RHS) const
Definition: OMPIRBuilder.h:1929
llvm::OpenMPIRBuilder::IdentMap
DenseMap< std::pair< Constant *, uint64_t >, Constant * > IdentMap
Map to remember existing ident_t*.
Definition: OMPIRBuilder.h:1062
llvm::OpenMPIRBuilder::getOrCreateInternalVariable
GlobalVariable * getOrCreateInternalVariable(Type *Ty, const StringRef &Name, unsigned AddressSpace=0)
Gets (if variable with the given name already exist) or creates internal global variable with the spe...
Definition: OMPIRBuilder.cpp:4061
llvm::OpenMPIRBuilder::getInsertionPoint
InsertPointTy getInsertionPoint()
}
Definition: OMPIRBuilder.h:912
llvm::IRBuilderBase::SetCurrentDebugLocation
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Definition: IRBuilder.h:212
llvm::OpenMPIRBuilder::~OpenMPIRBuilder
~OpenMPIRBuilder()
Definition: OMPIRBuilder.cpp:539
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::CanonicalLoopInfo::isValid
bool isValid() const
Returns whether this object currently represents the IR of a loop.
Definition: OMPIRBuilder.h:2297
llvm::OpenMPIRBuilder::getOrCreateSrcLocStr
Constant * getOrCreateSrcLocStr(StringRef LocStr, uint32_t &SrcLocStrSize)
Return the (LLVM-IR) string describing the source location LocStr.
Definition: OMPIRBuilder.cpp:594
llvm::OpenMPIRBuilder::AtomicOpValue::IsSigned
bool IsSigned
Definition: OMPIRBuilder.h:1718
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const InsertPointTy &IP)
Definition: OMPIRBuilder.h:308
llvm::Instruction
Definition: Instruction.h:41
llvm::OpenMPIRBuilder::createAtomicCompare
InsertPointTy createAtomicCompare(const LocationDescription &Loc, AtomicOpValue &X, AtomicOpValue &V, AtomicOpValue &R, Value *E, Value *D, AtomicOrdering AO, omp::OMPAtomicCompareOp Op, bool IsXBinopExpr, bool IsPostfixUpdate, bool IsFailOnly)
Emit atomic compare for constructs: — Only scalar data types cond-expr-stmt: x = x ordop expr ?...
Definition: OMPIRBuilder.cpp:4549
llvm::splitBBWithSuffix
BasicBlock * splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch, llvm::Twine Suffix=".split")
Like splitBB, but reuses the current block's name for the new name.
Definition: OMPIRBuilder.cpp:325
llvm::OpenMPIRBuilder::EMIT_MD_GLOBAL_VAR_LINK_ERROR
@ EMIT_MD_GLOBAL_VAR_LINK_ERROR
Definition: OMPIRBuilder.h:1214
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::OffloadingEntryInfoInvalid
@ OffloadingEntryInfoInvalid
Invalid entry info.
Definition: OMPIRBuilder.h:1955
llvm::OpenMPIRBuilder::createOffloadEntriesAndInfoMetadata
void createOffloadEntriesAndInfoMetadata(OffloadEntriesInfoManager &OffloadEntriesInfoManager, EmitMetadataErrorReportFunctionTy &ErrorReportFunction)
Definition: OMPIRBuilder.cpp:4813
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const InsertPointTy &IP, const DebugLoc &DL)
Definition: OMPIRBuilder.h:309
llvm::CanonicalLoopInfo::getBodyIP
OpenMPIRBuilder::InsertPointTy getBodyIP() const
Return the insertion point for user code in the body.
Definition: OMPIRBuilder.h:2384
DebugLoc.h
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::OpenMPIRBuilder::TargetDataInfo::RTArgs
TargetDataRTArgs RTArgs
Definition: OMPIRBuilder.h:1166
llvm::OpenMPIRBuilder::MapperAllocas::Args
AllocaInst * Args
Definition: OMPIRBuilder.h:1109
llvm::OpenMPIRBuilder::TargetDataInfo::isValid
bool isValid()
Return true if the current target data information has valid arrays.
Definition: OMPIRBuilder.h:1185
llvm::OffloadEntriesInfoManager::OffloadEntryInfoDeviceGlobalVar::getLinkage
GlobalValue::LinkageTypes getLinkage() const
Definition: OMPIRBuilder.h:2098
llvm::omp::IdentFlag
IdentFlag
IDs for all omp runtime library ident_t flag encodings (see their defintion in openmp/runtime/src/kmp...
Definition: OMPConstants.h:66
llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryDtor
@ OMPTargetRegionEntryDtor
Mark the entry as a global destructor.
Definition: OMPIRBuilder.h:2010
llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion::getID
Constant * getID() const
Definition: OMPIRBuilder.h:2029
llvm::OpenMPIRBuilder::OpenMPIRBuilder
OpenMPIRBuilder(Module &M)
Create a new OpenMPIRBuilder operating on the given module M.
Definition: OMPIRBuilder.h:170
llvm::OpenMPIRBuilder::TargetDataRTArgs::MapTypesArrayEnd
Value * MapTypesArrayEnd
The array of map types passed to the runtime library for the end of the region, or nullptr if there a...
Definition: OMPIRBuilder.h:1148
llvm::OpenMPIRBuilder::unrollLoopFull
void unrollLoopFull(DebugLoc DL, CanonicalLoopInfo *Loop)
Fully unroll a loop.
Definition: OMPIRBuilder.cpp:2980
llvm::OpenMPIRBuilder::emitTaskwaitImpl
void emitTaskwaitImpl(const LocationDescription &Loc)
Generate a taskwait runtime call.
Definition: OMPIRBuilder.cpp:1245
llvm::AddressSpace
AddressSpace
Definition: NVPTXBaseInfo.h:21
llvm::OpenMPIRBuilder::createOMPAlloc
CallInst * createOMPAlloc(const LocationDescription &Loc, Value *Size, Value *Allocator, std::string Name="")
Create a runtime call for kmpc_Alloc.
Definition: OMPIRBuilder.cpp:3751
llvm::OpenMPIRBuilder::addAttributes
void addAttributes(omp::RuntimeFunction FnID, Function &Fn)
Add attributes known for FnID to Fn.
Definition: OMPIRBuilder.cpp:331
llvm::OpenMPIRBuilder::loadOffloadInfoMetadata
void loadOffloadInfoMetadata(Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager)
Loads all the offload entries information from the host IR metadata.
Definition: OMPIRBuilder.cpp:4978
llvm::OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo
@ OMPTargetGlobalVarEntryTo
Mark the entry as a to declare target.
Definition: OMPIRBuilder.h:2070
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::StringMap< bool >
llvm::OpenMPIRBuilder::TargetDataInfo::separateBeginEndCalls
bool separateBeginEndCalls()
Definition: OMPIRBuilder.h:1191
llvm::OpenMPIRBuilder::OutlineInfo::EntryBB
BasicBlock * EntryBB
Definition: OMPIRBuilder.h:1069
llvm::OffloadEntriesInfoManager::OffloadEntryInfoDeviceGlobalVar::OffloadEntryInfoDeviceGlobalVar
OffloadEntryInfoDeviceGlobalVar()
Definition: OMPIRBuilder.h:2082
llvm::OpenMPIRBuilder::Builder
IRBuilder Builder
The LLVM-IR Builder used to create IR.
Definition: OMPIRBuilder.h:1056
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion::OffloadEntryInfoTargetRegion
OffloadEntryInfoTargetRegion(unsigned Order, Constant *Addr, Constant *ID, OMPTargetRegionEntryKind Flags)
Definition: OMPIRBuilder.h:2021
llvm::omp::RuntimeFunction
RuntimeFunction
IDs for all omp runtime library (RTL) functions.
Definition: OMPConstants.h:46
llvm::AtomicOrdering
AtomicOrdering
Atomic ordering for LLVM's memory model.
Definition: AtomicOrdering.h:56
llvm::OpenMPIRBuilder::createTaskyield
void createTaskyield(const LocationDescription &Loc)
Generator for '#omp taskyield'.
Definition: OMPIRBuilder.cpp:1276
llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion
Target region entries info.
Definition: OMPIRBuilder.h:2014
llvm::OpenMPIRBuilder::EmitMetadataErrorKind
EmitMetadataErrorKind
The kind of errors that can occur when emitting the offload entries and metadata.
Definition: OMPIRBuilder.h:1211
llvm::OpenMPIRBuilder::createOffloadMaptypes
GlobalVariable * createOffloadMaptypes(SmallVectorImpl< uint64_t > &Mappings, std::string VarName)
Create the global variable holding the offload mappings information.
Definition: OMPIRBuilder.cpp:4089
llvm::OpenMPIRBuilder::AtomicOpValue::IsVolatile
bool IsVolatile
Definition: OMPIRBuilder.h:1719
llvm::OpenMPIRBuilder::createSections
InsertPointTy createSections(const LocationDescription &Loc, InsertPointTy AllocaIP, ArrayRef< StorableBodyGenCallbackTy > SectionCBs, PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB, bool IsCancellable, bool IsNowait)
Generator for '#omp sections'.
Definition: OMPIRBuilder.cpp:1579
llvm::OpenMPIRBuilder::MapperAllocas::ArgsBase
AllocaInst * ArgsBase
Definition: OMPIRBuilder.h:1108
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::OpenMPIRBuilder::createOMPInteropDestroy
CallInst * createOMPInteropDestroy(const LocationDescription &Loc, Value *InteropVar, Value *Device, Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause)
Create a runtime call for __tgt_interop_destroy.
Definition: OMPIRBuilder.cpp:3812
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::OpenMPIRBuilder::registerTargetRegionFunction
Constant * registerTargetRegionFunction(OffloadEntriesInfoManager &InfoManager, TargetRegionEntryInfo &EntryInfo, Function *OutlinedFunction, StringRef EntryFnName, StringRef EntryFnIDName, int32_t NumTeams, int32_t NumThreads)
Registers the given function and sets up the attribtues of the function Returns the FunctionID.
Definition: OMPIRBuilder.cpp:4027
llvm::OpenMPIRBuilder::ReductionInfo::PrivateVariable
Value * PrivateVariable
Thread-private partial reduction variable.
Definition: OMPIRBuilder.h:829
llvm::OpenMPIRBuilder::createOrderedThreadsSimd
InsertPointTy createOrderedThreadsSimd(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, bool IsThreads)
Generator for '#omp ordered [threads | simd]'.
Definition: OMPIRBuilder.cpp:3559
llvm::OpenMPIRBuilder::OutlineInfo::getFunction
Function * getFunction() const
Return the function that contains the region to be outlined.
Definition: OMPIRBuilder.h:1078
uint64_t
llvm::OffloadEntriesInfoManager::OffloadEntryInfoDeviceGlobalVar::setVarSize
void setVarSize(int64_t Size)
Definition: OMPIRBuilder.h:2097
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::OffloadEntriesInfoManager::OffloadTargetRegionEntryInfoActTy
function_ref< void(const TargetRegionEntryInfo &EntryInfo, const OffloadEntryInfoTargetRegion &)> OffloadTargetRegionEntryInfoActTy
brief Applies action Action on all registered entries.
Definition: OMPIRBuilder.h:2059
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::OffloadingEntryInfoDeviceGlobalVar
@ OffloadingEntryInfoDeviceGlobalVar
Entry is a declare target variable.
Definition: OMPIRBuilder.h:1953
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const IRBuilderBase &IRB)
Definition: OMPIRBuilder.h:306
llvm::WeakTrackingVH::pointsToAliveValue
bool pointsToAliveValue() const
Definition: ValueHandle.h:224
llvm::OpenMPIRBuilder::isLastFinalizationInfoCancellable
bool isLastFinalizationInfoCancellable(omp::Directive DK)
Return true if the last entry in the finalization stack is of kind DK and cancellable.
Definition: OMPIRBuilder.h:1028
llvm::OpenMPIRBuilderConfig::IsEmbedded
std::optional< bool > IsEmbedded
Flag for specifying if the compilation is done for embedded device code or host code.
Definition: OMPIRBuilder.h:86
llvm::DenseMap
Definition: DenseMap.h:714
llvm::OpenMPIRBuilder::FinalizationInfo::DK
omp::Directive DK
The directive kind of the innermost directive that has an associated region which might require final...
Definition: OMPIRBuilder.h:218
llvm::OpenMPIRBuilder::emitCancelationCheckImpl
void emitCancelationCheckImpl(Value *CancelFlag, omp::Directive CanceledDirective, FinalizeCallbackTy ExitCB={})
Generate control flow and cleanup for cancellation.
Definition: OMPIRBuilder.cpp:842
llvm::OpenMPIRBuilder::createCanonicalLoop
CanonicalLoopInfo * createCanonicalLoop(const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB, Value *TripCount, const Twine &Name="loop")
Generator for the control flow structure of an OpenMP canonical loop.
Definition: OMPIRBuilder.cpp:2000
llvm::OpenMPIRBuilderConfig::OpenMPIRBuilderConfig
OpenMPIRBuilderConfig(bool IsEmbedded, bool IsTargetCodegen, bool HasRequiresUnifiedSharedMemory, bool OpenMPOffloadMandatory)
Definition: OMPIRBuilder.h:105
llvm::OpenMPIRBuilder::setConfig
void setConfig(OpenMPIRBuilderConfig C)
Definition: OMPIRBuilder.h:178
llvm::OpenMPIRBuilder::getOrCreateIdent
Constant * getOrCreateIdent(Constant *SrcLocStr, uint32_t SrcLocStrSize, omp::IdentFlag Flags=omp::IdentFlag(0), unsigned Reserve2Flags=0)
Return an ident_t* encoding the source location SrcLocStr and Flags.
Definition: OMPIRBuilder.cpp:554
llvm::OpenMPIRBuilder::createParallel
IRBuilder ::InsertPoint createParallel(const LocationDescription &Loc, InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB, Value *IfCondition, Value *NumThreads, omp::ProcBindKind ProcBind, bool IsCancellable)
Generator for '#omp parallel'.
Definition: OMPIRBuilder.cpp:881
llvm::OpenMPIRBuilder::OutlineInfo::OuterAllocaBB
BasicBlock * OuterAllocaBB
Definition: OMPIRBuilder.h:1069
llvm::OpenMPIRBuilder::TargetDataRTArgs::PointersArray
Value * PointersArray
The array of section pointers passed to the runtime library.
Definition: OMPIRBuilder.h:1138
llvm::OpenMPIRBuilder::createTaskgroup
InsertPointTy createTaskgroup(const LocationDescription &Loc, InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB)
Generator for the taskgroup construct.
Definition: OMPIRBuilder.cpp:1551
llvm::OpenMPIRBuilder::finalize
void finalize(Function *Fn=nullptr)
Finalize the underlying module, e.g., by outlining regions.
Definition: OMPIRBuilder.cpp:450
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::isValid
bool isValid() const
Definition: OMPIRBuilder.h:1967
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion::setID
void setID(Constant *V)
Definition: OMPIRBuilder.h:2030
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::getKind
OffloadingEntryInfoKinds getKind() const
Definition: OMPIRBuilder.h:1969
llvm::OpenMPIRBuilder::ReductionGenTy
function_ref< InsertPointTy(InsertPointTy, Value *, Value *, Value *&)> ReductionGenTy
Functions used to generate reductions.
Definition: OMPIRBuilder.h:801
llvm::OpenMPIRBuilderConfig::OpenMPIRBuilderConfig
OpenMPIRBuilderConfig()
Definition: OMPIRBuilder.h:104
llvm::OpenMPIRBuilder::TargetDataRTArgs::TargetDataRTArgs
TargetDataRTArgs()
Definition: OMPIRBuilder.h:1134
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::OpenMPIRBuilder::LocationDescription::DL
DebugLoc DL
Definition: OMPIRBuilder.h:312
llvm::OpenMPIRBuilder::emitTargetKernel
InsertPointTy emitTargetKernel(const LocationDescription &Loc, Value *&Return, Value *Ident, Value *DeviceID, Value *NumTeams, Value *NumThreads, Value *HostPtr, ArrayRef< Value * > KernelArgs)
Generate a target region entry call.
Definition: OMPIRBuilder.cpp:815
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::OpenMPIRBuilder::TargetDataInfo::TargetDataInfo
TargetDataInfo(bool RequiresDevicePointerInfo, bool SeparateBeginEndCalls)
Definition: OMPIRBuilder.h:1174
llvm::OpenMPIRBuilder::unrollLoopHeuristic
void unrollLoopHeuristic(DebugLoc DL, CanonicalLoopInfo *Loop)
Fully or partially unroll a loop.
Definition: OMPIRBuilder.cpp:2987
llvm::OpenMPIRBuilder::getOrCreateRuntimeFunctionPtr
Function * getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID)
Definition: OMPIRBuilder.cpp:441
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::OffloadEntryInfo
OffloadEntryInfo(OffloadingEntryInfoKinds Kind)
Definition: OMPIRBuilder.h:1960
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::OpenMPIRBuilder::createMaster
InsertPointTy createMaster(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB)
Generator for '#omp master'.
Definition: OMPIRBuilder.cpp:1884
llvm::OffloadEntriesInfoManager::OffloadDeviceGlobalVarEntryInfoActTy
function_ref< void(StringRef, const OffloadEntryInfoDeviceGlobalVar &)> OffloadDeviceGlobalVarEntryInfoActTy
Applies action Action on all registered entries.
Definition: OMPIRBuilder.h:2122
llvm::OpenMPIRBuilder::createFlush
void createFlush(const LocationDescription &Loc)
Generator for '#omp flush'.
Definition: OMPIRBuilder.cpp:1239
llvm::OpenMPIRBuilder::createPlatformSpecificName
std::string createPlatformSpecificName(ArrayRef< StringRef > Parts) const
Get the create a name using the platform specific separators.
Definition: OMPIRBuilder.cpp:4055
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::OpenMPIRBuilder::OutlineInfo
Helper that contains information about regions we need to outline during finalization.
Definition: OMPIRBuilder.h:1066
llvm::CanonicalLoopInfo
Class to represented the control flow structure of an OpenMP canonical loop.
Definition: OMPIRBuilder.h:2253
llvm::OpenMPIRBuilder::createGlobalFlag
GlobalValue * createGlobalFlag(unsigned Value, StringRef Name)
Create a hidden global flag Name in the module with initial value Value.
Definition: OMPIRBuilder.cpp:543
llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryTargetRegion
@ OMPTargetRegionEntryTargetRegion
Mark the entry as target region.
Definition: OMPIRBuilder.h:2006
llvm::OpenMPIRBuilder::TargetDataRTArgs::MapTypesArray
Value * MapTypesArray
The array of map types passed to the runtime library for the beginning of the region or for the entir...
Definition: OMPIRBuilder.h:1144
llvm::OpenMPIRBuilderConfig::Separator
std::optional< StringRef > Separator
Separator used between all of the rest consecutive parts of s name.
Definition: OMPIRBuilder.h:102
llvm::OpenMPIRBuilder::createOMPInteropInit
CallInst * createOMPInteropInit(const LocationDescription &Loc, Value *InteropVar, omp::OMPInteropType InteropType, Value *Device, Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause)
Create a runtime call for __tgt_interop_init.
Definition: OMPIRBuilder.cpp:3783
llvm::omp::OMPAtomicCompareOp
OMPAtomicCompareOp
Atomic compare operations. Currently OpenMP only supports ==, >, and <.
Definition: OMPConstants.h:256
llvm::OffloadEntriesInfoManager::OffloadEntryInfo
Base class of the entries info.
Definition: OMPIRBuilder.h:1946
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:33
llvm::OpenMPIRBuilder::TargetDataRTArgs::SizesArray
Value * SizesArray
The array of sizes passed to the runtime library.
Definition: OMPIRBuilder.h:1140
llvm::OpenMPIRBuilderConfig::separator
StringRef separator() const
Definition: OMPIRBuilder.h:146
Cond
SmallVector< MachineOperand, 4 > Cond
Definition: BasicBlockSections.cpp:137
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind
OMPTargetGlobalVarEntryKind
Kind of the global variable entry..
Definition: OMPIRBuilder.h:2068
llvm::OpenMPIRBuilder::DependData::DepKind
omp::RTLDependenceKindTy DepKind
Definition: OMPIRBuilder.h:759
llvm::TargetRegionEntryInfo::ParentName
std::string ParentName
Definition: OMPIRBuilder.h:1911
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::OpenMPIRBuilder::createOffloadMapnames
GlobalVariable * createOffloadMapnames(SmallVectorImpl< llvm::Constant * > &Names, std::string VarName)
Create the global variable holding the offload names information.
Definition: OMPIRBuilder.cpp:4732
uint32_t
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::~OffloadEntryInfo
~OffloadEntryInfo()=default
llvm::OpenMPIRBuilderConfig::FirstSeparator
std::optional< StringRef > FirstSeparator
First separator used between the initial two parts of a name.
Definition: OMPIRBuilder.h:100
llvm::OpenMPIRBuilder::DependData::DepVal
Value * DepVal
Definition: OMPIRBuilder.h:761
llvm::IRBuilderBase
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:94
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::splitBB
BasicBlock * splitBB(IRBuilderBase::InsertPoint IP, bool CreateBranch, llvm::Twine Name={})
Split a BasicBlock at an InsertPoint, even if the block is degenerate (missing the terminator).
Definition: OMPIRBuilder.cpp:286
llvm::OpenMPIRBuilder::MapperAllocas::ArgSizes
AllocaInst * ArgSizes
Definition: OMPIRBuilder.h:1110
llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCB
PostOutlineCBTy PostOutlineCB
Definition: OMPIRBuilder.h:1068
llvm::OpenMPIRBuilder::unrollLoopPartial
void unrollLoopPartial(DebugLoc DL, CanonicalLoopInfo *Loop, int32_t Factor, CanonicalLoopInfo **UnrolledCLI)
Partially unroll a loop.
Definition: OMPIRBuilder.cpp:3346
llvm::ValueMap< const Value *, WeakTrackingVH >
llvm::OpenMPIRBuilder::addOutlineInfo
void addOutlineInfo(OutlineInfo &&OI)
Add a new region that will be outlined later.
Definition: OMPIRBuilder.h:1089
llvm::OpenMPIRBuilder::createMasked
InsertPointTy createMasked(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, Value *Filter)
Generator for '#omp masked'.
Definition: OMPIRBuilder.cpp:1909
llvm::OpenMPIRBuilder::updateToLocation
bool updateToLocation(const LocationDescription &Loc)
Update the internal location to Loc.
Definition: OMPIRBuilder.h:915
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::classof
static bool classof(const OffloadEntryInfo *Info)
Definition: OMPIRBuilder.h:1977
llvm::OpenMPIRBuilder::FinalizationStack
SmallVector< FinalizationInfo, 8 > FinalizationStack
The finalization stack made up of finalize callbacks currently in-flight, wrapped into FinalizationIn...
Definition: OMPIRBuilder.h:1024
llvm::TargetRegionEntryInfo::TargetRegionEntryInfo
TargetRegionEntryInfo()
Definition: OMPIRBuilder.h:1917
llvm::CanonicalLoopInfo::getExit
BasicBlock * getExit() const
Reaching the exit indicates no more iterations are being executed.
Definition: OMPIRBuilder.h:2336
llvm::OpenMPIRBuilder::LoopInfos
std::forward_list< CanonicalLoopInfo > LoopInfos
Collection of owned canonical loop objects that eventually need to be free'd.
Definition: OMPIRBuilder.h:1086
llvm::OpenMPIRBuilder::createTaskwait
void createTaskwait(const LocationDescription &Loc)
Generator for '#omp taskwait'.
Definition: OMPIRBuilder.cpp:1258
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::OpenMPIRBuilder::ReductionInfo::ReductionGen
ReductionGenTy ReductionGen
Callback for generating the reduction body.
Definition: OMPIRBuilder.h:834
llvm::OpenMPIRBuilder::AtomicOpValue::ElemTy
Type * ElemTy
Definition: OMPIRBuilder.h:1717
llvm::OpenMPIRBuilder::TargetDataInfo
Struct that keeps the information that should be kept throughout a 'target data' region.
Definition: OMPIRBuilder.h:1158
llvm::TargetRegionEntryInfo::FileID
unsigned FileID
Definition: OMPIRBuilder.h:1913
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:354
llvm::OpenMPIRBuilder::ReductionInfo::ElementType
Type * ElementType
Reduction element type, must match pointee type of variable.
Definition: OMPIRBuilder.h:823
llvm::OpenMPIRBuilder::createAtomicWrite
InsertPointTy createAtomicWrite(const LocationDescription &Loc, AtomicOpValue &X, Value *Expr, AtomicOrdering AO)
Emit atomic write for : X = Expr — Only Scalar data types.
Definition: OMPIRBuilder.cpp:4308
llvm::OffloadEntriesInfoManager::actOnDeviceGlobalVarEntriesInfo
void actOnDeviceGlobalVarEntriesInfo(const OffloadDeviceGlobalVarEntryInfoActTy &Action)
Definition: OMPIRBuilder.cpp:5151
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::setFlags
void setFlags(uint32_t NewFlags)
Definition: OMPIRBuilder.h:1971
llvm::OpenMPIRBuilderConfig::setSeparator
void setSeparator(StringRef S)
Definition: OMPIRBuilder.h:160
llvm::SectionName
Definition: DWARFSection.h:21
llvm::OpenMPIRBuilder::createAtomicCapture
InsertPointTy createAtomicCapture(const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &X, AtomicOpValue &V, Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp, bool UpdateExpr, bool IsPostfixUpdate, bool IsXBinopExpr)
Emit atomic update for constructs: — Only Scalar data types V = X; X = X BinOp Expr ,...
Definition: OMPIRBuilder.cpp:4515
llvm::OpenMPIRBuilder::emitTargetRegionFunction
void emitTargetRegionFunction(OffloadEntriesInfoManager &InfoManager, TargetRegionEntryInfo &EntryInfo, FunctionGenCallback &GenerateFunctionCallback, int32_t NumTeams, int32_t NumThreads, bool IsOffloadEntry, Function *&OutlinedFn, Constant *&OutlinedFnID)
Create a unique name for the entry function using the source location information of the current targ...
Definition: OMPIRBuilder.cpp:3998
llvm::CanonicalLoopInfo::invalidate
void invalidate()
Invalidate this loop.
Definition: OMPIRBuilder.cpp:5316
llvm::OffloadEntriesInfoManager::actOnTargetRegionEntriesInfo
void actOnTargetRegionEntriesInfo(const OffloadTargetRegionEntryInfoActTy &Action)
Definition: OMPIRBuilder.cpp:5102
llvm::OpenMPIRBuilder::InternalVars
StringMap< Constant *, BumpPtrAllocator > InternalVars
An ordered map of auto-generated variables to their unique names.
Definition: OMPIRBuilder.h:1096
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::setAddress
void setAddress(Constant *V)
Definition: OMPIRBuilder.h:1973
llvm::OpenMPIRBuilderConfig::IsTargetCodegen
std::optional< bool > IsTargetCodegen
Flag for specifying if the compilation is done for an offloading target, like GPU.
Definition: OMPIRBuilder.h:90
llvm::OpenMPIRBuilder::createCancel
InsertPointTy createCancel(const LocationDescription &Loc, Value *IfCondition, omp::Directive CanceledDirective)
Generator for '#omp cancel'.
Definition: OMPIRBuilder.cpp:726
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::OpenMPIRBuilderConfig::setHasRequiresUnifiedSharedMemory
void setHasRequiresUnifiedSharedMemory(bool Value)
Definition: OMPIRBuilder.h:156
llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCBTy
std::function< void(Function &)> PostOutlineCBTy
Definition: OMPIRBuilder.h:1067
llvm::OffloadEntriesInfoManager::registerTargetRegionEntryInfo
void registerTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo, Constant *Addr, Constant *ID, OMPTargetRegionEntryKind Flags)
Register target region entry.
Definition: OMPIRBuilder.cpp:5054
llvm::CanonicalLoopInfo::getHeader
BasicBlock * getHeader() const
The header is the entry for each iteration.
Definition: OMPIRBuilder.h:2307
llvm::StringMap::count
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition: StringMap.h:245
llvm::OpenMPIRBuilder::applyWorkshareLoop
InsertPointTy applyWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, bool NeedsBarrier, llvm::omp::ScheduleKind SchedKind=llvm::omp::OMP_SCHEDULE_Default, Value *ChunkSize=nullptr, bool HasSimdModifier=false, bool HasMonotonicModifier=false, bool HasNonmonotonicModifier=false, bool HasOrderedClause=false)
Modifies the canonical loop to be a workshare loop.
Definition: OMPIRBuilder.cpp:2347
OMPConstants.h
llvm::OpenMPIRBuilder::ReductionInfo
Information about an OpenMP reduction.
Definition: OMPIRBuilder.h:811
llvm::IRBuilderBase::saveIP
InsertPoint saveIP() const
Returns the current insert point.
Definition: IRBuilder.h:263
llvm::OpenMPIRBuilder::initialize
void initialize()
Initialize the internal state, this will put structures types and potentially other helpers into the ...
Definition: OMPIRBuilder.cpp:448
llvm::OffloadEntriesInfoManager::OffloadEntryInfoDeviceGlobalVar::OffloadEntryInfoDeviceGlobalVar
OffloadEntryInfoDeviceGlobalVar(unsigned Order, Constant *Addr, int64_t VarSize, OMPTargetGlobalVarEntryKind Flags, GlobalValue::LinkageTypes Linkage)
Definition: OMPIRBuilder.h:2087
llvm::OpenMPIRBuilder::createTargetDeinit
void createTargetDeinit(const LocationDescription &Loc, bool IsSPMD)
Create a runtime call for kmpc_target_deinit.
Definition: OMPIRBuilder.cpp:3938
llvm::CanonicalLoopInfo::getLatch
BasicBlock * getLatch() const
Reaching the latch indicates the end of the loop body code.
Definition: OMPIRBuilder.h:2330
llvm::OffloadEntriesInfoManager::hasDeviceGlobalVarEntryInfo
bool hasDeviceGlobalVarEntryInfo(StringRef VarName) const
Checks if the variable with the given name has been registered already.
Definition: OMPIRBuilder.h:2117
llvm::TargetRegionEntryInfo
Data structure to contain the information needed to uniquely identify a target entry.
Definition: OMPIRBuilder.h:1910
llvm::OpenMPIRBuilder::BodyGenCallbackTy
function_ref< void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)> BodyGenCallbackTy
Callback type for body (=inner region) code generation.
Definition: OMPIRBuilder.h:261
llvm::OpenMPIRBuilderConfig::setIsEmbedded
void setIsEmbedded(bool Value)
Definition: OMPIRBuilder.h:154
llvm::OpenMPIRBuilder::FinalizationInfo
Definition: OMPIRBuilder.h:211
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:143
llvm::CanonicalLoopInfo::getIndVarType
Type * getIndVarType() const
Return the type of the induction variable (and the trip count).
Definition: OMPIRBuilder.h:2371
llvm::OpenMPIRBuilder::SrcLocStrMap
StringMap< Constant * > SrcLocStrMap
Map to remember source location strings.
Definition: OMPIRBuilder.h:1059
llvm::OpenMPIRBuilder::emitBarrierImpl
InsertPointTy emitBarrierImpl(const LocationDescription &Loc, omp::Directive DK, bool ForceSimpleCall, bool CheckCancelFlag)
Generate a barrier runtime call.
Definition: OMPIRBuilder.cpp:677
llvm::FunctionCallee
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:165
llvm::OpenMPIRBuilder::Config
OpenMPIRBuilderConfig Config
The OpenMPIRBuilder Configuration.
Definition: OMPIRBuilder.h:1050
llvm::OpenMPIRBuilder::FunctionGenCallback
std::function< Function *(StringRef FunctionName)> FunctionGenCallback
Functions used to generate a function with the given name.
Definition: OMPIRBuilder.h:1494
llvm::SmallVectorImpl< BasicBlock * >
llvm::CanonicalLoopInfo::getTripCount
Value * getTripCount() const
Returns the llvm::Value containing the number of loop iterations.
Definition: OMPIRBuilder.h:2354
llvm::SmallPtrSetImpl
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:344
llvm::OpenMPIRBuilder::emitFlush
void emitFlush(const LocationDescription &Loc)
Generate a flush runtime call.
Definition: OMPIRBuilder.cpp:1230
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1485
llvm::OpenMPIRBuilder::OutlineInfo::collectBlocks
void collectBlocks(SmallPtrSetImpl< BasicBlock * > &BlockSet, SmallVectorImpl< BasicBlock * > &BlockVector)
Collect all blocks in between EntryBB and ExitBB in both the given vector and set.
Definition: OMPIRBuilder.cpp:4766
llvm::OpenMPIRBuilder::MapperAllocas
Definition: OMPIRBuilder.h:1107
llvm::OpenMPIRBuilder::ReductionInfo::ReductionInfo
ReductionInfo(Type *ElementType, Value *Variable, Value *PrivateVariable, ReductionGenTy ReductionGen, AtomicReductionGenTy AtomicReductionGen)
Definition: OMPIRBuilder.h:812
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:58
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::OffloadEntriesInfoManager::OffloadEntryInfo::OffloadEntryInfo
OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order, uint32_t Flags)
Definition: OMPIRBuilder.h:1961
llvm::OpenMPIRBuilder::TargetDataInfo::HasMapper
bool HasMapper
Indicate whether any user-defined mapper exists.
Definition: OMPIRBuilder.h:1169
llvm::OpenMPIRBuilder::createCopyinClauseBlocks
InsertPointTy createCopyinClauseBlocks(InsertPointTy IP, Value *MasterAddr, Value *PrivateAddr, llvm::IntegerType *IntPtrTy, bool BranchtoEnd=true)
Generate conditional branch and relevant BasicBlocks through which private threads copy the 'copyin' ...
Definition: OMPIRBuilder.cpp:3701
llvm::OpenMPIRBuilder::createCopyPrivate
InsertPointTy createCopyPrivate(const LocationDescription &Loc, llvm::Value *BufSize, llvm::Value *CpyBuf, llvm::Value *CpyFn, llvm::Value *DidIt)
Generator for __kmpc_copyprivate.
Definition: OMPIRBuilder.cpp:3415
llvm::omp::OMPScheduleType
OMPScheduleType
Definition: OMPConstants.h:77
llvm::OpenMPIRBuilder::getOrCreateRuntimeFunction
FunctionCallee getOrCreateRuntimeFunction(Module &M, omp::RuntimeFunction FnID)
Return the function declaration for the runtime function with FnID.
Definition: OMPIRBuilder.cpp:383
llvm::omp::RTLDependenceKindTy
RTLDependenceKindTy
Dependence kind for RTL.
Definition: OMPConstants.h:262
llvm::OpenMPIRBuilder::ReductionInfo::AtomicReductionGen
AtomicReductionGenTy AtomicReductionGen
Callback for generating the atomic reduction body, may be null.
Definition: OMPIRBuilder.h:840
llvm::CanonicalLoopInfo::getBody
BasicBlock * getBody() const
The body block is the single entry for a loop iteration and not controlled by CanonicalLoopInfo.
Definition: OMPIRBuilder.h:2322
llvm::OpenMPIRBuilderConfig::setFirstSeparator
void setFirstSeparator(StringRef FS)
Definition: OMPIRBuilder.h:159
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::OpenMPIRBuilder::EMIT_MD_DECLARE_TARGET_ERROR
@ EMIT_MD_DECLARE_TARGET_ERROR
Definition: OMPIRBuilder.h:1213
llvm::OpenMPIRBuilder::TargetDataInfo::requiresDevicePointerInfo
bool requiresDevicePointerInfo()
Definition: OMPIRBuilder.h:1190
llvm::TargetRegionEntryInfo::Line
unsigned Line
Definition: OMPIRBuilder.h:1914
llvm::OffloadEntriesInfoManager::initializeDeviceGlobalVarEntryInfo
void initializeDeviceGlobalVarEntryInfo(StringRef Name, OMPTargetGlobalVarEntryKind Flags, unsigned Order)
Initialize device global variable entry.
Definition: OMPIRBuilder.cpp:5110
llvm::OpenMPIRBuilder::createOffloadEntry
void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t Size, int32_t Flags, GlobalValue::LinkageTypes)
Creates offloading entry for the provided entry ID ID, address Addr, size Size, and flags Flags.
Definition: OMPIRBuilder.cpp:4783
llvm::OpenMPIRBuilder::LocationDescription::IP
InsertPointTy IP
Definition: OMPIRBuilder.h:311