[Mlir-commits] [mlir] 10e0878 - [MLIR][OpenMP][NFC] Moved Synchronization Hint related functions
Shraiysh Vaishay
llvmlistbot at llvm.org
Tue Oct 19 07:08:40 PDT 2021
Author: Shraiysh Vaishay
Date: 2021-10-19T19:38:31+05:30
New Revision: 10e08784ca27028c2f88e946d3cb0d2696f9b8f5
URL: https://github.com/llvm/llvm-project/commit/10e08784ca27028c2f88e946d3cb0d2696f9b8f5
DIFF: https://github.com/llvm/llvm-project/commit/10e08784ca27028c2f88e946d3cb0d2696f9b8f5.diff
LOG: [MLIR][OpenMP][NFC] Moved Synchronization Hint related functions
The functions are moved above the parseClauses function as they
will be used inside it to parse `hint` clause
Reviewed By: clementval
Differential Revision: https://reviews.llvm.org/D112071
Added:
Modified:
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index ebd0e0ba8bf9..5a73850042c0 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -370,6 +370,97 @@ static LogicalResult verifyReductionVarList(Operation *op,
return success();
}
+//===----------------------------------------------------------------------===//
+// Parser, printer and verifier for Synchronization Hint (2.17.12)
+//===----------------------------------------------------------------------===//
+
+/// Parses a Synchronization Hint clause. The value of hint is an integer
+/// which is a combination of
diff erent hints from `omp_sync_hint_t`.
+///
+/// hint-clause = `hint` `(` hint-value `)`
+static ParseResult parseSynchronizationHint(OpAsmParser &parser,
+ IntegerAttr &hintAttr) {
+ if (failed(parser.parseOptionalKeyword("hint"))) {
+ hintAttr = IntegerAttr::get(parser.getBuilder().getI64Type(), 0);
+ return success();
+ }
+
+ if (failed(parser.parseLParen()))
+ return failure();
+ StringRef hintKeyword;
+ int64_t hint = 0;
+ do {
+ if (failed(parser.parseKeyword(&hintKeyword)))
+ return failure();
+ if (hintKeyword == "uncontended")
+ hint |= 1;
+ else if (hintKeyword == "contended")
+ hint |= 2;
+ else if (hintKeyword == "nonspeculative")
+ hint |= 4;
+ else if (hintKeyword == "speculative")
+ hint |= 8;
+ else
+ return parser.emitError(parser.getCurrentLocation())
+ << hintKeyword << " is not a valid hint";
+ } while (succeeded(parser.parseOptionalComma()));
+ if (failed(parser.parseRParen()))
+ return failure();
+ hintAttr = IntegerAttr::get(parser.getBuilder().getI64Type(), hint);
+ return success();
+}
+
+/// Prints a Synchronization Hint clause
+static void printSynchronizationHint(OpAsmPrinter &p, Operation *op,
+ IntegerAttr hintAttr) {
+ int64_t hint = hintAttr.getInt();
+
+ if (hint == 0)
+ return;
+
+ // Helper function to get n-th bit from the right end of `value`
+ auto bitn = [](int value, int n) -> bool { return value & (1 << n); };
+
+ bool uncontended = bitn(hint, 0);
+ bool contended = bitn(hint, 1);
+ bool nonspeculative = bitn(hint, 2);
+ bool speculative = bitn(hint, 3);
+
+ SmallVector<StringRef> hints;
+ if (uncontended)
+ hints.push_back("uncontended");
+ if (contended)
+ hints.push_back("contended");
+ if (nonspeculative)
+ hints.push_back("nonspeculative");
+ if (speculative)
+ hints.push_back("speculative");
+
+ p << "hint(";
+ llvm::interleaveComma(hints, p);
+ p << ")";
+}
+
+/// Verifies a synchronization hint clause
+static LogicalResult verifySynchronizationHint(Operation *op, int32_t hint) {
+
+ // Helper function to get n-th bit from the right end of `value`
+ auto bitn = [](int value, int n) -> bool { return value & (1 << n); };
+
+ bool uncontended = bitn(hint, 0);
+ bool contended = bitn(hint, 1);
+ bool nonspeculative = bitn(hint, 2);
+ bool speculative = bitn(hint, 3);
+
+ if (uncontended && contended)
+ return op->emitOpError() << "the hints omp_sync_hint_uncontended and "
+ "omp_sync_hint_contended cannot be combined";
+ if (nonspeculative && speculative)
+ return op->emitOpError() << "the hints omp_sync_hint_nonspeculative and "
+ "omp_sync_hint_speculative cannot be combined.";
+ return success();
+}
+
enum ClauseType {
ifClause,
numThreadsClause,
@@ -1015,97 +1106,6 @@ static LogicalResult verifyWsLoopOp(WsLoopOp op) {
return verifyReductionVarList(op, op.reductions(), op.reduction_vars());
}
-//===----------------------------------------------------------------------===//
-// Parser, printer and verifier for Synchronization Hint (2.17.12)
-//===----------------------------------------------------------------------===//
-
-/// Parses a Synchronization Hint clause. The value of hint is an integer
-/// which is a combination of
diff erent hints from `omp_sync_hint_t`.
-///
-/// hint-clause = `hint` `(` hint-value `)`
-static ParseResult parseSynchronizationHint(OpAsmParser &parser,
- IntegerAttr &hintAttr) {
- if (failed(parser.parseOptionalKeyword("hint"))) {
- hintAttr = IntegerAttr::get(parser.getBuilder().getI64Type(), 0);
- return success();
- }
-
- if (failed(parser.parseLParen()))
- return failure();
- StringRef hintKeyword;
- int64_t hint = 0;
- do {
- if (failed(parser.parseKeyword(&hintKeyword)))
- return failure();
- if (hintKeyword == "uncontended")
- hint |= 1;
- else if (hintKeyword == "contended")
- hint |= 2;
- else if (hintKeyword == "nonspeculative")
- hint |= 4;
- else if (hintKeyword == "speculative")
- hint |= 8;
- else
- return parser.emitError(parser.getCurrentLocation())
- << hintKeyword << " is not a valid hint";
- } while (succeeded(parser.parseOptionalComma()));
- if (failed(parser.parseRParen()))
- return failure();
- hintAttr = IntegerAttr::get(parser.getBuilder().getI64Type(), hint);
- return success();
-}
-
-/// Prints a Synchronization Hint clause
-static void printSynchronizationHint(OpAsmPrinter &p, Operation *op,
- IntegerAttr hintAttr) {
- int64_t hint = hintAttr.getInt();
-
- if (hint == 0)
- return;
-
- // Helper function to get n-th bit from the right end of `value`
- auto bitn = [](int value, int n) -> bool { return value & (1 << n); };
-
- bool uncontended = bitn(hint, 0);
- bool contended = bitn(hint, 1);
- bool nonspeculative = bitn(hint, 2);
- bool speculative = bitn(hint, 3);
-
- SmallVector<StringRef> hints;
- if (uncontended)
- hints.push_back("uncontended");
- if (contended)
- hints.push_back("contended");
- if (nonspeculative)
- hints.push_back("nonspeculative");
- if (speculative)
- hints.push_back("speculative");
-
- p << "hint(";
- llvm::interleaveComma(hints, p);
- p << ")";
-}
-
-/// Verifies a synchronization hint clause
-static LogicalResult verifySynchronizationHint(Operation *op, int32_t hint) {
-
- // Helper function to get n-th bit from the right end of `value`
- auto bitn = [](int value, int n) -> bool { return value & (1 << n); };
-
- bool uncontended = bitn(hint, 0);
- bool contended = bitn(hint, 1);
- bool nonspeculative = bitn(hint, 2);
- bool speculative = bitn(hint, 3);
-
- if (uncontended && contended)
- return op->emitOpError() << "the hints omp_sync_hint_uncontended and "
- "omp_sync_hint_contended cannot be combined";
- if (nonspeculative && speculative)
- return op->emitOpError() << "the hints omp_sync_hint_nonspeculative and "
- "omp_sync_hint_speculative cannot be combined.";
- return success();
-}
-
//===----------------------------------------------------------------------===//
// Verifier for critical construct (2.17.1)
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list