mgrang created this revision.
mgrang added reviewers: asb, kito-cheng, apazos.
Herald added subscribers: cfe-commits, niosHD, sabuasal, jordy.potman.lists,
simoncook, johnrusso, rbar, aheejin, jgravelle-google, sbc100, sdardis,
dschuff, jfb.
If the flag -fuse-int128 is passed, it will enable support for __int128_t and
uint128_t types.
This flag can then be used to build compiler-rt for RISCV32.
Repository:
rC Clang
https://reviews.llvm.org/D43105
Files:
include/clang/Basic/LangOptions.def
include/clang/Basic/TargetInfo.h
include/clang/Driver/Options.td
lib/Basic/Targets/Mips.h
lib/Basic/Targets/RISCV.h
lib/Basic/Targets/WebAssembly.h
lib/Basic/Targets/X86.h
lib/CodeGen/SwiftCallingConv.cpp
lib/Driver/ToolChains/Clang.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Frontend/InitPreprocessor.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaOverload.cpp
lib/Sema/SemaType.cpp
test/Driver/types.c
Index: test/Driver/types.c
===================================================================
--- /dev/null
+++ test/Driver/types.c
@@ -0,0 +1,14 @@
+// Check whether __int128_t and __uint128_t are supported.
+
+// RUN: not %clang -c --target=riscv32-unknown-linux-gnu %s \
+// RUN: 2>&1 | FileCheck %s
+
+// RUN: %clang -c --target=riscv32-unknown-linux-gnu %s -fuse-int128
+
+void a() {
+ __int128_t s;
+ __uint128_t t;
+}
+
+// CHECK: error: use of undeclared identifier '__int128_t'
+// CHECK: error: use of undeclared identifier '__uint128_t'
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1385,7 +1385,7 @@
break;
}
case DeclSpec::TST_int128:
- if (!S.Context.getTargetInfo().hasInt128Type())
+ if (!S.Context.getTargetInfo().hasInt128Type(S.getLangOpts()))
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
<< "__int128";
if (DS.getTypeSpecSign() == DeclSpec::TSS_unsigned)
Index: lib/Sema/SemaOverload.cpp
===================================================================
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -7680,12 +7680,12 @@
ArithmeticTypes.push_back(S.Context.IntTy);
ArithmeticTypes.push_back(S.Context.LongTy);
ArithmeticTypes.push_back(S.Context.LongLongTy);
- if (S.Context.getTargetInfo().hasInt128Type())
+ if (S.Context.getTargetInfo().hasInt128Type(S.getLangOpts()))
ArithmeticTypes.push_back(S.Context.Int128Ty);
ArithmeticTypes.push_back(S.Context.UnsignedIntTy);
ArithmeticTypes.push_back(S.Context.UnsignedLongTy);
ArithmeticTypes.push_back(S.Context.UnsignedLongLongTy);
- if (S.Context.getTargetInfo().hasInt128Type())
+ if (S.Context.getTargetInfo().hasInt128Type(S.getLangOpts()))
ArithmeticTypes.push_back(S.Context.UnsignedInt128Ty);
LastPromotedIntegralType = ArithmeticTypes.size();
LastPromotedArithmeticType = ArithmeticTypes.size();
Index: lib/Sema/Sema.cpp
===================================================================
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -196,7 +196,7 @@
return;
// Initialize predefined 128-bit integer types, if needed.
- if (Context.getTargetInfo().hasInt128Type()) {
+ if (Context.getTargetInfo().hasInt128Type(getLangOpts())) {
// If either of the 128-bit integer types are unavailable to name lookup,
// define them now.
DeclarationName Int128 = &Context.Idents.get("__int128_t");
Index: lib/Frontend/InitPreprocessor.cpp
===================================================================
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -778,7 +778,7 @@
TI.getTypeWidth(TI.getWCharType()), TI, Builder);
DefineTypeSizeof("__SIZEOF_WINT_T__",
TI.getTypeWidth(TI.getWIntType()), TI, Builder);
- if (TI.hasInt128Type())
+ if (TI.hasInt128Type(LangOpts))
DefineTypeSizeof("__SIZEOF_INT128__", 128, TI, Builder);
DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
@@ -1048,7 +1048,7 @@
Builder.defineMacro("__IMAGE_SUPPORT__");
}
- if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
+ if (TI.hasInt128Type(LangOpts) && LangOpts.CPlusPlus && LangOpts.GNUMode) {
// For each extended integer type, g++ defines a macro mapping the
// index of the type (0 in this case) in some list of extended types
// to the type.
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2343,6 +2343,7 @@
Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns)
| Opts.NativeHalfArgsAndReturns;
Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
+ Opts.UseInt128 = Args.hasArg(OPT_fuse_int128);
// __declspec is enabled by default for the PS4 by the driver, and also
// enabled for Microsoft Extensions or Borland Extensions, here.
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -1705,6 +1705,11 @@
CmdArgs.push_back("-target-abi");
CmdArgs.push_back(ABIName);
+
+ if (Triple.getArch() == llvm::Triple::riscv32) {
+ if (Args.hasArg(options::OPT_fuse_int128))
+ CmdArgs.push_back("-fuse-int128");
+ }
}
void Clang::AddSparcTargetArgs(const ArgList &Args,
Index: lib/CodeGen/SwiftCallingConv.cpp
===================================================================
--- lib/CodeGen/SwiftCallingConv.cpp
+++ lib/CodeGen/SwiftCallingConv.cpp
@@ -632,7 +632,8 @@
return true;
case 128:
- return CGM.getContext().getTargetInfo().hasInt128Type();
+ return CGM.getContext().getTargetInfo().hasInt128Type(
+ CGM.getContext().getLangOpts());
default:
return false;
Index: lib/Basic/Targets/X86.h
===================================================================
--- lib/Basic/Targets/X86.h
+++ lib/Basic/Targets/X86.h
@@ -637,7 +637,7 @@
}
// for x32 we need it here explicitly
- bool hasInt128Type() const override { return true; }
+ bool hasInt128Type(const LangOptions &Opts) const override { return true; }
unsigned getUnwindWordWidth() const override { return 64; }
Index: lib/Basic/Targets/WebAssembly.h
===================================================================
--- lib/Basic/Targets/WebAssembly.h
+++ lib/Basic/Targets/WebAssembly.h
@@ -98,7 +98,7 @@
bool isCLZForZeroUndef() const final { return false; }
- bool hasInt128Type() const final { return true; }
+ bool hasInt128Type(const LangOptions &Opts) const final { return true; }
IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
// WebAssembly prefers long long for explicitly 64-bit integers.
Index: lib/Basic/Targets/RISCV.h
===================================================================
--- lib/Basic/Targets/RISCV.h
+++ lib/Basic/Targets/RISCV.h
@@ -14,6 +14,7 @@
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
#define LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
+#include "Targets.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/ADT/Triple.h"
@@ -60,6 +61,7 @@
return false;
}
};
+
class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
public:
RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
@@ -78,7 +80,12 @@
}
return false;
}
+
+ bool hasInt128Type(const LangOptions &Opts) const override {
+ return Opts.UseInt128;
+ }
};
+
class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
public:
RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Index: lib/Basic/Targets/Mips.h
===================================================================
--- lib/Basic/Targets/Mips.h
+++ lib/Basic/Targets/Mips.h
@@ -387,7 +387,9 @@
return llvm::makeArrayRef(NewABIRegAliases);
}
- bool hasInt128Type() const override { return ABI == "n32" || ABI == "n64"; }
+ bool hasInt128Type(const LangOptions &Opts) const override {
+ return ABI == "n32" || ABI == "n64";
+ }
bool validateTarget(DiagnosticsEngine &Diags) const override;
};
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -839,6 +839,8 @@
def fjump_tables : Flag<["-"], "fjump-tables">, Group<f_Group>;
def fno_jump_tables : Flag<["-"], "fno-jump-tables">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Do not use jump tables for lowering switches">;
+def fuse_int128 : Flag<["-"], "fuse-int128">, Group<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Enable support for int128_t type">;
// Begin sanitizer flags. These should all be core options exposed in all driver
// modes.
Index: include/clang/Basic/TargetInfo.h
===================================================================
--- include/clang/Basic/TargetInfo.h
+++ include/clang/Basic/TargetInfo.h
@@ -357,7 +357,7 @@
unsigned getLongLongAlign() const { return LongLongAlign; }
/// \brief Determine whether the __int128 type is supported on this target.
- virtual bool hasInt128Type() const {
+ virtual bool hasInt128Type(const LangOptions &Opts) const {
return getPointerWidth(0) >= 64;
} // FIXME
Index: include/clang/Basic/LangOptions.def
===================================================================
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -277,6 +277,8 @@
LANGOPT(XRayAlwaysEmitCustomEvents, 1, 0,
"controls whether to always emit intrinsic calls to "
"__xray_customevent(...) builtin.")
+LANGOPT(UseInt128, 1, 0, "controls whether __int128_t and __uint128_t "
+ "are supported")
BENIGN_LANGOPT(AllowEditorPlaceholders, 1, 0,
"allow editor placeholders in source")
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits