Author: mgrang Date: Sat Feb 24 19:58:23 2018 New Revision: 326045 URL: http://llvm.org/viewvc/llvm-project?rev=326045&view=rev Log: [RISCV] Enable __int128_t and __uint128_t through clang flag
Summary: If the flag -fforce-enable-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. Reviewers: asb, kito-cheng, apazos, efriedma Reviewed By: asb, efriedma Subscribers: shiva0217, efriedma, jfb, dschuff, sdardis, sbc100, jgravelle-google, aheejin, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, cfe-commits Differential Revision: https://reviews.llvm.org/D43105 Added: cfe/trunk/test/Driver/types.c Modified: cfe/trunk/include/clang/Basic/TargetInfo.h cfe/trunk/include/clang/Basic/TargetOptions.h cfe/trunk/include/clang/Driver/Options.td cfe/trunk/lib/Basic/Targets/Mips.h cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/test/CodeGen/riscv32-abi.c cfe/trunk/test/Preprocessor/init.c Modified: cfe/trunk/include/clang/Basic/TargetInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=326045&r1=326044&r2=326045&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/TargetInfo.h (original) +++ cfe/trunk/include/clang/Basic/TargetInfo.h Sat Feb 24 19:58:23 2018 @@ -358,7 +358,7 @@ public: /// \brief Determine whether the __int128 type is supported on this target. virtual bool hasInt128Type() const { - return getPointerWidth(0) >= 64; + return (getPointerWidth(0) >= 64) || getTargetOpts().ForceEnableInt128; } // FIXME /// \brief Determine whether the __float128 type is supported on this target. Modified: cfe/trunk/include/clang/Basic/TargetOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetOptions.h?rev=326045&r1=326044&r2=326045&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/TargetOptions.h (original) +++ cfe/trunk/include/clang/Basic/TargetOptions.h Sat Feb 24 19:58:23 2018 @@ -60,6 +60,9 @@ public: /// \brief The list of OpenCL extensions to enable or disable, as written on /// the command line. std::vector<std::string> OpenCLExtensionsAsWritten; + + /// \brief If given, enables support for __int128_t and __uint128_t types. + bool ForceEnableInt128; }; } // end namespace clang Modified: cfe/trunk/include/clang/Driver/Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=326045&r1=326044&r2=326045&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/Options.td (original) +++ cfe/trunk/include/clang/Driver/Options.td Sat Feb 24 19:58:23 2018 @@ -849,6 +849,12 @@ def fno_signaling_math : Flag<["-"], "fn 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 fforce_enable_int128 : Flag<["-"], "fforce-enable-int128">, + Group<f_Group>, Flags<[CC1Option]>, + HelpText<"Enable support for int128_t type">; +def fno_force_enable_int128 : Flag<["-"], "fno-force-enable-int128">, + Group<f_Group>, Flags<[CC1Option]>, + HelpText<"Disable support for int128_t type">; // Begin sanitizer flags. These should all be core options exposed in all driver // modes. Modified: cfe/trunk/lib/Basic/Targets/Mips.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/Mips.h?rev=326045&r1=326044&r2=326045&view=diff ============================================================================== --- cfe/trunk/lib/Basic/Targets/Mips.h (original) +++ cfe/trunk/lib/Basic/Targets/Mips.h Sat Feb 24 19:58:23 2018 @@ -392,7 +392,9 @@ public: return llvm::makeArrayRef(NewABIRegAliases); } - bool hasInt128Type() const override { return ABI == "n32" || ABI == "n64"; } + bool hasInt128Type() const override { + return (ABI == "n32" || ABI == "n64") || getTargetOpts().ForceEnableInt128; + } bool validateTarget(DiagnosticsEngine &Diags) const override; }; Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=326045&r1=326044&r2=326045&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Sat Feb 24 19:58:23 2018 @@ -4750,6 +4750,12 @@ void Clang::ConstructJob(Compilation &C, } } + if (Arg *A = Args.getLastArg(options::OPT_fforce_enable_int128, + options::OPT_fno_force_enable_int128)) { + if (A->getOption().matches(options::OPT_fforce_enable_int128)) + CmdArgs.push_back("-fforce-enable-int128"); + } + // Finally add the compile command to the compilation. if (Args.hasArg(options::OPT__SLASH_fallback) && Output.getType() == types::TY_Object && Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=326045&r1=326044&r2=326045&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sat Feb 24 19:58:23 2018 @@ -2781,6 +2781,7 @@ static void ParseTargetArgs(TargetOption if (Opts.Triple.empty()) Opts.Triple = llvm::sys::getDefaultTargetTriple(); Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ); + Opts.ForceEnableInt128 = Args.hasArg(OPT_fforce_enable_int128); } bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, Modified: cfe/trunk/test/CodeGen/riscv32-abi.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/riscv32-abi.c?rev=326045&r1=326044&r2=326045&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/riscv32-abi.c (original) +++ cfe/trunk/test/CodeGen/riscv32-abi.c Sat Feb 24 19:58:23 2018 @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -triple riscv32 -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple riscv32 -emit-llvm -fforce-enable-int128 %s -o - \ +// RUN: | FileCheck %s -check-prefixes=CHECK,CHECK-FORCEINT128 #include <stddef.h> #include <stdint.h> @@ -24,6 +26,11 @@ int32_t f_scalar_3(int32_t x) { return x // CHECK-LABEL: define i64 @f_scalar_4(i64 %x) int64_t f_scalar_4(int64_t x) { return x; } +#ifdef __SIZEOF_INT128__ +// CHECK-FORCEINT128-LABEL: define i128 @f_scalar_5(i128 %x) +__int128_t f_scalar_5(__int128_t x) { return x; } +#endif + // CHECK-LABEL: define float @f_fp_scalar_1(float %x) float f_fp_scalar_1(float x) { return x; } Added: cfe/trunk/test/Driver/types.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/types.c?rev=326045&view=auto ============================================================================== --- cfe/trunk/test/Driver/types.c (added) +++ cfe/trunk/test/Driver/types.c Sat Feb 24 19:58:23 2018 @@ -0,0 +1,18 @@ +// Check whether __int128_t and __uint128_t are supported. + +// RUN: not %clang -c --target=riscv32-unknown-linux-gnu -fsyntax-only %s \ +// RUN: 2>&1 | FileCheck %s + +// RUN: %clang -c --target=riscv32-unknown-linux-gnu -fsyntax-only %s \ +// RUN: -fno-force-enable-int128 -fforce-enable-int128 + +// RUN: not %clang -c --target=riscv32-unknown-linux-gnu -fsyntax-only %s \ +// RUN: -fforce-enable-int128 -fno-force-enable-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' Modified: cfe/trunk/test/Preprocessor/init.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=326045&r1=326044&r2=326045&view=diff ============================================================================== --- cfe/trunk/test/Preprocessor/init.c (original) +++ cfe/trunk/test/Preprocessor/init.c Sat Feb 24 19:58:23 2018 @@ -10007,6 +10007,9 @@ // RUN: | FileCheck -match-full-lines -check-prefix=RISCV32 %s // RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv32-unknown-linux < /dev/null \ // RUN: | FileCheck -match-full-lines -check-prefixes=RISCV32,RISCV32-LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv32 \ +// RUN: -fforce-enable-int128 < /dev/null | FileCheck -match-full-lines \ +// RUN: -check-prefixes=RISCV32,RISCV32-INT128 %s // RISCV32: #define _ILP32 1 // RISCV32: #define __ATOMIC_ACQUIRE 2 // RISCV32: #define __ATOMIC_ACQ_REL 4 @@ -10136,6 +10139,7 @@ // RISCV32: #define __SIG_ATOMIC_WIDTH__ 32 // RISCV32: #define __SIZEOF_DOUBLE__ 8 // RISCV32: #define __SIZEOF_FLOAT__ 4 +// RISCV32-INT128: #define __SIZEOF_INT128__ 16 // RISCV32: #define __SIZEOF_INT__ 4 // RISCV32: #define __SIZEOF_LONG_DOUBLE__ 16 // RISCV32: #define __SIZEOF_LONG_LONG__ 8 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits