[Mlir-commits] [mlir] 16b0225 - [mlir] do not require LLVMDialect in conversion from LLVM IR

Alex Zinenko llvmlistbot at llvm.org
Fri Aug 7 05:27:11 PDT 2020


Author: Alex Zinenko
Date: 2020-08-07T14:27:04+02:00
New Revision: 16b02253778caf1723b63c8ee482bb68ccae0a90

URL: https://github.com/llvm/llvm-project/commit/16b02253778caf1723b63c8ee482bb68ccae0a90
DIFF: https://github.com/llvm/llvm-project/commit/16b02253778caf1723b63c8ee482bb68ccae0a90.diff

LOG: [mlir] do not require LLVMDialect in conversion from LLVM IR

Historically, LLVMDialect has been required in the conversion from LLVM IR in
order to be able to construct types. This is no longer necessary with the new
type model and the dialect can be replaced with a local LLVM context.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D85444

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
index 54d527510398..470044bc9953 100644
--- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
@@ -52,7 +52,6 @@ class Importer {
         unknownLoc(FileLineColLoc::get("imported-bitcode", 0, 0, context)),
         typeTranslator(*context) {
     b.setInsertionPointToStart(module.getBody());
-    dialect = context->getRegisteredDialect<LLVMDialect>();
   }
 
   /// Imports `f` into the current module.
@@ -129,8 +128,6 @@ class Importer {
   DenseMap<llvm::GlobalVariable *, GlobalOp> globals;
   /// Cached FileLineColLoc::get("imported-bitcode", 0, 0).
   Location unknownLoc;
-  /// Cached dialect.
-  LLVMDialect *dialect;
   /// The stateful type translator (contains named structs).
   LLVM::TypeFromLLVMIRTranslator typeTranslator;
 };
@@ -719,7 +716,7 @@ LogicalResult Importer::processInstruction(llvm::Instruction *inst) {
   case llvm::Instruction::Fence: {
     StringRef syncscope;
     SmallVector<StringRef, 4> ssNs;
-    llvm::LLVMContext &llvmContext = dialect->getLLVMContext();
+    llvm::LLVMContext &llvmContext = inst->getContext();
     llvm::FenceInst *fence = cast<llvm::FenceInst>(inst);
     llvmContext.getSyncScopeNames(ssNs);
     int fenceSyncScopeID = fence->getSyncScopeID();
@@ -766,7 +763,7 @@ FlatSymbolRefAttr Importer::getPersonalityAsAttr(llvm::Function *f) {
   // bitcast to i8* are parsed.
   if (auto ce = dyn_cast<llvm::ConstantExpr>(pf)) {
     if (ce->getOpcode() == llvm::Instruction::BitCast &&
-        ce->getType() == llvm::Type::getInt8PtrTy(dialect->getLLVMContext())) {
+        ce->getType() == llvm::Type::getInt8PtrTy(f->getContext())) {
       if (auto func = dyn_cast<llvm::Function>(ce->getOperand(0)))
         return b.getSymbolRefAttr(func->getName());
     }
@@ -859,13 +856,10 @@ mlir::translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
 // LLVM dialect.
 OwningModuleRef translateLLVMIRToModule(llvm::SourceMgr &sourceMgr,
                                         MLIRContext *context) {
-  LLVMDialect *dialect = context->getRegisteredDialect<LLVMDialect>();
-  assert(dialect && "Could not find LLVMDialect?");
-
   llvm::SMDiagnostic err;
-  std::unique_ptr<llvm::Module> llvmModule =
-      llvm::parseIR(*sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID()), err,
-                    dialect->getLLVMContext());
+  llvm::LLVMContext llvmContext;
+  std::unique_ptr<llvm::Module> llvmModule = llvm::parseIR(
+      *sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID()), err, llvmContext);
   if (!llvmModule) {
     std::string errStr;
     llvm::raw_string_ostream errStream(errStr);


        


More information about the Mlir-commits mailing list