Skip to content

Commit 2260ff1

Browse files
committed
[SYCL] Added a new CLANG pass that adapts the names of OclCXX
classes and funcs for translation to SPIRV. Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 71d6139 commit 2260ff1

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

clang/lib/CodeGen/BackendUtil.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "clang/Basic/Diagnostic.h"
1313
#include "clang/Basic/LangOptions.h"
1414
#include "clang/Basic/TargetOptions.h"
15+
#include "clang/CodeGen/OclCxxRewrite/BifNameReflower.h"
1516
#include "clang/Frontend/FrontendDiagnostic.h"
1617
#include "clang/Frontend/Utils.h"
1718
#include "clang/Lex/HeaderSearchOptions.h"
@@ -39,6 +40,7 @@
3940
#include "llvm/Passes/PassBuilder.h"
4041
#include "llvm/Support/BuryPointer.h"
4142
#include "llvm/Support/CommandLine.h"
43+
#include "llvm/Support/Debug.h"
4244
#include "llvm/Support/MemoryBuffer.h"
4345
#include "llvm/Support/PrettyStackTrace.h"
4446
#include "llvm/Support/TargetRegistry.h"
@@ -801,6 +803,10 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
801803
PerFunctionPasses.add(
802804
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
803805

806+
if (LangOpts.SYCL) {
807+
PerModulePasses.add(createOclCxxBifNameReflowerPass());
808+
}
809+
804810
CreatePasses(PerModulePasses, PerFunctionPasses);
805811

806812
legacy::PassManager CodeGenPasses;

clang/lib/CodeGen/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
add_subdirectory(OclCxxRewrite)
2+
13
set(LLVM_LINK_COMPONENTS
24
Analysis
35
BitReader
@@ -105,4 +107,5 @@ add_clang_library(clangCodeGen
105107
clangFrontend
106108
clangLex
107109
clangSerialization
110+
clangOclCxxRewrite
108111
)

clang/lib/CodeGen/CodeGenTypes.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD,
5555
llvm::raw_svector_ostream OS(TypeName);
5656
OS << RD->getKindName() << '.';
5757

58+
// NOTE: The following block of code is copied from CLANG-3.6 with
59+
// support of OpenCLCPlusPlus. It is rather the temporary solution
60+
// that is going to be used until the general solution is ported/developed
61+
// in the latest llvm trunc.
62+
//
63+
// For SYCL, the mangled type name is attached, so it can be
64+
// reflown to proper name later.
65+
if (getContext().getLangOpts().SYCL) {
66+
std::unique_ptr<MangleContext> MC(getContext().createMangleContext());
67+
auto RDT = getContext().getRecordType(RD);
68+
MC->mangleCXXRTTIName(RDT, OS);
69+
OS << ".";
70+
}
71+
5872
// Name the codegen type after the typedef name
5973
// if there is no tag type name available
6074
if (RD->getIdentifier()) {

0 commit comments

Comments
 (0)