brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · ee42015 Raw
70 lines · cpp
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8//9// Similar to MLIR/LLVM's "opt" tools but also deals with analysis and custom10// arguments. TODO: this is basically a copy from MlirOptMain.cpp, but capable11// of module emission as specified by the user.12//13//===----------------------------------------------------------------------===//14 15#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h"16#include "mlir/Dialect/DLTI/DLTI.h"17#include "mlir/Dialect/Func/IR/FuncOps.h"18#include "mlir/Dialect/LLVMIR/LLVMDialect.h"19#include "mlir/Dialect/MemRef/IR/MemRef.h"20#include "mlir/IR/BuiltinDialect.h"21#include "mlir/Pass/PassManager.h"22#include "mlir/Pass/PassOptions.h"23#include "mlir/Pass/PassRegistry.h"24#include "mlir/Tools/mlir-opt/MlirOptMain.h"25#include "mlir/Transforms/Passes.h"26#include "clang/CIR/Dialect/IR/CIRDialect.h"27#include "clang/CIR/Dialect/Passes.h"28#include "clang/CIR/Passes.h"29 30struct CIRToLLVMPipelineOptions31    : public mlir::PassPipelineOptions<CIRToLLVMPipelineOptions> {};32 33int main(int argc, char **argv) {34  // TODO: register needed MLIR passes for CIR?35  mlir::DialectRegistry registry;36  registry.insert<mlir::BuiltinDialect, cir::CIRDialect,37                  mlir::memref::MemRefDialect, mlir::LLVM::LLVMDialect,38                  mlir::DLTIDialect>();39 40  ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {41    return mlir::createCIRCanonicalizePass();42  });43  ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {44    return mlir::createCIRSimplifyPass();45  });46 47  mlir::PassPipelineRegistration<CIRToLLVMPipelineOptions> pipeline(48      "cir-to-llvm", "",49      [](mlir::OpPassManager &pm, const CIRToLLVMPipelineOptions &options) {50        cir::direct::populateCIRToLLVMPasses(pm);51      });52 53  ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {54    return mlir::createCIRFlattenCFGPass();55  });56 57  ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {58    return mlir::createHoistAllocasPass();59  });60 61  ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {62    return mlir::createGotoSolverPass();63  });64 65  mlir::registerTransformsPasses();66 67  return mlir::asMainReturnCode(MlirOptMain(68      argc, argv, "Clang IR analysis and optimization tool\n", registry));69}70