summaryrefslogtreecommitdiff
path: root/source/opt/decoration_manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/opt/decoration_manager.cpp')
-rw-r--r--source/opt/decoration_manager.cpp78
1 files changed, 39 insertions, 39 deletions
diff --git a/source/opt/decoration_manager.cpp b/source/opt/decoration_manager.cpp
index 9078c9f0..f218e149 100644
--- a/source/opt/decoration_manager.cpp
+++ b/source/opt/decoration_manager.cpp
@@ -25,35 +25,35 @@ namespace opt {
namespace analysis {
void DecorationManager::RemoveDecorationsFrom(
- uint32_t id, std::function<bool(const opt::Instruction&)> pred) {
+ uint32_t id, std::function<bool(const Instruction&)> pred) {
const auto ids_iter = id_to_decoration_insts_.find(id);
if (ids_iter == id_to_decoration_insts_.end()) return;
TargetData& decorations_info = ids_iter->second;
auto context = module_->context();
- std::vector<opt::Instruction*> insts_to_kill;
+ std::vector<Instruction*> insts_to_kill;
const bool is_group = !decorations_info.decorate_insts.empty();
// Schedule all direct decorations for removal if instructed as such by
// |pred|.
- for (opt::Instruction* inst : decorations_info.direct_decorations)
+ for (Instruction* inst : decorations_info.direct_decorations)
if (pred(*inst)) insts_to_kill.push_back(inst);
// For all groups being directly applied to |id|, remove |id| (and the
// literal if |inst| is an OpGroupMemberDecorate) from the instruction
// applying the group.
- std::unordered_set<const opt::Instruction*> indirect_decorations_to_remove;
- for (opt::Instruction* inst : decorations_info.indirect_decorations) {
+ std::unordered_set<const Instruction*> indirect_decorations_to_remove;
+ for (Instruction* inst : decorations_info.indirect_decorations) {
assert(inst->opcode() == SpvOpGroupDecorate ||
inst->opcode() == SpvOpGroupMemberDecorate);
- std::vector<opt::Instruction*> group_decorations_to_keep;
+ std::vector<Instruction*> group_decorations_to_keep;
const uint32_t group_id = inst->GetSingleWordInOperand(0u);
const auto group_iter = id_to_decoration_insts_.find(group_id);
assert(group_iter != id_to_decoration_insts_.end() &&
"Unknown decoration group");
const auto& group_decorations = group_iter->second.direct_decorations;
- for (opt::Instruction* decoration : group_decorations) {
+ for (Instruction* decoration : group_decorations) {
if (!pred(*decoration)) group_decorations_to_keep.push_back(decoration);
}
@@ -97,9 +97,9 @@ void DecorationManager::RemoveDecorationsFrom(
// If only some of the decorations should be kept, clone them and apply
// them directly to |id|.
if (!group_decorations_to_keep.empty()) {
- for (opt::Instruction* decoration : group_decorations_to_keep) {
+ for (Instruction* decoration : group_decorations_to_keep) {
// simply clone decoration and change |group_id| to |id|
- std::unique_ptr<opt::Instruction> new_inst(
+ std::unique_ptr<Instruction> new_inst(
decoration->Clone(module_->context()));
new_inst->SetInOperand(0, {id});
module_->AddAnnotationInst(std::move(new_inst));
@@ -113,22 +113,22 @@ void DecorationManager::RemoveDecorationsFrom(
indirect_decorations.erase(
std::remove_if(
indirect_decorations.begin(), indirect_decorations.end(),
- [&indirect_decorations_to_remove](const opt::Instruction* inst) {
+ [&indirect_decorations_to_remove](const Instruction* inst) {
return indirect_decorations_to_remove.count(inst);
}),
indirect_decorations.end());
- for (opt::Instruction* inst : insts_to_kill) context->KillInst(inst);
+ for (Instruction* inst : insts_to_kill) context->KillInst(inst);
insts_to_kill.clear();
// Schedule all instructions applying the group for removal if this group no
// longer applies decorations, either directly or indirectly.
if (is_group && decorations_info.direct_decorations.empty() &&
decorations_info.indirect_decorations.empty()) {
- for (opt::Instruction* inst : decorations_info.decorate_insts)
+ for (Instruction* inst : decorations_info.decorate_insts)
insts_to_kill.push_back(inst);
}
- for (opt::Instruction* inst : insts_to_kill) context->KillInst(inst);
+ for (Instruction* inst : insts_to_kill) context->KillInst(inst);
if (decorations_info.direct_decorations.empty() &&
decorations_info.indirect_decorations.empty() &&
@@ -140,20 +140,20 @@ void DecorationManager::RemoveDecorationsFrom(
}
}
-std::vector<opt::Instruction*> DecorationManager::GetDecorationsFor(
+std::vector<Instruction*> DecorationManager::GetDecorationsFor(
uint32_t id, bool include_linkage) {
- return InternalGetDecorationsFor<opt::Instruction*>(id, include_linkage);
+ return InternalGetDecorationsFor<Instruction*>(id, include_linkage);
}
-std::vector<const opt::Instruction*> DecorationManager::GetDecorationsFor(
+std::vector<const Instruction*> DecorationManager::GetDecorationsFor(
uint32_t id, bool include_linkage) const {
return const_cast<DecorationManager*>(this)
- ->InternalGetDecorationsFor<const opt::Instruction*>(id, include_linkage);
+ ->InternalGetDecorationsFor<const Instruction*>(id, include_linkage);
}
bool DecorationManager::HaveTheSameDecorations(uint32_t id1,
uint32_t id2) const {
- using InstructionList = std::vector<const opt::Instruction*>;
+ using InstructionList = std::vector<const Instruction*>;
using DecorationSet = std::set<std::u32string>;
const InstructionList decorations_for1 = GetDecorationsFor(id1, false);
@@ -167,7 +167,7 @@ bool DecorationManager::HaveTheSameDecorations(uint32_t id1,
[](const InstructionList& decoration_list, DecorationSet* decorate_set,
DecorationSet* decorate_id_set, DecorationSet* decorate_string_set,
DecorationSet* member_decorate_set) {
- for (const opt::Instruction* inst : decoration_list) {
+ for (const Instruction* inst : decoration_list) {
std::u32string decoration_payload;
// Ignore the opcode and the target as we do not want them to be
// compared.
@@ -223,8 +223,8 @@ bool DecorationManager::HaveTheSameDecorations(uint32_t id1,
// TODO(pierremoreau): If OpDecorateId is referencing an OpConstant, one could
// check that the constants are the same rather than just
// looking at the constant ID.
-bool DecorationManager::AreDecorationsTheSame(const opt::Instruction* inst1,
- const opt::Instruction* inst2,
+bool DecorationManager::AreDecorationsTheSame(const Instruction* inst1,
+ const Instruction* inst2,
bool ignore_target) const {
switch (inst1->opcode()) {
case SpvOpDecorate:
@@ -250,11 +250,11 @@ void DecorationManager::AnalyzeDecorations() {
if (!module_) return;
// For each group and instruction, collect all their decoration instructions.
- for (opt::Instruction& inst : module_->annotations()) {
+ for (Instruction& inst : module_->annotations()) {
AddDecoration(&inst);
}
}
-void DecorationManager::AddDecoration(opt::Instruction* inst) {
+void DecorationManager::AddDecoration(Instruction* inst) {
switch (inst->opcode()) {
case SpvOpDecorate:
case SpvOpDecorateId:
@@ -295,8 +295,8 @@ std::vector<T> DecorationManager::InternalGetDecorationsFor(
const auto process_direct_decorations =
[include_linkage,
- &decorations](const std::vector<opt::Instruction*>& direct_decorations) {
- for (opt::Instruction* inst : direct_decorations) {
+ &decorations](const std::vector<Instruction*>& direct_decorations) {
+ for (Instruction* inst : direct_decorations) {
const bool is_linkage = inst->opcode() == SpvOpDecorate &&
inst->GetSingleWordInOperand(1u) ==
SpvDecorationLinkageAttributes;
@@ -308,7 +308,7 @@ std::vector<T> DecorationManager::InternalGetDecorationsFor(
process_direct_decorations(ids_iter->second.direct_decorations);
// Process the decorations of all groups applied to |id|.
- for (const opt::Instruction* inst : target_data.indirect_decorations) {
+ for (const Instruction* inst : target_data.indirect_decorations) {
const uint32_t group_id = inst->GetSingleWordInOperand(0u);
const auto group_iter = id_to_decoration_insts_.find(group_id);
assert(group_iter != id_to_decoration_insts_.end() && "Unknown group ID");
@@ -320,8 +320,8 @@ std::vector<T> DecorationManager::InternalGetDecorationsFor(
bool DecorationManager::WhileEachDecoration(
uint32_t id, uint32_t decoration,
- std::function<bool(const opt::Instruction&)> f) {
- for (const opt::Instruction* inst : GetDecorationsFor(id, true)) {
+ std::function<bool(const Instruction&)> f) {
+ for (const Instruction* inst : GetDecorationsFor(id, true)) {
switch (inst->opcode()) {
case SpvOpMemberDecorate:
if (inst->GetSingleWordInOperand(2) == decoration) {
@@ -344,8 +344,8 @@ bool DecorationManager::WhileEachDecoration(
void DecorationManager::ForEachDecoration(
uint32_t id, uint32_t decoration,
- std::function<void(const opt::Instruction&)> f) {
- WhileEachDecoration(id, decoration, [&f](const opt::Instruction& inst) {
+ std::function<void(const Instruction&)> f) {
+ WhileEachDecoration(id, decoration, [&f](const Instruction& inst) {
f(inst);
return true;
});
@@ -355,9 +355,9 @@ void DecorationManager::CloneDecorations(uint32_t from, uint32_t to) {
const auto decoration_list = id_to_decoration_insts_.find(from);
if (decoration_list == id_to_decoration_insts_.end()) return;
auto context = module_->context();
- for (opt::Instruction* inst : decoration_list->second.direct_decorations) {
+ for (Instruction* inst : decoration_list->second.direct_decorations) {
// simply clone decoration and change |target-id| to |to|
- std::unique_ptr<opt::Instruction> new_inst(inst->Clone(module_->context()));
+ std::unique_ptr<Instruction> new_inst(inst->Clone(module_->context()));
new_inst->SetInOperand(0, {to});
module_->AddAnnotationInst(std::move(new_inst));
auto decoration_iter = --module_->annotation_end();
@@ -365,15 +365,15 @@ void DecorationManager::CloneDecorations(uint32_t from, uint32_t to) {
}
// We need to copy the list of instructions as ForgetUses and AnalyzeUses are
// going to modify it.
- std::vector<opt::Instruction*> indirect_decorations =
+ std::vector<Instruction*> indirect_decorations =
decoration_list->second.indirect_decorations;
- for (opt::Instruction* inst : indirect_decorations) {
+ for (Instruction* inst : indirect_decorations) {
switch (inst->opcode()) {
case SpvOpGroupDecorate:
context->ForgetUses(inst);
// add |to| to list of decorated id's
inst->AddOperand(
- opt::Operand(spv_operand_type_t::SPV_OPERAND_TYPE_ID, {to}));
+ Operand(spv_operand_type_t::SPV_OPERAND_TYPE_ID, {to}));
context->AnalyzeUses(inst);
break;
case SpvOpGroupMemberDecorate: {
@@ -381,10 +381,10 @@ void DecorationManager::CloneDecorations(uint32_t from, uint32_t to) {
// for each (id == from), add (to, literal) as operands
const uint32_t num_operands = inst->NumOperands();
for (uint32_t i = 1; i < num_operands; i += 2) {
- opt::Operand op = inst->GetOperand(i);
+ Operand op = inst->GetOperand(i);
if (op.words[0] == from) { // add new pair of operands: (to, literal)
inst->AddOperand(
- opt::Operand(spv_operand_type_t::SPV_OPERAND_TYPE_ID, {to}));
+ Operand(spv_operand_type_t::SPV_OPERAND_TYPE_ID, {to}));
op = inst->GetOperand(i + 1);
inst->AddOperand(std::move(op));
}
@@ -398,8 +398,8 @@ void DecorationManager::CloneDecorations(uint32_t from, uint32_t to) {
}
}
-void DecorationManager::RemoveDecoration(opt::Instruction* inst) {
- const auto remove_from_container = [inst](std::vector<opt::Instruction*>& v) {
+void DecorationManager::RemoveDecoration(Instruction* inst) {
+ const auto remove_from_container = [inst](std::vector<Instruction*>& v) {
v.erase(std::remove(v.begin(), v.end(), inst), v.end());
};