// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License.
intdumpLLVMIR(mlir::ModuleOp module){ mlir::registerLLVMDialectTranslation(*module->getContext()); // Convert the module to LLVM IR in a new LLVM IR context.
llvm::LLVMContext llvmContext; auto llvmModule = mlir::translateModuleToLLVMIR(module, llvmContext); if (!llvmModule) { llvm::errs() << "Failed to emit LLVM IR\n"; return-1; }
// Register the translation from MLIR to LLVM IR, which must happen before we // can JIT-compile. mlir::registerLLVMDialectTranslation(*module->getContext());
// An optimization pipeline to use within the execution engine. auto optPipeline = mlir::makeOptimizingTransformer(0, /*sizeLevel=*/0, /*targetMachine=*/nullptr);
// Create an MLIR execution engine. The execution engine eagerly JIT-compiles // the module. mlir::ExecutionEngineOptions engineOptions; engineOptions.transformer = optPipeline; auto maybeEngine = mlir::ExecutionEngine::create(module, engineOptions); assert(maybeEngine && "failed to construct an execution engine"); auto &engine = maybeEngine.get();
// Invoke the JIT-compiled function. auto invocationResult = engine->invokePacked("main"); if (invocationResult) { llvm::errs() << "JIT invocation failed\n"; return-1; }