aboutsummaryrefslogtreecommitdiff
path: root/source/opt/local_single_store_elim_pass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/opt/local_single_store_elim_pass.cpp')
-rw-r--r--source/opt/local_single_store_elim_pass.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/source/opt/local_single_store_elim_pass.cpp b/source/opt/local_single_store_elim_pass.cpp
index e494689f..81648c7b 100644
--- a/source/opt/local_single_store_elim_pass.cpp
+++ b/source/opt/local_single_store_elim_pass.cpp
@@ -23,10 +23,13 @@
namespace spvtools {
namespace opt {
+
namespace {
-constexpr uint32_t kStoreValIdInIdx = 1;
-constexpr uint32_t kVariableInitIdInIdx = 1;
-} // namespace
+
+const uint32_t kStoreValIdInIdx = 1;
+const uint32_t kVariableInitIdInIdx = 1;
+
+} // anonymous namespace
bool LocalSingleStoreElimPass::LocalSingleStoreElim(Function* func) {
bool modified = false;
@@ -34,7 +37,7 @@ bool LocalSingleStoreElimPass::LocalSingleStoreElim(Function* func) {
// Check all function scope variables in |func|.
BasicBlock* entry_block = &*func->begin();
for (Instruction& inst : *entry_block) {
- if (inst.opcode() != spv::Op::OpVariable) {
+ if (inst.opcode() != SpvOpVariable) {
break;
}
@@ -54,7 +57,7 @@ bool LocalSingleStoreElimPass::AllExtensionsSupported() const {
// around unknown extended
// instruction sets even if they are non-semantic
for (auto& inst : context()->module()->ext_inst_imports()) {
- assert(inst.opcode() == spv::Op::OpExtInstImport &&
+ assert(inst.opcode() == SpvOpExtInstImport &&
"Expecting an import of an extension's instruction set.");
const std::string extension_name = inst.GetInOperand(0).AsString();
if (spvtools::utils::starts_with(extension_name, "NonSemantic.") &&
@@ -67,7 +70,7 @@ bool LocalSingleStoreElimPass::AllExtensionsSupported() const {
Pass::Status LocalSingleStoreElimPass::ProcessImpl() {
// Assumes relaxed logical addressing only (see instruction.h)
- if (context()->get_feature_mgr()->HasCapability(spv::Capability::Addresses))
+ if (context()->get_feature_mgr()->HasCapability(SpvCapabilityAddresses))
return Status::SuccessWithoutChange;
// Do not process if any disallowed extensions are enabled
@@ -191,7 +194,7 @@ Instruction* LocalSingleStoreElimPass::FindSingleStoreAndCheckUses(
for (Instruction* user : users) {
switch (user->opcode()) {
- case spv::Op::OpStore:
+ case SpvOpStore:
// Since we are in the relaxed addressing mode, the use has to be the
// base address of the store, and not the value being store. Otherwise,
// we would have a pointer to a pointer to function scope memory, which
@@ -203,19 +206,19 @@ Instruction* LocalSingleStoreElimPass::FindSingleStoreAndCheckUses(
return nullptr;
}
break;
- case spv::Op::OpAccessChain:
- case spv::Op::OpInBoundsAccessChain:
+ case SpvOpAccessChain:
+ case SpvOpInBoundsAccessChain:
if (FeedsAStore(user)) {
// Has a partial store. Cannot propagate that.
return nullptr;
}
break;
- case spv::Op::OpLoad:
- case spv::Op::OpImageTexelPointer:
- case spv::Op::OpName:
- case spv::Op::OpCopyObject:
+ case SpvOpLoad:
+ case SpvOpImageTexelPointer:
+ case SpvOpName:
+ case SpvOpCopyObject:
break;
- case spv::Op::OpExtInst: {
+ case SpvOpExtInst: {
auto dbg_op = user->GetCommonDebugOpcode();
if (dbg_op == CommonDebugInfoDebugDeclare ||
dbg_op == CommonDebugInfoDebugValue) {
@@ -240,7 +243,7 @@ void LocalSingleStoreElimPass::FindUses(
analysis::DefUseManager* def_use_mgr = context()->get_def_use_mgr();
def_use_mgr->ForEachUser(var_inst, [users, this](Instruction* user) {
users->push_back(user);
- if (user->opcode() == spv::Op::OpCopyObject) {
+ if (user->opcode() == SpvOpCopyObject) {
FindUses(user, users);
}
});
@@ -250,15 +253,15 @@ bool LocalSingleStoreElimPass::FeedsAStore(Instruction* inst) const {
analysis::DefUseManager* def_use_mgr = context()->get_def_use_mgr();
return !def_use_mgr->WhileEachUser(inst, [this](Instruction* user) {
switch (user->opcode()) {
- case spv::Op::OpStore:
+ case SpvOpStore:
return false;
- case spv::Op::OpAccessChain:
- case spv::Op::OpInBoundsAccessChain:
- case spv::Op::OpCopyObject:
+ case SpvOpAccessChain:
+ case SpvOpInBoundsAccessChain:
+ case SpvOpCopyObject:
return !FeedsAStore(user);
- case spv::Op::OpLoad:
- case spv::Op::OpImageTexelPointer:
- case spv::Op::OpName:
+ case SpvOpLoad:
+ case SpvOpImageTexelPointer:
+ case SpvOpName:
return true;
default:
// Don't know if this instruction modifies the variable.
@@ -276,7 +279,7 @@ bool LocalSingleStoreElimPass::RewriteLoads(
context()->GetDominatorAnalysis(store_block->GetParent());
uint32_t stored_id;
- if (store_inst->opcode() == spv::Op::OpStore)
+ if (store_inst->opcode() == SpvOpStore)
stored_id = store_inst->GetSingleWordInOperand(kStoreValIdInIdx);
else
stored_id = store_inst->GetSingleWordInOperand(kVariableInitIdInIdx);
@@ -284,12 +287,12 @@ bool LocalSingleStoreElimPass::RewriteLoads(
*all_rewritten = true;
bool modified = false;
for (Instruction* use : uses) {
- if (use->opcode() == spv::Op::OpStore) continue;
+ if (use->opcode() == SpvOpStore) continue;
auto dbg_op = use->GetCommonDebugOpcode();
if (dbg_op == CommonDebugInfoDebugDeclare ||
dbg_op == CommonDebugInfoDebugValue)
continue;
- if (use->opcode() == spv::Op::OpLoad &&
+ if (use->opcode() == SpvOpLoad &&
dominator_analysis->Dominates(store_inst, use)) {
modified = true;
context()->KillNamesAndDecorates(use->result_id());