Skip to content

Commit 95e76c1

Browse files
committed
Revert "[IR] Remove options to make scalable TypeSize access a warning (#156336)"
This reverts commit 8f59a94. Failed on clang-aarch64-sve-vls-2stage, which still uses the option.
1 parent a7ff607 commit 95e76c1

File tree

12 files changed

+66
-8
lines changed

12 files changed

+66
-8
lines changed

llvm/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,18 @@ endif()
706706

707707
option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
708708

709+
# While adding scalable vector support to LLVM, we temporarily want to
710+
# allow an implicit conversion of TypeSize to uint64_t, and to allow
711+
# code to get the fixed number of elements from a possibly scalable vector.
712+
# This CMake flag enables a more strict mode where it asserts that the type
713+
# is not a scalable vector type.
714+
#
715+
# Enabling this flag makes it easier to find cases where the compiler makes
716+
# assumptions on the size being 'fixed size', when building tests for
717+
# SVE/SVE2 or other scalable vector architectures.
718+
option(LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS
719+
"Enable assertions that type is not scalable in implicit conversion from TypeSize to uint64_t and calls to getNumElements" OFF)
720+
709721
set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
710722
"Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
711723

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ if (LLVM_USES_LIBSTDCXX)
201201
endif()
202202
endif()
203203

204+
if (LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS)
205+
add_compile_definitions(STRICT_FIXED_SIZE_VECTORS)
206+
endif()
207+
204208
string(TOUPPER "${LLVM_ABI_BREAKING_CHECKS}" uppercase_LLVM_ABI_BREAKING_CHECKS)
205209

206210
if( uppercase_LLVM_ABI_BREAKING_CHECKS STREQUAL "WITH_ASSERTS" )

llvm/include/llvm/CodeGen/ValueTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ namespace llvm {
332332
assert(isVector() && "Invalid vector type!");
333333

334334
if (isScalableVector())
335-
llvm::reportFatalInternalError(
335+
llvm::reportInvalidSizeRequest(
336336
"Possible incorrect use of EVT::getVectorNumElements() for "
337337
"scalable vector. Scalable flag may be dropped, use "
338338
"EVT::getVectorElementCount() instead");

llvm/include/llvm/CodeGenTypes/LowLevelType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class LLT {
159159
/// vector types.
160160
constexpr uint16_t getNumElements() const {
161161
if (isScalable())
162-
llvm::reportFatalInternalError(
162+
llvm::reportInvalidSizeRequest(
163163
"Possible incorrect use of LLT::getNumElements() for "
164164
"scalable vector. Scalable flag may be dropped, use "
165165
"LLT::getElementCount() instead");

llvm/include/llvm/CodeGenTypes/MachineValueType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ namespace llvm {
294294

295295
unsigned getVectorNumElements() const {
296296
if (isScalableVector())
297-
llvm::reportFatalInternalError(
297+
llvm::reportInvalidSizeRequest(
298298
"Possible incorrect use of MVT::getVectorNumElements() for "
299299
"scalable vector. Scalable flag may be dropped, use "
300300
"MVT::getVectorElementCount() instead");

llvm/include/llvm/Support/TypeSize.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
namespace llvm {
2828

29+
/// Reports a diagnostic message to indicate an invalid size request has been
30+
/// done on a scalable vector. This function may not return.
31+
LLVM_ABI void reportInvalidSizeRequest(const char *Msg);
32+
2933
/// StackOffset holds a fixed and a scalable offset in bytes.
3034
class StackOffset {
3135
int64_t Fixed = 0;

llvm/lib/Support/CommandLine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,7 @@ static void initCommonOptions() {
26712671
initSignalsOptions();
26722672
initStatisticOptions();
26732673
initTimerOptions();
2674+
initTypeSizeOptions();
26742675
initWithColorOptions();
26752676
initDebugOptions();
26762677
initRandomSeedOptions();

llvm/lib/Support/DebugOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ void initGraphWriterOptions();
2424
void initSignalsOptions();
2525
void initStatisticOptions();
2626
void initTimerOptions();
27+
void initTypeSizeOptions();
2728
void initWithColorOptions();
2829
void initDebugOptions();
2930
void initRandomSeedOptions();

llvm/lib/Support/TypeSize.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,49 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Support/TypeSize.h"
10-
#include "llvm/Support/Error.h"
10+
#include "llvm/Support/CommandLine.h"
11+
#include "llvm/Support/ManagedStatic.h"
12+
#include "llvm/Support/WithColor.h"
13+
14+
#include "DebugOptions.h"
1115

1216
using namespace llvm;
1317

18+
#ifndef STRICT_FIXED_SIZE_VECTORS
19+
namespace {
20+
struct CreateScalableErrorAsWarning {
21+
/// The ScalableErrorAsWarning is a temporary measure to suppress errors from
22+
/// using the wrong interface on a scalable vector.
23+
static void *call() {
24+
return new cl::opt<bool>(
25+
"treat-scalable-fixed-error-as-warning", cl::Hidden,
26+
cl::desc(
27+
"Treat issues where a fixed-width property is requested from a "
28+
"scalable type as a warning, instead of an error"));
29+
}
30+
};
31+
} // namespace
32+
static ManagedStatic<cl::opt<bool>, CreateScalableErrorAsWarning>
33+
ScalableErrorAsWarning;
34+
void llvm::initTypeSizeOptions() { *ScalableErrorAsWarning; }
35+
#else
36+
void llvm::initTypeSizeOptions() {}
37+
#endif
38+
39+
void llvm::reportInvalidSizeRequest(const char *Msg) {
40+
#ifndef STRICT_FIXED_SIZE_VECTORS
41+
if (*ScalableErrorAsWarning) {
42+
WithColor::warning() << "Invalid size request on a scalable vector; " << Msg
43+
<< "\n";
44+
return;
45+
}
46+
#endif
47+
report_fatal_error("Invalid size request on a scalable vector.");
48+
}
49+
1450
TypeSize::operator TypeSize::ScalarTy() const {
1551
if (isScalable()) {
16-
reportFatalInternalError(
52+
reportInvalidSizeRequest(
1753
"Cannot implicitly convert a scalable size to a fixed-width size in "
1854
"`TypeSize::operator ScalarTy()`");
1955
return getKnownMinValue();

llvm/test/CodeGen/AArch64/sms-order-physreg-deps.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RUN: llc --verify-machineinstrs -mtriple=aarch64 -o - %s -mcpu=a64fx -aarch64-enable-pipeliner -pipeliner-max-mii=100 -pipeliner-enable-copytophi=0 -debug-only=pipeliner -run-pass=pipeliner 2>&1 | FileCheck %s
1+
# RUN: llc --verify-machineinstrs -mtriple=aarch64 -o - %s -mcpu=a64fx -aarch64-enable-pipeliner -pipeliner-max-mii=100 -pipeliner-enable-copytophi=0 -debug-only=pipeliner -run-pass=pipeliner -treat-scalable-fixed-error-as-warning 2>&1 | FileCheck %s
22

33
# REQUIRES: asserts
44

0 commit comments

Comments
 (0)