Skip to content

Commit 92b7444

Browse files
committed
scan lowering changes
1 parent 2c8e260 commit 92b7444

File tree

5 files changed

+720
-92
lines changed

5 files changed

+720
-92
lines changed

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
namespace llvm {
3131
class CanonicalLoopInfo;
3232
struct TargetRegionEntryInfo;
33+
class ScanInfo;
3334
class OffloadEntriesInfoManager;
3435
class OpenMPIRBuilder;
3536

@@ -728,6 +729,11 @@ class OpenMPIRBuilder {
728729
LoopBodyGenCallbackTy BodyGenCB, Value *TripCount,
729730
const Twine &Name = "loop");
730731

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+
731737
/// Calculate the trip count of a canonical loop.
732738
///
733739
/// This allows specifying user-defined loop counter values using increment,
@@ -800,10 +806,12 @@ class OpenMPIRBuilder {
800806
///
801807
/// \returns An object representing the created control flow structure which
802808
/// 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);
807815

808816
/// Collapse a loop nest into a single loop.
809817
///
@@ -1530,6 +1538,20 @@ class OpenMPIRBuilder {
15301538
ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos,
15311539
Function *ReduceFn, AttributeList FuncAttrs);
15321540

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+
15331555
/// This function emits a helper that gathers Reduce lists from the first
15341556
/// lane of every active warp to lanes in the first warp.
15351557
///
@@ -1981,7 +2003,7 @@ class OpenMPIRBuilder {
19812003
/// in reductions.
19822004
/// \param ReductionInfos A list of info on each reduction variable.
19832005
/// \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
19852007
/// or direct value.
19862008
InsertPointOrErrorTy createReductions(const LocationDescription &Loc,
19872009
InsertPointTy AllocaIP,
@@ -2177,7 +2199,6 @@ class OpenMPIRBuilder {
21772199
// block, if possible, or else at the end of the function. Also add a branch
21782200
// from current block to BB if current block does not have a terminator.
21792201
void emitBlock(BasicBlock *BB, Function *CurFn, bool IsFinished = false);
2180-
21812202
/// Emits code for OpenMP 'if' clause using specified \a BodyGenCallbackTy
21822203
/// Here is the logic:
21832204
/// if (Cond) {
@@ -2603,6 +2624,31 @@ class OpenMPIRBuilder {
26032624
BodyGenCallbackTy BodyGenCB,
26042625
FinalizeCallbackTy FiniCB, Value *Filter);
26052626

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);
26062652
/// Generator for '#omp critical'
26072653
///
26082654
/// \param Loc The insert and source location description.
@@ -3711,6 +3757,20 @@ class CanonicalLoopInfo {
37113757
void invalidate();
37123758
};
37133759

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+
llvm::Value *iv;
3770+
llvm::Value *span;
3771+
SmallVector<llvm::BasicBlock *> continueBlocks;
3772+
};
3773+
37143774
} // end namespace llvm
37153775

37163776
#endif // LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H

0 commit comments

Comments
 (0)