MCPcopy Create free account
hub / github.com/AliveToolkit/alive2 / get_operand

Function get_operand

llvm_util/utils.cpp:279–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277
278
279Value* 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();

Callers 15

get_operandMethod · 0.85
visitCallInstMethod · 0.85
visitMemSetInstMethod · 0.85
visitMemTransferInstMethod · 0.85
visitExtractValueInstMethod · 0.85
visitInsertValueInstMethod · 0.85
visitAllocaInstMethod · 0.85
visitStoreInstMethod · 0.85
visitBranchInstMethod · 0.85
visitSwitchInstMethod · 0.85
visitReturnInstMethod · 0.85

Calls 15

get_identifierFunction · 0.85
llvm_type2aliveFunction · 0.85
make_intconstFunction · 0.85
toStringFunction · 0.85
get_poisonFunction · 0.85
hasOpaqueTypeFunction · 0.85
to_stringFunction · 0.85
addConstantMethod · 0.80
addUndefMethod · 0.80
getParentMethod · 0.80
strMethod · 0.80
numElementsConstMethod · 0.80

Tested by

no test coverage detected