forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CIR][Passes] Add CallConvLowering pass skeleton (llvm#642)
This patch adds a new CallConvLowering pass that aims to lower the calling conventions of the functions in the module. It also includes a new Clang command line option to enable it. Also, it is considered a part of the lowering prepare set of passes, as it is unlikely to be used elsewhere in the pipeline. Since this will be dealing with ABI/Target-specific information, it requires AST info. For this reason, it can only be executed through the clang driver or cc1 tool for now as CIR does not encode AST info. This pass is disabled by default and can be enabled by passing the flag `-fclangir-call-conv-lowering`. Once this pass is more mature, it should be enabled by default as a required step to lower to LLVM Dialect.
- Loading branch information
1 parent
d0aabe7
commit 966a733
Showing
12 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//===- CallConvLowering.cpp - Rewrites functions according to call convs --===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir/IR/PatternMatch.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
#include "clang/CIR/Dialect/IR/CIRDialect.h" | ||
|
||
#define GEN_PASS_DEF_CALLCONVLOWERING | ||
#include "clang/CIR/Dialect/Passes.h.inc" | ||
|
||
namespace mlir { | ||
namespace cir { | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Rewrite Patterns | ||
//===----------------------------------------------------------------------===// | ||
|
||
struct CallConvLoweringPattern : public OpRewritePattern<FuncOp> { | ||
using OpRewritePattern<FuncOp>::OpRewritePattern; | ||
|
||
LogicalResult matchAndRewrite(FuncOp op, | ||
PatternRewriter &rewriter) const final { | ||
if (!op.getAst()) | ||
return op.emitError("function has no AST information"); | ||
return success(); | ||
} | ||
}; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Pass | ||
//===----------------------------------------------------------------------===// | ||
|
||
struct CallConvLoweringPass | ||
: ::impl::CallConvLoweringBase<CallConvLoweringPass> { | ||
using CallConvLoweringBase::CallConvLoweringBase; | ||
|
||
void runOnOperation() override; | ||
StringRef getArgument() const override { return "cir-call-conv-lowering"; }; | ||
}; | ||
|
||
void populateCallConvLoweringPassPatterns(RewritePatternSet &patterns) { | ||
patterns.add<CallConvLoweringPattern>(patterns.getContext()); | ||
} | ||
|
||
void CallConvLoweringPass::runOnOperation() { | ||
|
||
// Collect rewrite patterns. | ||
RewritePatternSet patterns(&getContext()); | ||
populateCallConvLoweringPassPatterns(patterns); | ||
|
||
// Collect operations to be considered by the pass. | ||
SmallVector<Operation *, 16> ops; | ||
getOperation()->walk([&](FuncOp op) { ops.push_back(op); }); | ||
|
||
// Configure rewrite to ignore new ops created during the pass. | ||
GreedyRewriteConfig config; | ||
config.strictMode = GreedyRewriteStrictness::ExistingOps; | ||
|
||
// Apply patterns. | ||
if (failed(applyOpPatternsAndFold(ops, std::move(patterns), config))) | ||
signalPassFailure(); | ||
} | ||
|
||
} // namespace cir | ||
|
||
std::unique_ptr<Pass> createCallConvLoweringPass() { | ||
return std::make_unique<cir::CallConvLoweringPass>(); | ||
} | ||
|
||
} // namespace mlir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
clang/test/CIR/Transforms/Target/x86/x86-call-conv-lowering-pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -fclangir-call-conv-lowering -emit-cir -mmlir --mlir-print-ir-after=cir-call-conv-lowering %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s | ||
|
||
// Just check if the pass is called for now. | ||
// CHECK: module |