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