Skip to content

Commit c0f66d9

Browse files
mshelegoigcbot
authored andcommitted
Opaque pointers support in GenXSLMResolution
This change is a part of the effort to support opaque pointers in newer LLVM versions
1 parent 4d8019b commit c0f66d9

File tree

5 files changed

+54
-48
lines changed

5 files changed

+54
-48
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXOCLRuntimeInfo.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,6 @@ class KernelArgBuilder final {
103103
};
104104
} // namespace llvm
105105

106-
static alignment_t
107-
getAlignment(const Argument &Arg,
108-
GenXOCLRuntimeInfo::KernelArgInfo::KindType Kind) {
109-
using ArgKindType = GenXOCLRuntimeInfo::KernelArgInfo::KindType;
110-
if (Kind != ArgKindType::SLM)
111-
return 0;
112-
113-
Type *TypeToAlign = Arg.getType();
114-
TypeToAlign = IGCLLVM::getNonOpaquePtrEltTy(TypeToAlign);
115-
return Arg.getParent()
116-
->getParent()
117-
->getDataLayout()
118-
.getABITypeAlign(TypeToAlign)
119-
.value();
120-
}
121-
122106
KernelArgBuilder::ArgAccessKindType
123107
KernelArgBuilder::getOCLArgAccessKind(ArrayRef<StringRef> Tokens,
124108
ArgKindType Kind) const {
@@ -301,7 +285,12 @@ KernelArgBuilder::translateArgument(const Argument &Arg) const {
301285
// Linearization arguments have a non-zero offset in the original explicit
302286
// byval arg.
303287
Info.OffsetInArg = KM.getOffsetInArg(ArgNo);
304-
Info.Alignment = (unsigned)getAlignment(Arg, Info.Kind);
288+
if (Info.Kind == GenXOCLRuntimeInfo::KernelArgInfo::KindType::SLM)
289+
// Max SLM alignment is 16 or 8 bytes and depends on what memory
290+
// messages are used: legacy or LSC.
291+
Info.Alignment = ST.translateLegacyMessages() ? 8 : 16;
292+
else
293+
Info.Alignment = 0;
305294

306295
return Info;
307296
}

IGC/VectorCompiler/lib/GenXCodeGen/GenXSLMResolution.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2023 Intel Corporation
3+
Copyright (C) 2023-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -35,6 +35,7 @@ SPDX-License-Identifier: MIT
3535
//===----------------------------------------------------------------------===//
3636

3737
#include "GenX.h"
38+
#include "GenXTargetMachine.h"
3839
#include "GenXUtil.h"
3940

4041
#include "vc/Support/GenXDiagnostic.h"
@@ -47,6 +48,7 @@ SPDX-License-Identifier: MIT
4748
#include "llvmWrapper/IR/Value.h"
4849
#include "llvmWrapper/Support/Alignment.h"
4950

51+
#include <llvm/CodeGen/TargetPassConfig.h>
5052
#include <llvm/IR/Constants.h>
5153
#include <llvm/IR/IRBuilder.h>
5254
#include <llvm/IR/InstIterator.h>
@@ -68,12 +70,12 @@ class GenXSLMResolution : public ModulePass {
6870
StringRef getPassName() const override { return "GenX SLM Resolution"; }
6971
void getAnalysisUsage(AnalysisUsage &AU) const override {
7072
AU.addRequired<CallGraphWrapperPass>();
73+
AU.addRequired<TargetPassConfig>();
7174
AU.setPreservesCFG();
7275
}
7376
bool runOnModule(Module &M) override;
7477

7578
private:
76-
llvm::Align getSLMArgAlign(const Argument &A) const;
7779
llvm::Align getGlobalVarAlign(const GlobalVariable &GV) const;
7880
Constant *allocateOnSLM(const GlobalVariable &GV, unsigned &SLMSize) const;
7981
Constant *getNextOffset(llvm::Align Alignment, LLVMContext &Ctx,
@@ -172,11 +174,6 @@ static SmallVector<GlobalVariable *, 4> collectSLMVariables(Module &M) {
172174
return SLMVars;
173175
}
174176

175-
llvm::Align GenXSLMResolution::getSLMArgAlign(const Argument &A) const {
176-
auto *TypeToAlign = IGCLLVM::getNonOpaquePtrEltTy(A.getType());
177-
return IGCLLVM::getABITypeAlign(*DL, TypeToAlign);
178-
}
179-
180177
llvm::Align
181178
GenXSLMResolution::getGlobalVarAlign(const GlobalVariable &GV) const {
182179
if (GV.getAlignment())
@@ -251,8 +248,12 @@ bool GenXSLMResolution::runForKernel(Function &Head, Module &M,
251248
if (Arg == Head.arg_end())
252249
return Modified;
253250

254-
auto Align = getSLMArgAlign(*Arg);
255-
auto *Offset = getNextOffset(Align, Head.getContext(), SLMSize);
251+
const auto &ST = getAnalysis<TargetPassConfig>()
252+
.getTM<GenXTargetMachine>()
253+
.getGenXSubtarget();
254+
auto Alignment =
255+
ST.translateLegacyMessages() ? llvm::Align(8) : llvm::Align(16);
256+
auto *Offset = getNextOffset(Alignment, Head.getContext(), SLMSize);
256257
auto *NewPtr = ConstantExpr::getIntToPtr(Offset, Arg->getType());
257258
Arg->replaceAllUsesWith(NewPtr);
258259
return true;

IGC/VectorCompiler/test/GenXSLMResolution/arg.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
;=========================== begin_copyright_notice ============================
22
;
3-
; Copyright (C) 2023 Intel Corporation
3+
; Copyright (C) 2023-2024 Intel Corporation
44
;
55
; SPDX-License-Identifier: MIT
66
;
77
;============================ end_copyright_notice =============================
88

9-
; RUN: %opt %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s
9+
; RUN: %opt_typed_ptrs %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s --check-prefix=CHECK-TYPED-PTRS
10+
; RUN: %opt_opaque_ptrs %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s --check-prefix=CHECK-OPAQUE-PTRS
1011

1112
target datalayout = "e-p:64:64-i64:64-n8:16:32"
1213

1314
define dllexport void @kernel(i32 addrspace(3)* align 1 %out, i32 addrspace(3)* nocapture readonly %in) local_unnamed_addr #0 {
1415
entry:
15-
; CHECK: %ld = load i32, i32 addrspace(3)* %in, align 4
16+
; CHECK-TYPED-PTRS: %ld = load i32, i32 addrspace(3)* %in, align 4
17+
; CHECK-OPAQUE-PTRS: %ld = load i32, ptr addrspace(3) %in, align 4
1618
%ld = load i32, i32 addrspace(3)* %in, align 4
1719

18-
; CHECK: store i32 %ld, i32 addrspace(3)* inttoptr (i32 12 to i32 addrspace(3)*), align 4
20+
; CHECK-TYPED-PTRS: store i32 %ld, i32 addrspace(3)* inttoptr (i32 16 to i32 addrspace(3)*), align 4
21+
; CHECK-OPAQUE-PTRS: store i32 %ld, ptr addrspace(3) inttoptr (i32 16 to ptr addrspace(3)), align 4
1922
store i32 %ld, i32 addrspace(3)* %out, align 4
2023
ret void
2124
}

IGC/VectorCompiler/test/GenXSLMResolution/cfg.ll

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;=========================== begin_copyright_notice ============================
22
;
3-
; Copyright (C) 2022-2023 Intel Corporation
3+
; Copyright (C) 2022-2024 Intel Corporation
44
;
55
; SPDX-License-Identifier: MIT
66
;
@@ -23,7 +23,8 @@
2323
; \ /
2424
; bar
2525

26-
; RUN: %opt %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s
26+
; RUN: %opt_typed_ptrs %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-TYPED-PTRS
27+
; RUN: %opt_opaque_ptrs %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-OPAQUE-PTRS
2728

2829
target datalayout = "e-p:64:64-i64:64-n8:16:32"
2930

@@ -37,8 +38,10 @@ define internal spir_func i32 @bar(i32 addrspace(3)* %arg) #1 {
3738

3839
; CHECK-LABEL: define internal spir_func i32 @foo
3940
define internal spir_func i32 @foo(i32 addrspace(3)* %arg) #1 {
40-
; CHECK: [[SPLIT_FOO:%[^ ]+]] = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 1
41-
; CHECK: %bar.res = call spir_func i32 @bar(i32 addrspace(3)* [[SPLIT_FOO]])
41+
; CHECK-TYPED-PTRS: [[SPLIT_FOO:%[^ ]+]] = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 1
42+
; CHECK-TYPED-PTRS: %bar.res = call spir_func i32 @bar(i32 addrspace(3)* [[SPLIT_FOO]])
43+
; CHECK-OPAQUE-PTRS: [[SPLIT_FOO:%[^ ]+]] = getelementptr inbounds [4 x i32], ptr addrspace(3) inttoptr (i32 268435456 to ptr addrspace(3)), i64 0, i64 1
44+
; CHECK-OPAQUE-PTRS: %bar.res = call spir_func i32 @bar(ptr addrspace(3) [[SPLIT_FOO]])
4245
%arg.ld = load i32, i32 addrspace(3)* %arg, align 4
4346
%bar.res = call spir_func i32 @bar(i32 addrspace(3)* getelementptr inbounds ([4 x i32], [4 x i32] addrspace(3)* @SLM_GV, i64 0, i64 1))
4447
%res = add i32 %bar.res, %arg.ld
@@ -47,19 +50,22 @@ define internal spir_func i32 @foo(i32 addrspace(3)* %arg) #1 {
4750

4851
; CHECK-LABEL: define internal spir_func i32 @f1
4952
define internal spir_func i32 @f1() #1 {
50-
; CHECK: %gv.p3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 2
53+
; CHECK-TYPED-PTRS: %gv.p3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 2
54+
; CHECK-OPAQUE-PTRS: %gv.p3 = getelementptr inbounds [4 x i32], ptr addrspace(3) inttoptr (i32 268435456 to ptr addrspace(3)), i64 0, i64 2
5155
%gv.p3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* @SLM_GV, i64 0, i64 2
5256
%foo.res = call spir_func i32 @foo(i32 addrspace(3)* %gv.p3)
5357
ret i32 %foo.res
5458
}
5559

5660
; CHECK-LABEL: define internal spir_func i32 @f2
5761
define internal spir_func i32 @f2() #1 {
58-
; CHECK: %gv.p3.0 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64
62+
; CHECK-TYPED-PTRS: %gv.p3.0 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64
63+
; CHECK-OPAQUE-PTRS: %gv.p3.0 = getelementptr inbounds [4 x i32], ptr addrspace(3) inttoptr (i32 268435456 to ptr addrspace(3)), i64 0, i64
5964
%gv.p3.0 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* @SLM_GV, i64 0, i64 0
6065
%gv.ld.0 = load i32, i32 addrspace(3)* %gv.p3.0, align 4
6166

62-
; CHECK: %gv.p3.3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 3
67+
; CHECK-TYPED-PTRS: %gv.p3.3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 3
68+
; CHECK-OPAQUE-PTRS: %gv.p3.3 = getelementptr inbounds [4 x i32], ptr addrspace(3) inttoptr (i32 268435456 to ptr addrspace(3)), i64 0, i64 3
6369
%gv.p3.3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* @SLM_GV, i64 0, i64 3
6470
%gv.ld.3 = load i32, i32 addrspace(3)* %gv.p3.3, align 4
6571

@@ -76,7 +82,8 @@ define internal spir_func i32 @f2() #1 {
7682
define internal spir_func i32 @f0(i32 addrspace(3)* %arg) #1 {
7783
%arg.ld = load i32, i32 addrspace(3)* %arg, align 4
7884

79-
; CHECK: %gv.p3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 0
85+
; CHECK-TYPED-PTRS: %gv.p3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 0
86+
; CHECK-OPAQUE-PTRS: %gv.p3 = getelementptr inbounds [4 x i32], ptr addrspace(3) inttoptr (i32 268435456 to ptr addrspace(3)), i64 0, i64 0
8087
%gv.p3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* @SLM_GV, i64 0, i64 0
8188
%gv.ld = load i32, i32 addrspace(3)* %gv.p3, align 4
8289

@@ -96,8 +103,9 @@ exit:
96103

97104
; CHECK-LABEL: define internal spir_func i32 @f3
98105
define internal spir_func i32 @f3(i32 addrspace(3)* %arg) #1 {
99-
; CHECK: [[SPLIT_F3:%[^ ]+]] = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 64 to [4 x i32] addrspace(3)*), i64 0, i64 0
100-
; CHECK: %bar.res = call spir_func i32 @bar(i32 addrspace(3)* [[SPLIT_F3]])
106+
; CHECK-TYPED-PTRS: [[SPLIT_F3:%[^ ]+]] = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 64 to [4 x i32] addrspace(3)*), i64 0, i64 0
107+
; CHECK-TYPED-PTRS: %bar.res = call spir_func i32 @bar(i32 addrspace(3)* [[SPLIT_F3]])
108+
; CHECK-OPAQUE-PTRS: ptr addrspace(3) inttoptr (i32 64 to ptr addrspace(3))
101109
%bar.res = call spir_func i32 @bar(i32 addrspace(3)* getelementptr inbounds ([4 x i32], [4 x i32] addrspace(3)* @SLM_GV, i64 0, i64 0))
102110
%arg.ld = load i32, i32 addrspace(3)* %arg, align 4
103111
%sum = add i32 %bar.res, %arg.ld
@@ -106,22 +114,27 @@ define internal spir_func i32 @f3(i32 addrspace(3)* %arg) #1 {
106114

107115
; CHECK-LABEL: define dllexport spir_kernel void @kernelA
108116
define dllexport spir_kernel void @kernelA() #2 {
109-
; CHECK: [[SPLIT_KA:%[^ ]+]] = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 0
110-
; CHECK: %res = call spir_func i32 @f0(i32 addrspace(3)* [[SPLIT_KA]])
117+
; CHECK-TYPED-PTRS: [[SPLIT_KA:%[^ ]+]] = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 268435456 to [4 x i32] addrspace(3)*), i64 0, i64 0
118+
; CHECK-TYPED-PTRS: %res = call spir_func i32 @f0(i32 addrspace(3)* [[SPLIT_KA]])
119+
; CHECK-OPAQUE-PTRS: ptr addrspace(3) inttoptr (i32 268435456 to ptr addrspace(3))
111120
%res = call spir_func i32 @f0(i32 addrspace(3)* getelementptr inbounds ([4 x i32], [4 x i32] addrspace(3)* @SLM_GV, i64 0, i64 0))
112121
ret void
113122
}
114123

115124
; CHECK-LABEL: define dllexport spir_kernel void @kernelB
116125
define dllexport spir_kernel void @kernelB() #2 {
117-
; CHECK: [[SPLIT_KB:%[^ ]+]] = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 64 to [4 x i32] addrspace(3)*), i64 0, i64 3
118-
; CHECK: %res = call spir_func i32 @f3(i32 addrspace(3)* [[SPLIT_KB]])
126+
; CHECK-TYPED-PTRS: [[SPLIT_KB:%[^ ]+]] = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* inttoptr (i32 64 to [4 x i32] addrspace(3)*), i64 0, i64 3
127+
; CHECK-TYPED-PTRS: %res = call spir_func i32 @f3(i32 addrspace(3)* [[SPLIT_KB]])
128+
; CHECK-OPAQUE-PTRS: [[SPLIT_KB:%[^ ]+]] = getelementptr inbounds [4 x i32], ptr addrspace(3) inttoptr (i32 64 to ptr addrspace(3)), i64 0, i64 3
129+
; CHECK-OPAQUE-PTRS: %res = call spir_func i32 @f3(ptr addrspace(3) [[SPLIT_KB]])
119130
%res = call spir_func i32 @f3(i32 addrspace(3)* getelementptr inbounds ([4 x i32], [4 x i32] addrspace(3)* @SLM_GV, i64 0, i64 3))
120131
ret void
121132
}
122133

123-
; CHECK: !{{[[:digit:]]}} = !{void ()* @kernelA, !"kernelA", !{{[[:digit:]]}}, i32 16, !{{[[:digit:]]}}, !{{[[:digit:]]}}, !{{[[:digit:]]}}, i32 0}
124-
; CHECK: !{{[[:digit:]]}} = !{void ()* @kernelB, !"kernelB", !{{[[:digit:]]}}, i32 80, !{{[[:digit:]]}}, !{{[[:digit:]]}}, !{{[[:digit:]]}}, i32 0}
134+
; CHECK-TYPED-PTRS: !{{[[:digit:]]}} = !{void ()* @kernelA, !"kernelA", !{{[[:digit:]]}}, i32 16, !{{[[:digit:]]}}, !{{[[:digit:]]}}, !{{[[:digit:]]}}, i32 0}
135+
; CHECK-TYPED-PTRS: !{{[[:digit:]]}} = !{void ()* @kernelB, !"kernelB", !{{[[:digit:]]}}, i32 80, !{{[[:digit:]]}}, !{{[[:digit:]]}}, !{{[[:digit:]]}}, i32 0}
136+
; CHECK-OPAQUE-PTRS: !{{[[:digit:]]}} = !{ptr @kernelA, !"kernelA", !{{[[:digit:]]}}, i32 16, !{{[[:digit:]]}}, !{{[[:digit:]]}}, !{{[[:digit:]]}}, i32 0}
137+
; CHECK-OPAQUE-PTRS: !{{[[:digit:]]}} = !{ptr @kernelB, !"kernelB", !{{[[:digit:]]}}, i32 80, !{{[[:digit:]]}}, !{{[[:digit:]]}}, !{{[[:digit:]]}}, i32 0}
125138

126139
attributes #0 = { "VCGlobalVariable" }
127140
attributes #1 = { noinline nounwind }

IGC/VectorCompiler/test/GenXSLMResolution/simple.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
;
77
;============================ end_copyright_notice =============================
88

9-
; RUN: %opt_typed_ptrs %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK-TYPED-PTRS
10-
; RUN: %opt_opaque_ptrs %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK-OPAQUE-PTRS
9+
; RUN: %opt_typed_ptrs %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s --check-prefix=CHECK-TYPED-PTRS
10+
; RUN: %opt_opaque_ptrs %use_old_pass_manager% -GenXSLMResolution -march=genx64 -mcpu=Gen9 -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s --check-prefix=CHECK-OPAQUE-PTRS
1111

1212
target datalayout = "e-p:64:64-i64:64-n8:16:32"
1313

0 commit comments

Comments
 (0)