clang 23.0.0git
CIRABIRewriteContext.h
Go to the documentation of this file.
1//===- CIRABIRewriteContext.h - CIR ABI rewrite context ---------*- C++ -*-===//
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// Defines CIRABIRewriteContext, the CIR dialect's implementation of the
10// generic mlir::abi::ABIRewriteContext. Given a FunctionClassification it
11// rewrites a cir.func signature, the function body, and call sites to match
12// the ABI-lowered shape.
13//
14// This file handles Direct (pass-through and coerce-in-registers), Extend,
15// Ignore, and an Indirect (sret) return. Indirect arguments (byval) and
16// Expand still emit an errorNYI.
17//
18//===----------------------------------------------------------------------===//
19
20#ifndef CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRABIREWRITECONTEXT_H
21#define CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRABIREWRITECONTEXT_H
22
23#include "mlir/ABI/ABIRewriteContext.h"
24#include "mlir/IR/BuiltinOps.h"
25#include "mlir/Interfaces/DataLayoutInterfaces.h"
27
28namespace cir {
29
30/// CIR-specific implementation of mlir::abi::ABIRewriteContext.
31///
32/// The driver pass (CallConvLoweringPass) computes a FunctionClassification
33/// for each cir.func / cir.call and dispatches to this class to perform the
34/// actual IR rewriting using cir dialect operations.
35///
36/// Holds a reference to the module's DataLayout for coercion alignment
37/// queries. The DataLayout must outlive the rewrite context.
39public:
40 CIRABIRewriteContext(mlir::ModuleOp module, const mlir::DataLayout &dl)
41 : module(module), dl(dl) {}
42
43 mlir::LogicalResult
44 rewriteFunctionDefinition(mlir::FunctionOpInterface funcOp,
45 const mlir::abi::FunctionClassification &fc,
46 mlir::OpBuilder &builder) override;
47
48 mlir::LogicalResult
49 rewriteCallSite(mlir::Operation *callOp,
50 const mlir::abi::FunctionClassification &fc,
51 mlir::OpBuilder &builder) override;
52
53 mlir::StringRef getDialectNamespace() const override { return "cir"; }
54
55private:
56 mlir::ModuleOp module;
57 const mlir::DataLayout &dl;
58};
59
60} // namespace cir
61
62#endif // CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRABIREWRITECONTEXT_H
mlir::LogicalResult rewriteFunctionDefinition(mlir::FunctionOpInterface funcOp, const mlir::abi::FunctionClassification &fc, mlir::OpBuilder &builder) override
mlir::StringRef getDialectNamespace() const override
CIRABIRewriteContext(mlir::ModuleOp module, const mlir::DataLayout &dl)
mlir::LogicalResult rewriteCallSite(mlir::Operation *callOp, const mlir::abi::FunctionClassification &fc, mlir::OpBuilder &builder) override