Skip to content

Commit

Permalink
Fixes based on code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-perron committed Apr 9, 2020
1 parent 64e6817 commit a09641e
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions source/opt/eliminate_dead_members_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,16 @@ void EliminateDeadMembersPass::MarkMembersAsLiveForCopyMemory(
void EliminateDeadMembersPass::MarkMembersAsLiveForExtract(
const Instruction* inst) {
assert(inst->opcode() == SpvOpCompositeExtract ||
(inst->opcode() == SpvOpSpecConstantOp &&
(inst->opcode() == SpvOpSpecConstantOp &&
inst->GetSingleWordInOperand(kSpecConstOpOpcodeIdx) ==
SpvOpCompositeExtract));

uint32_t first_operand = 0;
if (inst->opcode() == SpvOpSpecConstantOp) {
first_operand = 1;
}

uint32_t first_operand = (inst->opcode() == SpvOpSpecConstantOp ? 1 : 0);
uint32_t composite_id = inst->GetSingleWordInOperand(first_operand);
Instruction* composite_inst = get_def_use_mgr()->GetDef(composite_id);
uint32_t type_id = composite_inst->type_id();

for (uint32_t i = first_operand+1; i < inst->NumInOperands(); ++i) {
for (uint32_t i = first_operand + 1; i < inst->NumInOperands(); ++i) {
Instruction* type_inst = get_def_use_mgr()->GetDef(type_id);
uint32_t member_idx = inst->GetSingleWordInOperand(i);
switch (type_inst->opcode()) {
Expand Down Expand Up @@ -335,10 +331,6 @@ bool EliminateDeadMembersPass::RemoveDeadMembers() {
default:
break;
}
// assert(false && "Not yet implemented.");
// with OpCompositeExtract, OpCompositeInsert
// For kernels: OpAccessChain, OpInBoundsAccessChain, OpPtrAccessChain,
// OpInBoundsPtrAccessChain
break;
default:
break;
Expand Down Expand Up @@ -562,10 +554,10 @@ bool EliminateDeadMembersPass::UpdateCompsiteExtract(Instruction* inst) {

Instruction::OperandList new_operands;
bool modified = false;
for(uint32_t i = 0; i < first_operand+1; i++) {
for (uint32_t i = 0; i < first_operand + 1; i++) {
new_operands.emplace_back(inst->GetInOperand(i));
}
for (uint32_t i = first_operand+1; i < inst->NumInOperands(); ++i) {
for (uint32_t i = first_operand + 1; i < inst->NumInOperands(); ++i) {
uint32_t member_idx = inst->GetSingleWordInOperand(i);
uint32_t new_member_idx = GetNewMemberIndex(type_id, member_idx);
assert(new_member_idx != kRemovedMember);
Expand Down Expand Up @@ -603,7 +595,7 @@ bool EliminateDeadMembersPass::UpdateCompsiteExtract(Instruction* inst) {

bool EliminateDeadMembersPass::UpdateCompositeInsert(Instruction* inst) {
assert(inst->opcode() == SpvOpCompositeInsert ||
(inst->opcode() == SpvOpSpecConstantOp &&
(inst->opcode() == SpvOpSpecConstantOp &&
inst->GetSingleWordInOperand(kSpecConstOpOpcodeIdx) ==
SpvOpCompositeInsert));

Expand All @@ -612,17 +604,17 @@ bool EliminateDeadMembersPass::UpdateCompositeInsert(Instruction* inst) {
first_operand = 1;
}

uint32_t composite_id = inst->GetSingleWordInOperand(first_operand+1);
uint32_t composite_id = inst->GetSingleWordInOperand(first_operand + 1);
Instruction* composite_inst = get_def_use_mgr()->GetDef(composite_id);
uint32_t type_id = composite_inst->type_id();

Instruction::OperandList new_operands;
bool modified = false;

for(uint32_t i = 0; i < first_operand+2; ++i) {
for (uint32_t i = 0; i < first_operand + 2; ++i) {
new_operands.emplace_back(inst->GetInOperand(i));
}
for (uint32_t i = first_operand+2; i < inst->NumInOperands(); ++i) {
for (uint32_t i = first_operand + 2; i < inst->NumInOperands(); ++i) {
uint32_t member_idx = inst->GetSingleWordInOperand(i);
uint32_t new_member_idx = GetNewMemberIndex(type_id, member_idx);
if (new_member_idx == kRemovedMember) {
Expand Down

0 comments on commit a09641e

Please sign in to comment.