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

Function FindOrCreateFunctionVariable

source/reduce/reduction_util.cpp:49–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49uint32_t FindOrCreateFunctionVariable(opt::IRContext* context,
50 opt::Function* function,
51 uint32_t pointer_type_id) {
52 // The pointer type of a function variable must have Function storage class.
53 assert(context->get_type_mgr()
54 ->GetType(pointer_type_id)
55 ->AsPointer()
56 ->storage_class() == spv::StorageClass::Function);
57
58 // Go through the instructions in the function's first block until we find a
59 // suitable variable, or go past all the variables.
60 opt::BasicBlock::iterator iter = function->begin()->begin();
61 for (;; ++iter) {
62 // We will either find a suitable variable, or find a non-variable
63 // instruction; we won't exhaust all instructions.
64 assert(iter != function->begin()->end());
65 if (iter->opcode() != spv::Op::OpVariable) {
66 // If we see a non-variable, we have gone through all the variables.
67 break;
68 }
69 if (iter->type_id() == pointer_type_id) {
70 return iter->result_id();
71 }
72 }
73 // At this point, iter refers to the first non-function instruction of the
74 // function's entry block.
75 const uint32_t variable_id = context->TakeNextId();
76 auto variable_inst = MakeUnique<opt::Instruction>(
77 context, spv::Op::OpVariable, pointer_type_id, variable_id,
78 opt::Instruction::OperandList(
79 {{SPV_OPERAND_TYPE_STORAGE_CLASS,
80 {uint32_t(spv::StorageClass::Function)}}}));
81 iter->InsertBefore(std::move(variable_inst));
82 return variable_id;
83}
84
85uint32_t FindOrCreateGlobalUndef(opt::IRContext* context, uint32_t type_id) {
86 for (auto& inst : context->module()->types_values()) {

Callers 1

FixNonDominatedIdUsesMethod · 0.85

Calls 11

AsPointerMethod · 0.80
get_type_mgrMethod · 0.80
storage_classMethod · 0.45
GetTypeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
opcodeMethod · 0.45
type_idMethod · 0.45
result_idMethod · 0.45
TakeNextIdMethod · 0.45
InsertBeforeMethod · 0.45

Tested by

no test coverage detected