| 216 | |
| 217 | template <class Range, class Inserter> |
| 218 | static std::vector<instruction_ref> |
| 219 | insert_generic_instructions_impl(module& m, |
| 220 | instruction_ref ins, |
| 221 | Range&& instructions, |
| 222 | std::unordered_map<instruction_ref, instruction_ref>& map_ins, |
| 223 | Inserter insert) // NOLINT(performance-unnecessary-value-param) |
| 224 | { |
| 225 | assert(m.has_instruction(ins) or is_end(ins, m.end())); |
| 226 | std::vector<instruction_ref> mod_outputs; |
| 227 | instruction_ref last; |
| 228 | for(instruction_ref sins : instructions) |
| 229 | { |
| 230 | last = sins; |
| 231 | if(contains(map_ins, sins)) |
| 232 | continue; |
| 233 | instruction_ref copy_ins; |
| 234 | if(sins->name() == "@literal") |
| 235 | { |
| 236 | auto l = sins->get_literal(); |
| 237 | copy_ins = m.add_literal(l); |
| 238 | } |
| 239 | else if(sins->name() == "@param") |
| 240 | { |
| 241 | auto&& name = any_cast<builtin::param>(sins->get_operator()).parameter; |
| 242 | auto s = sins->get_shape(); |
| 243 | copy_ins = m.add_parameter(name, s); |
| 244 | } |
| 245 | else if(sins->name() == "@outline") |
| 246 | { |
| 247 | auto s = sins->get_shape(); |
| 248 | copy_ins = m.add_outline(s); |
| 249 | } |
| 250 | else |
| 251 | { |
| 252 | auto mod_args = sins->module_inputs(); |
| 253 | auto inputs = sins->inputs(); |
| 254 | std::vector<instruction_ref> copy_inputs(inputs.size()); |
| 255 | std::transform(inputs.begin(), inputs.end(), copy_inputs.begin(), [&](auto i) { |
| 256 | return contains(map_ins, i) ? map_ins[i] : i; |
| 257 | }); |
| 258 | |
| 259 | if(sins->name() == "@return") |
| 260 | { |
| 261 | mod_outputs = copy_inputs; |
| 262 | break; |
| 263 | } |
| 264 | |
| 265 | copy_ins = insert(m, ins, sins->get_operator(), copy_inputs, mod_args); |
| 266 | } |
| 267 | map_ins[sins] = copy_ins; |
| 268 | } |
| 269 | if(mod_outputs.empty() and instructions.begin() != instructions.end()) |
| 270 | mod_outputs = {map_ins.at(last)}; |
| 271 | return mod_outputs; |
| 272 | } |
| 273 | |
| 274 | template <class Range> |
| 275 | static std::vector<instruction_ref> |
no test coverage detected