Skip to content

Commit 35ee8d2

Browse files
authored
[SYCL][NFC] Move LowerWGScope pass to LLVM project (#1306)
LowerWGScope pass is an llvm pass that performs SYCL specific transformations in LLVM IR right after frontend. LLVM passes are supposed to be in llvm project and not in clang project. Add lit tests for SYCL specific CodeGen and LowerWGScope pass Signed-off-by: Artur Gainullin <artur.gainullin@intel.com>
1 parent 3b6799a commit 35ee8d2

File tree

20 files changed

+149
-73
lines changed

20 files changed

+149
-73
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang/CodeGen/BackendUtil.h"
10-
#include "SYCLLowerIR/LowerWGScope.h"
1110
#include "clang/Basic/CodeGenOptions.h"
1211
#include "clang/Basic/Diagnostic.h"
1312
#include "clang/Basic/LangOptions.h"

clang/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
add_subdirectory(SYCLLowerIR)
2-
31
set(LLVM_LINK_COMPONENTS
42
Analysis
53
BitReader
@@ -23,6 +21,7 @@ set(LLVM_LINK_COMPONENTS
2321
Remarks
2422
ScalarOpts
2523
Support
24+
SYCLLowerIR
2625
Target
2726
TransformUtils
2827
)
@@ -112,5 +111,4 @@ add_clang_library(clangCodeGen
112111
clangFrontend
113112
clangLex
114113
clangSerialization
115-
clangSYCLLowerIR
116114
)

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "CodeGenModule.h"
1111
#include "CoverageMappingGen.h"
1212
#include "MacroPPCallbacks.h"
13-
#include "SYCLLowerIR/LowerWGScope.h"
1413
#include "clang/AST/ASTConsumer.h"
1514
#include "clang/AST/ASTContext.h"
1615
#include "clang/AST/DeclCXX.h"
@@ -39,6 +38,7 @@
3938
#include "llvm/IRReader/IRReader.h"
4039
#include "llvm/Linker/Linker.h"
4140
#include "llvm/Pass.h"
41+
#include "llvm/SYCLLowerIR/LowerWGScope.h"
4242
#include "llvm/Support/MemoryBuffer.h"
4343
#include "llvm/Support/SourceMgr.h"
4444
#include "llvm/Support/TimeProfiler.h"
@@ -335,7 +335,7 @@ namespace clang {
335335
if (LangOpts.SYCLIsDevice) {
336336
PrettyStackTraceString CrashInfo("Pre-linking SYCL passes");
337337
legacy::PassManager PreLinkingSyclPasses;
338-
PreLinkingSyclPasses.add(createSYCLLowerWGScopePass());
338+
PreLinkingSyclPasses.add(llvm::createSYCLLowerWGScopePass());
339339
PreLinkingSyclPasses.run(*getModule());
340340
}
341341

clang/lib/CodeGen/SYCLLowerIR/CMakeLists.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

clang/test/CodeGenSYCL/hier_par.cpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ void initializeStripNonDebugSymbolsPass(PassRegistry&);
404404
void initializeStripNonLineTableDebugInfoPass(PassRegistry&);
405405
void initializeStripSymbolsPass(PassRegistry&);
406406
void initializeStructurizeCFGPass(PassRegistry&);
407+
void initializeSYCLLowerWGScopeLegacyPassPass(PassRegistry &);
407408
void initializeTailCallElimPass(PassRegistry&);
408409
void initializeTailDuplicatePass(PassRegistry&);
409410
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/LowerWGScope.h"
4041
#include "llvm/Support/Valgrind.h"
4142
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
4243
#include "llvm/Transforms/IPO.h"
@@ -199,6 +200,7 @@ namespace {
199200
(void) llvm::createMergeFunctionsPass();
200201
(void) llvm::createMergeICmpsLegacyPass();
201202
(void) llvm::createExpandMemCmpPass();
203+
(void)llvm::createSYCLLowerWGScopePass();
202204
std::string buf;
203205
llvm::raw_string_ostream os(buf);
204206
(void) llvm::createPrintModulePass(os);

clang/lib/CodeGen/SYCLLowerIR/LowerWGScope.h renamed to llvm/include/llvm/SYCLLowerIR/LowerWGScope.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class SYCLLowerWGScopePass : public PassInfoMixin<SYCLLowerWGScopePass> {
2525
};
2626

2727
FunctionPass *createSYCLLowerWGScopePass();
28-
void initializeSYCLLowerWGScopeLegacyPassPass(PassRegistry &);
2928

3029
} // namespace llvm
3130

llvm/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ add_subdirectory(AsmParser)
2727
add_subdirectory(LineEditor)
2828
add_subdirectory(ProfileData)
2929
add_subdirectory(Passes)
30+
add_subdirectory(SYCLLowerIR)
3031
add_subdirectory(TextAPI)
3132
add_subdirectory(ToolDrivers)
3233
add_subdirectory(XRay)

llvm/lib/LLVMBuild.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ subdirectories =
4242
Passes
4343
ProfileData
4444
Support
45+
SYCLLowerIR
4546
TableGen
4647
TextAPI
4748
Target

llvm/lib/SYCLLowerIR/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
add_llvm_component_library(LLVMSYCLLowerIR
2+
LowerWGScope.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${LLVM_MAIN_INCLUDE_DIR}/llvm/SYCLLowerIR
6+
7+
DEPENDS
8+
intrinsics_gen
9+
)

llvm/lib/SYCLLowerIR/LLVMBuild.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
;===- ./lib/SYCLLowerIR/LLVMBuild.txt -----------------------------*- Conf -*--===;
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+
; This is an LLVMBuild description file for the components in this subdirectory.
10+
;
11+
; For more information on the LLVMBuild system, please see:
12+
;
13+
; http://llvm.org/docs/LLVMBuild.html
14+
;
15+
;===------------------------------------------------------------------------===;
16+
17+
[component_0]
18+
type = Group
19+
name = SYCLLowerIR
20+
parent = Libraries

clang/lib/CodeGen/SYCLLowerIR/LowerWGScope.cpp renamed to llvm/lib/SYCLLowerIR/LowerWGScope.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@
7373
// et. al.
7474
//===----------------------------------------------------------------------===//
7575

76-
#include "LowerWGScope.h"
77-
78-
#include "clang/Basic/AddressSpaces.h"
79-
76+
#include "llvm/SYCLLowerIR/LowerWGScope.h"
8077
#include "llvm/ADT/SmallPtrSet.h"
8178
#include "llvm/ADT/SmallVector.h"
8279
#include "llvm/ADT/Statistic.h"
@@ -85,6 +82,7 @@
8582
#include "llvm/IR/Instructions.h"
8683
#include "llvm/IR/IntrinsicInst.h"
8784
#include "llvm/IR/Module.h"
85+
#include "llvm/InitializePasses.h"
8886
#include "llvm/Pass.h"
8987
#include "llvm/Support/CommandLine.h"
9088

llvm/test/SYCLLowerIR/byval_arg.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: opt < %s -LowerWGScope -S | FileCheck %s
2+
3+
; Check that argument of the function marked with !work_group_scope
4+
; attribute passed as byval is shared by leader work item via local
5+
; memory to all work items
6+
7+
%struct.baz = type { i64 }
8+
9+
; CHECK: @[[SHADOW:[a-zA-Z0-9]+]] = internal unnamed_addr addrspace(3) global %struct.baz undef
10+
11+
define internal spir_func void @wibble(%struct.baz* byval(%struct.baz) %arg1) !work_group_scope !0 {
12+
; CHECK-LABEL: @wibble(
13+
; CHECK-NEXT: [[TMP1:%.*]] = load i64, i64 addrspace(1)* @__spirv_BuiltInLocalInvocationIndex
14+
; CHECK-NEXT: [[CMPZ:%.*]] = icmp eq i64 [[TMP1]], 0
15+
; CHECK-NEXT: br i1 [[CMPZ]], label [[LEADER:%.*]], label [[MERGE:%.*]]
16+
; CHECK: leader:
17+
; CHECK-NEXT: [[TMP2:%.*]] = bitcast %struct.baz* [[ARG1:%.*]] to i8*
18+
; CHECK-NEXT: call void @llvm.memcpy.p3i8.p0i8.i64(i8 addrspace(3)* align 8 bitcast (%struct.baz addrspace(3)* @[[SHADOW]] to i8 addrspace(3)*), i8* [[TMP2]], i64 8, i1 false)
19+
; CHECK-NEXT: br label [[MERGE]]
20+
; CHECK: merge:
21+
; CHECK-NEXT: call void @__spirv_ControlBarrier(i32 2, i32 2, i32 272)
22+
; CHECK-NEXT: ret void
23+
;
24+
ret void
25+
}
26+
27+
!0 = !{}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -LowerWGScope -S | FileCheck %s
3+
4+
; Check that allocas which correspond to PFWI lambda object and a local copy of the PFWG lambda object
5+
; are properly handled by LowerWGScope pass. Check that WG-shared local "shadow" variables are created
6+
; and before each PFWI invocation leader WI stores its private copy of the variable into the shadow,
7+
; then all WIs load the shadow value into their private copies ("materialize" the private copy).
8+
9+
%struct.bar = type { i8 }
10+
%struct.zot = type { %struct.widget, %struct.widget, %struct.widget, %struct.foo }
11+
%struct.widget = type { %struct.barney }
12+
%struct.barney = type { [3 x i64] }
13+
%struct.foo = type { %struct.barney }
14+
%struct.foo.0 = type { i8 }
15+
16+
; CHECK: @[[PFWG_SHADOW:.*]] = internal unnamed_addr addrspace(3) global %struct.bar addrspace(4)*
17+
; CHECK: @[[PFWI_SHADOW:.*]] = internal unnamed_addr addrspace(3) global %struct.foo.0
18+
; CHECK: @[[GROUP_SHADOW:.*]] = internal unnamed_addr addrspace(3) global %struct.zot
19+
20+
define internal spir_func void @wibble(%struct.bar addrspace(4)* %arg, %struct.zot* byval(%struct.zot) align 8 %arg1) align 2 !work_group_scope !0 {
21+
; CHECK-LABEL: @wibble(
22+
; CHECK-NEXT: bb:
23+
; CHECK-NEXT: [[TMP0:%.*]] = load i64, i64 addrspace(1)* @__spirv_BuiltInLocalInvocationIndex
24+
; CHECK-NEXT: [[CMPZ3:%.*]] = icmp eq i64 [[TMP0]], 0
25+
; CHECK-NEXT: br i1 [[CMPZ3]], label [[LEADER:%.*]], label [[MERGE:%.*]]
26+
; CHECK: leader:
27+
; CHECK-NEXT: [[TMP1:%.*]] = bitcast %struct.zot* [[ARG1:%.*]] to i8*
28+
; CHECK-NEXT: call void @llvm.memcpy.p3i8.p0i8.i64(i8 addrspace(3)* align 16 bitcast (%struct.zot addrspace(3)* @[[GROUP_SHADOW]] to i8 addrspace(3)*), i8* align 8 [[TMP1]], i64 96, i1 false)
29+
; CHECK-NEXT: br label [[MERGE]]
30+
; CHECK: merge:
31+
; CHECK-NEXT: call void @__spirv_ControlBarrier(i32 2, i32 2, i32 272)
32+
; CHECK-NEXT: [[TMP:%.*]] = alloca [[STRUCT_BAR:%.*]] addrspace(4)*, align 8
33+
; CHECK-NEXT: [[TMP2:%.*]] = alloca [[STRUCT_FOO_0:%.*]], align 1
34+
; CHECK-NEXT: [[ID:%.*]] = load i64, i64 addrspace(1)* @__spirv_BuiltInLocalInvocationIndex
35+
; CHECK-NEXT: [[CMPZ:%.*]] = icmp eq i64 [[ID]], 0
36+
; CHECK-NEXT: br i1 [[CMPZ]], label [[WG_LEADER:%.*]], label [[WG_CF:%.*]]
37+
; CHECK: wg_leader:
38+
; CHECK-NEXT: store [[STRUCT_BAR]] addrspace(4)* [[ARG:%.*]], [[STRUCT_BAR]] addrspace(4)** [[TMP]], align 8
39+
; CHECK-NEXT: [[TMP3:%.*]] = load [[STRUCT_BAR]] addrspace(4)*, [[STRUCT_BAR]] addrspace(4)** [[TMP]], align 8
40+
; CHECK-NEXT: [[TMP4:%.*]] = addrspacecast [[STRUCT_ZOT:%.*]] addrspace(3)* @[[GROUP_SHADOW]] to [[STRUCT_ZOT]] addrspace(4)*
41+
; CHECK-NEXT: store [[STRUCT_ZOT]] addrspace(4)* [[TMP4]], [[STRUCT_ZOT]] addrspace(4)* addrspace(3)* @wibbleWG_tmp4
42+
; CHECK-NEXT: br label [[WG_CF]]
43+
; CHECK: wg_cf:
44+
; CHECK-NEXT: [[TMP3:%.*]] = load i64, i64 addrspace(1)* @__spirv_BuiltInLocalInvocationIndex
45+
; CHECK-NEXT: [[CMPZ2:%.*]] = icmp eq i64 [[TMP3]], 0
46+
; CHECK-NEXT: br i1 [[CMPZ2]], label [[TESTMAT:%.*]], label [[LEADERMAT:%.*]]
47+
; CHECK: TestMat:
48+
; CHECK-NEXT: [[TMP4:%.*]] = bitcast %struct.foo.0* [[TMP2]] to i8*
49+
; CHECK-NEXT: call void @llvm.memcpy.p3i8.p0i8.i64(i8 addrspace(3)* align 8 getelementptr inbounds (%struct.foo.0, [[STRUCT_FOO_0]] addrspace(3)* @[[PFWI_SHADOW]], i32 0, i32 0), i8* align 1 [[TMP4]], i64 1, i1 false)
50+
; CHECK-NEXT: [[MAT_LD:%.*]] = load [[STRUCT_BAR]] addrspace(4)*, [[STRUCT_BAR]] addrspace(4)** [[TMP]]
51+
; CHECK-NEXT: store [[STRUCT_BAR]] addrspace(4)* [[MAT_LD]], [[STRUCT_BAR]] addrspace(4)* addrspace(3)* @[[PFWG_SHADOW]]
52+
; CHECK-NEXT: br label [[LEADERMAT]]
53+
; CHECK: LeaderMat:
54+
; CHECK-NEXT: call void @__spirv_ControlBarrier(i32 2, i32 2, i32 272)
55+
; CHECK-NEXT: [[MAT_LD1:%.*]] = load [[STRUCT_BAR]] addrspace(4)*, [[STRUCT_BAR]] addrspace(4)* addrspace(3)* @[[PFWG_SHADOW]]
56+
; CHECK-NEXT: store [[STRUCT_BAR]] addrspace(4)* [[MAT_LD1]], [[STRUCT_BAR]] addrspace(4)** [[TMP]]
57+
; CHECK-NEXT: [[TMP5:%.*]] = bitcast %struct.foo.0* [[TMP2]] to i8*
58+
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p3i8.i64(i8* align 1 [[TMP5]], i8 addrspace(3)* align 8 getelementptr inbounds (%struct.foo.0, [[STRUCT_FOO_0]] addrspace(3)* @[[PFWI_SHADOW]], i32 0, i32 0), i64 1, i1 false)
59+
; CHECK-NEXT: call void @__spirv_ControlBarrier(i32 2, i32 2, i32 272)
60+
; CHECK-NEXT: [[WG_VAL_TMP4:%.*]] = load [[STRUCT_ZOT]] addrspace(4)*, [[STRUCT_ZOT]] addrspace(4)* addrspace(3)* @wibbleWG_tmp4
61+
; CHECK-NEXT: call spir_func void @bar(%struct.zot addrspace(4)* [[WG_VAL_TMP4]], %struct.foo.0* byval(%struct.foo.0) align 1 [[TMP2]])
62+
; CHECK-NEXT: ret void
63+
;
64+
bb:
65+
%tmp = alloca %struct.bar addrspace(4)*, align 8
66+
%tmp2 = alloca %struct.foo.0, align 1
67+
store %struct.bar addrspace(4)* %arg, %struct.bar addrspace(4)** %tmp, align 8
68+
%tmp3 = load %struct.bar addrspace(4)*, %struct.bar addrspace(4)** %tmp, align 8
69+
%tmp4 = addrspacecast %struct.zot* %arg1 to %struct.zot addrspace(4)*
70+
call spir_func void @bar(%struct.zot addrspace(4)* %tmp4, %struct.foo.0* byval(%struct.foo.0) align 1 %tmp2)
71+
ret void
72+
}
73+
74+
define internal spir_func void @bar(%struct.zot addrspace(4)* %arg, %struct.foo.0* byval(%struct.foo.0) align 1 %arg1) align 2 !work_item_scope !0 !parallel_for_work_item !0 {
75+
bb:
76+
ret void
77+
}
78+
79+
!0 = !{}

llvm/tools/bugpoint/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(LLVM_LINK_COMPONENTS
1616
ObjCARCOpts
1717
ScalarOpts
1818
Support
19+
SYCLLowerIR
1920
Target
2021
TransformUtils
2122
Vectorize

llvm/tools/opt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(LLVM_LINK_COMPONENTS
1818
Remarks
1919
ScalarOpts
2020
Support
21+
SYCLLowerIR
2122
Target
2223
TransformUtils
2324
Vectorize

llvm/tools/opt/opt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ int main(int argc, char **argv) {
563563
initializeWriteBitcodePassPass(Registry);
564564
initializeHardwareLoopsPass(Registry);
565565
initializeTypePromotionPass(Registry);
566+
initializeSYCLLowerWGScopeLegacyPassPass(Registry);
566567

567568
#ifdef BUILD_EXAMPLES
568569
initializeExampleIRTransforms(Registry);

sycl/test/hier_par/hier_par_wgscope.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// RUN: %GPU_RUN_PLACEHOLDER %t.out
1313
// RUN: %ACC_RUN_PLACEHOLDER %t.out
1414

15-
// RUN: %clangxx -O0 -fsycl %s -o %t.out
15+
// RUN: %clangxx -O0 -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
1616
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
1717
// RUN: %CPU_RUN_PLACEHOLDER %t.out
1818
// RUN: %GPU_RUN_PLACEHOLDER %t.out

0 commit comments

Comments
 (0)