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

Method UpgradeMemoryAndImages

source/opt/upgrade_memory_model.cpp:126–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126void UpgradeMemoryModel::UpgradeMemoryAndImages() {
127 for (auto& func : *get_module()) {
128 func.ForEachInst([this](Instruction* inst) {
129 bool is_coherent = false;
130 bool is_volatile = false;
131 bool src_coherent = false;
132 bool src_volatile = false;
133 bool dst_coherent = false;
134 bool dst_volatile = false;
135 uint32_t start_operand = 0u;
136 spv::Scope scope = spv::Scope::QueueFamilyKHR;
137 spv::Scope src_scope = spv::Scope::QueueFamilyKHR;
138 spv::Scope dst_scope = spv::Scope::QueueFamilyKHR;
139 switch (inst->opcode()) {
140 case spv::Op::OpLoad:
141 case spv::Op::OpStore:
142 std::tie(is_coherent, is_volatile, scope) =
143 GetInstructionAttributes(inst->GetSingleWordInOperand(0u));
144 break;
145 case spv::Op::OpImageRead:
146 case spv::Op::OpImageSparseRead:
147 case spv::Op::OpImageWrite:
148 std::tie(is_coherent, is_volatile, scope) =
149 GetInstructionAttributes(inst->GetSingleWordInOperand(0u));
150 break;
151 case spv::Op::OpCopyMemory:
152 case spv::Op::OpCopyMemorySized:
153 std::tie(dst_coherent, dst_volatile, dst_scope) =
154 GetInstructionAttributes(inst->GetSingleWordInOperand(0u));
155 std::tie(src_coherent, src_volatile, src_scope) =
156 GetInstructionAttributes(inst->GetSingleWordInOperand(1u));
157 break;
158 default:
159 break;
160 }
161
162 switch (inst->opcode()) {
163 case spv::Op::OpLoad: {
164 Instruction* src_pointer = context()->get_def_use_mgr()->GetDef(
165 inst->GetSingleWordInOperand(0u));
166 analysis::Type* src_type =
167 context()->get_type_mgr()->GetType(src_pointer->type_id());
168 auto storage_class = src_type->AsPointer()->storage_class();
169 if (storage_class == spv::StorageClass::Function ||
170 storage_class == spv::StorageClass::Private) {
171 // If the buffer from function variable or private variable, flag
172 // NonPrivatePointer is unnecessary.
173 is_coherent = false;
174 }
175 UpgradeFlags(inst, 1u, is_coherent, is_volatile, kVisibility,
176 kMemory);
177 break;
178 }
179 case spv::Op::OpStore: {
180 Instruction* src_pointer = context()->get_def_use_mgr()->GetDef(
181 inst->GetSingleWordInOperand(0u));
182 analysis::Type* src_type =
183 context()->get_type_mgr()->GetType(src_pointer->type_id());

Callers

nothing calls this directly

Calls 15

MemoryAccessNumWordsFunction · 0.85
get_type_mgrMethod · 0.80
AsPointerMethod · 0.80
AddOperandMethod · 0.80
NumInOperandsMethod · 0.80
SetInOperandsMethod · 0.80
ForEachInstMethod · 0.45
opcodeMethod · 0.45
GetDefMethod · 0.45
get_def_use_mgrMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected