1//===--- ExprConstShared.h - Shared consetxpr functionality ----*- 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// Shared functionality between the new constant expression
10// interpreter (AST/ByteCode/) and the current one (ExprConstant.cpp).
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
15#define LLVM_CLANG_LIB_AST_EXPRCONSTSHARED_H
16
17#include "clang/Basic/TypeTraits.h"
18#include <cstdint>
19#include <optional>
20
21namespace llvm {
22class APFloat;
23class APSInt;
24class APInt;
25}
26namespace clang {
27class QualType;
28class LangOptions;
29class ASTContext;
30class CharUnits;
31class Expr;
32} // namespace clang
33using namespace clang;
34/// Values returned by __builtin_classify_type, chosen to match the values
35/// produced by GCC's builtin.
36enum class GCCTypeClass {
37 None = -1,
38 Void = 0,
39 Integer = 1,
40 // GCC reserves 2 for character types, but instead classifies them as
41 // integers.
42 Enum = 3,
43 Bool = 4,
44 Pointer = 5,
45 // GCC reserves 6 for references, but appears to never use it (because
46 // expressions never have reference type, presumably).
47 PointerToDataMember = 7,
48 RealFloat = 8,
49 Complex = 9,
50 // GCC reserves 10 for functions, but does not use it since GCC version 6 due
51 // to decay to pointer. (Prior to version 6 it was only used in C++ mode).
52 // GCC claims to reserve 11 for pointers to member functions, but *actually*
53 // uses 12 for that purpose, same as for a class or struct. Maybe it
54 // internally implements a pointer to member as a struct? Who knows.
55 PointerToMemberFunction = 12, // Not a bug, see above.
56 ClassOrStruct = 12,
57 Union = 13,
58 // GCC reserves 14 for arrays, but does not use it since GCC version 6 due to
59 // decay to pointer. (Prior to version 6 it was only used in C++ mode).
60 // GCC reserves 15 for strings, but actually uses 5 (pointer) for string
61 // literals.
62 // Lang = 16,
63 // OpaqueType = 17,
64 BitInt = 18,
65 Vector = 19
66};
67
68GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
69 const LangOptions &LangOpts);
70
71void HandleComplexComplexMul(llvm::APFloat A, llvm::APFloat B, llvm::APFloat C,
72 llvm::APFloat D, llvm::APFloat &ResR,
73 llvm::APFloat &ResI);
74void HandleComplexComplexDiv(llvm::APFloat A, llvm::APFloat B, llvm::APFloat C,
75 llvm::APFloat D, llvm::APFloat &ResR,
76 llvm::APFloat &ResI);
77
78CharUnits GetAlignOfExpr(const ASTContext &Ctx, const Expr *E,
79 UnaryExprOrTypeTrait ExprKind);
80
81uint8_t GFNIMultiplicativeInverse(uint8_t Byte);
82uint8_t GFNIMul(uint8_t AByte, uint8_t BByte);
83uint8_t GFNIAffine(uint8_t XByte, const llvm::APInt &AQword,
84 const llvm::APSInt &Imm, bool Inverse = false);
85llvm::APSInt NormalizeRotateAmount(const llvm::APSInt &Value,
86 const llvm::APSInt &Amount);
87
88std::optional<llvm::APFloat>
89EvalScalarMinMaxFp(const llvm::APFloat &A, const llvm::APFloat &B,
90 std::optional<llvm::APSInt> RoundingMode, bool IsMin);
91
92#endif
93