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 @@ -1384,6 +1384,8 @@ struct ConvertCIRToLLVMPass
1384
1384
1385
1385
void processCIRAttrs (mlir::ModuleOp moduleOp);
1386
1386
1387
+ inline static std::function<void (mlir::ConversionTarget)> runAtStartHook;
1388
+
1387
1389
StringRef getDescription () const override {
1388
1390
return " Convert the prepared CIR dialect module to LLVM dialect" ;
1389
1391
}
@@ -4640,6 +4642,9 @@ void ConvertCIRToLLVMPass::runOnOperation() {
4640
4642
// ,YieldOp
4641
4643
>();
4642
4644
// clang-format on
4645
+ if (runAtStartHook)
4646
+ runAtStartHook (target);
4647
+
4643
4648
target.addLegalDialect <mlir::LLVM::LLVMDialect>();
4644
4649
target.addIllegalDialect <mlir::BuiltinDialect, cir::CIRDialect,
4645
4650
mlir::func::FuncDialect>();
@@ -4677,6 +4682,13 @@ void ConvertCIRToLLVMPass::runOnOperation() {
4677
4682
buildGlobalAnnotationsVar (stringGlobalsMap, argStringGlobalsMap, argsVarMap);
4678
4683
}
4679
4684
4685
+ // / Set a hook to be called just before applying the dialect conversion so other
4686
+ // / dialects or patterns can be added
4687
+ void runAtStartOfConvertCIRToLLVMPass (
4688
+ std::function<void (mlir::ConversionTarget)> hook) {
4689
+ ConvertCIRToLLVMPass::runAtStartHook = std::move (hook);
4690
+ }
4691
+
4680
4692
std::unique_ptr<mlir::Pass> createConvertCIRToLLVMPass () {
4681
4693
return std::make_unique<ConvertCIRToLLVMPass>();
4682
4694
}
You can’t perform that action at this time.
0 commit comments