diff options
author | Alex Zinenko <zinenko@google.com> | 2019-08-09 08:59:45 -0700 |
---|---|---|
committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-08-09 09:00:13 -0700 |
commit | 68451df267eda7961fca930ab29c6d38f43b97e2 (patch) | |
tree | 6ccdf1a904bfcd43a44e6cd94be08ac273af362e /mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | |
parent | b9ff2dd87edef4a750f2caccbd4923500f3d8405 (diff) | |
download | bcm5719-llvm-68451df267eda7961fca930ab29c6d38f43b97e2.tar.gz bcm5719-llvm-68451df267eda7961fca930ab29c6d38f43b97e2.zip |
LLVM dialect and translation: support global strings
Unlike regular constant values, strings must be placed in some memory and
referred to through a pointer to that memory. Until now, they were not
supported in function-local constant declarations with `llvm.constant`.
Introduce support for global strings using `llvm.global`, which would translate
them into global arrays in LLVM IR and thus make sure they have some memory
allocated for storage.
PiperOrigin-RevId: 262569316
Diffstat (limited to 'mlir/lib/Target/LLVMIR/ModuleTranslation.cpp')
-rw-r--r-- | mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 11 |
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, |