MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ValidateFunction

Function ValidateFunction

source/val/validate_function.cpp:58–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58spv_result_t ValidateFunction(ValidationState_t& _, const Instruction* inst) {
59 const auto function_type_id = inst->GetOperandAs<uint32_t>(3);
60 const auto function_type = _.FindDef(function_type_id);
61 if (!function_type || spv::Op::OpTypeFunction != function_type->opcode()) {
62 return _.diag(SPV_ERROR_INVALID_ID, inst)
63 << "OpFunction Function Type <id> " << _.getIdName(function_type_id)
64 << " is not a function type.";
65 }
66
67 const auto return_id = function_type->GetOperandAs<uint32_t>(1);
68 if (return_id != inst->type_id()) {
69 return _.diag(SPV_ERROR_INVALID_ID, inst)
70 << "OpFunction Result Type <id> " << _.getIdName(inst->type_id())
71 << " does not match the Function Type's return type <id> "
72 << _.getIdName(return_id) << ".";
73 }
74
75 const std::vector<spv::Op> acceptable = {
76 spv::Op::OpGroupDecorate,
77 spv::Op::OpDecorate,
78 spv::Op::OpEnqueueKernel,
79 spv::Op::OpEntryPoint,
80 spv::Op::OpExecutionMode,
81 spv::Op::OpExecutionModeId,
82 spv::Op::OpFunctionCall,
83 spv::Op::OpGetKernelNDrangeSubGroupCount,
84 spv::Op::OpGetKernelNDrangeMaxSubGroupSize,
85 spv::Op::OpGetKernelWorkGroupSize,
86 spv::Op::OpGetKernelPreferredWorkGroupSizeMultiple,
87 spv::Op::OpGetKernelLocalSizeForSubgroupCount,
88 spv::Op::OpGetKernelMaxNumSubgroups,
89 spv::Op::OpName,
90 spv::Op::OpCooperativeMatrixPerElementOpNV,
91 spv::Op::OpCooperativeMatrixReduceNV,
92 spv::Op::OpCooperativeMatrixLoadTensorNV,
93 spv::Op::OpConditionalEntryPointINTEL,
94 spv::Op::OpConstantFunctionPointerINTEL};
95 for (auto& pair : inst->uses()) {
96 const auto* use = pair.first;
97 if (std::find(acceptable.begin(), acceptable.end(), use->opcode()) ==
98 acceptable.end() &&
99 !use->IsNonSemantic() && !use->IsDebugInfo() &&
100 !spvOpcodeIsDecoration(use->opcode())) {
101 return _.diag(SPV_ERROR_INVALID_ID, use)
102 << "Invalid use of function result id " << _.getIdName(inst->id())
103 << ".";
104 }
105 }
106
107 return SPV_SUCCESS;
108}
109
110spv_result_t ValidateFunctionParameter(ValidationState_t& _,
111 const Instruction* inst) {

Callers 1

FunctionPassFunction · 0.85

Calls 12

findFunction · 0.85
spvOpcodeIsDecorationFunction · 0.85
FindDefMethod · 0.80
diagMethod · 0.80
getIdNameMethod · 0.80
IsNonSemanticMethod · 0.80
IsDebugInfoMethod · 0.80
opcodeMethod · 0.45
type_idMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected