[Mlir-commits] [mlir] 821fe9e - [MLIR][Presburger] reintroduce int64_t versions of floorDiv, ceilDiv in mlir::presburger namespace

Arjun P llvmlistbot at llvm.org
Fri Jul 15 09:29:23 PDT 2022


Author: Arjun P
Date: 2022-07-15T17:29:31+01:00
New Revision: 821fe9efa4832112071a21a2e6a898069a37d752

URL: https://github.com/llvm/llvm-project/commit/821fe9efa4832112071a21a2e6a898069a37d752
DIFF: https://github.com/llvm/llvm-project/commit/821fe9efa4832112071a21a2e6a898069a37d752.diff

LOG: [MLIR][Presburger] reintroduce int64_t versions of floorDiv, ceilDiv in mlir::presburger namespace

This is useful because MPInt.h defines identically-named functions that
operate on MPInts, which would otherwie become the only candidates of
overload resolution when calling e.g. ceilDiv from the mlir::presburger
namespace (iff MPInt.h is included). So to access the 64-bit overloads, an
explict call to mlir::ceilDiv would be required. This patch adds `using`
declarations allowing overload resolution to transparently call the right
function.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D129820

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/Presburger/MPInt.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/MPInt.h b/mlir/include/mlir/Analysis/Presburger/MPInt.h
index a979107cd7c1..0017715adcaa 100644
--- a/mlir/include/mlir/Analysis/Presburger/MPInt.h
+++ b/mlir/include/mlir/Analysis/Presburger/MPInt.h
@@ -23,6 +23,17 @@
 namespace mlir {
 namespace presburger {
 
+/// Redefine these functions, which operate on 64-bit ints, to also be part of
+/// the mlir::presburger namespace. This is useful because this file defines
+/// identically-named functions that operate on MPInts, which would otherwie
+/// become the only candidates of overload resolution when calling e.g. ceilDiv
+/// from the mlir::presburger namespace. So to access the 64-bit overloads, an
+/// explict call to mlir::ceilDiv would be required. These using declarations
+/// allow overload resolution to transparently call the right function.
+using ::mlir::ceilDiv;
+using ::mlir::floorDiv;
+using ::mlir::mod;
+
 namespace detail {
 /// If builtin intrinsics for overflow-checked arithmetic are available,
 /// use them. Otherwise, call through to LLVM's overflow-checked arithmetic
@@ -362,7 +373,7 @@ LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt ceilDiv(const MPInt &lhs, const MPInt &rhs) {
   if (LLVM_LIKELY(lhs.isSmall() && rhs.isSmall())) {
     if (LLVM_UNLIKELY(detail::divWouldOverflow(lhs.getSmall(), rhs.getSmall())))
       return -lhs;
-    return MPInt(mlir::ceilDiv(lhs.getSmall(), rhs.getSmall()));
+    return MPInt(ceilDiv(lhs.getSmall(), rhs.getSmall()));
   }
   return MPInt(ceilDiv(detail::SlowMPInt(lhs), detail::SlowMPInt(rhs)));
 }
@@ -371,7 +382,7 @@ LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt floorDiv(const MPInt &lhs,
   if (LLVM_LIKELY(lhs.isSmall() && rhs.isSmall())) {
     if (LLVM_UNLIKELY(detail::divWouldOverflow(lhs.getSmall(), rhs.getSmall())))
       return -lhs;
-    return MPInt(mlir::floorDiv(lhs.getSmall(), rhs.getSmall()));
+    return MPInt(floorDiv(lhs.getSmall(), rhs.getSmall()));
   }
   return MPInt(floorDiv(detail::SlowMPInt(lhs), detail::SlowMPInt(rhs)));
 }
@@ -379,7 +390,7 @@ LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt floorDiv(const MPInt &lhs,
 /// is always non-negative.
 LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mod(const MPInt &lhs, const MPInt &rhs) {
   if (LLVM_LIKELY(lhs.isSmall() && rhs.isSmall()))
-    return MPInt(mlir::mod(lhs.getSmall(), rhs.getSmall()));
+    return MPInt(mod(lhs.getSmall(), rhs.getSmall()));
   return MPInt(mod(detail::SlowMPInt(lhs), detail::SlowMPInt(rhs)));
 }
 


        


More information about the Mlir-commits mailing list