case SpvOpMemberDecorate:
if (decoration->GetSingleWordInOperand(1u) ==
SpvDecorationFuncParamAttr)
- decoration->ToNop();
+ linked_context->KillInst(decoration);
break;
default:
break;
}
// Remove import linkage attributes
- for (auto& inst : linked_context->annotations())
- if (inst.opcode() == SpvOpDecorate &&
- inst.GetSingleWordOperand(1u) == SpvDecorationLinkageAttributes &&
- inst.GetSingleWordOperand(3u) == SpvLinkageTypeImport)
- inst.ToNop();
+ auto next = linked_context->annotation_begin();
+ for (auto inst = next; inst != linked_context->annotation_end();
+ inst = next) {
+ ++next;
+ if (inst->opcode() == SpvOpDecorate &&
+ inst->GetSingleWordOperand(1u) == SpvDecorationLinkageAttributes &&
+ inst->GetSingleWordOperand(3u) == SpvLinkageTypeImport) {
+ linked_context->KillInst(&*inst);
+ }
+ }
// Remove export linkage attributes and Linkage capability if making an
// executable
if (create_executable) {
- for (auto& inst : linked_context->annotations())
- if (inst.opcode() == SpvOpDecorate &&
- inst.GetSingleWordOperand(1u) == SpvDecorationLinkageAttributes &&
- inst.GetSingleWordOperand(3u) == SpvLinkageTypeExport)
- inst.ToNop();
+ next = linked_context->annotation_begin();
+ for (auto inst = next; inst != linked_context->annotation_end();
+ inst = next) {
+ ++next;
+ if (inst->opcode() == SpvOpDecorate &&
+ inst->GetSingleWordOperand(1u) == SpvDecorationLinkageAttributes &&
+ inst->GetSingleWordOperand(3u) == SpvLinkageTypeExport) {
+ linked_context->KillInst(&*inst);
+ }
+ }
for (auto& inst : linked_context->capabilities())
if (inst.GetSingleWordInOperand(0u) == SpvCapabilityLinkage) {
- inst.ToNop();
+ linked_context->KillInst(&inst);
// The RemoveDuplicatesPass did remove duplicated capabilities, so we
// now there aren’t more SpvCapabilityLinkage further down.
break;
Pass::Status FreezeSpecConstantValuePass::Process(ir::IRContext* irContext) {
bool modified = false;
- irContext->module()->ForEachInst([&modified](ir::Instruction* inst) {
- switch (inst->opcode()) {
- case SpvOp::SpvOpSpecConstant:
- inst->SetOpcode(SpvOp::SpvOpConstant);
- modified = true;
- break;
- case SpvOp::SpvOpSpecConstantTrue:
- inst->SetOpcode(SpvOp::SpvOpConstantTrue);
- modified = true;
- break;
- case SpvOp::SpvOpSpecConstantFalse:
- inst->SetOpcode(SpvOp::SpvOpConstantFalse);
- modified = true;
- break;
- case SpvOp::SpvOpDecorate:
- if (inst->GetSingleWordInOperand(1) ==
- SpvDecoration::SpvDecorationSpecId) {
- inst->ToNop();
- modified = true;
+ irContext->module()->ForEachInst(
+ [&modified, irContext](ir::Instruction* inst) {
+ switch (inst->opcode()) {
+ case SpvOp::SpvOpSpecConstant:
+ inst->SetOpcode(SpvOp::SpvOpConstant);
+ modified = true;
+ break;
+ case SpvOp::SpvOpSpecConstantTrue:
+ inst->SetOpcode(SpvOp::SpvOpConstantTrue);
+ modified = true;
+ break;
+ case SpvOp::SpvOpSpecConstantFalse:
+ inst->SetOpcode(SpvOp::SpvOpConstantFalse);
+ modified = true;
+ break;
+ case SpvOp::SpvOpDecorate:
+ if (inst->GetSingleWordInOperand(1) ==
+ SpvDecoration::SpvDecorationSpecId) {
+ irContext->KillInst(inst);
+ modified = true;
+ }
+ break;
+ default:
+ break;
}
- break;
- default:
- break;
- }
- });
+ });
return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange;
}