Files
clang-p2996/mlir/lib/Analysis/Presburger/MPInt.cpp
Arjun P cdbc5f1e10 [MLIR][Presburger] introduce MPInt to support fast arbitrary precision in Presburger
This uses an int64_t-based fastpath for the common case and falls back to
SlowMPInt to handle the rare cases where larger numbers occur.
It uses `__builtin_*` for performance through the support in LLVM MathExtras.

Using this in the Presburger library results in a minor performance
*improvement* over any commit hash before sequence of patches
starting at d5e31cf38a.

This was previously reverted in 1e10d35ea9 due
to a build failure; relanding now with an attempted fix.

Reviewed By: Groverkss, ftynse

Differential Revision: https://reviews.llvm.org/D128811
2022-07-11 15:46:44 +01:00

37 lines
1.2 KiB
C++

//===- MPInt.cpp - MLIR MPInt Class ---------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "mlir/Analysis/Presburger/MPInt.h"
#include "llvm/Support/MathExtras.h"
using namespace mlir;
using namespace presburger;
llvm::hash_code mlir::presburger::hash_value(const MPInt &x) {
if (x.isSmall())
return llvm::hash_value(x.getSmall());
return detail::hash_value(x.getLarge());
}
/// ---------------------------------------------------------------------------
/// Printing.
/// ---------------------------------------------------------------------------
llvm::raw_ostream &MPInt::print(llvm::raw_ostream &os) const {
if (isSmall())
return os << valSmall;
return os << valLarge;
}
void MPInt::dump() const { print(llvm::errs()); }
llvm::raw_ostream &mlir::presburger::operator<<(llvm::raw_ostream &os,
const MPInt &x) {
x.print(os);
return os;
}