File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
lib/CIR/Lowering/DirectToLLVM Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 13
13
#define CLANG_CIR_LOWERTOLLVM_H
14
14
15
15
#include " mlir/Pass/Pass.h"
16
+ #include " mlir/Transforms/DialectConversion.h"
16
17
18
+ #include < functional>
17
19
#include < memory>
18
20
19
21
namespace llvm {
@@ -33,7 +35,9 @@ std::unique_ptr<llvm::Module> lowerDirectlyFromCIRToLLVMIR(
33
35
mlir::ModuleOp theModule, llvm::LLVMContext &llvmCtx,
34
36
bool disableVerifier = false , bool disableCCLowering = false ,
35
37
bool disableDebugInfo = false );
36
- }
38
+ void runAtStartOfConvertCIRToLLVMPass (
39
+ std::function<void (mlir::ConversionTarget)>);
40
+ } // namespace direct
37
41
38
42
// Lower directly from pristine CIR to LLVMIR.
39
43
std::unique_ptr<llvm::Module>
Original file line number Diff line number Diff line change @@ -1347,6 +1347,8 @@ struct ConvertCIRToLLVMPass
1347
1347
1348
1348
void processCIRAttrs (mlir::ModuleOp moduleOp);
1349
1349
1350
+ inline static std::function<void (mlir::ConversionTarget)> runAtStartHook;
1351
+
1350
1352
StringRef getDescription () const override {
1351
1353
return " Convert the prepared CIR dialect module to LLVM dialect" ;
1352
1354
}
@@ -4626,6 +4628,9 @@ void ConvertCIRToLLVMPass::runOnOperation() {
4626
4628
// ,YieldOp
4627
4629
>();
4628
4630
// clang-format on
4631
+ if (runAtStartHook)
4632
+ runAtStartHook (target);
4633
+
4629
4634
target.addLegalDialect <mlir::LLVM::LLVMDialect>();
4630
4635
target.addIllegalDialect <mlir::BuiltinDialect, cir::CIRDialect,
4631
4636
mlir::func::FuncDialect>();
@@ -4663,6 +4668,13 @@ void ConvertCIRToLLVMPass::runOnOperation() {
4663
4668
buildGlobalAnnotationsVar (stringGlobalsMap, argStringGlobalsMap, argsVarMap);
4664
4669
}
4665
4670
4671
+ // / Set a hook to be called just before applying the dialect conversion so other
4672
+ // / dialects or patterns can be added
4673
+ void runAtStartOfConvertCIRToLLVMPass (
4674
+ std::function<void (mlir::ConversionTarget)> hook) {
4675
+ ConvertCIRToLLVMPass::runAtStartHook = std::move (hook);
4676
+ }
4677
+
4666
4678
std::unique_ptr<mlir::Pass> createConvertCIRToLLVMPass () {
4667
4679
return std::make_unique<ConvertCIRToLLVMPass>();
4668
4680
}
You can’t perform that action at this time.
0 commit comments