|
30 | 30 | namespace llvm { |
31 | 31 | class CanonicalLoopInfo; |
32 | 32 | struct TargetRegionEntryInfo; |
| 33 | +class ScanInfo; |
33 | 34 | class OffloadEntriesInfoManager; |
34 | 35 | class OpenMPIRBuilder; |
35 | 36 |
|
@@ -728,6 +729,11 @@ class OpenMPIRBuilder { |
728 | 729 | LoopBodyGenCallbackTy BodyGenCB, Value *TripCount, |
729 | 730 | const Twine &Name = "loop"); |
730 | 731 |
|
| 732 | + Expected<SmallVector<llvm::CanonicalLoopInfo *>> createCanonicalScanLoops( |
| 733 | + const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB, |
| 734 | + Value *Start, Value *Stop, Value *Step, bool IsSigned, bool InclusiveStop, |
| 735 | + InsertPointTy ComputeIP, const Twine &Name, bool InScan); |
| 736 | + |
731 | 737 | /// Calculate the trip count of a canonical loop. |
732 | 738 | /// |
733 | 739 | /// This allows specifying user-defined loop counter values using increment, |
@@ -800,10 +806,12 @@ class OpenMPIRBuilder { |
800 | 806 | /// |
801 | 807 | /// \returns An object representing the created control flow structure which |
802 | 808 | /// can be used for loop-associated directives. |
803 | | - Expected<CanonicalLoopInfo *> createCanonicalLoop( |
804 | | - const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB, |
805 | | - Value *Start, Value *Stop, Value *Step, bool IsSigned, bool InclusiveStop, |
806 | | - InsertPointTy ComputeIP = {}, const Twine &Name = "loop"); |
| 809 | + Expected<CanonicalLoopInfo *> |
| 810 | + createCanonicalLoop(const LocationDescription &Loc, |
| 811 | + LoopBodyGenCallbackTy BodyGenCB, Value *Start, |
| 812 | + Value *Stop, Value *Step, bool IsSigned, |
| 813 | + bool InclusiveStop, InsertPointTy ComputeIP = {}, |
| 814 | + const Twine &Name = "loop", bool InScan = false); |
807 | 815 |
|
808 | 816 | /// Collapse a loop nest into a single loop. |
809 | 817 | /// |
@@ -1530,6 +1538,20 @@ class OpenMPIRBuilder { |
1530 | 1538 | ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos, |
1531 | 1539 | Function *ReduceFn, AttributeList FuncAttrs); |
1532 | 1540 |
|
| 1541 | + Expected<SmallVector<llvm::CanonicalLoopInfo *>> emitScanBasedDirectiveIR( |
| 1542 | + llvm::function_ref<Expected<CanonicalLoopInfo *>()> FirstGen, |
| 1543 | + llvm::function_ref<Expected<CanonicalLoopInfo *>(LocationDescription loc)> |
| 1544 | + SecondGen); |
| 1545 | + llvm::CallInst *emitNoUnwindRuntimeCall(llvm::FunctionCallee callee, |
| 1546 | + ArrayRef<llvm::Value *> args, |
| 1547 | + const llvm::Twine &name); |
| 1548 | + |
| 1549 | + void createScanBBs(); |
| 1550 | + void emitScanBasedDirectiveDeclsIR(llvm::Value *span, |
| 1551 | + ArrayRef<llvm::Value *> ScanVars); |
| 1552 | + void emitScanBasedDirectiveFinalsIR( |
| 1553 | + SmallVector<llvm::OpenMPIRBuilder::ReductionInfo> reductionInfos); |
| 1554 | + |
1533 | 1555 | /// This function emits a helper that gathers Reduce lists from the first |
1534 | 1556 | /// lane of every active warp to lanes in the first warp. |
1535 | 1557 | /// |
@@ -1981,7 +2003,7 @@ class OpenMPIRBuilder { |
1981 | 2003 | /// in reductions. |
1982 | 2004 | /// \param ReductionInfos A list of info on each reduction variable. |
1983 | 2005 | /// \param IsNoWait A flag set if the reduction is marked as nowait. |
1984 | | - /// \param IsByRef A flag set if the reduction is using reference |
| 2006 | + /// \param IsByRef At flag set if the reduction is using reference |
1985 | 2007 | /// or direct value. |
1986 | 2008 | InsertPointOrErrorTy createReductions(const LocationDescription &Loc, |
1987 | 2009 | InsertPointTy AllocaIP, |
@@ -2177,7 +2199,6 @@ class OpenMPIRBuilder { |
2177 | 2199 | // block, if possible, or else at the end of the function. Also add a branch |
2178 | 2200 | // from current block to BB if current block does not have a terminator. |
2179 | 2201 | void emitBlock(BasicBlock *BB, Function *CurFn, bool IsFinished = false); |
2180 | | - |
2181 | 2202 | /// Emits code for OpenMP 'if' clause using specified \a BodyGenCallbackTy |
2182 | 2203 | /// Here is the logic: |
2183 | 2204 | /// if (Cond) { |
@@ -2603,6 +2624,31 @@ class OpenMPIRBuilder { |
2603 | 2624 | BodyGenCallbackTy BodyGenCB, |
2604 | 2625 | FinalizeCallbackTy FiniCB, Value *Filter); |
2605 | 2626 |
|
| 2627 | + /// Generator for the scan reduction |
| 2628 | + /// |
| 2629 | + /// \param Loc The insert and source location description. |
| 2630 | + /// \param FinalizeIP The IP where the reduction result needs |
| 2631 | + // to be copied back to original variable. |
| 2632 | + /// \param ReductionInfos Array type containing the ReductionOps. |
| 2633 | + /// |
| 2634 | + /// \returns The insertion position *after* the masked. |
| 2635 | + InsertPointOrErrorTy emitScanReduction( |
| 2636 | + const LocationDescription &Loc, InsertPointTy &FinalizeIP, |
| 2637 | + SmallVector<llvm::OpenMPIRBuilder::ReductionInfo> reductionInfos); |
| 2638 | + |
| 2639 | + /// Generator for the scan reduction |
| 2640 | + /// |
| 2641 | + /// \param Loc The insert and source location description. |
| 2642 | + /// \param AllocaIP The IP where the temporary buffer for scan reduction |
| 2643 | + // needs to be allocated. |
| 2644 | + /// \param ScanVars Scan Variables. |
| 2645 | + /// \param IsInclusive Indicates if it is an inclusive or exclusive scan. |
| 2646 | + /// |
| 2647 | + /// \returns The insertion position *after* the masked. |
| 2648 | + InsertPointOrErrorTy createScan(const LocationDescription &Loc, |
| 2649 | + InsertPointTy AllocaIP, |
| 2650 | + ArrayRef<llvm::Value *> ScanVars, |
| 2651 | + bool IsInclusive); |
2606 | 2652 | /// Generator for '#omp critical' |
2607 | 2653 | /// |
2608 | 2654 | /// \param Loc The insert and source location description. |
@@ -3711,6 +3757,22 @@ class CanonicalLoopInfo { |
3711 | 3757 | void invalidate(); |
3712 | 3758 | }; |
3713 | 3759 |
|
| 3760 | +class ScanInfo { |
| 3761 | +public: |
| 3762 | + llvm::BasicBlock *OMPBeforeScanBlock = nullptr; |
| 3763 | + llvm::BasicBlock *OMPAfterScanBlock = nullptr; |
| 3764 | + llvm::BasicBlock *OMPScanExitBlock = nullptr; |
| 3765 | + llvm::BasicBlock *OMPScanDispatch = nullptr; |
| 3766 | + llvm::BasicBlock *OMPScanLoopExit = nullptr; |
| 3767 | + bool OMPFirstScanLoop = false; |
| 3768 | + llvm::SmallDenseMap<llvm::Value *, llvm::Value *> ReductionVarToScanBuffs; |
| 3769 | + SmallVector<llvm::Value *> privateReductionVariables; |
| 3770 | + SmallVector<llvm::Value *> originalReductionVariables; |
| 3771 | + llvm::Value *iv; |
| 3772 | + llvm::Value *span; |
| 3773 | + SmallVector<llvm::BasicBlock *> continueBlocks; |
| 3774 | +}; |
| 3775 | + |
3714 | 3776 | } // end namespace llvm |
3715 | 3777 |
|
3716 | 3778 | #endif // LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H |
0 commit comments