@@ -3746,9 +3746,6 @@ MLIRASTConsumer::GetOrCreateLLVMGlobal(const ValueDecl *FD,
37463746 break ;
37473747 }
37483748
3749- if (cast<VarDecl>(FD)->getInit ())
3750- cast<VarDecl>(FD)->getInit ()->dump ();
3751-
37523749 auto rt = getMLIRType (FD->getType ());
37533750
37543751 mlir::OpBuilder builder (module ->getContext ());
@@ -3757,17 +3754,24 @@ MLIRASTConsumer::GetOrCreateLLVMGlobal(const ValueDecl *FD,
37573754 auto glob = builder.create <LLVM::GlobalOp>(
37583755 module ->getLoc (), rt, /* constant*/ false , lnk, name, mlir::Attribute ());
37593756
3760- if (cast<VarDecl>(FD)->isThisDeclarationADefinition () ==
3757+ if (cast<VarDecl>(FD)->getInit () ||
3758+ cast<VarDecl>(FD)->isThisDeclarationADefinition () ==
37613759 VarDecl::Definition ||
37623760 cast<VarDecl>(FD)->isThisDeclarationADefinition () ==
37633761 VarDecl::TentativeDefinition) {
37643762 Block *blk = new Block ();
37653763 glob.getInitializerRegion ().push_back (blk);
37663764 builder.setInsertionPointToStart (blk);
3767- builder.create <LLVM::ReturnOp>(
3768- module ->getLoc (),
3769- std::vector<mlir::Value>(
3770- {builder.create <LLVM::UndefOp>(module ->getLoc (), rt)}));
3765+ mlir::Value res;
3766+ if (auto init = cast<VarDecl>(FD)->getInit ()) {
3767+ MLIRScanner ms (*this , module , LTInfo);
3768+ ms.setEntryAndAllocBlock (blk);
3769+ res = ms.Visit (const_cast <Expr *>(init)).getValue (builder);
3770+ } else {
3771+ res = builder.create <LLVM::UndefOp>(module ->getLoc (), rt);
3772+ }
3773+ builder.create <LLVM::ReturnOp>(module ->getLoc (),
3774+ std::vector<mlir::Value>({res}));
37713775 }
37723776 return llvmGlobals[name] = glob;
37733777}
0 commit comments