forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MLIR][OpenMP] NFC: Split OpenMP dialect definitions (llvm#91741)
This patch splits definitions for the OpenMP dialect into multiple files to simplify the addition of new features, reduce merge conflicts, make it easier to understand, etc. The split is based on the structure of the more mature LLVMIR dialect. More specifically: - The OpenMP dialect definition is located in OpenMPDialect.td. - Base classes for OpenMP operations and types, as well as generic OpenMP types are moved to OpenMPOpBase.td. - OpenMP enumeration attributes, their case attributes and shared base classes for these are placed in OpenMPEnums.td. - Other OpenMP attributes are separated into OpenMPAttrDefs.td. - OpenMPOps.td only contains operation definitions. Even though this change should be useful on its own, it is intended as a precursor to a follow-up PR in which operation arguments and attributes are split into clause-specific classes which are then shared by all operations to which they apply to. Without this prior change, that approach would make the OpenMPOps.td file harder to navigate.
- Loading branch information
Showing
6 changed files
with
371 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//=== OpenMPAttrDefs.td - OpenMP Attributes definition -----*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef OPENMP_ATTR_DEFS | ||
#define OPENMP_ATTR_DEFS | ||
|
||
include "mlir/Dialect/OpenMP/OpenMPDialect.td" | ||
include "mlir/Dialect/OpenMP/OpenMPEnums.td" | ||
include "mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td" | ||
include "mlir/Dialect/OpenMP/OpenMPTypeInterfaces.td" | ||
include "mlir/IR/AttrTypeBase.td" | ||
include "mlir/IR/CommonAttrConstraints.td" | ||
|
||
class OpenMP_Attr<string name, string attrMnemonic, list<Trait> traits = [], | ||
string baseCppClass = "::mlir::Attribute"> | ||
: AttrDef<OpenMP_Dialect, name, traits, baseCppClass> { | ||
let mnemonic = attrMnemonic; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DeclareTargetAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DeclareTargetAttr : OpenMP_Attr<"DeclareTarget", "declaretarget"> { | ||
let parameters = (ins | ||
OptionalParameter<"DeclareTargetDeviceTypeAttr">:$device_type, | ||
OptionalParameter<"DeclareTargetCaptureClauseAttr">:$capture_clause | ||
); | ||
|
||
let assemblyFormat = "`<` struct(params) `>`"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// FlagsAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Runtime library flags attribute that holds information for lowering to LLVM. | ||
def FlagsAttr : OpenMP_Attr<"Flags", "flags"> { | ||
let parameters = (ins | ||
DefaultValuedParameter<"uint32_t", "0">:$debug_kind, | ||
DefaultValuedParameter<"bool", "false">:$assume_teams_oversubscription, | ||
DefaultValuedParameter<"bool", "false">:$assume_threads_oversubscription, | ||
DefaultValuedParameter<"bool", "false">:$assume_no_thread_state, | ||
DefaultValuedParameter<"bool", "false">:$assume_no_nested_parallelism, | ||
DefaultValuedParameter<"bool", "false">:$no_gpu_lib, | ||
DefaultValuedParameter<"uint32_t", "50">:$openmp_device_version | ||
); | ||
|
||
let assemblyFormat = "`<` struct(params) `>`"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// TaskDependArrayAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def TaskDependArrayAttr | ||
: TypedArrayAttrBase<ClauseTaskDependAttr, | ||
ClauseTaskDependAttr.summary # " array"> { | ||
let constBuilderCall = ?; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// VersionAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def VersionAttr : OpenMP_Attr<"Version", "version"> { | ||
let parameters = (ins | ||
"uint32_t":$version | ||
); | ||
|
||
let assemblyFormat = "`<` struct(params) `>`"; | ||
} | ||
|
||
#endif // OPENMP_ATTR_DEFS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===- OpenMPDialect.td - OpenMP dialect definition --------*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef OPENMP_DIALECT | ||
#define OPENMP_DIALECT | ||
|
||
include "mlir/IR/DialectBase.td" | ||
|
||
def OpenMP_Dialect : Dialect { | ||
let name = "omp"; | ||
let cppNamespace = "::mlir::omp"; | ||
let dependentDialects = ["::mlir::LLVM::LLVMDialect, ::mlir::func::FuncDialect"]; | ||
let useDefaultAttributePrinterParser = 1; | ||
let useDefaultTypePrinterParser = 1; | ||
} | ||
|
||
#endif // OPENMP_DIALECT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
//===-- OpenMPEnums.td - OpenMP dialect enum file ----------*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef OPENMP_ENUMS | ||
#define OPENMP_ENUMS | ||
|
||
include "mlir/Dialect/OpenMP/OpenMPDialect.td" | ||
include "mlir/IR/EnumAttr.td" | ||
|
||
include "mlir/Dialect/OpenMP/OmpCommon.td" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Base classes for OpenMP enum attributes. | ||
//===----------------------------------------------------------------------===// | ||
|
||
class OpenMP_I32EnumAttr<string name, string summary, | ||
list<I32EnumAttrCase> cases> | ||
: I32EnumAttr<name, summary, cases> { | ||
let genSpecializedAttr = 0; | ||
let cppNamespace = "::mlir::omp"; | ||
} | ||
|
||
class OpenMP_BitEnumAttr<string name, string summary, | ||
list<BitEnumAttrCaseBase> cases> | ||
: I32BitEnumAttr<name, summary, cases> { | ||
let genSpecializedAttr = 0; | ||
let cppNamespace = "::mlir::omp"; | ||
} | ||
|
||
class OpenMP_EnumAttr<EnumAttrInfo enumInfo, string name> | ||
: EnumAttr<OpenMP_Dialect, enumInfo, name>; | ||
|
||
|
||
//===----------------------------------------------------------------------===// | ||
// capture_clause enum. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def CaptureClauseTo : I32EnumAttrCase<"to", 0>; | ||
def CaptureClauseLink : I32EnumAttrCase<"link", 1>; | ||
def CaptureClauseEnter : I32EnumAttrCase<"enter", 2>; | ||
|
||
def DeclareTargetCaptureClause : OpenMP_I32EnumAttr< | ||
"DeclareTargetCaptureClause", | ||
"capture clause", [ | ||
CaptureClauseTo, | ||
CaptureClauseLink, | ||
CaptureClauseEnter | ||
]>; | ||
|
||
def DeclareTargetCaptureClauseAttr : OpenMP_EnumAttr<DeclareTargetCaptureClause, | ||
"capture_clause"> { | ||
let assemblyFormat = "`(` $value `)`"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// clause_depend enum. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def ClauseDependSource : I32EnumAttrCase<"dependsource", 0>; | ||
def ClauseDependSink : I32EnumAttrCase<"dependsink", 1>; | ||
|
||
def ClauseDepend : OpenMP_I32EnumAttr< | ||
"ClauseDepend", | ||
"depend clause", [ | ||
ClauseDependSource, | ||
ClauseDependSink | ||
]>; | ||
|
||
def ClauseDependAttr : OpenMP_EnumAttr<ClauseDepend, "clause_depend"> { | ||
let assemblyFormat = "`(` $value `)`"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// clause_requires enum. | ||
//===----------------------------------------------------------------------===// | ||
|
||
// atomic_default_mem_order clause values not defined here because they can be | ||
// represented by the OMPC_MemoryOrder enumeration instead. | ||
def ClauseRequiresNone : I32BitEnumAttrCaseNone<"none">; | ||
def ClauseRequiresReverseOffload : I32BitEnumAttrCaseBit<"reverse_offload", 0>; | ||
def ClauseRequiresUnifiedAddress : I32BitEnumAttrCaseBit<"unified_address", 1>; | ||
def ClauseRequiresUnifiedSharedMemory | ||
: I32BitEnumAttrCaseBit<"unified_shared_memory", 2>; | ||
def ClauseRequiresDynamicAllocators | ||
: I32BitEnumAttrCaseBit<"dynamic_allocators", 3>; | ||
|
||
def ClauseRequires : OpenMP_BitEnumAttr< | ||
"ClauseRequires", | ||
"requires clauses", [ | ||
ClauseRequiresNone, | ||
ClauseRequiresReverseOffload, | ||
ClauseRequiresUnifiedAddress, | ||
ClauseRequiresUnifiedSharedMemory, | ||
ClauseRequiresDynamicAllocators | ||
]>; | ||
|
||
def ClauseRequiresAttr : OpenMP_EnumAttr<ClauseRequires, "clause_requires">; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// clause_task_depend enum. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def ClauseTaskDependIn : I32EnumAttrCase<"taskdependin", 0>; | ||
def ClauseTaskDependOut : I32EnumAttrCase<"taskdependout", 1>; | ||
def ClauseTaskDependInOut : I32EnumAttrCase<"taskdependinout", 2>; | ||
|
||
def ClauseTaskDepend : OpenMP_I32EnumAttr< | ||
"ClauseTaskDepend", | ||
"depend clause in a target or task construct", [ | ||
ClauseTaskDependIn, | ||
ClauseTaskDependOut, | ||
ClauseTaskDependInOut | ||
]>; | ||
|
||
def ClauseTaskDependAttr : OpenMP_EnumAttr<ClauseTaskDepend, | ||
"clause_task_depend"> { | ||
let assemblyFormat = "`(` $value `)`"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// data_sharing_type enum. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DataSharingTypePrivate : I32EnumAttrCase<"Private", 0, "private">; | ||
def DataSharingTypeFirstPrivate | ||
: I32EnumAttrCase<"FirstPrivate", 1, "firstprivate">; | ||
|
||
def DataSharingClauseType : OpenMP_I32EnumAttr< | ||
"DataSharingClauseType", | ||
"Type of a data-sharing clause", [ | ||
DataSharingTypePrivate, | ||
DataSharingTypeFirstPrivate | ||
]>; | ||
|
||
def DataSharingClauseTypeAttr : OpenMP_EnumAttr<DataSharingClauseType, | ||
"data_sharing_type"> { | ||
let assemblyFormat = "`{` `type` `=` $value `}`"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// device_type enum. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DeviceTypeAny : I32EnumAttrCase<"any", 0>; | ||
def DeviceTypeHost : I32EnumAttrCase<"host", 1>; | ||
def DeviceTypeNoHost : I32EnumAttrCase<"nohost", 2>; | ||
|
||
def DeclareTargetDeviceType : OpenMP_I32EnumAttr< | ||
"DeclareTargetDeviceType", | ||
"device_type clause", [ | ||
DeviceTypeAny, | ||
DeviceTypeHost, | ||
DeviceTypeNoHost | ||
]>; | ||
|
||
def DeclareTargetDeviceTypeAttr : OpenMP_EnumAttr<DeclareTargetDeviceType, | ||
"device_type"> { | ||
let assemblyFormat = "`(` $value `)`"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// sched_mod enum. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def OpenMP_ScheduleModNone : I32EnumAttrCase<"none", 0>; | ||
def OpenMP_ScheduleModMonotonic : I32EnumAttrCase<"monotonic", 1>; | ||
def OpenMP_ScheduleModNonmonotonic : I32EnumAttrCase<"nonmonotonic", 2>; | ||
// FIXME: remove this value for the modifier because this is handled using a | ||
// separate attribute | ||
def OpenMP_ScheduleModSimd : I32EnumAttrCase<"simd", 3>; | ||
|
||
def ScheduleModifier : OpenMP_I32EnumAttr< | ||
"ScheduleModifier", | ||
"OpenMP Schedule Modifier", [ | ||
OpenMP_ScheduleModNone, | ||
OpenMP_ScheduleModMonotonic, | ||
OpenMP_ScheduleModNonmonotonic, | ||
OpenMP_ScheduleModSimd | ||
]>; | ||
|
||
def ScheduleModifierAttr : OpenMP_EnumAttr<ScheduleModifier, "sched_mod">; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// variable_capture_kind enum. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def CaptureThis : I32EnumAttrCase<"This", 0>; | ||
def CaptureByRef : I32EnumAttrCase<"ByRef", 1>; | ||
def CaptureByCopy : I32EnumAttrCase<"ByCopy", 2>; | ||
def CaptureVLAType : I32EnumAttrCase<"VLAType", 3>; | ||
|
||
def VariableCaptureKind : OpenMP_I32EnumAttr< | ||
"VariableCaptureKind", | ||
"variable capture kind", [ | ||
CaptureThis, | ||
CaptureByRef, | ||
CaptureByCopy, | ||
CaptureVLAType | ||
]>; | ||
|
||
def VariableCaptureKindAttr : OpenMP_EnumAttr<VariableCaptureKind, | ||
"variable_capture_kind"> { | ||
let assemblyFormat = "`(` $value `)`"; | ||
} | ||
|
||
#endif // OPENMP_ENUMS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//===- OpenMPOpBase.td - OpenMP dialect shared definitions -*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains shared definitions for the OpenMP dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef OPENMP_OP_BASE | ||
#define OPENMP_OP_BASE | ||
|
||
include "mlir/Dialect/OpenMP/OpenMPAttrDefs.td" | ||
include "mlir/Dialect/OpenMP/OpenMPDialect.td" | ||
include "mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td" | ||
include "mlir/Dialect/OpenMP/OpenMPTypeInterfaces.td" | ||
include "mlir/IR/OpBase.td" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// OpenMP dialect type constraints. | ||
//===----------------------------------------------------------------------===// | ||
|
||
class OpenMP_Type<string name, string typeMnemonic> : | ||
TypeDef<OpenMP_Dialect, name> { | ||
let mnemonic = typeMnemonic; | ||
} | ||
|
||
// Type which can be constraint accepting standard integers and indices. | ||
def IntLikeType : AnyTypeOf<[AnyInteger, Index]>; | ||
|
||
def OpenMP_PointerLikeType : TypeAlias<OpenMP_PointerLikeTypeInterface, | ||
"OpenMP-compatible variable type">; | ||
|
||
def OpenMP_MapBoundsType : OpenMP_Type<"MapBounds", "map_bounds_ty"> { | ||
let summary = "Type for representing omp map clause bounds information"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Base classes for OpenMP dialect operations. | ||
//===----------------------------------------------------------------------===// | ||
|
||
class OpenMP_Op<string mnemonic, list<Trait> traits = []> : | ||
Op<OpenMP_Dialect, mnemonic, traits>; | ||
|
||
#endif // OPENMP_OP_BASE |
Oops, something went wrong.