LLVM  13.0.0git
OMPIRBuilder.h
Go to the documentation of this file.
1 //===- IR/OpenMPIRBuilder.h - OpenMP encoding builder for LLVM IR - C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the OpenMPIRBuilder class and helpers used as a convenient
10 // way to create LLVM instructions for OpenMP directives.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
15 #define LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
16 
18 #include "llvm/IR/DebugLoc.h"
19 #include "llvm/IR/IRBuilder.h"
20 #include "llvm/Support/Allocator.h"
21 #include <forward_list>
22 
23 namespace llvm {
24 class CanonicalLoopInfo;
25 
26 /// An interface to create LLVM-IR for OpenMP directives.
27 ///
28 /// Each OpenMP directive has a corresponding public generator method.
30 public:
31  /// Create a new OpenMPIRBuilder operating on the given module \p M. This will
32  /// not have an effect on \p M (see initialize).
33  OpenMPIRBuilder(Module &M) : M(M), Builder(M.getContext()) {}
35 
36  /// Initialize the internal state, this will put structures types and
37  /// potentially other helpers into the underlying module. Must be called
38  /// before any other method and only once!
39  void initialize();
40 
41  /// Finalize the underlying module, e.g., by outlining regions.
42  /// \param Fn The function to be finalized. If not used,
43  /// all functions are finalized.
44  /// \param AllowExtractorSinking Flag to include sinking instructions,
45  /// emitted by CodeExtractor, in the
46  /// outlined region. Default is false.
47  void finalize(Function *Fn = nullptr, bool AllowExtractorSinking = false);
48 
49  /// Add attributes known for \p FnID to \p Fn.
51 
52  /// Type used throughout for insertion points.
54 
55  /// Callback type for variable finalization (think destructors).
56  ///
57  /// \param CodeGenIP is the insertion point at which the finalization code
58  /// should be placed.
59  ///
60  /// A finalize callback knows about all objects that need finalization, e.g.
61  /// destruction, when the scope of the currently generated construct is left
62  /// at the time, and location, the callback is invoked.
64 
66  /// The finalization callback provided by the last in-flight invocation of
67  /// createXXXX for the directive of kind DK.
69 
70  /// The directive kind of the innermost directive that has an associated
71  /// region which might require finalization when it is left.
72  omp::Directive DK;
73 
74  /// Flag to indicate if the directive is cancellable.
76  };
77 
78  /// Push a finalization callback on the finalization stack.
79  ///
80  /// NOTE: Temporary solution until Clang CG is gone.
82  FinalizationStack.push_back(FI);
83  }
84 
85  /// Pop the last finalization callback from the finalization stack.
86  ///
87  /// NOTE: Temporary solution until Clang CG is gone.
88  void popFinalizationCB() { FinalizationStack.pop_back(); }
89 
90  /// Callback type for body (=inner region) code generation
91  ///
92  /// The callback takes code locations as arguments, each describing a
93  /// location at which code might need to be generated or a location that is
94  /// the target of control transfer.
95  ///
96  /// \param AllocaIP is the insertion point at which new alloca instructions
97  /// should be placed.
98  /// \param CodeGenIP is the insertion point at which the body code should be
99  /// placed.
100  /// \param ContinuationBB is the basic block target to leave the body.
101  ///
102  /// Note that all blocks pointed to by the arguments have terminators.
103  using BodyGenCallbackTy =
104  function_ref<void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
105  BasicBlock &ContinuationBB)>;
106 
107  /// Callback type for loop body code generation.
108  ///
109  /// \param CodeGenIP is the insertion point where the loop's body code must be
110  /// placed. This will be a dedicated BasicBlock with a
111  /// conditional branch from the loop condition check and
112  /// terminated with an unconditional branch to the loop
113  /// latch.
114  /// \param IndVar is the induction variable usable at the insertion point.
115  using LoopBodyGenCallbackTy =
116  function_ref<void(InsertPointTy CodeGenIP, Value *IndVar)>;
117 
118  /// Callback type for variable privatization (think copy & default
119  /// constructor).
120  ///
121  /// \param AllocaIP is the insertion point at which new alloca instructions
122  /// should be placed.
123  /// \param CodeGenIP is the insertion point at which the privatization code
124  /// should be placed.
125  /// \param Original The value being copied/created, should not be used in the
126  /// generated IR.
127  /// \param Inner The equivalent of \p Original that should be used in the
128  /// generated IR; this is equal to \p Original if the value is
129  /// a pointer and can thus be passed directly, otherwise it is
130  /// an equivalent but different value.
131  /// \param ReplVal The replacement value, thus a copy or new created version
132  /// of \p Inner.
133  ///
134  /// \returns The new insertion point where code generation continues and
135  /// \p ReplVal the replacement value.
137  InsertPointTy AllocaIP, InsertPointTy CodeGenIP, Value &Original,
138  Value &Inner, Value *&ReplVal)>;
139 
140  /// Description of a LLVM-IR insertion point (IP) and a debug/source location
141  /// (filename, line, column, ...).
143  template <typename T, typename U>
145  : IP(IRB.saveIP()), DL(IRB.getCurrentDebugLocation()) {}
148  : IP(IP), DL(DL) {}
151  };
152 
153  /// Emitter methods for OpenMP directives.
154  ///
155  ///{
156 
157  /// Generator for '#omp barrier'
158  ///
159  /// \param Loc The location where the barrier directive was encountered.
160  /// \param DK The kind of directive that caused the barrier.
161  /// \param ForceSimpleCall Flag to force a simple (=non-cancellation) barrier.
162  /// \param CheckCancelFlag Flag to indicate a cancel barrier return value
163  /// should be checked and acted upon.
164  ///
165  /// \returns The insertion point after the barrier.
166  InsertPointTy createBarrier(const LocationDescription &Loc, omp::Directive DK,
167  bool ForceSimpleCall = false,
168  bool CheckCancelFlag = true);
169 
170  /// Generator for '#omp cancel'
171  ///
172  /// \param Loc The location where the directive was encountered.
173  /// \param IfCondition The evaluated 'if' clause expression, if any.
174  /// \param CanceledDirective The kind of directive that is cancled.
175  ///
176  /// \returns The insertion point after the barrier.
177  InsertPointTy createCancel(const LocationDescription &Loc, Value *IfCondition,
178  omp::Directive CanceledDirective);
179 
180  /// Generator for '#omp parallel'
181  ///
182  /// \param Loc The insert and source location description.
183  /// \param AllocaIP The insertion points to be used for alloca instructions.
184  /// \param BodyGenCB Callback that will generate the region code.
185  /// \param PrivCB Callback to copy a given variable (think copy constructor).
186  /// \param FiniCB Callback to finalize variable copies.
187  /// \param IfCondition The evaluated 'if' clause expression, if any.
188  /// \param NumThreads The evaluated 'num_threads' clause expression, if any.
189  /// \param ProcBind The value of the 'proc_bind' clause (see ProcBindKind).
190  /// \param IsCancellable Flag to indicate a cancellable parallel region.
191  ///
192  /// \returns The insertion position *after* the parallel.
194  createParallel(const LocationDescription &Loc, InsertPointTy AllocaIP,
195  BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
196  FinalizeCallbackTy FiniCB, Value *IfCondition,
197  Value *NumThreads, omp::ProcBindKind ProcBind,
198  bool IsCancellable);
199 
200  /// Generator for the control flow structure of an OpenMP canonical loop.
201  ///
202  /// This generator operates on the logical iteration space of the loop, i.e.
203  /// the caller only has to provide a loop trip count of the loop as defined by
204  /// base language semantics. The trip count is interpreted as an unsigned
205  /// integer. The induction variable passed to \p BodyGenCB will be of the same
206  /// type and run from 0 to \p TripCount - 1. It is up to the callback to
207  /// convert the logical iteration variable to the loop counter variable in the
208  /// loop body.
209  ///
210  /// \param Loc The insert and source location description. The insert
211  /// location can be between two instructions or the end of a
212  /// degenerate block (e.g. a BB under construction).
213  /// \param BodyGenCB Callback that will generate the loop body code.
214  /// \param TripCount Number of iterations the loop body is executed.
215  /// \param Name Base name used to derive BB and instruction names.
216  ///
217  /// \returns An object representing the created control flow structure which
218  /// can be used for loop-associated directives.
220  LoopBodyGenCallbackTy BodyGenCB,
221  Value *TripCount,
222  const Twine &Name = "loop");
223 
224  /// Generator for the control flow structure of an OpenMP canonical loop.
225  ///
226  /// Instead of a logical iteration space, this allows specifying user-defined
227  /// loop counter values using increment, upper- and lower bounds. To
228  /// disambiguate the terminology when counting downwards, instead of lower
229  /// bounds we use \p Start for the loop counter value in the first body
230  /// iteration.
231  ///
232  /// Consider the following limitations:
233  ///
234  /// * A loop counter space over all integer values of its bit-width cannot be
235  /// represented. E.g using uint8_t, its loop trip count of 256 cannot be
236  /// stored into an 8 bit integer):
237  ///
238  /// DO I = 0, 255, 1
239  ///
240  /// * Unsigned wrapping is only supported when wrapping only "once"; E.g.
241  /// effectively counting downwards:
242  ///
243  /// for (uint8_t i = 100u; i > 0; i += 127u)
244  ///
245  ///
246  /// TODO: May need to add additional parameters to represent:
247  ///
248  /// * Allow representing downcounting with unsigned integers.
249  ///
250  /// * Sign of the step and the comparison operator might disagree:
251  ///
252  /// for (int i = 0; i < 42; --i)
253  ///
254  //
255  /// \param Loc The insert and source location description.
256  /// \param BodyGenCB Callback that will generate the loop body code.
257  /// \param Start Value of the loop counter for the first iterations.
258  /// \param Stop Loop counter values past this will stop the the
259  /// iterations.
260  /// \param Step Loop counter increment after each iteration; negative
261  /// means counting down. \param IsSigned Whether Start, Stop
262  /// and Stop are signed integers.
263  /// \param InclusiveStop Whether \p Stop itself is a valid value for the loop
264  /// counter.
265  /// \param ComputeIP Insertion point for instructions computing the trip
266  /// count. Can be used to ensure the trip count is available
267  /// at the outermost loop of a loop nest. If not set,
268  /// defaults to the preheader of the generated loop.
269  /// \param Name Base name used to derive BB and instruction names.
270  ///
271  /// \returns An object representing the created control flow structure which
272  /// can be used for loop-associated directives.
274  LoopBodyGenCallbackTy BodyGenCB,
275  Value *Start, Value *Stop, Value *Step,
276  bool IsSigned, bool InclusiveStop,
277  InsertPointTy ComputeIP = {},
278  const Twine &Name = "loop");
279 
280  /// Collapse a loop nest into a single loop.
281  ///
282  /// Merges loops of a loop nest into a single CanonicalLoopNest representation
283  /// that has the same number of innermost loop iterations as the origin loop
284  /// nest. The induction variables of the input loops are derived from the
285  /// collapsed loop's induction variable. This is intended to be used to
286  /// implement OpenMP's collapse clause. Before applying a directive,
287  /// collapseLoops normalizes a loop nest to contain only a single loop and the
288  /// directive's implementation does not need to handle multiple loops itself.
289  /// This does not remove the need to handle all loop nest handling by
290  /// directives, such as the ordered(<n>) clause or the simd schedule-clause
291  /// modifier of the worksharing-loop directive.
292  ///
293  /// Example:
294  /// \code
295  /// for (int i = 0; i < 7; ++i) // Canonical loop "i"
296  /// for (int j = 0; j < 9; ++j) // Canonical loop "j"
297  /// body(i, j);
298  /// \endcode
299  ///
300  /// After collapsing with Loops={i,j}, the loop is changed to
301  /// \code
302  /// for (int ij = 0; ij < 63; ++ij) {
303  /// int i = ij / 9;
304  /// int j = ij % 9;
305  /// body(i, j);
306  /// }
307  /// \endcode
308  ///
309  /// In the current implementation, the following limitations apply:
310  ///
311  /// * All input loops have an induction variable of the same type.
312  ///
313  /// * The collapsed loop will have the same trip count integer type as the
314  /// input loops. Therefore it is possible that the collapsed loop cannot
315  /// represent all iterations of the input loops. For instance, assuming a
316  /// 32 bit integer type, and two input loops both iterating 2^16 times, the
317  /// theoretical trip count of the collapsed loop would be 2^32 iteration,
318  /// which cannot be represented in an 32-bit integer. Behavior is undefined
319  /// in this case.
320  ///
321  /// * The trip counts of every input loop must be available at \p ComputeIP.
322  /// Non-rectangular loops are not yet supported.
323  ///
324  /// * At each nest level, code between a surrounding loop and its nested loop
325  /// is hoisted into the loop body, and such code will be executed more
326  /// often than before collapsing (or not at all if any inner loop iteration
327  /// has a trip count of 0). This is permitted by the OpenMP specification.
328  ///
329  /// \param DL Debug location for instructions added for collapsing,
330  /// such as instructions to compute derive the input loop's
331  /// induction variables.
332  /// \param Loops Loops in the loop nest to collapse. Loops are specified
333  /// from outermost-to-innermost and every control flow of a
334  /// loop's body must pass through its directly nested loop.
335  /// \param ComputeIP Where additional instruction that compute the collapsed
336  /// trip count. If not set, defaults to before the generated
337  /// loop.
338  ///
339  /// \returns The CanonicalLoopInfo object representing the collapsed loop.
342  InsertPointTy ComputeIP);
343 
344  /// Modifies the canonical loop to be a statically-scheduled workshare loop.
345  ///
346  /// This takes a \p LoopInfo representing a canonical loop, such as the one
347  /// created by \p createCanonicalLoop and emits additional instructions to
348  /// turn it into a workshare loop. In particular, it calls to an OpenMP
349  /// runtime function in the preheader to obtain the loop bounds to be used in
350  /// the current thread, updates the relevant instructions in the canonical
351  /// loop and calls to an OpenMP runtime finalization function after the loop.
352  ///
353  /// \param Loc The source location description, the insertion location
354  /// is not used.
355  /// \param CLI A descriptor of the canonical loop to workshare.
356  /// \param AllocaIP An insertion point for Alloca instructions usable in the
357  /// preheader of the loop.
358  /// \param NeedsBarrier Indicates whether a barrier must be inserted after
359  /// the loop.
360  /// \param Chunk The size of loop chunk considered as a unit when
361  /// scheduling. If \p nullptr, defaults to 1.
362  ///
363  /// \returns Updated CanonicalLoopInfo.
364  CanonicalLoopInfo *createStaticWorkshareLoop(const LocationDescription &Loc,
365  CanonicalLoopInfo *CLI,
366  InsertPointTy AllocaIP,
367  bool NeedsBarrier,
368  Value *Chunk = nullptr);
369 
370  /// Modifies the canonical loop to be a dynamically-scheduled workshare loop.
371  ///
372  /// This takes a \p LoopInfo representing a canonical loop, such as the one
373  /// created by \p createCanonicalLoop and emits additional instructions to
374  /// turn it into a workshare loop. In particular, it calls to an OpenMP
375  /// runtime function in the preheader to obtain, and then in each iteration
376  /// to update the loop counter.
377  /// \param Loc The source location description, the insertion location
378  /// is not used.
379  /// \param CLI A descriptor of the canonical loop to workshare.
380  /// \param AllocaIP An insertion point for Alloca instructions usable in the
381  /// preheader of the loop.
382  /// \param NeedsBarrier Indicates whether a barrier must be insterted after
383  /// the loop.
384  /// \param Chunk The size of loop chunk considered as a unit when
385  /// scheduling. If \p nullptr, defaults to 1.
386  ///
387  /// \returns Point where to insert code after the loop.
388  InsertPointTy createDynamicWorkshareLoop(const LocationDescription &Loc,
389  CanonicalLoopInfo *CLI,
390  InsertPointTy AllocaIP,
391  bool NeedsBarrier,
392  Value *Chunk = nullptr);
393 
394  /// Modifies the canonical loop to be a workshare loop.
395  ///
396  /// This takes a \p LoopInfo representing a canonical loop, such as the one
397  /// created by \p createCanonicalLoop and emits additional instructions to
398  /// turn it into a workshare loop. In particular, it calls to an OpenMP
399  /// runtime function in the preheader to obtain the loop bounds to be used in
400  /// the current thread, updates the relevant instructions in the canonical
401  /// loop and calls to an OpenMP runtime finalization function after the loop.
402  ///
403  /// \param Loc The source location description, the insertion location
404  /// is not used.
405  /// \param CLI A descriptor of the canonical loop to workshare.
406  /// \param AllocaIP An insertion point for Alloca instructions usable in the
407  /// preheader of the loop.
408  /// \param NeedsBarrier Indicates whether a barrier must be insterted after
409  /// the loop.
410  ///
411  /// \returns Updated CanonicalLoopInfo.
412  CanonicalLoopInfo *createWorkshareLoop(const LocationDescription &Loc,
413  CanonicalLoopInfo *CLI,
414  InsertPointTy AllocaIP,
415  bool NeedsBarrier);
416 
417  /// Tile a loop nest.
418  ///
419  /// Tiles the loops of \p Loops by the tile sizes in \p TileSizes. Loops in
420  /// \p/ Loops must be perfectly nested, from outermost to innermost loop
421  /// (i.e. Loops.front() is the outermost loop). The trip count llvm::Value
422  /// of every loop and every tile sizes must be usable in the outermost
423  /// loop's preheader. This implies that the loop nest is rectangular.
424  ///
425  /// Example:
426  /// \code
427  /// for (int i = 0; i < 15; ++i) // Canonical loop "i"
428  /// for (int j = 0; j < 14; ++j) // Canonical loop "j"
429  /// body(i, j);
430  /// \endcode
431  ///
432  /// After tiling with Loops={i,j} and TileSizes={5,7}, the loop is changed to
433  /// \code
434  /// for (int i1 = 0; i1 < 3; ++i1)
435  /// for (int j1 = 0; j1 < 2; ++j1)
436  /// for (int i2 = 0; i2 < 5; ++i2)
437  /// for (int j2 = 0; j2 < 7; ++j2)
438  /// body(i1*3+i2, j1*3+j2);
439  /// \endcode
440  ///
441  /// The returned vector are the loops {i1,j1,i2,j2}. The loops i1 and j1 are
442  /// referred to the floor, and the loops i2 and j2 are the tiles. Tiling also
443  /// handles non-constant trip counts, non-constant tile sizes and trip counts
444  /// that are not multiples of the tile size. In the latter case the tile loop
445  /// of the last floor-loop iteration will have fewer iterations than specified
446  /// as its tile size.
447  ///
448  ///
449  /// @param DL Debug location for instructions added by tiling, for
450  /// instance the floor- and tile trip count computation.
451  /// @param Loops Loops to tile. The CanonicalLoopInfo objects are
452  /// invalidated by this method, i.e. should not used after
453  /// tiling.
454  /// @param TileSizes For each loop in \p Loops, the tile size for that
455  /// dimensions.
456  ///
457  /// \returns A list of generated loops. Contains twice as many loops as the
458  /// input loop nest; the first half are the floor loops and the
459  /// second half are the tile loops.
460  std::vector<CanonicalLoopInfo *>
462  ArrayRef<Value *> TileSizes);
463 
464  /// Generator for '#omp flush'
465  ///
466  /// \param Loc The location where the flush directive was encountered
467  void createFlush(const LocationDescription &Loc);
468 
469  /// Generator for '#omp taskwait'
470  ///
471  /// \param Loc The location where the taskwait directive was encountered.
472  void createTaskwait(const LocationDescription &Loc);
473 
474  /// Generator for '#omp taskyield'
475  ///
476  /// \param Loc The location where the taskyield directive was encountered.
477  void createTaskyield(const LocationDescription &Loc);
478 
479  ///}
480 
481  /// Return the insertion point used by the underlying IRBuilder.
483 
484  /// Update the internal location to \p Loc.
486  Builder.restoreIP(Loc.IP);
488  return Loc.IP.getBlock() != nullptr;
489  }
490 
491  /// Return the function declaration for the runtime function with \p FnID.
493  omp::RuntimeFunction FnID);
494 
496 
497  /// Return the (LLVM-IR) string describing the source location \p LocStr.
499 
500  /// Return the (LLVM-IR) string describing the default source location.
502 
503  /// Return the (LLVM-IR) string describing the source location identified by
504  /// the arguments.
505  Constant *getOrCreateSrcLocStr(StringRef FunctionName, StringRef FileName,
506  unsigned Line, unsigned Column);
507 
508  /// Return the (LLVM-IR) string describing the source location \p Loc.
509  Constant *getOrCreateSrcLocStr(const LocationDescription &Loc);
510 
511  /// Return an ident_t* encoding the source location \p SrcLocStr and \p Flags.
512  /// TODO: Create a enum class for the Reserve2Flags
513  Value *getOrCreateIdent(Constant *SrcLocStr,
514  omp::IdentFlag Flags = omp::IdentFlag(0),
515  unsigned Reserve2Flags = 0);
516 
517  // Get the type corresponding to __kmpc_impl_lanemask_t from the deviceRTL
519 
520  /// Generate control flow and cleanup for cancellation.
521  ///
522  /// \param CancelFlag Flag indicating if the cancellation is performed.
523  /// \param CanceledDirective The kind of directive that is cancled.
524  void emitCancelationCheckImpl(Value *CancelFlag,
525  omp::Directive CanceledDirective);
526 
527  /// Generate a barrier runtime call.
528  ///
529  /// \param Loc The location at which the request originated and is fulfilled.
530  /// \param DK The directive which caused the barrier
531  /// \param ForceSimpleCall Flag to force a simple (=non-cancellation) barrier.
532  /// \param CheckCancelFlag Flag to indicate a cancel barrier return value
533  /// should be checked and acted upon.
534  ///
535  /// \returns The insertion point after the barrier.
536  InsertPointTy emitBarrierImpl(const LocationDescription &Loc,
537  omp::Directive DK, bool ForceSimpleCall,
538  bool CheckCancelFlag);
539 
540  /// Generate a flush runtime call.
541  ///
542  /// \param Loc The location at which the request originated and is fulfilled.
543  void emitFlush(const LocationDescription &Loc);
544 
545  /// The finalization stack made up of finalize callbacks currently in-flight,
546  /// wrapped into FinalizationInfo objects that reference also the finalization
547  /// target block and the kind of cancellable directive.
549 
550  /// Return true if the last entry in the finalization stack is of kind \p DK
551  /// and cancellable.
552  bool isLastFinalizationInfoCancellable(omp::Directive DK) {
553  return !FinalizationStack.empty() &&
554  FinalizationStack.back().IsCancellable &&
555  FinalizationStack.back().DK == DK;
556  }
557 
558  /// Generate a taskwait runtime call.
559  ///
560  /// \param Loc The location at which the request originated and is fulfilled.
561  void emitTaskwaitImpl(const LocationDescription &Loc);
562 
563  /// Generate a taskyield runtime call.
564  ///
565  /// \param Loc The location at which the request originated and is fulfilled.
566  void emitTaskyieldImpl(const LocationDescription &Loc);
567 
568  /// Return the current thread ID.
569  ///
570  /// \param Ident The ident (ident_t*) describing the query origin.
572 
573  /// The underlying LLVM-IR module
575 
576  /// The LLVM-IR Builder used to create IR.
578 
579  /// Map to remember source location strings
581 
582  /// Map to remember existing ident_t*.
584 
585  /// Helper that contains information about regions we need to outline
586  /// during finalization.
587  struct OutlineInfo {
591 
592  /// Collect all blocks in between EntryBB and ExitBB in both the given
593  /// vector and set.
595  SmallVectorImpl<BasicBlock *> &BlockVector);
596 
597  /// Return the function that contains the region to be outlined.
598  Function *getFunction() const { return EntryBB->getParent(); }
599  };
600 
601  /// Collection of regions that need to be outlined during finalization.
603 
604  /// Collection of owned canonical loop objects that eventually need to be
605  /// free'd.
606  std::forward_list<CanonicalLoopInfo> LoopInfos;
607 
608  /// Add a new region that will be outlined later.
609  void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
610 
611  /// An ordered map of auto-generated variables to their unique names.
612  /// It stores variables with the following names: 1) ".gomp_critical_user_" +
613  /// <critical_section_name> + ".var" for "omp critical" directives; 2)
614  /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
615  /// variables.
617 
618 public:
619  /// Generator for __kmpc_copyprivate
620  ///
621  /// \param Loc The source location description.
622  /// \param BufSize Number of elements in the buffer.
623  /// \param CpyBuf List of pointers to data to be copied.
624  /// \param CpyFn function to call for copying data.
625  /// \param DidIt flag variable; 1 for 'single' thread, 0 otherwise.
626  ///
627  /// \return The insertion position *after* the CopyPrivate call.
628 
630  llvm::Value *BufSize, llvm::Value *CpyBuf,
631  llvm::Value *CpyFn, llvm::Value *DidIt);
632 
633  /// Generator for '#omp single'
634  ///
635  /// \param Loc The source location description.
636  /// \param BodyGenCB Callback that will generate the region code.
637  /// \param FiniCB Callback to finalize variable copies.
638  /// \param DidIt Local variable used as a flag to indicate 'single' thread
639  ///
640  /// \returns The insertion position *after* the single call.
642  BodyGenCallbackTy BodyGenCB,
643  FinalizeCallbackTy FiniCB, llvm::Value *DidIt);
644 
645  /// Generator for '#omp master'
646  ///
647  /// \param Loc The insert and source location description.
648  /// \param BodyGenCB Callback that will generate the region code.
649  /// \param FiniCB Callback to finalize variable copies.
650  ///
651  /// \returns The insertion position *after* the master.
653  BodyGenCallbackTy BodyGenCB,
654  FinalizeCallbackTy FiniCB);
655 
656  /// Generator for '#omp masked'
657  ///
658  /// \param Loc The insert and source location description.
659  /// \param BodyGenCB Callback that will generate the region code.
660  /// \param FiniCB Callback to finialize variable copies.
661  ///
662  /// \returns The insertion position *after* the master.
664  BodyGenCallbackTy BodyGenCB,
665  FinalizeCallbackTy FiniCB, Value *Filter);
666 
667  /// Generator for '#omp critical'
668  ///
669  /// \param Loc The insert and source location description.
670  /// \param BodyGenCB Callback that will generate the region body code.
671  /// \param FiniCB Callback to finalize variable copies.
672  /// \param CriticalName name of the lock used by the critical directive
673  /// \param HintInst Hint Instruction for hint clause associated with critical
674  ///
675  /// \returns The insertion position *after* the master.
677  BodyGenCallbackTy BodyGenCB,
678  FinalizeCallbackTy FiniCB,
679  StringRef CriticalName, Value *HintInst);
680 
681  /// Generate conditional branch and relevant BasicBlocks through which private
682  /// threads copy the 'copyin' variables from Master copy to threadprivate
683  /// copies.
684  ///
685  /// \param IP insertion block for copyin conditional
686  /// \param MasterVarPtr a pointer to the master variable
687  /// \param PrivateVarPtr a pointer to the threadprivate variable
688  /// \param IntPtrTy Pointer size type
689  /// \param BranchtoEnd Create a branch between the copyin.not.master blocks
690  // and copy.in.end block
691  ///
692  /// \returns The insertion point where copying operation to be emitted.
694  Value *PrivateAddr,
695  llvm::IntegerType *IntPtrTy,
696  bool BranchtoEnd = true);
697 
698  /// Create a runtime call for kmpc_Alloc
699  ///
700  /// \param Loc The insert and source location description.
701  /// \param Size Size of allocated memory space
702  /// \param Allocator Allocator information instruction
703  /// \param Name Name of call Instruction for OMP_alloc
704  ///
705  /// \returns CallInst to the OMP_Alloc call
707  Value *Allocator, std::string Name = "");
708 
709  /// Create a runtime call for kmpc_free
710  ///
711  /// \param Loc The insert and source location description.
712  /// \param Addr Address of memory space to be freed
713  /// \param Allocator Allocator information instruction
714  /// \param Name Name of call Instruction for OMP_Free
715  ///
716  /// \returns CallInst to the OMP_Free call
718  Value *Allocator, std::string Name = "");
719 
720  /// Create a runtime call for kmpc_threadprivate_cached
721  ///
722  /// \param Loc The insert and source location description.
723  /// \param Pointer pointer to data to be cached
724  /// \param Size size of data to be cached
725  /// \param Name Name of call Instruction for callinst
726  ///
727  /// \returns CallInst to the thread private cache call.
729  llvm::Value *Pointer,
731  const llvm::Twine &Name = Twine(""));
732 
733  /// Declarations for LLVM-IR types (simple, array, function and structure) are
734  /// generated below. Their names are defined and used in OpenMPKinds.def. Here
735  /// we provide the declarations, the initializeTypes function will provide the
736  /// values.
737  ///
738  ///{
739 #define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
740 #define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
741  ArrayType *VarName##Ty = nullptr; \
742  PointerType *VarName##PtrTy = nullptr;
743 #define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
744  FunctionType *VarName = nullptr; \
745  PointerType *VarName##Ptr = nullptr;
746 #define OMP_STRUCT_TYPE(VarName, StrName, ...) \
747  StructType *VarName = nullptr; \
748  PointerType *VarName##Ptr = nullptr;
749 #include "llvm/Frontend/OpenMP/OMPKinds.def"
750 
751  ///}
752 
753 private:
754  /// Create all simple and struct types exposed by the runtime and remember
755  /// the llvm::PointerTypes of them for easy access later.
756  void initializeTypes(Module &M);
757 
758  /// Common interface for generating entry calls for OMP Directives.
759  /// if the directive has a region/body, It will set the insertion
760  /// point to the body
761  ///
762  /// \param OMPD Directive to generate entry blocks for
763  /// \param EntryCall Call to the entry OMP Runtime Function
764  /// \param ExitBB block where the region ends.
765  /// \param Conditional indicate if the entry call result will be used
766  /// to evaluate a conditional of whether a thread will execute
767  /// body code or not.
768  ///
769  /// \return The insertion position in exit block
770  InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD, Value *EntryCall,
771  BasicBlock *ExitBB,
772  bool Conditional = false);
773 
774  /// Common interface to finalize the region
775  ///
776  /// \param OMPD Directive to generate exiting code for
777  /// \param FinIP Insertion point for emitting Finalization code and exit call
778  /// \param ExitCall Call to the ending OMP Runtime Function
779  /// \param HasFinalize indicate if the directive will require finalization
780  /// and has a finalization callback in the stack that
781  /// should be called.
782  ///
783  /// \return The insertion position in exit block
784  InsertPointTy emitCommonDirectiveExit(omp::Directive OMPD,
785  InsertPointTy FinIP,
786  Instruction *ExitCall,
787  bool HasFinalize = true);
788 
789  /// Common Interface to generate OMP inlined regions
790  ///
791  /// \param OMPD Directive to generate inlined region for
792  /// \param EntryCall Call to the entry OMP Runtime Function
793  /// \param ExitCall Call to the ending OMP Runtime Function
794  /// \param BodyGenCB Body code generation callback.
795  /// \param FiniCB Finalization Callback. Will be called when finalizing region
796  /// \param Conditional indicate if the entry call result will be used
797  /// to evaluate a conditional of whether a thread will execute
798  /// body code or not.
799  /// \param HasFinalize indicate if the directive will require finalization
800  /// and has a finalization callback in the stack that
801  /// should be called.
802  ///
803  /// \return The insertion point after the region
804 
806  EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
807  Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
808  FinalizeCallbackTy FiniCB, bool Conditional = false,
809  bool HasFinalize = true);
810 
811  /// Get the platform-specific name separator.
812  /// \param Parts different parts of the final name that needs separation
813  /// \param FirstSeparator First separator used between the initial two
814  /// parts of the name.
815  /// \param Separator separator used between all of the rest consecutive
816  /// parts of the name
817  static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
818  StringRef FirstSeparator,
819  StringRef Separator);
820 
821  /// Gets (if variable with the given name already exist) or creates
822  /// internal global variable with the specified Name. The created variable has
823  /// linkage CommonLinkage by default and is initialized by null value.
824  /// \param Ty Type of the global variable. If it is exist already the type
825  /// must be the same.
826  /// \param Name Name of the variable.
827  Constant *getOrCreateOMPInternalVariable(Type *Ty, const Twine &Name,
828  unsigned AddressSpace = 0);
829 
830  /// Returns corresponding lock object for the specified critical region
831  /// name. If the lock object does not exist it is created, otherwise the
832  /// reference to the existing copy is returned.
833  /// \param CriticalName Name of the critical region.
834  ///
835  Value *getOMPCriticalRegionLock(StringRef CriticalName);
836 
837  /// Create the control flow structure of a canonical OpenMP loop.
838  ///
839  /// The emitted loop will be disconnected, i.e. no edge to the loop's
840  /// preheader and no terminator in the AfterBB. The OpenMPIRBuilder's
841  /// IRBuilder location is not preserved.
842  ///
843  /// \param DL DebugLoc used for the instructions in the skeleton.
844  /// \param TripCount Value to be used for the trip count.
845  /// \param F Function in which to insert the BasicBlocks.
846  /// \param PreInsertBefore Where to insert BBs that execute before the body,
847  /// typically the body itself.
848  /// \param PostInsertBefore Where to insert BBs that execute after the body.
849  /// \param Name Base name used to derive BB
850  /// and instruction names.
851  ///
852  /// \returns The CanonicalLoopInfo that represents the emitted loop.
853  CanonicalLoopInfo *createLoopSkeleton(DebugLoc DL, Value *TripCount,
854  Function *F,
855  BasicBlock *PreInsertBefore,
856  BasicBlock *PostInsertBefore,
857  const Twine &Name = {});
858 };
859 
860 /// Class to represented the control flow structure of an OpenMP canonical loop.
861 ///
862 /// The control-flow structure is standardized for easy consumption by
863 /// directives associated with loops. For instance, the worksharing-loop
864 /// construct may change this control flow such that each loop iteration is
865 /// executed on only one thread.
866 ///
867 /// The control flow can be described as follows:
868 ///
869 /// Preheader
870 /// |
871 /// /-> Header
872 /// | |
873 /// | Cond---\
874 /// | | |
875 /// | Body |
876 /// | | | |
877 /// | <...> |
878 /// | | | |
879 /// \--Latch |
880 /// |
881 /// Exit
882 /// |
883 /// After
884 ///
885 /// Code in the header, condition block, latch and exit block must not have any
886 /// side-effect. The body block is the single entry point into the loop body,
887 /// which may contain arbitrary control flow as long as all control paths
888 /// eventually branch to the latch block.
889 ///
890 /// Defined outside OpenMPIRBuilder because one cannot forward-declare nested
891 /// classes.
893  friend class OpenMPIRBuilder;
894 
895 private:
896  /// Whether this object currently represents a loop.
897  bool IsValid = false;
898 
899  BasicBlock *Preheader;
900  BasicBlock *Header;
901  BasicBlock *Cond;
902  BasicBlock *Body;
903  BasicBlock *Latch;
904  BasicBlock *Exit;
905  BasicBlock *After;
906 
907  /// Add the control blocks of this loop to \p BBs.
908  ///
909  /// This does not include any block from the body, including the one returned
910  /// by getBody().
911  void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
912 
913 public:
914  /// The preheader ensures that there is only a single edge entering the loop.
915  /// Code that must be execute before any loop iteration can be emitted here,
916  /// such as computing the loop trip count and begin lifetime markers. Code in
917  /// the preheader is not considered part of the canonical loop.
918  BasicBlock *getPreheader() const { return Preheader; }
919 
920  /// The header is the entry for each iteration. In the canonical control flow,
921  /// it only contains the PHINode for the induction variable.
922  BasicBlock *getHeader() const { return Header; }
923 
924  /// The condition block computes whether there is another loop iteration. If
925  /// yes, branches to the body; otherwise to the exit block.
926  BasicBlock *getCond() const { return Cond; }
927 
928  /// The body block is the single entry for a loop iteration and not controlled
929  /// by CanonicalLoopInfo. It can contain arbitrary control flow but must
930  /// eventually branch to the \p Latch block.
931  BasicBlock *getBody() const { return Body; }
932 
933  /// Reaching the latch indicates the end of the loop body code. In the
934  /// canonical control flow, it only contains the increment of the induction
935  /// variable.
936  BasicBlock *getLatch() const { return Latch; }
937 
938  /// Reaching the exit indicates no more iterations are being executed.
939  BasicBlock *getExit() const { return Exit; }
940 
941  /// The after block is intended for clean-up code such as lifetime end
942  /// markers. It is separate from the exit block to ensure, analogous to the
943  /// preheader, it having just a single entry edge and being free from PHI
944  /// nodes should there be multiple loop exits (such as from break
945  /// statements/cancellations).
946  BasicBlock *getAfter() const { return After; }
947 
948  /// Returns the llvm::Value containing the number of loop iterations. It must
949  /// be valid in the preheader and always interpreted as an unsigned integer of
950  /// any bit-width.
951  Value *getTripCount() const {
952  Instruction *CmpI = &Cond->front();
953  assert(isa<CmpInst>(CmpI) && "First inst must compare IV with TripCount");
954  return CmpI->getOperand(1);
955  }
956 
957  /// Returns the instruction representing the current logical induction
958  /// variable. Always unsigned, always starting at 0 with an increment of one.
960  Instruction *IndVarPHI = &Header->front();
961  assert(isa<PHINode>(IndVarPHI) && "First inst must be the IV PHI");
962  return IndVarPHI;
963  }
964 
965  /// Return the type of the induction variable (and the trip count).
966  Type *getIndVarType() const { return getIndVar()->getType(); }
967 
968  /// Return the insertion point for user code before the loop.
970  return {Preheader, std::prev(Preheader->end())};
971  };
972 
973  /// Return the insertion point for user code in the body.
975  return {Body, Body->begin()};
976  };
977 
978  /// Return the insertion point for user code after the loop.
980  return {After, After->begin()};
981  };
982 
983  Function *getFunction() const { return Header->getParent(); }
984 
985  /// Consistency self-check.
986  void assertOK() const;
987 };
988 
989 } // end namespace llvm
990 
991 #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:969
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:2030
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:142
llvm::OpenMPIRBuilder::OutlineInfo::ExitBB
BasicBlock * ExitBB
Definition: OMPIRBuilder.h:590
llvm
Definition: AllocatorList.h:23
llvm::OpenMPIRBuilder::createCritical
InsertPointTy createCritical(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, StringRef CriticalName, Value *HintInst)
Generator for '#omp critical'.
Definition: OMPIRBuilder.cpp:1786
llvm::CanonicalLoopInfo::getAfter
BasicBlock * getAfter() const
The after block is intended for clean-up code such as lifetime end markers.
Definition: OMPIRBuilder.h:946
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:107
llvm::OpenMPIRBuilder::pushFinalizationCB
void pushFinalizationCB(const FinalizationInfo &FI)
Push a finalization callback on the finalization stack.
Definition: OMPIRBuilder.h:81
llvm::Function
Definition: Function.h:61
Loops
Hexagon Hardware Loops
Definition: HexagonHardwareLoops.cpp:372
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::OpenMPIRBuilder::tileLoops
std::vector< CanonicalLoopInfo * > tileLoops(DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, ArrayRef< Value * > TileSizes)
Tile a loop nest.
Definition: OMPIRBuilder.cpp:1546
llvm::OpenMPIRBuilder::createWorkshareLoop
CanonicalLoopInfo * createWorkshareLoop(const LocationDescription &Loc, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, bool NeedsBarrier)
Modifies the canonical loop to be a workshare loop.
Definition: OMPIRBuilder.cpp:1214
llvm::OpenMPIRBuilder::getLanemaskType
Type * getLanemaskType()
Definition: OMPIRBuilder.cpp:263
llvm::OpenMPIRBuilder::InsertPointTy
IRBuilder<>::InsertPoint InsertPointTy
Type used throughout for insertion points.
Definition: OMPIRBuilder.h:53
llvm::IRBuilder
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2586
llvm::OpenMPIRBuilder::getOrCreateThreadID
Value * getOrCreateThreadID(Value *Ident)
Return the current thread ID.
Definition: OMPIRBuilder.cpp:328
Allocator.h
llvm::OpenMPIRBuilder::emitCancelationCheckImpl
void emitCancelationCheckImpl(Value *CancelFlag, omp::Directive CanceledDirective)
Generate control flow and cleanup for cancellation.
Definition: OMPIRBuilder.cpp:431
llvm::OpenMPIRBuilder::FinalizationInfo::IsCancellable
bool IsCancellable
Flag to indicate if the directive is cancellable.
Definition: OMPIRBuilder.h:75
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::OpenMPIRBuilder::FinalizationInfo::FiniCB
FinalizeCallbackTy FiniCB
The finalization callback provided by the last in-flight invocation of createXXXX for the directive o...
Definition: OMPIRBuilder.h:68
llvm::CanonicalLoopInfo::getAfterIP
OpenMPIRBuilder::InsertPointTy getAfterIP() const
Return the insertion point for user code after the loop.
Definition: OMPIRBuilder.h:979
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const IRBuilder< T, U > &IRB)
Definition: OMPIRBuilder.h:144
llvm::OpenMPIRBuilder::FinalizeCallbackTy
std::function< void(InsertPointTy CodeGenIP)> FinalizeCallbackTy
Callback type for variable finalization (think destructors).
Definition: OMPIRBuilder.h:63
llvm::CanonicalLoopInfo::getFunction
Function * getFunction() const
Definition: OMPIRBuilder.h:983
llvm::OpenMPIRBuilder::BodyGenCallbackTy
function_ref< void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP, BasicBlock &ContinuationBB)> BodyGenCallbackTy
Callback type for body (=inner region) code generation.
Definition: OMPIRBuilder.h:105
llvm::OpenMPIRBuilder::emitTaskyieldImpl
void emitTaskyieldImpl(const LocationDescription &Loc)
Generate a taskyield runtime call.
Definition: OMPIRBuilder.cpp:863
llvm::OpenMPIRBuilder::collapseLoops
CanonicalLoopInfo * collapseLoops(DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, InsertPointTy ComputeIP)
Collapse a loop nest into a single loop.
Definition: OMPIRBuilder.cpp:1425
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::CanonicalLoopInfo::getIndVar
Instruction * getIndVar() const
Returns the instruction representing the current logical induction variable.
Definition: OMPIRBuilder.h:959
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::OpenMPIRBuilder::finalize
void finalize(Function *Fn=nullptr, bool AllowExtractorSinking=false)
Finalize the underlying module, e.g., by outlining regions.
Definition: OMPIRBuilder.cpp:141
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:77
llvm::OpenMPIRBuilder::popFinalizationCB
void popFinalizationCB()
Pop the last finalization callback from the finalization stack.
Definition: OMPIRBuilder.h:88
llvm::OpenMPIRBuilder::getOrCreateDefaultSrcLocStr
Constant * getOrCreateDefaultSrcLocStr()
Return the (LLVM-IR) string describing the default source location.
Definition: OMPIRBuilder.cpp:308
llvm::OpenMPIRBuilder::getOrCreateIdent
Value * getOrCreateIdent(Constant *SrcLocStr, omp::IdentFlag Flags=omp::IdentFlag(0), unsigned Reserve2Flags=0)
Return an ident_t* encoding the source location SrcLocStr and Flags.
Definition: OMPIRBuilder.cpp:230
llvm::OpenMPIRBuilder::M
Module & M
The underlying LLVM-IR module.
Definition: OMPIRBuilder.h:574
llvm::CanonicalLoopInfo::assertOK
void assertOK() const
Consistency self-check.
Definition: OMPIRBuilder.cpp:2146
llvm::CanonicalLoopInfo::getCond
BasicBlock * getCond() const
The condition block computes whether there is another loop iteration.
Definition: OMPIRBuilder.h:926
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:602
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:2016
llvm::BasicBlock::begin
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:296
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:335
IP
Definition: NVPTXLowerArgs.cpp:166
llvm::OpenMPIRBuilder::getInsertionPoint
InsertPointTy getInsertionPoint()
}
Definition: OMPIRBuilder.h:482
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:226
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::OpenMPIRBuilder::IdentMap
DenseMap< std::pair< Constant *, uint64_t >, Value * > IdentMap
Map to remember existing ident_t*.
Definition: OMPIRBuilder.h:583
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const InsertPointTy &IP)
Definition: OMPIRBuilder.h:146
llvm::Instruction
Definition: Instruction.h:45
llvm::OpenMPIRBuilder::LocationDescription::LocationDescription
LocationDescription(const InsertPointTy &IP, const DebugLoc &DL)
Definition: OMPIRBuilder.h:147
llvm::CanonicalLoopInfo::getBodyIP
OpenMPIRBuilder::InsertPointTy getBodyIP() const
Return the insertion point for user code in the body.
Definition: OMPIRBuilder.h:974
DebugLoc.h
llvm::omp::IdentFlag
IdentFlag
IDs for all omp runtime library ident_t flag encodings (see their defintion in openmp/runtime/src/kmp...
Definition: OMPConstants.h:74
llvm::OpenMPIRBuilder::OpenMPIRBuilder
OpenMPIRBuilder(Module &M)
Create a new OpenMPIRBuilder operating on the given module M.
Definition: OMPIRBuilder.h:33
llvm::OpenMPIRBuilder::emitTaskwaitImpl
void emitTaskwaitImpl(const LocationDescription &Loc)
Generate a taskwait runtime call.
Definition: OMPIRBuilder.cpp:845
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:2000
llvm::OpenMPIRBuilder::addAttributes
void addAttributes(omp::RuntimeFunction FnID, Function &Fn)
Add attributes known for FnID to Fn.
Definition: OMPIRBuilder.cpp:41
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::OpenMPIRBuilder::OutlineInfo::EntryBB
BasicBlock * EntryBB
Definition: OMPIRBuilder.h:590
llvm::OpenMPIRBuilder::Builder
IRBuilder Builder
The LLVM-IR Builder used to create IR.
Definition: OMPIRBuilder.h:577
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:176
llvm::omp::RuntimeFunction
RuntimeFunction
IDs for all omp runtime library (RTL) functions.
Definition: OMPConstants.h:54
llvm::OpenMPIRBuilder::createTaskyield
void createTaskyield(const LocationDescription &Loc)
Generator for '#omp taskyield'.
Definition: OMPIRBuilder.cpp:874
llvm::CanonicalLoopInfo::getPreheader
BasicBlock * getPreheader() const
The preheader ensures that there is only a single edge entering the loop.
Definition: OMPIRBuilder.h:918
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::OpenMPIRBuilder::OutlineInfo::getFunction
Function * getFunction() const
Return the function that contains the region to be outlined.
Definition: OMPIRBuilder.h:598
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
llvm::OpenMPIRBuilder::isLastFinalizationInfoCancellable
bool isLastFinalizationInfoCancellable(omp::Directive DK)
Return true if the last entry in the finalization stack is of kind DK and cancellable.
Definition: OMPIRBuilder.h:552
llvm::DenseMap
Definition: DenseMap.h:714
llvm::OpenMPIRBuilder::FinalizationInfo::DK
omp::Directive DK
The directive kind of the innermost directive that has an associated region which might require final...
Definition: OMPIRBuilder.h:72
llvm::OpenMPIRBuilder::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:1000
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:467
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:64
llvm::OpenMPIRBuilder::LocationDescription::DL
DebugLoc DL
Definition: OMPIRBuilder.h:150
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::OpenMPIRBuilder::getOrCreateRuntimeFunctionPtr
Function * getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID)
Definition: OMPIRBuilder.cpp:132
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::OpenMPIRBuilder::createMaster
InsertPointTy createMaster(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB)
Generator for '#omp master'.
Definition: OMPIRBuilder.cpp:881
llvm::OpenMPIRBuilder::createFlush
void createFlush(const LocationDescription &Loc)
Generator for '#omp flush'.
Definition: OMPIRBuilder.cpp:839
llvm::OpenMPIRBuilder::OutlineInfo
Helper that contains information about regions we need to outline during finalization.
Definition: OMPIRBuilder.h:587
llvm::CanonicalLoopInfo
Class to represented the control flow structure of an OpenMP canonical loop.
Definition: OMPIRBuilder.h:892
llvm::OpenMPIRBuilder::createDynamicWorkshareLoop
InsertPointTy createDynamicWorkshareLoop(const LocationDescription &Loc, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, bool NeedsBarrier, Value *Chunk=nullptr)
Modifies the canonical loop to be a dynamically-scheduled workshare loop.
Definition: OMPIRBuilder.cpp:1253
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:33
Cond
SmallVector< MachineOperand, 4 > Cond
Definition: BasicBlockSections.cpp:167
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCB
PostOutlineCBTy PostOutlineCB
Definition: OMPIRBuilder.h:589
llvm::OpenMPIRBuilder::addOutlineInfo
void addOutlineInfo(OutlineInfo &&OI)
Add a new region that will be outlined later.
Definition: OMPIRBuilder.h:609
llvm::OpenMPIRBuilder::createMasked
InsertPointTy createMasked(const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, Value *Filter)
Generator for '#omp masked'.
Definition: OMPIRBuilder.cpp:905
llvm::OpenMPIRBuilder::updateToLocation
bool updateToLocation(const LocationDescription &Loc)
Update the internal location to Loc.
Definition: OMPIRBuilder.h:485
llvm::OpenMPIRBuilder::FinalizationStack
SmallVector< FinalizationInfo, 8 > FinalizationStack
The finalization stack made up of finalize callbacks currently in-flight, wrapped into FinalizationIn...
Definition: OMPIRBuilder.h:548
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:939
llvm::OpenMPIRBuilder::createStaticWorkshareLoop
CanonicalLoopInfo * createStaticWorkshareLoop(const LocationDescription &Loc, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, bool NeedsBarrier, Value *Chunk=nullptr)
Modifies the canonical loop to be a statically-scheduled workshare loop.
Definition: OMPIRBuilder.cpp:1129
llvm::OpenMPIRBuilder::LoopInfos
std::forward_list< CanonicalLoopInfo > LoopInfos
Collection of owned canonical loop objects that eventually need to be free'd.
Definition: OMPIRBuilder.h:606
llvm::OpenMPIRBuilder::createTaskwait
void createTaskwait(const LocationDescription &Loc)
Generator for '#omp taskwait'.
Definition: OMPIRBuilder.cpp:857
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::OpenMPIRBuilder::createCancel
InsertPointTy createCancel(const LocationDescription &Loc, Value *IfCondition, omp::Directive CanceledDirective)
Generator for '#omp cancel'.
Definition: OMPIRBuilder.cpp:390
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCBTy
std::function< void(Function &)> PostOutlineCBTy
Definition: OMPIRBuilder.h:588
llvm::CanonicalLoopInfo::getHeader
BasicBlock * getHeader() const
The header is the entry for each iteration.
Definition: OMPIRBuilder.h:922
llvm::OpenMPIRBuilder::getOrCreateSrcLocStr
Constant * getOrCreateSrcLocStr(StringRef LocStr)
Return the (LLVM-IR) string describing the source location LocStr.
Definition: OMPIRBuilder.cpp:271
OMPConstants.h
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:139
llvm::CanonicalLoopInfo::getLatch
BasicBlock * getLatch() const
Reaching the latch indicates the end of the loop body code.
Definition: OMPIRBuilder.h:936
llvm::OpenMPIRBuilder::FinalizationInfo
Definition: OMPIRBuilder.h:65
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:966
llvm::OpenMPIRBuilder::SrcLocStrMap
StringMap< Constant * > SrcLocStrMap
Map to remember source location strings.
Definition: OMPIRBuilder.h:580
llvm::OpenMPIRBuilder::emitBarrierImpl
InsertPointTy emitBarrierImpl(const LocationDescription &Loc, omp::Directive DK, bool ForceSimpleCall, bool CheckCancelFlag)
Generate a barrier runtime call.
Definition: OMPIRBuilder.cpp:343
llvm::OpenMPIRBuilder::InternalVars
StringMap< AssertingVH< Constant >, BumpPtrAllocator > InternalVars
An ordered map of auto-generated variables to their unique names.
Definition: OMPIRBuilder.h:616
llvm::FunctionCallee
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:164
llvm::SmallVectorImpl< BasicBlock * >
llvm::CanonicalLoopInfo::getTripCount
Value * getTripCount() const
Returns the llvm::Value containing the number of loop iterations.
Definition: OMPIRBuilder.h:951
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:831
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1450
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:2119
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
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:1752
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:1950
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:1731
llvm::OpenMPIRBuilder::getOrCreateRuntimeFunction
FunctionCallee getOrCreateRuntimeFunction(Module &M, omp::RuntimeFunction FnID)
Return the function declaration for the runtime function with FnID.
Definition: OMPIRBuilder.cpp:74
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:931
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::OpenMPIRBuilder::LocationDescription::IP
InsertPointTy IP
Definition: OMPIRBuilder.h:149