Skip to content

Commit a774adb

Browse files
authored
Bulk port 64-bit x86 builtins to TableGen (#121043)
This PR follows #120831 for x86-64. Similar to that PR, this does a very mechanical port of X86 builtins to TableGen. There is a *lot* of improvement available here to use TableGen more effectively and collapse repeated structures. But those can now be follow-up PRs that restructure *within* the `.td` file. The current structure produces a file that exactly matches the original X-macros except for the differences outlined in #120831: - Horizontal whitespace - `long long` types now use `long long` outside of OpenCL, but switch to `long` in OpenCL where relevant. Otherwise, only the order of builtins change, and no tests regress.
1 parent c1ea05e commit a774adb

File tree

7 files changed

+521
-272
lines changed

7 files changed

+521
-272
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
include "clang/Basic/BuiltinsBase.td"
14-
15-
class X86Builtin<string prototype> : TargetBuiltin {
16-
let Spellings = ["__builtin_ia32_" # NAME];
17-
let Prototype = prototype;
18-
let EnableOpenCLLong = 1;
19-
}
20-
21-
class X86NoPrefixBuiltin<string prototype> : TargetBuiltin {
22-
let Spellings = [NAME];
23-
let Prototype = prototype;
24-
}
25-
26-
class X86LibBuiltin<string prototype> : TargetLibBuiltin {
27-
let Spellings = [NAME];
28-
let Prototype = prototype;
29-
}
13+
include "clang/Basic/BuiltinsX86Base.td"
3014

3115
def rdpmc : X86Builtin<"unsigned long long int(int)">;
3216
def rdtsc : X86Builtin<"unsigned long long int()">;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===--- BuiltinsX86Base.td - X86 Builtin function classes ------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the X86-specific builtin function classes.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
include "clang/Basic/BuiltinsBase.td"
14+
15+
class X86Builtin<string prototype> : TargetBuiltin {
16+
let Spellings = ["__builtin_ia32_" # NAME];
17+
let Prototype = prototype;
18+
let EnableOpenCLLong = 1;
19+
}
20+
21+
class X86NoPrefixBuiltin<string prototype> : TargetBuiltin {
22+
let Spellings = [NAME];
23+
let Prototype = prototype;
24+
}
25+
26+
class X86LibBuiltin<string prototype> : TargetLibBuiltin {
27+
let Spellings = [NAME];
28+
let Prototype = prototype;
29+
}

clang/include/clang/Basic/BuiltinsX86_64.def

Lines changed: 0 additions & 253 deletions
This file was deleted.

clang/include/clang/Basic/BuiltinsX86_64.td

Lines changed: 485 additions & 0 deletions
Large diffs are not rendered by default.

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ clang_tablegen(BuiltinsX86.inc -gen-clang-builtins
6464
SOURCE BuiltinsX86.td
6565
TARGET ClangBuiltinsX86)
6666

67+
clang_tablegen(BuiltinsX86_64.inc -gen-clang-builtins
68+
SOURCE BuiltinsX86_64.td
69+
TARGET ClangBuiltinsX86_64)
70+
6771
# ARM NEON and MVE
6872
clang_tablegen(arm_neon.inc -gen-arm-neon-sema
6973
SOURCE arm_neon.td

clang/include/clang/Basic/TargetBuiltins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ namespace clang {
128128
FirstX86_64Builtin,
129129
LastX86CommonBuiltin = FirstX86_64Builtin - 1,
130130
#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
131-
#include "clang/Basic/BuiltinsX86_64.def"
131+
#include "clang/Basic/BuiltinsX86_64.inc"
132132
LastTSBuiltin
133133
};
134134
}

clang/lib/Basic/Targets/X86.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static constexpr Builtin::Info BuiltinInfoX86[] = {
3838
{#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
3939
#define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \
4040
{#ID, TYPE, ATTRS, FEATURE, HeaderDesc::HEADER, LANGS},
41-
#include "clang/Basic/BuiltinsX86_64.def"
41+
#include "clang/Basic/BuiltinsX86_64.inc"
4242
};
4343

4444
static const char *const GCCRegNames[] = {

0 commit comments

Comments
 (0)