Skip to content

Commit 24726df

Browse files
authored
[Driver][SYCL][FPGA] Do not generate host dependency files by default (#1918)
When compiling for -fsycl -fintelfpga, dependency file information needs to be generated and added to the AOT compilation step. The dep file is only needed from the device compilation. Remove the generation of the dependency files for the host compilation unless the user explicitly calls for it (with a generation option) Signed-off-by: Michael D Toguchi <[email protected]>
1 parent d8ec8b5 commit 24726df

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,8 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
407407
if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu, false))
408408
DAL->AddFlagArg(0, Opts.getOption(options::OPT_static));
409409

410-
// Use of -fintelfpga implies -g and -MMD
410+
// Use of -fintelfpga implies -g
411411
if (Args.hasArg(options::OPT_fintelfpga)) {
412-
DAL->AddFlagArg(0, Opts.getOption(options::OPT_MMD));
413412
// if any -gN option is provided, use that.
414413
if (Arg *A = Args.getLastArg(options::OPT_gN_Group))
415414
DAL->append(A);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,16 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11381138
else
11391139
ArgM = ArgMD;
11401140

1141+
auto createFPGATempDepFile = [&](const char *&DepFile) {
1142+
// Generate dependency files as temporary. These will be used for the
1143+
// aoc call/bundled during fat object creation
1144+
std::string BaseName(Clang::getBaseInputName(Args, Inputs[0]));
1145+
std::string DepTmpName =
1146+
C.getDriver().GetTemporaryPath(llvm::sys::path::stem(BaseName), "d");
1147+
DepFile = C.addTempFile(C.getArgs().MakeArgString(DepTmpName));
1148+
C.getDriver().addFPGATempDepFile(DepFile, BaseName);
1149+
};
1150+
11411151
if (ArgM) {
11421152
// Determine the output location.
11431153
const char *DepFile;
@@ -1148,16 +1158,9 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11481158
DepFile = Output.getFilename();
11491159
} else if (!ArgMD) {
11501160
DepFile = "-";
1151-
} else if (ArgMD->getOption().matches(options::OPT_MMD) &&
1152-
Args.hasArg(options::OPT_fintelfpga) &&
1161+
} else if (Args.hasArg(options::OPT_fintelfpga) &&
11531162
JA.isDeviceOffloading(Action::OFK_SYCL)) {
1154-
// Generate dependency files as temporary. These will be used for the
1155-
// aoc call/bundled during fat object creation
1156-
std::string BaseName(Clang::getBaseInputName(Args, Inputs[0]));
1157-
std::string DepTmpName =
1158-
C.getDriver().GetTemporaryPath(llvm::sys::path::stem(BaseName), "d");
1159-
DepFile = C.addTempFile(C.getArgs().MakeArgString(DepTmpName));
1160-
C.getDriver().addFPGATempDepFile(DepFile, BaseName);
1163+
createFPGATempDepFile(DepFile);
11611164
} else {
11621165
DepFile = getDependencyFileName(Args, Inputs);
11631166
C.addFailureResultFile(DepFile, &JA);
@@ -1212,6 +1215,22 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
12121215
CmdArgs.push_back("-module-file-deps");
12131216
}
12141217

1218+
if (!ArgM && Args.hasArg(options::OPT_fintelfpga) &&
1219+
JA.isDeviceOffloading(Action::OFK_SYCL)) {
1220+
// No dep generation option was provided, add all of the needed options
1221+
// to ensure a successful dep generation.
1222+
const char *DepFile;
1223+
createFPGATempDepFile(DepFile);
1224+
CmdArgs.push_back("-dependency-file");
1225+
CmdArgs.push_back(DepFile);
1226+
CmdArgs.push_back("-MT");
1227+
SmallString<128> P(Inputs[0].getBaseInput());
1228+
llvm::sys::path::replace_extension(P, "o");
1229+
SmallString<128> Quoted;
1230+
QuoteTarget(llvm::sys::path::filename(P), Quoted);
1231+
CmdArgs.push_back(Args.MakeArgString(Quoted));
1232+
}
1233+
12151234
if (Args.hasArg(options::OPT_MG)) {
12161235
if (!ArgM || ArgM->getOption().matches(options::OPT_MD) ||
12171236
ArgM->getOption().matches(options::OPT_MMD))

clang/test/Driver/sycl-offload-intelfpga.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,19 @@
226226
// RUN: | FileCheck -check-prefix=CHK-FPGA-DEP-FILES %s
227227
// RUN: %clang_cl -### -fsycl -fintelfpga %t-1.cpp %t-2.cpp 2>&1 \
228228
// RUN: | FileCheck -check-prefix=CHK-FPGA-DEP-FILES %s
229-
// CHK-FPGA-DEP-FILES: clang{{.*}} "-dependency-file" "[[INPUT1:.+\.d]]"
230-
// CHK-FPGA-DEP-FILES: clang{{.*}} "-dependency-file" "[[INPUT2:.+\.d]]"
229+
// CHK-FPGA-DEP-FILES: clang{{.*}} "-dependency-file" "[[INPUT1:.+\.d]]" "-MT" "{{.*}}.o"
230+
// CHK-FPGA-DEP-FILES: clang{{.*}} "-dependency-file" "[[INPUT2:.+\.d]]" "-MT" "{{.*}}.o"
231231
// CHK-FPGA-DEP-FILES: aoc{{.*}} "-dep-files={{.*}}[[INPUT1]],{{.*}}[[INPUT2]]"
232+
// CHK-FPGA-DEP-FILES-NOT: clang{{.*}} "-dependency-file" {{.*}} "-fsycl-is-host"
233+
234+
/// -fintelfpga dependency file check with host .d enabled
235+
// RUN: %clangxx -### -MMD -fsycl -fintelfpga %t-1.cpp %t-2.cpp 2>&1 \
236+
// RUN: | FileCheck -check-prefix=CHK-FPGA-DEP-FILES-HOST %s
237+
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-dependency-file" "[[INPUT1:.+\.d]]" "-MT" "{{.*}}.o"
238+
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-dependency-file" "[[INPUT2:.+\.d]]" "-MT" "{{.*}}.o"
239+
// CHK-FPGA-DEP-FILES-HOST: aoc{{.*}} "-dep-files={{.*}}[[INPUT1]],{{.*}}[[INPUT2]]"
240+
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-dependency-file" {{.*}} "-fsycl-is-host"
241+
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-dependency-file" {{.*}} "-fsycl-is-host"
232242

233243
/// -fintelfpga dependency file generation test to object
234244
// RUN: %clangxx -### -fsycl -fintelfpga %t-1.cpp %t-2.cpp -c 2>&1 \

0 commit comments

Comments
 (0)