Skip to content

Commit f900171

Browse files
committed
llvm2alive: add support for weird automatic splat of constants into vectors
LLVM API support is very poor for this, hence the long code..
1 parent 653b79d commit f900171

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

llvm_util/utils.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,32 @@ Value* get_operand(llvm::Value *v,
286286
if (!ty)
287287
return nullptr;
288288

289+
// automatic splat of constant values
290+
if (auto vty = dyn_cast<llvm::FixedVectorType>(v->getType());
291+
vty && !isa<llvm::ConstantAggregate, llvm::ConstantAggregateZero,
292+
llvm::ConstantDataSequential>(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+
return nullptr;
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+
289315
if (auto cnst = dyn_cast<llvm::ConstantInt>(v)) {
290316
RETURN_CACHE(make_intconst(cnst->getValue()));
291317
}

0 commit comments

Comments
 (0)