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 atd5e31cf38a. This was previously reverted in1e10d35ea9due to a build failure; relanding now with an attempted fix. Reviewed By: Groverkss, ftynse Differential Revision: https://reviews.llvm.org/D128811
37 lines
1.2 KiB
C++
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;
|
|
}
|