clang 24.0.0git
LibOpt.cpp
Go to the documentation of this file.
1//===- LibOpt.cpp - Optimize CIR raised C/C++ library idioms --------------===//
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 pass optimizes C/C++ standard library idioms in Clang IR.
10//
11//===----------------------------------------------------------------------===//
12
13#include "PassDetail.h"
14#include "mlir/Dialect/Func/IR/FuncOps.h"
15#include "mlir/IR/BuiltinAttributes.h"
16#include "mlir/IR/Region.h"
17#include "clang/Basic/Module.h"
21#include "llvm/ADT/SmallVector.h"
22#include "llvm/ADT/StringMap.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/ADT/StringSet.h"
25#include "llvm/ADT/Twine.h"
26#include "llvm/Support/ErrorHandling.h"
27#include "llvm/Support/Path.h"
28
30using namespace mlir;
31using namespace cir;
32
33namespace mlir {
34#define GEN_PASS_DEF_LIBOPT
35#include "clang/CIR/Dialect/Passes.h.inc"
36} // namespace mlir
37
38namespace {
39
40struct LibOptPass : public impl::LibOptBase<LibOptPass> {
41 LibOptPass() = default;
42 mlir::LogicalResult
43 initializeOptions(llvm::StringRef options,
44 llvm::function_ref<mlir::LogicalResult(const llvm::Twine &)>
45 errorHandler) override;
46 void runOnOperation() override;
47
48 // Raw libopt option string forwarded by the frontend. This will later control
49 // which optimizations the pass enables.
50 std::string optimizationOptions;
51
52 /// Tracks current module.
53 ModuleOp theModule;
54};
55} // namespace
56
57mlir::LogicalResult LibOptPass::initializeOptions(
58 llvm::StringRef options,
59 llvm::function_ref<mlir::LogicalResult(const llvm::Twine &)> errorHandler) {
60 (void)errorHandler;
61 optimizationOptions = options.str();
62 // TODO(cir): Parse options to select the active transformations for the
63 // pass.
64 return mlir::success();
65}
66
67void LibOptPass::runOnOperation() {
68 auto *op = getOperation();
69 if (isa<::mlir::ModuleOp>(op))
70 theModule = cast<::mlir::ModuleOp>(op);
71}
72
73std::unique_ptr<Pass> mlir::createLibOptPass() {
74 return std::make_unique<LibOptPass>();
75}
Defines the clang::Module class, which describes a module in the source code.
std::unique_ptr< Pass > createLibOptPass()
Definition LibOpt.cpp:73