Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #95218 and #94953 #95244

Merged
merged 2 commits into from
Jun 12, 2024
Merged

Revert #95218 and #94953 #95244

merged 2 commits into from
Jun 12, 2024

Conversation

makslevental
Copy link
Contributor

@makslevental makslevental commented Jun 12, 2024

Reverts #95218 and #94953 which broke for all release builds without LLVM_ENABLE_DUMP=ON. Which is probably the majority of builds since it is off by default.

Next time please revert instead of fixing forward.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 12, 2024

@llvm/pr-subscribers-mlir-core
@llvm/pr-subscribers-mlir-llvm
@llvm/pr-subscribers-mlir-presburger
@llvm/pr-subscribers-llvm-adt

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

Changes

Reverts #95218 and #94953. Next time please revert instead of fixing forward.


Patch is 244.08 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95244.diff

40 Files Affected:

  • (removed) llvm/include/llvm/ADT/DynamicAPInt.h (-640)
  • (removed) llvm/include/llvm/ADT/SlowDynamicAPInt.h (-140)
  • (modified) llvm/lib/Support/CMakeLists.txt (-2)
  • (removed) llvm/lib/Support/DynamicAPInt.cpp (-29)
  • (removed) llvm/lib/Support/SlowDynamicAPInt.cpp (-288)
  • (modified) llvm/unittests/ADT/CMakeLists.txt (-1)
  • (removed) llvm/unittests/ADT/DynamicAPIntTest.cpp (-200)
  • (modified) mlir/include/mlir/Analysis/Presburger/Barvinok.h (+1-1)
  • (modified) mlir/include/mlir/Analysis/Presburger/Fraction.h (+23-29)
  • (modified) mlir/include/mlir/Analysis/Presburger/IntegerRelation.h (+43-59)
  • (modified) mlir/include/mlir/Analysis/Presburger/LinearTransform.h (+2-4)
  • (added) mlir/include/mlir/Analysis/Presburger/MPInt.h (+611)
  • (modified) mlir/include/mlir/Analysis/Presburger/Matrix.h (+13-13)
  • (modified) mlir/include/mlir/Analysis/Presburger/PWMAFunction.h (+7-11)
  • (modified) mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h (+4-4)
  • (modified) mlir/include/mlir/Analysis/Presburger/Simplex.h (+20-21)
  • (added) mlir/include/mlir/Analysis/Presburger/SlowMPInt.h (+135)
  • (modified) mlir/include/mlir/Analysis/Presburger/Utils.h (+28-34)
  • (modified) mlir/include/mlir/Support/LLVM.h (-2)
  • (modified) mlir/lib/Analysis/FlatLinearValueConstraints.cpp (+1-2)
  • (modified) mlir/lib/Analysis/Presburger/Barvinok.cpp (+3-3)
  • (modified) mlir/lib/Analysis/Presburger/CMakeLists.txt (+2)
  • (modified) mlir/lib/Analysis/Presburger/IntegerRelation.cpp (+92-100)
  • (modified) mlir/lib/Analysis/Presburger/LinearTransform.cpp (+7-6)
  • (added) mlir/lib/Analysis/Presburger/MPInt.cpp (+38)
  • (modified) mlir/lib/Analysis/Presburger/Matrix.cpp (+12-11)
  • (modified) mlir/lib/Analysis/Presburger/PWMAFunction.cpp (+19-20)
  • (modified) mlir/lib/Analysis/Presburger/PresburgerRelation.cpp (+28-30)
  • (modified) mlir/lib/Analysis/Presburger/Simplex.cpp (+84-88)
  • (added) mlir/lib/Analysis/Presburger/SlowMPInt.cpp (+290)
  • (modified) mlir/lib/Analysis/Presburger/Utils.cpp (+64-73)
  • (modified) mlir/unittests/Analysis/Presburger/CMakeLists.txt (+1)
  • (modified) mlir/unittests/Analysis/Presburger/FractionTest.cpp (+1-1)
  • (modified) mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp (+10-12)
  • (modified) mlir/unittests/Analysis/Presburger/LinearTransformTest.cpp (+1-2)
  • (added) mlir/unittests/Analysis/Presburger/MPIntTest.cpp (+200)
  • (modified) mlir/unittests/Analysis/Presburger/MatrixTest.cpp (+1-1)
  • (modified) mlir/unittests/Analysis/Presburger/SimplexTest.cpp (+14-15)
  • (modified) mlir/unittests/Analysis/Presburger/Utils.h (+9-11)
  • (modified) mlir/unittests/Analysis/Presburger/UtilsTest.cpp (+19-28)
diff --git a/llvm/include/llvm/ADT/DynamicAPInt.h b/llvm/include/llvm/ADT/DynamicAPInt.h
deleted file mode 100644
index 78a0372e09c49..0000000000000
--- a/llvm/include/llvm/ADT/DynamicAPInt.h
+++ /dev/null
@@ -1,640 +0,0 @@
-//===- DynamicAPInt.h - DynamicAPInt Class ----------------------*- C++ -*-===//
-//
-// 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 is a simple class to represent arbitrary precision signed integers.
-// Unlike APInt, one does not have to specify a fixed maximum size, and the
-// integer can take on any arbitrary values. This is optimized for small-values
-// by providing fast-paths for the cases when the value stored fits in 64-bits.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ADT_DYNAMICAPINT_H
-#define LLVM_ADT_DYNAMICAPINT_H
-
-#include "llvm/ADT/SlowDynamicAPInt.h"
-#include "llvm/Support/MathExtras.h"
-#include "llvm/Support/raw_ostream.h"
-#include <numeric>
-
-namespace llvm {
-/// This class provides support for dynamic arbitrary-precision arithmetic.
-///
-/// Unlike APInt, this extends the precision as necessary to prevent overflows
-/// and supports operations between objects with differing internal precisions.
-///
-/// This is optimized for small-values by providing fast-paths for the cases
-/// when the value stored fits in 64-bits. We annotate all fastpaths by using
-/// the LLVM_LIKELY/LLVM_UNLIKELY annotations. Removing these would result in
-/// a 1.2x performance slowdown.
-///
-/// We always_inline all operations; removing these results in a 1.5x
-/// performance slowdown.
-///
-/// When HoldsLarge is true, a SlowMPInt is held in the union. If it is false,
-/// the int64_t is held. Using std::variant instead would lead to significantly
-/// worse performance.
-class DynamicAPInt {
-  union {
-    int64_t ValSmall;
-    detail::SlowDynamicAPInt ValLarge;
-  };
-  unsigned HoldsLarge;
-
-  LLVM_ATTRIBUTE_ALWAYS_INLINE void initSmall(int64_t O) {
-    if (LLVM_UNLIKELY(isLarge()))
-      ValLarge.detail::SlowDynamicAPInt::~SlowDynamicAPInt();
-    ValSmall = O;
-    HoldsLarge = false;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE void
-  initLarge(const detail::SlowDynamicAPInt &O) {
-    if (LLVM_LIKELY(isSmall())) {
-      // The data in memory could be in an arbitrary state, not necessarily
-      // corresponding to any valid state of ValLarge; we cannot call any member
-      // functions, e.g. the assignment operator on it, as they may access the
-      // invalid internal state. We instead construct a new object using
-      // placement new.
-      new (&ValLarge) detail::SlowDynamicAPInt(O);
-    } else {
-      // In this case, we need to use the assignment operator, because if we use
-      // placement-new as above we would lose track of allocated memory
-      // and leak it.
-      ValLarge = O;
-    }
-    HoldsLarge = true;
-  }
-
-  LLVM_ATTRIBUTE_ALWAYS_INLINE explicit DynamicAPInt(
-      const detail::SlowDynamicAPInt &Val)
-      : ValLarge(Val), HoldsLarge(true) {}
-  LLVM_ATTRIBUTE_ALWAYS_INLINE bool isSmall() const { return !HoldsLarge; }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE bool isLarge() const { return HoldsLarge; }
-  /// Get the stored value. For getSmall/Large,
-  /// the stored value should be small/large.
-  LLVM_ATTRIBUTE_ALWAYS_INLINE int64_t getSmall() const {
-    assert(isSmall() &&
-           "getSmall should only be called when the value stored is small!");
-    return ValSmall;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE int64_t &getSmall() {
-    assert(isSmall() &&
-           "getSmall should only be called when the value stored is small!");
-    return ValSmall;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE const detail::SlowDynamicAPInt &
-  getLarge() const {
-    assert(isLarge() &&
-           "getLarge should only be called when the value stored is large!");
-    return ValLarge;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE detail::SlowDynamicAPInt &getLarge() {
-    assert(isLarge() &&
-           "getLarge should only be called when the value stored is large!");
-    return ValLarge;
-  }
-  explicit operator detail::SlowDynamicAPInt() const {
-    if (isSmall())
-      return detail::SlowDynamicAPInt(getSmall());
-    return getLarge();
-  }
-
-public:
-  LLVM_ATTRIBUTE_ALWAYS_INLINE explicit DynamicAPInt(int64_t Val)
-      : ValSmall(Val), HoldsLarge(false) {}
-  LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt() : DynamicAPInt(0) {}
-  LLVM_ATTRIBUTE_ALWAYS_INLINE ~DynamicAPInt() {
-    if (LLVM_UNLIKELY(isLarge()))
-      ValLarge.detail::SlowDynamicAPInt::~SlowDynamicAPInt();
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt(const DynamicAPInt &O)
-      : ValSmall(O.ValSmall), HoldsLarge(false) {
-    if (LLVM_UNLIKELY(O.isLarge()))
-      initLarge(O.ValLarge);
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &operator=(const DynamicAPInt &O) {
-    if (LLVM_LIKELY(O.isSmall())) {
-      initSmall(O.ValSmall);
-      return *this;
-    }
-    initLarge(O.ValLarge);
-    return *this;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &operator=(int X) {
-    initSmall(X);
-    return *this;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE explicit operator int64_t() const {
-    if (isSmall())
-      return getSmall();
-    return static_cast<int64_t>(getLarge());
-  }
-
-  bool operator==(const DynamicAPInt &O) const;
-  bool operator!=(const DynamicAPInt &O) const;
-  bool operator>(const DynamicAPInt &O) const;
-  bool operator<(const DynamicAPInt &O) const;
-  bool operator<=(const DynamicAPInt &O) const;
-  bool operator>=(const DynamicAPInt &O) const;
-  DynamicAPInt operator+(const DynamicAPInt &O) const;
-  DynamicAPInt operator-(const DynamicAPInt &O) const;
-  DynamicAPInt operator*(const DynamicAPInt &O) const;
-  DynamicAPInt operator/(const DynamicAPInt &O) const;
-  DynamicAPInt operator%(const DynamicAPInt &O) const;
-  DynamicAPInt &operator+=(const DynamicAPInt &O);
-  DynamicAPInt &operator-=(const DynamicAPInt &O);
-  DynamicAPInt &operator*=(const DynamicAPInt &O);
-  DynamicAPInt &operator/=(const DynamicAPInt &O);
-  DynamicAPInt &operator%=(const DynamicAPInt &O);
-  DynamicAPInt operator-() const;
-  DynamicAPInt &operator++();
-  DynamicAPInt &operator--();
-
-  // Divide by a number that is known to be positive.
-  // This is slightly more efficient because it saves an overflow check.
-  DynamicAPInt divByPositive(const DynamicAPInt &O) const;
-  DynamicAPInt &divByPositiveInPlace(const DynamicAPInt &O);
-
-  friend DynamicAPInt abs(const DynamicAPInt &X);
-  friend DynamicAPInt ceilDiv(const DynamicAPInt &LHS, const DynamicAPInt &RHS);
-  friend DynamicAPInt floorDiv(const DynamicAPInt &LHS,
-                               const DynamicAPInt &RHS);
-  // The operands must be non-negative for gcd.
-  friend DynamicAPInt gcd(const DynamicAPInt &A, const DynamicAPInt &B);
-  friend DynamicAPInt lcm(const DynamicAPInt &A, const DynamicAPInt &B);
-  friend DynamicAPInt mod(const DynamicAPInt &LHS, const DynamicAPInt &RHS);
-
-  /// ---------------------------------------------------------------------------
-  /// Convenience operator overloads for int64_t.
-  /// ---------------------------------------------------------------------------
-  friend DynamicAPInt &operator+=(DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt &operator-=(DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt &operator*=(DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt &operator/=(DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt &operator%=(DynamicAPInt &A, int64_t B);
-
-  friend bool operator==(const DynamicAPInt &A, int64_t B);
-  friend bool operator!=(const DynamicAPInt &A, int64_t B);
-  friend bool operator>(const DynamicAPInt &A, int64_t B);
-  friend bool operator<(const DynamicAPInt &A, int64_t B);
-  friend bool operator<=(const DynamicAPInt &A, int64_t B);
-  friend bool operator>=(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator+(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator-(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator*(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator/(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator%(const DynamicAPInt &A, int64_t B);
-
-  friend bool operator==(int64_t A, const DynamicAPInt &B);
-  friend bool operator!=(int64_t A, const DynamicAPInt &B);
-  friend bool operator>(int64_t A, const DynamicAPInt &B);
-  friend bool operator<(int64_t A, const DynamicAPInt &B);
-  friend bool operator<=(int64_t A, const DynamicAPInt &B);
-  friend bool operator>=(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator+(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator-(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator*(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator/(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator%(int64_t A, const DynamicAPInt &B);
-
-  friend hash_code hash_value(const DynamicAPInt &x); // NOLINT
-
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-  raw_ostream &print(raw_ostream &OS) const;
-  LLVM_DUMP_METHOD void dump() const;
-#endif
-};
-
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-inline raw_ostream &operator<<(raw_ostream &OS, const DynamicAPInt &X) {
-  X.print(OS);
-  return OS;
-}
-#endif
-
-/// Redeclarations of friend declaration above to
-/// make it discoverable by lookups.
-hash_code hash_value(const DynamicAPInt &X); // NOLINT
-
-/// This just calls through to the operator int64_t, but it's useful when a
-/// function pointer is required. (Although this is marked inline, it is still
-/// possible to obtain and use a function pointer to this.)
-static inline int64_t int64fromDynamicAPInt(const DynamicAPInt &X) {
-  return int64_t(X);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt dynamicAPIntFromInt64(int64_t X) {
-  return DynamicAPInt(X);
-}
-
-// The RHS is always expected to be positive, and the result
-/// is always non-negative.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt mod(const DynamicAPInt &LHS,
-                                              const DynamicAPInt &RHS);
-
-namespace detail {
-// Division overflows only when trying to negate the minimal signed value.
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool divWouldOverflow(int64_t X, int64_t Y) {
-  return X == std::numeric_limits<int64_t>::min() && Y == -1;
-}
-} // namespace detail
-
-/// We define the operations here in the header to facilitate inlining.
-
-/// ---------------------------------------------------------------------------
-/// Comparison operators.
-/// ---------------------------------------------------------------------------
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator==(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() == O.getSmall();
-  return detail::SlowDynamicAPInt(*this) == detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator!=(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() != O.getSmall();
-  return detail::SlowDynamicAPInt(*this) != detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator>(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() > O.getSmall();
-  return detail::SlowDynamicAPInt(*this) > detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator<(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() < O.getSmall();
-  return detail::SlowDynamicAPInt(*this) < detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator<=(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() <= O.getSmall();
-  return detail::SlowDynamicAPInt(*this) <= detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator>=(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() >= O.getSmall();
-  return detail::SlowDynamicAPInt(*this) >= detail::SlowDynamicAPInt(O);
-}
-
-/// ---------------------------------------------------------------------------
-/// Arithmetic operators.
-/// ---------------------------------------------------------------------------
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator+(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    DynamicAPInt Result;
-    bool Overflow = AddOverflow(getSmall(), O.getSmall(), Result.getSmall());
-    if (LLVM_LIKELY(!Overflow))
-      return Result;
-    return DynamicAPInt(detail::SlowDynamicAPInt(*this) +
-                        detail::SlowDynamicAPInt(O));
-  }
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) +
-                      detail::SlowDynamicAPInt(O));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator-(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    DynamicAPInt Result;
-    bool Overflow = SubOverflow(getSmall(), O.getSmall(), Result.getSmall());
-    if (LLVM_LIKELY(!Overflow))
-      return Result;
-    return DynamicAPInt(detail::SlowDynamicAPInt(*this) -
-                        detail::SlowDynamicAPInt(O));
-  }
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) -
-                      detail::SlowDynamicAPInt(O));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator*(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    DynamicAPInt Result;
-    bool Overflow = MulOverflow(getSmall(), O.getSmall(), Result.getSmall());
-    if (LLVM_LIKELY(!Overflow))
-      return Result;
-    return DynamicAPInt(detail::SlowDynamicAPInt(*this) *
-                        detail::SlowDynamicAPInt(O));
-  }
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) *
-                      detail::SlowDynamicAPInt(O));
-}
-
-// Division overflows only occur when negating the minimal possible value.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::divByPositive(const DynamicAPInt &O) const {
-  assert(O > 0);
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return DynamicAPInt(getSmall() / O.getSmall());
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) /
-                      detail::SlowDynamicAPInt(O));
-}
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator/(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    // Division overflows only occur when negating the minimal possible value.
-    if (LLVM_UNLIKELY(detail::divWouldOverflow(getSmall(), O.getSmall())))
-      return -*this;
-    return DynamicAPInt(getSmall() / O.getSmall());
-  }
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) /
-                      detail::SlowDynamicAPInt(O));
-}
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt abs(const DynamicAPInt &X) {
-  return DynamicAPInt(X >= 0 ? X : -X);
-}
-// Division overflows only occur when negating the minimal possible value.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt ceilDiv(const DynamicAPInt &LHS,
-                                                  const DynamicAPInt &RHS) {
-  if (LLVM_LIKELY(LHS.isSmall() && RHS.isSmall())) {
-    if (LLVM_UNLIKELY(detail::divWouldOverflow(LHS.getSmall(), RHS.getSmall())))
-      return -LHS;
-    return DynamicAPInt(divideCeilSigned(LHS.getSmall(), RHS.getSmall()));
-  }
-  return DynamicAPInt(
-      ceilDiv(detail::SlowDynamicAPInt(LHS), detail::SlowDynamicAPInt(RHS)));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt floorDiv(const DynamicAPInt &LHS,
-                                                   const DynamicAPInt &RHS) {
-  if (LLVM_LIKELY(LHS.isSmall() && RHS.isSmall())) {
-    if (LLVM_UNLIKELY(detail::divWouldOverflow(LHS.getSmall(), RHS.getSmall())))
-      return -LHS;
-    return DynamicAPInt(divideFloorSigned(LHS.getSmall(), RHS.getSmall()));
-  }
-  return DynamicAPInt(
-      floorDiv(detail::SlowDynamicAPInt(LHS), detail::SlowDynamicAPInt(RHS)));
-}
-// The RHS is always expected to be positive, and the result
-/// is always non-negative.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt mod(const DynamicAPInt &LHS,
-                                              const DynamicAPInt &RHS) {
-  if (LLVM_LIKELY(LHS.isSmall() && RHS.isSmall()))
-    return DynamicAPInt(mod(LHS.getSmall(), RHS.getSmall()));
-  return DynamicAPInt(
-      mod(detail::SlowDynamicAPInt(LHS), detail::SlowDynamicAPInt(RHS)));
-}
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt gcd(const DynamicAPInt &A,
-                                              const DynamicAPInt &B) {
-  assert(A >= 0 && B >= 0 && "operands must be non-negative!");
-  if (LLVM_LIKELY(A.isSmall() && B.isSmall()))
-    return DynamicAPInt(std::gcd(A.getSmall(), B.getSmall()));
-  return DynamicAPInt(
-      gcd(detail::SlowDynamicAPInt(A), detail::SlowDynamicAPInt(B)));
-}
-
-/// Returns the least common multiple of A and B.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt lcm(const DynamicAPInt &A,
-                                              const DynamicAPInt &B) {
-  DynamicAPInt X = abs(A);
-  DynamicAPInt Y = abs(B);
-  return (X * Y) / gcd(X, Y);
-}
-
-/// This operation cannot overflow.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator%(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return DynamicAPInt(getSmall() % O.getSmall());
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) %
-                      detail::SlowDynamicAPInt(O));
-}
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt DynamicAPInt::operator-() const {
-  if (LLVM_LIKELY(isSmall())) {
-    if (LLVM_LIKELY(getSmall() != std::numeric_limits<int64_t>::min()))
-      return DynamicAPInt(-getSmall());
-    return DynamicAPInt(-detail::SlowDynamicAPInt(*this));
-  }
-  return DynamicAPInt(-detail::SlowDynamicAPInt(*this));
-}
-
-/// ---------------------------------------------------------------------------
-/// Assignment operators, preincrement, predecrement.
-/// ---------------------------------------------------------------------------
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &
-DynamicAPInt::operator+=(const DynamicAPInt &O) {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    int64_t Result = getSmall();
-    bool Overflow = AddOverflow(getSmall(), O.getSmall(), Result);
-    if (LLVM_LIKELY(!Overflow)) {
-      getSmall() = Result;
-      return *this;
-    }
-    // Note: this return is not strictly required but
-    // removing it leads to a performance regression.
-    return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) +
-                                detail::SlowDynamicAPInt(O));
-  }
-  return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) +
-                              detail::SlowDynamicAPInt(O));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &
-DynamicAPInt::operator-=(const DynamicAPInt &O) {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    int64_t Result = getSmall();
-    bool Overflow = SubOverflow(getSmall(), O.getSmall(), Result);
-    if (LLVM_LIKELY(!Overflow)) {
-      getSmall() = Result;
-      return *this;
-    }
-    // Note: this return is not strictly required but
-    // removing it leads to a performance regression.
-    return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) -
-                                detail::SlowDynamicAPInt(O));
-  }
-  return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) -
-                              detail::SlowDynamicAPInt(O));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &
-DynamicAPInt::operator*=(const DynamicAPInt &O) {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    int64_t Result = getSmall();
-    bool Overflow = MulOverflow(getSmall(), O.getSmall(), Result);
-    if (LLVM_LIKELY(!Overflow)) {
-      getSmall() = Result;
-      return *this;
-    }
-    // Note: this return is not strictly required but
-    // removing it leads to a performance regression.
-    return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) *
-                                detail::SlowDynamicAPInt(O));
-  }
-  return *this = DynamicAPInt(detail::SlowDynamicAPInt(*t...
[truncated]

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 12, 2024

@llvm/pr-subscribers-llvm-support

Author: Maksim Levental (makslevental)

Changes

Reverts #95218 and #94953. Next time please revert instead of fixing forward.


Patch is 244.08 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95244.diff

40 Files Affected:

  • (removed) llvm/include/llvm/ADT/DynamicAPInt.h (-640)
  • (removed) llvm/include/llvm/ADT/SlowDynamicAPInt.h (-140)
  • (modified) llvm/lib/Support/CMakeLists.txt (-2)
  • (removed) llvm/lib/Support/DynamicAPInt.cpp (-29)
  • (removed) llvm/lib/Support/SlowDynamicAPInt.cpp (-288)
  • (modified) llvm/unittests/ADT/CMakeLists.txt (-1)
  • (removed) llvm/unittests/ADT/DynamicAPIntTest.cpp (-200)
  • (modified) mlir/include/mlir/Analysis/Presburger/Barvinok.h (+1-1)
  • (modified) mlir/include/mlir/Analysis/Presburger/Fraction.h (+23-29)
  • (modified) mlir/include/mlir/Analysis/Presburger/IntegerRelation.h (+43-59)
  • (modified) mlir/include/mlir/Analysis/Presburger/LinearTransform.h (+2-4)
  • (added) mlir/include/mlir/Analysis/Presburger/MPInt.h (+611)
  • (modified) mlir/include/mlir/Analysis/Presburger/Matrix.h (+13-13)
  • (modified) mlir/include/mlir/Analysis/Presburger/PWMAFunction.h (+7-11)
  • (modified) mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h (+4-4)
  • (modified) mlir/include/mlir/Analysis/Presburger/Simplex.h (+20-21)
  • (added) mlir/include/mlir/Analysis/Presburger/SlowMPInt.h (+135)
  • (modified) mlir/include/mlir/Analysis/Presburger/Utils.h (+28-34)
  • (modified) mlir/include/mlir/Support/LLVM.h (-2)
  • (modified) mlir/lib/Analysis/FlatLinearValueConstraints.cpp (+1-2)
  • (modified) mlir/lib/Analysis/Presburger/Barvinok.cpp (+3-3)
  • (modified) mlir/lib/Analysis/Presburger/CMakeLists.txt (+2)
  • (modified) mlir/lib/Analysis/Presburger/IntegerRelation.cpp (+92-100)
  • (modified) mlir/lib/Analysis/Presburger/LinearTransform.cpp (+7-6)
  • (added) mlir/lib/Analysis/Presburger/MPInt.cpp (+38)
  • (modified) mlir/lib/Analysis/Presburger/Matrix.cpp (+12-11)
  • (modified) mlir/lib/Analysis/Presburger/PWMAFunction.cpp (+19-20)
  • (modified) mlir/lib/Analysis/Presburger/PresburgerRelation.cpp (+28-30)
  • (modified) mlir/lib/Analysis/Presburger/Simplex.cpp (+84-88)
  • (added) mlir/lib/Analysis/Presburger/SlowMPInt.cpp (+290)
  • (modified) mlir/lib/Analysis/Presburger/Utils.cpp (+64-73)
  • (modified) mlir/unittests/Analysis/Presburger/CMakeLists.txt (+1)
  • (modified) mlir/unittests/Analysis/Presburger/FractionTest.cpp (+1-1)
  • (modified) mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp (+10-12)
  • (modified) mlir/unittests/Analysis/Presburger/LinearTransformTest.cpp (+1-2)
  • (added) mlir/unittests/Analysis/Presburger/MPIntTest.cpp (+200)
  • (modified) mlir/unittests/Analysis/Presburger/MatrixTest.cpp (+1-1)
  • (modified) mlir/unittests/Analysis/Presburger/SimplexTest.cpp (+14-15)
  • (modified) mlir/unittests/Analysis/Presburger/Utils.h (+9-11)
  • (modified) mlir/unittests/Analysis/Presburger/UtilsTest.cpp (+19-28)
diff --git a/llvm/include/llvm/ADT/DynamicAPInt.h b/llvm/include/llvm/ADT/DynamicAPInt.h
deleted file mode 100644
index 78a0372e09c49..0000000000000
--- a/llvm/include/llvm/ADT/DynamicAPInt.h
+++ /dev/null
@@ -1,640 +0,0 @@
-//===- DynamicAPInt.h - DynamicAPInt Class ----------------------*- C++ -*-===//
-//
-// 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 is a simple class to represent arbitrary precision signed integers.
-// Unlike APInt, one does not have to specify a fixed maximum size, and the
-// integer can take on any arbitrary values. This is optimized for small-values
-// by providing fast-paths for the cases when the value stored fits in 64-bits.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ADT_DYNAMICAPINT_H
-#define LLVM_ADT_DYNAMICAPINT_H
-
-#include "llvm/ADT/SlowDynamicAPInt.h"
-#include "llvm/Support/MathExtras.h"
-#include "llvm/Support/raw_ostream.h"
-#include <numeric>
-
-namespace llvm {
-/// This class provides support for dynamic arbitrary-precision arithmetic.
-///
-/// Unlike APInt, this extends the precision as necessary to prevent overflows
-/// and supports operations between objects with differing internal precisions.
-///
-/// This is optimized for small-values by providing fast-paths for the cases
-/// when the value stored fits in 64-bits. We annotate all fastpaths by using
-/// the LLVM_LIKELY/LLVM_UNLIKELY annotations. Removing these would result in
-/// a 1.2x performance slowdown.
-///
-/// We always_inline all operations; removing these results in a 1.5x
-/// performance slowdown.
-///
-/// When HoldsLarge is true, a SlowMPInt is held in the union. If it is false,
-/// the int64_t is held. Using std::variant instead would lead to significantly
-/// worse performance.
-class DynamicAPInt {
-  union {
-    int64_t ValSmall;
-    detail::SlowDynamicAPInt ValLarge;
-  };
-  unsigned HoldsLarge;
-
-  LLVM_ATTRIBUTE_ALWAYS_INLINE void initSmall(int64_t O) {
-    if (LLVM_UNLIKELY(isLarge()))
-      ValLarge.detail::SlowDynamicAPInt::~SlowDynamicAPInt();
-    ValSmall = O;
-    HoldsLarge = false;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE void
-  initLarge(const detail::SlowDynamicAPInt &O) {
-    if (LLVM_LIKELY(isSmall())) {
-      // The data in memory could be in an arbitrary state, not necessarily
-      // corresponding to any valid state of ValLarge; we cannot call any member
-      // functions, e.g. the assignment operator on it, as they may access the
-      // invalid internal state. We instead construct a new object using
-      // placement new.
-      new (&ValLarge) detail::SlowDynamicAPInt(O);
-    } else {
-      // In this case, we need to use the assignment operator, because if we use
-      // placement-new as above we would lose track of allocated memory
-      // and leak it.
-      ValLarge = O;
-    }
-    HoldsLarge = true;
-  }
-
-  LLVM_ATTRIBUTE_ALWAYS_INLINE explicit DynamicAPInt(
-      const detail::SlowDynamicAPInt &Val)
-      : ValLarge(Val), HoldsLarge(true) {}
-  LLVM_ATTRIBUTE_ALWAYS_INLINE bool isSmall() const { return !HoldsLarge; }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE bool isLarge() const { return HoldsLarge; }
-  /// Get the stored value. For getSmall/Large,
-  /// the stored value should be small/large.
-  LLVM_ATTRIBUTE_ALWAYS_INLINE int64_t getSmall() const {
-    assert(isSmall() &&
-           "getSmall should only be called when the value stored is small!");
-    return ValSmall;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE int64_t &getSmall() {
-    assert(isSmall() &&
-           "getSmall should only be called when the value stored is small!");
-    return ValSmall;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE const detail::SlowDynamicAPInt &
-  getLarge() const {
-    assert(isLarge() &&
-           "getLarge should only be called when the value stored is large!");
-    return ValLarge;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE detail::SlowDynamicAPInt &getLarge() {
-    assert(isLarge() &&
-           "getLarge should only be called when the value stored is large!");
-    return ValLarge;
-  }
-  explicit operator detail::SlowDynamicAPInt() const {
-    if (isSmall())
-      return detail::SlowDynamicAPInt(getSmall());
-    return getLarge();
-  }
-
-public:
-  LLVM_ATTRIBUTE_ALWAYS_INLINE explicit DynamicAPInt(int64_t Val)
-      : ValSmall(Val), HoldsLarge(false) {}
-  LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt() : DynamicAPInt(0) {}
-  LLVM_ATTRIBUTE_ALWAYS_INLINE ~DynamicAPInt() {
-    if (LLVM_UNLIKELY(isLarge()))
-      ValLarge.detail::SlowDynamicAPInt::~SlowDynamicAPInt();
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt(const DynamicAPInt &O)
-      : ValSmall(O.ValSmall), HoldsLarge(false) {
-    if (LLVM_UNLIKELY(O.isLarge()))
-      initLarge(O.ValLarge);
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &operator=(const DynamicAPInt &O) {
-    if (LLVM_LIKELY(O.isSmall())) {
-      initSmall(O.ValSmall);
-      return *this;
-    }
-    initLarge(O.ValLarge);
-    return *this;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &operator=(int X) {
-    initSmall(X);
-    return *this;
-  }
-  LLVM_ATTRIBUTE_ALWAYS_INLINE explicit operator int64_t() const {
-    if (isSmall())
-      return getSmall();
-    return static_cast<int64_t>(getLarge());
-  }
-
-  bool operator==(const DynamicAPInt &O) const;
-  bool operator!=(const DynamicAPInt &O) const;
-  bool operator>(const DynamicAPInt &O) const;
-  bool operator<(const DynamicAPInt &O) const;
-  bool operator<=(const DynamicAPInt &O) const;
-  bool operator>=(const DynamicAPInt &O) const;
-  DynamicAPInt operator+(const DynamicAPInt &O) const;
-  DynamicAPInt operator-(const DynamicAPInt &O) const;
-  DynamicAPInt operator*(const DynamicAPInt &O) const;
-  DynamicAPInt operator/(const DynamicAPInt &O) const;
-  DynamicAPInt operator%(const DynamicAPInt &O) const;
-  DynamicAPInt &operator+=(const DynamicAPInt &O);
-  DynamicAPInt &operator-=(const DynamicAPInt &O);
-  DynamicAPInt &operator*=(const DynamicAPInt &O);
-  DynamicAPInt &operator/=(const DynamicAPInt &O);
-  DynamicAPInt &operator%=(const DynamicAPInt &O);
-  DynamicAPInt operator-() const;
-  DynamicAPInt &operator++();
-  DynamicAPInt &operator--();
-
-  // Divide by a number that is known to be positive.
-  // This is slightly more efficient because it saves an overflow check.
-  DynamicAPInt divByPositive(const DynamicAPInt &O) const;
-  DynamicAPInt &divByPositiveInPlace(const DynamicAPInt &O);
-
-  friend DynamicAPInt abs(const DynamicAPInt &X);
-  friend DynamicAPInt ceilDiv(const DynamicAPInt &LHS, const DynamicAPInt &RHS);
-  friend DynamicAPInt floorDiv(const DynamicAPInt &LHS,
-                               const DynamicAPInt &RHS);
-  // The operands must be non-negative for gcd.
-  friend DynamicAPInt gcd(const DynamicAPInt &A, const DynamicAPInt &B);
-  friend DynamicAPInt lcm(const DynamicAPInt &A, const DynamicAPInt &B);
-  friend DynamicAPInt mod(const DynamicAPInt &LHS, const DynamicAPInt &RHS);
-
-  /// ---------------------------------------------------------------------------
-  /// Convenience operator overloads for int64_t.
-  /// ---------------------------------------------------------------------------
-  friend DynamicAPInt &operator+=(DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt &operator-=(DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt &operator*=(DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt &operator/=(DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt &operator%=(DynamicAPInt &A, int64_t B);
-
-  friend bool operator==(const DynamicAPInt &A, int64_t B);
-  friend bool operator!=(const DynamicAPInt &A, int64_t B);
-  friend bool operator>(const DynamicAPInt &A, int64_t B);
-  friend bool operator<(const DynamicAPInt &A, int64_t B);
-  friend bool operator<=(const DynamicAPInt &A, int64_t B);
-  friend bool operator>=(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator+(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator-(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator*(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator/(const DynamicAPInt &A, int64_t B);
-  friend DynamicAPInt operator%(const DynamicAPInt &A, int64_t B);
-
-  friend bool operator==(int64_t A, const DynamicAPInt &B);
-  friend bool operator!=(int64_t A, const DynamicAPInt &B);
-  friend bool operator>(int64_t A, const DynamicAPInt &B);
-  friend bool operator<(int64_t A, const DynamicAPInt &B);
-  friend bool operator<=(int64_t A, const DynamicAPInt &B);
-  friend bool operator>=(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator+(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator-(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator*(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator/(int64_t A, const DynamicAPInt &B);
-  friend DynamicAPInt operator%(int64_t A, const DynamicAPInt &B);
-
-  friend hash_code hash_value(const DynamicAPInt &x); // NOLINT
-
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-  raw_ostream &print(raw_ostream &OS) const;
-  LLVM_DUMP_METHOD void dump() const;
-#endif
-};
-
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-inline raw_ostream &operator<<(raw_ostream &OS, const DynamicAPInt &X) {
-  X.print(OS);
-  return OS;
-}
-#endif
-
-/// Redeclarations of friend declaration above to
-/// make it discoverable by lookups.
-hash_code hash_value(const DynamicAPInt &X); // NOLINT
-
-/// This just calls through to the operator int64_t, but it's useful when a
-/// function pointer is required. (Although this is marked inline, it is still
-/// possible to obtain and use a function pointer to this.)
-static inline int64_t int64fromDynamicAPInt(const DynamicAPInt &X) {
-  return int64_t(X);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt dynamicAPIntFromInt64(int64_t X) {
-  return DynamicAPInt(X);
-}
-
-// The RHS is always expected to be positive, and the result
-/// is always non-negative.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt mod(const DynamicAPInt &LHS,
-                                              const DynamicAPInt &RHS);
-
-namespace detail {
-// Division overflows only when trying to negate the minimal signed value.
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool divWouldOverflow(int64_t X, int64_t Y) {
-  return X == std::numeric_limits<int64_t>::min() && Y == -1;
-}
-} // namespace detail
-
-/// We define the operations here in the header to facilitate inlining.
-
-/// ---------------------------------------------------------------------------
-/// Comparison operators.
-/// ---------------------------------------------------------------------------
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator==(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() == O.getSmall();
-  return detail::SlowDynamicAPInt(*this) == detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator!=(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() != O.getSmall();
-  return detail::SlowDynamicAPInt(*this) != detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator>(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() > O.getSmall();
-  return detail::SlowDynamicAPInt(*this) > detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator<(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() < O.getSmall();
-  return detail::SlowDynamicAPInt(*this) < detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator<=(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() <= O.getSmall();
-  return detail::SlowDynamicAPInt(*this) <= detail::SlowDynamicAPInt(O);
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE bool
-DynamicAPInt::operator>=(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return getSmall() >= O.getSmall();
-  return detail::SlowDynamicAPInt(*this) >= detail::SlowDynamicAPInt(O);
-}
-
-/// ---------------------------------------------------------------------------
-/// Arithmetic operators.
-/// ---------------------------------------------------------------------------
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator+(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    DynamicAPInt Result;
-    bool Overflow = AddOverflow(getSmall(), O.getSmall(), Result.getSmall());
-    if (LLVM_LIKELY(!Overflow))
-      return Result;
-    return DynamicAPInt(detail::SlowDynamicAPInt(*this) +
-                        detail::SlowDynamicAPInt(O));
-  }
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) +
-                      detail::SlowDynamicAPInt(O));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator-(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    DynamicAPInt Result;
-    bool Overflow = SubOverflow(getSmall(), O.getSmall(), Result.getSmall());
-    if (LLVM_LIKELY(!Overflow))
-      return Result;
-    return DynamicAPInt(detail::SlowDynamicAPInt(*this) -
-                        detail::SlowDynamicAPInt(O));
-  }
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) -
-                      detail::SlowDynamicAPInt(O));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator*(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    DynamicAPInt Result;
-    bool Overflow = MulOverflow(getSmall(), O.getSmall(), Result.getSmall());
-    if (LLVM_LIKELY(!Overflow))
-      return Result;
-    return DynamicAPInt(detail::SlowDynamicAPInt(*this) *
-                        detail::SlowDynamicAPInt(O));
-  }
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) *
-                      detail::SlowDynamicAPInt(O));
-}
-
-// Division overflows only occur when negating the minimal possible value.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::divByPositive(const DynamicAPInt &O) const {
-  assert(O > 0);
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return DynamicAPInt(getSmall() / O.getSmall());
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) /
-                      detail::SlowDynamicAPInt(O));
-}
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator/(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    // Division overflows only occur when negating the minimal possible value.
-    if (LLVM_UNLIKELY(detail::divWouldOverflow(getSmall(), O.getSmall())))
-      return -*this;
-    return DynamicAPInt(getSmall() / O.getSmall());
-  }
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) /
-                      detail::SlowDynamicAPInt(O));
-}
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt abs(const DynamicAPInt &X) {
-  return DynamicAPInt(X >= 0 ? X : -X);
-}
-// Division overflows only occur when negating the minimal possible value.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt ceilDiv(const DynamicAPInt &LHS,
-                                                  const DynamicAPInt &RHS) {
-  if (LLVM_LIKELY(LHS.isSmall() && RHS.isSmall())) {
-    if (LLVM_UNLIKELY(detail::divWouldOverflow(LHS.getSmall(), RHS.getSmall())))
-      return -LHS;
-    return DynamicAPInt(divideCeilSigned(LHS.getSmall(), RHS.getSmall()));
-  }
-  return DynamicAPInt(
-      ceilDiv(detail::SlowDynamicAPInt(LHS), detail::SlowDynamicAPInt(RHS)));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt floorDiv(const DynamicAPInt &LHS,
-                                                   const DynamicAPInt &RHS) {
-  if (LLVM_LIKELY(LHS.isSmall() && RHS.isSmall())) {
-    if (LLVM_UNLIKELY(detail::divWouldOverflow(LHS.getSmall(), RHS.getSmall())))
-      return -LHS;
-    return DynamicAPInt(divideFloorSigned(LHS.getSmall(), RHS.getSmall()));
-  }
-  return DynamicAPInt(
-      floorDiv(detail::SlowDynamicAPInt(LHS), detail::SlowDynamicAPInt(RHS)));
-}
-// The RHS is always expected to be positive, and the result
-/// is always non-negative.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt mod(const DynamicAPInt &LHS,
-                                              const DynamicAPInt &RHS) {
-  if (LLVM_LIKELY(LHS.isSmall() && RHS.isSmall()))
-    return DynamicAPInt(mod(LHS.getSmall(), RHS.getSmall()));
-  return DynamicAPInt(
-      mod(detail::SlowDynamicAPInt(LHS), detail::SlowDynamicAPInt(RHS)));
-}
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt gcd(const DynamicAPInt &A,
-                                              const DynamicAPInt &B) {
-  assert(A >= 0 && B >= 0 && "operands must be non-negative!");
-  if (LLVM_LIKELY(A.isSmall() && B.isSmall()))
-    return DynamicAPInt(std::gcd(A.getSmall(), B.getSmall()));
-  return DynamicAPInt(
-      gcd(detail::SlowDynamicAPInt(A), detail::SlowDynamicAPInt(B)));
-}
-
-/// Returns the least common multiple of A and B.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt lcm(const DynamicAPInt &A,
-                                              const DynamicAPInt &B) {
-  DynamicAPInt X = abs(A);
-  DynamicAPInt Y = abs(B);
-  return (X * Y) / gcd(X, Y);
-}
-
-/// This operation cannot overflow.
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt
-DynamicAPInt::operator%(const DynamicAPInt &O) const {
-  if (LLVM_LIKELY(isSmall() && O.isSmall()))
-    return DynamicAPInt(getSmall() % O.getSmall());
-  return DynamicAPInt(detail::SlowDynamicAPInt(*this) %
-                      detail::SlowDynamicAPInt(O));
-}
-
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt DynamicAPInt::operator-() const {
-  if (LLVM_LIKELY(isSmall())) {
-    if (LLVM_LIKELY(getSmall() != std::numeric_limits<int64_t>::min()))
-      return DynamicAPInt(-getSmall());
-    return DynamicAPInt(-detail::SlowDynamicAPInt(*this));
-  }
-  return DynamicAPInt(-detail::SlowDynamicAPInt(*this));
-}
-
-/// ---------------------------------------------------------------------------
-/// Assignment operators, preincrement, predecrement.
-/// ---------------------------------------------------------------------------
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &
-DynamicAPInt::operator+=(const DynamicAPInt &O) {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    int64_t Result = getSmall();
-    bool Overflow = AddOverflow(getSmall(), O.getSmall(), Result);
-    if (LLVM_LIKELY(!Overflow)) {
-      getSmall() = Result;
-      return *this;
-    }
-    // Note: this return is not strictly required but
-    // removing it leads to a performance regression.
-    return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) +
-                                detail::SlowDynamicAPInt(O));
-  }
-  return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) +
-                              detail::SlowDynamicAPInt(O));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &
-DynamicAPInt::operator-=(const DynamicAPInt &O) {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    int64_t Result = getSmall();
-    bool Overflow = SubOverflow(getSmall(), O.getSmall(), Result);
-    if (LLVM_LIKELY(!Overflow)) {
-      getSmall() = Result;
-      return *this;
-    }
-    // Note: this return is not strictly required but
-    // removing it leads to a performance regression.
-    return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) -
-                                detail::SlowDynamicAPInt(O));
-  }
-  return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) -
-                              detail::SlowDynamicAPInt(O));
-}
-LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt &
-DynamicAPInt::operator*=(const DynamicAPInt &O) {
-  if (LLVM_LIKELY(isSmall() && O.isSmall())) {
-    int64_t Result = getSmall();
-    bool Overflow = MulOverflow(getSmall(), O.getSmall(), Result);
-    if (LLVM_LIKELY(!Overflow)) {
-      getSmall() = Result;
-      return *this;
-    }
-    // Note: this return is not strictly required but
-    // removing it leads to a performance regression.
-    return *this = DynamicAPInt(detail::SlowDynamicAPInt(*this) *
-                                detail::SlowDynamicAPInt(O));
-  }
-  return *this = DynamicAPInt(detail::SlowDynamicAPInt(*t...
[truncated]

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff ad9fe3b2a949fb3379e0a1bafbcd2ca81f5fa414 1ec122c4afdfef1109db2e3400010807c3123e10 -- mlir/include/mlir/Analysis/Presburger/MPInt.h mlir/include/mlir/Analysis/Presburger/SlowMPInt.h mlir/lib/Analysis/Presburger/MPInt.cpp mlir/lib/Analysis/Presburger/SlowMPInt.cpp mlir/unittests/Analysis/Presburger/MPIntTest.cpp mlir/include/mlir/Analysis/Presburger/Barvinok.h mlir/include/mlir/Analysis/Presburger/Fraction.h mlir/include/mlir/Analysis/Presburger/IntegerRelation.h mlir/include/mlir/Analysis/Presburger/LinearTransform.h mlir/include/mlir/Analysis/Presburger/Matrix.h mlir/include/mlir/Analysis/Presburger/PWMAFunction.h mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h mlir/include/mlir/Analysis/Presburger/Simplex.h mlir/include/mlir/Analysis/Presburger/Utils.h mlir/include/mlir/Support/LLVM.h mlir/lib/Analysis/FlatLinearValueConstraints.cpp mlir/lib/Analysis/Presburger/Barvinok.cpp mlir/lib/Analysis/Presburger/IntegerRelation.cpp mlir/lib/Analysis/Presburger/LinearTransform.cpp mlir/lib/Analysis/Presburger/Matrix.cpp mlir/lib/Analysis/Presburger/PWMAFunction.cpp mlir/lib/Analysis/Presburger/PresburgerRelation.cpp mlir/lib/Analysis/Presburger/Simplex.cpp mlir/lib/Analysis/Presburger/Utils.cpp mlir/unittests/Analysis/Presburger/FractionTest.cpp mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp mlir/unittests/Analysis/Presburger/LinearTransformTest.cpp mlir/unittests/Analysis/Presburger/MatrixTest.cpp mlir/unittests/Analysis/Presburger/SimplexTest.cpp mlir/unittests/Analysis/Presburger/Utils.h mlir/unittests/Analysis/Presburger/UtilsTest.cpp
View the diff from clang-format here.
diff --git a/mlir/include/mlir/Analysis/Presburger/Matrix.h b/mlir/include/mlir/Analysis/Presburger/Matrix.h
index c20a7bcecd..10a74424df 100644
--- a/mlir/include/mlir/Analysis/Presburger/Matrix.h
+++ b/mlir/include/mlir/Analysis/Presburger/Matrix.h
@@ -254,9 +254,9 @@ class IntMatrix : public Matrix<MPInt> {
 public:
   IntMatrix(unsigned rows, unsigned columns, unsigned reservedRows = 0,
             unsigned reservedColumns = 0)
-      : Matrix<MPInt>(rows, columns, reservedRows, reservedColumns){};
+      : Matrix<MPInt>(rows, columns, reservedRows, reservedColumns) {};
 
-  IntMatrix(Matrix<MPInt> m) : Matrix<MPInt>(std::move(m)){};
+  IntMatrix(Matrix<MPInt> m) : Matrix<MPInt>(std::move(m)) {};
 
   /// Return the identity matrix of the specified dimension.
   static IntMatrix identity(unsigned dimension);
diff --git a/mlir/lib/Analysis/FlatLinearValueConstraints.cpp b/mlir/lib/Analysis/FlatLinearValueConstraints.cpp
index 5c4f353f31..4c07c68672 100644
--- a/mlir/lib/Analysis/FlatLinearValueConstraints.cpp
+++ b/mlir/lib/Analysis/FlatLinearValueConstraints.cpp
@@ -1317,7 +1317,8 @@ mlir::getMultiAffineFunctionFromMap(AffineMap map,
          "AffineMap cannot produce divs without local representation");
 
   // TODO: We shouldn't have to do this conversion.
-  Matrix<MPInt> mat(map.getNumResults(), map.getNumInputs() + divs.getNumDivs() + 1);
+  Matrix<MPInt> mat(map.getNumResults(),
+                    map.getNumInputs() + divs.getNumDivs() + 1);
   for (unsigned i = 0, e = flattenedExprs.size(); i < e; ++i)
     for (unsigned j = 0, f = flattenedExprs[i].size(); j < f; ++j)
       mat(i, j) = flattenedExprs[i][j];

Copy link
Member

@Groverkss Groverkss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, reverting since release build is broken seems fair to me.

Copy link
Member

@akuegel akuegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending the revert.

@artagnon
Copy link
Contributor

artagnon commented Jun 12, 2024 via email

@makslevental
Copy link
Contributor Author

My fix will be ready in 10 mins. Go ahead with the revert, if you think it’s necessary.

Two fails in a row means absolutely a revert is warranted and an exceptionally detailed review of your fix will be necessary.

@artagnon
Copy link
Contributor

artagnon commented Jun 12, 2024 via email

@makslevental makslevental merged commit cb5d1b5 into llvm:main Jun 12, 2024
10 of 13 checks passed
@makslevental makslevental deleted the revert branch June 12, 2024 13:55
@stellaraccident
Copy link
Contributor

Agreed/thank you. While always a judgement call when considering a fix forward, the default action should be a revert when it is project impacting. Double fix forwards are extremely costly to everyone in the project who depends on the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants