Skip to content

Commit ac24bb5

Browse files
author
Mandeep Singh Grang
committedFeb 25, 2018
[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 llvm-svn: 326045
1 parent 295e8b4 commit ac24bb5

File tree

9 files changed

+49
-2
lines changed

9 files changed

+49
-2
lines changed
 

‎clang/include/clang/Basic/TargetInfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class TargetInfo : public RefCountedBase<TargetInfo> {
358358

359359
/// \brief Determine whether the __int128 type is supported on this target.
360360
virtual bool hasInt128Type() const {
361-
return getPointerWidth(0) >= 64;
361+
return (getPointerWidth(0) >= 64) || getTargetOpts().ForceEnableInt128;
362362
} // FIXME
363363

364364
/// \brief Determine whether the __float128 type is supported on this target.

‎clang/include/clang/Basic/TargetOptions.h

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class TargetOptions {
6060
/// \brief The list of OpenCL extensions to enable or disable, as written on
6161
/// the command line.
6262
std::vector<std::string> OpenCLExtensionsAsWritten;
63+
64+
/// \brief If given, enables support for __int128_t and __uint128_t types.
65+
bool ForceEnableInt128;
6366
};
6467

6568
} // end namespace clang

‎clang/include/clang/Driver/Options.td

+6
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,12 @@ def fno_signaling_math : Flag<["-"], "fno-signaling-math">, Group<f_Group>;
849849
def fjump_tables : Flag<["-"], "fjump-tables">, Group<f_Group>;
850850
def fno_jump_tables : Flag<["-"], "fno-jump-tables">, Group<f_Group>, Flags<[CC1Option]>,
851851
HelpText<"Do not use jump tables for lowering switches">;
852+
def fforce_enable_int128 : Flag<["-"], "fforce-enable-int128">,
853+
Group<f_Group>, Flags<[CC1Option]>,
854+
HelpText<"Enable support for int128_t type">;
855+
def fno_force_enable_int128 : Flag<["-"], "fno-force-enable-int128">,
856+
Group<f_Group>, Flags<[CC1Option]>,
857+
HelpText<"Disable support for int128_t type">;
852858

853859
// Begin sanitizer flags. These should all be core options exposed in all driver
854860
// modes.

‎clang/lib/Basic/Targets/Mips.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
392392
return llvm::makeArrayRef(NewABIRegAliases);
393393
}
394394

395-
bool hasInt128Type() const override { return ABI == "n32" || ABI == "n64"; }
395+
bool hasInt128Type() const override {
396+
return (ABI == "n32" || ABI == "n64") || getTargetOpts().ForceEnableInt128;
397+
}
396398

397399
bool validateTarget(DiagnosticsEngine &Diags) const override;
398400
};

‎clang/lib/Driver/ToolChains/Clang.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -4750,6 +4750,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
47504750
}
47514751
}
47524752

4753+
if (Arg *A = Args.getLastArg(options::OPT_fforce_enable_int128,
4754+
options::OPT_fno_force_enable_int128)) {
4755+
if (A->getOption().matches(options::OPT_fforce_enable_int128))
4756+
CmdArgs.push_back("-fforce-enable-int128");
4757+
}
4758+
47534759
// Finally add the compile command to the compilation.
47544760
if (Args.hasArg(options::OPT__SLASH_fallback) &&
47554761
Output.getType() == types::TY_Object &&

‎clang/lib/Frontend/CompilerInvocation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2781,6 +2781,7 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
27812781
if (Opts.Triple.empty())
27822782
Opts.Triple = llvm::sys::getDefaultTargetTriple();
27832783
Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
2784+
Opts.ForceEnableInt128 = Args.hasArg(OPT_fforce_enable_int128);
27842785
}
27852786

27862787
bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,

‎clang/test/CodeGen/riscv32-abi.c

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %clang_cc1 -triple riscv32 -emit-llvm %s -o - | FileCheck %s
2+
// RUN: %clang_cc1 -triple riscv32 -emit-llvm -fforce-enable-int128 %s -o - \
3+
// RUN: | FileCheck %s -check-prefixes=CHECK,CHECK-FORCEINT128
24

35
#include <stddef.h>
46
#include <stdint.h>
@@ -24,6 +26,11 @@ int32_t f_scalar_3(int32_t x) { return x; }
2426
// CHECK-LABEL: define i64 @f_scalar_4(i64 %x)
2527
int64_t f_scalar_4(int64_t x) { return x; }
2628

29+
#ifdef __SIZEOF_INT128__
30+
// CHECK-FORCEINT128-LABEL: define i128 @f_scalar_5(i128 %x)
31+
__int128_t f_scalar_5(__int128_t x) { return x; }
32+
#endif
33+
2734
// CHECK-LABEL: define float @f_fp_scalar_1(float %x)
2835
float f_fp_scalar_1(float x) { return x; }
2936

‎clang/test/Driver/types.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Check whether __int128_t and __uint128_t are supported.
2+
3+
// RUN: not %clang -c --target=riscv32-unknown-linux-gnu -fsyntax-only %s \
4+
// RUN: 2>&1 | FileCheck %s
5+
6+
// RUN: %clang -c --target=riscv32-unknown-linux-gnu -fsyntax-only %s \
7+
// RUN: -fno-force-enable-int128 -fforce-enable-int128
8+
9+
// RUN: not %clang -c --target=riscv32-unknown-linux-gnu -fsyntax-only %s \
10+
// RUN: -fforce-enable-int128 -fno-force-enable-int128
11+
12+
void a() {
13+
__int128_t s;
14+
__uint128_t t;
15+
}
16+
17+
// CHECK: error: use of undeclared identifier '__int128_t'
18+
// CHECK: error: use of undeclared identifier '__uint128_t'

‎clang/test/Preprocessor/init.c

+4
Original file line numberDiff line numberDiff line change
@@ -10007,6 +10007,9 @@
1000710007
// RUN: | FileCheck -match-full-lines -check-prefix=RISCV32 %s
1000810008
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv32-unknown-linux < /dev/null \
1000910009
// RUN: | FileCheck -match-full-lines -check-prefixes=RISCV32,RISCV32-LINUX %s
10010+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv32 \
10011+
// RUN: -fforce-enable-int128 < /dev/null | FileCheck -match-full-lines \
10012+
// RUN: -check-prefixes=RISCV32,RISCV32-INT128 %s
1001010013
// RISCV32: #define _ILP32 1
1001110014
// RISCV32: #define __ATOMIC_ACQUIRE 2
1001210015
// RISCV32: #define __ATOMIC_ACQ_REL 4
@@ -10136,6 +10139,7 @@
1013610139
// RISCV32: #define __SIG_ATOMIC_WIDTH__ 32
1013710140
// RISCV32: #define __SIZEOF_DOUBLE__ 8
1013810141
// RISCV32: #define __SIZEOF_FLOAT__ 4
10142+
// RISCV32-INT128: #define __SIZEOF_INT128__ 16
1013910143
// RISCV32: #define __SIZEOF_INT__ 4
1014010144
// RISCV32: #define __SIZEOF_LONG_DOUBLE__ 16
1014110145
// RISCV32: #define __SIZEOF_LONG_LONG__ 8

0 commit comments

Comments
 (0)