• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- AVX512Intr.cpp - Convert MLIR LLVM dialect to LLVM intrinsics ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a translation between the MLIR LLVM and AVX512 dialects
10 // and LLVM IR with AVX intrinsics.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h"
15 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
16 #include "mlir/Translation.h"
17 #include "llvm/IR/IntrinsicsX86.h"
18 
19 using namespace mlir;
20 
21 namespace {
22 class LLVMAVX512ModuleTranslation : public LLVM::ModuleTranslation {
23   friend LLVM::ModuleTranslation;
24 
25 public:
26   using LLVM::ModuleTranslation::ModuleTranslation;
27 
28 protected:
convertOperation(Operation & opInst,llvm::IRBuilder<> & builder)29   LogicalResult convertOperation(Operation &opInst,
30                                  llvm::IRBuilder<> &builder) override {
31 #include "mlir/Dialect/LLVMIR/LLVMAVX512Conversions.inc"
32 
33     return LLVM::ModuleTranslation::convertOperation(opInst, builder);
34   }
35 };
36 
37 std::unique_ptr<llvm::Module>
translateLLVMAVX512ModuleToLLVMIR(Operation * m,llvm::LLVMContext & llvmContext,StringRef name)38 translateLLVMAVX512ModuleToLLVMIR(Operation *m, llvm::LLVMContext &llvmContext,
39                                   StringRef name) {
40   return LLVM::ModuleTranslation::translateModule<LLVMAVX512ModuleTranslation>(
41       m, llvmContext, name);
42 }
43 } // end namespace
44 
45 namespace mlir {
registerAVX512ToLLVMIRTranslation()46 void registerAVX512ToLLVMIRTranslation() {
47   TranslateFromMLIRRegistration reg(
48       "avx512-mlir-to-llvmir",
49       [](ModuleOp module, raw_ostream &output) {
50         llvm::LLVMContext llvmContext;
51         auto llvmModule = translateLLVMAVX512ModuleToLLVMIR(
52             module, llvmContext, "LLVMDialectModule");
53         if (!llvmModule)
54           return failure();
55 
56         llvmModule->print(output, nullptr);
57         return success();
58       },
59       [](DialectRegistry &registry) {
60         registry.insert<LLVM::LLVMAVX512Dialect, LLVM::LLVMDialect>();
61       });
62 }
63 } // namespace mlir
64