Skip to content

Commit 9f923f5

Browse files
committed
Run the llvm-import Script to Update to a new LLVM
This copies in Swift-LLVM stable at ab94816b593daf1c623322b0fb981abb0b156833
1 parent e510daa commit 9f923f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+9467
-13191
lines changed

include/llvm-c/Error.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*===------- llvm-c/Error.h - llvm::Error class C Interface -------*- C -*-===*\
2+
|* *|
3+
|* The LLVM Compiler Infrastructure *|
4+
|* *|
5+
|* This file is distributed under the University of Illinois Open Source *|
6+
|* License. See LICENSE.TXT for details. *|
7+
|* *|
8+
|*===----------------------------------------------------------------------===*|
9+
|* *|
10+
|* This file defines the C interface to LLVM's Error class. *|
11+
|* *|
12+
\*===----------------------------------------------------------------------===*/
13+
14+
#ifndef LLVM_C_ERROR_H
15+
#define LLVM_C_ERROR_H
16+
17+
#include "llvm/Config/indexstoredb-prefix.h"
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
#define LLVMErrorSuccess 0
24+
25+
/**
26+
* Opaque reference to an error instance. Null serves as the 'success' value.
27+
*/
28+
typedef struct LLVMOpaqueError *LLVMErrorRef;
29+
30+
/**
31+
* Error type identifier.
32+
*/
33+
typedef const void *LLVMErrorTypeId;
34+
35+
/**
36+
* Returns the type id for the given error instance, which must be a failure
37+
* value (i.e. non-null).
38+
*/
39+
LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err);
40+
41+
/**
42+
* Dispose of the given error without handling it. This operation consumes the
43+
* error, and the given LLVMErrorRef value is not usable once this call returns.
44+
* Note: This method *only* needs to be called if the error is not being passed
45+
* to some other consuming operation, e.g. LLVMGetErrorMessage.
46+
*/
47+
void LLVMConsumeError(LLVMErrorRef Err);
48+
49+
/**
50+
* Returns the given string's error message. This operation consumes the error,
51+
* and the given LLVMErrorRef value is not usable once this call returns.
52+
* The caller is responsible for disposing of the string by calling
53+
* LLVMDisposeErrorMessage.
54+
*/
55+
char *LLVMGetErrorMessage(LLVMErrorRef Err);
56+
57+
/**
58+
* Dispose of the given error message.
59+
*/
60+
void LLVMDisposeErrorMessage(char *ErrMsg);
61+
62+
/**
63+
* Returns the type id for llvm StringError.
64+
*/
65+
LLVMErrorTypeId LLVMGetStringErrorTypeId();
66+
67+
#ifdef __cplusplus
68+
}
69+
#endif
70+
71+
#endif

include/llvm-c/Types.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
8989
*/
9090
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
9191

92+
/**
93+
* Represents an LLVM Named Metadata Node.
94+
*
95+
* This models llvm::NamedMDNode.
96+
*/
97+
typedef struct LLVMOpaqueNamedMDNode *LLVMNamedMDNodeRef;
98+
99+
/**
100+
* Represents an entry in a Global Object's metadata attachments.
101+
*
102+
* This models std::pair<unsigned, MDNode *>
103+
*/
104+
typedef struct LLVMOpaqueValueMetadataEntry LLVMValueMetadataEntry;
105+
92106
/**
93107
* Represents an LLVM basic block builder.
94108
*

include/llvm/ADT/APFloat.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,13 +870,13 @@ class APFloat : public APFloatBase {
870870
/// Factory for NaN values.
871871
///
872872
/// \param Negative - True iff the NaN generated should be negative.
873-
/// \param type - The unspecified fill bits for creating the NaN, 0 by
873+
/// \param payload - The unspecified fill bits for creating the NaN, 0 by
874874
/// default. The value is truncated as necessary.
875875
static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
876-
unsigned type = 0) {
877-
if (type) {
878-
APInt fill(64, type);
879-
return getQNaN(Sem, Negative, &fill);
876+
uint64_t payload = 0) {
877+
if (payload) {
878+
APInt intPayload(64, payload);
879+
return getQNaN(Sem, Negative, &intPayload);
880880
} else {
881881
return getQNaN(Sem, Negative, nullptr);
882882
}
@@ -1243,6 +1243,32 @@ inline APFloat maxnum(const APFloat &A, const APFloat &B) {
12431243
return (A.compare(B) == APFloat::cmpLessThan) ? B : A;
12441244
}
12451245

1246+
/// Implements IEEE 754-2018 minimum semantics. Returns the smaller of 2
1247+
/// arguments, propagating NaNs and treating -0 as less than +0.
1248+
LLVM_READONLY
1249+
inline APFloat minimum(const APFloat &A, const APFloat &B) {
1250+
if (A.isNaN())
1251+
return A;
1252+
if (B.isNaN())
1253+
return B;
1254+
if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1255+
return A.isNegative() ? A : B;
1256+
return (B.compare(A) == APFloat::cmpLessThan) ? B : A;
1257+
}
1258+
1259+
/// Implements IEEE 754-2018 maximum semantics. Returns the larger of 2
1260+
/// arguments, propagating NaNs and treating -0 as less than +0.
1261+
LLVM_READONLY
1262+
inline APFloat maximum(const APFloat &A, const APFloat &B) {
1263+
if (A.isNaN())
1264+
return A;
1265+
if (B.isNaN())
1266+
return B;
1267+
if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
1268+
return A.isNegative() ? B : A;
1269+
return (A.compare(B) == APFloat::cmpLessThan) ? B : A;
1270+
}
1271+
12461272
} // namespace llvm
12471273

12481274
#undef APFLOAT_DISPATCH_ON_SEMANTICS

include/llvm/ADT/APInt.h

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class raw_ostream;
3131

3232
template <typename T> class SmallVectorImpl;
3333
template <typename T> class ArrayRef;
34+
template <typename T> class Optional;
3435

3536
class APInt;
3637

@@ -84,7 +85,7 @@ class LLVM_NODISCARD APInt {
8485
UP,
8586
};
8687

87-
static const WordType WORD_MAX = ~WordType(0);
88+
static const WordType WORDTYPE_MAX = ~WordType(0);
8889

8990
private:
9091
/// This union is used to store the integer value. When the
@@ -149,7 +150,7 @@ class LLVM_NODISCARD APInt {
149150
unsigned WordBits = ((BitWidth-1) % APINT_BITS_PER_WORD) + 1;
150151

151152
// Mask out the high bits.
152-
uint64_t mask = WORD_MAX >> (APINT_BITS_PER_WORD - WordBits);
153+
uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - WordBits);
153154
if (isSingleWord())
154155
U.VAL &= mask;
155156
else
@@ -394,7 +395,7 @@ class LLVM_NODISCARD APInt {
394395
/// This checks to see if the value has all bits of the APInt are set or not.
395396
bool isAllOnesValue() const {
396397
if (isSingleWord())
397-
return U.VAL == WORD_MAX >> (APINT_BITS_PER_WORD - BitWidth);
398+
return U.VAL == WORDTYPE_MAX >> (APINT_BITS_PER_WORD - BitWidth);
398399
return countTrailingOnesSlowCase() == BitWidth;
399400
}
400401

@@ -495,7 +496,7 @@ class LLVM_NODISCARD APInt {
495496
assert(numBits != 0 && "numBits must be non-zero");
496497
assert(numBits <= BitWidth && "numBits out of range");
497498
if (isSingleWord())
498-
return U.VAL == (WORD_MAX >> (APINT_BITS_PER_WORD - numBits));
499+
return U.VAL == (WORDTYPE_MAX >> (APINT_BITS_PER_WORD - numBits));
499500
unsigned Ones = countTrailingOnesSlowCase();
500501
return (numBits == Ones) &&
501502
((Ones + countLeadingZerosSlowCase()) == BitWidth);
@@ -559,7 +560,7 @@ class LLVM_NODISCARD APInt {
559560
///
560561
/// \returns the all-ones value for an APInt of the specified bit-width.
561562
static APInt getAllOnesValue(unsigned numBits) {
562-
return APInt(numBits, WORD_MAX, true);
563+
return APInt(numBits, WORDTYPE_MAX, true);
563564
}
564565

565566
/// Get the '0' value.
@@ -1104,6 +1105,12 @@ class LLVM_NODISCARD APInt {
11041105
APInt sshl_ov(const APInt &Amt, bool &Overflow) const;
11051106
APInt ushl_ov(const APInt &Amt, bool &Overflow) const;
11061107

1108+
// Operations that saturate
1109+
APInt sadd_sat(const APInt &RHS) const;
1110+
APInt uadd_sat(const APInt &RHS) const;
1111+
APInt ssub_sat(const APInt &RHS) const;
1112+
APInt usub_sat(const APInt &RHS) const;
1113+
11071114
/// Array-indexing support.
11081115
///
11091116
/// \returns the bit value at bitPosition
@@ -1382,7 +1389,7 @@ class LLVM_NODISCARD APInt {
13821389
/// Set every bit to 1.
13831390
void setAllBits() {
13841391
if (isSingleWord())
1385-
U.VAL = WORD_MAX;
1392+
U.VAL = WORDTYPE_MAX;
13861393
else
13871394
// Set all the bits in all the words.
13881395
memset(U.pVal, -1, getNumWords() * APINT_WORD_SIZE);
@@ -1394,7 +1401,7 @@ class LLVM_NODISCARD APInt {
13941401
///
13951402
/// Set the given bit to 1 whose position is given as "bitPosition".
13961403
void setBit(unsigned BitPosition) {
1397-
assert(BitPosition <= BitWidth && "BitPosition out of range");
1404+
assert(BitPosition < BitWidth && "BitPosition out of range");
13981405
WordType Mask = maskBit(BitPosition);
13991406
if (isSingleWord())
14001407
U.VAL |= Mask;
@@ -1415,7 +1422,7 @@ class LLVM_NODISCARD APInt {
14151422
if (loBit == hiBit)
14161423
return;
14171424
if (loBit < APINT_BITS_PER_WORD && hiBit <= APINT_BITS_PER_WORD) {
1418-
uint64_t mask = WORD_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit));
1425+
uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit));
14191426
mask <<= loBit;
14201427
if (isSingleWord())
14211428
U.VAL |= mask;
@@ -1453,7 +1460,7 @@ class LLVM_NODISCARD APInt {
14531460
///
14541461
/// Set the given bit to 0 whose position is given as "bitPosition".
14551462
void clearBit(unsigned BitPosition) {
1456-
assert(BitPosition <= BitWidth && "BitPosition out of range");
1463+
assert(BitPosition < BitWidth && "BitPosition out of range");
14571464
WordType Mask = ~maskBit(BitPosition);
14581465
if (isSingleWord())
14591466
U.VAL &= Mask;
@@ -1469,7 +1476,7 @@ class LLVM_NODISCARD APInt {
14691476
/// Toggle every bit to its opposite value.
14701477
void flipAllBits() {
14711478
if (isSingleWord()) {
1472-
U.VAL ^= WORD_MAX;
1479+
U.VAL ^= WORDTYPE_MAX;
14731480
clearUnusedBits();
14741481
} else {
14751482
flipAllBitsSlowCase();
@@ -1758,7 +1765,7 @@ class LLVM_NODISCARD APInt {
17581765
/// referencing 2 in a space where 2 does no exist.
17591766
unsigned nearestLogBase2() const {
17601767
// Special case when we have a bitwidth of 1. If VAL is 1, then we
1761-
// get 0. If VAL is 0, we get WORD_MAX which gets truncated to
1768+
// get 0. If VAL is 0, we get WORDTYPE_MAX which gets truncated to
17621769
// UINT32_MAX.
17631770
if (BitWidth == 1)
17641771
return U.VAL - 1;
@@ -2166,6 +2173,41 @@ APInt RoundingUDiv(const APInt &A, const APInt &B, APInt::Rounding RM);
21662173
/// Return A sign-divided by B, rounded by the given rounding mode.
21672174
APInt RoundingSDiv(const APInt &A, const APInt &B, APInt::Rounding RM);
21682175

2176+
/// Let q(n) = An^2 + Bn + C, and BW = bit width of the value range
2177+
/// (e.g. 32 for i32).
2178+
/// This function finds the smallest number n, such that
2179+
/// (a) n >= 0 and q(n) = 0, or
2180+
/// (b) n >= 1 and q(n-1) and q(n), when evaluated in the set of all
2181+
/// integers, belong to two different intervals [Rk, Rk+R),
2182+
/// where R = 2^BW, and k is an integer.
2183+
/// The idea here is to find when q(n) "overflows" 2^BW, while at the
2184+
/// same time "allowing" subtraction. In unsigned modulo arithmetic a
2185+
/// subtraction (treated as addition of negated numbers) would always
2186+
/// count as an overflow, but here we want to allow values to decrease
2187+
/// and increase as long as they are within the same interval.
2188+
/// Specifically, adding of two negative numbers should not cause an
2189+
/// overflow (as long as the magnitude does not exceed the bith width).
2190+
/// On the other hand, given a positive number, adding a negative
2191+
/// number to it can give a negative result, which would cause the
2192+
/// value to go from [-2^BW, 0) to [0, 2^BW). In that sense, zero is
2193+
/// treated as a special case of an overflow.
2194+
///
2195+
/// This function returns None if after finding k that minimizes the
2196+
/// positive solution to q(n) = kR, both solutions are contained between
2197+
/// two consecutive integers.
2198+
///
2199+
/// There are cases where q(n) > T, and q(n+1) < T (assuming evaluation
2200+
/// in arithmetic modulo 2^BW, and treating the values as signed) by the
2201+
/// virtue of *signed* overflow. This function will *not* find such an n,
2202+
/// however it may find a value of n satisfying the inequalities due to
2203+
/// an *unsigned* overflow (if the values are treated as unsigned).
2204+
/// To find a solution for a signed overflow, treat it as a problem of
2205+
/// finding an unsigned overflow with a range with of BW-1.
2206+
///
2207+
/// The returned value may have a different bit width from the input
2208+
/// coefficients.
2209+
Optional<APInt> SolveQuadraticEquationWrap(APInt A, APInt B, APInt C,
2210+
unsigned RangeWidth);
21692211
} // End of APIntOps namespace
21702212

21712213
// See friend declaration above. This additional declaration is required in

include/llvm/ADT/Bit.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//===-- llvm/ADT/bit.h - C++20 <bit> ----------------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This file implements the C++20 <bit> header.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_ADT_BIT_H
15+
#define LLVM_ADT_BIT_H
16+
17+
#include "llvm/Support/Compiler.h"
18+
#include <cstring>
19+
#include <type_traits>
20+
21+
namespace llvm {
22+
23+
// This implementation of bit_cast is different from the C++17 one in two ways:
24+
// - It isn't constexpr because that requires compiler support.
25+
// - It requires trivially-constructible To, to avoid UB in the implementation.
26+
template <typename To, typename From
27+
, typename = typename std::enable_if<sizeof(To) == sizeof(From)>::type
28+
#if (__has_feature(is_trivially_constructible) && defined(_LIBCPP_VERSION)) || \
29+
(defined(__GNUC__) && __GNUC__ >= 5)
30+
, typename = typename std::is_trivially_constructible<To>::type
31+
#elif __has_feature(is_trivially_constructible)
32+
, typename = typename std::enable_if<__is_trivially_constructible(To)>::type
33+
#else
34+
// See comment below.
35+
#endif
36+
#if (__has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)) || \
37+
(defined(__GNUC__) && __GNUC__ >= 5)
38+
, typename = typename std::enable_if<std::is_trivially_copyable<To>::value>::type
39+
, typename = typename std::enable_if<std::is_trivially_copyable<From>::value>::type
40+
#elif __has_feature(is_trivially_copyable)
41+
, typename = typename std::enable_if<__is_trivially_copyable(To)>::type
42+
, typename = typename std::enable_if<__is_trivially_copyable(From)>::type
43+
#else
44+
// This case is GCC 4.x. clang with libc++ or libstdc++ never get here. Unlike
45+
// llvm/Support/type_traits.h's isPodLike we don't want to provide a
46+
// good-enough answer here: developers in that configuration will hit
47+
// compilation failures on the bots instead of locally. That's acceptable
48+
// because it's very few developers, and only until we move past C++11.
49+
#endif
50+
>
51+
inline To bit_cast(const From &from) noexcept {
52+
To to;
53+
std::memcpy(&to, &from, sizeof(To));
54+
return to;
55+
}
56+
57+
} // namespace llvm
58+
59+
#endif

0 commit comments

Comments
 (0)