LLVM 20.0.0git
SlowDynamicAPInt.h
Go to the documentation of this file.
1//===- SlowDynamicAPInt.h - SlowDynamicAPInt Class --------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is a simple class to represent arbitrary precision signed integers.
10// Unlike APInt, one does not have to specify a fixed maximum size, and the
11// integer can take on any arbitrary values.
12//
13// This class is to be used as a fallback slow path for the DynamicAPInt class,
14// and is not intended to be used directly.
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_ADT_SLOWDYNAMICAPINT_H
19#define LLVM_ADT_SLOWDYNAMICAPINT_H
20
21#include "llvm/ADT/APInt.h"
22
23namespace llvm {
24class DynamicAPInt;
25class raw_ostream;
26} // namespace llvm
27
28namespace llvm::detail {
29/// A simple class providing dynamic arbitrary-precision arithmetic. Internally,
30/// it stores an APInt, whose width is doubled whenever an overflow occurs at a
31/// certain width. The default constructor sets the initial width to 64.
32/// SlowDynamicAPInt is primarily intended to be used as a slow fallback path
33/// for the upcoming DynamicAPInt class.
35 APInt Val;
36
37public:
38 explicit SlowDynamicAPInt(int64_t Val);
40 explicit SlowDynamicAPInt(const APInt &Val);
41 SlowDynamicAPInt &operator=(int64_t Val);
42 explicit operator int64_t() const;
44 bool operator==(const SlowDynamicAPInt &O) const;
45 bool operator!=(const SlowDynamicAPInt &O) const;
46 bool operator>(const SlowDynamicAPInt &O) const;
47 bool operator<(const SlowDynamicAPInt &O) const;
48 bool operator<=(const SlowDynamicAPInt &O) const;
49 bool operator>=(const SlowDynamicAPInt &O) const;
60
63
66 const SlowDynamicAPInt &RHS);
68 const SlowDynamicAPInt &RHS);
69 /// The operands must be non-negative for gcd.
71 const SlowDynamicAPInt &B);
72
73 /// Overload to compute a hash_code for a SlowDynamicAPInt value.
74 friend hash_code hash_value(const SlowDynamicAPInt &X); // NOLINT
75
76 // Make DynamicAPInt a friend so it can access Val directly.
78
79 unsigned getBitWidth() const { return Val.getBitWidth(); }
80
81 void print(raw_ostream &OS) const;
82 LLVM_DUMP_METHOD void dump() const;
83};
84
86 X.print(OS);
87 return OS;
88}
89
90/// Returns the remainder of dividing LHS by RHS.
91///
92/// The RHS is always expected to be positive, and the result
93/// is always non-negative.
94SlowDynamicAPInt mod(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS);
95
96/// Returns the least common multiple of A and B.
97SlowDynamicAPInt lcm(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B);
98
99/// Redeclarations of friend declarations above to
100/// make it discoverable by lookups.
101SlowDynamicAPInt abs(const SlowDynamicAPInt &X);
102SlowDynamicAPInt ceilDiv(const SlowDynamicAPInt &LHS,
103 const SlowDynamicAPInt &RHS);
104SlowDynamicAPInt floorDiv(const SlowDynamicAPInt &LHS,
105 const SlowDynamicAPInt &RHS);
106SlowDynamicAPInt gcd(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B);
107hash_code hash_value(const SlowDynamicAPInt &X); // NOLINT
108
109/// ---------------------------------------------------------------------------
110/// Convenience operator overloads for int64_t.
111/// ---------------------------------------------------------------------------
112SlowDynamicAPInt &operator+=(SlowDynamicAPInt &A, int64_t B);
113SlowDynamicAPInt &operator-=(SlowDynamicAPInt &A, int64_t B);
114SlowDynamicAPInt &operator*=(SlowDynamicAPInt &A, int64_t B);
115SlowDynamicAPInt &operator/=(SlowDynamicAPInt &A, int64_t B);
116SlowDynamicAPInt &operator%=(SlowDynamicAPInt &A, int64_t B);
117
118bool operator==(const SlowDynamicAPInt &A, int64_t B);
119bool operator!=(const SlowDynamicAPInt &A, int64_t B);
120bool operator>(const SlowDynamicAPInt &A, int64_t B);
121bool operator<(const SlowDynamicAPInt &A, int64_t B);
122bool operator<=(const SlowDynamicAPInt &A, int64_t B);
123bool operator>=(const SlowDynamicAPInt &A, int64_t B);
124SlowDynamicAPInt operator+(const SlowDynamicAPInt &A, int64_t B);
125SlowDynamicAPInt operator-(const SlowDynamicAPInt &A, int64_t B);
126SlowDynamicAPInt operator*(const SlowDynamicAPInt &A, int64_t B);
127SlowDynamicAPInt operator/(const SlowDynamicAPInt &A, int64_t B);
128SlowDynamicAPInt operator%(const SlowDynamicAPInt &A, int64_t B);
129
130bool operator==(int64_t A, const SlowDynamicAPInt &B);
131bool operator!=(int64_t A, const SlowDynamicAPInt &B);
132bool operator>(int64_t A, const SlowDynamicAPInt &B);
133bool operator<(int64_t A, const SlowDynamicAPInt &B);
134bool operator<=(int64_t A, const SlowDynamicAPInt &B);
135bool operator>=(int64_t A, const SlowDynamicAPInt &B);
136SlowDynamicAPInt operator+(int64_t A, const SlowDynamicAPInt &B);
137SlowDynamicAPInt operator-(int64_t A, const SlowDynamicAPInt &B);
138SlowDynamicAPInt operator*(int64_t A, const SlowDynamicAPInt &B);
139SlowDynamicAPInt operator/(int64_t A, const SlowDynamicAPInt &B);
140SlowDynamicAPInt operator%(int64_t A, const SlowDynamicAPInt &B);
141} // namespace llvm::detail
142
143#endif // LLVM_ADT_SLOWDYNAMICAPINT_H
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:533
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
raw_pwrite_stream & OS
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:78
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1446
A simple class providing dynamic arbitrary-precision arithmetic.
void print(raw_ostream &OS) const
SlowDynamicAPInt operator%(const SlowDynamicAPInt &O) const
This operation cannot overflow.
SlowDynamicAPInt operator*(const SlowDynamicAPInt &O) const
SlowDynamicAPInt & operator+=(const SlowDynamicAPInt &O)
LLVM_DUMP_METHOD void dump() const
bool operator<=(const SlowDynamicAPInt &O) const
SlowDynamicAPInt & operator-=(const SlowDynamicAPInt &O)
friend SlowDynamicAPInt ceilDiv(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
SlowDynamicAPInt & operator*=(const SlowDynamicAPInt &O)
SlowDynamicAPInt & operator=(int64_t Val)
SlowDynamicAPInt operator-() const
bool operator!=(const SlowDynamicAPInt &O) const
friend SlowDynamicAPInt gcd(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B)
The operands must be non-negative for gcd.
friend hash_code hash_value(const SlowDynamicAPInt &X)
Overload to compute a hash_code for a SlowDynamicAPInt value.
bool operator>(const SlowDynamicAPInt &O) const
bool operator==(const SlowDynamicAPInt &O) const
friend SlowDynamicAPInt abs(const SlowDynamicAPInt &X)
Redeclarations of friend declarations above to make it discoverable by lookups.
friend SlowDynamicAPInt floorDiv(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
SlowDynamicAPInt operator/(const SlowDynamicAPInt &O) const
SlowDynamicAPInt & operator/=(const SlowDynamicAPInt &O)
SlowDynamicAPInt & operator%=(const SlowDynamicAPInt &O)
bool operator<(const SlowDynamicAPInt &O) const
bool operator>=(const SlowDynamicAPInt &O) const
SlowDynamicAPInt operator+(const SlowDynamicAPInt &O) const
An opaque object representing a hash code.
Definition: Hashing.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
These are wrappers over isa* function that allow them to be used in generic algorithms such as llvm:a...
Definition: ADL.h:123
SlowDynamicAPInt abs(const SlowDynamicAPInt &X)
Redeclarations of friend declarations above to make it discoverable by lookups.
bool operator>=(const SlowDynamicAPInt &A, int64_t B)
SlowDynamicAPInt ceilDiv(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
SlowDynamicAPInt operator/(const SlowDynamicAPInt &A, int64_t B)
SlowDynamicAPInt operator+(const SlowDynamicAPInt &A, int64_t B)
hash_code hash_value(const IEEEFloat &Arg)
Definition: APFloat.cpp:3430
SlowDynamicAPInt operator-(const SlowDynamicAPInt &A, int64_t B)
bool operator!=(const DenseSetImpl< ValueT, MapTy, ValueInfoT > &LHS, const DenseSetImpl< ValueT, MapTy, ValueInfoT > &RHS)
Inequality comparison for DenseSet.
Definition: DenseSet.h:259
SlowDynamicAPInt gcd(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B)
SlowDynamicAPInt floorDiv(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
bool operator>(const SlowDynamicAPInt &A, int64_t B)
raw_ostream & operator<<(raw_ostream &OS, const SlowDynamicAPInt &X)
SlowDynamicAPInt & operator+=(SlowDynamicAPInt &A, int64_t B)
SlowDynamicAPInt operator%(const SlowDynamicAPInt &A, int64_t B)
SlowDynamicAPInt operator*(const SlowDynamicAPInt &A, int64_t B)
bool operator<=(const SlowDynamicAPInt &A, int64_t B)
SlowDynamicAPInt & operator/=(SlowDynamicAPInt &A, int64_t B)
SlowDynamicAPInt lcm(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B)
Returns the least common multiple of A and B.
SlowDynamicAPInt mod(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
Returns the remainder of dividing LHS by RHS.
SlowDynamicAPInt & operator*=(SlowDynamicAPInt &A, int64_t B)
bool operator<(const SlowDynamicAPInt &A, int64_t B)
SlowDynamicAPInt & operator-=(SlowDynamicAPInt &A, int64_t B)
SlowDynamicAPInt & operator%=(SlowDynamicAPInt &A, int64_t B)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)