Skip to content

Commit fd6d948

Browse files
authored
[Driver][SYCL] Update dependency file generation with the integration footer (#4399)
When generating dependency information and compiling the source + footer file, the generated dependency information did not match the actual source file that needs to be checked. Update the compilation behavior when we are generating dependency information with the source + footer so we do an additional specific dependency creation step (preprocess only) against the original source file which is used instead of the source + footer compilation.
1 parent 8eb0d87 commit fd6d948

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5492,6 +5492,16 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
54925492
break;
54935493
}
54945494

5495+
// When performing -fsycl based compilations and generating dependency
5496+
// information, perform a specific dependency generation compilation which
5497+
// is not based on the source + footer compilation.
5498+
if (Phase == phases::Preprocess && Args.hasArg(options::OPT_fsycl) &&
5499+
Args.hasArg(options::OPT_M_Group) &&
5500+
!Args.hasArg(options::OPT_fno_sycl_use_footer)) {
5501+
Actions.push_back(
5502+
C.MakeAction<PreprocessJobAction>(Current, types::TY_Dependencies));
5503+
}
5504+
54955505
// FIXME: Should we include any prior module file outputs as inputs of
54965506
// later actions in the same command line?
54975507

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,12 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
12031203
C.getDriver().addFPGATempDepFile(DepFile, BaseName);
12041204
};
12051205

1206+
// Do not add dependency generation information when compiling the source +
1207+
// footer combination. The dependency generation is done in a separate
1208+
// compile step so we can retain original source information.
1209+
if (ContainsAppendFooterAction(&JA))
1210+
ArgM = nullptr;
1211+
12061212
if (ArgM) {
12071213
// Determine the output location.
12081214
const char *DepFile;
@@ -1216,6 +1222,12 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
12161222
DepFile, Clang::getBaseInputName(Args, Inputs[0]));
12171223
} else if (Output.getType() == types::TY_Dependencies) {
12181224
DepFile = Output.getFilename();
1225+
if (!ContainsAppendFooterAction(&JA) && Args.hasArg(options::OPT_fsycl) &&
1226+
!Args.hasArg(options::OPT_fno_sycl_use_footer) &&
1227+
!JA.isDeviceOffloading(Action::OFK_SYCL))
1228+
// Name the dependency file for the specific dependency generation
1229+
// step created for the integration footer enabled compilation.
1230+
DepFile = getDependencyFileName(Args, Inputs);
12191231
} else if (!ArgMD) {
12201232
DepFile = "-";
12211233
} else if (IsIntelFPGA && JA.isDeviceOffloading(Action::OFK_SYCL)) {

clang/test/Driver/sycl-int-footer.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,30 @@
6767
// FOOTER_PATH: append-file{{.*}} "--append=dummy_dir{{(/|\\\\)}}{{.*}}-footer-{{.*}}.h"
6868
// FOOTER_PATH-SAME: "--output=dummy_dir{{(/|\\\\)}}[[APPENDEDSRC:.+\.cpp]]"
6969
// FOOTER_PATH: clang{{.*}} "-x" "c++" "dummy_dir{{(/|\\\\)}}[[APPENDEDSRC]]"
70+
71+
/// Check behaviors for dependency generation
72+
// RUN: %clangxx -fsycl -MD -c %s -### 2>&1 \
73+
// RUN: | FileCheck -check-prefix DEP_GEN %s
74+
// DEP_GEN: clang{{.*}} "-Eonly"
75+
// DEP_GEN-SAME: "-dependency-file"
76+
// DEP_GEN-SAME: "-MT"
77+
// DEP_GEN-SAME: "-x" "c++" "[[INPUTFILE:.+\.cpp]]"
78+
// DEP_GEN: append-file{{.*}} "[[INPUTFILE]]"
79+
// DEP_GEN-NOT: clang{{.*}} "-dependency-file"
80+
81+
/// Dependency generation phases
82+
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -MD -c %s -ccc-print-phases 2>&1 \
83+
// RUN: | FileCheck -check-prefix DEP_GEN_PHASES %s
84+
// DEP_GEN_PHASES: 0: input, "[[INPUTFILE:.+\.cpp]]", c++, (host-sycl)
85+
// DEP_GEN_PHASES: 1: preprocessor, {0}, dependencies
86+
// DEP_GEN_PHASES: 2: input, "[[INPUTFILE]]", c++, (device-sycl)
87+
// DEP_GEN_PHASES: 3: preprocessor, {2}, c++-cpp-output, (device-sycl)
88+
// DEP_GEN_PHASES: 4: compiler, {3}, ir, (device-sycl)
89+
// DEP_GEN_PHASES: 5: offload, "device-sycl (spir64-unknown-unknown-sycldevice)" {4}, ir
90+
// DEP_GEN_PHASES: 6: append-footer, {0}, c++, (host-sycl)
91+
// DEP_GEN_PHASES: 7: preprocessor, {6}, c++-cpp-output, (host-sycl)
92+
// DEP_GEN_PHASES: 8: offload, "host-sycl (x86_64-unknown-linux-gnu)" {7}, "device-sycl (spir64-unknown-unknown-sycldevice)" {4}, c++-cpp-output
93+
// DEP_GEN_PHASES: 9: compiler, {8}, ir, (host-sycl)
94+
// DEP_GEN_PHASES: 10: backend, {9}, assembler, (host-sycl)
95+
// DEP_GEN_PHASES: 11: assembler, {10}, object, (host-sycl)
96+
// DEP_GEN_PHASES: 12: clang-offload-bundler, {5, 11}, object, (host-sycl)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@
322322
/// -fintelfpga dependency file check with host .d enabled
323323
// RUN: %clangxx -### -MMD -fsycl -fintelfpga -Xshardware %t-1.cpp %t-2.cpp 2>&1 \
324324
// RUN: | FileCheck -check-prefix=CHK-FPGA-DEP-FILES-HOST %s
325-
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-dependency-file" "[[INPUT1:.+\.d]]" "-MT" "{{.*}}.o"
326-
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-dependency-file" "[[INPUT2:.+\.d]]" "-MT" "{{.*}}.o"
325+
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-triple" "spir64_fpga-unknown-unknown-sycldevice"{{.*}} "-dependency-file" "[[INPUT1:.+\.d]]" "-MT" "{{.*}}.o"
326+
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-triple" "spir64_fpga-unknown-unknown-sycldevice"{{.*}} "-dependency-file" "[[INPUT2:.+\.d]]" "-MT" "{{.*}}.o"
327327
// CHK-FPGA-DEP-FILES-HOST: aoc{{.*}} "-dep-files={{.*}}[[INPUT1]],{{.*}}[[INPUT2]]"
328-
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-fsycl-is-host"{{.*}} "-dependency-file"
329-
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-fsycl-is-host"{{.*}} "-dependency-file"
328+
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-fsycl-is-host"{{.*}}
329+
// CHK-FPGA-DEP-FILES-HOST: clang{{.*}} "-fsycl-is-host"{{.*}}
330330

331331
/// -fintelfpga dependency file generation test to object
332332
// RUN: %clangxx -### -fsycl -fintelfpga -target x86_64-unknown-linux-gnu %t-1.cpp %t-2.cpp -c 2>&1 \
@@ -348,7 +348,7 @@
348348
// RUN: | FileCheck -check-prefixes=CHK-FPGA-DEP-FILES3,CHK-FPGA-DEP-FILES3-LIN %s
349349
// RUN: %clang_cl -### --target=x86_64-pc-windows-msvc -fsycl -fintelfpga %t-1.cpp -c -Fodummy.obj 2>&1 \
350350
// RUN: | FileCheck -check-prefixes=CHK-FPGA-DEP-FILES3,CHK-FPGA-DEP-FILES3-WIN %s
351-
// CHK-FPGA-DEP-FILES3: clang{{.*}} "-dependency-file" "[[OUTPUT:.+\.d]]"
351+
// CHK-FPGA-DEP-FILES3: clang{{.*}} "-triple" "spir64_fpga-unknown-unknown-sycldevice"{{.*}} "-dependency-file" "[[OUTPUT:.+\.d]]"
352352
// CHK-FPGA-DEP-FILES3-LIN: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64_fpga-unknown-unknown-sycldevice,host-x86_64-unknown-linux-gnu,sycl-fpga_dep" {{.*}} "-inputs={{.*}}.bc,{{.*}}.o,[[OUTPUT]]"
353353
// CHK-FPGA-DEP-FILES3-WIN: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64_fpga-unknown-unknown-sycldevice,host-x86_64-pc-windows-msvc,sycl-fpga_dep" {{.*}} "-inputs={{.*}}.bc,{{.*}}.obj,[[OUTPUT]]"
354354

0 commit comments

Comments
 (0)