clang 23.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"
18#include "clang/AST/Mangle.h"
19#include "clang/Basic/Module.h"
23#include "llvm/ADT/SmallVector.h"
24#include "llvm/ADT/StringMap.h"
25#include "llvm/ADT/StringRef.h"
26#include "llvm/ADT/StringSet.h"
27#include "llvm/ADT/Twine.h"
28#include "llvm/Support/ErrorHandling.h"
29#include "llvm/Support/Path.h"
30
32using namespace mlir;
33using namespace cir;
34
35namespace mlir {
36#define GEN_PASS_DEF_LIBOPT
37#include "clang/CIR/Dialect/Passes.h.inc"
38} // namespace mlir
39
40namespace {
41
42struct LibOptPass : public impl::LibOptBase<LibOptPass> {
43 LibOptPass() = default;
44 mlir::LogicalResult
45 initializeOptions(llvm::StringRef options,
46 llvm::function_ref<mlir::LogicalResult(const llvm::Twine &)>
47 errorHandler) override;
48 void runOnOperation() override;
49
50 // Raw libopt option string forwarded by the frontend. This will later control
51 // which optimizations the pass enables.
52 std::string optimizationOptions;
53
54 /// Tracks current module.
55 ModuleOp theModule;
56};
57} // namespace
58
59mlir::LogicalResult LibOptPass::initializeOptions(
60 llvm::StringRef options,
61 llvm::function_ref<mlir::LogicalResult(const llvm::Twine &)> errorHandler) {
62 (void)errorHandler;
63 optimizationOptions = options.str();
64 // TODO(cir): Parse options to select the active transformations for the
65 // pass.
66 return mlir::success();
67}
68
69void LibOptPass::runOnOperation() {
70 auto *op = getOperation();
71 if (isa<::mlir::ModuleOp>(op))
72 theModule = cast<::mlir::ModuleOp>(op);
73}
74
75std::unique_ptr<Pass> mlir::createLibOptPass() {
76 return std::make_unique<LibOptPass>();
77}
Defines the clang::ASTContext interface.
Defines the clang::Module class, which describes a module in the source code.
std::unique_ptr< Pass > createLibOptPass()
Definition LibOpt.cpp:75