[MLIR][OpenMP][NFC] Moved Synchronization Hint related functions
authorShraiysh Vaishay <Shraiysh.Vaishay@amd.com>
Tue, 19 Oct 2021 13:38:29 +0000 (19:08 +0530)
committerShraiysh Vaishay <Shraiysh.Vaishay@amd.com>
Tue, 19 Oct 2021 14:08:31 +0000 (19:38 +0530)
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

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

index ebd0e0b..5a73850 100644 (file)
@@ -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 different 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,
@@ -1016,97 +1107,6 @@ static LogicalResult verifyWsLoopOp(WsLoopOp op) {
 }
 
 //===----------------------------------------------------------------------===//
-// 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 different 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)
 //===----------------------------------------------------------------------===//