Skip to content

Commit

Permalink
Merged master:7f34b9ddf817 into amd-gfx:c4699df8d15a
Browse files Browse the repository at this point in the history
Local branch amd-gfx c4699df Merged master:9b0578d54631 into amd-gfx:bd1ebe497adc
Remote branch master 7f34b9d [Sphinx] Fix langref formatting. NFC
  • Loading branch information
Sw authored and Sw committed Nov 10, 2020
2 parents c4699df + 7f34b9d commit 8988583
Show file tree
Hide file tree
Showing 167 changed files with 4,146 additions and 4,198 deletions.
24 changes: 12 additions & 12 deletions compiler-rt/lib/builtins/int_div_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ static __inline fixuint_t __umodXi3(fixuint_t n, fixuint_t d) {
#ifdef COMPUTE_UDIV
static __inline fixint_t __divXi3(fixint_t a, fixint_t b) {
const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
fixint_t s_a = a >> N; // s_a = a < 0 ? -1 : 0
fixint_t s_b = b >> N; // s_b = b < 0 ? -1 : 0
a = (a ^ s_a) - s_a; // negate if s_a == -1
b = (b ^ s_b) - s_b; // negate if s_b == -1
s_a ^= s_b; // sign of quotient
return (COMPUTE_UDIV(a, b) ^ s_a) - s_a; // negate if s_a == -1
fixint_t s_a = a >> N; // s_a = a < 0 ? -1 : 0
fixint_t s_b = b >> N; // s_b = b < 0 ? -1 : 0
fixuint_t a_u = (fixuint_t)(a ^ s_a) + (-s_a); // negate if s_a == -1
fixuint_t b_u = (fixuint_t)(b ^ s_b) + (-s_b); // negate if s_b == -1
s_a ^= s_b; // sign of quotient
return (COMPUTE_UDIV(a_u, b_u) ^ s_a) + (-s_a); // negate if s_a == -1
}
#endif // COMPUTE_UDIV

#ifdef ASSIGN_UMOD
static __inline fixint_t __modXi3(fixint_t a, fixint_t b) {
const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
fixint_t s = b >> N; // s = b < 0 ? -1 : 0
b = (b ^ s) - s; // negate if s == -1
s = a >> N; // s = a < 0 ? -1 : 0
a = (a ^ s) - s; // negate if s == -1
fixint_t s = b >> N; // s = b < 0 ? -1 : 0
fixuint_t b_u = (fixuint_t)(b ^ s) + (-s); // negate if s == -1
s = a >> N; // s = a < 0 ? -1 : 0
fixuint_t a_u = (fixuint_t)(a ^ s) + (-s); // negate if s == -1
fixuint_t res;
ASSIGN_UMOD(res, a, b);
return (res ^ s) - s; // negate if s == -1
ASSIGN_UMOD(res, a_u, b_u);
return (res ^ s) + (-s); // negate if s == -1
}
#endif // ASSIGN_UMOD
5 changes: 3 additions & 2 deletions libcxx/include/__config
Original file line number Diff line number Diff line change
Expand Up @@ -1219,8 +1219,9 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
# endif
#endif

#if defined(__BIONIC__) || defined(__CloudABI__) || \
defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC)
#if defined(__BIONIC__) || defined(__CloudABI__) || \
defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) || \
defined(__MVS__)
#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
#endif

Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__locale
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#if defined(_LIBCPP_MSVCRT_LIKE)
# include <cstring>
# include <support/win32/locale_win32.h>
#elif defined(_AIX)
#elif defined(_AIX) || defined(__MVS__)
# include <support/ibm/xlocale.h>
#elif defined(__ANDROID__)
# include <support/android/locale_bionic.h>
Expand Down
13 changes: 9 additions & 4 deletions libcxx/include/support/ibm/xlocale.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#define _LIBCPP_SUPPORT_IBM_XLOCALE_H
#include <support/ibm/locale_mgmt_aix.h>

#if defined(_AIX)
#include "cstdlib"

#ifdef __cplusplus
extern "C" {
#endif

#if defined(_AIX)
#if !defined(_AIX71)
// AIX 7.1 and higher has these definitions. Definitions and stubs
// are provied here as a temporary workaround on AIX 6.1.
Expand Down Expand Up @@ -207,14 +207,20 @@ size_t wcsxfrm_l(wchar_t *__ws1, const wchar_t *__ws2, size_t __n,
}
#endif // !defined(_AIX71)

// strftime_l() is defined by POSIX. However, AIX 7.1 does not have it
// implemented yet.
// strftime_l() is defined by POSIX. However, AIX 7.1 and z/OS do not have it
// implemented yet. z/OS retrieves it from the POSIX fallbacks.
static inline
size_t strftime_l(char *__s, size_t __size, const char *__fmt,
const struct tm *__tm, locale_t locale) {
return __xstrftime(locale, __s, __size, __fmt, __tm);
}

#elif defined(__MVS__)
#include <wctype.h>
// POSIX routines
#include <support/xlocale/__posix_l_fallback.h>
#endif // defined(__MVS__)

// The following are not POSIX routines. These are quick-and-dirty hacks
// to make things pretend to work
static inline
Expand Down Expand Up @@ -266,5 +272,4 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
#ifdef __cplusplus
}
#endif
#endif // defined(_AIX)
#endif // _LIBCPP_SUPPORT_IBM_XLOCALE_H
2 changes: 2 additions & 0 deletions lldb/include/lldb/Utility/Scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class Scalar {
}
Scalar(llvm::APInt v)
: m_type(e_int), m_integer(std::move(v), false), m_float(0.0f) {}
Scalar(llvm::APSInt v)
: m_type(e_int), m_integer(std::move(v)), m_float(0.0f) {}

bool SignExtend(uint32_t bit_pos);

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/API/SystemInitializerFull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ llvm::Error SystemInitializerFull::Initialize() {
// this, we terminate here before the uninitialized debugger inevitably
// crashes.
if (repro::Reproducer::Instance().IsReplaying())
llvm::report_fatal_error("system initialization failed");
llvm::report_fatal_error(std::move(error));
return error;
}

Expand Down
47 changes: 31 additions & 16 deletions lldb/source/Expression/DWARFExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,16 @@ bool DWARFExpression::Evaluate(
Value pieces; // Used for DW_OP_piece

Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
// A generic type is "an integral type that has the size of an address and an
// unspecified signedness". For now, just use the signedness of the operand.
// TODO: Implement a real typed stack, and store the genericness of the value
// there.
auto to_generic = [&](auto v) {
bool is_signed = std::is_signed<decltype(v)>::value;
return Scalar(llvm::APSInt(
llvm::APInt(8 * opcodes.GetAddressByteSize(), v, is_signed),
!is_signed));
};

while (opcodes.ValidOffset(offset)) {
const lldb::offset_t op_offset = offset;
Expand Down Expand Up @@ -1251,37 +1261,42 @@ bool DWARFExpression::Evaluate(
// All DW_OP_constXXX opcodes have a single operand as noted below:
//
// Opcode Operand 1
// DW_OP_const1u 1-byte unsigned integer constant DW_OP_const1s
// 1-byte signed integer constant DW_OP_const2u 2-byte unsigned integer
// constant DW_OP_const2s 2-byte signed integer constant DW_OP_const4u
// 4-byte unsigned integer constant DW_OP_const4s 4-byte signed integer
// constant DW_OP_const8u 8-byte unsigned integer constant DW_OP_const8s
// 8-byte signed integer constant DW_OP_constu unsigned LEB128 integer
// constant DW_OP_consts signed LEB128 integer constant
// DW_OP_const1u 1-byte unsigned integer constant
// DW_OP_const1s 1-byte signed integer constant
// DW_OP_const2u 2-byte unsigned integer constant
// DW_OP_const2s 2-byte signed integer constant
// DW_OP_const4u 4-byte unsigned integer constant
// DW_OP_const4s 4-byte signed integer constant
// DW_OP_const8u 8-byte unsigned integer constant
// DW_OP_const8s 8-byte signed integer constant
// DW_OP_constu unsigned LEB128 integer constant
// DW_OP_consts signed LEB128 integer constant
case DW_OP_const1u:
stack.push_back(Scalar((uint8_t)opcodes.GetU8(&offset)));
stack.push_back(to_generic(opcodes.GetU8(&offset)));
break;
case DW_OP_const1s:
stack.push_back(Scalar((int8_t)opcodes.GetU8(&offset)));
stack.push_back(to_generic((int8_t)opcodes.GetU8(&offset)));
break;
case DW_OP_const2u:
stack.push_back(Scalar((uint16_t)opcodes.GetU16(&offset)));
stack.push_back(to_generic(opcodes.GetU16(&offset)));
break;
case DW_OP_const2s:
stack.push_back(Scalar((int16_t)opcodes.GetU16(&offset)));
stack.push_back(to_generic((int16_t)opcodes.GetU16(&offset)));
break;
case DW_OP_const4u:
stack.push_back(Scalar((uint32_t)opcodes.GetU32(&offset)));
stack.push_back(to_generic(opcodes.GetU32(&offset)));
break;
case DW_OP_const4s:
stack.push_back(Scalar((int32_t)opcodes.GetU32(&offset)));
stack.push_back(to_generic((int32_t)opcodes.GetU32(&offset)));
break;
case DW_OP_const8u:
stack.push_back(Scalar((uint64_t)opcodes.GetU64(&offset)));
stack.push_back(to_generic(opcodes.GetU64(&offset)));
break;
case DW_OP_const8s:
stack.push_back(Scalar((int64_t)opcodes.GetU64(&offset)));
stack.push_back(to_generic((int64_t)opcodes.GetU64(&offset)));
break;
// These should also use to_generic, but we can't do that due to a
// producer-side bug in llvm. See llvm.org/pr48087.
case DW_OP_constu:
stack.push_back(Scalar(opcodes.GetULEB128(&offset)));
break;
Expand Down Expand Up @@ -1888,7 +1903,7 @@ bool DWARFExpression::Evaluate(
case DW_OP_lit29:
case DW_OP_lit30:
case DW_OP_lit31:
stack.push_back(Scalar((uint64_t)(op - DW_OP_lit0)));
stack.push_back(to_generic(op - DW_OP_lit0));
break;

// OPCODE: DW_OP_regN
Expand Down
64 changes: 50 additions & 14 deletions lldb/unittests/Expression/DWARFExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,37 @@ TEST(DWARFExpression, DW_OP_pick) {
llvm::Failed());
}

TEST(DWARFExpression, DW_OP_const) {
// Extend to address size.
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const1u, 0x88}), llvm::HasValue(0x88));
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const1s, 0x88}),
llvm::HasValue(0xffffff88));
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const2u, 0x47, 0x88}),
llvm::HasValue(0x8847));
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const2s, 0x47, 0x88}),
llvm::HasValue(0xffff8847));
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const4u, 0x44, 0x42, 0x47, 0x88}),
llvm::HasValue(0x88474244));
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const4s, 0x44, 0x42, 0x47, 0x88}),
llvm::HasValue(0x88474244));

// Truncate to address size.
EXPECT_THAT_EXPECTED(
Evaluate({DW_OP_const8u, 0x00, 0x11, 0x22, 0x33, 0x44, 0x42, 0x47, 0x88}),
llvm::HasValue(0x33221100));
EXPECT_THAT_EXPECTED(
Evaluate({DW_OP_const8s, 0x00, 0x11, 0x22, 0x33, 0x44, 0x42, 0x47, 0x88}),
llvm::HasValue(0x33221100));

// Don't truncate to address size for compatibility with clang (pr48087).
EXPECT_THAT_EXPECTED(
Evaluate({DW_OP_constu, 0x81, 0x82, 0x84, 0x88, 0x90, 0xa0, 0x40}),
llvm::HasValue(0x01010101010101));
EXPECT_THAT_EXPECTED(
Evaluate({DW_OP_consts, 0x81, 0x82, 0x84, 0x88, 0x90, 0xa0, 0x40}),
llvm::HasValue(0xffff010101010101));
}

TEST(DWARFExpression, DW_OP_convert) {
/// Auxiliary debug info.
const char *yamldata = R"(
Expand Down Expand Up @@ -157,29 +188,34 @@ TEST(DWARFExpression, DW_OP_convert) {
// Positive tests.
//

// Truncate to default unspecified (pointer-sized) type.
EXPECT_THAT_EXPECTED(
t.Eval({DW_OP_const8u, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, //
DW_OP_convert, 0x00}),
llvm::HasValue(GetScalar(32, 0x44332211, not_signed)));
// Truncate to 32 bits.
EXPECT_THAT_EXPECTED(t.Eval({DW_OP_const8u, //
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,//
// Leave as is.
EXPECT_THAT_EXPECTED(t.Eval({DW_OP_const4u, 0x11, 0x22, 0x33, 0x44, //
DW_OP_convert, offs_uint32_t}),
llvm::HasValue(GetScalar(32, 0x44332211, not_signed)));
llvm::HasValue(GetScalar(64, 0x44332211, not_signed)));

// Leave as is.
EXPECT_THAT_EXPECTED(
t.Eval({DW_OP_const8u, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, //
DW_OP_convert, offs_uint64_t}),
llvm::HasValue(GetScalar(64, 0x8877665544332211, not_signed)));
// Zero-extend to 64 bits.
EXPECT_THAT_EXPECTED(t.Eval({DW_OP_const4u, 0x11, 0x22, 0x33, 0x44, //
DW_OP_convert, offs_uint64_t}),
llvm::HasValue(GetScalar(64, 0x44332211, not_signed)));

// Sign-extend to 64 bits.
EXPECT_THAT_EXPECTED(
t.Eval({DW_OP_const4s, 0xcc, 0xdd, 0xee, 0xff, //
DW_OP_convert, offs_sint64_t}),
llvm::HasValue(GetScalar(64, 0xffffffffffeeddcc, is_signed)));

// Sign-extend, then truncate.
EXPECT_THAT_EXPECTED(t.Eval({DW_OP_const4s, 0xcc, 0xdd, 0xee, 0xff, //
DW_OP_convert, offs_sint64_t, //
DW_OP_convert, offs_uint32_t}),
llvm::HasValue(GetScalar(32, 0xffeeddcc, not_signed)));

// Truncate to default unspecified (pointer-sized) type.
EXPECT_THAT_EXPECTED(t.Eval({DW_OP_const4s, 0xcc, 0xdd, 0xee, 0xff, //
DW_OP_convert, offs_sint64_t, //
DW_OP_convert, 0x00}),
llvm::HasValue(GetScalar(32, 0xffeeddcc, not_signed)));

// Truncate to 8 bits.
EXPECT_THAT_EXPECTED(
t.Eval({DW_OP_const4s, 'A', 'B', 'C', 'D', DW_OP_convert, offs_uchar}),
Expand Down
39 changes: 39 additions & 0 deletions llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15502,6 +15502,45 @@ on their operand. It's a hint to the backend that can use this to set up the
hardware-loop count with a target specific instruction, usually a move of this
value to a special register or a hardware-loop instruction.


'``llvm.start.loop.iterations.*``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Syntax:
"""""""

This is an overloaded intrinsic.

::

declare i32 @llvm.start.loop.iterations.i32(i32)
declare i64 @llvm.start.loop.iterations.i64(i64)

Overview:
"""""""""

The '``llvm.start.loop.iterations.*``' intrinsics are similar to the
'``llvm.set.loop.iterations.*``' intrinsics, used to specify the
hardware-loop trip count but also produce a value identical to the input
that can be used as the input to the loop. They are placed in the loop
preheader basic block and the output is expected to be the input to the
phi for the induction variable of the loop, decremented by the
'``llvm.loop.decrement.reg.*``'.

Arguments:
""""""""""

The integer operand is the loop trip count of the hardware-loop, and thus
not e.g. the loop back-edge taken count.

Semantics:
""""""""""

The '``llvm.start.loop.iterations.*``' intrinsics do not perform any arithmetic
on their operand. It's a hint to the backend that can use this to set up the
hardware-loop count with a target specific instruction, usually a move of this
value to a special register or a hardware-loop instruction.

'``llvm.test.set.loop.iterations.*``' Intrinsic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/IR/Intrinsics.td
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,11 @@ def int_matrix_column_major_store
def int_set_loop_iterations :
DefaultAttrsIntrinsic<[], [llvm_anyint_ty], [IntrNoDuplicate]>;

// Same as the above, but produces a value (the same as the input operand) to
// be fed into the loop.
def int_start_loop_iterations :
DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], [IntrNoDuplicate]>;

// Specify that the value given is the number of iterations that the next loop
// will execute. Also test that the given count is not zero, allowing it to
// control entry to a 'while' loop.
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6672,6 +6672,10 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
const SCEV *ClampedX = getUMinExpr(X, getNotSCEV(Y));
return getAddExpr(ClampedX, Y, SCEV::FlagNUW);
}
case Intrinsic::start_loop_iterations:
// A start_loop_iterations is just equivalent to the first operand for
// SCEV purposes.
return getSCEV(II->getArgOperand(0));
default:
break;
}
Expand Down
Loading

0 comments on commit 8988583

Please sign in to comment.