summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Target
diff options
context:
space:
mode:
authorChristian Sigg <csigg@google.com>2019-09-21 01:19:43 -0700
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-09-21 01:20:28 -0700
commit33a3a91ba2decbf5187228e0fdd528c05b6b963c (patch)
tree9f35fc7b32580571a5f91001f40acec4f7aafd5e /mlir/lib/Target
parent3a643de92b4c1a93b0725f171f4384c8dd941dd5 (diff)
downloadbcm5719-llvm-33a3a91ba2decbf5187228e0fdd528c05b6b963c.tar.gz
bcm5719-llvm-33a3a91ba2decbf5187228e0fdd528c05b6b963c.zip
Make GlobalOp's value attribute optional.
Make GlobalOp's value attribute an OptionalAttr. Change code that uses the value to handle 'nullopt'. Translate an unitialized value attribute to llvm::UndefValue. PiperOrigin-RevId: 270423646
Diffstat (limited to 'mlir/lib/Target')
-rw-r--r--mlir/lib/Target/LLVMIR/ModuleTranslation.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 5b5c06a1e86..ffdd6163ed2 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -78,6 +78,8 @@ static llvm::FunctionType *convertFunctionType(llvm::LLVMContext &llvmContext,
llvm::Constant *ModuleTranslation::getLLVMConstant(llvm::Type *llvmType,
Attribute attr,
Location loc) {
+ if (!attr)
+ return llvm::UndefValue::get(llvmType);
if (auto intAttr = attr.dyn_cast<IntegerAttr>())
return llvm::ConstantInt::get(llvmType, intAttr.getValue());
if (auto floatAttr = attr.dyn_cast<FloatAttr>())
@@ -317,13 +319,13 @@ void ModuleTranslation::convertGlobals() {
llvm::Type *type;
// 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>()) {
+ if (auto strAttr = op.getValueOrNull().dyn_cast_or_null<StringAttr>()) {
cst = llvm::ConstantDataArray::getString(
llvmModule->getContext(), strAttr.getValue(), /*AddNull=*/false);
type = cst->getType();
} else {
type = op.getType().getUnderlyingType();
- cst = getLLVMConstant(type, op.value(), op.getLoc());
+ cst = getLLVMConstant(type, op.getValueOrNull(), op.getLoc());
}
auto addrSpace = op.addr_space().getLimitedValue();
OpenPOWER on IntegriCloud