Skip to content

Commit a115520

Browse files
authored
[SYCL][ESIMD] Implement IR pass to lower C++ ESIMD intrinsics. (#1881)
The pass transforms *__esimd_* Itanium - mangled C++ intrinsics to genx.*style parseable by the ESIMD - capable SPIRV translator. Move vc-intrinsics dependency build to llvm/lib/SYCLLowerIR. SYCLLowerIR is the only user of vc-intrinsics. Authors: Konstantin S Bobrovsky <[email protected]> Gang Chen <[email protected]> Wei Pan Denis Bakhvalov <[email protected]> Anton Sidorenko <[email protected]> Kaiyu Chen <[email protected]> Pratik Ashar <[email protected]> Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent c7bb288 commit a115520

File tree

8 files changed

+1601
-29
lines changed

8 files changed

+1601
-29
lines changed

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ void initializeStripNonLineTableDebugInfoPass(PassRegistry&);
414414
void initializeStripSymbolsPass(PassRegistry&);
415415
void initializeStructurizeCFGPass(PassRegistry&);
416416
void initializeSYCLLowerWGScopeLegacyPassPass(PassRegistry &);
417+
void initializeSYCLLowerESIMDLegacyPassPass(PassRegistry &);
417418
void initializeTailCallElimPass(PassRegistry&);
418419
void initializeTailDuplicatePass(PassRegistry&);
419420
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry&);

llvm/include/llvm/LinkAllPasses.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/CodeGen/Passes.h"
3838
#include "llvm/IR/Function.h"
3939
#include "llvm/IR/IRPrintingPasses.h"
40+
#include "llvm/SYCLLowerIR/LowerESIMD.h"
4041
#include "llvm/SYCLLowerIR/LowerWGScope.h"
4142
#include "llvm/Support/Valgrind.h"
4243
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
@@ -201,6 +202,7 @@ namespace {
201202
(void) llvm::createMergeICmpsLegacyPass();
202203
(void) llvm::createExpandMemCmpPass();
203204
(void)llvm::createSYCLLowerWGScopePass();
205+
(void)llvm::createSYCLLowerESIMDPass();
204206
std::string buf;
205207
llvm::raw_string_ostream os(buf);
206208
(void) llvm::createPrintModulePass(os);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===---- LowerESIMD.h - lower Explicit SIMD (ESIMD) constructs -----------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Lowers CM-specific LLVM IR constructs coming out of the front-end. These are:
10+
// - ESIMD intrinsics, e.g.:
11+
// template <typename Ty, int N, int M, int VStride, int Width,
12+
// int Stride, int ParentWidth = 0>
13+
// sycl::intel::gpu::vector_type_t<Ty, M>
14+
// __esimd_rdregion(sycl::intel::gpu::vector_type_t<Ty, N> Input,
15+
// uint16_t Offset);
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef LLVM_SYCLLOWERIR_LOWERESIMD_H
19+
#define LLVM_SYCLLOWERIR_LOWERESIMD_H
20+
21+
#include "llvm/IR/Function.h"
22+
#include "llvm/IR/PassManager.h"
23+
24+
namespace llvm {
25+
26+
/// SPIRV (ESIMD) target specific pass to transform ESIMD specific constructs
27+
/// like intrinsics to a form parsable by the ESIMD-aware SPIRV translator.
28+
class SYCLLowerESIMDPass : public PassInfoMixin<SYCLLowerESIMDPass> {
29+
public:
30+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &,
31+
SmallPtrSet<Type *, 4> &GVTS);
32+
};
33+
34+
FunctionPass *createSYCLLowerESIMDPass();
35+
void initializeSYCLLowerESIMDLegacyPassPass(PassRegistry &);
36+
37+
} // namespace llvm
38+
39+
#endif // LLVM_SYCLLOWERIR_LOWERESIMD_H

llvm/lib/SYCLLowerIR/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,54 @@
1+
# Lowering of SYCL ESIMD kernels depends on vc-intrinsics
2+
# NOTE: could have been added earlier from llvm/projects
3+
if (NOT TARGET LLVMGenXIntrinsics)
4+
if (NOT DEFINED LLVMGenXIntrinsics_SOURCE_DIR)
5+
message(STATUS "vc-intrinsics are missing. Will try to download them from github.com")
6+
7+
include(FetchContent)
8+
FetchContent_Declare(vc-intrinsics
9+
GIT_REPOSITORY https://github.com/intel/vc-intrinsics.git
10+
GIT_TAG cce6e48c28eb850d7dadd30841c0d95f009bbca1
11+
)
12+
FetchContent_MakeAvailable(vc-intrinsics)
13+
FetchContent_GetProperties(vc-intrinsics)
14+
15+
set(LLVMGenXIntrinsics_SOURCE_DIR ${vc-intrinsics_SOURCE_DIR})
16+
set(LLVMGenXIntrinsics_BINARY_DIR ${vc-intrinsics_BINARY_DIR})
17+
else()
18+
# -DLLVMGenXIntrinsics_SOURCE_DIR is provided
19+
message(STATUS "vc-intrinsics are added manually ${LLVMGenXIntrinsics_SOURCE_DIR}")
20+
21+
set(LLVMGenXIntrinsics_BINARY_DIR ${CMAKE_BINARY_DIR}/vc-intrinsics-build)
22+
add_subdirectory(${LLVMGenXIntrinsics_SOURCE_DIR} ${LLVMGenXIntrinsics_BINARY_DIR})
23+
endif()
24+
25+
target_include_directories(LLVMGenXIntrinsics
26+
PUBLIC $<BUILD_INTERFACE:${LLVMGenXIntrinsics_SOURCE_DIR}/GenXIntrinsics/include>
27+
PUBLIC $<BUILD_INTERFACE:${LLVMGenXIntrinsics_BINARY_DIR}/GenXIntrinsics/include>
28+
)
29+
endif()
30+
131
add_llvm_component_library(LLVMSYCLLowerIR
232
LowerWGScope.cpp
33+
LowerESIMD.cpp
334

435
ADDITIONAL_HEADER_DIRS
536
${LLVM_MAIN_INCLUDE_DIR}/llvm/SYCLLowerIR
37+
${LLVM_MAIN_SRC_DIR}/projects/vc-intrinsics/GenXIntrinsics/include
38+
${LLVM_BINARY_DIR}/projects/vc-intrinsics/GenXIntrinsics/include
639

740
DEPENDS
841
intrinsics_gen
42+
LLVMGenXIntrinsics
43+
LLVMDemangle
44+
LLVMTransformUtils
45+
46+
LINK_LIBS
47+
LLVMGenXIntrinsics
48+
LLVMDemangle
49+
LLVMTransformUtils
950
)
51+
52+
target_include_directories(LLVMSYCLLowerIR
53+
PRIVATE ${LLVM_MAIN_SRC_DIR}/projects/vc-intrinsics/GenXIntrinsics/include
54+
PRIVATE ${LLVM_BINARY_DIR}/projects/vc-intrinsics/GenXIntrinsics/include)

0 commit comments

Comments
 (0)