| 203 | } |
| 204 | |
| 205 | Instruction* ConstantManager::BuildInstructionAndAddToModule( |
| 206 | const Constant* new_const, Module::inst_iterator* pos, uint32_t type_id) { |
| 207 | // TODO(1841): Handle id overflow. |
| 208 | uint32_t new_id = context()->TakeNextId(); |
| 209 | if (new_id == 0) { |
| 210 | return nullptr; |
| 211 | } |
| 212 | |
| 213 | auto new_inst = CreateInstruction(new_id, new_const, type_id); |
| 214 | if (!new_inst) { |
| 215 | return nullptr; |
| 216 | } |
| 217 | auto* new_inst_ptr = new_inst.get(); |
| 218 | *pos = pos->InsertBefore(std::move(new_inst)); |
| 219 | ++(*pos); |
| 220 | if (context()->AreAnalysesValid(IRContext::Analysis::kAnalysisDefUse)) |
| 221 | context()->get_def_use_mgr()->AnalyzeInstDefUse(new_inst_ptr); |
| 222 | MapConstantToInst(new_const, new_inst_ptr); |
| 223 | return new_inst_ptr; |
| 224 | } |
| 225 | |
| 226 | Instruction* ConstantManager::GetDefiningInstruction( |
| 227 | const Constant* c, uint32_t type_id, Module::inst_iterator* pos) { |