[llvm] b0020f4 - [SPIR-V] Support memory(...) function attributes
Michal Paszkowski via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 19 10:41:01 PST 2022
Author: Michal Paszkowski
Date: 2022-12-19T19:36:32+01:00
New Revision: b0020f423feb922c35802af96234c5d21b8d3f51
URL: https://github.com/llvm/llvm-project/commit/b0020f423feb922c35802af96234c5d21b8d3f51
DIFF: https://github.com/llvm/llvm-project/commit/b0020f423feb922c35802af96234c5d21b8d3f51.diff
LOG: [SPIR-V] Support memory(...) function attributes
Adds support for memory(...) function attributes in SPIR-V function
control info lowering.
Differential Revision: https://reviews.llvm.org/D139133
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
llvm/test/CodeGen/SPIRV/function/trivial-function-with-attributes.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
index 9cd32cc373952..8b618686ee7da 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
@@ -21,6 +21,7 @@
#include "SPIRVSubtarget.h"
#include "SPIRVUtils.h"
#include "llvm/CodeGen/FunctionLoweringInfo.h"
+#include "llvm/Support/ModRef.h"
using namespace llvm;
@@ -49,19 +50,20 @@ bool SPIRVCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
// Based on the LLVM function attributes, get a SPIR-V FunctionControl.
static uint32_t getFunctionControl(const Function &F) {
+ MemoryEffects MemEffects = F.getMemoryEffects();
+
uint32_t FuncControl = static_cast<uint32_t>(SPIRV::FunctionControl::None);
- if (F.hasFnAttribute(Attribute::AttrKind::AlwaysInline)) {
+
+ if (F.hasFnAttribute(Attribute::AttrKind::NoInline))
+ FuncControl |= static_cast<uint32_t>(SPIRV::FunctionControl::DontInline);
+ else if (F.hasFnAttribute(Attribute::AttrKind::AlwaysInline))
FuncControl |= static_cast<uint32_t>(SPIRV::FunctionControl::Inline);
- }
- if (F.hasFnAttribute(Attribute::AttrKind::ReadNone)) {
+
+ if (MemEffects.doesNotAccessMemory())
FuncControl |= static_cast<uint32_t>(SPIRV::FunctionControl::Pure);
- }
- if (F.hasFnAttribute(Attribute::AttrKind::ReadOnly)) {
+ else if (MemEffects.onlyReadsMemory())
FuncControl |= static_cast<uint32_t>(SPIRV::FunctionControl::Const);
- }
- if (F.hasFnAttribute(Attribute::AttrKind::NoInline)) {
- FuncControl |= static_cast<uint32_t>(SPIRV::FunctionControl::DontInline);
- }
+
return FuncControl;
}
diff --git a/llvm/test/CodeGen/SPIRV/function/trivial-function-with-attributes.ll b/llvm/test/CodeGen/SPIRV/function/trivial-function-with-attributes.ll
index 568cb40a97e22..6c11993bc6dcc 100644
--- a/llvm/test/CodeGen/SPIRV/function/trivial-function-with-attributes.ll
+++ b/llvm/test/CodeGen/SPIRV/function/trivial-function-with-attributes.ll
@@ -10,6 +10,8 @@
; CHECK-DAG: OpName %[[#FN5:]] "fn5"
; CHECK-DAG: OpName %[[#FN6:]] "fn6"
; CHECK-DAG: OpName %[[#FN7:]] "fn7"
+; CHECK-DAG: OpName %[[#FN8:]] "fn8"
+; CHECK-DAG: OpName %[[#FN9:]] "fn9"
;; Types:
; CHECK: %[[#VOID:]] = OpTypeVoid
@@ -56,15 +58,29 @@ define void @fn5() readnone {
; CHECK: OpFunctionEnd
-define void @fn6() readonly {
+define void @fn6() memory(none) {
ret void
}
-; CHECK: %[[#FN6]] = OpFunction %[[#VOID]] Const %[[#FN]]
+; CHECK: %[[#FN6]] = OpFunction %[[#VOID]] Pure %[[#FN]]
; CHECK: OpFunctionEnd
-define void @fn7() alwaysinline readnone {
+define void @fn7() readonly {
ret void
}
-; CHECK: %[[#FN7]] = OpFunction %[[#VOID]] Inline|Pure %[[#FN]]
+; CHECK: %[[#FN7]] = OpFunction %[[#VOID]] Const %[[#FN]]
+; CHECK: OpFunctionEnd
+
+
+define void @fn8() memory(read) {
+ ret void
+}
+; CHECK: %[[#FN8]] = OpFunction %[[#VOID]] Const %[[#FN]]
+; CHECK: OpFunctionEnd
+
+
+define void @fn9() alwaysinline readnone {
+ ret void
+}
+; CHECK: %[[#FN9]] = OpFunction %[[#VOID]] Inline|Pure %[[#FN]]
; CHECK: OpFunctionEnd
More information about the llvm-commits
mailing list