[flang] Use value_or (NFC)

This commit is contained in:
Kazu Hirata 2022-07-16 00:51:54 -07:00
parent 685775bbab
commit c715e2ff92
2 changed files with 9 additions and 15 deletions

View File

@ -252,12 +252,10 @@ public:
rewriter.setInsertionPoint(mem); rewriter.setInsertionPoint(mem);
auto toTy = typeConverter.convertType(unwrapRefType(ty)); auto toTy = typeConverter.convertType(unwrapRefType(ty));
bool isPinned = mem.getPinned(); bool isPinned = mem.getPinned();
llvm::StringRef uniqName; llvm::StringRef uniqName =
if (mem.getUniqName()) mem.getUniqName().value_or(llvm::StringRef());
uniqName = mem.getUniqName().getValue(); llvm::StringRef bindcName =
llvm::StringRef bindcName; mem.getBindcName().value_or(llvm::StringRef());
if (mem.getBindcName())
bindcName = mem.getBindcName().getValue();
rewriter.replaceOpWithNewOp<AllocaOp>( rewriter.replaceOpWithNewOp<AllocaOp>(
mem, toTy, uniqName, bindcName, isPinned, mem.getTypeparams(), mem, toTy, uniqName, bindcName, isPinned, mem.getTypeparams(),
mem.getShape()); mem.getShape());
@ -267,12 +265,10 @@ public:
if (typeConverter.needsConversion(ty)) { if (typeConverter.needsConversion(ty)) {
rewriter.setInsertionPoint(mem); rewriter.setInsertionPoint(mem);
auto toTy = typeConverter.convertType(unwrapRefType(ty)); auto toTy = typeConverter.convertType(unwrapRefType(ty));
llvm::StringRef uniqName; llvm::StringRef uniqName =
if (mem.getUniqName()) mem.getUniqName().value_or(llvm::StringRef());
uniqName = mem.getUniqName().getValue(); llvm::StringRef bindcName =
llvm::StringRef bindcName; mem.getBindcName().value_or(llvm::StringRef());
if (mem.getBindcName())
bindcName = mem.getBindcName().getValue();
rewriter.replaceOpWithNewOp<AllocMemOp>( rewriter.replaceOpWithNewOp<AllocMemOp>(
mem, toTy, uniqName, bindcName, mem.getTypeparams(), mem, toTy, uniqName, bindcName, mem.getTypeparams(),
mem.getShape()); mem.getShape());

View File

@ -2679,9 +2679,7 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> {
if (global.getType().isa<fir::BoxType>()) if (global.getType().isa<fir::BoxType>())
tyAttr = tyAttr.cast<mlir::LLVM::LLVMPointerType>().getElementType(); tyAttr = tyAttr.cast<mlir::LLVM::LLVMPointerType>().getElementType();
auto loc = global.getLoc(); auto loc = global.getLoc();
mlir::Attribute initAttr; mlir::Attribute initAttr = global.getInitVal().value_or(mlir::Attribute());
if (global.getInitVal())
initAttr = global.getInitVal().getValue();
auto linkage = convertLinkage(global.getLinkName()); auto linkage = convertLinkage(global.getLinkName());
auto isConst = global.getConstant().has_value(); auto isConst = global.getConstant().has_value();
auto g = rewriter.create<mlir::LLVM::GlobalOp>( auto g = rewriter.create<mlir::LLVM::GlobalOp>(