| 277 | |
| 278 | |
| 279 | Value* get_operand(llvm::Value *v, |
| 280 | function<Value*(llvm::ConstantExpr*)> constexpr_conv, |
| 281 | function<Value*(AggregateValue*)> copy_inserter, |
| 282 | function<bool(llvm::Function*)> register_fn_decl) { |
| 283 | if (auto ptr = get_identifier(*v)) |
| 284 | return ptr; |
| 285 | |
| 286 | auto ty = llvm_type2alive(v->getType()); |
| 287 | if (!ty) |
| 288 | return nullptr; |
| 289 | |
| 290 | // automatic splat of constant values |
| 291 | if (auto vty = dyn_cast<llvm::FixedVectorType>(v->getType()); |
| 292 | vty && isa<llvm::ConstantInt, llvm::ConstantFP>(v)) { |
| 293 | llvm::Value *llvm_splat = nullptr; |
| 294 | if (auto cnst = dyn_cast<llvm::ConstantInt>(v)) { |
| 295 | llvm_splat |
| 296 | = llvm::ConstantInt::get(vty->getElementType(), cnst->getValue()); |
| 297 | } else if (auto cnst = dyn_cast<llvm::ConstantFP>(v)) { |
| 298 | llvm_splat |
| 299 | = llvm::ConstantFP::get(vty->getElementType(), cnst->getValue()); |
| 300 | } else |
| 301 | UNREACHABLE(); |
| 302 | |
| 303 | auto splat = get_operand(llvm_splat, constexpr_conv, copy_inserter, |
| 304 | register_fn_decl); |
| 305 | if (!splat) |
| 306 | return nullptr; |
| 307 | |
| 308 | vector<Value*> vals(vty->getNumElements(), splat); |
| 309 | auto val = make_unique<AggregateValue>(*ty, std::move(vals)); |
| 310 | auto ret = val.get(); |
| 311 | current_fn->addConstant(std::move(val)); |
| 312 | RETURN_CACHE(ret); |
| 313 | } |
| 314 | |
| 315 | if (auto cnst = dyn_cast<llvm::ConstantInt>(v)) { |
| 316 | RETURN_CACHE(make_intconst(cnst->getValue())); |
| 317 | } |
| 318 | |
| 319 | if (auto cnst = dyn_cast<llvm::ConstantFP>(v)) { |
| 320 | auto &apfloat = cnst->getValueAPF(); |
| 321 | auto c |
| 322 | = make_unique<FloatConst>(*ty, |
| 323 | toString(apfloat.bitcastToAPInt(), 10, false), |
| 324 | true); |
| 325 | auto ret = c.get(); |
| 326 | current_fn->addConstant(std::move(c)); |
| 327 | RETURN_CACHE(ret); |
| 328 | } |
| 329 | |
| 330 | if (isa<llvm::PoisonValue>(v)) { |
| 331 | RETURN_CACHE(get_poison(*ty)); |
| 332 | } |
| 333 | |
| 334 | if (isa<llvm::UndefValue>(v)) { |
| 335 | auto val = make_unique<UndefValue>(*ty); |
| 336 | auto ret = val.get(); |
no test coverage detected