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

Function IsVariablePointer

source/val/validate_logical_pointers.cpp:45–113  ·  view source on GitHub ↗

Returns true if inst is a variable pointer. Caches the result in variable_pointers.

Source from the content-addressed store, hash-verified

43// Returns true if inst is a variable pointer.
44// Caches the result in variable_pointers.
45bool IsVariablePointer(const ValidationState_t& _,
46 std::unordered_map<uint32_t, bool>& variable_pointers,
47 const Instruction* inst) {
48 const auto iter = variable_pointers.find(inst->id());
49 if (iter != variable_pointers.end()) {
50 return iter->second;
51 }
52
53 // Temporarily mark the instruction as NOT a variable pointer.
54 variable_pointers[inst->id()] = false;
55
56 bool is_var_ptr = false;
57 switch (inst->opcode()) {
58 case spv::Op::OpPtrAccessChain:
59 case spv::Op::OpUntypedPtrAccessChainKHR:
60 case spv::Op::OpUntypedInBoundsPtrAccessChainKHR:
61 case spv::Op::OpLoad:
62 case spv::Op::OpSelect:
63 case spv::Op::OpPhi:
64 case spv::Op::OpFunctionCall:
65 case spv::Op::OpConstantNull:
66 is_var_ptr = true;
67 break;
68 case spv::Op::OpFunctionParameter:
69 // Special case: skip to function calls.
70 if (IsLogicalPointer(_, inst)) {
71 auto func = inst->function();
72 auto func_inst = _.FindDef(func->id());
73
74 const auto param_inst_num = inst - &_.ordered_instructions()[0];
75 uint32_t param_index = 0;
76 uint32_t inst_index = 1;
77 while (_.ordered_instructions()[param_inst_num - inst_index].opcode() !=
78 spv::Op::OpFunction) {
79 if (_.ordered_instructions()[param_inst_num - inst_index].opcode() ==
80 spv::Op::OpFunctionParameter) {
81 param_index++;
82 }
83 ++inst_index;
84 }
85
86 for (const auto& use_pair : func_inst->uses()) {
87 const auto use_inst = use_pair.first;
88 if (use_inst->opcode() == spv::Op::OpFunctionCall) {
89 const auto arg_id =
90 use_inst->GetOperandAs<uint32_t>(3 + param_index);
91 const auto arg_inst = _.FindDef(arg_id);
92 is_var_ptr |= IsVariablePointer(_, variable_pointers, arg_inst);
93 }
94 }
95 }
96 break;
97 default: {
98 for (uint32_t i = 0; i < inst->operands().size(); ++i) {
99 if (inst->operands()[i].type != SPV_OPERAND_TYPE_ID) {
100 continue;
101 }
102

Callers 2

ValidateVariablePointersFunction · 0.85
ValidateLogicalPointersFunction · 0.85

Calls 8

IsLogicalPointerFunction · 0.85
FindDefMethod · 0.80
operandsMethod · 0.80
idMethod · 0.45
endMethod · 0.45
opcodeMethod · 0.45
functionMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected