Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for SPV_EXT_optnone #2951

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/LLVMSPIRVExtensions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ EXT(SPV_INTEL_fpga_cluster_attributes)
EXT(SPV_INTEL_loop_fuse)
EXT(SPV_INTEL_long_constant_composite) // TODO: rename to
// SPV_INTEL_long_composites later
EXT(SPV_EXT_optnone)
EXT(SPV_INTEL_optnone)
EXT(SPV_INTEL_fpga_dsp_control)
EXT(SPV_INTEL_memory_access_aliasing)
Expand Down
2 changes: 1 addition & 1 deletion lib/SPIRV/SPIRVInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ inline void
SPIRVMap<Attribute::AttrKind, SPIRVFunctionControlMaskKind>::init() {
add(Attribute::AlwaysInline, FunctionControlInlineMask);
add(Attribute::NoInline, FunctionControlDontInlineMask);
add(Attribute::OptimizeNone, internal::FunctionControlOptNoneINTELMask);
add(Attribute::OptimizeNone, FunctionControlOptNoneEXTMask);
}
typedef SPIRVMap<Attribute::AttrKind, SPIRVFunctionControlMaskKind>
SPIRSPIRVFuncCtlMaskMap;
Expand Down
12 changes: 9 additions & 3 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5538,10 +5538,15 @@ SPIRVWord LLVMToSPIRVBase::transFunctionControlMask(Function *F) {
[&](Attribute::AttrKind Attr, SPIRVFunctionControlMaskKind Mask) {
if (F->hasFnAttribute(Attr)) {
if (Attr == Attribute::OptimizeNone) {
if (!BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_optnone))
if (BM->isAllowedToUseExtension(ExtensionID::SPV_EXT_optnone)) {
BM->addExtension(ExtensionID::SPV_EXT_optnone);
BM->addCapability(CapabilityOptNoneEXT);
} else if (BM->isAllowedToUseExtension(
ExtensionID::SPV_INTEL_optnone)) {
BM->addExtension(ExtensionID::SPV_INTEL_optnone);
BM->addCapability(CapabilityOptNoneINTEL);
} else
return;
BM->addExtension(ExtensionID::SPV_INTEL_optnone);
BM->addCapability(internal::CapabilityOptNoneINTEL);
}
FCM |= Mask;
}
Expand Down Expand Up @@ -7031,6 +7036,7 @@ bool runSpirvBackend(Module *M, std::string &Result, std::string &ErrMsg,
SPIRV::ExtensionID::SPV_INTEL_cache_controls,
SPIRV::ExtensionID::SPV_INTEL_global_variable_fpga_decorations,
SPIRV::ExtensionID::SPV_INTEL_global_variable_host_access,
SPIRV::ExtensionID::SPV_EXT_optnone,
SPIRV::ExtensionID::SPV_INTEL_optnone,
SPIRV::ExtensionID::SPV_INTEL_usm_storage_classes,
SPIRV::ExtensionID::SPV_INTEL_subgroups,
Expand Down
2 changes: 1 addition & 1 deletion lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ inline bool isValidFunctionControlMask(SPIRVWord Mask) {
ValidMask |= FunctionControlDontInlineMask;
ValidMask |= FunctionControlPureMask;
ValidMask |= FunctionControlConstMask;
ValidMask |= internal::FunctionControlOptNoneINTELMask;
ValidMask |= FunctionControlOptNoneEXTMask;

return (Mask & ~ValidMask) == 0;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
add(CapabilityAtomicFloat32AddEXT, "AtomicFloat32AddEXT");
add(CapabilityAtomicFloat64AddEXT, "AtomicFloat64AddEXT");
add(CapabilityLongCompositesINTEL, "LongCompositesINTEL");
add(CapabilityOptNoneINTEL, "OptNoneINTEL");
add(CapabilityOptNoneEXT, "OptNoneEXT");
add(CapabilityAtomicFloat16AddEXT, "AtomicFloat16AddEXT");
add(CapabilityDebugInfoModuleINTEL, "DebugInfoModuleINTEL");
add(CapabilitySplitBarrierINTEL, "SplitBarrierINTEL");
Expand All @@ -642,7 +642,6 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
add(CapabilityRegisterLimitsINTEL, "RegisterLimitsINTEL");
// From spirv_internal.hpp
add(internal::CapabilityFastCompositeINTEL, "FastCompositeINTEL");
add(internal::CapabilityOptNoneINTEL, "OptNoneINTEL");
add(internal::CapabilityTokenTypeINTEL, "TokenTypeINTEL");
add(internal::CapabilityFPArithmeticFenceINTEL, "FPArithmeticFenceINTEL");
add(internal::CapabilityBfloat16ConversionINTEL, "Bfloat16ConversionINTEL");
Expand Down
8 changes: 0 additions & 8 deletions lib/SPIRV/libSPIRV/spirv_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ enum InternalDecoration {

enum InternalCapability {
ICapFastCompositeINTEL = 6093,
ICapOptNoneINTEL = 6094,
ICapTokenTypeINTEL = 6112,
ICapBfloat16ConversionINTEL = 6115,
ICapabilityJointMatrixINTEL = 6118,
Expand All @@ -132,8 +131,6 @@ enum InternalCapability {
ICapabilityBindlessImagesINTEL = 6528
};

enum InternalFunctionControlMask { IFunctionControlOptNoneINTELMask = 0x10000 };

enum InternalExecutionMode {
IExecModeFastCompositeKernelINTEL = 6088,
IExecModeNamedSubgroupSizeINTEL = 6446,
Expand Down Expand Up @@ -291,8 +288,6 @@ constexpr Decoration DecorationArgumentAttributeINTEL =

constexpr Capability CapabilityFastCompositeINTEL =
static_cast<Capability>(ICapFastCompositeINTEL);
constexpr Capability CapabilityOptNoneINTEL =
static_cast<Capability>(ICapOptNoneINTEL);
constexpr Capability CapabilityTokenTypeINTEL =
static_cast<Capability>(ICapTokenTypeINTEL);
constexpr Capability CapabilityFPArithmeticFenceINTEL =
Expand All @@ -302,9 +297,6 @@ constexpr Capability CapabilityBfloat16ConversionINTEL =
constexpr Capability CapabilityGlobalVariableDecorationsINTEL =
static_cast<Capability>(ICapGlobalVariableDecorationsINTEL);

constexpr FunctionControlMask FunctionControlOptNoneINTELMask =
static_cast<FunctionControlMask>(IFunctionControlOptNoneINTELMask);

constexpr ExecutionMode ExecutionModeFastCompositeKernelINTEL =
static_cast<ExecutionMode>(IExecModeFastCompositeKernelINTEL);

Expand Down
2 changes: 1 addition & 1 deletion spirv-headers-tag.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
efb6b4099ddb8fa60f62956dee592c4b94ec6a49
3f17b2af6784bfa2c5aa5dbb8e0e74a607dd8b3b
36 changes: 24 additions & 12 deletions test/optnone.ll
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_optnone -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_EXT_optnone -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-EXT
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_optnone -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-INTEL
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_EXT_optnone,+SPV_INTEL_optnone -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-BOTH

; RUN: llvm-spirv --spirv-ext=+SPV_INTEL_optnone %t.bc -o %t.spv

; RUN: llvm-spirv --spirv-ext=+SPV_EXT_optnone %t.bc -o %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM

; Check that optnone is correctly ignored when extension is not enabled
; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-NO-EXT
; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-NONE

; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-NO-EXT
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-NONE

; Note: The capability is unconditionally printed with the EXT suffix.
; CHECK-SPIRV-EXT: Capability OptNoneEXT
; CHECK-SPIRV-INTEL: Capability OptNoneEXT
; CHECK-SPIRV-BOTH: Capability OptNoneEXT

; CHECK-SPIRV: Capability OptNoneINTEL
; CHECK-SPIRV: Extension "SPV_INTEL_optnone"
; CHECK-SPIRV-EXT: Extension "SPV_EXT_optnone"
; CHECK-SPIRV-INTEL: Extension "SPV_INTEL_optnone"
; Note: When both extensions are enabled, prefer the EXT extension.
; CHECK-SPIRV-BOTH: Extension "SPV_EXT_optnone"

; Per SPIR-V spec:
; FunctionControlDontInlineMask = 0x2 (2)
; Per SPIR-V spec extension SPV_INTEL_optnone:
; FunctionControlOptNoneINTELMask = 0x10000 (65536)
; CHECK-SPIRV: Function {{[0-9]+}} {{[0-9]+}} 65538
; CHECK-SPIRV-NO-EXT: Function {{[0-9]+}} {{[0-9]+}} 2
; Per SPIR-V spec extension spec:
; FunctionControlOptNoneMask = 0x10000 (65536)
; CHECK-SPIRV-EXT: Function {{[0-9]+}} {{[0-9]+}} 65538
; CHECK-SPIRV-INTEL: Function {{[0-9]+}} {{[0-9]+}} 65538
; CHECK-SPIRV-BOTH: Function {{[0-9]+}} {{[0-9]+}} 65538
; CHECK-SPIRV-NONE: Function {{[0-9]+}} {{[0-9]+}} 2

; CHECK-LLVM: define spir_func void @_Z3foov() #[[ATTR:[0-9]+]]
; CHECK-LLVM: #[[ATTR]] = { {{.*}}noinline{{.*}}optnone{{.*}} }

; CHECK-LLVM-NO-EXT: define spir_func void @_Z3foov() #[[ATTR:[0-9]+]]
; CHECK-LLVM-NO-EXT-NOT: #[[ATTR]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
; CHECK-LLVM-NONE: define spir_func void @_Z3foov() #[[ATTR:[0-9]+]]
; CHECK-LLVM-NONE-NOT: #[[ATTR]] = { {{.*}}noinline{{.*}}optnone{{.*}} }

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir-unknown-unknown"
Expand Down
Loading