clang
23.0.0git
lib
CIR
Dialect
Transforms
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/AST/ASTContext.h
"
18
#include "
clang/AST/Mangle.h
"
19
#include "
clang/Basic/Module.h
"
20
#include "
clang/CIR/Dialect/Builder/CIRBaseBuilder.h
"
21
#include "
clang/CIR/Dialect/IR/CIRDialect.h
"
22
#include "
clang/CIR/Dialect/Passes.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
31
using
cir::CIRBaseBuilderTy
;
32
using namespace
mlir
;
33
using namespace
cir
;
34
35
namespace
mlir
{
36
#define GEN_PASS_DEF_LIBOPT
37
#include "clang/CIR/Dialect/Passes.h.inc"
38
}
// namespace mlir
39
40
namespace
{
41
42
struct
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
59
mlir::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
69
void
LibOptPass::runOnOperation() {
70
auto
*op = getOperation();
71
if
(isa<::mlir::ModuleOp>(op))
72
theModule = cast<::mlir::ModuleOp>(op);
73
}
74
75
std::unique_ptr<Pass>
mlir::createLibOptPass
() {
76
return
std::make_unique<LibOptPass>();
77
}
ASTContext.h
Defines the clang::ASTContext interface.
CIRBaseBuilder.h
CIRDialect.h
Passes.h
Mangle.h
Module.h
Defines the clang::Module class, which describes a module in the source code.
PassDetail.h
cir::CIRBaseBuilderTy
Definition
CIRBaseBuilder.h:64
cir
Definition
ABIArgInfo.h:22
mlir
Definition
CIRGenerator.h:33
mlir::createLibOptPass
std::unique_ptr< Pass > createLibOptPass()
Definition
LibOpt.cpp:75
Generated on
for clang by
1.14.0