Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clang/lib/DPCT/AnalysisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,11 +842,11 @@ StringRef DpctFileInfo::getHeaderSpelling(HeaderType Value) {
}
void DpctFileInfo::insertHeader(HeaderType Type, unsigned Offset,
ReplacementType IsForCodePin) {
if (Type == HT_DPL_Algorithm || Type == HT_DPL_Execution ||
Type == HT_DPCT_DNNL_Utils) {
if (this != DpctGlobalInfo::getInstance().getMainFile().get())
DpctGlobalInfo::getInstance().getMainFile()->insertHeader(
Type, FirstIncludeOffset);
if (Type == HT_DPL_Algorithm || Type == HT_DPL_Execution || Type == HT_SYCL) {
if (auto MF = DpctGlobalInfo::getInstance().getMainFile())
if (this != MF.get())
DpctGlobalInfo::getInstance().getMainFile()->insertHeader(
Type, FirstIncludeOffset);
}
if (HeaderInsertedBitMap[Type])
return;
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/DPCT/MigrationAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ void DpctToolAction::runPasses() {
for (auto Pass : Passes) {
runPass(Pass);
}
// Before post-processing, we need to set the MainFile to empty since it is no
// longer valid. Currently, DpctFileInfo::insertHeader() is executed both
// before and during the post-processing. In that function, the MainFile value
// is accessed for inserting two kinds of header files: oneDPL header and SYCL
// header. We assume those two headers have already been inserted before the
// post-processing. So, clearing the value of MainFile can avoid the MainFile
// value used in the post-processing.
DpctGlobalInfo::getInstance().setMainFile(nullptr);
Comment thread
zhiweij1 marked this conversation as resolved.
runWithCrashGuard(
[&]() {
Global.buildReplacements();
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/d_dh_constant_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// RUN: echo " \"file\": \"%/T/d_dh_constant_db/d_dh_constant_db.cpp\"" >> compile_commands.json
// RUN: echo " }" >> compile_commands.json
// RUN: echo "]" >> compile_commands.json
// RUN: rm %T/d_dh_constant_db/out/MainSourceFiles.yaml
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: FileCheck %s --match-full-lines --input-file %T/d_dh_constant_db/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/d_dh_constant_db_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// RUN: echo " \"file\": \"%/T/d_dh_constant_db_win/d_dh_constant_db_win.cpp\"" >> compile_commands.json
// RUN: echo " }" >> compile_commands.json
// RUN: echo "]" >> compile_commands.json
// RUN: rm %T/d_dh_constant_db_win/out/MainSourceFiles.yaml
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: FileCheck %s --match-full-lines --input-file %T/d_dh_constant_db_win/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/d_hd_constant_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// RUN: echo " \"file\": \"%/T/d_hd_constant_db/d_hd_constant_db.cpp\"" >> compile_commands.json
// RUN: echo " }" >> compile_commands.json
// RUN: echo "]" >> compile_commands.json
// RUN: rm %T/d_hd_constant_db/out/MainSourceFiles.yaml
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: FileCheck %s --match-full-lines --input-file %T/d_hd_constant_db/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/d_hd_constant_db_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// RUN: echo " \"file\": \"%/T/d_hd_constant_db_win/d_hd_constant_db_win.cpp\"" >> compile_commands.json
// RUN: echo " }" >> compile_commands.json
// RUN: echo "]" >> compile_commands.json
// RUN: rm %T/d_hd_constant_db_win/out/MainSourceFiles.yaml
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: FileCheck %s --match-full-lines --input-file %T/d_hd_constant_db_win/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/dh_d_constant_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: echo "]" >> compile_commands.json
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: rm compile_commands.json
// RUN: rm %T/dh_d_constant_db/out/MainSourceFiles.yaml
// RUN: dpct dh_d_constant_db.cpp --out-root=./out --cuda-include-path="%cuda-path/include" -- -x cuda --cuda-host-only
// RUN: FileCheck %s --match-full-lines --input-file %T/dh_d_constant_db/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/dh_d_constant_db_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: echo "]" >> compile_commands.json
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: rm compile_commands.json
// RUN: rm %T/dh_d_constant_db_win/out/MainSourceFiles.yaml
// RUN: dpct dh_d_constant_db_win.cpp --out-root=./out --cuda-include-path="%cuda-path/include" -- -x cuda --cuda-host-only
// RUN: FileCheck %s --match-full-lines --input-file %T/dh_d_constant_db_win/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/dh_h_constant_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: echo "]" >> compile_commands.json
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: rm compile_commands.json
// RUN: rm %T/dh_h_constant_db/out/MainSourceFiles.yaml
// RUN: dpct dh_h_constant_db.cpp --out-root=./out --cuda-include-path="%cuda-path/include" -- -x c --cuda-host-only
// RUN: FileCheck %s --match-full-lines --input-file %T/dh_h_constant_db/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/dh_h_constant_db_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: echo "]" >> compile_commands.json
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: rm compile_commands.json
// RUN: rm %T/dh_h_constant_db_win/out/MainSourceFiles.yaml
// RUN: dpct dh_h_constant_db_win.cpp --out-root=./out --cuda-include-path="%cuda-path/include" -- -x c --cuda-host-only
// RUN: FileCheck %s --match-full-lines --input-file %T/dh_h_constant_db_win/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/h_dh_constant_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// RUN: echo " \"file\": \"%/T/h_dh_constant_db/h_dh_constant_db.cpp\"" >> compile_commands.json
// RUN: echo " }" >> compile_commands.json
// RUN: echo "]" >> compile_commands.json
// RUN: rm %T/h_dh_constant_db/out/MainSourceFiles.yaml
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: FileCheck %s --match-full-lines --input-file %T/h_dh_constant_db/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/h_dh_constant_db_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// RUN: echo " \"file\": \"%/T/h_dh_constant_db_win/h_dh_constant_db_win.cpp\"" >> compile_commands.json
// RUN: echo " }" >> compile_commands.json
// RUN: echo "]" >> compile_commands.json
// RUN: rm %T/h_dh_constant_db_win/out/MainSourceFiles.yaml
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: FileCheck %s --match-full-lines --input-file %T/h_dh_constant_db_win/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/h_hd_constant_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// RUN: echo " \"file\": \"%/T/h_hd_constant_db/h_hd_constant_db.cpp\"" >> compile_commands.json
// RUN: echo " }" >> compile_commands.json
// RUN: echo "]" >> compile_commands.json
// RUN: rm %T/h_hd_constant_db/out/MainSourceFiles.yaml
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: FileCheck %s --match-full-lines --input-file %T/h_hd_constant_db/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/h_hd_constant_db_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// RUN: echo " \"file\": \"%/T/h_hd_constant_db_win/h_hd_constant_db_win.cpp\"" >> compile_commands.json
// RUN: echo " }" >> compile_commands.json
// RUN: echo "]" >> compile_commands.json
// RUN: rm %T/h_hd_constant_db_win/out/MainSourceFiles.yaml
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: FileCheck %s --match-full-lines --input-file %T/h_hd_constant_db_win/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/hd_d_constant_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: echo "]" >> compile_commands.json
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: rm compile_commands.json
// RUN: rm %T/hd_d_constant_db/out/MainSourceFiles.yaml
// RUN: dpct hd_d_constant_db.cpp --out-root=./out --cuda-include-path="%cuda-path/include" -- -x cuda --cuda-host-only
// RUN: FileCheck %s --match-full-lines --input-file %T/hd_d_constant_db/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/hd_d_constant_db_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: echo "]" >> compile_commands.json
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: rm compile_commands.json
// RUN: rm %T/hd_d_constant_db_win/out/MainSourceFiles.yaml
// RUN: dpct hd_d_constant_db_win.cpp --out-root=./out --cuda-include-path="%cuda-path/include" -- -x cuda --cuda-host-only
// RUN: FileCheck %s --match-full-lines --input-file %T/hd_d_constant_db_win/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/hd_h_constant_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: echo "]" >> compile_commands.json
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: rm compile_commands.json
// RUN: rm %T/hd_h_constant_db/out/MainSourceFiles.yaml
// RUN: dpct hd_h_constant_db.cpp --out-root=./out --cuda-include-path="%cuda-path/include" -- -x c --cuda-host-only
// RUN: FileCheck %s --match-full-lines --input-file %T/hd_h_constant_db/out/constant_header.h
// RUN: cd ..
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/hd_h_constant_db_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: echo "]" >> compile_commands.json
// RUN: dpct -p=. --out-root=./out --cuda-include-path="%cuda-path/include"
// RUN: rm compile_commands.json
// RUN: rm %T/hd_h_constant_db_win/out/MainSourceFiles.yaml
// RUN: dpct hd_h_constant_db_win.cpp --out-root=./out --cuda-include-path="%cuda-path/include" -- -x c --cuda-host-only
// RUN: FileCheck %s --match-full-lines --input-file %T/hd_h_constant_db_win/out/constant_header.h
// RUN: cd ..
Expand Down
11 changes: 11 additions & 0 deletions clang/test/dpct/header_insert/a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: dpct --out-root %T/ %s --cuda-include-path="%cuda-path/include"
// RUN: FileCheck --input-file %T/a.cpp.dp.cpp --match-full-lines %s

// CHECK: #include <sycl/sycl.hpp>
// CHECK-NEXT: #include <dpct/dpct.hpp>
// CHECK-NEXT: #include "h1.h"
#include "h1.h"

int main() {
return 0;
}
5 changes: 5 additions & 0 deletions clang/test/dpct/header_insert/h1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#include <vector>
#include <numeric>
#include "h2.h"
#include "h3.h"
2 changes: 2 additions & 0 deletions clang/test/dpct/header_insert/h2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

#include <bits/stdc++.h>
4 changes: 4 additions & 0 deletions clang/test/dpct/header_insert/h3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#include <iostream>
#include <string>
#include <cudnn.h>
1 change: 0 additions & 1 deletion clang/test/dpct/header_order/dnn.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// CHECK: #include <sycl/sycl.hpp>
// CHECK-NEXT: #include <dpct/dpct.hpp>
// CHECK-NEXT: #include "dnn.h"
// CHECK-NEXT: #include <dpct/dnnl_utils.hpp>
#include "dnn.h"

int test(cudnnHandle_t handle) {
Expand Down
1 change: 0 additions & 1 deletion clang/test/dpct/header_order/test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// CHECK-NEXT: #include <iostream>
// CHECK-NEXT: #include <algorithm>
// CHECK-NEXT: #include "dnn.h"
// CHECK-NEXT: #include <dpct/dnnl_utils.hpp>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
Expand Down
8 changes: 5 additions & 3 deletions clang/test/dpct/uncanonical_path/test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// RUN: dpct --out-root %T/uncanonical_path %s --cuda-include-path="%cuda-path/include"
// RUN: FileCheck --input-file %T/uncanonical_path/test.cpp --match-full-lines %s
// RUN: %if build_lit %{icpx -c -fsycl %T/uncanonical_path/test.cpp -o %T/uncanonical_path/test.o %}
// RUN: FileCheck --input-file %T/uncanonical_path/test.cpp.dp.cpp --match-full-lines %s
// RUN: %if build_lit %{icpx -c -fsycl %T/uncanonical_path/test.cpp.dp.cpp -o %T/uncanonical_path/test.o %}

// CHECK: #include "../uncanonical_path//test.h"
// CHECK: #include <sycl/sycl.hpp>
// CHECK-NEXT: #include <dpct/dpct.hpp>
// CHECK-NEXT: #include "../uncanonical_path//test.h"
#include "../uncanonical_path//test.h"

int main() {
Expand Down