summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/Target/LLVMIR/ModuleTranslation.cpp')
-rw-r--r--mlir/lib/Target/LLVMIR/ModuleTranslation.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index bf43848c9ef..3cbf543bdfc 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -292,6 +292,17 @@ bool ModuleTranslation::convertBlock(Block &bb, bool ignoreArguments) {
// Create named global variables that correspond to llvm.global definitions.
void ModuleTranslation::convertGlobals() {
for (auto op : mlirModule.getOps<LLVM::GlobalOp>()) {
+ // String attributes are treated separately because they cannot appear as
+ // in-function constants and are thus not supported by getLLVMConstant.
+ if (auto strAttr = op.value().dyn_cast<StringAttr>()) {
+ llvm::Constant *cst = llvm::ConstantDataArray::getString(
+ llvmModule->getContext(), strAttr.getValue(), /*AddNull=*/false);
+ new llvm::GlobalVariable(*llvmModule, cst->getType(), op.constant(),
+ llvm::GlobalValue::InternalLinkage, cst,
+ op.sym_name());
+ return;
+ }
+
llvm::Type *type = op.getType().getUnderlyingType();
new llvm::GlobalVariable(
*llvmModule, type, op.constant(), llvm::GlobalValue::InternalLinkage,
OpenPOWER on IntegriCloud