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 @@ -1352,6 +1352,8 @@ struct ConvertCIRToLLVMPass
1352
1352
1353
1353
void processCIRAttrs (mlir::ModuleOp moduleOp);
1354
1354
1355
+ inline static std::function<void (mlir::ConversionTarget)> runAtStartHook;
1356
+
1355
1357
StringRef getDescription () const override {
1356
1358
return " Convert the prepared CIR dialect module to LLVM dialect" ;
1357
1359
}
@@ -4692,6 +4694,9 @@ void ConvertCIRToLLVMPass::runOnOperation() {
4692
4694
// ,YieldOp
4693
4695
>();
4694
4696
// clang-format on
4697
+ if (runAtStartHook)
4698
+ runAtStartHook (target);
4699
+
4695
4700
target.addLegalDialect <mlir::LLVM::LLVMDialect>();
4696
4701
target.addIllegalDialect <mlir::BuiltinDialect, cir::CIRDialect,
4697
4702
mlir::func::FuncDialect>();
@@ -4729,6 +4734,13 @@ void ConvertCIRToLLVMPass::runOnOperation() {
4729
4734
buildGlobalAnnotationsVar (stringGlobalsMap, argStringGlobalsMap, argsVarMap);
4730
4735
}
4731
4736
4737
+ // / Set a hook to be called just before applying the dialect conversion so other
4738
+ // / dialects or patterns can be added
4739
+ void runAtStartOfConvertCIRToLLVMPass (
4740
+ std::function<void (mlir::ConversionTarget)> hook) {
4741
+ ConvertCIRToLLVMPass::runAtStartHook = std::move (hook);
4742
+ }
4743
+
4732
4744
std::unique_ptr<mlir::Pass> createConvertCIRToLLVMPass () {
4733
4745
return std::make_unique<ConvertCIRToLLVMPass>();
4734
4746
}
You can’t perform that action at this time.
0 commit comments