Refactor DenseElementsAttr to support auto-splatting the dense data on construction. This essentially means that we always auto-detect splat data and only store the minimum amount of data necessary. Support for parsing dense splats, and removing SplatElementsAttr(now that it is redundant) will come in followup cls

PiperOrigin-RevId: 252720561
This commit is contained in:
River Riddle
2019-06-11 16:14:17 -07:00
committed by Mehdi Amini
parent 5da741f671
commit d8cd96bc8b
8 changed files with 444 additions and 104 deletions

View File

@@ -97,6 +97,13 @@ llvm::Constant *ModuleTranslation::getLLVMConstant(llvm::Type *llvmType,
}
if (auto denseAttr = attr.dyn_cast<DenseElementsAttr>()) {
auto *vectorType = cast<llvm::VectorType>(llvmType);
if (denseAttr.isSplat()) {
auto *child = getLLVMConstant(vectorType->getElementType(),
denseAttr.getSplatValue(), loc);
return llvm::ConstantVector::getSplat(vectorType->getNumElements(),
child);
}
SmallVector<llvm::Constant *, 8> constants;
uint64_t numElements = vectorType->getNumElements();
constants.reserve(numElements);