Skip to content

Commit 411bb3a

Browse files
committed
Some non-functional refactoring and extra check to not call llvm-link when only one input is present
Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent 23fb5c2 commit 411bb3a

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

clang/test/Driver/clang-sycl-linker-test.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
// Tests the clang-sycl-linker tool.
22
//
33
// Test a simple case without arguments.
4-
// RUN: %clangxx -fsycl -emit-llvm -c %s -o %t.bc
5-
// RUN: clang-sycl-linker --dry-run -triple spirv64 %t.bc -o a.spv 2>&1 \
4+
// RUN: %clangxx -emit-llvm -c %s -o %t_1.bc
5+
// RUN: %clangxx -emit-llvm -c %s -o %t_2.bc
6+
// RUN: clang-sycl-linker --dry-run -triple spirv64 %t_1.bc %t_2.bc -o a.spv 2>&1 \
67
// RUN: | FileCheck %s --check-prefix=SIMPLE
7-
// SIMPLE: "{{.*}}llvm-link{{.*}}" {{.*}}.bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
8+
// SIMPLE: "{{.*}}llvm-link{{.*}}" {{.*}}.bc {{.*}}.bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
89
// SIMPLE-NEXT: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv [[FIRSTLLVMLINKOUT]].bc
910
//
11+
// Test that llvm-link is not called when only one input is present.
12+
// RUN: clang-sycl-linker --dry-run -triple spirv64 %t_1.bc -o a.spv 2>&1 \
13+
// RUN: | FileCheck %s --check-prefix=SIMPLE-NO-LINK
14+
// SIMPLE-NO-LINK: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv {{.*}}.bc
15+
//
1016
// Test a simple case with device library files specified.
11-
// RUN: echo ' ' > %T/lib1.bc
12-
// RUN: echo ' ' > %T/lib2.bc
13-
// RUN: clang-sycl-linker --dry-run -triple spirv64 %t.bc --library-path=%T --device-libs=lib1.bc,lib2.bc -o a.spv 2>&1 \
17+
// RUN: touch %T/lib1.bc
18+
// RUN: touch %T/lib2.bc
19+
// RUN: clang-sycl-linker --dry-run -triple spirv64 %t_1.bc %t_2.bc --library-path=%T --device-libs=lib1.bc,lib2.bc -o a.spv 2>&1 \
1420
// RUN: | FileCheck %s --check-prefix=DEVLIBS
15-
// DEVLIBS: "{{.*}}llvm-link{{.*}}" {{.*}}.bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
21+
// DEVLIBS: "{{.*}}llvm-link{{.*}}" {{.*}}.bc {{.*}}.bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
1622
// DEVLIBS-NEXT: "{{.*}}llvm-link{{.*}}" -only-needed [[FIRSTLLVMLINKOUT]].bc {{.*}}lib1.bc {{.*}}lib2.bc -o [[SECONDLLVMLINKOUT:.*]].bc --suppress-warnings
1723
// DEVLIBS-NEXT: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv [[SECONDLLVMLINKOUT]].bc
1824
//
1925
// Test a simple case with .o (fat object) as input.
2026
// TODO: Remove this test once fat object support is added.
21-
// RUN: %clangxx -fsycl -c %s -o %t.o
27+
// RUN: %clangxx -c %s -o %t.o
2228
// RUN: not clang-sycl-linker --dry-run -triple spirv64 %t.o -o a.spv 2>&1 \
2329
// RUN: | FileCheck %s --check-prefix=FILETYPEERROR
2430
// FILETYPEERROR: Unsupported file type
@@ -27,9 +33,9 @@
2733
// RUN: not clang-sycl-linker --dry-run -triple spirv64 %t.bc --library-path=%T --device-libs= -o a.spv 2>&1 \
2834
// RUN: | FileCheck %s --check-prefix=DEVLIBSERR1
2935
// DEVLIBSERR1: Number of device library files cannot be zero
30-
// RUN: not clang-sycl-linker --dry-run -triple spirv64 %t.bc --library-path=%T --device-libs=lib3.bc -o a.spv 2>&1 \
36+
// RUN: not clang-sycl-linker --dry-run -triple spirv64 %t.bc --library-path=%T --device-libs=lib1.bc,lib2.bc,lib3.bc -o a.spv 2>&1 \
3137
// RUN: | FileCheck %s --check-prefix=DEVLIBSERR2
32-
// DEVLIBSERR2: SYCL device library file is not found
38+
// DEVLIBSERR2: '{{.*}}lib3.bc' SYCL device library file is not found
3339
//
3440
// Test if correct set of llvm-spirv options are emitted for windows environment.
3541
// RUN: clang-sycl-linker --dry-run -triple spirv64 --is-windows-msvc-env %t.bc -o a.spv 2>&1 \

clang/test/Driver/sycl-link-spirv-target.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
// Tests the driver when linking LLVM IR bitcode files and targeting SPIR-V
22
// architecture.
33
//
4-
// RUN: touch %t.bc
5-
// RUN: %clangxx --target=spirv64 --sycl-link -### %t.bc 2>&1 \
6-
// RUN: | FileCheck %s -check-prefix=LINK
7-
// LINK: "{{.*}}clang-sycl-linker{{.*}}" "{{.*}}.bc" "-o" "a.out"
8-
//
94
// Test that -Xlinker options are being passed to clang-sycl-linker.
5+
// RUN: touch %t.bc
106
// RUN: %clangxx -### --target=spirv64 --sycl-link -Xlinker --llvm-spirv-path=/tmp \
117
// RUN: -Xlinker --library-path=/tmp -Xlinker --device-libs=lib1.bc,lib2.bc %t.bc 2>&1 \
128
// RUN: | FileCheck %s -check-prefix=XLINKEROPTS

clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static SmallVector<SmallString<128>> TempFiles;
7878

7979
namespace {
8080
// Must not overlap with llvm::opt::DriverFlag.
81-
enum WrapperFlags { WrapperOnlyOption = (1 << 4) };
81+
enum LinkerFlags { LinkerOnlyOption = (1 << 4) };
8282

8383
enum ID {
8484
OPT_INVALID = 0, // This is not an option ID.
@@ -101,14 +101,14 @@ static constexpr OptTable::Info InfoTable[] = {
101101
#undef OPTION
102102
};
103103

104-
class WrapperOptTable : public opt::GenericOptTable {
104+
class LinkerOptTable : public opt::GenericOptTable {
105105
public:
106-
WrapperOptTable() : opt::GenericOptTable(InfoTable) {}
106+
LinkerOptTable() : opt::GenericOptTable(InfoTable) {}
107107
};
108108

109109
const OptTable &getOptTable() {
110-
static const WrapperOptTable *Table = []() {
111-
auto Result = std::make_unique<WrapperOptTable>();
110+
static const LinkerOptTable *Table = []() {
111+
auto Result = std::make_unique<LinkerOptTable>();
112112
return Result.release();
113113
}();
114114
return *Table;
@@ -205,6 +205,12 @@ Expected<SmallVector<std::string>> getInput(const ArgList &Args) {
205205
Expected<StringRef> linkDeviceInputFiles(ArrayRef<std::string> InputFiles,
206206
const ArgList &Args) {
207207
llvm::TimeTraceScope TimeScope("SYCL LinkDeviceInputFiles");
208+
209+
assert(InputFiles.size() && "No inputs to llvm-link");
210+
// Early check to see if there is only one input.
211+
if (InputFiles.size() < 2)
212+
return InputFiles[0];
213+
208214
Expected<std::string> LLVMLinkPath =
209215
findProgram(Args, "llvm-link", {getMainExecutable("llvm-link")});
210216
if (!LLVMLinkPath)
@@ -249,7 +255,7 @@ Expected<SmallVector<std::string>> getSYCLDeviceLibs(const ArgList &Args) {
249255
DeviceLibFiles.push_back(std::string(LibName));
250256
else
251257
return createStringError(inconvertibleErrorCode(),
252-
std::string(LibName) +
258+
"\'" + std::string(LibName) + "\'" +
253259
" SYCL device library file is not found.");
254260
}
255261
}

clang/tools/clang-sycl-linker/SYCLLinkOpts.td

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include "llvm/Option/OptParser.td"
22

3-
def WrapperOnlyOption : OptionFlag;
3+
def LinkerOnlyOption : OptionFlag;
44

55
def help : Flag<["-", "--"], "help">,
66
HelpText<"Display available options (--help-hidden for more)">;
@@ -21,35 +21,32 @@ def library_path_EQ : Joined<["--", "-"], "library-path=">,
2121
Flags<[HelpHidden]>, HelpText<"Add <dir> to the library search path">;
2222

2323
def device_libs_EQ : CommaJoined<["--", "-"], "device-libs=">,
24-
Flags<[WrapperOnlyOption]>,
24+
Flags<[LinkerOnlyOption]>,
2525
HelpText<"A comma separated list of device libraries that are linked during the device link.">;
2626

2727
def triple : Joined<["--"], "triple">,
2828
HelpText<"The device target triple">;
2929
def arch : Separate<["--", "-"], "arch">,
3030
HelpText<"Specify the name of the target architecture.">;
3131

32-
def g : Flag<["-"], "g">, HelpText<"Specify that this was a debug compile.">;
33-
def debug : Flag<["--"], "debug">, Alias<g>;
34-
3532
def save_temps : Flag<["--", "-"], "save-temps">,
36-
Flags<[WrapperOnlyOption]>, HelpText<"Save intermediate results">;
33+
Flags<[LinkerOnlyOption]>, HelpText<"Save intermediate results">;
3734

38-
def dry_run : Flag<["--", "-"], "dry-run">, Flags<[WrapperOnlyOption]>,
35+
def dry_run : Flag<["--", "-"], "dry-run">, Flags<[LinkerOnlyOption]>,
3936
HelpText<"Print generated commands without running.">;
4037

4138
def spirv_dump_device_code_EQ : Joined<["--", "-"], "spirv-dump-device-code=">,
42-
Flags<[WrapperOnlyOption]>,
39+
Flags<[LinkerOnlyOption]>,
4340
HelpText<"Path to the folder where the tool dumps SPIR-V device code. Other formats aren't dumped.">;
4441

4542
def is_windows_msvc_env : Flag<["--", "-"], "is-windows-msvc-env">,
46-
Flags<[WrapperOnlyOption, HelpHidden]>;
43+
Flags<[LinkerOnlyOption, HelpHidden]>;
4744

4845
def llvm_spirv_path_EQ : Joined<["--"], "llvm-spirv-path=">,
49-
Flags<[WrapperOnlyOption]>, MetaVarName<"<dir>">,
46+
Flags<[LinkerOnlyOption]>, MetaVarName<"<dir>">,
5047
HelpText<"Set the system llvm-spirv path">;
5148

5249
// Options to pass to llvm-spirv tool
5350
def llvm_spirv_options_EQ : Joined<["--", "-"], "llvm-spirv-options=">,
54-
Flags<[WrapperOnlyOption]>,
51+
Flags<[LinkerOnlyOption]>,
5552
HelpText<"Options that will control llvm-spirv step">;

0 commit comments

Comments
 (0)