Skip to content

Commit ff3341c

Browse files
authored
[MLIR][OpenMP] Simplify OpenMP to LLVM dialect conversion (#132009)
This patch makes a few changes to unify the conversion process from the 'omp' to the 'llvm' dialect. The main goal of this change is to consolidate the logic used to identify legal and illegal ops, and to consolidate the conversion logic into a single class. Changes introduced are the following: - Removal of `getNumVariableOperands()` and `getVariableOperand()` extra class declarations from OpenMP operations. These are redundant, as they are equivalent to `mlir::Operation::getNumOperands()` and `mlir::Operation::getOperands()`, respectively. - Consolidation of `RegionOpConversion`, `RegionLessOpWithVarOperandsConversion`, `RegionOpWithVarOperandsConversion`, `RegionLessOpConversion`, `AtomicReadOpConversion`, `MapInfoOpConversion`, `DeclMapperOpConversion` and `MultiRegionOpConversion` into a single `OpenMPOpConversion` class. This is possible because all of the previous were doing parts of the same set of operations based on whether they defined any regions, whether they took operands, type attributes, etc. - Update of `mlir::configureOpenMPToLLVMConversionLegality` to use a single generic set of checks for all operations, removing the need to list every operation manually. - Update of `mlir::populateOpenMPToLLVMConversionPatterns` to automatically populate the list of patterns to include all dialect operations.
1 parent 55d3a55 commit ff3341c

File tree

2 files changed

+77
-344
lines changed

2 files changed

+77
-344
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -891,17 +891,6 @@ def FlushOp : OpenMP_Op<"flush", clauses = [
891891

892892
// Override inherited assembly format to include `varList`.
893893
let assemblyFormat = "( `(` $varList^ `:` type($varList) `)` )? attr-dict";
894-
895-
let extraClassDeclaration = [{
896-
/// The number of variable operands.
897-
unsigned getNumVariableOperands() {
898-
return getOperation()->getNumOperands();
899-
}
900-
/// The i-th variable operand passed.
901-
Value getVariableOperand(unsigned i) {
902-
return getOperand(i);
903-
}
904-
}] # clausesExtraClassDeclaration;
905894
}
906895

907896
//===----------------------------------------------------------------------===//
@@ -1001,18 +990,6 @@ def MapBoundsOp : OpenMP_Op<"map.bounds",
1001990
) attr-dict
1002991
}];
1003992

1004-
let extraClassDeclaration = [{
1005-
/// The number of variable operands.
1006-
unsigned getNumVariableOperands() {
1007-
return getNumOperands();
1008-
}
1009-
1010-
/// The i-th variable operand passed.
1011-
Value getVariableOperand(unsigned i) {
1012-
return getOperands()[i];
1013-
}
1014-
}];
1015-
1016993
let hasVerifier = 1;
1017994
}
1018995

@@ -1098,18 +1075,6 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> {
10981075
| `bounds` `(` $bounds `)`
10991076
) `->` type($omp_ptr) attr-dict
11001077
}];
1101-
1102-
let extraClassDeclaration = [{
1103-
/// The number of variable operands.
1104-
unsigned getNumVariableOperands() {
1105-
return getNumOperands();
1106-
}
1107-
1108-
/// The i-th variable operand passed.
1109-
Value getVariableOperand(unsigned i) {
1110-
return getOperands()[i];
1111-
}
1112-
}];
11131078
}
11141079

11151080
//===---------------------------------------------------------------------===//
@@ -1515,21 +1480,6 @@ def AtomicReadOp : OpenMP_Op<"atomic.read", traits = [
15151480
clausesOptAssemblyFormat #
15161481
") `:` type($v) `,` type($x) `,` $element_type attr-dict";
15171482

1518-
let extraClassDeclaration = [{
1519-
/// The number of variable operands.
1520-
unsigned getNumVariableOperands() {
1521-
assert(getX() && "expected 'x' operand");
1522-
assert(getV() && "expected 'v' operand");
1523-
return 2;
1524-
}
1525-
1526-
/// The i-th variable operand passed.
1527-
Value getVariableOperand(unsigned i) {
1528-
assert(i < 2 && "invalid index position for an operand");
1529-
return i == 0 ? getX() : getV();
1530-
}
1531-
}] # clausesExtraClassDeclaration;
1532-
15331483
let hasVerifier = 1;
15341484
}
15351485

@@ -1555,21 +1505,6 @@ def AtomicWriteOp : OpenMP_Op<"atomic.write", traits = [
15551505
let assemblyFormat = "$x `=` $expr" # clausesReqAssemblyFormat # " oilist(" #
15561506
clausesOptAssemblyFormat # ") `:` type($x) `,` type($expr) attr-dict";
15571507

1558-
let extraClassDeclaration = [{
1559-
/// The number of variable operands.
1560-
unsigned getNumVariableOperands() {
1561-
assert(getX() && "expected address operand");
1562-
assert(getExpr() && "expected value operand");
1563-
return 2;
1564-
}
1565-
1566-
/// The i-th variable operand passed.
1567-
Value getVariableOperand(unsigned i) {
1568-
assert(i < 2 && "invalid index position for an operand");
1569-
return i == 0 ? getX() : getExpr();
1570-
}
1571-
}] # clausesExtraClassDeclaration;
1572-
15731508
let hasVerifier = 1;
15741509
}
15751510

@@ -1614,20 +1549,6 @@ def AtomicUpdateOp : OpenMP_Op<"atomic.update", traits = [
16141549
let assemblyFormat = clausesAssemblyFormat #
16151550
"$x `:` type($x) $region attr-dict";
16161551

1617-
let extraClassDeclaration = [{
1618-
/// The number of variable operands.
1619-
unsigned getNumVariableOperands() {
1620-
assert(getX() && "expected 'x' operand");
1621-
return 1;
1622-
}
1623-
1624-
/// The i-th variable operand passed.
1625-
Value getVariableOperand(unsigned i) {
1626-
assert(i == 0 && "invalid index position for an operand");
1627-
return getX();
1628-
}
1629-
}] # clausesExtraClassDeclaration;
1630-
16311552
let hasVerifier = 1;
16321553
let hasRegionVerifier = 1;
16331554
let hasCanonicalizeMethod = 1;
@@ -1715,19 +1636,6 @@ def ThreadprivateOp : OpenMP_Op<"threadprivate",
17151636
let assemblyFormat = [{
17161637
$sym_addr `:` type($sym_addr) `->` type($tls_addr) attr-dict
17171638
}];
1718-
let extraClassDeclaration = [{
1719-
/// The number of variable operands.
1720-
unsigned getNumVariableOperands() {
1721-
assert(getSymAddr() && "expected one variable operand");
1722-
return 1;
1723-
}
1724-
1725-
/// The i-th variable operand passed.
1726-
Value getVariableOperand(unsigned i) {
1727-
assert(i == 0 && "invalid index position for an operand");
1728-
return getSymAddr();
1729-
}
1730-
}];
17311639
}
17321640

17331641
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)