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

Function FindOrCreateGlobalVariable

source/reduce/reduction_util.cpp:26–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24const uint32_t kFalseBranchOperandIndex = 2;
25
26uint32_t FindOrCreateGlobalVariable(opt::IRContext* context,
27 uint32_t pointer_type_id) {
28 for (auto& inst : context->module()->types_values()) {
29 if (inst.opcode() != spv::Op::OpVariable) {
30 continue;
31 }
32 if (inst.type_id() == pointer_type_id) {
33 return inst.result_id();
34 }
35 }
36 const uint32_t variable_id = context->TakeNextId();
37 auto variable_inst = MakeUnique<opt::Instruction>(
38 context, spv::Op::OpVariable, pointer_type_id, variable_id,
39 opt::Instruction::OperandList(
40 {{SPV_OPERAND_TYPE_STORAGE_CLASS,
41 {static_cast<uint32_t>(context->get_type_mgr()
42 ->GetType(pointer_type_id)
43 ->AsPointer()
44 ->storage_class())}}}));
45 context->module()->AddGlobalValue(std::move(variable_inst));
46 return variable_id;
47}
48
49uint32_t FindOrCreateFunctionVariable(opt::IRContext* context,
50 opt::Function* function,

Callers 2

FixNonDominatedIdUsesMethod · 0.85
ApplyMethod · 0.85

Calls 11

AsPointerMethod · 0.80
get_type_mgrMethod · 0.80
types_valuesMethod · 0.45
moduleMethod · 0.45
opcodeMethod · 0.45
type_idMethod · 0.45
result_idMethod · 0.45
TakeNextIdMethod · 0.45
storage_classMethod · 0.45
GetTypeMethod · 0.45
AddGlobalValueMethod · 0.45

Tested by

no test coverage detected