Skip to content

[SPIRV] FIX print the symbolic operand for opcode for the operation OpSpecConstantOp #135756

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

Merged
merged 4 commits into from
Jun 11, 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
3 changes: 2 additions & 1 deletion llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category,
Category != SPIRV::OperandCategory::FunctionControlOperand &&
Category != SPIRV::OperandCategory::MemorySemanticsOperand &&
Category != SPIRV::OperandCategory::MemoryOperandOperand &&
Category != SPIRV::OperandCategory::KernelProfilingInfoOperand)
Category != SPIRV::OperandCategory::KernelProfilingInfoOperand &&
Category != SPIRV::OperandCategory::SpecConstantOpOperandsOperand)
return "UNKNOWN";
// Value that encodes many enum values (one bit per enum value).
std::string Name;
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ namespace CooperativeMatrixOperands {
#include "SPIRVGenTables.inc"
} // namespace CooperativeMatrixOperands

namespace SpecConstantOpOperands {
#define GET_SpecConstantOpOperands_DECL
#include "SPIRVGenTables.inc"
} // namespace SpecConstantOpOperands

struct ExtendedBuiltin {
StringRef Name;
InstructionSet::InstructionSet Set;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/SPIRV/SPIRVInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def OpSpecConstantComposite: Op<51, (outs ID:$res), (ins TYPE:$type, variable_op
"$res = OpSpecConstantComposite $type">;
def OpSpecConstantCompositeContinuedINTEL: Op<6092, (outs), (ins variable_ops),
"OpSpecConstantCompositeContinuedINTEL">;
def OpSpecConstantOp: Op<52, (outs ID:$res), (ins TYPE:$t, i32imm:$c, ID:$o, variable_ops),
def OpSpecConstantOp: Op<52, (outs ID:$res), (ins TYPE:$t, SpecConstantOpOperands:$c, ID:$o, variable_ops),
"$res = OpSpecConstantOp $t $c $o">;

// 3.42.8 Memory Instructions
Expand Down
90 changes: 90 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def KernelProfilingInfoOperand : OperandCategory;
def OpcodeOperand : OperandCategory;
def CooperativeMatrixLayoutOperand : OperandCategory;
def CooperativeMatrixOperandsOperand : OperandCategory;
def SpecConstantOpOperandsOperand : OperandCategory;
def MatrixMultiplyAccumulateOperandsOperand : OperandCategory;

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -1755,6 +1756,95 @@ defm MatrixAAndBBFloat16ComponentsINTEL : CooperativeMatrixOperandsOperand<0x40,
defm MatrixCBFloat16ComponentsINTEL : CooperativeMatrixOperandsOperand<0x80, [SPV_INTEL_joint_matrix], [CooperativeMatrixBFloat16ComponentTypeINTEL]>;
defm MatrixResultBFloat16ComponentsINTEL : CooperativeMatrixOperandsOperand<0x100, [SPV_INTEL_joint_matrix], [CooperativeMatrixBFloat16ComponentTypeINTEL]>;

//===----------------------------------------------------------------------===//
// Multiclass used to define SpecConstant Operands enum values and at the
// same time SymbolicOperand.
//===----------------------------------------------------------------------===//

def SpecConstantOpOperands : GenericEnum, Operand<i32> {
let FilterClass = "SpecConstantOpOperands";
let NameField = "Name";
let ValueField = "Value";
let PrintMethod = !strconcat("printSymbolicOperand<OperandCategory::", FilterClass, "Operand>");
}

class SpecConstantOpOperands<string name, bits<32> value> {
string Name = name;
bits<32> Value = value;
}

multiclass SpecConstantOpOperandsOperand<bits<32> value, list<Extension> reqExtensions, list<Capability> reqCapabilities> {
def : SpecConstantOpOperands<NAME, value>;
defm : SymbolicOperandWithRequirements<SpecConstantOpOperandsOperand, value, NAME, 0, 0, reqExtensions, reqCapabilities>;
}

// Conversion
defm SConvert : SpecConstantOpOperandsOperand<114, [], []>;
defm FConvert : SpecConstantOpOperandsOperand<115, [], []>;
defm ConvertFToS : SpecConstantOpOperandsOperand<110, [], [Kernel]>;
defm ConvertSToF : SpecConstantOpOperandsOperand<111, [], [Kernel]>;
defm ConvertFToU : SpecConstantOpOperandsOperand<109, [], [Kernel]>;
defm ConvertUToF : SpecConstantOpOperandsOperand<112, [], [Kernel]>;
defm UConvert : SpecConstantOpOperandsOperand<113, [], [Kernel]>;
defm ConvertPtrToU : SpecConstantOpOperandsOperand<117, [], [Kernel]>;
defm ConvertUToPtr : SpecConstantOpOperandsOperand<120, [], [Kernel]>;
defm GenericCastToPtr : SpecConstantOpOperandsOperand<122, [], [Kernel]>;
defm PtrCastToGeneric : SpecConstantOpOperandsOperand<121, [], [Kernel]>;
defm Bitcast : SpecConstantOpOperandsOperand<124, [], []>;
defm QuantizeToF16 : SpecConstantOpOperandsOperand<116, [], [Shader]>;
// Arithmetic
defm SNegate : SpecConstantOpOperandsOperand<126, [], []>;
defm Not : SpecConstantOpOperandsOperand<200, [], []>;
defm IAdd : SpecConstantOpOperandsOperand<128, [], []>;
defm ISub : SpecConstantOpOperandsOperand<130, [], []>;
defm IMul : SpecConstantOpOperandsOperand<132, [], []>;
defm UDiv : SpecConstantOpOperandsOperand<134, [], []>;
defm SDiv : SpecConstantOpOperandsOperand<135, [], []>;
defm UMod : SpecConstantOpOperandsOperand<137, [], []>;
defm SRem : SpecConstantOpOperandsOperand<138, [], []>;
defm SMod : SpecConstantOpOperandsOperand<139, [], []>;
defm ShiftRightLogical : SpecConstantOpOperandsOperand<194, [], []>;
defm ShiftRightArithmetic : SpecConstantOpOperandsOperand<195, [], []>;
defm ShiftLeftLogical : SpecConstantOpOperandsOperand<196, [], []>;
defm BitwiseOr : SpecConstantOpOperandsOperand<197, [], []>;
defm BitwiseAnd : SpecConstantOpOperandsOperand<199, [], []>;
defm BitwiseXor : SpecConstantOpOperandsOperand<198, [], []>;
defm FNegate : SpecConstantOpOperandsOperand<127, [], [Kernel]>;
defm FAdd : SpecConstantOpOperandsOperand<129, [], [Kernel]>;
defm FSub : SpecConstantOpOperandsOperand<131, [], [Kernel]>;
defm FMul : SpecConstantOpOperandsOperand<133, [], [Kernel]>;
defm FDiv : SpecConstantOpOperandsOperand<136, [], [Kernel]>;
defm FRem : SpecConstantOpOperandsOperand<140, [], [Kernel]>;
defm FMod : SpecConstantOpOperandsOperand<141, [], [Kernel]>;
// Composite;
defm VectorShuffle : SpecConstantOpOperandsOperand<79, [], []>;
defm CompositeExtract : SpecConstantOpOperandsOperand<81, [], []>;
defm CompositeInsert : SpecConstantOpOperandsOperand<82, [], []>;
// Logical;
defm LogicalOr : SpecConstantOpOperandsOperand<166, [], []>;
defm LogicalAnd : SpecConstantOpOperandsOperand<167, [], []>;
defm LogicalNot : SpecConstantOpOperandsOperand<168, [], []>;
defm LogicalEqual : SpecConstantOpOperandsOperand<164, [], []>;
defm LogicalNotEqual : SpecConstantOpOperandsOperand<165, [], []>;
defm Select : SpecConstantOpOperandsOperand<169, [], []>;
// Comparison;
defm IEqual : SpecConstantOpOperandsOperand<170, [], []>;
defm INotEqual : SpecConstantOpOperandsOperand<171, [], []>;
defm ULessThan : SpecConstantOpOperandsOperand<176, [], []>;
defm SLessThan : SpecConstantOpOperandsOperand<177, [], []>;
defm UGreaterThan : SpecConstantOpOperandsOperand<172, [], []>;
defm SGreaterThan : SpecConstantOpOperandsOperand<173, [], []>;
defm ULessThanEqual : SpecConstantOpOperandsOperand<178, [], []>;
defm SLessThanEqual : SpecConstantOpOperandsOperand<179, [], []>;
defm UGreaterThanEqual : SpecConstantOpOperandsOperand<174, [], []>;
defm SGreaterThanEqual : SpecConstantOpOperandsOperand<175, [], []>;
// Memory
defm AccessChain : SpecConstantOpOperandsOperand<65, [], [Kernel]>;
defm InBoundsAccessChain : SpecConstantOpOperandsOperand<66, [], [Kernel]>;
defm PtrAccessChain : SpecConstantOpOperandsOperand<67, [], [Kernel]>;
defm InBoundsPtrAccessChain : SpecConstantOpOperandsOperand<70, [], [Kernel]>;
defm CooperativeMatrixLengthKHR : SpecConstantOpOperandsOperand<4460, [], []>;

//===----------------------------------------------------------------------===//
// Multiclass used to define Matrix Multiply Accumulate Operands enum values and at the same time
// SymbolicOperand entries with string mnemonics and capabilities.
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/SPIRV/const-nested-vecs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
; CHECK-SPIRV-DAG: %[[#IntZero:]] = OpConstantNull %[[#IntTy]]
; CHECK-SPIRV-DAG: %[[#LongZero:]] = OpConstantNull %[[#LongTy]]
; CHECK-SPIRV64-DAG: %[[#ConstLong2:]] = OpConstant %[[#LongTy]] 2
; CHECK-SPIRV64-DAG: %[[#PvarInit:]] = OpSpecConstantOp %[[#PtrCharTy]] 70 %[[#VarV2Char:]] %[[#IntZero]] %[[#ConstLong2]]
; CHECK-SPIRV32-DAG: %[[#PvarInit:]] = OpSpecConstantOp %[[#PtrCharTy]] 70 %[[#VarV2Char:]] %[[#IntZero]] %[[#Const2]]
; CHECK-SPIRV64-DAG: %[[#PvarInit:]] = OpSpecConstantOp %[[#PtrCharTy]] InBoundsPtrAccessChain %[[#VarV2Char:]] %[[#IntZero]] %[[#ConstLong2]]
; CHECK-SPIRV32-DAG: %[[#PvarInit:]] = OpSpecConstantOp %[[#PtrCharTy]] InBoundsPtrAccessChain %[[#VarV2Char:]] %[[#IntZero]] %[[#Const2]]
; CHECK-SPIRV-DAG: %[[#PtrPtrCharTy:]] = OpTypePointer CrossWorkgroup %[[#PtrCharTy]]
; CHECK-SPIRV-DAG: %[[#AVar]] = OpVariable %[[#PtrArr2V2CharTy]] CrossWorkgroup %[[#Arr2V2Char]]
; CHECK-SPIRV-DAG: %[[#PVar]] = OpVariable %[[#PtrPtrCharTy]] CrossWorkgroup %[[#PvarInit]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - --spirv-ext=+SPV_INTEL_function_pointers | FileCheck %s
; TODO: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK-COUNT-3: %[[#]] = OpSpecConstantOp %[[#]] 121 %[[#]]
; CHECK-COUNT-3: %[[#]] = OpSpecConstantOp %[[#]] PtrCastToGeneric %[[#]]
; CHECK-COUNT-3: OpPtrCastToGeneric

@G1 = addrspace(1) constant { [3 x ptr addrspace(4)] } { [3 x ptr addrspace(4)] [ptr addrspace(4) null, ptr addrspace(4) addrspacecast (ptr @foo to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr @bar to ptr addrspace(4))] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
; CHECK-DAG: %[[#pt2:]] = OpTypePointer CrossWorkgroup %[[#arr2]]
; CHECK-DAG: %[[#pt3:]] = OpTypePointer CrossWorkgroup %[[#pt1]]
; CHECK-DAG: %[[#a_var]] = OpVariable %[[#pt2]] CrossWorkgroup
; CHECK-DAG: %[[#const:]] = OpSpecConstantOp %[[#pt1]] 70 %[[#a_var]]
; CHECK-DAG: %[[#const:]] = OpSpecConstantOp %[[#pt1]] InBoundsPtrAccessChain %[[#a_var]]
; CHECK-DAG: %[[#p_var]] = OpVariable %[[#pt3]] CrossWorkgroup %[[#const]]
@var = addrspace(1) global i8 0, align 1
@g_var = addrspace(1) global i8 1, align 1
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/SPIRV/opt-gepoperator-of-gvar.ll
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
; CHECK-DAG: %[[#PtrStruct:]] = OpTypePointer CrossWorkgroup %[[#Struct]]
; CHECK-DAG: %[[#Var:]] = OpVariable %[[#PtrStruct]] CrossWorkgroup %[[#VarInit]]
; CHECK-DAG: %[[#Bytes:]] = OpVariable %[[#PtrChar]] CrossWorkgroup %[[#]]
; CHECK-DAG: %[[#BytesGEP:]] = OpSpecConstantOp %[[#PtrChar]] 70 %[[#Bytes]] %[[#C648]]
; CHECK-DAG: %[[#BytesGEP:]] = OpSpecConstantOp %[[#PtrChar]] InBoundsPtrAccessChain %[[#Bytes]] %[[#C648]]

; CHECK: OpFunction
; CHECK: %[[#]] = OpFunctionParameter %[[#]]
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/SPIRV/pointers/PtrCast-in-OpSpecConstantOp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
; CHECK-DAG: %[[WPtr:.*]] = OpTypePointer Workgroup %[[Int]]

; CHECK-DAG: %[[F]] = OpVariable %[[CWPtr]] CrossWorkgroup %[[#]]
; CHECK-DAG: %[[GenF:.*]] = OpSpecConstantOp %[[GenPtrChar]] 121 %[[F]]
; CHECK-DAG: %[[GenF:.*]] = OpSpecConstantOp %[[GenPtrChar]] PtrCastToGeneric %[[F]]
; CHECK-DAG: %[[B]] = OpVariable %[[CWPtr]] CrossWorkgroup %[[#]]
; CHECK-DAG: %[[GenB:.*]] = OpSpecConstantOp %[[GenPtrChar]] 121 %[[B]]
; CHECK-DAG: %[[GenB:.*]] = OpSpecConstantOp %[[GenPtrChar]] PtrCastToGeneric %[[B]]
; CHECK-DAG: %[[GenFB:.*]] = OpConstantComposite %[[Arr2]] %[[GenF]] %[[GenB]]
; CHECK-DAG: %[[GenBF:.*]] = OpConstantComposite %[[Arr2]] %[[GenB]] %[[GenF]]
; CHECK-DAG: %[[CG1:.*]] = OpConstantComposite %[[Struct2]] %[[GenFB]]
; CHECK-DAG: %[[CG2:.*]] = OpConstantComposite %[[Struct2]] %[[GenBF]]

; CHECK-DAG: %[[X]] = OpVariable %[[WPtr]] Workgroup %[[#]]
; CHECK-DAG: %[[GenX:.*]] = OpSpecConstantOp %[[GenPtr]] 121 %[[X]]
; CHECK-DAG: %[[CWX:.*]] = OpSpecConstantOp %[[CWPtrChar]] 122 %[[GenX]]
; CHECK-DAG: %[[GenX:.*]] = OpSpecConstantOp %[[GenPtr]] PtrCastToGeneric %[[X]]
; CHECK-DAG: %[[CWX:.*]] = OpSpecConstantOp %[[CWPtrChar]] GenericCastToPtr %[[GenX]]
; CHECK-DAG: %[[Y]] = OpVariable %[[WPtr]] Workgroup %[[#]]
; CHECK-DAG: %[[GenY:.*]] = OpSpecConstantOp %[[GenPtr]] 121 %[[Y]]
; CHECK-DAG: %[[CWY:.*]] = OpSpecConstantOp %[[CWPtrChar]] 122 %[[GenY]]
; CHECK-DAG: %[[GenY:.*]] = OpSpecConstantOp %[[GenPtr]] PtrCastToGeneric %[[Y]]
; CHECK-DAG: %[[CWY:.*]] = OpSpecConstantOp %[[CWPtrChar]] GenericCastToPtr %[[GenY]]
; CHECK-DAG: %[[CWXY:.*]] = OpConstantComposite %[[Arr1]] %[[CWX]] %[[CWY]]
; CHECK-DAG: %[[CWYX:.*]] = OpConstantComposite %[[Arr1]] %[[CWY]] %[[CWX]]
; CHECK-DAG: %[[CG3:.*]] = OpConstantComposite %[[Struct1]] %[[CWXY]]
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/SPIRV/pointers/global-ptrtoint.ll
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
; CHECK-DAG: %[[TyStruct:.*]] = OpTypeStruct %[[TyI64]] %[[TyI64]]
; CHECK-DAG: %[[Const128:.*]] = OpConstant %[[TyI64]] 128
; CHECK-DAG: %[[GlobalValue]] = OpVariable
; CHECK-DAG: %[[PtrToInt:.*]] = OpSpecConstantOp %[[TyI64]] 117 %[[GlobalValue]]
; CHECK-DAG: %[[PtrToInt:.*]] = OpSpecConstantOp %[[TyI64]] ConvertPtrToU %[[GlobalValue]]
; TODO: The following bitcast line looks unneeded and we may expect it to be removed in future
; CHECK-DAG: %[[UseGlobalValue:.*]] = OpSpecConstantOp %[[TyI64]] 124 %[[PtrToInt]]
; CHECK-DAG: %[[UseGlobalValue:.*]] = OpSpecConstantOp %[[TyI64]] Bitcast %[[PtrToInt]]
; CHECK-DAG: %[[ConstComposite:.*]] = OpConstantComposite %[[TyStruct]] %[[Const128]] %[[UseGlobalValue]]
; CHECK-DAG: %[[TyPtrStruct:.*]] = OpTypePointer CrossWorkgroup %[[TyStruct]]
; CHECK: OpVariable %[[TyPtrStruct]] CrossWorkgroup %[[ConstComposite]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
; CHECK-SPIRV64-DAG: %[[#IntTy:]] = OpTypeInt 64 0
; CHECK-SPIRV32-DAG: %[[#IntTy:]] = OpTypeInt 32 0
; CHECK-SPIRV-DAG: %[[#Const2:]] = OpConstant %[[#IntTy]] 2
; CHECK-SPIRV-DAG: %[[#]] = OpSpecConstantOp %[[#]] 70 %[[#]] %[[#]] %[[#Const2]]
; CHECK-SPIRV-DAG: %[[#]] = OpSpecConstantOp %[[#]] InBoundsPtrAccessChain %[[#]] %[[#]] %[[#Const2]]
; CHECK-SPIRV: OpFunction

@a_var = addrspace(1) global [2 x i8] [i8 1, i8 1]
Expand Down
Loading