Skip to content

Commit fc67ccf

Browse files
committed
[CIR][WIP] Add ABI lowering pass
This patch adds a new pass cir-abi-lowering to the CIR dialect. This pass runs before the CallConvLowering pass, and it expands all ABI-dependent types and operations inside a function to their ABI-independent equivalences according to the ABI specification. This patch also moves the lowering code of the following types and operations from the LLVM lowering conversion to the new pass: - The pointer-to-data-member type `cir.data_member`; - The pointer-to-member-function type `cir.method`; - All operations working on operands of the above types.
1 parent b647f4b commit fc67ccf

File tree

17 files changed

+829
-303
lines changed

17 files changed

+829
-303
lines changed

clang/include/clang/CIR/Dialect/Passes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ std::unique_ptr<Pass> createFlattenCFGPass();
4040
std::unique_ptr<Pass> createHoistAllocasPass();
4141
std::unique_ptr<Pass> createGotoSolverPass();
4242

43+
/// Create a pass to expand ABI-dependent types and operations.
44+
std::unique_ptr<Pass> createABILoweringPass();
45+
4346
/// Create a pass to lower ABI-independent function definitions/calls.
4447
std::unique_ptr<Pass> createCallConvLoweringPass();
4548

clang/include/clang/CIR/Dialect/Passes.td

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,27 @@ def LibOpt : Pass<"cir-lib-opt"> {
180180
];
181181
}
182182

183+
def ABILowering : Pass<"cir-abi-lowering"> {
184+
let summary = "Expands ABI-dependent types and operations";
185+
let description = [{
186+
This pass expands ABI-dependent CIR types and operations to more "primitive"
187+
ABI-independent CIR types and operations according to the target ABI
188+
specification.
189+
190+
Some CIR types, such as pointers to members, may have different layouts and
191+
representations under different target ABIs. This pass expands these types
192+
to their underlying representations as specified by the target ABI. For
193+
example, when targeting Itanium ABI, this pass will replace pointers to
194+
member functions with a struct with two ptrdiff_t fields.
195+
196+
Similarly, some CIR operations may also behave differently under different
197+
target ABIs. This pass also expands these operations to more "primitive"
198+
CIR operations as specified by the target ABI.
199+
}];
200+
let constructor = "mlir::createABILoweringPass()";
201+
let dependentDialects = ["cir::CIRDialect"];
202+
}
203+
183204
def CallConvLowering : Pass<"cir-call-conv-lowering"> {
184205
let summary = "Handle calling conventions for CIR functions";
185206
let description = [{

clang/lib/CIR/CodeGen/CIRPasses.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ mlir::LogicalResult runCIRToCIRPasses(
9797
namespace mlir {
9898

9999
void populateCIRPreLoweringPasses(OpPassManager &pm, bool useCCLowering) {
100+
pm.addPass(createABILoweringPass());
100101
if (useCCLowering)
101102
pm.addPass(createCallConvLoweringPass());
102103
pm.addPass(createHoistAllocasPass());

0 commit comments

Comments
 (0)