13#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H
14#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H
18#include "llvm/ADT/APSInt.h"
19#include "llvm/Support/MathExtras.h"
20#include "llvm/Support/raw_ostream.h"
29using APInt = llvm::APInt;
30using APSInt = llvm::APSInt;
45 template <
typename T,
bool InputSigned>
47 constexpr unsigned BitSize =
sizeof(T) * 8;
48 if (BitSize >=
V.getBitWidth()) {
50 if constexpr (InputSigned)
51 Extended =
V.sext(BitSize);
53 Extended =
V.zext(BitSize);
54 return std::is_signed_v<T> ? Extended.getSExtValue()
55 : Extended.getZExtValue();
58 return std::is_signed_v<T> ?
V.trunc(BitSize).getSExtValue()
59 :
V.trunc(BitSize).getZExtValue();
65 unsigned NumWords = llvm::APInt::getNumWords(
BitWidth);
72 void take(uint64_t *NewMemory) {
82 if (
V.isSingleWord()) {
84 Val =
V.getSExtValue();
86 Val =
V.getZExtValue();
90 std::memcpy(
Memory,
V.getRawData(),
V.getNumWords() *
sizeof(uint64_t));
101 if (
V.isSingleWord()) {
102 Val = Signed ? V.getSExtValue() : V.getZExtValue();
104 Memory = const_cast<uint64_t *>(V.getRawData());
125 template <
typename Ty,
typename = std::enable_if_t<std::is_
integral_v<Ty>>>
126 explicit operator Ty()
const {
132 NumBits =
sizeof(T) * 8;
134 assert(APInt::getNumWords(NumBits) == 1);
169 return getValue().isMinSignedValue();
174 return getValue().isMaxSignedValue();
185 llvm::raw_string_ostream OS(NameStr);
210 llvm::LoadIntFromMemory(
V, (
const uint8_t *)Src,
BitWidth / 8);
246 return CheckAddSubMulUB<std::plus>(A, B, OpBits, R);
250 return CheckAddSubMulUB<std::minus>(A, B, OpBits, R);
254 return CheckAddSubMulUB<std::multiplies>(A, B, OpBits, R);
310 unsigned ShiftAmount = B.
getValue().getZExtValue();
312 R->copy(A.
getValue().ashr(ShiftAmount));
314 R->copy(A.
getValue().lshr(ShiftAmount));
320 return sizeof(uint32_t) + (
numWords() *
sizeof(uint64_t));
324 std::memcpy(Buff, &
BitWidth,
sizeof(uint32_t));
326 std::memcpy(Buff +
sizeof(uint32_t), &
Val,
sizeof(uint64_t));
328 std::memcpy(Buff +
sizeof(uint32_t),
Memory,
334 return *
reinterpret_cast<const uint32_t *
>(Buff);
340 unsigned NumWords = llvm::APInt::getNumWords(
BitWidth);
343 std::memcpy(&
Result->Val, Buff +
sizeof(uint32_t),
sizeof(uint64_t));
346 std::memcpy(
Result->Memory, Buff +
sizeof(uint32_t),
347 NumWords *
sizeof(uint64_t));
352 template <
template <
typename T>
class Op>
370template <
bool Signed>
377template <
bool Signed>
static uint32_t getBitWidth(const Expr *E)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
If an IntegralAP is constructed from Memory, it DOES NOT OWN THAT MEMORY.
IntegralAP(unsigned BitWidth)
Zeroed, single-word IntegralAP of the given bitwidth.
void take(uint64_t *NewMemory)
void print(llvm::raw_ostream &OS) const
static constexpr bool isSigned()
static void shiftLeft(const IntegralAP A, const IntegralAP B, unsigned OpBits, IntegralAP *R)
IntegralAP(uint64_t *Memory, unsigned BitWidth)
IntegralAP< false > toUnsigned() const
static uint32_t deserializeSize(const std::byte *Buff)
static bool rem(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R)
void serialize(std::byte *Buff) const
static bool decrement(IntegralAP A, IntegralAP *R)
static bool increment(IntegralAP A, IntegralAP *R)
static bool bitOr(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R)
constexpr bool singleWord() const
static void shiftRight(const IntegralAP A, const IntegralAP B, unsigned OpBits, IntegralAP *R)
bool operator>(const IntegralAP &RHS) const
APValue toAPValue(const ASTContext &) const
void bitcastToMemory(std::byte *Dest) const
static void bitcastFromMemory(const std::byte *Src, unsigned BitWidth, IntegralAP *Result)
std::string toDiagnosticString(const ASTContext &Ctx) const
IntegralAP(const APInt &V)
bool operator>=(unsigned RHS) const
APSInt toAPSInt(unsigned Bits=0) const
static IntegralAP from(T Value, unsigned NumBits=0)
ComparisonCategoryResult compare(const IntegralAP &RHS) const
IntegralAP truncate(unsigned BitWidth) const
static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R)
static void deserialize(const std::byte *Buff, IntegralAP< Signed > *Result)
static bool bitXor(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R)
IntegralAP operator-() const
IntegralAP< false > AsUnsigned
constexpr uint32_t bitWidth() const
size_t bytesToSerialize() const
static bool div(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R)
static T truncateCast(const APInt &V)
void copy(const APInt &V)
static bool sub(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R)
static bool mul(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R)
static constexpr bool isNumber()
unsigned countLeadingZeros() const
static bool comp(IntegralAP A, IntegralAP *R)
bool operator<(IntegralAP RHS) const
static bool bitAnd(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R)
static bool neg(const IntegralAP &A, IntegralAP *R)
constexpr unsigned numWords() const
FixedPoint getSwappedBytes(FixedPoint F)
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
The JSON file list parser is used to communicate input to InstallAPI.
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
@ Result
The result type of a method or function.