Skip to content

[MLIR][OpenMP] Automate operand structure definition #99508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions flang/lib/Lower/OpenMP/ClauseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static void addUseDeviceClause(

static void convertLoopBounds(lower::AbstractConverter &converter,
mlir::Location loc,
mlir::omp::LoopRelatedOps &result,
mlir::omp::LoopRelatedClauseOps &result,
std::size_t loopVarTypeSize) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
// The types of lower bound, upper bound, and step are converted into the
Expand All @@ -203,7 +203,7 @@ static void convertLoopBounds(lower::AbstractConverter &converter,

bool ClauseProcessor::processCollapse(
mlir::Location currentLocation, lower::pft::Evaluation &eval,
mlir::omp::LoopRelatedOps &result,
mlir::omp::LoopRelatedClauseOps &result,
llvm::SmallVectorImpl<const semantics::Symbol *> &iv) const {
bool found = false;
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
Expand Down Expand Up @@ -855,7 +855,7 @@ bool ClauseProcessor::processIf(
// Assume that, at most, a single 'if' clause will be applicable to the
// given directive.
if (operand) {
result.ifVar = operand;
result.ifExpr = operand;
found = true;
}
});
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Lower/OpenMP/ClauseProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ClauseProcessor {
// 'Unique' clauses: They can appear at most once in the clause list.
bool
processCollapse(mlir::Location currentLocation, lower::pft::Evaluation &eval,
mlir::omp::LoopRelatedOps &result,
mlir::omp::LoopRelatedClauseOps &result,
llvm::SmallVectorImpl<const semantics::Symbol *> &iv) const;
bool processDevice(lower::StatementContext &stmtCtx,
mlir::omp::DeviceClauseOps &result) const;
Expand Down
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mlir_tablegen(OpenMPOpsDialect.h.inc -gen-dialect-decls -dialect=omp)
mlir_tablegen(OpenMPOpsDialect.cpp.inc -gen-dialect-defs -dialect=omp)
mlir_tablegen(OpenMPOps.h.inc -gen-op-decls)
mlir_tablegen(OpenMPOps.cpp.inc -gen-op-defs)
mlir_tablegen(OpenMPClauseOps.h.inc -gen-openmp-clause-ops)
mlir_tablegen(OpenMPOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=omp)
mlir_tablegen(OpenMPOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=omp)
mlir_tablegen(OpenMPOpsEnums.h.inc -gen-enum-decls)
Expand Down
292 changes: 10 additions & 282 deletions mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,303 +23,31 @@
#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.h.inc"

#include "mlir/Dialect/OpenMP/OpenMPClauseOps.h.inc"

namespace mlir {
namespace omp {

//===----------------------------------------------------------------------===//
// Mixin structures defining MLIR operands associated with each OpenMP clause.
// Extra clause operand structures.
//===----------------------------------------------------------------------===//

struct AlignedClauseOps {
llvm::SmallVector<Value> alignedVars;
llvm::SmallVector<Attribute> alignments;
};

struct AllocateClauseOps {
llvm::SmallVector<Value> allocateVars, allocatorVars;
};

struct CancelDirectiveNameClauseOps {
ClauseCancellationConstructTypeAttr cancelDirective;
};

struct CopyprivateClauseOps {
llvm::SmallVector<Value> copyprivateVars;
llvm::SmallVector<Attribute> copyprivateSyms;
};

struct CriticalNameClauseOps {
/// This field has a generic name because it's mirroring the `sym_name`
/// argument of the `OpenMP_CriticalNameClause` tablegen definition. That one
/// can't be renamed to anything more specific because the `sym_name` name is
/// a requirement of the `Symbol` MLIR trait associated with that clause.
StringAttr symName;
};

struct DependClauseOps {
llvm::SmallVector<Attribute> dependKinds;
llvm::SmallVector<Value> dependVars;
};

struct DeviceClauseOps {
Value device;
};

struct DeviceTypeClauseOps {
// The default capture type.
/// The default capture type.
DeclareTargetDeviceType deviceType = DeclareTargetDeviceType::any;
};

struct DistScheduleClauseOps {
UnitAttr distScheduleStatic;
Value distScheduleChunkSize;
};

struct DoacrossClauseOps {
ClauseDependAttr doacrossDependType;
IntegerAttr doacrossNumLoops;
llvm::SmallVector<Value> doacrossDependVars;
};

struct FilterClauseOps {
Value filteredThreadId;
};

struct FinalClauseOps {
Value final;
};

struct GrainsizeClauseOps {
Value grainsize;
};

struct HasDeviceAddrClauseOps {
llvm::SmallVector<Value> hasDeviceAddrVars;
};

struct HintClauseOps {
IntegerAttr hint;
};

struct IfClauseOps {
Value ifVar;
};

struct InReductionClauseOps {
llvm::SmallVector<Value> inReductionVars;
llvm::SmallVector<bool> inReductionByref;
llvm::SmallVector<Attribute> inReductionSyms;
};

struct IsDevicePtrClauseOps {
llvm::SmallVector<Value> isDevicePtrVars;
};

struct LinearClauseOps {
llvm::SmallVector<Value> linearVars, linearStepVars;
};

struct LoopRelatedOps {
llvm::SmallVector<Value> loopLowerBounds, loopUpperBounds, loopSteps;
UnitAttr loopInclusive;
};

struct MapClauseOps {
llvm::SmallVector<Value> mapVars;
};

struct MergeableClauseOps {
UnitAttr mergeable;
};

struct NogroupClauseOps {
UnitAttr nogroup;
};

struct NontemporalClauseOps {
llvm::SmallVector<Value> nontemporalVars;
};

struct NowaitClauseOps {
UnitAttr nowait;
};

struct NumTasksClauseOps {
Value numTasks;
};

struct NumTeamsClauseOps {
Value numTeamsLower, numTeamsUpper;
};

struct NumThreadsClauseOps {
Value numThreads;
};

struct OrderClauseOps {
ClauseOrderKindAttr order;
OrderModifierAttr orderMod;
};

struct OrderedClauseOps {
IntegerAttr ordered;
};

struct ParallelizationLevelClauseOps {
UnitAttr parLevelSimd;
};

struct PriorityClauseOps {
Value priority;
};

struct PrivateClauseOps {
// SSA values that correspond to "original" values being privatized.
// They refer to the SSA value outside the OpenMP region from which a clone is
// created inside the region.
llvm::SmallVector<Value> privateVars;
// The list of symbols referring to delayed privatizer ops (i.e. `omp.private`
// ops).
llvm::SmallVector<Attribute> privateSyms;
};

struct ProcBindClauseOps {
ClauseProcBindKindAttr procBindKind;
};

struct ReductionClauseOps {
llvm::SmallVector<Value> reductionVars;
llvm::SmallVector<bool> reductionByref;
llvm::SmallVector<Attribute> reductionSyms;
};

struct SafelenClauseOps {
IntegerAttr safelen;
};

struct ScheduleClauseOps {
ClauseScheduleKindAttr scheduleKind;
Value scheduleChunk;
ScheduleModifierAttr scheduleMod;
UnitAttr scheduleSimd;
};

struct SimdlenClauseOps {
IntegerAttr simdlen;
};

struct TaskReductionClauseOps {
llvm::SmallVector<Value> taskReductionVars;
llvm::SmallVector<bool> taskReductionByref;
llvm::SmallVector<Attribute> taskReductionSyms;
};

struct ThreadLimitClauseOps {
Value threadLimit;
};

struct UntiedClauseOps {
UnitAttr untied;
};

struct UseDeviceAddrClauseOps {
llvm::SmallVector<Value> useDeviceAddrVars;
};

struct UseDevicePtrClauseOps {
llvm::SmallVector<Value> useDevicePtrVars;
};

//===----------------------------------------------------------------------===//
// Structures defining clause operands associated with each OpenMP leaf
// construct.
//
// These mirror the arguments expected by the corresponding OpenMP MLIR ops.
// Extra operation operand structures.
//===----------------------------------------------------------------------===//

namespace detail {
template <typename... Mixins>
struct Clauses : public Mixins... {};
} // namespace detail

using CancelOperands =
detail::Clauses<CancelDirectiveNameClauseOps, IfClauseOps>;

using CancellationPointOperands = detail::Clauses<CancelDirectiveNameClauseOps>;

using CriticalDeclareOperands =
detail::Clauses<CriticalNameClauseOps, HintClauseOps>;

// TODO `indirect` clause.
// TODO: Add `indirect` clause.
using DeclareTargetOperands = detail::Clauses<DeviceTypeClauseOps>;

using DistributeOperands =
detail::Clauses<AllocateClauseOps, DistScheduleClauseOps, OrderClauseOps,
PrivateClauseOps>;

using LoopNestOperands = detail::Clauses<LoopRelatedOps>;

using MaskedOperands = detail::Clauses<FilterClauseOps>;

using OrderedOperands = detail::Clauses<DoacrossClauseOps>;

using OrderedRegionOperands = detail::Clauses<ParallelizationLevelClauseOps>;

using ParallelOperands =
detail::Clauses<AllocateClauseOps, IfClauseOps, NumThreadsClauseOps,
PrivateClauseOps, ProcBindClauseOps, ReductionClauseOps>;

using SectionsOperands = detail::Clauses<AllocateClauseOps, NowaitClauseOps,
PrivateClauseOps, ReductionClauseOps>;

using SimdOperands =
detail::Clauses<AlignedClauseOps, IfClauseOps, LinearClauseOps,
NontemporalClauseOps, OrderClauseOps, PrivateClauseOps,
ReductionClauseOps, SafelenClauseOps, SimdlenClauseOps>;

using SingleOperands = detail::Clauses<AllocateClauseOps, CopyprivateClauseOps,
NowaitClauseOps, PrivateClauseOps>;

// TODO `defaultmap`, `uses_allocators` clauses.
using TargetOperands =
detail::Clauses<AllocateClauseOps, DependClauseOps, DeviceClauseOps,
HasDeviceAddrClauseOps, IfClauseOps, InReductionClauseOps,
IsDevicePtrClauseOps, MapClauseOps, NowaitClauseOps,
PrivateClauseOps, ThreadLimitClauseOps>;

using TargetDataOperands =
detail::Clauses<DeviceClauseOps, IfClauseOps, MapClauseOps,
UseDeviceAddrClauseOps, UseDevicePtrClauseOps>;

using TargetEnterExitUpdateDataOperands =
detail::Clauses<DependClauseOps, DeviceClauseOps, IfClauseOps, MapClauseOps,
NowaitClauseOps>;

// TODO `affinity`, `detach` clauses.
using TaskOperands =
detail::Clauses<AllocateClauseOps, DependClauseOps, FinalClauseOps,
IfClauseOps, InReductionClauseOps, MergeableClauseOps,
PriorityClauseOps, PrivateClauseOps, UntiedClauseOps>;

using TaskgroupOperands =
detail::Clauses<AllocateClauseOps, TaskReductionClauseOps>;

using TaskloopOperands =
detail::Clauses<AllocateClauseOps, FinalClauseOps, GrainsizeClauseOps,
IfClauseOps, InReductionClauseOps, MergeableClauseOps,
NogroupClauseOps, NumTasksClauseOps, PriorityClauseOps,
PrivateClauseOps, ReductionClauseOps, UntiedClauseOps>;

using TaskwaitOperands = detail::Clauses<DependClauseOps, NowaitClauseOps>;

using TeamsOperands =
detail::Clauses<AllocateClauseOps, IfClauseOps, NumTeamsClauseOps,
PrivateClauseOps, ReductionClauseOps, ThreadLimitClauseOps>;

using WsloopOperands =
detail::Clauses<AllocateClauseOps, LinearClauseOps, NowaitClauseOps,
OrderClauseOps, OrderedClauseOps, PrivateClauseOps,
ReductionClauseOps, ScheduleClauseOps>;
/// omp.target_enter_data, omp.target_exit_data and omp.target_update take the
/// same clauses, so we give the structure to be shared by all of them a
/// representative name.
using TargetEnterExitUpdateDataOperands = TargetEnterDataOperands;

} // namespace omp
} // namespace mlir
Expand Down
Loading
Loading