aboutsummaryrefslogtreecommitdiff
path: root/source/opt/copy_prop_arrays.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/opt/copy_prop_arrays.cpp')
-rw-r--r--source/opt/copy_prop_arrays.cpp108
1 files changed, 54 insertions, 54 deletions
diff --git a/source/opt/copy_prop_arrays.cpp b/source/opt/copy_prop_arrays.cpp
index 66a268fb..0b235629 100644
--- a/source/opt/copy_prop_arrays.cpp
+++ b/source/opt/copy_prop_arrays.cpp
@@ -22,12 +22,12 @@ namespace spvtools {
namespace opt {
namespace {
-constexpr uint32_t kLoadPointerInOperand = 0;
-constexpr uint32_t kStorePointerInOperand = 0;
-constexpr uint32_t kStoreObjectInOperand = 1;
-constexpr uint32_t kCompositeExtractObjectInOperand = 0;
-constexpr uint32_t kTypePointerStorageClassInIdx = 0;
-constexpr uint32_t kTypePointerPointeeInIdx = 1;
+const uint32_t kLoadPointerInOperand = 0;
+const uint32_t kStorePointerInOperand = 0;
+const uint32_t kStoreObjectInOperand = 1;
+const uint32_t kCompositeExtractObjectInOperand = 0;
+const uint32_t kTypePointerStorageClassInIdx = 0;
+const uint32_t kTypePointerPointeeInIdx = 1;
bool IsDebugDeclareOrValue(Instruction* di) {
auto dbg_opcode = di->GetCommonDebugOpcode();
@@ -46,8 +46,8 @@ Pass::Status CopyPropagateArrays::Process() {
BasicBlock* entry_bb = &*function.begin();
- for (auto var_inst = entry_bb->begin();
- var_inst->opcode() == spv::Op::OpVariable; ++var_inst) {
+ for (auto var_inst = entry_bb->begin(); var_inst->opcode() == SpvOpVariable;
+ ++var_inst) {
if (!IsPointerToArrayType(var_inst->type_id())) {
continue;
}
@@ -76,7 +76,7 @@ Pass::Status CopyPropagateArrays::Process() {
std::unique_ptr<CopyPropagateArrays::MemoryObject>
CopyPropagateArrays::FindSourceObjectIfPossible(Instruction* var_inst,
Instruction* store_inst) {
- assert(var_inst->opcode() == spv::Op::OpVariable && "Expecting a variable.");
+ assert(var_inst->opcode() == SpvOpVariable && "Expecting a variable.");
// Check that the variable is a composite object where |store_inst|
// dominates all of its loads.
@@ -114,7 +114,7 @@ Instruction* CopyPropagateArrays::FindStoreInstruction(
Instruction* store_inst = nullptr;
get_def_use_mgr()->WhileEachUser(
var_inst, [&store_inst, var_inst](Instruction* use) {
- if (use->opcode() == spv::Op::OpStore &&
+ if (use->opcode() == SpvOpStore &&
use->GetSingleWordInOperand(kStorePointerInOperand) ==
var_inst->result_id()) {
if (store_inst == nullptr) {
@@ -132,7 +132,7 @@ Instruction* CopyPropagateArrays::FindStoreInstruction(
void CopyPropagateArrays::PropagateObject(Instruction* var_inst,
MemoryObject* source,
Instruction* insertion_point) {
- assert(var_inst->opcode() == spv::Op::OpVariable &&
+ assert(var_inst->opcode() == SpvOpVariable &&
"This function propagates variables.");
Instruction* new_access_chain = BuildNewAccessChain(insertion_point, source);
@@ -166,17 +166,17 @@ Instruction* CopyPropagateArrays::BuildNewAccessChain(
bool CopyPropagateArrays::HasNoStores(Instruction* ptr_inst) {
return get_def_use_mgr()->WhileEachUser(ptr_inst, [this](Instruction* use) {
- if (use->opcode() == spv::Op::OpLoad) {
+ if (use->opcode() == SpvOpLoad) {
return true;
- } else if (use->opcode() == spv::Op::OpAccessChain) {
+ } else if (use->opcode() == SpvOpAccessChain) {
return HasNoStores(use);
- } else if (use->IsDecoration() || use->opcode() == spv::Op::OpName) {
+ } else if (use->IsDecoration() || use->opcode() == SpvOpName) {
return true;
- } else if (use->opcode() == spv::Op::OpStore) {
+ } else if (use->opcode() == SpvOpStore) {
return false;
- } else if (use->opcode() == spv::Op::OpImageTexelPointer) {
+ } else if (use->opcode() == SpvOpImageTexelPointer) {
return true;
- } else if (use->opcode() == spv::Op::OpEntryPoint) {
+ } else if (use->opcode() == SpvOpEntryPoint) {
return true;
}
// Some other instruction. Be conservative.
@@ -193,19 +193,19 @@ bool CopyPropagateArrays::HasValidReferencesOnly(Instruction* ptr_inst,
return get_def_use_mgr()->WhileEachUser(
ptr_inst,
[this, store_inst, dominator_analysis, ptr_inst](Instruction* use) {
- if (use->opcode() == spv::Op::OpLoad ||
- use->opcode() == spv::Op::OpImageTexelPointer) {
+ if (use->opcode() == SpvOpLoad ||
+ use->opcode() == SpvOpImageTexelPointer) {
// TODO: If there are many load in the same BB as |store_inst| the
// time to do the multiple traverses can add up. Consider collecting
// those loads and doing a single traversal.
return dominator_analysis->Dominates(store_inst, use);
- } else if (use->opcode() == spv::Op::OpAccessChain) {
+ } else if (use->opcode() == SpvOpAccessChain) {
return HasValidReferencesOnly(use, store_inst);
- } else if (use->IsDecoration() || use->opcode() == spv::Op::OpName) {
+ } else if (use->IsDecoration() || use->opcode() == SpvOpName) {
return true;
- } else if (use->opcode() == spv::Op::OpStore) {
+ } else if (use->opcode() == SpvOpStore) {
// If we are storing to part of the object it is not an candidate.
- return ptr_inst->opcode() == spv::Op::OpVariable &&
+ return ptr_inst->opcode() == SpvOpVariable &&
store_inst->GetSingleWordInOperand(kStorePointerInOperand) ==
ptr_inst->result_id();
} else if (IsDebugDeclareOrValue(use)) {
@@ -221,15 +221,15 @@ CopyPropagateArrays::GetSourceObjectIfAny(uint32_t result) {
Instruction* result_inst = context()->get_def_use_mgr()->GetDef(result);
switch (result_inst->opcode()) {
- case spv::Op::OpLoad:
+ case SpvOpLoad:
return BuildMemoryObjectFromLoad(result_inst);
- case spv::Op::OpCompositeExtract:
+ case SpvOpCompositeExtract:
return BuildMemoryObjectFromExtract(result_inst);
- case spv::Op::OpCompositeConstruct:
+ case SpvOpCompositeConstruct:
return BuildMemoryObjectFromCompositeConstruct(result_inst);
- case spv::Op::OpCopyObject:
+ case SpvOpCopyObject:
return GetSourceObjectIfAny(result_inst->GetSingleWordInOperand(0));
- case spv::Op::OpCompositeInsert:
+ case SpvOpCompositeInsert:
return BuildMemoryObjectFromInsert(result_inst);
default:
return nullptr;
@@ -251,7 +251,7 @@ CopyPropagateArrays::BuildMemoryObjectFromLoad(Instruction* load_inst) {
//
// It is built in reverse order because the different |OpAccessChain|
// instructions are visited in reverse order from which they are applied.
- while (current_inst->opcode() == spv::Op::OpAccessChain) {
+ while (current_inst->opcode() == SpvOpAccessChain) {
for (uint32_t i = current_inst->NumInOperands() - 1; i >= 1; --i) {
uint32_t element_index_id = current_inst->GetSingleWordInOperand(i);
components_in_reverse.push_back(element_index_id);
@@ -263,7 +263,7 @@ CopyPropagateArrays::BuildMemoryObjectFromLoad(Instruction* load_inst) {
// instruction followed by a series of |OpAccessChain| instructions, then
// return |nullptr| because we cannot identify the owner or access chain
// exactly.
- if (current_inst->opcode() != spv::Op::OpVariable) {
+ if (current_inst->opcode() != SpvOpVariable) {
return nullptr;
}
@@ -276,7 +276,7 @@ CopyPropagateArrays::BuildMemoryObjectFromLoad(Instruction* load_inst) {
std::unique_ptr<CopyPropagateArrays::MemoryObject>
CopyPropagateArrays::BuildMemoryObjectFromExtract(Instruction* extract_inst) {
- assert(extract_inst->opcode() == spv::Op::OpCompositeExtract &&
+ assert(extract_inst->opcode() == SpvOpCompositeExtract &&
"Expecting an OpCompositeExtract instruction.");
std::unique_ptr<MemoryObject> result = GetSourceObjectIfAny(
extract_inst->GetSingleWordInOperand(kCompositeExtractObjectInOperand));
@@ -297,7 +297,7 @@ CopyPropagateArrays::BuildMemoryObjectFromExtract(Instruction* extract_inst) {
std::unique_ptr<CopyPropagateArrays::MemoryObject>
CopyPropagateArrays::BuildMemoryObjectFromCompositeConstruct(
Instruction* conststruct_inst) {
- assert(conststruct_inst->opcode() == spv::Op::OpCompositeConstruct &&
+ assert(conststruct_inst->opcode() == SpvOpCompositeConstruct &&
"Expecting an OpCompositeConstruct instruction.");
// If every operand in the instruction are part of the same memory object, and
@@ -352,7 +352,7 @@ CopyPropagateArrays::BuildMemoryObjectFromCompositeConstruct(
std::unique_ptr<CopyPropagateArrays::MemoryObject>
CopyPropagateArrays::BuildMemoryObjectFromInsert(Instruction* insert_inst) {
- assert(insert_inst->opcode() == spv::Op::OpCompositeInsert &&
+ assert(insert_inst->opcode() == SpvOpCompositeInsert &&
"Expecting an OpCompositeInsert instruction.");
analysis::DefUseManager* def_use_mgr = context()->get_def_use_mgr();
@@ -407,7 +407,7 @@ CopyPropagateArrays::BuildMemoryObjectFromInsert(Instruction* insert_inst) {
Instruction* current_insert =
def_use_mgr->GetDef(insert_inst->GetSingleWordInOperand(1));
for (uint32_t i = number_of_elements - 1; i > 0; --i) {
- if (current_insert->opcode() != spv::Op::OpCompositeInsert) {
+ if (current_insert->opcode() != SpvOpCompositeInsert) {
return nullptr;
}
@@ -500,7 +500,7 @@ bool CopyPropagateArrays::CanUpdateUses(Instruction* original_ptr_inst,
if (IsDebugDeclareOrValue(use)) return true;
switch (use->opcode()) {
- case spv::Op::OpLoad: {
+ case SpvOpLoad: {
analysis::Pointer* pointer_type = type->AsPointer();
uint32_t new_type_id = type_mgr->GetId(pointer_type->pointee_type());
@@ -509,7 +509,7 @@ bool CopyPropagateArrays::CanUpdateUses(Instruction* original_ptr_inst,
}
return true;
}
- case spv::Op::OpAccessChain: {
+ case SpvOpAccessChain: {
analysis::Pointer* pointer_type = type->AsPointer();
const analysis::Type* pointee_type = pointer_type->pointee_type();
@@ -547,7 +547,7 @@ bool CopyPropagateArrays::CanUpdateUses(Instruction* original_ptr_inst,
}
return true;
}
- case spv::Op::OpCompositeExtract: {
+ case SpvOpCompositeExtract: {
std::vector<uint32_t> access_chain;
for (uint32_t i = 1; i < use->NumInOperands(); ++i) {
access_chain.push_back(use->GetSingleWordInOperand(i));
@@ -565,13 +565,13 @@ bool CopyPropagateArrays::CanUpdateUses(Instruction* original_ptr_inst,
}
return true;
}
- case spv::Op::OpStore:
+ case SpvOpStore:
// If needed, we can create an element-by-element copy to change the
// type of the value being stored. This way we can always handled
// stores.
return true;
- case spv::Op::OpImageTexelPointer:
- case spv::Op::OpName:
+ case SpvOpImageTexelPointer:
+ case SpvOpName:
return true;
default:
return use->IsDecoration();
@@ -598,8 +598,8 @@ void CopyPropagateArrays::UpdateUses(Instruction* original_ptr_inst,
if (use->IsCommonDebugInstr()) {
switch (use->GetCommonDebugOpcode()) {
case CommonDebugInfoDebugDeclare: {
- if (new_ptr_inst->opcode() == spv::Op::OpVariable ||
- new_ptr_inst->opcode() == spv::Op::OpFunctionParameter) {
+ if (new_ptr_inst->opcode() == SpvOpVariable ||
+ new_ptr_inst->opcode() == SpvOpFunctionParameter) {
context()->ForgetUses(use);
use->SetOperand(index, {new_ptr_inst->result_id()});
context()->AnalyzeUses(use);
@@ -640,7 +640,7 @@ void CopyPropagateArrays::UpdateUses(Instruction* original_ptr_inst,
}
switch (use->opcode()) {
- case spv::Op::OpLoad: {
+ case SpvOpLoad: {
// Replace the actual use.
context()->ForgetUses(use);
use->SetOperand(index, {new_ptr_inst->result_id()});
@@ -658,7 +658,7 @@ void CopyPropagateArrays::UpdateUses(Instruction* original_ptr_inst,
context()->AnalyzeUses(use);
}
} break;
- case spv::Op::OpAccessChain: {
+ case SpvOpAccessChain: {
// Update the actual use.
context()->ForgetUses(use);
use->SetOperand(index, {new_ptr_inst->result_id()});
@@ -685,7 +685,7 @@ void CopyPropagateArrays::UpdateUses(Instruction* original_ptr_inst,
pointer_type_inst->GetSingleWordInOperand(kTypePointerPointeeInIdx),
access_chain);
- spv::StorageClass storage_class = static_cast<spv::StorageClass>(
+ SpvStorageClass storage_class = static_cast<SpvStorageClass>(
pointer_type_inst->GetSingleWordInOperand(
kTypePointerStorageClassInIdx));
@@ -700,7 +700,7 @@ void CopyPropagateArrays::UpdateUses(Instruction* original_ptr_inst,
context()->AnalyzeUses(use);
}
} break;
- case spv::Op::OpCompositeExtract: {
+ case SpvOpCompositeExtract: {
// Update the actual use.
context()->ForgetUses(use);
use->SetOperand(index, {new_ptr_inst->result_id()});
@@ -721,7 +721,7 @@ void CopyPropagateArrays::UpdateUses(Instruction* original_ptr_inst,
context()->AnalyzeUses(use);
}
} break;
- case spv::Op::OpStore:
+ case SpvOpStore:
// If the use is the pointer, then it is the single store to that
// variable. We do not want to replace it. Instead, it will become
// dead after all of the loads are removed, and ADCE will get rid of it.
@@ -744,11 +744,11 @@ void CopyPropagateArrays::UpdateUses(Instruction* original_ptr_inst,
context()->AnalyzeUses(use);
}
break;
- case spv::Op::OpDecorate:
+ case SpvOpDecorate:
// We treat an OpImageTexelPointer as a load. The result type should
// always have the Image storage class, and should not need to be
// updated.
- case spv::Op::OpImageTexelPointer:
+ case SpvOpImageTexelPointer:
// Replace the actual use.
context()->ForgetUses(use);
use->SetOperand(index, {new_ptr_inst->result_id()});
@@ -766,13 +766,13 @@ uint32_t CopyPropagateArrays::GetMemberTypeId(
for (uint32_t element_index : access_chain) {
Instruction* type_inst = get_def_use_mgr()->GetDef(id);
switch (type_inst->opcode()) {
- case spv::Op::OpTypeArray:
- case spv::Op::OpTypeRuntimeArray:
- case spv::Op::OpTypeMatrix:
- case spv::Op::OpTypeVector:
+ case SpvOpTypeArray:
+ case SpvOpTypeRuntimeArray:
+ case SpvOpTypeMatrix:
+ case SpvOpTypeVector:
id = type_inst->GetSingleWordInOperand(0);
break;
- case spv::Op::OpTypeStruct:
+ case SpvOpTypeStruct:
id = type_inst->GetSingleWordInOperand(element_index);
break;
default: