Skip to content

Commit 15993ac

Browse files
committed
Make the OpenCL type opt-in, and only use it for non-header and non-lib
X86 builtins. This minimizes the delta from the non-TableGen and avoids unintended consequences on other targets.
1 parent c15684d commit 15993ac

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

clang/include/clang/Basic/BuiltinsBase.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class Builtin {
8888
// On some platforms, some functions are actually macros. In that case we need
8989
// to #undef them.
9090
bit RequiresUndef = 0;
91+
// Enables builtins to generate `long long` outside of OpenCL and `long` inside.
92+
bit EnableOpenCLLong = 0;
9193
}
9294

9395
class CustomEntry {

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ include "clang/Basic/BuiltinsBase.td"
1515
class X86Builtin<string prototype> : TargetBuiltin {
1616
let Spellings = ["__builtin_ia32_" # NAME];
1717
let Prototype = prototype;
18+
let EnableOpenCLLong = 1;
1819
}
1920

2021
class X86NoPrefixBuiltin<string prototype> : TargetBuiltin {
@@ -29,7 +30,9 @@ class X86LibBuiltin<string prototype> : TargetLibBuiltin {
2930

3031
def rdpmc : X86Builtin<"unsigned long long int(int)">;
3132
def rdtsc : X86Builtin<"unsigned long long int()">;
32-
def __rdtsc : X86NoPrefixBuiltin<"unsigned long long int()">;
33+
def __rdtsc : X86NoPrefixBuiltin<"unsigned long long int()"> {
34+
let EnableOpenCLLong = 1;
35+
}
3336
def rdtscp : X86Builtin<"unsigned long long int(unsigned int*)">;
3437

3538
// Undefined Values
@@ -1023,7 +1026,7 @@ let Features = "rdpid", Attributes = [NoThrow] in {
10231026
def rdpid : X86Builtin<"unsigned int()">;
10241027
}
10251028

1026-
let Features = "rdpru", Attributes = [NoThrow] in {
1029+
let Features = "rdpru", Attributes = [NoThrow], EnableOpenCLLong = 0 in {
10271030
def rdpru : X86Builtin<"unsigned long long int(int)">;
10281031
}
10291032

clang/utils/TableGen/ClangBuiltinsEmitter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ enum class BuiltinType {
3131
class PrototypeParser {
3232
public:
3333
PrototypeParser(StringRef Substitution, const Record *Builtin)
34-
: Loc(Builtin->getFieldLoc("Prototype")), Substitution(Substitution) {
34+
: Loc(Builtin->getFieldLoc("Prototype")), Substitution(Substitution),
35+
EnableOpenCLLong(Builtin->getValueAsBit("EnableOpenCLLong")) {
3536
ParsePrototype(Builtin->getValueAsString("Prototype"));
3637
}
3738

@@ -109,7 +110,7 @@ class PrototypeParser {
109110
} else if (T.consume_back("&")) {
110111
ParseType(T);
111112
Type += "&";
112-
} else if (T.consume_front("long long")) {
113+
} else if (EnableOpenCLLong && T.consume_front("long long")) {
113114
Type += "O";
114115
ParseType(T);
115116
} else if (T.consume_front("long")) {
@@ -202,6 +203,7 @@ class PrototypeParser {
202203
private:
203204
SMLoc Loc;
204205
StringRef Substitution;
206+
bool EnableOpenCLLong;
205207
std::string Type;
206208
};
207209

0 commit comments

Comments
 (0)