| 23 | namespace opt { |
| 24 | |
| 25 | Function* Function::Clone(IRContext* ctx) const { |
| 26 | Function* clone = |
| 27 | new Function(std::unique_ptr<Instruction>(DefInst().Clone(ctx))); |
| 28 | clone->params_.reserve(params_.size()); |
| 29 | ForEachParam( |
| 30 | [clone, ctx](const Instruction* inst) { |
| 31 | clone->AddParameter(std::unique_ptr<Instruction>(inst->Clone(ctx))); |
| 32 | }, |
| 33 | true); |
| 34 | |
| 35 | for (const auto& i : debug_insts_in_header_) { |
| 36 | clone->AddDebugInstructionInHeader( |
| 37 | std::unique_ptr<Instruction>(i.Clone(ctx))); |
| 38 | } |
| 39 | |
| 40 | clone->blocks_.reserve(blocks_.size()); |
| 41 | for (const auto& b : blocks_) { |
| 42 | std::unique_ptr<BasicBlock> bb(b->Clone(ctx)); |
| 43 | if (!bb) { |
| 44 | delete clone; |
| 45 | return nullptr; |
| 46 | } |
| 47 | clone->AddBasicBlock(std::move(bb)); |
| 48 | } |
| 49 | |
| 50 | clone->SetFunctionEnd(std::unique_ptr<Instruction>(EndInst()->Clone(ctx))); |
| 51 | |
| 52 | clone->non_semantic_.reserve(non_semantic_.size()); |
| 53 | for (auto& non_semantic : non_semantic_) { |
| 54 | clone->AddNonSemanticInstruction( |
| 55 | std::unique_ptr<Instruction>(non_semantic->Clone(ctx))); |
| 56 | } |
| 57 | return clone; |
| 58 | } |
| 59 | |
| 60 | void Function::ForEachInst(const std::function<void(Instruction*)>& f, |
| 61 | bool run_on_debug_line_insts, |
nothing calls this directly
no test coverage detected