Author: Matthias Gehre
Date: 2022-06-09T07:15:03+01:00
New Revision: 7e17e15c9f01a04283524c6a6735d639aac39fe6
URL:
https://github.com/llvm/llvm-project/commit/7e17e15c9f01a04283524c6a6735d639aac39fe6
DIFF:
https://github.com/llvm/llvm-project/commit/7e17e15c9f01a04283524c6a6735d639aac39fe6.diff
LOG: clang: Introduce -fexperimental-max-bitint-width
This splits of the introduction of -fexperimental-max-bitint-width
from https://reviews.llvm.org/D122234
because that PR is still blocked on discussions on the backend side.
I was asked [0] to upstream at least the flag.
[0]
https://github.com/llvm/llvm-project/commit/09854f2af3b914b616f29cb640bede3a27cf7c4e#commitcomment-75116619
Differential Revision: https://reviews.llvm.org/D127287
Added:
clang/test/Sema/large-bit-int.c
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/TargetInfo.h
clang/include/clang/Driver/Options.td
clang/lib/Basic/TargetInfo.cpp
clang/lib/Serialization/ASTReader.cpp
Removed:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1b1649ac09c87..1ead55633a093 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -291,6 +291,11 @@ New Compiler Flags
``-mfix-cortex-a72-aes-1655431``. The pass is enabled when using either of
these cpus with ``-mcpu=`` and can be disabled using
``-mno-fix-cortex-a57-aes-1742098`` or ``-mno-fix-cortex-a72-aes-1655431``.
+- Added the ``-fexperimental-max-bitint-width=`` option to increase the maximum
+ allowed bit width of ``_BitInt`` types beyond the default of 128 bits. Some
+ operations, such as division or float-to-integer conversion, on ``_BitInt``
+ types with more than 128 bits currently crash clang. This option will be
+ removed in the future once clang supports all such operations.
Deprecated Compiler Flags
-
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 9c4d639178145..af6ff6292256e 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -446,6 +446,11 @@ ENUM_LANGOPT(ExtendIntArgs, ExtendArgsKind, 1,
ExtendArgsKind::ExtendTo32,
VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
+// This option will be removed in the future once the backend
+// supports all operations (like division or float-to-integer conversion)
+// on large _BitInts.
+BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
+
#undef LANGOPT
#undef COMPATIBLE_LANGOPT
#undef BENIGN_LANGOPT
diff --git a/clang/include/clang/Basic/TargetInfo.h
b/clang/include/clang/Basic/TargetInfo.h
index e4b5f0b751c48..5877123dab249 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -31,6 +31,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Frontend/OpenMP/OMPGridValues.h"
+#include "llvm/IR/DerivedTypes.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/VersionTuple.h"
@@ -235,6 +236,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
unsigned MaxOpenCLWorkGroupSize;
+ Optional MaxBitIntWidth;
+
Optional DarwinTargetVariantTriple;
// TargetInfo Constructor. Default initializes all fields.
@@ -595,11 +598,16 @@ class TargetInfo : public virtual TransferrableTargetInfo,
// Different targets may support a
diff erent maximum width for the _BitInt
// type, depending on what operations are supported.
virtual size_t getMaxBitIntWidth() const {
+// Consider -fexperimental-max-bitint-width= first.
+if (MaxBitIntWidth)
+ return std::min(*MaxBitIntWidth,
llvm::IntegerType::MAX_INT_BITS);
+
// FIXME: this value should be llvm::IntegerType::MAX_INT_BITS, which is
// maximum bit width that LLVM claims its IR can support. However, most
-// backends currently have a bug where they only support division
-// operations on types that are <= 128 bits and crash otherwise. We're
-// setting the max supported value to 128 to be conservative.
+// backends currently have a bug where they only support float to int
+// conversion (and vice versa) on types that are <= 128 bits and crash
+// otherwise. We're setting the max supported value to 128 to be
+// conservative.
return 128;
}
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index de3cd2ded8bef..6707714f170b3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6093,6 +6093,12 @@ def fobjc_gc_only : Flag<["-"], "fobjc-gc-only">,
Group,
def fobjc_gc : Flag<["-"], "fobjc-gc">, Group,
HelpText<"Enable Objective-C garbage collection">;
+def fexperimental_max_bitint_width_EQ:
+ Joined<["