Skip to content

Commit 093f89b

Browse files
authored
[Driver][FPGA] Improve output project folder behaviors for multi-file (#3697)
When performing multi-file compilations with AOT for FPGA, there is an additional output report folder that is created with the separate aoc call. This folder was continually over-written due to each subsequent aoc call creating the same output folder name. Add an additional capability to llvm-foreach: let the user provide an --out-increment='file' argument. This will append the number representing the current call made by llvm-foreach to the given 'file' name.
1 parent 4dbb34a commit 093f89b

File tree

6 files changed

+41
-15
lines changed

6 files changed

+41
-15
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void SYCL::constructLLVMForeachCommand(Compilation &C, const JobAction &JA,
6161
std::unique_ptr<Command> InputCommand,
6262
const InputInfoList &InputFiles,
6363
const InputInfo &Output, const Tool *T,
64+
StringRef Increment,
6465
StringRef Ext = "out") {
6566
// Construct llvm-foreach command.
6667
// The llvm-foreach command looks like this:
@@ -80,6 +81,9 @@ void SYCL::constructLLVMForeachCommand(Compilation &C, const JobAction &JA,
8081
C.getArgs().MakeArgString("--out-file-list=" + OutputFileName));
8182
ForeachArgs.push_back(
8283
C.getArgs().MakeArgString("--out-replace=" + OutputFileName));
84+
if (!Increment.empty())
85+
ForeachArgs.push_back(
86+
C.getArgs().MakeArgString("--out-increment=" + Increment));
8387
ForeachArgs.push_back(C.getArgs().MakeArgString("--"));
8488
ForeachArgs.push_back(
8589
C.getArgs().MakeArgString(InputCommand->getExecutable()));
@@ -345,7 +349,7 @@ void SYCL::fpga::BackendCompiler::constructOpenCLAOTCommand(
345349
Exec, CmdArgs, None);
346350
if (!ForeachInputs.empty())
347351
constructLLVMForeachCommand(C, JA, std::move(Cmd), ForeachInputs, Output,
348-
this, ForeachExt);
352+
this, "", ForeachExt);
349353
else
350354
C.addCommand(std::move(Cmd));
351355
}
@@ -498,7 +502,7 @@ void SYCL::fpga::BackendCompiler::ConstructJob(
498502
Exec, CmdArgs, None);
499503
if (!ForeachInputs.empty())
500504
constructLLVMForeachCommand(C, JA, std::move(Cmd), ForeachInputs, Output,
501-
this, ForeachExt);
505+
this, ReportOptArg, ForeachExt);
502506
else
503507
C.addCommand(std::move(Cmd));
504508
}
@@ -537,7 +541,7 @@ void SYCL::gen::BackendCompiler::ConstructJob(Compilation &C,
537541
Exec, CmdArgs, None);
538542
if (!ForeachInputs.empty())
539543
constructLLVMForeachCommand(C, JA, std::move(Cmd), ForeachInputs, Output,
540-
this);
544+
this, "");
541545
else
542546
C.addCommand(std::move(Cmd));
543547
}
@@ -570,7 +574,7 @@ void SYCL::x86_64::BackendCompiler::ConstructJob(
570574
Exec, CmdArgs, None);
571575
if (!ForeachInputs.empty())
572576
constructLLVMForeachCommand(C, JA, std::move(Cmd), ForeachInputs, Output,
573-
this);
577+
this, "");
574578
else
575579
C.addCommand(std::move(Cmd));
576580
}

clang/lib/Driver/ToolChains/SYCL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void constructLLVMForeachCommand(Compilation &C, const JobAction &JA,
2424
std::unique_ptr<Command> InputCommand,
2525
const InputInfoList &InputFiles,
2626
const InputInfo &Output, const Tool *T,
27-
StringRef Ext);
27+
StringRef Increment, StringRef Ext);
2828

2929
// Runs llvm-spirv to convert spirv to bc, llvm-link, which links multiple LLVM
3030
// bitcode. Converts generated bc back to spirv using llvm-spirv, wraps with

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@
9292
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=ao" "-targets=sycl-fpga_aocx-intel-unknown-sycldevice" "-inputs={{.*}}" "-check-section"
9393
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=ao" "-targets=sycl-fpga_aocr-intel-unknown-sycldevice" "-inputs={{.*}}" "-check-section"
9494
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aocr" "-targets=sycl-fpga_aocr-intel-unknown-sycldevice" "-inputs=[[INPUT:.+\.a]]" "-outputs=[[OUTPUT2:.+\.aocr]]" "-unbundle"
95-
// CHK-FPGA-LINK-LIB-IMAGE: llvm-foreach{{.*}} "--out-ext=aocx" "--in-file-list=[[OUTPUT2]]" "--in-replace=[[OUTPUT2]]" "--out-file-list=[[OUTPUT3:.+\.aocx]]" "--out-replace=[[OUTPUT3]]" "--" "{{.*}}aoc{{.*}}" "-o" "[[OUTPUT3]]" "[[OUTPUT2]]" "-sycl" "-output-report-folder={{.*}}-aocr.prj" "-g"
95+
// CHK-FPGA-LINK-LIB-IMAGE: llvm-foreach{{.*}} "--out-ext=aocx" "--in-file-list=[[OUTPUT2]]" "--in-replace=[[OUTPUT2]]" "--out-file-list=[[OUTPUT3:.+\.aocx]]" "--out-replace=[[OUTPUT3]]" "--out-increment={{.*}}-aocr.prj" "--" "{{.*}}aoc{{.*}}" "-o" "[[OUTPUT3]]" "[[OUTPUT2]]" "-sycl" "-output-report-folder={{.*}}-aocr.prj" "-g"
9696
// CHK-FPGA-LINK-LIB-IMAGE: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[OUTPUT4:.+\.txt]]" "[[OUTPUT3]]"
9797
// CHK-FPGA-LINK-LIB-IMAGE: clang-offload-wrapper{{.*}} "-host=x86_64-unknown-linux-gnu" "--emit-reg-funcs=0" "-target=fpga_aocx-intel-unknown-sycldevice" "-kind=sycl" "-batch" "[[OUTPUT4]]"
98-
// CHK-FPGA-LINK-LIB-EARLY: llvm-foreach{{.*}} "--out-ext=aocr" "--in-file-list=[[OUTPUT2]]" "--in-replace=[[OUTPUT2]]" "--out-file-list=[[OUTPUT3:.+\.aocr]]" "--out-replace=[[OUTPUT3]]" "--" "{{.*}}aoc{{.*}}" "-o" "[[OUTPUT3]]" "[[OUTPUT2]]" "-sycl" "-rtl" "-output-report-folder={{.*}}-aocr.prj" "-g"
98+
// CHK-FPGA-LINK-LIB-EARLY: llvm-foreach{{.*}} "--out-ext=aocr" "--in-file-list=[[OUTPUT2]]" "--in-replace=[[OUTPUT2]]" "--out-file-list=[[OUTPUT3:.+\.aocr]]" "--out-replace=[[OUTPUT3]]" "--out-increment={{.*}}-aocr.prj" "--" "{{.*}}aoc{{.*}}" "-o" "[[OUTPUT3]]" "[[OUTPUT2]]" "-sycl" "-rtl" "-output-report-folder={{.*}}-aocr.prj" "-g"
9999
// CHK-FPGA-LINK-LIB-EARLY: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[OUTPUT4:.+\.txt]]" "[[OUTPUT3]]"
100100
// CHK-FPGA-LINK-LIB-EARLY: clang-offload-wrapper{{.*}} "-host=x86_64-unknown-linux-gnu" "-target=fpga_aocr-intel-unknown-sycldevice" "-kind=sycl" "-batch" "[[OUTPUT4]]"
101101
// CHK-FPGA-LINK-LIB: llc{{.*}} "-filetype=obj" "-o" "[[OUTPUT5:.+\.o]]"
@@ -125,7 +125,7 @@
125125
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fno-sycl-device-lib=all -fsycl -fintelfpga -Xshardware %t-aocr.a %t2.o 2>&1 \
126126
// RUN: | FileCheck -check-prefixes=CHK-FPGA %s
127127
// CHK-FPGA: clang-offload-bundler{{.*}} "-type=aocr" "-targets=sycl-fpga_aocr-intel-unknown-sycldevice" "-inputs=[[INPUT:.+\.a]]" "-outputs=[[OUTPUT2:.+\.aocr]]" "-unbundle"
128-
// CHK-FPGA: llvm-foreach{{.*}} "--out-ext=aocx" "--in-file-list=[[OUTPUT2]]" "--in-replace=[[OUTPUT2]]" "--out-file-list=[[OUTPUT3:.+\.aocx]]" "--out-replace=[[OUTPUT3]]" "--" "{{.*}}aoc{{.*}}" "-o" "[[OUTPUT3]]" "[[OUTPUT2]]" "-sycl" {{.*}} "-g"
128+
// CHK-FPGA: llvm-foreach{{.*}} "--out-ext=aocx" "--in-file-list=[[OUTPUT2]]" "--in-replace=[[OUTPUT2]]" "--out-file-list=[[OUTPUT3:.+\.aocx]]" "--out-replace=[[OUTPUT3]]" "--out-increment={{.*}}" "--" "{{.*}}aoc{{.*}}" "-o" "[[OUTPUT3]]" "[[OUTPUT2]]" "-sycl" {{.*}} "-g"
129129
// CHK-FPGA: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[OUTPUT4:.+\.txt]]" "[[OUTPUT3]]"
130130
// CHK-FPGA: clang-offload-wrapper{{.*}} "-o=[[OUTPUT_AOCX_BC:.+\.bc]]" "-host=x86_64-unknown-linux-gnu" "-target=spir64_fpga" "-kind=sycl" "-batch" "[[OUTPUT4]]"
131131
// CHK-FPGA: llc{{.*}} "-filetype=obj" "-o" "[[FINALLINK:.+\.o]]" "[[OUTPUT_AOCX_BC]]"

llvm/test/tools/llvm-foreach/llvm-foreach-lin.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
; RUN: echo 'something again' > %t4.tgt
2121
; RUN: echo "%t3.tgt" > %t1.list
2222
; RUN: echo "%t4.tgt" >> %t1.list
23-
; RUN: llvm-foreach --in-replace="{}" --in-replace="in" --in-file-list=%t.list --in-file-list=%t1.list -- echo -first-part-of-arg={}.out -first-part-of-arg=in.out > %t1.res
23+
; RUN: llvm-foreach --in-replace="{}" --in-replace="inrep" --in-file-list=%t.list --in-file-list=%t1.list --out-increment="%t_out.prj" -- echo -first-part-of-arg={}.out -first-part-of-arg=inrep.out -another-arg=%t_out.prj > %t1.res
2424
; RUN: FileCheck < %t1.res %s --check-prefix=CHECK-DOUBLE-LISTS
25-
; CHECK-DOUBLE-LISTS: -first-part-of-arg=[[FIRST:.+1.tgt.out]] -first-part-of-arg=[[THIRD:.+3.tgt.out]]
26-
; CHECK-DOUBLE-LISTS: -first-part-of-arg=[[SECOND:.+2.tgt.out]] -first-part-of-arg=[[FOURTH:.+4.tgt.out]]
25+
; CHECK-DOUBLE-LISTS: -first-part-of-arg=[[FIRST:.+1.tgt.out]] -first-part-of-arg=[[THIRD:.+3.tgt.out]] -another-arg={{.+}}_out.prj
26+
; CHECK-DOUBLE-LISTS: -first-part-of-arg=[[SECOND:.+2.tgt.out]] -first-part-of-arg=[[FOURTH:.+4.tgt.out]] -another-arg={{.+}}_out.prj_1

llvm/test/tools/llvm-foreach/llvm-foreach-win.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
; RUN: echo 'something again' > %t4.tgt
2121
; RUN: echo "%t3.tgt" > %t1.list
2222
; RUN: echo "%t4.tgt" >> %t1.list
23-
; RUN: llvm-foreach --in-replace="{}" --in-replace="in" --in-file-list=%t.list --in-file-list=%t1.list -- echo -first-part-of-arg={}.out -first-part-of-arg=in.out > %t1.res
23+
; RUN: llvm-foreach --in-replace="{}" --in-replace="inrep" --in-file-list=%t.list --in-file-list=%t1.list --out-increment=%t_out.prj -- echo -first-part-of-arg={}.out -first-part-of-arg=inrep.out -another-arg=%t_out.prj > %t1.res
2424
; RUN: FileCheck < %t1.res %s --check-prefix=CHECK-DOUBLE-LISTS
25-
; CHECK-DOUBLE-LISTS: -first-part-of-arg=[[FIRST:.+1.tgt.out]] -first-part-of-arg=[[THIRD:.+3.tgt.out]]
26-
; CHECK-DOUBLE-LISTS: -first-part-of-arg=[[SECOND:.+2.tgt.out]] -first-part-of-arg=[[FOURTH:.+4.tgt.out]]
25+
; CHECK-DOUBLE-LISTS: -first-part-of-arg=[[FIRST:.+1.tgt.out]] -first-part-of-arg=[[THIRD:.+3.tgt.out]] -another-arg={{.+}}_out.prj
26+
; CHECK-DOUBLE-LISTS: -first-part-of-arg=[[SECOND:.+2.tgt.out]] -first-part-of-arg=[[FOURTH:.+4.tgt.out]] -another-arg={{.+}}_out.prj_1

llvm/tools/llvm-foreach/llvm-foreach.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static cl::opt<std::string> OutDirectory{
5353

5454
static cl::opt<std::string> OutFilesExt{
5555
"out-ext",
56-
cl::desc("Specify extenstion for output files; If unspecified, assume "
56+
cl::desc("Specify extension for output files; If unspecified, assume "
5757
".out"),
5858
cl::init("out"), cl::value_desc("R")};
5959

@@ -62,6 +62,13 @@ static cl::opt<std::string> OutputFileList{
6262
"out-file-list", cl::desc("Specify filename for list of outputs."),
6363
cl::value_desc("filename"), cl::init("")};
6464

65+
static cl::opt<std::string> OutIncrement{
66+
"out-increment",
67+
cl::desc(
68+
"Specify output file which should be incrementally named with each "
69+
"pass."),
70+
cl::init(""), cl::value_desc("R")};
71+
6572
static void error(const Twine &Msg) {
6673
errs() << "llvm-foreach: " << Msg << '\n';
6774
exit(1);
@@ -112,6 +119,7 @@ int main(int argc, char **argv) {
112119
// Find args to replace with filenames from input list.
113120
std::vector<ArgumentReplace> InReplaceArgs;
114121
ArgumentReplace OutReplaceArg;
122+
ArgumentReplace OutIncrementArg;
115123
for (size_t i = 1; i < Args.size(); ++i) {
116124
for (auto &Replace : Replaces) {
117125
size_t ReplaceStart = Args[i].find(Replace);
@@ -124,6 +132,12 @@ int main(int argc, char **argv) {
124132
if (ReplaceStart != StringRef::npos)
125133
OutReplaceArg = {i, ReplaceStart, OutReplace.size()};
126134
}
135+
136+
if (!OutIncrement.empty() && Args[i].contains(OutIncrement)) {
137+
size_t IncrementStart = Args[i].find(OutIncrement);
138+
if (IncrementStart != StringRef::npos)
139+
OutIncrementArg = {i, IncrementStart, OutIncrement.size()};
140+
}
127141
}
128142

129143
// Emit an error if user requested replace output file in the command but
@@ -197,6 +211,14 @@ int main(int argc, char **argv) {
197211
OS << Path << "\n";
198212
}
199213

214+
if (!OutIncrement.empty()) {
215+
// Name the file by adding the current file list index to the name.
216+
ResOutArg = InputCommandArgs[OutIncrementArg.ArgNum];
217+
if (j > 0)
218+
ResOutArg += ("_" + Twine(j)).str();
219+
Args[OutIncrementArg.ArgNum] = ResOutArg;
220+
}
221+
200222
std::string ErrMsg;
201223
// TODO: Add possibility to execute commands in parallel.
202224
int Result =

0 commit comments

Comments
 (0)