clang 24.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, Indirect (sret return, byval and byref arguments), and Expand
16// (struct flattening into scalar fields).
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 /// Retype \p addrOp, which holds the address of \p funcOp, to the signature
54 /// funcOp was rewritten to, and cast it back so existing uses keep the type
55 /// they were built for. A no-op when the ABI left funcOp's type alone.
56 /// Call after funcOp has been rewritten. Not an override, since taking a
57 /// function's address has no counterpart in the generic contract.
58 void rewriteFunctionAddress(cir::GetGlobalOp addrOp, cir::FuncOp funcOp,
59 mlir::OpBuilder &builder);
60
61 mlir::StringRef getDialectNamespace() const override { return "cir"; }
62
63private:
64 mlir::ModuleOp module;
65 const mlir::DataLayout &dl;
66};
67
68} // namespace cir
69
70#endif // CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRABIREWRITECONTEXT_H
void rewriteFunctionAddress(cir::GetGlobalOp addrOp, cir::FuncOp funcOp, mlir::OpBuilder &builder)
Retype addrOp, which holds the address of funcOp, to the signature funcOp was rewritten to,...
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