return nullptr;
T translator(m, std::move(llvmModule));
- translator.convertGlobals();
+ if (failed(translator.convertGlobals()))
+ return nullptr;
if (failed(translator.convertFunctions()))
return nullptr;
static LogicalResult checkSupportedModuleOps(Operation *m);
LogicalResult convertFunctions();
- void convertGlobals();
+ LogicalResult convertGlobals();
LogicalResult convertOneFunction(LLVMFuncOp func);
void connectPHINodes(LLVMFuncOp func);
LogicalResult convertBlock(Block &bb, bool ignoreArguments);
/// Create named global variables that correspond to llvm.mlir.global
/// definitions.
-void ModuleTranslation::convertGlobals() {
+LogicalResult ModuleTranslation::convertGlobals() {
for (auto op : getModuleBody(mlirModule).getOps<LLVM::GlobalOp>()) {
llvm::Type *type = op.getType().getUnderlyingType();
llvm::Constant *cst = llvm::UndefValue::get(type);
cst = llvm::ConstantDataArray::getString(
llvmModule->getContext(), strAttr.getValue(), /*AddNull=*/false);
type = cst->getType();
- } else {
- cst = getLLVMConstant(type, op.getValueOrNull(), op.getLoc());
+ } else if (!(cst = getLLVMConstant(type, op.getValueOrNull(),
+ op.getLoc()))) {
+ return failure();
}
} else if (Block *initializer = op.getInitializerBlock()) {
llvm::IRBuilder<> builder(llvmModule->getContext());
for (auto &op : initializer->without_terminator()) {
if (failed(convertOperation(op, builder)) ||
- !isa<llvm::Constant>(valueMapping.lookup(op.getResult(0)))) {
- emitError(op.getLoc(), "unemittable constant value");
- return;
- }
+ !isa<llvm::Constant>(valueMapping.lookup(op.getResult(0))))
+ return emitError(op.getLoc(), "unemittable constant value");
}
ReturnOp ret = cast<ReturnOp>(initializer->getTerminator());
cst = cast<llvm::Constant>(valueMapping.lookup(ret.getOperand(0)));
globalsMapping.try_emplace(op, var);
}
+
+ return success();
}
/// Get the SSA value passed to the current block from the terminator operation
%0 = llvm.mlir.constant(dense<[[[1, 2], [3, 4]], [[42, 43], [44, 45]]]> : tensor<2x2x2xi32>) : !llvm<"[2 x [2 x [2 x {i32}]]]">
llvm.return %0 : !llvm<"[2 x [2 x [2 x {i32}]]]">
}
+
+// -----
+
+// expected-error @+1 {{unsupported constant value}}
+llvm.mlir.global internal constant @test([2.5, 7.4]) : !llvm<"[2 x double]">