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()

0 commit comments

Comments
 (0)