diff options
| author | Tres Popp <tpopp@google.com> | 2019-12-16 01:35:03 -0800 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-12-16 01:45:44 -0800 |
| commit | 44fc7d72b3cb44147394e22f1f21ad36cca7bca8 (patch) | |
| tree | 056115a82b26879275e2de6b10a759b71e0df335 /mlir/include | |
| parent | 97af93227283e9252d7e497bd08ea2b78ece8f92 (diff) | |
| download | bcm5719-llvm-44fc7d72b3cb44147394e22f1f21ad36cca7bca8.tar.gz bcm5719-llvm-44fc7d72b3cb44147394e22f1f21ad36cca7bca8.zip | |
Remove LLVM dependency on mlir::Module and instead check Traits.
PiperOrigin-RevId: 285724678
Diffstat (limited to 'mlir/include')
| -rw-r--r-- | mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h | 4 | ||||
| -rw-r--r-- | mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h | 20 | ||||
| -rw-r--r-- | mlir/include/mlir/Target/NVVMIR.h | 12 | ||||
| -rw-r--r-- | mlir/include/mlir/Target/ROCDLIR.h | 12 |
4 files changed, 31 insertions, 17 deletions
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h index 83c30e64b9f..5332a7479ad 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h @@ -198,6 +198,10 @@ Value *createGlobalString(Location loc, OpBuilder &builder, StringRef name, StringRef value, LLVM::Linkage linkage, LLVM::LLVMDialect *llvmDialect); +/// LLVM requires some operations to be inside of a Module operation. This +/// function confirms that the Operation has the desired properties. +bool satisfiesLLVMModule(Operation *op); + } // end namespace LLVM } // end namespace mlir diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h index b957c824be1..288901221db 100644 --- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h +++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h @@ -23,6 +23,7 @@ #ifndef MLIR_TARGET_LLVMIR_MODULETRANSLATION_H #define MLIR_TARGET_LLVMIR_MODULETRANSLATION_H +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/IR/Block.h" #include "mlir/IR/Module.h" #include "mlir/IR/Value.h" @@ -50,7 +51,9 @@ class LLVMFuncOp; class ModuleTranslation { public: template <typename T = ModuleTranslation> - static std::unique_ptr<llvm::Module> translateModule(ModuleOp m) { + static std::unique_ptr<llvm::Module> translateModule(Operation *m) { + if (!satisfiesLLVMModule(m)) + return nullptr; if (failed(checkSupportedModuleOps(m))) return nullptr; auto llvmModule = prepareLLVMModule(m); @@ -66,23 +69,30 @@ public: return std::move(translator.llvmModule); } + /// A helper method to get the single Block in an operation honoring LLVM's + /// module requirements. + static Block &getModuleBody(Operation *m) { return m->getRegion(0).front(); } + protected: // Translate the given MLIR module expressed in MLIR LLVM IR dialect into an // LLVM IR module. The MLIR LLVM IR dialect holds a pointer to an // LLVMContext, the LLVM IR module will be created in that context. - explicit ModuleTranslation(ModuleOp module) : mlirModule(module) {} + explicit ModuleTranslation(Operation *module) : mlirModule(module) { + assert(satisfiesLLVMModule(mlirModule) && + "mlirModule should honor LLVM's module semantics."); + } virtual ~ModuleTranslation() {} virtual LogicalResult convertOperation(Operation &op, llvm::IRBuilder<> &builder); - static std::unique_ptr<llvm::Module> prepareLLVMModule(ModuleOp m); + static std::unique_ptr<llvm::Module> prepareLLVMModule(Operation *m); template <typename Range> SmallVector<llvm::Value *, 8> lookupValues(Range &&values); private: /// Check whether the module contains only supported ops directly in its body. - static LogicalResult checkSupportedModuleOps(ModuleOp m); + static LogicalResult checkSupportedModuleOps(Operation *m); LogicalResult convertFunctions(); void convertGlobals(); @@ -94,7 +104,7 @@ private: Location loc); // Original and translated module. - ModuleOp mlirModule; + Operation *mlirModule; std::unique_ptr<llvm::Module> llvmModule; // Mappings between llvm.mlir.global definitions and corresponding globals. diff --git a/mlir/include/mlir/Target/NVVMIR.h b/mlir/include/mlir/Target/NVVMIR.h index 3a4442ebf87..ec9858e0fd7 100644 --- a/mlir/include/mlir/Target/NVVMIR.h +++ b/mlir/include/mlir/Target/NVVMIR.h @@ -30,14 +30,14 @@ class Module; } // namespace llvm namespace mlir { -class ModuleOp; +class Operation; -/// Convert the given MLIR module into NVVM IR. This conversion requires the -/// registration of the LLVM IR dialect and will extract the LLVM context -/// from the registered LLVM IR dialect. In case of error, report it -/// to the error handler registered with the MLIR context, if any (obtained from +/// Convert the given LLVM-module-like operation into NVVM IR. This conversion +/// requires the registration of the LLVM IR dialect and will extract the LLVM +/// context from the registered LLVM IR dialect. In case of error, report it to +/// the error handler registered with the MLIR context, if any (obtained from /// the MLIR module), and return `nullptr`. -std::unique_ptr<llvm::Module> translateModuleToNVVMIR(ModuleOp m); +std::unique_ptr<llvm::Module> translateModuleToNVVMIR(Operation *m); } // namespace mlir diff --git a/mlir/include/mlir/Target/ROCDLIR.h b/mlir/include/mlir/Target/ROCDLIR.h index 6295a1b0d98..fd00e9458ef 100644 --- a/mlir/include/mlir/Target/ROCDLIR.h +++ b/mlir/include/mlir/Target/ROCDLIR.h @@ -31,14 +31,14 @@ class Module; } // namespace llvm namespace mlir { -class ModuleOp; +class Operation; -/// Convert the given MLIR module into ROCDL IR. This conversion requires the -/// registration of the LLVM IR dialect and will extract the LLVM context -/// from the registered LLVM IR dialect. In case of error, report it -/// to the error handler registered with the MLIR context, if any (obtained from +/// Convert the given LLVM-module-like operation into ROCDL IR. This conversion +/// requires the registration of the LLVM IR dialect and will extract the LLVM +/// context from the registered LLVM IR dialect. In case of error, report it to +/// the error handler registered with the MLIR context, if any (obtained from /// the MLIR module), and return `nullptr`. -std::unique_ptr<llvm::Module> translateModuleToROCDLIR(ModuleOp m); +std::unique_ptr<llvm::Module> translateModuleToROCDLIR(Operation *m); } // namespace mlir |

