LLVM 22.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"
23
24namespace llvm {
25class DynamicAPInt;
26class raw_ostream;
27} // namespace llvm
28
29namespace llvm::detail {
30/// A simple class providing dynamic arbitrary-precision arithmetic. Internally,
31/// it stores an APInt, whose width is doubled whenever an overflow occurs at a
32/// certain width. The default constructor sets the initial width to 64.
33/// SlowDynamicAPInt is primarily intended to be used as a slow fallback path
34/// for the upcoming DynamicAPInt class.
36 APInt Val;
37
38public:
39 LLVM_ABI explicit SlowDynamicAPInt(int64_t Val);
41 LLVM_ABI explicit SlowDynamicAPInt(const APInt &Val);
43 LLVM_ABI explicit operator int64_t() const;
45 LLVM_ABI bool operator==(const SlowDynamicAPInt &O) const;
46 LLVM_ABI bool operator!=(const SlowDynamicAPInt &O) const;
47 LLVM_ABI bool operator>(const SlowDynamicAPInt &O) const;
48 LLVM_ABI bool operator<(const SlowDynamicAPInt &O) const;
49 LLVM_ABI bool operator<=(const SlowDynamicAPInt &O) const;
50 LLVM_ABI bool operator>=(const SlowDynamicAPInt &O) const;
61
64
67 const SlowDynamicAPInt &RHS);
69 const SlowDynamicAPInt &RHS);
70 /// The operands must be non-negative for gcd.
72 const SlowDynamicAPInt &B);
73
74 /// Overload to compute a hash_code for a SlowDynamicAPInt value.
76
77 // Make DynamicAPInt a friend so it can access Val directly.
79
80 unsigned getBitWidth() const { return Val.getBitWidth(); }
81
82 LLVM_ABI void print(raw_ostream &OS) const;
83
84#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
85 LLVM_DUMP_METHOD void dump() const;
86#endif
87};
88
90 X.print(OS);
91 return OS;
92}
93
94/// Returns the remainder of dividing LHS by RHS.
95///
96/// The RHS is always expected to be positive, and the result
97/// is always non-negative.
98LLVM_ABI SlowDynamicAPInt mod(const SlowDynamicAPInt &LHS,
99 const SlowDynamicAPInt &RHS);
100
101/// Returns the least common multiple of A and B.
102LLVM_ABI SlowDynamicAPInt lcm(const SlowDynamicAPInt &A,
103 const SlowDynamicAPInt &B);
104
105/// Redeclarations of friend declarations above to
106/// make it discoverable by lookups.
107LLVM_ABI SlowDynamicAPInt abs(const SlowDynamicAPInt &X);
108LLVM_ABI SlowDynamicAPInt ceilDiv(const SlowDynamicAPInt &LHS,
109 const SlowDynamicAPInt &RHS);
110LLVM_ABI SlowDynamicAPInt floorDiv(const SlowDynamicAPInt &LHS,
111 const SlowDynamicAPInt &RHS);
112LLVM_ABI SlowDynamicAPInt gcd(const SlowDynamicAPInt &A,
113 const SlowDynamicAPInt &B);
114LLVM_ABI hash_code hash_value(const SlowDynamicAPInt &X); // NOLINT
115
116/// ---------------------------------------------------------------------------
117/// Convenience operator overloads for int64_t.
118/// ---------------------------------------------------------------------------
119LLVM_ABI SlowDynamicAPInt &operator+=(SlowDynamicAPInt &A, int64_t B);
120LLVM_ABI SlowDynamicAPInt &operator-=(SlowDynamicAPInt &A, int64_t B);
121LLVM_ABI SlowDynamicAPInt &operator*=(SlowDynamicAPInt &A, int64_t B);
122LLVM_ABI SlowDynamicAPInt &operator/=(SlowDynamicAPInt &A, int64_t B);
123LLVM_ABI SlowDynamicAPInt &operator%=(SlowDynamicAPInt &A, int64_t B);
124
125LLVM_ABI bool operator==(const SlowDynamicAPInt &A, int64_t B);
126LLVM_ABI bool operator!=(const SlowDynamicAPInt &A, int64_t B);
127LLVM_ABI bool operator>(const SlowDynamicAPInt &A, int64_t B);
128LLVM_ABI bool operator<(const SlowDynamicAPInt &A, int64_t B);
129LLVM_ABI bool operator<=(const SlowDynamicAPInt &A, int64_t B);
130LLVM_ABI bool operator>=(const SlowDynamicAPInt &A, int64_t B);
131LLVM_ABI SlowDynamicAPInt operator+(const SlowDynamicAPInt &A, int64_t B);
132LLVM_ABI SlowDynamicAPInt operator-(const SlowDynamicAPInt &A, int64_t B);
133LLVM_ABI SlowDynamicAPInt operator*(const SlowDynamicAPInt &A, int64_t B);
134LLVM_ABI SlowDynamicAPInt operator/(const SlowDynamicAPInt &A, int64_t B);
135LLVM_ABI SlowDynamicAPInt operator%(const SlowDynamicAPInt &A, int64_t B);
136
137LLVM_ABI bool operator==(int64_t A, const SlowDynamicAPInt &B);
138LLVM_ABI bool operator!=(int64_t A, const SlowDynamicAPInt &B);
139LLVM_ABI bool operator>(int64_t A, const SlowDynamicAPInt &B);
140LLVM_ABI bool operator<(int64_t A, const SlowDynamicAPInt &B);
141LLVM_ABI bool operator<=(int64_t A, const SlowDynamicAPInt &B);
142LLVM_ABI bool operator>=(int64_t A, const SlowDynamicAPInt &B);
143LLVM_ABI SlowDynamicAPInt operator+(int64_t A, const SlowDynamicAPInt &B);
144LLVM_ABI SlowDynamicAPInt operator-(int64_t A, const SlowDynamicAPInt &B);
145LLVM_ABI SlowDynamicAPInt operator*(int64_t A, const SlowDynamicAPInt &B);
146LLVM_ABI SlowDynamicAPInt operator/(int64_t A, const SlowDynamicAPInt &B);
147LLVM_ABI SlowDynamicAPInt operator%(int64_t A, const SlowDynamicAPInt &B);
148} // namespace llvm::detail
149
150#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_ABI
Definition: Compiler.h:213
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:638
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:1488
A simple class providing dynamic arbitrary-precision arithmetic.
LLVM_ABI friend SlowDynamicAPInt gcd(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B)
The operands must be non-negative for gcd.
LLVM_ABI void print(raw_ostream &OS) const
LLVM_ABI SlowDynamicAPInt operator%(const SlowDynamicAPInt &O) const
This operation cannot overflow.
LLVM_ABI friend SlowDynamicAPInt ceilDiv(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
LLVM_ABI SlowDynamicAPInt operator*(const SlowDynamicAPInt &O) const
LLVM_ABI SlowDynamicAPInt & operator+=(const SlowDynamicAPInt &O)
LLVM_ABI SlowDynamicAPInt & operator--()
LLVM_ABI bool operator<=(const SlowDynamicAPInt &O) const
LLVM_ABI SlowDynamicAPInt & operator-=(const SlowDynamicAPInt &O)
LLVM_ABI SlowDynamicAPInt & operator*=(const SlowDynamicAPInt &O)
LLVM_ABI SlowDynamicAPInt & operator=(int64_t Val)
LLVM_ABI SlowDynamicAPInt & operator++()
LLVM_ABI SlowDynamicAPInt operator-() const
LLVM_ABI bool operator!=(const SlowDynamicAPInt &O) const
LLVM_ABI bool operator>(const SlowDynamicAPInt &O) const
LLVM_ABI bool operator==(const SlowDynamicAPInt &O) const
LLVM_ABI SlowDynamicAPInt operator/(const SlowDynamicAPInt &O) const
LLVM_DUMP_METHOD void dump() const
LLVM_ABI SlowDynamicAPInt & operator/=(const SlowDynamicAPInt &O)
LLVM_ABI SlowDynamicAPInt & operator%=(const SlowDynamicAPInt &O)
LLVM_ABI friend hash_code hash_value(const SlowDynamicAPInt &X)
Overload to compute a hash_code for a SlowDynamicAPInt value.
LLVM_ABI bool operator<(const SlowDynamicAPInt &O) const
LLVM_ABI friend SlowDynamicAPInt abs(const SlowDynamicAPInt &X)
Redeclarations of friend declarations above to make it discoverable by lookups.
LLVM_ABI friend SlowDynamicAPInt floorDiv(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
LLVM_ABI bool operator>=(const SlowDynamicAPInt &O) const
LLVM_ABI SlowDynamicAPInt operator+(const SlowDynamicAPInt &O) const
An opaque object representing a hash code.
Definition: Hashing.h:76
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
These are wrappers over isa* function that allow them to be used in generic algorithms such as llvm:a...
Definition: ADL.h:123
LLVM_ABI SlowDynamicAPInt abs(const SlowDynamicAPInt &X)
Redeclarations of friend declarations above to make it discoverable by lookups.
LLVM_ABI bool operator>=(const SlowDynamicAPInt &A, int64_t B)
LLVM_ABI SlowDynamicAPInt ceilDiv(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
LLVM_ABI SlowDynamicAPInt operator/(const SlowDynamicAPInt &A, int64_t B)
LLVM_ABI SlowDynamicAPInt operator+(const SlowDynamicAPInt &A, int64_t B)
LLVM_ABI hash_code hash_value(const IEEEFloat &Arg)
Definition: APFloat.cpp:3508
LLVM_ABI 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:250
LLVM_ABI SlowDynamicAPInt gcd(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B)
LLVM_ABI SlowDynamicAPInt floorDiv(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
LLVM_ABI bool operator>(const SlowDynamicAPInt &A, int64_t B)
raw_ostream & operator<<(raw_ostream &OS, const SlowDynamicAPInt &X)
LLVM_ABI SlowDynamicAPInt & operator+=(SlowDynamicAPInt &A, int64_t B)
LLVM_ABI SlowDynamicAPInt operator%(const SlowDynamicAPInt &A, int64_t B)
LLVM_ABI SlowDynamicAPInt operator*(const SlowDynamicAPInt &A, int64_t B)
LLVM_ABI bool operator<=(const SlowDynamicAPInt &A, int64_t B)
LLVM_ABI SlowDynamicAPInt & operator/=(SlowDynamicAPInt &A, int64_t B)
LLVM_ABI SlowDynamicAPInt lcm(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B)
Returns the least common multiple of A and B.
LLVM_ABI SlowDynamicAPInt mod(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS)
Returns the remainder of dividing LHS by RHS.
LLVM_ABI SlowDynamicAPInt & operator*=(SlowDynamicAPInt &A, int64_t B)
LLVM_ABI bool operator<(const SlowDynamicAPInt &A, int64_t B)
LLVM_ABI SlowDynamicAPInt & operator-=(SlowDynamicAPInt &A, int64_t B)
LLVM_ABI 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)