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  void finalize(Function *Fn = nullptr);
45 
46  /// Add attributes known for \p FnID to \p Fn.
48 
49  /// Type used throughout for insertion points.
51 
52  /// Callback type for variable finalization (think destructors).
53  ///
54  /// \param CodeGenIP is the insertion point at which the finalization code
55  /// should be placed.
56  ///
57  /// A finalize callback knows about all objects that need finalization, e.g.
58  /// destruction, when the scope of the currently generated construct is left
59  /// at the time, and location, the callback is invoked.
61 
63  /// The finalization callback provided by the last in-flight invocation of
64  /// createXXXX for the directive of kind DK.
66 
67  /// The directive kind of the innermost directive that has an associated
68  /// region which might require finalization when it is left.
69  omp::Directive DK;
70 
71  /// Flag to indicate if the directive is cancellable.
73  };
74 
75  /// Push a finalization callback on the finalization stack.
76  ///
77  /// NOTE: Temporary solution until Clang CG is gone.
79  FinalizationStack.push_back(FI);
80  }
81 
82  /// Pop the last finalization callback from the finalization stack.
83  ///
84  /// NOTE: Temporary solution until Clang CG is gone.
85  void popFinalizationCB() { FinalizationStack.pop_back(); }
86 
87  /// Callback type for body (=inner region) code generation
88  ///
89  /// The callback takes code locations as arguments, each describing a
90  /// location at which code might need to be generated or a location that is
91  /// the target of control transfer.
92  ///
93  /// \param AllocaIP is the insertion point at which new alloca instructions
94  /// should be placed.
95  /// \param CodeGenIP is the insertion point at which the body code should be
96  /// placed.
97  /// \param ContinuationBB is the basic block target to leave the body.
98  ///
99  /// Note that all blocks pointed to by the arguments have terminators.
100  using BodyGenCallbackTy =
101  function_ref<void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
102  BasicBlock &ContinuationBB)>;
103 
104  // This is created primarily for sections construct as llvm::function_ref
105  // (BodyGenCallbackTy) is not storable (as described in the comments of
106  // function_ref class - function_ref contains non-ownable reference
107  // to the callable.
109  std::function<void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
110  BasicBlock &ContinuationBB)>;
111 
112  /// Callback type for loop body code generation.
113  ///
114  /// \param CodeGenIP is the insertion point where the loop's body code must be
115  /// placed. This will be a dedicated BasicBlock with a
116  /// conditional branch from the loop condition check and
117  /// terminated with an unconditional branch to the loop
118  /// latch.
119  /// \param IndVar is the induction variable usable at the insertion point.
120  using LoopBodyGenCallbackTy =
121  function_ref<void(InsertPointTy CodeGenIP, Value *IndVar)>;
122 
123  /// Callback type for variable privatization (think copy & default
124  /// constructor).
125  ///
126  /// \param AllocaIP is the insertion point at which new alloca instructions
127  /// should be placed.
128  /// \param CodeGenIP is the insertion point at which the privatization code
129  /// should be placed.
130  /// \param Original The value being copied/created, should not be used in the
131  /// generated IR.
132  /// \param Inner The equivalent of \p Original that should be used in the
133  /// generated IR; this is equal to \p Original if the value is
134  /// a pointer and can thus be passed directly, otherwise it is
135  /// an equivalent but different value.
136  /// \param ReplVal The replacement value, thus a copy or new created version
137  /// of \p Inner.
138  ///
139  /// \returns The new insertion point where code generation continues and
140  /// \p ReplVal the replacement value.
142  InsertPointTy AllocaIP, InsertPointTy CodeGenIP, Value &Original,
143  Value &Inner, Value *&ReplVal)>;
144 
145  /// Description of a LLVM-IR insertion point (IP) and a debug/source location
146  /// (filename, line, column, ...).
148  template <typename T, typename U>
150  : IP(IRB.saveIP()), DL(IRB.getCurrentDebugLocation()) {}
153  : IP(IP), DL(DL) {}
156  };
157 
158  /// Emitter methods for OpenMP directives.
159  ///
160  ///{
161 
162  /// Generator for '#omp barrier'
163  ///
164  /// \param Loc The location where the barrier directive was encountered.
165  /// \param DK The kind of directive that caused the barrier.
166  /// \param ForceSimpleCall Flag to force a simple (=non-cancellation) barrier.
167  /// \param CheckCancelFlag Flag to indicate a cancel barrier return value
168  /// should be checked and acted upon.
169  ///
170  /// \returns The insertion point after the barrier.
171  InsertPointTy createBarrier(const LocationDescription &Loc, omp::Directive DK,
172  bool ForceSimpleCall = false,
173  bool CheckCancelFlag = true);
174 
175  /// Generator for '#omp cancel'
176  ///
177  /// \param Loc The location where the directive was encountered.
178  /// \param IfCondition The evaluated 'if' clause expression, if any.
179  /// \param CanceledDirective The kind of directive that is cancled.
180  ///
181  /// \returns The insertion point after the barrier.
182  InsertPointTy createCancel(const LocationDescription &Loc, Value *IfCondition,
183  omp::Directive CanceledDirective);
184 
185  /// Generator for '#omp parallel'
186  ///
187  /// \param Loc The insert and source location description.
188  /// \param AllocaIP The insertion points to be used for alloca instructions.
189  /// \param BodyGenCB Callback that will generate the region code.
190  /// \param PrivCB Callback to copy a given variable (think copy constructor).
191  /// \param FiniCB Callback to finalize variable copies.
192  /// \param IfCondition The evaluated 'if' clause expression, if any.
193  /// \param NumThreads The evaluated 'num_threads' clause expression, if any.
194  /// \param ProcBind The value of the 'proc_bind' clause (see ProcBindKind).
195  /// \param IsCancellable Flag to indicate a cancellable parallel region.
196  ///
197  /// \returns The insertion position *after* the parallel.
199  createParallel(const LocationDescription &Loc, InsertPointTy AllocaIP,
200  BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
201  FinalizeCallbackTy FiniCB, Value *IfCondition,
202  Value *NumThreads, omp::ProcBindKind ProcBind,
203  bool IsCancellable);
204 
205  /// Generator for the control flow structure of an OpenMP canonical loop.
206  ///
207  /// This generator operates on the logical iteration space of the loop, i.e.
208  /// the caller only has to provide a loop trip count of the loop as defined by
209  /// base language semantics. The trip count is interpreted as an unsigned
210  /// integer. The induction variable passed to \p BodyGenCB will be of the same
211  /// type and run from 0 to \p TripCount - 1. It is up to the callback to
212  /// convert the logical iteration variable to the loop counter variable in the
213  /// loop body.
214  ///
215  /// \param Loc The insert and source location description. The insert
216  /// location can be between two instructions or the end of a
217  /// degenerate block (e.g. a BB under construction).
218  /// \param BodyGenCB Callback that will generate the loop body code.
219  /// \param TripCount Number of iterations the loop body is executed.
220  /// \param Name Base name used to derive BB and instruction names.
221  ///
222  /// \returns An object representing the created control flow structure which
223  /// can be used for loop-associated directives.
225  LoopBodyGenCallbackTy BodyGenCB,
226  Value *TripCount,
227  const Twine &Name = "loop");
228 
229  /// Generator for the control flow structure of an OpenMP canonical loop.
230  ///
231  /// Instead of a logical iteration space, this allows specifying user-defined
232  /// loop counter values using increment, upper- and lower bounds. To
233  /// disambiguate the terminology when counting downwards, instead of lower
234  /// bounds we use \p Start for the loop counter value in the first body
235  /// iteration.
236  ///
237  /// Consider the following limitations:
238  ///
239  /// * A loop counter space over all integer values of its bit-width cannot be
240  /// represented. E.g using uint8_t, its loop trip count of 256 cannot be
241  /// stored into an 8 bit integer):
242  ///
243  /// DO I = 0, 255, 1
244  ///
245  /// * Unsigned wrapping is only supported when wrapping only "once"; E.g.
246  /// effectively counting downwards:
247  ///
248  /// for (uint8_t i = 100u; i > 0; i += 127u)
249  ///
250  ///
251  /// TODO: May need to add additional parameters to represent:
252  ///
253  /// * Allow representing downcounting with unsigned integers.
254  ///
255  /// * Sign of the step and the comparison operator might disagree:
256  ///
257  /// for (int i = 0; i < 42; i -= 1u)
258  ///
259  //
260  /// \param Loc The insert and source location description.
261  /// \param BodyGenCB Callback that will generate the loop body code.
262  /// \param Start Value of the loop counter for the first iterations.
263  /// \param Stop Loop counter values past this will stop the loop.
264  /// \param Step Loop counter increment after each iteration; negative
265  /// means counting down.
266  /// \param IsSigned Whether Start, Stop and Step are signed integers.
267  /// \param InclusiveStop Whether \p Stop itself is a valid value for the loop
268  /// counter.
269  /// \param ComputeIP Insertion point for instructions computing the trip
270  /// count. Can be used to ensure the trip count is available
271  /// at the outermost loop of a loop nest. If not set,
272  /// defaults to the preheader of the generated loop.
273  /// \param Name Base name used to derive BB and instruction names.
274  ///
275  /// \returns An object representing the created control flow structure which
276  /// can be used for loop-associated directives.
278  LoopBodyGenCallbackTy BodyGenCB,
279  Value *Start, Value *Stop, Value *Step,
280  bool IsSigned, bool InclusiveStop,
281  InsertPointTy ComputeIP = {},
282  const Twine &Name = "loop");
283 
284  /// Collapse a loop nest into a single loop.
285  ///
286  /// Merges loops of a loop nest into a single CanonicalLoopNest representation
287  /// that has the same number of innermost loop iterations as the origin loop
288  /// nest. The induction variables of the input loops are derived from the
289  /// collapsed loop's induction variable. This is intended to be used to
290  /// implement OpenMP's collapse clause. Before applying a directive,
291  /// collapseLoops normalizes a loop nest to contain only a single loop and the
292  /// directive's implementation does not need to handle multiple loops itself.
293  /// This does not remove the need to handle all loop nest handling by
294  /// directives, such as the ordered(<n>) clause or the simd schedule-clause
295  /// modifier of the worksharing-loop directive.
296  ///
297  /// Example:
298  /// \code
299  /// for (int i = 0; i < 7; ++i) // Canonical loop "i"
300  /// for (int j = 0; j < 9; ++j) // Canonical loop "j"
301  /// body(i, j);
302  /// \endcode
303  ///
304  /// After collapsing with Loops={i,j}, the loop is changed to
305  /// \code
306  /// for (int ij = 0; ij < 63; ++ij) {
307  /// int i = ij / 9;
308  /// int j = ij % 9;
309  /// body(i, j);
310  /// }
311  /// \endcode
312  ///
313  /// In the current implementation, the following limitations apply:
314  ///
315  /// * All input loops have an induction variable of the same type.
316  ///
317  /// * The collapsed loop will have the same trip count integer type as the
318  /// input loops. Therefore it is possible that the collapsed loop cannot
319  /// represent all iterations of the input loops. For instance, assuming a
320  /// 32 bit integer type, and two input loops both iterating 2^16 times, the
321  /// theoretical trip count of the collapsed loop would be 2^32 iteration,
322  /// which cannot be represented in an 32-bit integer. Behavior is undefined
323  /// in this case.
324  ///
325  /// * The trip counts of every input loop must be available at \p ComputeIP.
326  /// Non-rectangular loops are not yet supported.
327  ///
328  /// * At each nest level, code between a surrounding loop and its nested loop
329  /// is hoisted into the loop body, and such code will be executed more
330  /// often than before collapsing (or not at all if any inner loop iteration
331  /// has a trip count of 0). This is permitted by the OpenMP specification.
332  ///
333  /// \param DL Debug location for instructions added for collapsing,
334  /// such as instructions to compute/derive the input loop's
335  /// induction variables.
336  /// \param Loops Loops in the loop nest to collapse. Loops are specified
337  /// from outermost-to-innermost and every control flow of a
338  /// loop's body must pass through its directly nested loop.
339  /// \param ComputeIP Where additional instruction that compute the collapsed
340  /// trip count. If not set, defaults to before the generated
341  /// loop.
342  ///
343  /// \returns The CanonicalLoopInfo object representing the collapsed loop.
346  InsertPointTy ComputeIP);
347 
348  /// Modifies the canonical loop to be a statically-scheduled workshare loop.
349  ///
350  /// This takes a \p LoopInfo representing a canonical loop, such as the one
351  /// created by \p createCanonicalLoop and emits additional instructions to
352  /// turn it into a workshare loop. In particular, it calls to an OpenMP
353  /// runtime function in the preheader to obtain the loop bounds to be used in
354  /// the current thread, updates the relevant instructions in the canonical
355  /// loop and calls to an OpenMP runtime finalization function after the loop.
356  ///
357  /// TODO: Workshare loops with static scheduling may contain up to two loops
358  /// that fulfill the requirements of an OpenMP canonical loop. One for
359  /// iterating over all iterations of a chunk and another one for iterating
360  /// over all chunks that are executed on the same thread. Returning
361  /// CanonicalLoopInfo objects representing them may eventually be useful for
362  /// the apply clause planned in OpenMP 6.0, but currently whether these are
363  /// canonical loops is irrelevant.
364  ///
365  /// \param DL Debug location for instructions added for the
366  /// workshare-loop construct itself.
367  /// \param CLI A descriptor of the canonical loop to workshare.
368  /// \param AllocaIP An insertion point for Alloca instructions usable in the
369  /// preheader of the loop.
370  /// \param NeedsBarrier Indicates whether a barrier must be inserted after
371  /// the loop.
372  /// \param Chunk The size of loop chunk considered as a unit when
373  /// scheduling. If \p nullptr, defaults to 1.
374  ///
375  /// \returns Point where to insert code after the workshare construct.
377  InsertPointTy AllocaIP,
378  bool NeedsBarrier,
379  Value *Chunk = nullptr);
380 
381  /// Modifies the canonical loop to be a dynamically-scheduled workshare loop.
382  ///
383  /// This takes a \p LoopInfo representing a canonical loop, such as the one
384  /// created by \p createCanonicalLoop and emits additional instructions to
385  /// turn it into a workshare loop. In particular, it calls to an OpenMP
386  /// runtime function in the preheader to obtain, and then in each iteration
387  /// to update the loop counter.
388  ///
389  /// \param DL Debug location for instructions added for the
390  /// workshare-loop construct itself.
391  /// \param CLI A descriptor of the canonical loop to workshare.
392  /// \param AllocaIP An insertion point for Alloca instructions usable in the
393  /// preheader of the loop.
394  /// \param SchedType Type of scheduling to be passed to the init function.
395  /// \param NeedsBarrier Indicates whether a barrier must be insterted after
396  /// the loop.
397  /// \param Chunk The size of loop chunk considered as a unit when
398  /// scheduling. If \p nullptr, defaults to 1.
399  ///
400  /// \returns Point where to insert code after the workshare construct.
402  InsertPointTy AllocaIP,
403  omp::OMPScheduleType SchedType,
404  bool NeedsBarrier,
405  Value *Chunk = nullptr);
406 
407  /// Modifies the canonical loop to be a workshare loop.
408  ///
409  /// This takes a \p LoopInfo representing a canonical loop, such as the one
410  /// created by \p createCanonicalLoop and emits additional instructions to
411  /// turn it into a workshare loop. In particular, it calls to an OpenMP
412  /// runtime function in the preheader to obtain the loop bounds to be used in
413  /// the current thread, updates the relevant instructions in the canonical
414  /// loop and calls to an OpenMP runtime finalization function after the loop.
415  ///
416  /// \param DL Debug location for instructions added for the
417  /// workshare-loop construct itself.
418  /// \param CLI A descriptor of the canonical loop to workshare.
419  /// \param AllocaIP An insertion point for Alloca instructions usable in the
420  /// preheader of the loop.
421  /// \param NeedsBarrier Indicates whether a barrier must be insterted after
422  /// the loop.
423  ///
424  /// \returns Point where to insert code after the workshare construct.
426  InsertPointTy AllocaIP, bool NeedsBarrier);
427 
428  /// Tile a loop nest.
429  ///
430  /// Tiles the loops of \p Loops by the tile sizes in \p TileSizes. Loops in
431  /// \p/ Loops must be perfectly nested, from outermost to innermost loop
432  /// (i.e. Loops.front() is the outermost loop). The trip count llvm::Value
433  /// of every loop and every tile sizes must be usable in the outermost
434  /// loop's preheader. This implies that the loop nest is rectangular.
435  ///
436  /// Example:
437  /// \code
438  /// for (int i = 0; i < 15; ++i) // Canonical loop "i"
439  /// for (int j = 0; j < 14; ++j) // Canonical loop "j"
440  /// body(i, j);
441  /// \endcode
442  ///
443  /// After tiling with Loops={i,j} and TileSizes={5,7}, the loop is changed to
444  /// \code
445  /// for (int i1 = 0; i1 < 3; ++i1)
446  /// for (int j1 = 0; j1 < 2; ++j1)
447  /// for (int i2 = 0; i2 < 5; ++i2)
448  /// for (int j2 = 0; j2 < 7; ++j2)
449  /// body(i1*3+i2, j1*3+j2);
450  /// \endcode
451  ///
452  /// The returned vector are the loops {i1,j1,i2,j2}. The loops i1 and j1 are
453  /// referred to the floor, and the loops i2 and j2 are the tiles. Tiling also
454  /// handles non-constant trip counts, non-constant tile sizes and trip counts
455  /// that are not multiples of the tile size. In the latter case the tile loop
456  /// of the last floor-loop iteration will have fewer iterations than specified
457  /// as its tile size.
458  ///
459  ///
460  /// @param DL Debug location for instructions added by tiling, for
461  /// instance the floor- and tile trip count computation.
462  /// @param Loops Loops to tile. The CanonicalLoopInfo objects are
463  /// invalidated by this method, i.e. should not used after
464  /// tiling.
465  /// @param TileSizes For each loop in \p Loops, the tile size for that
466  /// dimensions.
467  ///
468  /// \returns A list of generated loops. Contains twice as many loops as the
469  /// input loop nest; the first half are the floor loops and the
470  /// second half are the tile loops.
471  std::vector<CanonicalLoopInfo *>
473  ArrayRef<Value *> TileSizes);
474 
475  /// Fully unroll a loop.
476  ///
477  /// Instead of unrolling the loop immediately (and duplicating its body
478  /// instructions), it is deferred to LLVM's LoopUnrollPass by adding loop
479  /// metadata.
480  ///
481  /// \param DL Debug location for instructions added by unrolling.
482  /// \param Loop The loop to unroll. The loop will be invalidated.
484 
485  /// Fully or partially unroll a loop. How the loop is unrolled is determined
486  /// using LLVM's LoopUnrollPass.
487  ///
488  /// \param DL Debug location for instructions added by unrolling.
489  /// \param Loop The loop to unroll. The loop will be invalidated.
491 
492  /// Partially unroll a loop.
493  ///
494  /// The CanonicalLoopInfo of the unrolled loop for use with chained
495  /// loop-associated directive can be requested using \p UnrolledCLI. Not
496  /// needing the CanonicalLoopInfo allows more efficient code generation by
497  /// deferring the actual unrolling to the LoopUnrollPass using loop metadata.
498  /// A loop-associated directive applied to the unrolled loop needs to know the
499  /// new trip count which means that if using a heuristically determined unroll
500  /// factor (\p Factor == 0), that factor must be computed immediately. We are
501  /// using the same logic as the LoopUnrollPass to derived the unroll factor,
502  /// but which assumes that some canonicalization has taken place (e.g.
503  /// Mem2Reg, LICM, GVN, Inlining, etc.). That is, the heuristic will perform
504  /// better when the unrolled loop's CanonicalLoopInfo is not needed.
505  ///
506  /// \param DL Debug location for instructions added by unrolling.
507  /// \param Loop The loop to unroll. The loop will be invalidated.
508  /// \param Factor The factor to unroll the loop by. A factor of 0
509  /// indicates that a heuristic should be used to determine
510  /// the unroll-factor.
511  /// \param UnrolledCLI If non-null, receives the CanonicalLoopInfo of the
512  /// partially unrolled loop. Otherwise, uses loop metadata
513  /// to defer unrolling to the LoopUnrollPass.
514  void unrollLoopPartial(DebugLoc DL, CanonicalLoopInfo *Loop, int32_t Factor,
515  CanonicalLoopInfo **UnrolledCLI);
516 
517  /// Add metadata to simd-ize a loop.
518  ///
519  /// \param DL Debug location for instructions added by unrolling.
520  /// \param Loop The loop to simd-ize.
522 
523  /// Generator for '#omp flush'
524  ///
525  /// \param Loc The location where the flush directive was encountered
526  void createFlush(const LocationDescription &Loc);
527 
528  /// Generator for '#omp taskwait'
529  ///
530  /// \param Loc The location where the taskwait directive was encountered.
531  void createTaskwait(const LocationDescription &Loc);
532 
533  /// Generator for '#omp taskyield'
534  ///
535  /// \param Loc The location where the taskyield directive was encountered.
536  void createTaskyield(const LocationDescription &Loc);
537 
538  /// Functions used to generate reductions. Such functions take two Values
539  /// representing LHS and RHS of the reduction, respectively, and a reference
540  /// to the value that is updated to refer to the reduction result.
541  using ReductionGenTy =
543 
544  /// Functions used to generate atomic reductions. Such functions take two
545  /// Values representing pointers to LHS and RHS of the reduction, as well as
546  /// the element type of these pointers. They are expected to atomically
547  /// update the LHS to the reduced value.
548  using AtomicReductionGenTy =
550 
551  /// Information about an OpenMP reduction.
552  struct ReductionInfo {
559  assert(cast<PointerType>(Variable->getType())
560  ->isOpaqueOrPointeeTypeMatches(ElementType) && "Invalid elem type");
561  }
562 
563  /// Reduction element type, must match pointee type of variable.
565 
566  /// Reduction variable of pointer type.
568 
569  /// Thread-private partial reduction variable.
571 
572  /// Callback for generating the reduction body. The IR produced by this will
573  /// be used to combine two values in a thread-safe context, e.g., under
574  /// lock or within the same thread, and therefore need not be atomic.
576 
577  /// Callback for generating the atomic reduction body, may be null. The IR
578  /// produced by this will be used to atomically combine two values during
579  /// reduction. If null, the implementation will use the non-atomic version
580  /// along with the appropriate synchronization mechanisms.
582  };
583 
584  // TODO: provide atomic and non-atomic reduction generators for reduction
585  // operators defined by the OpenMP specification.
586 
587  /// Generator for '#omp reduction'.
588  ///
589  /// Emits the IR instructing the runtime to perform the specific kind of
590  /// reductions. Expects reduction variables to have been privatized and
591  /// initialized to reduction-neutral values separately. Emits the calls to
592  /// runtime functions as well as the reduction function and the basic blocks
593  /// performing the reduction atomically and non-atomically.
594  ///
595  /// The code emitted for the following:
596  ///
597  /// \code
598  /// type var_1;
599  /// type var_2;
600  /// #pragma omp <directive> reduction(reduction-op:var_1,var_2)
601  /// /* body */;
602  /// \endcode
603  ///
604  /// corresponds to the following sketch.
605  ///
606  /// \code
607  /// void _outlined_par() {
608  /// // N is the number of different reductions.
609  /// void *red_array[] = {privatized_var_1, privatized_var_2, ...};
610  /// switch(__kmpc_reduce(..., N, /*size of data in red array*/, red_array,
611  /// _omp_reduction_func,
612  /// _gomp_critical_user.reduction.var)) {
613  /// case 1: {
614  /// var_1 = var_1 <reduction-op> privatized_var_1;
615  /// var_2 = var_2 <reduction-op> privatized_var_2;
616  /// // ...
617  /// __kmpc_end_reduce(...);
618  /// break;
619  /// }
620  /// case 2: {
621  /// _Atomic<ReductionOp>(var_1, privatized_var_1);
622  /// _Atomic<ReductionOp>(var_2, privatized_var_2);
623  /// // ...
624  /// break;
625  /// }
626  /// default: break;
627  /// }
628  /// }
629  ///
630  /// void _omp_reduction_func(void **lhs, void **rhs) {
631  /// *(type *)lhs[0] = *(type *)lhs[0] <reduction-op> *(type *)rhs[0];
632  /// *(type *)lhs[1] = *(type *)lhs[1] <reduction-op> *(type *)rhs[1];
633  /// // ...
634  /// }
635  /// \endcode
636  ///
637  /// \param Loc The location where the reduction was
638  /// encountered. Must be within the associate
639  /// directive and after the last local access to the
640  /// reduction variables.
641  /// \param AllocaIP An insertion point suitable for allocas usable
642  /// in reductions.
643  /// \param ReductionInfos A list of info on each reduction variable.
644  /// \param IsNoWait A flag set if the reduction is marked as nowait.
646  InsertPointTy AllocaIP,
647  ArrayRef<ReductionInfo> ReductionInfos,
648  bool IsNoWait = false);
649 
650  ///}
651 
652  /// Return the insertion point used by the underlying IRBuilder.
654 
655  /// Update the internal location to \p Loc.
657  Builder.restoreIP(Loc.IP);
659  return Loc.IP.getBlock() != nullptr;
660  }
661 
662  /// Return the function declaration for the runtime function with \p FnID.
664  omp::RuntimeFunction FnID);
665 
667 
668  /// Return the (LLVM-IR) string describing the source location \p LocStr.
669  Constant *getOrCreateSrcLocStr(StringRef LocStr, uint32_t &SrcLocStrSize);
670 
671  /// Return the (LLVM-IR) string describing the default source location.
673 
674  /// Return the (LLVM-IR) string describing the source location identified by
675  /// the arguments.
676  Constant *getOrCreateSrcLocStr(StringRef FunctionName, StringRef FileName,
677  unsigned Line, unsigned Column,
678  uint32_t &SrcLocStrSize);
679 
680  /// Return the (LLVM-IR) string describing the DebugLoc \p DL. Use \p F as
681  /// fallback if \p DL does not specify the function name.
683  Function *F = nullptr);
684 
685  /// Return the (LLVM-IR) string describing the source location \p Loc.
686  Constant *getOrCreateSrcLocStr(const LocationDescription &Loc,
687  uint32_t &SrcLocStrSize);
688 
689  /// Return an ident_t* encoding the source location \p SrcLocStr and \p Flags.
690  /// TODO: Create a enum class for the Reserve2Flags
691  Constant *getOrCreateIdent(Constant *SrcLocStr, uint32_t SrcLocStrSize,
692  omp::IdentFlag Flags = omp::IdentFlag(0),
693  unsigned Reserve2Flags = 0);
694 
695  /// Create a hidden global flag \p Name in the module with initial value \p
696  /// Value.
698 
699  /// Generate control flow and cleanup for cancellation.
700  ///
701  /// \param CancelFlag Flag indicating if the cancellation is performed.
702  /// \param CanceledDirective The kind of directive that is cancled.
703  /// \param ExitCB Extra code to be generated in the exit block.
704  void emitCancelationCheckImpl(Value *CancelFlag,
705  omp::Directive CanceledDirective,
706  FinalizeCallbackTy ExitCB = {});
707 
708  /// Generate a barrier runtime call.
709  ///
710  /// \param Loc The location at which the request originated and is fulfilled.
711  /// \param DK The directive which caused the barrier
712  /// \param ForceSimpleCall Flag to force a simple (=non-cancellation) barrier.
713  /// \param CheckCancelFlag Flag to indicate a cancel barrier return value
714  /// should be checked and acted upon.
715  ///
716  /// \returns The insertion point after the barrier.
717  InsertPointTy emitBarrierImpl(const LocationDescription &Loc,
718  omp::Directive DK, bool ForceSimpleCall,
719  bool CheckCancelFlag);
720 
721  /// Generate a flush runtime call.
722  ///
723  /// \param Loc The location at which the request originated and is fulfilled.
724  void emitFlush(const LocationDescription &Loc);
725 
726  /// The finalization stack made up of finalize callbacks currently in-flight,
727  /// wrapped into FinalizationInfo objects that reference also the finalization
728  /// target block and the kind of cancellable directive.
730 
731  /// Return true if the last entry in the finalization stack is of kind \p DK
732  /// and cancellable.
733  bool isLastFinalizationInfoCancellable(omp::Directive DK) {
734  return !FinalizationStack.empty() &&
735  FinalizationStack.back().IsCancellable &&
736  FinalizationStack.back().DK == DK;
737  }
738 
739  /// Generate a taskwait runtime call.
740  ///
741  /// \param Loc The location at which the request originated and is fulfilled.
742  void emitTaskwaitImpl(const LocationDescription &Loc);
743 
744  /// Generate a taskyield runtime call.
745  ///
746  /// \param Loc The location at which the request originated and is fulfilled.
747  void emitTaskyieldImpl(const LocationDescription &Loc);
748 
749  /// Return the current thread ID.
750  ///
751  /// \param Ident The ident (ident_t*) describing the query origin.
753 
754  /// The underlying LLVM-IR module
756 
757  /// The LLVM-IR Builder used to create IR.
759 
760  /// Map to remember source location strings
762 
763  /// Map to remember existing ident_t*.
765 
766  /// Helper that contains information about regions we need to outline
767  /// during finalization.
768  struct OutlineInfo {
773 
774  /// Collect all blocks in between EntryBB and ExitBB in both the given
775  /// vector and set.
777  SmallVectorImpl<BasicBlock *> &BlockVector);
778 
779  /// Return the function that contains the region to be outlined.
780  Function *getFunction() const { return EntryBB->getParent(); }
781  };
782 
783  /// Collection of regions that need to be outlined during finalization.
785 
786  /// Collection of owned canonical loop objects that eventually need to be
787  /// free'd.
788  std::forward_list<CanonicalLoopInfo> LoopInfos;
789 
790  /// Add a new region that will be outlined later.
791  void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
792 
793  /// An ordered map of auto-generated variables to their unique names.
794  /// It stores variables with the following names: 1) ".gomp_critical_user_" +
795  /// <critical_section_name> + ".var" for "omp critical" directives; 2)
796  /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
797  /// variables.
799 
800  /// Create the global variable holding the offload mappings information.
802  std::string VarName);
803 
804  /// Create the global variable holding the offload names information.
807  std::string VarName);
808 
809  struct MapperAllocas {
810  AllocaInst *ArgsBase = nullptr;
811  AllocaInst *Args = nullptr;
812  AllocaInst *ArgSizes = nullptr;
813  };
814 
815  /// Create the allocas instruction used in call to mapper functions.
817  InsertPointTy AllocaIP, unsigned NumOperands,
818  struct MapperAllocas &MapperAllocas);
819 
820  /// Create the call for the target mapper function.
821  /// \param Loc The source location description.
822  /// \param MapperFunc Function to be called.
823  /// \param SrcLocInfo Source location information global.
824  /// \param MaptypesArg The argument types.
825  /// \param MapnamesArg The argument names.
826  /// \param MapperAllocas The AllocaInst used for the call.
827  /// \param DeviceID Device ID for the call.
828  /// \param NumOperands Number of operands in the call.
829  void emitMapperCall(const LocationDescription &Loc, Function *MapperFunc,
830  Value *SrcLocInfo, Value *MaptypesArg, Value *MapnamesArg,
831  struct MapperAllocas &MapperAllocas, int64_t DeviceID,
832  unsigned NumOperands);
833 
834 public:
835  /// Generator for __kmpc_copyprivate
836  ///
837  /// \param Loc The source location description.
838  /// \param BufSize Number of elements in the buffer.
839  /// \param CpyBuf List of pointers to data to be copied.
840  /// \param CpyFn function to call for copying data.
841  /// \param DidIt flag variable; 1 for 'single' thread, 0 otherwise.
842  ///
843  /// \return The insertion position *after* the CopyPrivate call.
844 
846  llvm::Value *BufSize, llvm::Value *CpyBuf,
847  llvm::Value *CpyFn, llvm::Value *DidIt);
848 
849  /// Generator for '#omp single'
850  ///
851  /// \param Loc The source location description.
852  /// \param BodyGenCB Callback that will generate the region code.
853  /// \param FiniCB Callback to finalize variable copies.
854  /// \param DidIt Local variable used as a flag to indicate 'single' thread
855  ///
856  /// \returns The insertion position *after* the single call.
858  BodyGenCallbackTy BodyGenCB,
859  FinalizeCallbackTy FiniCB, llvm::Value *DidIt);
860 
861  /// Generator for '#omp master'
862  ///
863  /// \param Loc The insert and source location description.
864  /// \param BodyGenCB Callback that will generate the region code.
865  /// \param FiniCB Callback to finalize variable copies.
866  ///
867  /// \returns The insertion position *after* the master.
869  BodyGenCallbackTy BodyGenCB,
870  FinalizeCallbackTy FiniCB);
871 
872  /// Generator for '#omp masked'
873  ///
874  /// \param Loc The insert and source location description.
875  /// \param BodyGenCB Callback that will generate the region code.
876  /// \param FiniCB Callback to finialize variable copies.
877  ///
878  /// \returns The insertion position *after* the masked.
880  BodyGenCallbackTy BodyGenCB,
881  FinalizeCallbackTy FiniCB, Value *Filter);
882 
883  /// Generator for '#omp critical'
884  ///
885  /// \param Loc The insert and source location description.
886  /// \param BodyGenCB Callback that will generate the region body code.
887  /// \param FiniCB Callback to finalize variable copies.
888  /// \param CriticalName name of the lock used by the critical directive
889  /// \param HintInst Hint Instruction for hint clause associated with critical
890  ///
891  /// \returns The insertion position *after* the critical.
893  BodyGenCallbackTy BodyGenCB,
894  FinalizeCallbackTy FiniCB,
895  StringRef CriticalName, Value *HintInst);
896 
897  /// Generator for '#omp ordered depend (source | sink)'
898  ///
899  /// \param Loc The insert and source location description.
900  /// \param AllocaIP The insertion point to be used for alloca instructions.
901  /// \param NumLoops The number of loops in depend clause.
902  /// \param StoreValues The value will be stored in vector address.
903  /// \param Name The name of alloca instruction.
904  /// \param IsDependSource If true, depend source; otherwise, depend sink.
905  ///
906  /// \return The insertion position *after* the ordered.
908  InsertPointTy AllocaIP, unsigned NumLoops,
909  ArrayRef<llvm::Value *> StoreValues,
910  const Twine &Name, bool IsDependSource);
911 
912  /// Generator for '#omp ordered [threads | simd]'
913  ///
914  /// \param Loc The insert and source location description.
915  /// \param BodyGenCB Callback that will generate the region code.
916  /// \param FiniCB Callback to finalize variable copies.
917  /// \param IsThreads If true, with threads clause or without clause;
918  /// otherwise, with simd clause;
919  ///
920  /// \returns The insertion position *after* the ordered.
922  BodyGenCallbackTy BodyGenCB,
923  FinalizeCallbackTy FiniCB,
924  bool IsThreads);
925 
926  /// Generator for '#omp sections'
927  ///
928  /// \param Loc The insert and source location description.
929  /// \param AllocaIP The insertion points to be used for alloca instructions.
930  /// \param SectionCBs Callbacks that will generate body of each section.
931  /// \param PrivCB Callback to copy a given variable (think copy constructor).
932  /// \param FiniCB Callback to finalize variable copies.
933  /// \param IsCancellable Flag to indicate a cancellable parallel region.
934  /// \param IsNowait If true, barrier - to ensure all sections are executed
935  /// before moving forward will not be generated.
936  /// \returns The insertion position *after* the sections.
938  InsertPointTy AllocaIP,
940  PrivatizeCallbackTy PrivCB,
941  FinalizeCallbackTy FiniCB, bool IsCancellable,
942  bool IsNowait);
943 
944  /// Generator for '#omp section'
945  ///
946  /// \param Loc The insert and source location description.
947  /// \param BodyGenCB Callback that will generate the region body code.
948  /// \param FiniCB Callback to finalize variable copies.
949  /// \returns The insertion position *after* the section.
951  BodyGenCallbackTy BodyGenCB,
952  FinalizeCallbackTy FiniCB);
953 
954  /// Generate conditional branch and relevant BasicBlocks through which private
955  /// threads copy the 'copyin' variables from Master copy to threadprivate
956  /// copies.
957  ///
958  /// \param IP insertion block for copyin conditional
959  /// \param MasterVarPtr a pointer to the master variable
960  /// \param PrivateVarPtr a pointer to the threadprivate variable
961  /// \param IntPtrTy Pointer size type
962  /// \param BranchtoEnd Create a branch between the copyin.not.master blocks
963  // and copy.in.end block
964  ///
965  /// \returns The insertion point where copying operation to be emitted.
967  Value *PrivateAddr,
968  llvm::IntegerType *IntPtrTy,
969  bool BranchtoEnd = true);
970 
971  /// Create a runtime call for kmpc_Alloc
972  ///
973  /// \param Loc The insert and source location description.
974  /// \param Size Size of allocated memory space
975  /// \param Allocator Allocator information instruction
976  /// \param Name Name of call Instruction for OMP_alloc
977  ///
978  /// \returns CallInst to the OMP_Alloc call
980  Value *Allocator, std::string Name = "");
981 
982  /// Create a runtime call for kmpc_free
983  ///
984  /// \param Loc The insert and source location description.
985  /// \param Addr Address of memory space to be freed
986  /// \param Allocator Allocator information instruction
987  /// \param Name Name of call Instruction for OMP_Free
988  ///
989  /// \returns CallInst to the OMP_Free call
991  Value *Allocator, std::string Name = "");
992 
993  /// Create a runtime call for kmpc_threadprivate_cached
994  ///
995  /// \param Loc The insert and source location description.
996  /// \param Pointer pointer to data to be cached
997  /// \param Size size of data to be cached
998  /// \param Name Name of call Instruction for callinst
999  ///
1000  /// \returns CallInst to the thread private cache call.
1002  llvm::Value *Pointer,
1004  const llvm::Twine &Name = Twine(""));
1005 
1006  /// The `omp target` interface
1007  ///
1008  /// For more information about the usage of this interface,
1009  /// \see openmp/libomptarget/deviceRTLs/common/include/target.h
1010  ///
1011  ///{
1012 
1013  /// Create a runtime call for kmpc_target_init
1014  ///
1015  /// \param Loc The insert and source location description.
1016  /// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
1017  /// \param RequiresFullRuntime Indicate if a full device runtime is necessary.
1018  InsertPointTy createTargetInit(const LocationDescription &Loc, bool IsSPMD,
1019  bool RequiresFullRuntime);
1020 
1021  /// Create a runtime call for kmpc_target_deinit
1022  ///
1023  /// \param Loc The insert and source location description.
1024  /// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
1025  /// \param RequiresFullRuntime Indicate if a full device runtime is necessary.
1026  void createTargetDeinit(const LocationDescription &Loc, bool IsSPMD,
1027  bool RequiresFullRuntime);
1028 
1029  ///}
1030 
1031  /// Declarations for LLVM-IR types (simple, array, function and structure) are
1032  /// generated below. Their names are defined and used in OpenMPKinds.def. Here
1033  /// we provide the declarations, the initializeTypes function will provide the
1034  /// values.
1035  ///
1036  ///{
1037 #define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
1038 #define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
1039  ArrayType *VarName##Ty = nullptr; \
1040  PointerType *VarName##PtrTy = nullptr;
1041 #define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
1042  FunctionType *VarName = nullptr; \
1043  PointerType *VarName##Ptr = nullptr;
1044 #define OMP_STRUCT_TYPE(VarName, StrName, ...) \
1045  StructType *VarName = nullptr; \
1046  PointerType *VarName##Ptr = nullptr;
1047 #include "llvm/Frontend/OpenMP/OMPKinds.def"
1048 
1049  ///}
1050 
1051 private:
1052  /// Create all simple and struct types exposed by the runtime and remember
1053  /// the llvm::PointerTypes of them for easy access later.
1054  void initializeTypes(Module &M);
1055 
1056  /// Common interface for generating entry calls for OMP Directives.
1057  /// if the directive has a region/body, It will set the insertion
1058  /// point to the body
1059  ///
1060  /// \param OMPD Directive to generate entry blocks for
1061  /// \param EntryCall Call to the entry OMP Runtime Function
1062  /// \param ExitBB block where the region ends.
1063  /// \param Conditional indicate if the entry call result will be used
1064  /// to evaluate a conditional of whether a thread will execute
1065  /// body code or not.
1066  ///
1067  /// \return The insertion position in exit block
1068  InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD, Value *EntryCall,
1069  BasicBlock *ExitBB,
1070  bool Conditional = false);
1071 
1072  /// Common interface to finalize the region
1073  ///
1074  /// \param OMPD Directive to generate exiting code for
1075  /// \param FinIP Insertion point for emitting Finalization code and exit call
1076  /// \param ExitCall Call to the ending OMP Runtime Function
1077  /// \param HasFinalize indicate if the directive will require finalization
1078  /// and has a finalization callback in the stack that
1079  /// should be called.
1080  ///
1081  /// \return The insertion position in exit block
1082  InsertPointTy emitCommonDirectiveExit(omp::Directive OMPD,
1083  InsertPointTy FinIP,
1084  Instruction *ExitCall,
1085  bool HasFinalize = true);
1086 
1087  /// Common Interface to generate OMP inlined regions
1088  ///
1089  /// \param OMPD Directive to generate inlined region for
1090  /// \param EntryCall Call to the entry OMP Runtime Function
1091  /// \param ExitCall Call to the ending OMP Runtime Function
1092  /// \param BodyGenCB Body code generation callback.
1093  /// \param FiniCB Finalization Callback. Will be called when finalizing region
1094  /// \param Conditional indicate if the entry call result will be used
1095  /// to evaluate a conditional of whether a thread will execute
1096  /// body code or not.
1097  /// \param HasFinalize indicate if the directive will require finalization
1098  /// and has a finalization callback in the stack that
1099  /// should be called.
1100  /// \param IsCancellable if HasFinalize is set to true, indicate if the
1101  /// the directive should be cancellable.
1102  /// \return The insertion point after the region
1103 
1105  EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
1106  Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
1107  FinalizeCallbackTy FiniCB, bool Conditional = false,
1108  bool HasFinalize = true, bool IsCancellable = false);
1109 
1110  /// Get the platform-specific name separator.
1111  /// \param Parts different parts of the final name that needs separation
1112  /// \param FirstSeparator First separator used between the initial two
1113  /// parts of the name.
1114  /// \param Separator separator used between all of the rest consecutive
1115  /// parts of the name
1116  static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
1117  StringRef FirstSeparator,
1118  StringRef Separator);
1119 
1120  /// Gets (if variable with the given name already exist) or creates
1121  /// internal global variable with the specified Name. The created variable has
1122  /// linkage CommonLinkage by default and is initialized by null value.
1123  /// \param Ty Type of the global variable. If it is exist already the type
1124  /// must be the same.
1125  /// \param Name Name of the variable.
1126  Constant *getOrCreateOMPInternalVariable(Type *Ty, const Twine &Name,
1127  unsigned AddressSpace = 0);
1128 
1129  /// Returns corresponding lock object for the specified critical region
1130  /// name. If the lock object does not exist it is created, otherwise the
1131  /// reference to the existing copy is returned.
1132  /// \param CriticalName Name of the critical region.
1133  ///
1134  Value *getOMPCriticalRegionLock(StringRef CriticalName);
1135 
1136  /// Callback type for Atomic Expression update
1137  /// ex:
1138  /// \code{.cpp}
1139  /// unsigned x = 0;
1140  /// #pragma omp atomic update
1141  /// x = Expr(x_old); //Expr() is any legal operation
1142  /// \endcode
1143  ///
1144  /// \param XOld the value of the atomic memory address to use for update
1145  /// \param IRB reference to the IRBuilder to use
1146  ///
1147  /// \returns Value to update X to.
1148  using AtomicUpdateCallbackTy =
1149  const function_ref<Value *(Value *XOld, IRBuilder<> &IRB)>;
1150 
1151 private:
1152  enum AtomicKind { Read, Write, Update, Capture };
1153 
1154  /// Determine whether to emit flush or not
1155  ///
1156  /// \param Loc The insert and source location description.
1157  /// \param AO The required atomic ordering
1158  /// \param AK The OpenMP atomic operation kind used.
1159  ///
1160  /// \returns wether a flush was emitted or not
1161  bool checkAndEmitFlushAfterAtomic(const LocationDescription &Loc,
1162  AtomicOrdering AO, AtomicKind AK);
1163 
1164  /// Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X
1165  /// For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X)
1166  /// Only Scalar data types.
1167  ///
1168  /// \param AllocIP Instruction to create AllocaInst before.
1169  /// \param X The target atomic pointer to be updated
1170  /// \param Expr The value to update X with.
1171  /// \param AO Atomic ordering of the generated atomic
1172  /// instructions.
1173  /// \param RMWOp The binary operation used for update. If
1174  /// operation is not supported by atomicRMW,
1175  /// or belong to {FADD, FSUB, BAD_BINOP}.
1176  /// Then a `cmpExch` based atomic will be generated.
1177  /// \param UpdateOp Code generator for complex expressions that cannot be
1178  /// expressed through atomicrmw instruction.
1179  /// \param VolatileX true if \a X volatile?
1180  /// \param IsXBinopExpr true if \a X is Left H.S. in Right H.S. part of the
1181  /// update expression, false otherwise.
1182  /// (e.g. true for X = X BinOp Expr)
1183  ///
1184  /// \returns A pair of the old value of X before the update, and the value
1185  /// used for the update.
1186  std::pair<Value *, Value *> emitAtomicUpdate(Instruction *AllocIP, Value *X,
1187  Value *Expr, AtomicOrdering AO,
1188  AtomicRMWInst::BinOp RMWOp,
1189  AtomicUpdateCallbackTy &UpdateOp,
1190  bool VolatileX,
1191  bool IsXBinopExpr);
1192 
1193  /// Emit the binary op. described by \p RMWOp, using \p Src1 and \p Src2 .
1194  ///
1195  /// \Return The instruction
1196  Value *emitRMWOpAsInstruction(Value *Src1, Value *Src2,
1197  AtomicRMWInst::BinOp RMWOp);
1198 
1199 public:
1200  /// a struct to pack relevant information while generating atomic Ops
1201  struct AtomicOpValue {
1202  Value *Var = nullptr;
1203  bool IsSigned = false;
1204  bool IsVolatile = false;
1205  };
1206 
1207  /// Emit atomic Read for : V = X --- Only Scalar data types.
1208  ///
1209  /// \param Loc The insert and source location description.
1210  /// \param X The target pointer to be atomically read
1211  /// \param V Memory address where to store atomically read
1212  /// value
1213  /// \param AO Atomic ordering of the generated atomic
1214  /// instructions.
1215  ///
1216  /// \return Insertion point after generated atomic read IR.
1219  AtomicOrdering AO);
1220 
1221  /// Emit atomic write for : X = Expr --- Only Scalar data types.
1222  ///
1223  /// \param Loc The insert and source location description.
1224  /// \param X The target pointer to be atomically written to
1225  /// \param Expr The value to store.
1226  /// \param AO Atomic ordering of the generated atomic
1227  /// instructions.
1228  ///
1229  /// \return Insertion point after generated atomic Write IR.
1231  AtomicOpValue &X, Value *Expr,
1232  AtomicOrdering AO);
1233 
1234  /// Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X
1235  /// For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X)
1236  /// Only Scalar data types.
1237  ///
1238  /// \param Loc The insert and source location description.
1239  /// \param AllocIP Instruction to create AllocaInst before.
1240  /// \param X The target atomic pointer to be updated
1241  /// \param Expr The value to update X with.
1242  /// \param AO Atomic ordering of the generated atomic instructions.
1243  /// \param RMWOp The binary operation used for update. If operation
1244  /// is not supported by atomicRMW, or belong to
1245  /// {FADD, FSUB, BAD_BINOP}. Then a `cmpExch` based
1246  /// atomic will be generated.
1247  /// \param UpdateOp Code generator for complex expressions that cannot be
1248  /// expressed through atomicrmw instruction.
1249  /// \param IsXBinopExpr true if \a X is Left H.S. in Right H.S. part of the
1250  /// update expression, false otherwise.
1251  /// (e.g. true for X = X BinOp Expr)
1252  ///
1253  /// \return Insertion point after generated atomic update IR.
1255  Instruction *AllocIP, AtomicOpValue &X,
1256  Value *Expr, AtomicOrdering AO,
1257  AtomicRMWInst::BinOp RMWOp,
1258  AtomicUpdateCallbackTy &UpdateOp,
1259  bool IsXBinopExpr);
1260 
1261  /// Emit atomic update for constructs: --- Only Scalar data types
1262  /// V = X; X = X BinOp Expr ,
1263  /// X = X BinOp Expr; V = X,
1264  /// V = X; X = Expr BinOp X,
1265  /// X = Expr BinOp X; V = X,
1266  /// V = X; X = UpdateOp(X),
1267  /// X = UpdateOp(X); V = X,
1268  ///
1269  /// \param Loc The insert and source location description.
1270  /// \param AllocIP Instruction to create AllocaInst before.
1271  /// \param X The target atomic pointer to be updated
1272  /// \param V Memory address where to store captured value
1273  /// \param Expr The value to update X with.
1274  /// \param AO Atomic ordering of the generated atomic instructions
1275  /// \param RMWOp The binary operation used for update. If
1276  /// operation is not supported by atomicRMW, or belong to
1277  /// {FADD, FSUB, BAD_BINOP}. Then a cmpExch based
1278  /// atomic will be generated.
1279  /// \param UpdateOp Code generator for complex expressions that cannot be
1280  /// expressed through atomicrmw instruction.
1281  /// \param UpdateExpr true if X is an in place update of the form
1282  /// X = X BinOp Expr or X = Expr BinOp X
1283  /// \param IsXBinopExpr true if X is Left H.S. in Right H.S. part of the
1284  /// update expression, false otherwise.
1285  /// (e.g. true for X = X BinOp Expr)
1286  /// \param IsPostfixUpdate true if original value of 'x' must be stored in
1287  /// 'v', not an updated one.
1288  ///
1289  /// \return Insertion point after generated atomic capture IR.
1292  AtomicOpValue &X, AtomicOpValue &V, Value *Expr,
1294  AtomicUpdateCallbackTy &UpdateOp, bool UpdateExpr,
1295  bool IsPostfixUpdate, bool IsXBinopExpr);
1296 
1297  /// Create the control flow structure of a canonical OpenMP loop.
1298  ///
1299  /// The emitted loop will be disconnected, i.e. no edge to the loop's
1300  /// preheader and no terminator in the AfterBB. The OpenMPIRBuilder's
1301  /// IRBuilder location is not preserved.
1302  ///
1303  /// \param DL DebugLoc used for the instructions in the skeleton.
1304  /// \param TripCount Value to be used for the trip count.
1305  /// \param F Function in which to insert the BasicBlocks.
1306  /// \param PreInsertBefore Where to insert BBs that execute before the body,
1307  /// typically the body itself.
1308  /// \param PostInsertBefore Where to insert BBs that execute after the body.
1309  /// \param Name Base name used to derive BB
1310  /// and instruction names.
1311  ///
1312  /// \returns The CanonicalLoopInfo that represents the emitted loop.
1314  Function *F,
1315  BasicBlock *PreInsertBefore,
1316  BasicBlock *PostInsertBefore,
1317  const Twine &Name = {});
1318 };
1319 
1320 /// Class to represented the control flow structure of an OpenMP canonical loop.
1321 ///
1322 /// The control-flow structure is standardized for easy consumption by
1323 /// directives associated with loops. For instance, the worksharing-loop
1324 /// construct may change this control flow such that each loop iteration is
1325 /// executed on only one thread. The constraints of a canonical loop in brief
1326 /// are:
1327 ///
1328 /// * The number of loop iterations must have been computed before entering the
1329 /// loop.
1330 ///
1331 /// * Has an (unsigned) logical induction variable that starts at zero and
1332 /// increments by one.
1333 ///
1334 /// * The loop's CFG itself has no side-effects. The OpenMP specification
1335 /// itself allows side-effects, but the order in which they happen, including
1336 /// how often or whether at all, is unspecified. We expect that the frontend
1337 /// will emit those side-effect instructions somewhere (e.g. before the loop)
1338 /// such that the CanonicalLoopInfo itself can be side-effect free.
1339 ///
1340 /// Keep in mind that CanonicalLoopInfo is meant to only describe a repeated
1341 /// execution of a loop body that satifies these constraints. It does NOT
1342 /// represent arbitrary SESE regions that happen to contain a loop. Do not use
1343 /// CanonicalLoopInfo for such purposes.
1344 ///
1345 /// The control flow can be described as follows:
1346 ///
1347 /// Preheader
1348 /// |
1349 /// /-> Header
1350 /// | |
1351 /// | Cond---\
1352 /// | | |
1353 /// | Body |
1354 /// | | | |
1355 /// | <...> |
1356 /// | | | |
1357 /// \--Latch |
1358 /// |
1359 /// Exit
1360 /// |
1361 /// After
1362 ///
1363 /// The loop is thought to start at PreheaderIP (at the Preheader's terminator,
1364 /// including) and end at AfterIP (at the After's first instruction, excluding).
1365 /// That is, instructions in the Preheader and After blocks (except the
1366 /// Preheader's terminator) are out of CanonicalLoopInfo's control and may have
1367 /// side-effects. Typically, the Preheader is used to compute the loop's trip
1368 /// count. The instructions from BodyIP (at the Body block's first instruction,
1369 /// excluding) until the Latch are also considered outside CanonicalLoopInfo's
1370 /// control and thus can have side-effects. The body block is the single entry
1371 /// point into the loop body, which may contain arbitrary control flow as long
1372 /// as all control paths eventually branch to the Latch block.
1373 ///
1374 /// TODO: Consider adding another standardized BasicBlock between Body CFG and
1375 /// Latch to guarantee that there is only a single edge to the latch. It would
1376 /// make loop transformations easier to not needing to consider multiple
1377 /// predecessors of the latch (See redirectAllPredecessorsTo) and would give us
1378 /// an equivalant to PreheaderIP, AfterIP and BodyIP for inserting code that
1379 /// executes after each body iteration.
1380 ///
1381 /// There must be no loop-carried dependencies through llvm::Values. This is
1382 /// equivalant to that the Latch has no PHINode and the Header's only PHINode is
1383 /// for the induction variable.
1384 ///
1385 /// All code in Header, Cond, Latch and Exit (plus the terminator of the
1386 /// Preheader) are CanonicalLoopInfo's responsibility and their build-up checked
1387 /// by assertOK(). They are expected to not be modified unless explicitly
1388 /// modifying the CanonicalLoopInfo through a methods that applies a OpenMP
1389 /// loop-associated construct such as applyWorkshareLoop, tileLoops, unrollLoop,
1390 /// etc. These methods usually invalidate the CanonicalLoopInfo and re-use its
1391 /// basic blocks. After invalidation, the CanonicalLoopInfo must not be used
1392 /// anymore as its underlying control flow may not exist anymore.
1393 /// Loop-transformation methods such as tileLoops, collapseLoops and unrollLoop
1394 /// may also return a new CanonicalLoopInfo that can be passed to other
1395 /// loop-associated construct implementing methods. These loop-transforming
1396 /// methods may either create a new CanonicalLoopInfo usually using
1397 /// createLoopSkeleton and invalidate the input CanonicalLoopInfo, or reuse and
1398 /// modify one of the input CanonicalLoopInfo and return it as representing the
1399 /// modified loop. What is done is an implementation detail of
1400 /// transformation-implementing method and callers should always assume that the
1401 /// CanonicalLoopInfo passed to it is invalidated and a new object is returned.
1402 /// Returned CanonicalLoopInfo have the same structure and guarantees as the one
1403 /// created by createCanonicalLoop, such that transforming methods do not have
1404 /// to special case where the CanonicalLoopInfo originated from.
1405 ///
1406 /// Generally, methods consuming CanonicalLoopInfo do not need an
1407 /// OpenMPIRBuilder::InsertPointTy as argument, but use the locations of the
1408 /// CanonicalLoopInfo to insert new or modify existing instructions. Unless
1409 /// documented otherwise, methods consuming CanonicalLoopInfo do not invalidate
1410 /// any InsertPoint that is outside CanonicalLoopInfo's control. Specifically,
1411 /// any InsertPoint in the Preheader, After or Block can still be used after
1412 /// calling such a method.
1413 ///
1414 /// TODO: Provide mechanisms for exception handling and cancellation points.
1415 ///
1416 /// Defined outside OpenMPIRBuilder because nested classes cannot be
1417 /// forward-declared, e.g. to avoid having to include the entire OMPIRBuilder.h.
1419  friend class OpenMPIRBuilder;
1420 
1421 private:
1422  BasicBlock *Header = nullptr;
1423  BasicBlock *Cond = nullptr;
1424  BasicBlock *Latch = nullptr;
1425  BasicBlock *Exit = nullptr;
1426 
1427  /// Add the control blocks of this loop to \p BBs.
1428  ///
1429  /// This does not include any block from the body, including the one returned
1430  /// by getBody().
1431  ///
1432  /// FIXME: This currently includes the Preheader and After blocks even though
1433  /// their content is (mostly) not under CanonicalLoopInfo's control.
1434  /// Re-evaluated whether this makes sense.
1435  void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
1436 
1437 public:
1438  /// Returns whether this object currently represents the IR of a loop. If
1439  /// returning false, it may have been consumed by a loop transformation or not
1440  /// been intialized. Do not use in this case;
1441  bool isValid() const { return Header; }
1442 
1443  /// The preheader ensures that there is only a single edge entering the loop.
1444  /// Code that must be execute before any loop iteration can be emitted here,
1445  /// such as computing the loop trip count and begin lifetime markers. Code in
1446  /// the preheader is not considered part of the canonical loop.
1447  BasicBlock *getPreheader() const;
1448 
1449  /// The header is the entry for each iteration. In the canonical control flow,
1450  /// it only contains the PHINode for the induction variable.
1452  assert(isValid() && "Requires a valid canonical loop");
1453  return Header;
1454  }
1455 
1456  /// The condition block computes whether there is another loop iteration. If
1457  /// yes, branches to the body; otherwise to the exit block.
1458  BasicBlock *getCond() const {
1459  assert(isValid() && "Requires a valid canonical loop");
1460  return Cond;
1461  }
1462 
1463  /// The body block is the single entry for a loop iteration and not controlled
1464  /// by CanonicalLoopInfo. It can contain arbitrary control flow but must
1465  /// eventually branch to the \p Latch block.
1466  BasicBlock *getBody() const {
1467  assert(isValid() && "Requires a valid canonical loop");
1468  return cast<BranchInst>(Cond->getTerminator())->getSuccessor(0);
1469  }
1470 
1471  /// Reaching the latch indicates the end of the loop body code. In the
1472  /// canonical control flow, it only contains the increment of the induction
1473  /// variable.
1475  assert(isValid() && "Requires a valid canonical loop");
1476  return Latch;
1477  }
1478 
1479  /// Reaching the exit indicates no more iterations are being executed.
1480  BasicBlock *getExit() const {
1481  assert(isValid() && "Requires a valid canonical loop");
1482  return Exit;
1483  }
1484 
1485  /// The after block is intended for clean-up code such as lifetime end
1486  /// markers. It is separate from the exit block to ensure, analogous to the
1487  /// preheader, it having just a single entry edge and being free from PHI
1488  /// nodes should there be multiple loop exits (such as from break
1489  /// statements/cancellations).
1491  assert(isValid() && "Requires a valid canonical loop");
1492  return Exit->getSingleSuccessor();
1493  }
1494 
1495  /// Returns the llvm::Value containing the number of loop iterations. It must
1496  /// be valid in the preheader and always interpreted as an unsigned integer of
1497  /// any bit-width.
1498  Value *getTripCount() const {
1499  assert(isValid() && "Requires a valid canonical loop");
1500  Instruction *CmpI = &Cond->front();
1501  assert(isa<CmpInst>(CmpI) && "First inst must compare IV with TripCount");
1502  return CmpI->getOperand(1);
1503  }
1504 
1505  /// Returns the instruction representing the current logical induction
1506  /// variable. Always unsigned, always starting at 0 with an increment of one.
1508  assert(isValid() && "Requires a valid canonical loop");
1509  Instruction *IndVarPHI = &Header->front();
1510  assert(isa<PHINode>(IndVarPHI) && "First inst must be the IV PHI");
1511  return IndVarPHI;
1512  }
1513 
1514  /// Return the type of the induction variable (and the trip count).
1515  Type *getIndVarType() const {
1516  assert(isValid() && "Requires a valid canonical loop");
1517  return getIndVar()->getType();
1518  }
1519 
1520  /// Return the insertion point for user code before the loop.
1522  assert(isValid() && "Requires a valid canonical loop");
1523  BasicBlock *Preheader = getPreheader();
1524  return {Preheader, std::prev(Preheader->end())};
1525  };
1526 
1527  /// Return the insertion point for user code in the body.
1529  assert(isValid() && "Requires a valid canonical loop");
1530  BasicBlock *Body = getBody();
1531  return {Body, Body->begin()};
1532  };
1533 
1534  /// Return the insertion point for user code after the loop.
1536  assert(isValid() && "Requires a valid canonical loop");
1537  BasicBlock *After = getAfter();
1538  return {After, After->begin()};
1539  };
1540 
1542  assert(isValid() && "Requires a valid canonical loop");
1543  return Header->getParent();
1544  }
1545 
1546  /// Consistency self-check.
1547  void assertOK() const;
1548 
1549  /// Invalidate this loop. That is, the underlying IR does not fulfill the
1550  /// requirements of an OpenMP canonical loop anymore.
1551  void invalidate();
1552 };
1553 
1554 } // end namespace llvm
1555 
1556 #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:1521
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:2869
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:147
llvm::OpenMPIRBuilder::OutlineInfo::ExitBB
BasicBlock * ExitBB
Definition: OMPIRBuilder.h:771
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:22
llvm::OpenMPIRBuilder::createSection
InsertPointTy createSection(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB)
Generator for '#omp section'.
Definition: OMPIRBuilder.cpp:1064
llvm::OpenMPIRBuilder::createCritical
InsertPointTy createCritical(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, StringRef CriticalName, Value *HintInst)
Generator for '#omp critical'.
Definition: OMPIRBuilder.cpp:2545
llvm::CanonicalLoopInfo::getAfter
BasicBlock * getAfter() const
The after block is intended for clean-up code such as lifetime end markers.
Definition: OMPIRBuilder.h:1490
llvm::OpenMPIRBuilder::OutlineInfo::ExcludeArgsFromAggregate
SmallVector< Value *, 2 > ExcludeArgsFromAggregate
Definition: OMPIRBuilder.h:772
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:1323
llvm::CanonicalLoopInfo::getPreheader
BasicBlock * getPreheader() const
The preheader ensures that there is only a single edge entering the loop.
Definition: OMPIRBuilder.cpp:3454
llvm::OpenMPIRBuilder::pushFinalizationCB
void pushFinalizationCB(const FinalizationInfo &FI)
Push a finalization callback on the finalization stack.
Definition: OMPIRBuilder.h:78
llvm::Function
Definition: Function.h:62
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:530
Loops
Hexagon Hardware Loops
Definition: HexagonHardwareLoops.cpp:372
llvm::AtomicRMWInst::BinOp
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:743
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1176
llvm::OpenMPIRBuilder::tileLoops
std::vector< CanonicalLoopInfo * > tileLoops(DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, ArrayRef< Value * > TileSizes)
Tile a loop nest.
Definition: OMPIRBuilder.cpp:1956
llvm::OpenMPIRBuilder::InsertPointTy
IRBuilder<>::InsertPoint InsertPointTy
Type used throughout for insertion points.
Definition: OMPIRBuilder.h:50
llvm::IRBuilder
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2515
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::OpenMPIRBuilder::getOrCreateThreadID
Value * getOrCreateThreadID(Value *Ident)
Return the current thread ID.
Definition: OMPIRBuilder.cpp:388
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:72
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:1201
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:65
llvm::CanonicalLoopInfo::getAfterIP
OpenMPIRBuilder::InsertPointTy getAfterIP() const
Return the insertion point for user code after the loop.
Definition: OMPIRBuilder.h:1535
llvm::BasicBlock::getSingleSuccessor
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:298
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const IRBuilder< T, U > &IRB)
Definition: OMPIRBuilder.h:149
llvm::OpenMPIRBuilder::ReductionInfo::Variable
Value * Variable
Reduction variable of pointer type.
Definition: OMPIRBuilder.h:567
llvm::OpenMPIRBuilder::FinalizeCallbackTy
std::function< void(InsertPointTy CodeGenIP)> FinalizeCallbackTy
Callback type for variable finalization (think destructors).
Definition: OMPIRBuilder.h:60
llvm::CanonicalLoopInfo::getFunction
Function * getFunction() const
Definition: OMPIRBuilder.h:1541
llvm::OpenMPIRBuilder::AtomicOpValue::Var
Value * Var
Definition: OMPIRBuilder.h:1202
llvm::OpenMPIRBuilder::BodyGenCallbackTy
function_ref< void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP, BasicBlock &ContinuationBB)> BodyGenCallbackTy
Callback type for body (=inner region) code generation.
Definition: OMPIRBuilder.h:102
llvm::OpenMPIRBuilder::emitTaskyieldImpl
void emitTaskyieldImpl(const LocationDescription &Loc)
Generate a taskyield runtime call.
Definition: OMPIRBuilder.cpp:945
llvm::OpenMPIRBuilder::createReductions
InsertPointTy createReductions(const LocationDescription &Loc, InsertPointTy AllocaIP, ArrayRef< ReductionInfo > ReductionInfos, bool IsNoWait=false)
Generator for '#omp reduction'.
Definition: OMPIRBuilder.cpp:1110
llvm::OpenMPIRBuilder::collapseLoops
CanonicalLoopInfo * collapseLoops(DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, InsertPointTy ComputeIP)
Collapse a loop nest into a single loop.
Definition: OMPIRBuilder.cpp:1828
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:1507
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
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:2580
Mappings
Inject TLI Mappings
Definition: InjectTLIMappings.cpp:172
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:85
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:3045
llvm::OpenMPIRBuilder::M
Module & M
The underlying LLVM-IR module.
Definition: OMPIRBuilder.h:755
llvm::CanonicalLoopInfo::assertOK
void assertOK() const
Consistency self-check.
Definition: OMPIRBuilder.cpp:3463
llvm::CanonicalLoopInfo::getCond
BasicBlock * getCond() const
The condition block computes whether there is another loop iteration.
Definition: OMPIRBuilder.h:1458
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:784
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:2854
llvm::OpenMPIRBuilder::getOrCreateDefaultSrcLocStr
Constant * getOrCreateDefaultSrcLocStr(uint32_t &SrcLocStrSize)
Return the (LLVM-IR) string describing the default source location.
Definition: OMPIRBuilder.cpp:360
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:3026
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:395
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:3132
llvm::OpenMPIRBuilder::IdentMap
DenseMap< std::pair< Constant *, uint64_t >, Constant * > IdentMap
Map to remember existing ident_t*.
Definition: OMPIRBuilder.h:764
IP
Definition: NVPTXLowerArgs.cpp:166
llvm::OpenMPIRBuilder::getInsertionPoint
InsertPointTy getInsertionPoint()
}
Definition: OMPIRBuilder.h:653
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:265
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:1441
llvm::OpenMPIRBuilder::getOrCreateSrcLocStr
Constant * getOrCreateSrcLocStr(StringRef LocStr, uint32_t &SrcLocStrSize)
Return the (LLVM-IR) string describing the source location LocStr.
Definition: OMPIRBuilder.cpp:320
llvm::OpenMPIRBuilder::AtomicOpValue::IsSigned
bool IsSigned
Definition: OMPIRBuilder.h:1203
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const InsertPointTy &IP)
Definition: OMPIRBuilder.h:151
llvm::Instruction
Definition: Instruction.h:45
llvm::OpenMPIRBuilder::StorableBodyGenCallbackTy
std::function< void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP, BasicBlock &ContinuationBB)> StorableBodyGenCallbackTy
Definition: OMPIRBuilder.h:110
llvm::OpenMPIRBuilder::applySimd
void applySimd(DebugLoc DL, CanonicalLoopInfo *Loop)
Add metadata to simd-ize a loop.
Definition: OMPIRBuilder.cpp:2202
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const InsertPointTy &IP, const DebugLoc &DL)
Definition: OMPIRBuilder.h:152
llvm::CanonicalLoopInfo::getBodyIP
OpenMPIRBuilder::InsertPointTy getBodyIP() const
Return the insertion point for user code in the body.
Definition: OMPIRBuilder.h:1528
DebugLoc.h
llvm::OpenMPIRBuilder::MapperAllocas::Args
AllocaInst * Args
Definition: OMPIRBuilder.h:811
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::OpenMPIRBuilder::OpenMPIRBuilder
OpenMPIRBuilder(Module &M)
Create a new OpenMPIRBuilder operating on the given module M.
Definition: OMPIRBuilder.h:33
llvm::OpenMPIRBuilder::unrollLoopFull
void unrollLoopFull(DebugLoc DL, CanonicalLoopInfo *Loop)
Fully unroll a loop.
Definition: OMPIRBuilder.cpp:2187
llvm::OpenMPIRBuilder::emitTaskwaitImpl
void emitTaskwaitImpl(const LocationDescription &Loc)
Generate a taskwait runtime call.
Definition: OMPIRBuilder.cpp:926
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:2837
llvm::OpenMPIRBuilder::addAttributes
void addAttributes(omp::RuntimeFunction FnID, Function &Fn)
Add attributes known for FnID to Fn.
Definition: OMPIRBuilder.cpp:77
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::OpenMPIRBuilder::applyDynamicWorkshareLoop
InsertPointTy applyDynamicWorkshareLoop(DebugLoc DL, 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:1652
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:109
llvm::OpenMPIRBuilder::OutlineInfo::EntryBB
BasicBlock * EntryBB
Definition: OMPIRBuilder.h:771
llvm::OpenMPIRBuilder::Builder
IRBuilder Builder
The LLVM-IR Builder used to create IR.
Definition: OMPIRBuilder.h:758
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
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:957
llvm::OpenMPIRBuilder::createOffloadMaptypes
GlobalVariable * createOffloadMaptypes(SmallVectorImpl< uint64_t > &Mappings, std::string VarName)
Create the global variable holding the offload mappings information.
Definition: OMPIRBuilder.cpp:3014
llvm::OpenMPIRBuilder::AtomicOpValue::IsVolatile
bool IsVolatile
Definition: OMPIRBuilder.h:1204
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:963
llvm::OpenMPIRBuilder::MapperAllocas::ArgsBase
AllocaInst * ArgsBase
Definition: OMPIRBuilder.h:810
llvm::GlobalValue
Definition: GlobalValue.h:44
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:570
llvm::OpenMPIRBuilder::createOrderedThreadsSimd
InsertPointTy createOrderedThreadsSimd(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, bool IsThreads)
Generator for '#omp ordered [threads | simd]'.
Definition: OMPIRBuilder.cpp:2625
llvm::OpenMPIRBuilder::OutlineInfo::getFunction
Function * getFunction() const
Return the function that contains the region to be outlined.
Definition: OMPIRBuilder.h:780
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
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:733
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:69
llvm::OpenMPIRBuilder::emitCancelationCheckImpl
void emitCancelationCheckImpl(Value *CancelFlag, omp::Directive CanceledDirective, FinalizeCallbackTy ExitCB={})
Generate control flow and cleanup for cancellation.
Definition: OMPIRBuilder.cpp:503
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:1390
llvm::OpenMPIRBuilder::createTargetInit
InsertPointTy createTargetInit(const LocationDescription &Loc, bool IsSPMD, bool RequiresFullRuntime)
The omp target interface.
Definition: OMPIRBuilder.cpp:2890
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:280
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:542
llvm::OpenMPIRBuilder::finalize
void finalize(Function *Fn=nullptr)
Finalize the underlying module, e.g., by outlining regions.
Definition: OMPIRBuilder.cpp:177
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:542
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::OpenMPIRBuilder::LocationDescription::DL
DebugLoc DL
Definition: OMPIRBuilder.h:155
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::OpenMPIRBuilder::unrollLoopHeuristic
void unrollLoopHeuristic(DebugLoc DL, CanonicalLoopInfo *Loop)
Fully or partially unroll a loop.
Definition: OMPIRBuilder.cpp:2194
llvm::OpenMPIRBuilder::getOrCreateRuntimeFunctionPtr
Function * getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID)
Definition: OMPIRBuilder.cpp:168
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:1274
llvm::OpenMPIRBuilder::createFlush
void createFlush(const LocationDescription &Loc)
Generator for '#omp flush'.
Definition: OMPIRBuilder.cpp:920
llvm::OpenMPIRBuilder::OutlineInfo
Helper that contains information about regions we need to outline during finalization.
Definition: OMPIRBuilder.h:768
llvm::CanonicalLoopInfo
Class to represented the control flow structure of an OpenMP canonical loop.
Definition: OMPIRBuilder.h:1418
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:269
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:255
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 IsXBinopExpr)
Emit atomic update for constructs: — Only Scalar data types V = X; X = X BinOp Expr ,...
Definition: OMPIRBuilder.cpp:3359
llvm::OpenMPIRBuilder::createOffloadMapnames
GlobalVariable * createOffloadMapnames(SmallVectorImpl< llvm::Constant * > &Names, std::string VarName)
Create the global variable holding the offload names information.
Definition: OMPIRBuilder.cpp:3393
uint32_t
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:812
llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCB
PostOutlineCBTy PostOutlineCB
Definition: OMPIRBuilder.h:770
llvm::OpenMPIRBuilder::unrollLoopPartial
void unrollLoopPartial(DebugLoc DL, CanonicalLoopInfo *Loop, int32_t Factor, CanonicalLoopInfo **UnrolledCLI)
Partially unroll a loop.
Definition: OMPIRBuilder.cpp:2419
llvm::OpenMPIRBuilder::addOutlineInfo
void addOutlineInfo(OutlineInfo &&OI)
Add a new region that will be outlined later.
Definition: OMPIRBuilder.h:791
llvm::OpenMPIRBuilder::createMasked
InsertPointTy createMasked(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, Value *Filter)
Generator for '#omp masked'.
Definition: OMPIRBuilder.cpp:1299
llvm::OpenMPIRBuilder::applyWorkshareLoop
InsertPointTy applyWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, bool NeedsBarrier)
Modifies the canonical loop to be a workshare loop.
Definition: OMPIRBuilder.cpp:1614
llvm::OpenMPIRBuilder::updateToLocation
bool updateToLocation(const LocationDescription &Loc)
Update the internal location to Loc.
Definition: OMPIRBuilder.h:656
llvm::OpenMPIRBuilder::FinalizationStack
SmallVector< FinalizationInfo, 8 > FinalizationStack
The finalization stack made up of finalize callbacks currently in-flight, wrapped into FinalizationIn...
Definition: OMPIRBuilder.h:729
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:1480
llvm::OpenMPIRBuilder::LoopInfos
std::forward_list< CanonicalLoopInfo > LoopInfos
Collection of owned canonical loop objects that eventually need to be free'd.
Definition: OMPIRBuilder.h:788
llvm::OpenMPIRBuilder::createTaskwait
void createTaskwait(const LocationDescription &Loc)
Generator for '#omp taskwait'.
Definition: OMPIRBuilder.cpp:939
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:575
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::OpenMPIRBuilder::ReductionInfo::ElementType
Type * ElementType
Reduction element type, must match pointee type of variable.
Definition: OMPIRBuilder.h:564
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:3174
llvm::CanonicalLoopInfo::invalidate
void invalidate()
Invalidate this loop.
Definition: OMPIRBuilder.cpp:3557
llvm::OpenMPIRBuilder::createCancel
InsertPointTy createCancel(const LocationDescription &Loc, Value *IfCondition, omp::Directive CanceledDirective)
Generator for '#omp cancel'.
Definition: OMPIRBuilder.cpp:452
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCBTy
std::function< void(Function &)> PostOutlineCBTy
Definition: OMPIRBuilder.h:769
llvm::CanonicalLoopInfo::getHeader
BasicBlock * getHeader() const
The header is the entry for each iteration.
Definition: OMPIRBuilder.h:1451
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:2943
llvm::OpenMPIRBuilder::ReductionInfo
Information about an OpenMP reduction.
Definition: OMPIRBuilder.h:552
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:175
llvm::OpenMPIRBuilder::createAtomicUpdate
InsertPointTy createAtomicUpdate(const LocationDescription &Loc, Instruction *AllocIP, 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:3207
llvm::CanonicalLoopInfo::getLatch
BasicBlock * getLatch() const
Reaching the latch indicates the end of the loop body code.
Definition: OMPIRBuilder.h:1474
llvm::OpenMPIRBuilder::FinalizationInfo
Definition: OMPIRBuilder.h:62
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:146
llvm::CanonicalLoopInfo::getIndVarType
Type * getIndVarType() const
Return the type of the induction variable (and the trip count).
Definition: OMPIRBuilder.h:1515
llvm::OpenMPIRBuilder::SrcLocStrMap
StringMap< Constant * > SrcLocStrMap
Map to remember source location strings.
Definition: OMPIRBuilder.h:761
llvm::OpenMPIRBuilder::emitBarrierImpl
InsertPointTy emitBarrierImpl(const LocationDescription &Loc, omp::Directive DK, bool ForceSimpleCall, bool CheckCancelFlag)
Generate a barrier runtime call.
Definition: OMPIRBuilder.cpp:403
llvm::OpenMPIRBuilder::InternalVars
StringMap< AssertingVH< Constant >, BumpPtrAllocator > InternalVars
An ordered map of auto-generated variables to their unique names.
Definition: OMPIRBuilder.h:798
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::SmallVectorImpl< BasicBlock * >
llvm::CanonicalLoopInfo::getTripCount
Value * getTripCount() const
Returns the llvm::Value containing the number of loop iterations.
Definition: OMPIRBuilder.h:1498
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:911
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1478
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:3427
llvm::OpenMPIRBuilder::MapperAllocas
Definition: OMPIRBuilder.h:809
llvm::OpenMPIRBuilder::applyStaticWorkshareLoop
InsertPointTy applyStaticWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, bool NeedsBarrier, Value *Chunk=nullptr)
Modifies the canonical loop to be a statically-scheduled workshare loop.
Definition: OMPIRBuilder.cpp:1520
llvm::OpenMPIRBuilder::ReductionInfo::ReductionInfo
ReductionInfo(Type *ElementType, Value *Variable, Value *PrivateVariable, ReductionGenTy ReductionGen, AtomicReductionGenTy AtomicReductionGen)
Definition: OMPIRBuilder.h:553
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:2510
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:2787
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:2488
llvm::omp::OMPScheduleType
OMPScheduleType
Definition: OMPConstants.h:78
llvm::OpenMPIRBuilder::getOrCreateRuntimeFunction
FunctionCallee getOrCreateRuntimeFunction(Module &M, omp::RuntimeFunction FnID)
Return the function declaration for the runtime function with FnID.
Definition: OMPIRBuilder.cpp:110
llvm::OpenMPIRBuilder::ReductionInfo::AtomicReductionGen
AtomicReductionGenTy AtomicReductionGen
Callback for generating the atomic reduction body, may be null.
Definition: OMPIRBuilder.h:581
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:1466
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::OpenMPIRBuilder::LocationDescription::IP
InsertPointTy IP
Definition: OMPIRBuilder.h:154