Skip to content

Commit c1fe5fe

Browse files
authored
Translate readnone attribute as function parameter attribute (#1697)
Community restricted readnone, readonly and writeonly attributes to be only function parameter attributes. This patch aligns the translator with llvm.org. It also fixes a bug, when readnone attribute is being mapped to NoWrite SPIR-V function parameter attribute. Signed-off-by: Sidorov, Dmitry <[email protected]> Signed-off-by: Sidorov, Dmitry <[email protected]>
1 parent ea3ddc1 commit c1fe5fe

14 files changed

+46
-34
lines changed

lib/SPIRV/SPIRVInternal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,14 @@ inline void SPIRVMap<Attribute::AttrKind, SPIRVFuncParamAttrKind>::init() {
236236
add(Attribute::NoAlias, FunctionParameterAttributeNoAlias);
237237
add(Attribute::NoCapture, FunctionParameterAttributeNoCapture);
238238
add(Attribute::ReadOnly, FunctionParameterAttributeNoWrite);
239+
add(Attribute::ReadNone, FunctionParameterAttributeNoReadWrite);
239240
}
240241
typedef SPIRVMap<Attribute::AttrKind, SPIRVFuncParamAttrKind>
241242
SPIRSPIRVFuncParamAttrMap;
242243

243244
template <>
244245
inline void
245246
SPIRVMap<Attribute::AttrKind, SPIRVFunctionControlMaskKind>::init() {
246-
add(Attribute::ReadNone, FunctionControlPureMask);
247-
add(Attribute::ReadOnly, FunctionControlConstMask);
248247
add(Attribute::AlwaysInline, FunctionControlInlineMask);
249248
add(Attribute::NoInline, FunctionControlDontInlineMask);
250249
add(Attribute::OptimizeNone, internal::FunctionControlOptNoneINTELMask);

lib/SPIRV/SPIRVReader.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4387,7 +4387,9 @@ Instruction *SPIRVToLLVM::transOCLBuiltinFromExtInst(SPIRVExtInst *BC,
43874387
if (isFuncNoUnwind())
43884388
F->addFnAttr(Attribute::NoUnwind);
43894389
if (isFuncReadNone(UnmangledName))
4390-
F->addFnAttr(Attribute::ReadNone);
4390+
for (llvm::Argument &Arg : F->args())
4391+
if (Arg.getType()->isPointerTy())
4392+
Arg.addAttr(Attribute::ReadNone);
43914393
}
43924394
auto Args = transValue(BC->getArgValues(), F, BB);
43934395
SPIRVDBG(dbgs() << "[transOCLBuiltinFromExtInst] Function: " << *F

lib/SPIRV/SPIRVUtil.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,8 +2063,10 @@ bool lowerBuiltinVariableToCall(GlobalVariable *GV,
20632063
Func = Function::Create(FT, GlobalValue::ExternalLinkage, MangledName, M);
20642064
Func->setCallingConv(CallingConv::SPIR_FUNC);
20652065
Func->addFnAttr(Attribute::NoUnwind);
2066-
Func->addFnAttr(Attribute::ReadNone);
20672066
Func->addFnAttr(Attribute::WillReturn);
2067+
for (llvm::Argument &Arg : Func->args())
2068+
if (Arg.getType()->isPointerTy())
2069+
Arg.addAttr(Attribute::ReadNone);
20682070
}
20692071

20702072
// Collect instructions in these containers to remove them later.

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,10 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) {
849849
BA->addAttr(FunctionParameterAttributeNoCapture);
850850
if (I->hasStructRetAttr())
851851
BA->addAttr(FunctionParameterAttributeSret);
852-
if (I->onlyReadsMemory())
852+
if (Attrs.hasParamAttr(ArgNo, Attribute::ReadOnly))
853853
BA->addAttr(FunctionParameterAttributeNoWrite);
854+
if (Attrs.hasParamAttr(ArgNo, Attribute::ReadNone))
855+
BA->addAttr(FunctionParameterAttributeNoReadWrite);
854856
if (Attrs.hasParamAttr(ArgNo, Attribute::ZExt))
855857
BA->addAttr(FunctionParameterAttributeZext);
856858
if (Attrs.hasParamAttr(ArgNo, Attribute::SExt))

test/transcoding/OpGenericPtrMemSemantics.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ target triple = "spir-unknown-unknown"
2424

2525
@gint = addrspace(1) global i32 1, align 4
2626

27-
; Function Attrs: nounwind readnone
27+
; Function Attrs: nounwind
2828
define spir_func i32 @isFenceValid(i32 %fence) #0 {
2929
entry:
3030
%switch = icmp ult i32 %fence, 4
@@ -66,7 +66,7 @@ entry:
6666

6767
declare spir_func i32 @_Z13get_global_idj(i32) #2
6868

69-
attributes #0 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
69+
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
7070
attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
7171
attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
7272
attributes #3 = { nounwind }

test/transcoding/OpImageSampleExplicitLod.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ entry:
4343
; Function Attrs: nounwind
4444
declare spir_func float @_Z11read_imagef20ocl_image2d_depth_ro11ocl_samplerDv2_i(%opencl.image2d_depth_ro_t addrspace(1)*, i32, <2 x i32>) #0
4545

46-
; Function Attrs: nounwind readnone
46+
; Function Attrs: nounwind
4747
declare spir_func i32 @_Z13get_global_idj(i32) #1
4848

4949
; Function Attrs: nounwind
5050
declare spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_depth_ro(%opencl.image2d_depth_ro_t addrspace(1)*) #0
5151

5252
attributes #0 = { nounwind }
53-
attributes #1 = { nounwind readnone }
53+
attributes #1 = { nounwind }
5454

5555
!opencl.enable.FP_CONTRACT = !{}
5656
!opencl.spir.version = !{!6}

test/transcoding/OpSwitch32.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ sw.epilog: ; preds = %entry, %sw.bb1, %sw
7575
ret void
7676
}
7777

78-
; Function Attrs: nounwind readnone
78+
; Function Attrs: nounwind
7979
declare spir_func i64 @_Z13get_global_idj(i32) #1
8080

8181
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
82-
attributes #1 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
83-
attributes #2 = { nounwind readnone }
82+
attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
83+
attributes #2 = { nounwind }
8484

8585
!opencl.enable.FP_CONTRACT = !{}
8686
!opencl.spir.version = !{!6}

test/transcoding/OpSwitch64.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ sw.epilog: ; preds = %entry, %sw.bb3, %sw
8686
ret void
8787
}
8888

89-
; Function Attrs: nounwind readnone
89+
; Function Attrs: nounwind
9090
declare spir_func i64 @_Z13get_global_idj(i32) #1
9191

9292
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
93-
attributes #1 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
94-
attributes #2 = { nounwind readnone }
93+
attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
94+
attributes #2 = { nounwind }
9595

9696
!opencl.enable.FP_CONTRACT = !{}
9797
!opencl.spir.version = !{!6}

test/transcoding/bitcast.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ entry:
2626
ret void
2727
}
2828

29-
; Function Attrs: nounwind readnone
29+
; Function Attrs: nounwind
3030
declare spir_func i64 @_Z13get_global_idj(i32) #1
3131

3232
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
33-
attributes #1 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
34-
attributes #2 = { nounwind readnone }
33+
attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
34+
attributes #2 = { nounwind }
3535

3636
!opencl.enable.FP_CONTRACT = !{}
3737
!opencl.spir.version = !{!6}

test/transcoding/builtin_calls.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ target triple = "spir-unknown-unknown"
1616
; CHECK-SPIRV: Variable {{[0-9]+}} [[Id:[0-9]+]]
1717
; CHECK-SPIRV: Variable {{[0-9]+}} [[Id:[0-9]+]]
1818

19-
; Function Attrs: nounwind readnone
19+
; Function Attrs: nounwind
2020
define spir_kernel void @f() #0 !kernel_arg_addr_space !0 !kernel_arg_access_qual !0 !kernel_arg_type !0 !kernel_arg_base_type !0 !kernel_arg_type_qual !0 {
2121
entry:
2222
%0 = call spir_func i32 @_Z29__spirv_BuiltInGlobalLinearIdv()

test/transcoding/builtin_function_readnone_attr.ll

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
; RUN: llvm-as %s -o %t.bc
22
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
4+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
35
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.bc
46
; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-LLVM
57

8+
; CHECK-SPIRV: Name [[#A:]] "a"
9+
; CHECK-SPIRV: Name [[#B:]] "b"
10+
; CHECK-SPIRV: Decorate [[#A]] FuncParamAttr 5
11+
; CHECK-SPIRV: Decorate [[#A]] FuncParamAttr 6
12+
; CHECK-SPIRV: Decorate [[#B]] FuncParamAttr 7
13+
14+
; CHECK-LLVM: {{.*}}void @test_builtin_readnone(ptr nocapture readonly %{{.*}}, ptr nocapture readnone %{{.*}})
15+
616
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
717
target triple = "spir-unknown-unknown"
818

919
; Function Attrs: convergent nofree norecurse nounwind uwtable
10-
define dso_local spir_kernel void @test_builtin_readnone(double* nocapture readonly %a, double* nocapture %b) local_unnamed_addr #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !5 !kernel_arg_type_qual !6 {
20+
define dso_local spir_kernel void @test_builtin_readnone(double* nocapture readonly %a, double* nocapture readnone %b) local_unnamed_addr #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !5 !kernel_arg_type_qual !6 {
1121
entry:
1222
%0 = load double, double* %a, align 8, !tbaa !7
1323
%call = tail call double @_Z3expd(double %0) #2
@@ -18,18 +28,15 @@ entry:
1828
ret void
1929
}
2030

21-
; Function Attrs: convergent nounwind readnone
22-
; CHECK-LLVM: declare{{.*}}@_Z3expd{{.*}}#[[#Attrs:]]
31+
; Function Attrs: convergent nounwind
2332
declare dso_local double @_Z3expd(double) local_unnamed_addr #1
2433

25-
; Function Attrs: convergent nounwind readnone
26-
; CHECK-LLVM: declare{{.*}}@_Z3cosd{{.*}}#[[#Attrs]]
34+
; Function Attrs: convergent nounwind
2735
declare dso_local double @_Z3cosd(double) local_unnamed_addr #1
2836

2937
attributes #0 = { convergent nofree norecurse nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
30-
; CHECK-LLVM: attributes #[[#Attrs]] {{.*}} readnone
31-
attributes #1 = { convergent nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
32-
attributes #2 = { convergent nounwind readnone }
38+
attributes #1 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
39+
attributes #2 = { convergent nounwind }
3340

3441
!llvm.module.flags = !{!0}
3542
!opencl.ocl.version = !{!1}

test/transcoding/builtin_vars_arithmetics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ entry:
123123

124124
attributes #0 = { norecurse "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="test.cpp" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
125125

126-
; CHECK-LLVM-OCL: attributes #1 = { nounwind readnone willreturn }
126+
; CHECK-LLVM-OCL: attributes #1 = { nounwind willreturn }
127127

128128
!llvm.module.flags = !{!0}
129129
!opencl.spir.version = !{!1}

test/transcoding/isequal.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ entry:
3030
ret void
3131
}
3232

33-
; Function Attrs: nounwind readnone
33+
; Function Attrs: nounwind
3434
declare spir_func i64 @_Z13get_global_idj(i32) #1
3535

36-
; Function Attrs: nounwind readnone
36+
; Function Attrs: nounwind
3737
declare spir_func <8 x i32> @_Z7isequalDv8_fDv8_f(<8 x float>, <8 x float>) #1
3838

3939
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
40-
attributes #1 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
41-
attributes #2 = { nounwind readnone }
40+
attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
41+
attributes #2 = { nounwind }
4242

4343
!opencl.enable.FP_CONTRACT = !{}
4444
!opencl.spir.version = !{!6}

test/transcoding/unreachable.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ define spir_kernel void @unreachable_simple(i32 addrspace(1)* nocapture %in, i32
3030
ret void
3131
}
3232

33-
; Function Attrs: nounwind readnone
33+
; Function Attrs: nounwind
3434
declare spir_func i64 @_Z13get_global_idj(i32) #1
3535

3636
attributes #0 = { nounwind }
37-
attributes #1 = { nounwind readnone }
37+
attributes #1 = { nounwind }
3838

3939
!opencl.enable.FP_CONTRACT = !{}
4040
!spirv.Source = !{!6}

0 commit comments

Comments
 (0)