LLVM  14.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 
18 #include "llvm/IR/DebugLoc.h"
19 #include "llvm/IR/IRBuilder.h"
20 #include "llvm/Support/Allocator.h"
21 #include <forward_list>
22 
23 namespace llvm {
24 class CanonicalLoopInfo;
25 
26 /// An interface to create LLVM-IR for OpenMP directives.
27 ///
28 /// Each OpenMP directive has a corresponding public generator method.
30 public:
31  /// Create a new OpenMPIRBuilder operating on the given module \p M. This will
32  /// not have an effect on \p M (see initialize).
33  OpenMPIRBuilder(Module &M) : M(M), Builder(M.getContext()) {}
35 
36  /// Initialize the internal state, this will put structures types and
37  /// potentially other helpers into the underlying module. Must be called
38  /// before any other method and only once!
39  void initialize();
40 
41  /// Finalize the underlying module, e.g., by outlining regions.
42  /// \param Fn The function to be finalized. If not used,
43  /// all functions are finalized.
44  /// \param AllowExtractorSinking Flag to include sinking instructions,
45  /// emitted by CodeExtractor, in the
46  /// outlined region. Default is false.
47  void finalize(Function *Fn = nullptr, bool AllowExtractorSinking = false);
48 
49  /// Add attributes known for \p FnID to \p Fn.
51 
52  /// Type used throughout for insertion points.
54 
55  /// Callback type for variable finalization (think destructors).
56  ///
57  /// \param CodeGenIP is the insertion point at which the finalization code
58  /// should be placed.
59  ///
60  /// A finalize callback knows about all objects that need finalization, e.g.
61  /// destruction, when the scope of the currently generated construct is left
62  /// at the time, and location, the callback is invoked.
64 
66  /// The finalization callback provided by the last in-flight invocation of
67  /// createXXXX for the directive of kind DK.
69 
70  /// The directive kind of the innermost directive that has an associated
71  /// region which might require finalization when it is left.
72  omp::Directive DK;
73 
74  /// Flag to indicate if the directive is cancellable.
76  };
77 
78  /// Push a finalization callback on the finalization stack.
79  ///
80  /// NOTE: Temporary solution until Clang CG is gone.
82  FinalizationStack.push_back(FI);
83  }
84 
85  /// Pop the last finalization callback from the finalization stack.
86  ///
87  /// NOTE: Temporary solution until Clang CG is gone.
88  void popFinalizationCB() { FinalizationStack.pop_back(); }
89 
90  /// Callback type for body (=inner region) code generation
91  ///
92  /// The callback takes code locations as arguments, each describing a
93  /// location at which code might need to be generated or a location that is
94  /// the target of control transfer.
95  ///
96  /// \param AllocaIP is the insertion point at which new alloca instructions
97  /// should be placed.
98  /// \param CodeGenIP is the insertion point at which the body code should be
99  /// placed.
100  /// \param ContinuationBB is the basic block target to leave the body.
101  ///
102  /// Note that all blocks pointed to by the arguments have terminators.
103  using BodyGenCallbackTy =
104  function_ref<void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
105  BasicBlock &ContinuationBB)>;
106 
107  // This is created primarily for sections construct as llvm::function_ref
108  // (BodyGenCallbackTy) is not storable (as described in the comments of
109  // function_ref class - function_ref contains non-ownable reference
110  // to the callable.
112  std::function<void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
113  BasicBlock &ContinuationBB)>;
114 
115  /// Callback type for loop body code generation.
116  ///
117  /// \param CodeGenIP is the insertion point where the loop's body code must be
118  /// placed. This will be a dedicated BasicBlock with a
119  /// conditional branch from the loop condition check and
120  /// terminated with an unconditional branch to the loop
121  /// latch.
122  /// \param IndVar is the induction variable usable at the insertion point.
123  using LoopBodyGenCallbackTy =
124  function_ref<void(InsertPointTy CodeGenIP, Value *IndVar)>;
125 
126  /// Callback type for variable privatization (think copy & default
127  /// constructor).
128  ///
129  /// \param AllocaIP is the insertion point at which new alloca instructions
130  /// should be placed.
131  /// \param CodeGenIP is the insertion point at which the privatization code
132  /// should be placed.
133  /// \param Original The value being copied/created, should not be used in the
134  /// generated IR.
135  /// \param Inner The equivalent of \p Original that should be used in the
136  /// generated IR; this is equal to \p Original if the value is
137  /// a pointer and can thus be passed directly, otherwise it is
138  /// an equivalent but different value.
139  /// \param ReplVal The replacement value, thus a copy or new created version
140  /// of \p Inner.
141  ///
142  /// \returns The new insertion point where code generation continues and
143  /// \p ReplVal the replacement value.
145  InsertPointTy AllocaIP, InsertPointTy CodeGenIP, Value &Original,
146  Value &Inner, Value *&ReplVal)>;
147 
148  /// Description of a LLVM-IR insertion point (IP) and a debug/source location
149  /// (filename, line, column, ...).
151  template <typename T, typename U>
153  : IP(IRB.saveIP()), DL(IRB.getCurrentDebugLocation()) {}
156  : IP(IP), DL(DL) {}
159  };
160 
161  /// Emitter methods for OpenMP directives.
162  ///
163  ///{
164 
165  /// Generator for '#omp barrier'
166  ///
167  /// \param Loc The location where the barrier directive was encountered.
168  /// \param DK The kind of directive that caused the barrier.
169  /// \param ForceSimpleCall Flag to force a simple (=non-cancellation) barrier.
170  /// \param CheckCancelFlag Flag to indicate a cancel barrier return value
171  /// should be checked and acted upon.
172  ///
173  /// \returns The insertion point after the barrier.
174  InsertPointTy createBarrier(const LocationDescription &Loc, omp::Directive DK,
175  bool ForceSimpleCall = false,
176  bool CheckCancelFlag = true);
177 
178  /// Generator for '#omp cancel'
179  ///
180  /// \param Loc The location where the directive was encountered.
181  /// \param IfCondition The evaluated 'if' clause expression, if any.
182  /// \param CanceledDirective The kind of directive that is cancled.
183  ///
184  /// \returns The insertion point after the barrier.
185  InsertPointTy createCancel(const LocationDescription &Loc, Value *IfCondition,
186  omp::Directive CanceledDirective);
187 
188  /// Generator for '#omp parallel'
189  ///
190  /// \param Loc The insert and source location description.
191  /// \param AllocaIP The insertion points to be used for alloca instructions.
192  /// \param BodyGenCB Callback that will generate the region code.
193  /// \param PrivCB Callback to copy a given variable (think copy constructor).
194  /// \param FiniCB Callback to finalize variable copies.
195  /// \param IfCondition The evaluated 'if' clause expression, if any.
196  /// \param NumThreads The evaluated 'num_threads' clause expression, if any.
197  /// \param ProcBind The value of the 'proc_bind' clause (see ProcBindKind).
198  /// \param IsCancellable Flag to indicate a cancellable parallel region.
199  ///
200  /// \returns The insertion position *after* the parallel.
202  createParallel(const LocationDescription &Loc, InsertPointTy AllocaIP,
203  BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
204  FinalizeCallbackTy FiniCB, Value *IfCondition,
205  Value *NumThreads, omp::ProcBindKind ProcBind,
206  bool IsCancellable);
207 
208  /// Generator for the control flow structure of an OpenMP canonical loop.
209  ///
210  /// This generator operates on the logical iteration space of the loop, i.e.
211  /// the caller only has to provide a loop trip count of the loop as defined by
212  /// base language semantics. The trip count is interpreted as an unsigned
213  /// integer. The induction variable passed to \p BodyGenCB will be of the same
214  /// type and run from 0 to \p TripCount - 1. It is up to the callback to
215  /// convert the logical iteration variable to the loop counter variable in the
216  /// loop body.
217  ///
218  /// \param Loc The insert and source location description. The insert
219  /// location can be between two instructions or the end of a
220  /// degenerate block (e.g. a BB under construction).
221  /// \param BodyGenCB Callback that will generate the loop body code.
222  /// \param TripCount Number of iterations the loop body is executed.
223  /// \param Name Base name used to derive BB and instruction names.
224  ///
225  /// \returns An object representing the created control flow structure which
226  /// can be used for loop-associated directives.
228  LoopBodyGenCallbackTy BodyGenCB,
229  Value *TripCount,
230  const Twine &Name = "loop");
231 
232  /// Generator for the control flow structure of an OpenMP canonical loop.
233  ///
234  /// Instead of a logical iteration space, this allows specifying user-defined
235  /// loop counter values using increment, upper- and lower bounds. To
236  /// disambiguate the terminology when counting downwards, instead of lower
237  /// bounds we use \p Start for the loop counter value in the first body
238  /// iteration.
239  ///
240  /// Consider the following limitations:
241  ///
242  /// * A loop counter space over all integer values of its bit-width cannot be
243  /// represented. E.g using uint8_t, its loop trip count of 256 cannot be
244  /// stored into an 8 bit integer):
245  ///
246  /// DO I = 0, 255, 1
247  ///
248  /// * Unsigned wrapping is only supported when wrapping only "once"; E.g.
249  /// effectively counting downwards:
250  ///
251  /// for (uint8_t i = 100u; i > 0; i += 127u)
252  ///
253  ///
254  /// TODO: May need to add additional parameters to represent:
255  ///
256  /// * Allow representing downcounting with unsigned integers.
257  ///
258  /// * Sign of the step and the comparison operator might disagree:
259  ///
260  /// for (int i = 0; i < 42; --i)
261  ///
262  //
263  /// \param Loc The insert and source location description.
264  /// \param BodyGenCB Callback that will generate the loop body code.
265  /// \param Start Value of the loop counter for the first iterations.
266  /// \param Stop Loop counter values past this will stop the the
267  /// iterations.
268  /// \param Step Loop counter increment after each iteration; negative
269  /// means counting down. \param IsSigned Whether Start, Stop
270  /// and Stop are signed integers.
271  /// \param InclusiveStop Whether \p Stop itself is a valid value for the loop
272  /// counter.
273  /// \param ComputeIP Insertion point for instructions computing the trip
274  /// count. Can be used to ensure the trip count is available
275  /// at the outermost loop of a loop nest. If not set,
276  /// defaults to the preheader of the generated loop.
277  /// \param Name Base name used to derive BB and instruction names.
278  ///
279  /// \returns An object representing the created control flow structure which
280  /// can be used for loop-associated directives.
282  LoopBodyGenCallbackTy BodyGenCB,
283  Value *Start, Value *Stop, Value *Step,
284  bool IsSigned, bool InclusiveStop,
285  InsertPointTy ComputeIP = {},
286  const Twine &Name = "loop");
287 
288  /// Collapse a loop nest into a single loop.
289  ///
290  /// Merges loops of a loop nest into a single CanonicalLoopNest representation
291  /// that has the same number of innermost loop iterations as the origin loop
292  /// nest. The induction variables of the input loops are derived from the
293  /// collapsed loop's induction variable. This is intended to be used to
294  /// implement OpenMP's collapse clause. Before applying a directive,
295  /// collapseLoops normalizes a loop nest to contain only a single loop and the
296  /// directive's implementation does not need to handle multiple loops itself.
297  /// This does not remove the need to handle all loop nest handling by
298  /// directives, such as the ordered(<n>) clause or the simd schedule-clause
299  /// modifier of the worksharing-loop directive.
300  ///
301  /// Example:
302  /// \code
303  /// for (int i = 0; i < 7; ++i) // Canonical loop "i"
304  /// for (int j = 0; j < 9; ++j) // Canonical loop "j"
305  /// body(i, j);
306  /// \endcode
307  ///
308  /// After collapsing with Loops={i,j}, the loop is changed to
309  /// \code
310  /// for (int ij = 0; ij < 63; ++ij) {
311  /// int i = ij / 9;
312  /// int j = ij % 9;
313  /// body(i, j);
314  /// }
315  /// \endcode
316  ///
317  /// In the current implementation, the following limitations apply:
318  ///
319  /// * All input loops have an induction variable of the same type.
320  ///
321  /// * The collapsed loop will have the same trip count integer type as the
322  /// input loops. Therefore it is possible that the collapsed loop cannot
323  /// represent all iterations of the input loops. For instance, assuming a
324  /// 32 bit integer type, and two input loops both iterating 2^16 times, the
325  /// theoretical trip count of the collapsed loop would be 2^32 iteration,
326  /// which cannot be represented in an 32-bit integer. Behavior is undefined
327  /// in this case.
328  ///
329  /// * The trip counts of every input loop must be available at \p ComputeIP.
330  /// Non-rectangular loops are not yet supported.
331  ///
332  /// * At each nest level, code between a surrounding loop and its nested loop
333  /// is hoisted into the loop body, and such code will be executed more
334  /// often than before collapsing (or not at all if any inner loop iteration
335  /// has a trip count of 0). This is permitted by the OpenMP specification.
336  ///
337  /// \param DL Debug location for instructions added for collapsing,
338  /// such as instructions to compute derive the input loop's
339  /// induction variables.
340  /// \param Loops Loops in the loop nest to collapse. Loops are specified
341  /// from outermost-to-innermost and every control flow of a
342  /// loop's body must pass through its directly nested loop.
343  /// \param ComputeIP Where additional instruction that compute the collapsed
344  /// trip count. If not set, defaults to before the generated
345  /// loop.
346  ///
347  /// \returns The CanonicalLoopInfo object representing the collapsed loop.
350  InsertPointTy ComputeIP);
351 
352  /// Modifies the canonical loop to be a statically-scheduled workshare loop.
353  ///
354  /// This takes a \p LoopInfo representing a canonical loop, such as the one
355  /// created by \p createCanonicalLoop and emits additional instructions to
356  /// turn it into a workshare loop. In particular, it calls to an OpenMP
357  /// runtime function in the preheader to obtain the loop bounds to be used in
358  /// the current thread, updates the relevant instructions in the canonical
359  /// loop and calls to an OpenMP runtime finalization function after the loop.
360  ///
361  /// \param Loc The source location description, the insertion location
362  /// is not used.
363  /// \param CLI A descriptor of the canonical loop to workshare.
364  /// \param AllocaIP An insertion point for Alloca instructions usable in the
365  /// preheader of the loop.
366  /// \param NeedsBarrier Indicates whether a barrier must be inserted after
367  /// the loop.
368  /// \param Chunk The size of loop chunk considered as a unit when
369  /// scheduling. If \p nullptr, defaults to 1.
370  ///
371  /// \returns Updated CanonicalLoopInfo.
372  CanonicalLoopInfo *createStaticWorkshareLoop(const LocationDescription &Loc,
373  CanonicalLoopInfo *CLI,
374  InsertPointTy AllocaIP,
375  bool NeedsBarrier,
376  Value *Chunk = nullptr);
377 
378  /// Modifies the canonical loop to be a dynamically-scheduled workshare loop.
379  ///
380  /// This takes a \p LoopInfo representing a canonical loop, such as the one
381  /// created by \p createCanonicalLoop and emits additional instructions to
382  /// turn it into a workshare loop. In particular, it calls to an OpenMP
383  /// runtime function in the preheader to obtain, and then in each iteration
384  /// to update the loop counter.
385  /// \param Loc The source location description, the insertion location
386  /// is not used.
387  /// \param CLI A descriptor of the canonical loop to workshare.
388  /// \param AllocaIP An insertion point for Alloca instructions usable in the
389  /// preheader of the loop.
390  /// \param SchedType Type of scheduling to be passed to the init function.
391  /// \param NeedsBarrier Indicates whether a barrier must be insterted after
392  /// the loop.
393  /// \param Chunk The size of loop chunk considered as a unit when
394  /// scheduling. If \p nullptr, defaults to 1.
395  ///
396  /// \returns Point where to insert code after the loop.
397  InsertPointTy createDynamicWorkshareLoop(const LocationDescription &Loc,
398  CanonicalLoopInfo *CLI,
399  InsertPointTy AllocaIP,
400  omp::OMPScheduleType SchedType,
401  bool NeedsBarrier,
402  Value *Chunk = nullptr);
403 
404  /// Modifies the canonical loop to be a workshare loop.
405  ///
406  /// This takes a \p LoopInfo representing a canonical loop, such as the one
407  /// created by \p createCanonicalLoop and emits additional instructions to
408  /// turn it into a workshare loop. In particular, it calls to an OpenMP
409  /// runtime function in the preheader to obtain the loop bounds to be used in
410  /// the current thread, updates the relevant instructions in the canonical
411  /// loop and calls to an OpenMP runtime finalization function after the loop.
412  ///
413  /// \param Loc The source location description, the insertion location
414  /// is not used.
415  /// \param CLI A descriptor of the canonical loop to workshare.
416  /// \param AllocaIP An insertion point for Alloca instructions usable in the
417  /// preheader of the loop.
418  /// \param NeedsBarrier Indicates whether a barrier must be insterted after
419  /// the loop.
420  ///
421  /// \returns Updated CanonicalLoopInfo.
422  CanonicalLoopInfo *createWorkshareLoop(const LocationDescription &Loc,
423  CanonicalLoopInfo *CLI,
424  InsertPointTy AllocaIP,
425  bool NeedsBarrier);
426 
427  /// Tile a loop nest.
428  ///
429  /// Tiles the loops of \p Loops by the tile sizes in \p TileSizes. Loops in
430  /// \p/ Loops must be perfectly nested, from outermost to innermost loop
431  /// (i.e. Loops.front() is the outermost loop). The trip count llvm::Value
432  /// of every loop and every tile sizes must be usable in the outermost
433  /// loop's preheader. This implies that the loop nest is rectangular.
434  ///
435  /// Example:
436  /// \code
437  /// for (int i = 0; i < 15; ++i) // Canonical loop "i"
438  /// for (int j = 0; j < 14; ++j) // Canonical loop "j"
439  /// body(i, j);
440  /// \endcode
441  ///
442  /// After tiling with Loops={i,j} and TileSizes={5,7}, the loop is changed to
443  /// \code
444  /// for (int i1 = 0; i1 < 3; ++i1)
445  /// for (int j1 = 0; j1 < 2; ++j1)
446  /// for (int i2 = 0; i2 < 5; ++i2)
447  /// for (int j2 = 0; j2 < 7; ++j2)
448  /// body(i1*3+i2, j1*3+j2);
449  /// \endcode
450  ///
451  /// The returned vector are the loops {i1,j1,i2,j2}. The loops i1 and j1 are
452  /// referred to the floor, and the loops i2 and j2 are the tiles. Tiling also
453  /// handles non-constant trip counts, non-constant tile sizes and trip counts
454  /// that are not multiples of the tile size. In the latter case the tile loop
455  /// of the last floor-loop iteration will have fewer iterations than specified
456  /// as its tile size.
457  ///
458  ///
459  /// @param DL Debug location for instructions added by tiling, for
460  /// instance the floor- and tile trip count computation.
461  /// @param Loops Loops to tile. The CanonicalLoopInfo objects are
462  /// invalidated by this method, i.e. should not used after
463  /// tiling.
464  /// @param TileSizes For each loop in \p Loops, the tile size for that
465  /// dimensions.
466  ///
467  /// \returns A list of generated loops. Contains twice as many loops as the
468  /// input loop nest; the first half are the floor loops and the
469  /// second half are the tile loops.
470  std::vector<CanonicalLoopInfo *>
472  ArrayRef<Value *> TileSizes);
473 
474  /// Generator for '#omp flush'
475  ///
476  /// \param Loc The location where the flush directive was encountered
477  void createFlush(const LocationDescription &Loc);
478 
479  /// Generator for '#omp taskwait'
480  ///
481  /// \param Loc The location where the taskwait directive was encountered.
482  void createTaskwait(const LocationDescription &Loc);
483 
484  /// Generator for '#omp taskyield'
485  ///
486  /// \param Loc The location where the taskyield directive was encountered.
487  void createTaskyield(const LocationDescription &Loc);
488 
489  /// Functions used to generate reductions. Such functions take two Values
490  /// representing LHS and RHS of the reduction, respectively, and a reference
491  /// to the value that is updated to refer to the reduction result.
492  using ReductionGenTy =
494 
495  /// Functions used to generate atomic reductions. Such functions take two
496  /// Values representing pointers to LHS and RHS of the reduction. They are
497  /// expected to atomically update the LHS to the reduced value.
498  using AtomicReductionGenTy =
500 
501  /// Information about an OpenMP reduction.
502  struct ReductionInfo {
503  /// Returns the type of the element being reduced.
504  Type *getElementType() const {
506  }
507 
508  /// Reduction variable of pointer type.
510 
511  /// Thread-private partial reduction variable.
513 
514  /// Callback for generating the reduction body. The IR produced by this will
515  /// be used to combine two values in a thread-safe context, e.g., under
516  /// lock or within the same thread, and therefore need not be atomic.
518 
519  /// Callback for generating the atomic reduction body, may be null. The IR
520  /// produced by this will be used to atomically combine two values during
521  /// reduction. If null, the implementation will use the non-atomic version
522  /// along with the appropriate synchronization mechanisms.
524  };
525 
526  // TODO: provide atomic and non-atomic reduction generators for reduction
527  // operators defined by the OpenMP specification.
528 
529  /// Generator for '#omp reduction'.
530  ///
531  /// Emits the IR instructing the runtime to perform the specific kind of
532  /// reductions. Expects reduction variables to have been privatized and
533  /// initialized to reduction-neutral values separately. Emits the calls to
534  /// runtime functions as well as the reduction function and the basic blocks
535  /// performing the reduction atomically and non-atomically.
536  ///
537  /// The code emitted for the following:
538  ///
539  /// \code
540  /// type var_1;
541  /// type var_2;
542  /// #pragma omp <directive> reduction(reduction-op:var_1,var_2)
543  /// /* body */;
544  /// \endcode
545  ///
546  /// corresponds to the following sketch.
547  ///
548  /// \code
549  /// void _outlined_par() {
550  /// // N is the number of different reductions.
551  /// void *red_array[] = {privatized_var_1, privatized_var_2, ...};
552  /// switch(__kmpc_reduce(..., N, /*size of data in red array*/, red_array,
553  /// _omp_reduction_func,
554  /// _gomp_critical_user.reduction.var)) {
555  /// case 1: {
556  /// var_1 = var_1 <reduction-op> privatized_var_1;
557  /// var_2 = var_2 <reduction-op> privatized_var_2;
558  /// // ...
559  /// __kmpc_end_reduce(...);
560  /// break;
561  /// }
562  /// case 2: {
563  /// _Atomic<ReductionOp>(var_1, privatized_var_1);
564  /// _Atomic<ReductionOp>(var_2, privatized_var_2);
565  /// // ...
566  /// break;
567  /// }
568  /// default: break;
569  /// }
570  /// }
571  ///
572  /// void _omp_reduction_func(void **lhs, void **rhs) {
573  /// *(type *)lhs[0] = *(type *)lhs[0] <reduction-op> *(type *)rhs[0];
574  /// *(type *)lhs[1] = *(type *)lhs[1] <reduction-op> *(type *)rhs[1];
575  /// // ...
576  /// }
577  /// \endcode
578  ///
579  /// \param Loc The location where the reduction was
580  /// encountered. Must be within the associate
581  /// directive and after the last local access to the
582  /// reduction variables.
583  /// \param AllocaIP An insertion point suitable for allocas usable
584  /// in reductions.
585  /// \param Variables A list of variables in which the reduction
586  /// results will be stored (values of pointer type).
587  /// \param PrivateVariables A list of variables in which the partial
588  /// reduction results are stored (values of pointer
589  /// type). Coindexed with Variables. Privatization
590  /// must be handled separately from this call.
591  /// \param ReductionGen A list of generators for non-atomic reduction
592  /// bodies. Each takes a pair of partially reduced
593  /// values and sets a new one.
594  /// \param AtomicReductionGen A list of generators for atomic reduction
595  /// bodies, empty if the reduction cannot be
596  /// performed with atomics. Each takes a pair of
597  /// _pointers_ to paritally reduced values and
598  /// atomically stores the result into the first.
599  /// \param IsNoWait A flag set if the reduction is marked as nowait.
601  InsertPointTy AllocaIP,
602  ArrayRef<ReductionInfo> ReductionInfos,
603  bool IsNoWait = false);
604 
605  ///}
606 
607  /// Return the insertion point used by the underlying IRBuilder.
609 
610  /// Update the internal location to \p Loc.
612  Builder.restoreIP(Loc.IP);
614  return Loc.IP.getBlock() != nullptr;
615  }
616 
617  /// Return the function declaration for the runtime function with \p FnID.
619  omp::RuntimeFunction FnID);
620 
622 
623  /// Return the (LLVM-IR) string describing the source location \p LocStr.
625 
626  /// Return the (LLVM-IR) string describing the default source location.
628 
629  /// Return the (LLVM-IR) string describing the source location identified by
630  /// the arguments.
631  Constant *getOrCreateSrcLocStr(StringRef FunctionName, StringRef FileName,
632  unsigned Line, unsigned Column);
633 
634  /// Return the (LLVM-IR) string describing the source location \p Loc.
635  Constant *getOrCreateSrcLocStr(const LocationDescription &Loc);
636 
637  /// Return an ident_t* encoding the source location \p SrcLocStr and \p Flags.
638  /// TODO: Create a enum class for the Reserve2Flags
639  Value *getOrCreateIdent(Constant *SrcLocStr,
640  omp::IdentFlag Flags = omp::IdentFlag(0),
641  unsigned Reserve2Flags = 0);
642 
643  // Get the type corresponding to __kmpc_impl_lanemask_t from the deviceRTL
645 
646  /// Generate control flow and cleanup for cancellation.
647  ///
648  /// \param CancelFlag Flag indicating if the cancellation is performed.
649  /// \param CanceledDirective The kind of directive that is cancled.
650  /// \param ExitCB Extra code to be generated in the exit block.
651  void emitCancelationCheckImpl(Value *CancelFlag,
652  omp::Directive CanceledDirective,
653  FinalizeCallbackTy ExitCB = {});
654 
655  /// Generate a barrier runtime call.
656  ///
657  /// \param Loc The location at which the request originated and is fulfilled.
658  /// \param DK The directive which caused the barrier
659  /// \param ForceSimpleCall Flag to force a simple (=non-cancellation) barrier.
660  /// \param CheckCancelFlag Flag to indicate a cancel barrier return value
661  /// should be checked and acted upon.
662  ///
663  /// \returns The insertion point after the barrier.
664  InsertPointTy emitBarrierImpl(const LocationDescription &Loc,
665  omp::Directive DK, bool ForceSimpleCall,
666  bool CheckCancelFlag);
667 
668  /// Generate a flush runtime call.
669  ///
670  /// \param Loc The location at which the request originated and is fulfilled.
671  void emitFlush(const LocationDescription &Loc);
672 
673  /// The finalization stack made up of finalize callbacks currently in-flight,
674  /// wrapped into FinalizationInfo objects that reference also the finalization
675  /// target block and the kind of cancellable directive.
677 
678  /// Return true if the last entry in the finalization stack is of kind \p DK
679  /// and cancellable.
680  bool isLastFinalizationInfoCancellable(omp::Directive DK) {
681  return !FinalizationStack.empty() &&
682  FinalizationStack.back().IsCancellable &&
683  FinalizationStack.back().DK == DK;
684  }
685 
686  /// Generate a taskwait runtime call.
687  ///
688  /// \param Loc The location at which the request originated and is fulfilled.
689  void emitTaskwaitImpl(const LocationDescription &Loc);
690 
691  /// Generate a taskyield runtime call.
692  ///
693  /// \param Loc The location at which the request originated and is fulfilled.
694  void emitTaskyieldImpl(const LocationDescription &Loc);
695 
696  /// Return the current thread ID.
697  ///
698  /// \param Ident The ident (ident_t*) describing the query origin.
700 
701  /// The underlying LLVM-IR module
703 
704  /// The LLVM-IR Builder used to create IR.
706 
707  /// Map to remember source location strings
709 
710  /// Map to remember existing ident_t*.
712 
713  /// Helper that contains information about regions we need to outline
714  /// during finalization.
715  struct OutlineInfo {
719 
720  /// Collect all blocks in between EntryBB and ExitBB in both the given
721  /// vector and set.
723  SmallVectorImpl<BasicBlock *> &BlockVector);
724 
725  /// Return the function that contains the region to be outlined.
726  Function *getFunction() const { return EntryBB->getParent(); }
727  };
728 
729  /// Collection of regions that need to be outlined during finalization.
731 
732  /// Collection of owned canonical loop objects that eventually need to be
733  /// free'd.
734  std::forward_list<CanonicalLoopInfo> LoopInfos;
735 
736  /// Add a new region that will be outlined later.
737  void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
738 
739  /// An ordered map of auto-generated variables to their unique names.
740  /// It stores variables with the following names: 1) ".gomp_critical_user_" +
741  /// <critical_section_name> + ".var" for "omp critical" directives; 2)
742  /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
743  /// variables.
745 
746  /// Create the global variable holding the offload mappings information.
748  std::string VarName);
749 
750  /// Create the global variable holding the offload names information.
753  std::string VarName);
754 
755  struct MapperAllocas {
756  AllocaInst *ArgsBase = nullptr;
757  AllocaInst *Args = nullptr;
758  AllocaInst *ArgSizes = nullptr;
759  };
760 
761  /// Create the allocas instruction used in call to mapper functions.
763  InsertPointTy AllocaIP, unsigned NumOperands,
764  struct MapperAllocas &MapperAllocas);
765 
766  /// Create the call for the target mapper function.
767  /// \param Loc The source location description.
768  /// \param MapperFunc Function to be called.
769  /// \param SrcLocInfo Source location information global.
770  /// \param MaptypesArgs
771  /// \param MapnamesArg
772  /// \param MapperAllocas The AllocaInst used for the call.
773  /// \param DeviceID Device ID for the call.
774  /// \param TotalNbOperand Number of operand in the call.
775  void emitMapperCall(const LocationDescription &Loc, Function *MapperFunc,
776  Value *SrcLocInfo, Value *MaptypesArg, Value *MapnamesArg,
777  struct MapperAllocas &MapperAllocas, int64_t DeviceID,
778  unsigned NumOperands);
779 
780 public:
781  /// Generator for __kmpc_copyprivate
782  ///
783  /// \param Loc The source location description.
784  /// \param BufSize Number of elements in the buffer.
785  /// \param CpyBuf List of pointers to data to be copied.
786  /// \param CpyFn function to call for copying data.
787  /// \param DidIt flag variable; 1 for 'single' thread, 0 otherwise.
788  ///
789  /// \return The insertion position *after* the CopyPrivate call.
790 
792  llvm::Value *BufSize, llvm::Value *CpyBuf,
793  llvm::Value *CpyFn, llvm::Value *DidIt);
794 
795  /// Generator for '#omp single'
796  ///
797  /// \param Loc The source location description.
798  /// \param BodyGenCB Callback that will generate the region code.
799  /// \param FiniCB Callback to finalize variable copies.
800  /// \param DidIt Local variable used as a flag to indicate 'single' thread
801  ///
802  /// \returns The insertion position *after* the single call.
804  BodyGenCallbackTy BodyGenCB,
805  FinalizeCallbackTy FiniCB, llvm::Value *DidIt);
806 
807  /// Generator for '#omp master'
808  ///
809  /// \param Loc The insert and source location description.
810  /// \param BodyGenCB Callback that will generate the region code.
811  /// \param FiniCB Callback to finalize variable copies.
812  ///
813  /// \returns The insertion position *after* the master.
815  BodyGenCallbackTy BodyGenCB,
816  FinalizeCallbackTy FiniCB);
817 
818  /// Generator for '#omp masked'
819  ///
820  /// \param Loc The insert and source location description.
821  /// \param BodyGenCB Callback that will generate the region code.
822  /// \param FiniCB Callback to finialize variable copies.
823  ///
824  /// \returns The insertion position *after* the master.
826  BodyGenCallbackTy BodyGenCB,
827  FinalizeCallbackTy FiniCB, Value *Filter);
828 
829  /// Generator for '#omp critical'
830  ///
831  /// \param Loc The insert and source location description.
832  /// \param BodyGenCB Callback that will generate the region body code.
833  /// \param FiniCB Callback to finalize variable copies.
834  /// \param CriticalName name of the lock used by the critical directive
835  /// \param HintInst Hint Instruction for hint clause associated with critical
836  ///
837  /// \returns The insertion position *after* the master.
839  BodyGenCallbackTy BodyGenCB,
840  FinalizeCallbackTy FiniCB,
841  StringRef CriticalName, Value *HintInst);
842 
843  /// Generator for '#omp sections'
844  ///
845  /// \param Loc The insert and source location description.
846  /// \param AllocaIP The insertion points to be used for alloca instructions.
847  /// \param SectionCBs Callbacks that will generate body of each section.
848  /// \param PrivCB Callback to copy a given variable (think copy constructor).
849  /// \param FiniCB Callback to finalize variable copies.
850  /// \param IsCancellable Flag to indicate a cancellable parallel region.
851  /// \param IsNowait If true, barrier - to ensure all sections are executed
852  /// before moving forward will not be generated.
853  /// \returns The insertion position *after* the sections.
855  InsertPointTy AllocaIP,
857  PrivatizeCallbackTy PrivCB,
858  FinalizeCallbackTy FiniCB, bool IsCancellable,
859  bool IsNowait);
860 
861  /// Generator for '#omp section'
862  ///
863  /// \param Loc The insert and source location description.
864  /// \param BodyGenCB Callback that will generate the region body code.
865  /// \param FiniCB Callback to finalize variable copies.
866  /// \returns The insertion position *after* the section.
868  BodyGenCallbackTy BodyGenCB,
869  FinalizeCallbackTy FiniCB);
870 
871  /// Generate conditional branch and relevant BasicBlocks through which private
872  /// threads copy the 'copyin' variables from Master copy to threadprivate
873  /// copies.
874  ///
875  /// \param IP insertion block for copyin conditional
876  /// \param MasterVarPtr a pointer to the master variable
877  /// \param PrivateVarPtr a pointer to the threadprivate variable
878  /// \param IntPtrTy Pointer size type
879  /// \param BranchtoEnd Create a branch between the copyin.not.master blocks
880  // and copy.in.end block
881  ///
882  /// \returns The insertion point where copying operation to be emitted.
884  Value *PrivateAddr,
885  llvm::IntegerType *IntPtrTy,
886  bool BranchtoEnd = true);
887 
888  /// Create a runtime call for kmpc_Alloc
889  ///
890  /// \param Loc The insert and source location description.
891  /// \param Size Size of allocated memory space
892  /// \param Allocator Allocator information instruction
893  /// \param Name Name of call Instruction for OMP_alloc
894  ///
895  /// \returns CallInst to the OMP_Alloc call
897  Value *Allocator, std::string Name = "");
898 
899  /// Create a runtime call for kmpc_free
900  ///
901  /// \param Loc The insert and source location description.
902  /// \param Addr Address of memory space to be freed
903  /// \param Allocator Allocator information instruction
904  /// \param Name Name of call Instruction for OMP_Free
905  ///
906  /// \returns CallInst to the OMP_Free call
908  Value *Allocator, std::string Name = "");
909 
910  /// Create a runtime call for kmpc_threadprivate_cached
911  ///
912  /// \param Loc The insert and source location description.
913  /// \param Pointer pointer to data to be cached
914  /// \param Size size of data to be cached
915  /// \param Name Name of call Instruction for callinst
916  ///
917  /// \returns CallInst to the thread private cache call.
919  llvm::Value *Pointer,
921  const llvm::Twine &Name = Twine(""));
922 
923  /// The `omp target` interface
924  ///
925  /// For more information about the usage of this interface,
926  /// \see openmp/libomptarget/deviceRTLs/common/include/target.h
927  ///
928  ///{
929 
930  /// Create a runtime call for kmpc_target_init
931  ///
932  /// \param Loc The insert and source location description.
933  /// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
934  /// \param RequiresFullRuntime Indicate if a full device runtime is necessary.
935  InsertPointTy createTargetInit(const LocationDescription &Loc, bool IsSPMD, bool RequiresFullRuntime);
936 
937  /// Create a runtime call for kmpc_target_deinit
938  ///
939  /// \param Loc The insert and source location description.
940  /// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
941  /// \param RequiresFullRuntime Indicate if a full device runtime is necessary.
942  void createTargetDeinit(const LocationDescription &Loc, bool IsSPMD, bool RequiresFullRuntime);
943 
944  ///}
945 
946  /// Declarations for LLVM-IR types (simple, array, function and structure) are
947  /// generated below. Their names are defined and used in OpenMPKinds.def. Here
948  /// we provide the declarations, the initializeTypes function will provide the
949  /// values.
950  ///
951  ///{
952 #define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
953 #define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
954  ArrayType *VarName##Ty = nullptr; \
955  PointerType *VarName##PtrTy = nullptr;
956 #define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
957  FunctionType *VarName = nullptr; \
958  PointerType *VarName##Ptr = nullptr;
959 #define OMP_STRUCT_TYPE(VarName, StrName, ...) \
960  StructType *VarName = nullptr; \
961  PointerType *VarName##Ptr = nullptr;
962 #include "llvm/Frontend/OpenMP/OMPKinds.def"
963 
964  ///}
965 
966 private:
967  /// Create all simple and struct types exposed by the runtime and remember
968  /// the llvm::PointerTypes of them for easy access later.
969  void initializeTypes(Module &M);
970 
971  /// Common interface for generating entry calls for OMP Directives.
972  /// if the directive has a region/body, It will set the insertion
973  /// point to the body
974  ///
975  /// \param OMPD Directive to generate entry blocks for
976  /// \param EntryCall Call to the entry OMP Runtime Function
977  /// \param ExitBB block where the region ends.
978  /// \param Conditional indicate if the entry call result will be used
979  /// to evaluate a conditional of whether a thread will execute
980  /// body code or not.
981  ///
982  /// \return The insertion position in exit block
983  InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD, Value *EntryCall,
984  BasicBlock *ExitBB,
985  bool Conditional = false);
986 
987  /// Common interface to finalize the region
988  ///
989  /// \param OMPD Directive to generate exiting code for
990  /// \param FinIP Insertion point for emitting Finalization code and exit call
991  /// \param ExitCall Call to the ending OMP Runtime Function
992  /// \param HasFinalize indicate if the directive will require finalization
993  /// and has a finalization callback in the stack that
994  /// should be called.
995  ///
996  /// \return The insertion position in exit block
997  InsertPointTy emitCommonDirectiveExit(omp::Directive OMPD,
998  InsertPointTy FinIP,
999  Instruction *ExitCall,
1000  bool HasFinalize = true);
1001 
1002  /// Common Interface to generate OMP inlined regions
1003  ///
1004  /// \param OMPD Directive to generate inlined region for
1005  /// \param EntryCall Call to the entry OMP Runtime Function
1006  /// \param ExitCall Call to the ending OMP Runtime Function
1007  /// \param BodyGenCB Body code generation callback.
1008  /// \param FiniCB Finalization Callback. Will be called when finalizing region
1009  /// \param Conditional indicate if the entry call result will be used
1010  /// to evaluate a conditional of whether a thread will execute
1011  /// body code or not.
1012  /// \param HasFinalize indicate if the directive will require finalization
1013  /// and has a finalization callback in the stack that
1014  /// should be called.
1015  /// \param IsCancellable if HasFinalize is set to true, indicate if the
1016  /// the directive should be cancellable.
1017  /// \return The insertion point after the region
1018 
1020  EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
1021  Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
1022  FinalizeCallbackTy FiniCB, bool Conditional = false,
1023  bool HasFinalize = true, bool IsCancellable = false);
1024 
1025  /// Get the platform-specific name separator.
1026  /// \param Parts different parts of the final name that needs separation
1027  /// \param FirstSeparator First separator used between the initial two
1028  /// parts of the name.
1029  /// \param Separator separator used between all of the rest consecutive
1030  /// parts of the name
1031  static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
1032  StringRef FirstSeparator,
1033  StringRef Separator);
1034 
1035  /// Gets (if variable with the given name already exist) or creates
1036  /// internal global variable with the specified Name. The created variable has
1037  /// linkage CommonLinkage by default and is initialized by null value.
1038  /// \param Ty Type of the global variable. If it is exist already the type
1039  /// must be the same.
1040  /// \param Name Name of the variable.
1041  Constant *getOrCreateOMPInternalVariable(Type *Ty, const Twine &Name,
1042  unsigned AddressSpace = 0);
1043 
1044  /// Returns corresponding lock object for the specified critical region
1045  /// name. If the lock object does not exist it is created, otherwise the
1046  /// reference to the existing copy is returned.
1047  /// \param CriticalName Name of the critical region.
1048  ///
1049  Value *getOMPCriticalRegionLock(StringRef CriticalName);
1050 
1051  /// Callback type for Atomic Expression update
1052  /// ex:
1053  /// \code{.cpp}
1054  /// unsigned x = 0;
1055  /// #pragma omp atomic update
1056  /// x = Expr(x_old); //Expr() is any legal operation
1057  /// \endcode
1058  ///
1059  /// \param XOld the value of the atomic memory address to use for update
1060  /// \param IRB reference to the IRBuilder to use
1061  ///
1062  /// \returns Value to update X to.
1063  using AtomicUpdateCallbackTy =
1064  const function_ref<Value *(Value *XOld, IRBuilder<> &IRB)>;
1065 
1066 private:
1067  enum AtomicKind { Read, Write, Update, Capture };
1068 
1069  /// Determine whether to emit flush or not
1070  ///
1071  /// \param Loc The insert and source location description.
1072  /// \param AO The required atomic ordering
1073  /// \param AK The OpenMP atomic operation kind used.
1074  ///
1075  /// \returns wether a flush was emitted or not
1076  bool checkAndEmitFlushAfterAtomic(const LocationDescription &Loc,
1077  AtomicOrdering AO, AtomicKind AK);
1078 
1079  /// Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X
1080  /// For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X)
1081  /// Only Scalar data types.
1082  ///
1083  /// \param AllocIP Instruction to create AllocaInst before.
1084  /// \param X The target atomic pointer to be updated
1085  /// \param Expr The value to update X with.
1086  /// \param AO Atomic ordering of the generated atomic
1087  /// instructions.
1088  /// \param RMWOp The binary operation used for update. If
1089  /// operation is not supported by atomicRMW,
1090  /// or belong to {FADD, FSUB, BAD_BINOP}.
1091  /// Then a `cmpExch` based atomic will be generated.
1092  /// \param UpdateOp Code generator for complex expressions that cannot be
1093  /// expressed through atomicrmw instruction.
1094  /// \param VolatileX true if \a X volatile?
1095  /// \param IsXLHSInRHSPart true if \a X is Left H.S. in Right H.S. part of
1096  /// the update expression, false otherwise.
1097  /// (e.g. true for X = X BinOp Expr)
1098  ///
1099  /// \returns A pair of the old value of X before the update, and the value
1100  /// used for the update.
1101  std::pair<Value *, Value *> emitAtomicUpdate(Instruction *AllocIP, Value *X,
1102  Value *Expr, AtomicOrdering AO,
1103  AtomicRMWInst::BinOp RMWOp,
1104  AtomicUpdateCallbackTy &UpdateOp,
1105  bool VolatileX,
1106  bool IsXLHSInRHSPart);
1107 
1108  /// Emit the binary op. described by \p RMWOp, using \p Src1 and \p Src2 .
1109  ///
1110  /// \Return The instruction
1111  Value *emitRMWOpAsInstruction(Value *Src1, Value *Src2,
1112  AtomicRMWInst::BinOp RMWOp);
1113 
1114 public:
1115  /// a struct to pack relevant information while generating atomic Ops
1116  struct AtomicOpValue {
1117  Value *Var = nullptr;
1118  bool IsSigned = false;
1119  bool IsVolatile = false;
1120  };
1121 
1122  /// Emit atomic Read for : V = X --- Only Scalar data types.
1123  ///
1124  /// \param Loc The insert and source location description.
1125  /// \param X The target pointer to be atomically read
1126  /// \param V Memory address where to store atomically read
1127  /// value
1128  /// \param AO Atomic ordering of the generated atomic
1129  /// instructions.
1130  ///
1131  /// \return Insertion point after generated atomic read IR.
1134  AtomicOrdering AO);
1135 
1136  /// Emit atomic write for : X = Expr --- Only Scalar data types.
1137  ///
1138  /// \param Loc The insert and source location description.
1139  /// \param X The target pointer to be atomically written to
1140  /// \param Expr The value to store.
1141  /// \param AO Atomic ordering of the generated atomic
1142  /// instructions.
1143  ///
1144  /// \return Insertion point after generated atomic Write IR.
1146  AtomicOpValue &X, Value *Expr,
1147  AtomicOrdering AO);
1148 
1149  /// Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X
1150  /// For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X)
1151  /// Only Scalar data types.
1152  ///
1153  /// \param Loc The insert and source location description.
1154  /// \param AllocIP Instruction to create AllocaInst before.
1155  /// \param X The target atomic pointer to be updated
1156  /// \param Expr The value to update X with.
1157  /// \param AO Atomic ordering of the generated atomic instructions.
1158  /// \param RMWOp The binary operation used for update. If operation
1159  /// is not supported by atomicRMW, or belong to
1160  /// {FADD, FSUB, BAD_BINOP}. Then a `cmpExch` based
1161  /// atomic will be generated.
1162  /// \param UpdateOp Code generator for complex expressions that cannot be
1163  /// expressed through atomicrmw instruction.
1164  /// \param IsXLHSInRHSPart true if \a X is Left H.S. in Right H.S. part of
1165  /// the update expression, false otherwise.
1166  /// (e.g. true for X = X BinOp Expr)
1167  ///
1168  /// \return Insertion point after generated atomic update IR.
1170  Instruction *AllocIP, AtomicOpValue &X,
1171  Value *Expr, AtomicOrdering AO,
1172  AtomicRMWInst::BinOp RMWOp,
1173  AtomicUpdateCallbackTy &UpdateOp,
1174  bool IsXLHSInRHSPart);
1175 
1176  /// Emit atomic update for constructs: --- Only Scalar data types
1177  /// V = X; X = X BinOp Expr ,
1178  /// X = X BinOp Expr; V = X,
1179  /// V = X; X = Expr BinOp X,
1180  /// X = Expr BinOp X; V = X,
1181  /// V = X; X = UpdateOp(X),
1182  /// X = UpdateOp(X); V = X,
1183  ///
1184  /// \param Loc The insert and source location description.
1185  /// \param AllocIP Instruction to create AllocaInst before.
1186  /// \param X The target atomic pointer to be updated
1187  /// \param V Memory address where to store captured value
1188  /// \param Expr The value to update X with.
1189  /// \param AO Atomic ordering of the generated atomic instructions
1190  /// \param RMWOp The binary operation used for update. If
1191  /// operation is not supported by atomicRMW, or belong to
1192  /// {FADD, FSUB, BAD_BINOP}. Then a cmpExch based
1193  /// atomic will be generated.
1194  /// \param UpdateOp Code generator for complex expressions that cannot be
1195  /// expressed through atomicrmw instruction.
1196  /// \param UpdateExpr true if X is an in place update of the form
1197  /// X = X BinOp Expr or X = Expr BinOp X
1198  /// \param IsXLHSInRHSPart true if X is Left H.S. in Right H.S. part of the
1199  /// update expression, false otherwise.
1200  /// (e.g. true for X = X BinOp Expr)
1201  /// \param IsPostfixUpdate true if original value of 'x' must be stored in
1202  /// 'v', not an updated one.
1203  ///
1204  /// \return Insertion point after generated atomic capture IR.
1207  AtomicOpValue &X, AtomicOpValue &V, Value *Expr,
1209  AtomicUpdateCallbackTy &UpdateOp, bool UpdateExpr,
1210  bool IsPostfixUpdate, bool IsXLHSInRHSPart);
1211 
1212  /// Create the control flow structure of a canonical OpenMP loop.
1213  ///
1214  /// The emitted loop will be disconnected, i.e. no edge to the loop's
1215  /// preheader and no terminator in the AfterBB. The OpenMPIRBuilder's
1216  /// IRBuilder location is not preserved.
1217  ///
1218  /// \param DL DebugLoc used for the instructions in the skeleton.
1219  /// \param TripCount Value to be used for the trip count.
1220  /// \param F Function in which to insert the BasicBlocks.
1221  /// \param PreInsertBefore Where to insert BBs that execute before the body,
1222  /// typically the body itself.
1223  /// \param PostInsertBefore Where to insert BBs that execute after the body.
1224  /// \param Name Base name used to derive BB
1225  /// and instruction names.
1226  ///
1227  /// \returns The CanonicalLoopInfo that represents the emitted loop.
1229  Function *F,
1230  BasicBlock *PreInsertBefore,
1231  BasicBlock *PostInsertBefore,
1232  const Twine &Name = {});
1233 };
1234 
1235 /// Class to represented the control flow structure of an OpenMP canonical loop.
1236 ///
1237 /// The control-flow structure is standardized for easy consumption by
1238 /// directives associated with loops. For instance, the worksharing-loop
1239 /// construct may change this control flow such that each loop iteration is
1240 /// executed on only one thread.
1241 ///
1242 /// The control flow can be described as follows:
1243 ///
1244 /// Preheader
1245 /// |
1246 /// /-> Header
1247 /// | |
1248 /// | Cond---\
1249 /// | | |
1250 /// | Body |
1251 /// | | | |
1252 /// | <...> |
1253 /// | | | |
1254 /// \--Latch |
1255 /// |
1256 /// Exit
1257 /// |
1258 /// After
1259 ///
1260 /// Code in the header, condition block, latch and exit block must not have any
1261 /// side-effect. The body block is the single entry point into the loop body,
1262 /// which may contain arbitrary control flow as long as all control paths
1263 /// eventually branch to the latch block.
1264 ///
1265 /// Defined outside OpenMPIRBuilder because one cannot forward-declare nested
1266 /// classes.
1268  friend class OpenMPIRBuilder;
1269 
1270 private:
1271  /// Whether this object currently represents a loop.
1272  bool IsValid = false;
1273 
1274  BasicBlock *Preheader;
1275  BasicBlock *Header;
1276  BasicBlock *Cond;
1277  BasicBlock *Body;
1278  BasicBlock *Latch;
1279  BasicBlock *Exit;
1280  BasicBlock *After;
1281 
1282  /// Add the control blocks of this loop to \p BBs.
1283  ///
1284  /// This does not include any block from the body, including the one returned
1285  /// by getBody().
1286  void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
1287 
1288 public:
1289  /// The preheader ensures that there is only a single edge entering the loop.
1290  /// Code that must be execute before any loop iteration can be emitted here,
1291  /// such as computing the loop trip count and begin lifetime markers. Code in
1292  /// the preheader is not considered part of the canonical loop.
1293  BasicBlock *getPreheader() const { return Preheader; }
1294 
1295  /// The header is the entry for each iteration. In the canonical control flow,
1296  /// it only contains the PHINode for the induction variable.
1297  BasicBlock *getHeader() const { return Header; }
1298 
1299  /// The condition block computes whether there is another loop iteration. If
1300  /// yes, branches to the body; otherwise to the exit block.
1301  BasicBlock *getCond() const { return Cond; }
1302 
1303  /// The body block is the single entry for a loop iteration and not controlled
1304  /// by CanonicalLoopInfo. It can contain arbitrary control flow but must
1305  /// eventually branch to the \p Latch block.
1306  BasicBlock *getBody() const { return Body; }
1307 
1308  /// Reaching the latch indicates the end of the loop body code. In the
1309  /// canonical control flow, it only contains the increment of the induction
1310  /// variable.
1311  BasicBlock *getLatch() const { return Latch; }
1312 
1313  /// Reaching the exit indicates no more iterations are being executed.
1314  BasicBlock *getExit() const { return Exit; }
1315 
1316  /// The after block is intended for clean-up code such as lifetime end
1317  /// markers. It is separate from the exit block to ensure, analogous to the
1318  /// preheader, it having just a single entry edge and being free from PHI
1319  /// nodes should there be multiple loop exits (such as from break
1320  /// statements/cancellations).
1321  BasicBlock *getAfter() const { return After; }
1322 
1323  /// Returns the llvm::Value containing the number of loop iterations. It must
1324  /// be valid in the preheader and always interpreted as an unsigned integer of
1325  /// any bit-width.
1326  Value *getTripCount() const {
1327  Instruction *CmpI = &Cond->front();
1328  assert(isa<CmpInst>(CmpI) && "First inst must compare IV with TripCount");
1329  return CmpI->getOperand(1);
1330  }
1331 
1332  /// Returns the instruction representing the current logical induction
1333  /// variable. Always unsigned, always starting at 0 with an increment of one.
1335  Instruction *IndVarPHI = &Header->front();
1336  assert(isa<PHINode>(IndVarPHI) && "First inst must be the IV PHI");
1337  return IndVarPHI;
1338  }
1339 
1340  /// Return the type of the induction variable (and the trip count).
1341  Type *getIndVarType() const { return getIndVar()->getType(); }
1342 
1343  /// Return the insertion point for user code before the loop.
1345  return {Preheader, std::prev(Preheader->end())};
1346  };
1347 
1348  /// Return the insertion point for user code in the body.
1350  return {Body, Body->begin()};
1351  };
1352 
1353  /// Return the insertion point for user code after the loop.
1355  return {After, After->begin()};
1356  };
1357 
1358  Function *getFunction() const { return Header->getParent(); }
1359 
1360  /// Consistency self-check.
1361  void assertOK() const;
1362 };
1363 
1364 } // end namespace llvm
1365 
1366 #endif // LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::CanonicalLoopInfo::getPreheaderIP
OpenMPIRBuilder::InsertPointTy getPreheaderIP() const
Return the insertion point for user code before the loop.
Definition: OMPIRBuilder.h:1344
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:2349
llvm::BasicBlock::end
iterator end()
Definition: BasicBlock.h:298
llvm::IRBuilderBase::restoreIP
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
Definition: IRBuilder.h:283
llvm::OpenMPIRBuilder::LocationDescription
Description of a LLVM-IR insertion point (IP) and a debug/source location (filename,...
Definition: OMPIRBuilder.h:150
llvm::OpenMPIRBuilder::OutlineInfo::ExitBB
BasicBlock * ExitBB
Definition: OMPIRBuilder.h:718
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::OpenMPIRBuilder::createSection
InsertPointTy createSection(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB)
Generator for '#omp section'.
Definition: OMPIRBuilder.cpp:991
llvm::OpenMPIRBuilder::createCritical
InsertPointTy createCritical(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, StringRef CriticalName, Value *HintInst)
Generator for '#omp critical'.
Definition: OMPIRBuilder.cpp:2103
llvm::CanonicalLoopInfo::getAfter
BasicBlock * getAfter() const
The after block is intended for clean-up code such as lifetime end markers.
Definition: OMPIRBuilder.h:1321
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:107
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:1246
llvm::OpenMPIRBuilder::pushFinalizationCB
void pushFinalizationCB(const FinalizationInfo &FI)
Push a finalization callback on the finalization stack.
Definition: OMPIRBuilder.h:81
llvm::Function
Definition: Function.h:61
llvm::OpenMPIRBuilder::ReductionInfo::getElementType
Type * getElementType() const
Returns the type of the element being reduced.
Definition: OMPIRBuilder.h:504
Loops
Hexagon Hardware Loops
Definition: HexagonHardwareLoops.cpp:372
llvm::AtomicRMWInst::BinOp
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:738
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::OpenMPIRBuilder::tileLoops
std::vector< CanonicalLoopInfo * > tileLoops(DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, ArrayRef< Value * > TileSizes)
Tile a loop nest.
Definition: OMPIRBuilder.cpp:1863
llvm::OpenMPIRBuilder::createWorkshareLoop
CanonicalLoopInfo * createWorkshareLoop(const LocationDescription &Loc, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, bool NeedsBarrier)
Modifies the canonical loop to be a workshare loop.
Definition: OMPIRBuilder.cpp:1532
llvm::OpenMPIRBuilder::getLanemaskType
Type * getLanemaskType()
Definition: OMPIRBuilder.cpp:264
llvm::OpenMPIRBuilder::InsertPointTy
IRBuilder<>::InsertPoint InsertPointTy
Type used throughout for insertion points.
Definition: OMPIRBuilder.h:53
llvm::IRBuilder
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2643
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::OpenMPIRBuilder::getOrCreateThreadID
Value * getOrCreateThreadID(Value *Ident)
Return the current thread ID.
Definition: OMPIRBuilder.cpp:329
Allocator.h
llvm::tgtok::VarName
@ VarName
Definition: TGLexer.h:71
llvm::OpenMPIRBuilder::FinalizationInfo::IsCancellable
bool IsCancellable
Flag to indicate if the directive is cancellable.
Definition: OMPIRBuilder.h:75
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::OpenMPIRBuilder::AtomicOpValue
a struct to pack relevant information while generating atomic Ops
Definition: OMPIRBuilder.h:1116
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:68
llvm::CanonicalLoopInfo::getAfterIP
OpenMPIRBuilder::InsertPointTy getAfterIP() const
Return the insertion point for user code after the loop.
Definition: OMPIRBuilder.h:1354
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const IRBuilder< T, U > &IRB)
Definition: OMPIRBuilder.h:152
llvm::OpenMPIRBuilder::ReductionInfo::Variable
Value * Variable
Reduction variable of pointer type.
Definition: OMPIRBuilder.h:509
llvm::OpenMPIRBuilder::FinalizeCallbackTy
std::function< void(InsertPointTy CodeGenIP)> FinalizeCallbackTy
Callback type for variable finalization (think destructors).
Definition: OMPIRBuilder.h:63
llvm::CanonicalLoopInfo::getFunction
Function * getFunction() const
Definition: OMPIRBuilder.h:1358
llvm::OpenMPIRBuilder::AtomicOpValue::Var
Value * Var
Definition: OMPIRBuilder.h:1117
llvm::OpenMPIRBuilder::createAtomicCapture
InsertPointTy createAtomicCapture(const LocationDescription &Loc, Instruction *AllocIP, AtomicOpValue &X, AtomicOpValue &V, Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp, bool UpdateExpr, bool IsPostfixUpdate, bool IsXLHSInRHSPart)
Emit atomic update for constructs: — Only Scalar data types V = X; X = X BinOp Expr ,...
Definition: OMPIRBuilder.cpp:2827
llvm::OpenMPIRBuilder::BodyGenCallbackTy
function_ref< void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP, BasicBlock &ContinuationBB)> BodyGenCallbackTy
Callback type for body (=inner region) code generation.
Definition: OMPIRBuilder.h:105
llvm::OpenMPIRBuilder::emitTaskyieldImpl
void emitTaskyieldImpl(const LocationDescription &Loc)
Generate a taskyield runtime call.
Definition: OMPIRBuilder.cpp:876
llvm::OpenMPIRBuilder::createReductions
InsertPointTy createReductions(const LocationDescription &Loc, InsertPointTy AllocaIP, ArrayRef< ReductionInfo > ReductionInfos, bool IsNoWait=false)
Generator for '#omp reduction'.
Definition: OMPIRBuilder.cpp:1037
llvm::OpenMPIRBuilder::collapseLoops
CanonicalLoopInfo * collapseLoops(DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, InsertPointTy ComputeIP)
Collapse a loop nest into a single loop.
Definition: OMPIRBuilder.cpp:1742
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::CanonicalLoopInfo::getIndVar
Instruction * getIndVar() const
Returns the instruction representing the current logical induction variable.
Definition: OMPIRBuilder.h:1334
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::OpenMPIRBuilder::finalize
void finalize(Function *Fn=nullptr, bool AllowExtractorSinking=false)
Finalize the underlying module, e.g., by outlining regions.
Definition: OMPIRBuilder.cpp:142
Mappings
Inject TLI Mappings
Definition: InjectTLIMappings.cpp:172
llvm::OpenMPIRBuilder::createDynamicWorkshareLoop
InsertPointTy createDynamicWorkshareLoop(const LocationDescription &Loc, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, omp::OMPScheduleType SchedType, bool NeedsBarrier, Value *Chunk=nullptr)
Modifies the canonical loop to be a dynamically-scheduled workshare loop.
Definition: OMPIRBuilder.cpp:1571
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
llvm::OpenMPIRBuilder::popFinalizationCB
void popFinalizationCB()
Pop the last finalization callback from the finalization stack.
Definition: OMPIRBuilder.h:88
llvm::OpenMPIRBuilder::getOrCreateDefaultSrcLocStr
Constant * getOrCreateDefaultSrcLocStr()
Return the (LLVM-IR) string describing the default source location.
Definition: OMPIRBuilder.cpp:309
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:2513
llvm::OpenMPIRBuilder::getOrCreateIdent
Value * getOrCreateIdent(Constant *SrcLocStr, omp::IdentFlag Flags=omp::IdentFlag(0), unsigned Reserve2Flags=0)
Return an ident_t* encoding the source location SrcLocStr and Flags.
Definition: OMPIRBuilder.cpp:231
llvm::OpenMPIRBuilder::M
Module & M
The underlying LLVM-IR module.
Definition: OMPIRBuilder.h:702
llvm::CanonicalLoopInfo::assertOK
void assertOK() const
Consistency self-check.
Definition: OMPIRBuilder.cpp:2923
llvm::CanonicalLoopInfo::getCond
BasicBlock * getCond() const
The condition block computes whether there is another loop iteration.
Definition: OMPIRBuilder.h:1301
llvm::OpenMPIRBuilder
An interface to create LLVM-IR for OpenMP directives.
Definition: OMPIRBuilder.h:29
llvm::OpenMPIRBuilder::OutlineInfos
SmallVector< OutlineInfo, 16 > OutlineInfos
Collection of regions that need to be outlined during finalization.
Definition: OMPIRBuilder.h:730
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:2335
llvm::BasicBlock::begin
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:296
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:2494
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:336
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:2600
IP
Definition: NVPTXLowerArgs.cpp:166
llvm::OpenMPIRBuilder::getInsertionPoint
InsertPointTy getInsertionPoint()
}
Definition: OMPIRBuilder.h:608
llvm::IRBuilderBase::SetCurrentDebugLocation
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Definition: IRBuilder.h:208
llvm::OpenMPIRBuilder::~OpenMPIRBuilder
~OpenMPIRBuilder()
Definition: OMPIRBuilder.cpp:227
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::OpenMPIRBuilder::IdentMap
DenseMap< std::pair< Constant *, uint64_t >, Value * > IdentMap
Map to remember existing ident_t*.
Definition: OMPIRBuilder.h:711
llvm::OpenMPIRBuilder::AtomicOpValue::IsSigned
bool IsSigned
Definition: OMPIRBuilder.h:1118
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const InsertPointTy &IP)
Definition: OMPIRBuilder.h:154
llvm::Instruction
Definition: Instruction.h:45
llvm::OpenMPIRBuilder::StorableBodyGenCallbackTy
std::function< void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP, BasicBlock &ContinuationBB)> StorableBodyGenCallbackTy
Definition: OMPIRBuilder.h:113
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const InsertPointTy &IP, const DebugLoc &DL)
Definition: OMPIRBuilder.h:155
llvm::CanonicalLoopInfo::getBodyIP
OpenMPIRBuilder::InsertPointTy getBodyIP() const
Return the insertion point for user code in the body.
Definition: OMPIRBuilder.h:1349
DebugLoc.h
llvm::OpenMPIRBuilder::MapperAllocas::Args
AllocaInst * Args
Definition: OMPIRBuilder.h:757
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:74
llvm::OpenMPIRBuilder::OpenMPIRBuilder
OpenMPIRBuilder(Module &M)
Create a new OpenMPIRBuilder operating on the given module M.
Definition: OMPIRBuilder.h:33
llvm::OpenMPIRBuilder::emitTaskwaitImpl
void emitTaskwaitImpl(const LocationDescription &Loc)
Generate a taskwait runtime call.
Definition: OMPIRBuilder.cpp:858
llvm::OpenMPIRBuilder::createAtomicUpdate
InsertPointTy createAtomicUpdate(const LocationDescription &Loc, Instruction *AllocIP, AtomicOpValue &X, Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp, bool IsXLHSInRHSPart)
Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X For complex Operations: X = ...
Definition: OMPIRBuilder.cpp:2675
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:2319
llvm::OpenMPIRBuilder::addAttributes
void addAttributes(omp::RuntimeFunction FnID, Function &Fn)
Add attributes known for FnID to Fn.
Definition: OMPIRBuilder.cpp:42
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:108
llvm::OpenMPIRBuilder::OutlineInfo::EntryBB
BasicBlock * EntryBB
Definition: OMPIRBuilder.h:718
llvm::OpenMPIRBuilder::Builder
IRBuilder Builder
The LLVM-IR Builder used to create IR.
Definition: OMPIRBuilder.h:705
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
llvm::omp::RuntimeFunction
RuntimeFunction
IDs for all omp runtime library (RTL) functions.
Definition: OMPConstants.h:54
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:887
llvm::CanonicalLoopInfo::getPreheader
BasicBlock * getPreheader() const
The preheader ensures that there is only a single edge entering the loop.
Definition: OMPIRBuilder.h:1293
llvm::OpenMPIRBuilder::createOffloadMaptypes
GlobalVariable * createOffloadMaptypes(SmallVectorImpl< uint64_t > &Mappings, std::string VarName)
Create the global variable holding the offload mappings information.
Definition: OMPIRBuilder.cpp:2482
llvm::OpenMPIRBuilder::AtomicOpValue::IsVolatile
bool IsVolatile
Definition: OMPIRBuilder.h:1119
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:893
llvm::OpenMPIRBuilder::MapperAllocas::ArgsBase
AllocaInst * ArgsBase
Definition: OMPIRBuilder.h:756
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::OpenMPIRBuilder::ReductionInfo::PrivateVariable
Value * PrivateVariable
Thread-private partial reduction variable.
Definition: OMPIRBuilder.h:512
llvm::OpenMPIRBuilder::OutlineInfo::getFunction
Function * getFunction() const
Return the function that contains the region to be outlined.
Definition: OMPIRBuilder.h:726
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
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:680
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:72
llvm::OpenMPIRBuilder::emitCancelationCheckImpl
void emitCancelationCheckImpl(Value *CancelFlag, omp::Directive CanceledDirective, FinalizeCallbackTy ExitCB={})
Generate control flow and cleanup for cancellation.
Definition: OMPIRBuilder.cpp:441
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:1318
llvm::OpenMPIRBuilder::createTargetInit
InsertPointTy createTargetInit(const LocationDescription &Loc, bool IsSPMD, bool RequiresFullRuntime)
The omp target interface.
Definition: OMPIRBuilder.cpp:2369
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:480
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::OpenMPIRBuilder::ReductionGenTy
function_ref< InsertPointTy(InsertPointTy, Value *, Value *, Value *&)> ReductionGenTy
Functions used to generate reductions.
Definition: OMPIRBuilder.h:493
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::OpenMPIRBuilder::LocationDescription::DL
DebugLoc DL
Definition: OMPIRBuilder.h:158
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::OpenMPIRBuilder::getOrCreateRuntimeFunctionPtr
Function * getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID)
Definition: OMPIRBuilder.cpp:133
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::OpenMPIRBuilder::createMaster
InsertPointTy createMaster(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB)
Generator for '#omp master'.
Definition: OMPIRBuilder.cpp:1199
llvm::OpenMPIRBuilder::createFlush
void createFlush(const LocationDescription &Loc)
Generator for '#omp flush'.
Definition: OMPIRBuilder.cpp:852
llvm::OpenMPIRBuilder::OutlineInfo
Helper that contains information about regions we need to outline during finalization.
Definition: OMPIRBuilder.h:715
llvm::CanonicalLoopInfo
Class to represented the control flow structure of an OpenMP canonical loop.
Definition: OMPIRBuilder.h:1267
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
Cond
SmallVector< MachineOperand, 4 > Cond
Definition: BasicBlockSections.cpp:179
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
llvm::OpenMPIRBuilder::createOffloadMapnames
GlobalVariable * createOffloadMapnames(SmallVectorImpl< llvm::Constant * > &Names, std::string VarName)
Create the global variable holding the offload names information.
Definition: OMPIRBuilder.cpp:2862
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::OpenMPIRBuilder::MapperAllocas::ArgSizes
AllocaInst * ArgSizes
Definition: OMPIRBuilder.h:758
llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCB
PostOutlineCBTy PostOutlineCB
Definition: OMPIRBuilder.h:717
llvm::OpenMPIRBuilder::addOutlineInfo
void addOutlineInfo(OutlineInfo &&OI)
Add a new region that will be outlined later.
Definition: OMPIRBuilder.h:737
llvm::OpenMPIRBuilder::createMasked
InsertPointTy createMasked(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, Value *Filter)
Generator for '#omp masked'.
Definition: OMPIRBuilder.cpp:1223
llvm::OpenMPIRBuilder::updateToLocation
bool updateToLocation(const LocationDescription &Loc)
Update the internal location to Loc.
Definition: OMPIRBuilder.h:611
llvm::OpenMPIRBuilder::FinalizationStack
SmallVector< FinalizationInfo, 8 > FinalizationStack
The finalization stack made up of finalize callbacks currently in-flight, wrapped into FinalizationIn...
Definition: OMPIRBuilder.h:676
llvm::BasicBlock::front
const Instruction & front() const
Definition: BasicBlock.h:308
llvm::CanonicalLoopInfo::getExit
BasicBlock * getExit() const
Reaching the exit indicates no more iterations are being executed.
Definition: OMPIRBuilder.h:1314
llvm::OpenMPIRBuilder::createStaticWorkshareLoop
CanonicalLoopInfo * createStaticWorkshareLoop(const LocationDescription &Loc, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, bool NeedsBarrier, Value *Chunk=nullptr)
Modifies the canonical loop to be a statically-scheduled workshare loop.
Definition: OMPIRBuilder.cpp:1447
llvm::OpenMPIRBuilder::LoopInfos
std::forward_list< CanonicalLoopInfo > LoopInfos
Collection of owned canonical loop objects that eventually need to be free'd.
Definition: OMPIRBuilder.h:734
llvm::OpenMPIRBuilder::createTaskwait
void createTaskwait(const LocationDescription &Loc)
Generator for '#omp taskwait'.
Definition: OMPIRBuilder.cpp:870
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::OpenMPIRBuilder::ReductionInfo::ReductionGen
ReductionGenTy ReductionGen
Callback for generating the reduction body.
Definition: OMPIRBuilder.h:517
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
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:2642
llvm::OpenMPIRBuilder::createCancel
InsertPointTy createCancel(const LocationDescription &Loc, Value *IfCondition, omp::Directive CanceledDirective)
Generator for '#omp cancel'.
Definition: OMPIRBuilder.cpp:391
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCBTy
std::function< void(Function &)> PostOutlineCBTy
Definition: OMPIRBuilder.h:716
llvm::CanonicalLoopInfo::getHeader
BasicBlock * getHeader() const
The header is the entry for each iteration.
Definition: OMPIRBuilder.h:1297
llvm::OpenMPIRBuilder::getOrCreateSrcLocStr
Constant * getOrCreateSrcLocStr(StringRef LocStr)
Return the (LLVM-IR) string describing the source location LocStr.
Definition: OMPIRBuilder.cpp:272
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:2416
llvm::OpenMPIRBuilder::ReductionInfo
Information about an OpenMP reduction.
Definition: OMPIRBuilder.h:502
llvm::IRBuilderBase::saveIP
InsertPoint saveIP() const
Returns the current insert point.
Definition: IRBuilder.h:271
llvm::OpenMPIRBuilder::initialize
void initialize()
Initialize the internal state, this will put structures types and potentially other helpers into the ...
Definition: OMPIRBuilder.cpp:140
llvm::CanonicalLoopInfo::getLatch
BasicBlock * getLatch() const
Reaching the latch indicates the end of the loop body code.
Definition: OMPIRBuilder.h:1311
llvm::OpenMPIRBuilder::FinalizationInfo
Definition: OMPIRBuilder.h:65
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:146
llvm::Type::getPointerElementType
Type * getPointerElementType() const
Definition: Type.h:380
llvm::CanonicalLoopInfo::getIndVarType
Type * getIndVarType() const
Return the type of the induction variable (and the trip count).
Definition: OMPIRBuilder.h:1341
llvm::OpenMPIRBuilder::SrcLocStrMap
StringMap< Constant * > SrcLocStrMap
Map to remember source location strings.
Definition: OMPIRBuilder.h:708
llvm::OpenMPIRBuilder::emitBarrierImpl
InsertPointTy emitBarrierImpl(const LocationDescription &Loc, omp::Directive DK, bool ForceSimpleCall, bool CheckCancelFlag)
Generate a barrier runtime call.
Definition: OMPIRBuilder.cpp:344
llvm::OpenMPIRBuilder::InternalVars
StringMap< AssertingVH< Constant >, BumpPtrAllocator > InternalVars
An ordered map of auto-generated variables to their unique names.
Definition: OMPIRBuilder.h:744
llvm::FunctionCallee
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:164
llvm::SmallVectorImpl< BasicBlock * >
llvm::CanonicalLoopInfo::getTripCount
Value * getTripCount() const
Returns the llvm::Value containing the number of loop iterations.
Definition: OMPIRBuilder.h:1326
llvm::SmallPtrSetImpl
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:343
llvm::OpenMPIRBuilder::emitFlush
void emitFlush(const LocationDescription &Loc)
Generate a flush runtime call.
Definition: OMPIRBuilder.cpp:844
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1475
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:2896
llvm::OpenMPIRBuilder::MapperAllocas
Definition: OMPIRBuilder.h:755
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:62
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::OpenMPIRBuilder::createSingle
InsertPointTy createSingle(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, llvm::Value *DidIt)
Generator for '#omp single'.
Definition: OMPIRBuilder.cpp:2069
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:2269
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:2048
llvm::omp::OMPScheduleType
OMPScheduleType
Definition: OMPConstants.h:113
llvm::OpenMPIRBuilder::getOrCreateRuntimeFunction
FunctionCallee getOrCreateRuntimeFunction(Module &M, omp::RuntimeFunction FnID)
Return the function declaration for the runtime function with FnID.
Definition: OMPIRBuilder.cpp:75
llvm::OpenMPIRBuilder::ReductionInfo::AtomicReductionGen
AtomicReductionGenTy AtomicReductionGen
Callback for generating the atomic reduction body, may be null.
Definition: OMPIRBuilder.h:523
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:1306
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::OpenMPIRBuilder::LocationDescription::IP
InsertPointTy IP
Definition: OMPIRBuilder.h:157