| 78 | } |
| 79 | |
| 80 | uint32_t ValueNumberTable::AssignValueNumber(Instruction* inst) { |
| 81 | // If it already has a value return that. |
| 82 | uint32_t value = GetValueNumber(inst); |
| 83 | if (value != 0) { |
| 84 | return value; |
| 85 | } |
| 86 | |
| 87 | auto assign_new_number = [this](Instruction* i) { |
| 88 | const auto new_value = TakeNextValueNumber(); |
| 89 | id_to_value_[i->result_id()] = new_value; |
| 90 | return new_value; |
| 91 | }; |
| 92 | |
| 93 | // If the instruction has other side effects, then it must |
| 94 | // have its own value number. |
| 95 | if (!context()->IsCombinatorInstruction(inst) && |
| 96 | !inst->IsCommonDebugInstr()) { |
| 97 | return assign_new_number(inst); |
| 98 | } |
| 99 | |
| 100 | // OpSampledImage and OpImage must remain in the same basic block in which |
| 101 | // they are used, because of this we will assign each one it own value number. |
| 102 | switch (inst->opcode()) { |
| 103 | case spv::Op::OpSampledImage: |
| 104 | case spv::Op::OpImage: |
| 105 | case spv::Op::OpVariable: |
| 106 | return assign_new_number(inst); |
| 107 | default: |
| 108 | break; |
| 109 | } |
| 110 | |
| 111 | // A load that yields an image, sampler, or sampled image must remain in |
| 112 | // the same basic block. So assign it its own value number. |
| 113 | if (inst->IsLoad()) { |
| 114 | switch (context()->get_def_use_mgr()->GetDef(inst->type_id())->opcode()) { |
| 115 | case spv::Op::OpTypeSampledImage: |
| 116 | case spv::Op::OpTypeImage: |
| 117 | case spv::Op::OpTypeSampler: |
| 118 | return assign_new_number(inst); |
| 119 | default: |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // If it is a load from memory that can be modified, we have to assume the |
| 125 | // memory has been modified, so we give it a new value number. |
| 126 | // |
| 127 | // Note that this test will also handle volatile loads because they are not |
| 128 | // read only. However, if this is ever relaxed because we analyze stores, we |
| 129 | // will have to add a new case for volatile loads. |
| 130 | if (inst->IsLoad() && !IsReadOnlyLoad(inst)) { |
| 131 | return assign_new_number(inst); |
| 132 | } |
| 133 | |
| 134 | analysis::DecorationManager* dec_mgr = context()->get_decoration_mgr(); |
| 135 | |
| 136 | // When we copy an object, the value numbers should be the same. |
| 137 | if (inst->opcode() == spv::Op::OpCopyObject && |
nothing calls this directly
no test coverage detected