Skip to content

Commit 511dac2

Browse files
Add IRPrintConfig to the the enable_ir_print function.
Not yet used, but will determine how the Pass print is created. Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
1 parent c007ef7 commit 511dac2

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

hir/src/pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod statistics;
1010
pub use self::{
1111
analysis::{Analysis, AnalysisManager, OperationAnalysis, PreservedAnalyses},
1212
instrumentation::{PassInstrumentation, PassInstrumentor, PipelineParentInfo},
13-
manager::{Nesting, OpPassManager, PassDisplayMode, PassManager},
13+
manager::{IRPrintingConfig, Nesting, OpPassManager, PassDisplayMode, PassManager},
1414
pass::{OperationPass, Pass, PassExecutionState},
1515
registry::{PassInfo, PassPipelineInfo},
1616
specialization::PassTarget,

hir/src/pass/manager.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
use alloc::{boxed::Box, collections::BTreeMap, format, rc::Rc, string::ToString};
1+
use alloc::{
2+
boxed::Box,
3+
collections::BTreeMap,
4+
format,
5+
rc::Rc,
6+
string::{String, ToString},
7+
vec::Vec,
8+
};
29

310
use compact_str::{CompactString, ToCompactString};
4-
use midenc_session::diagnostics::Severity;
11+
use midenc_session::{diagnostics::Severity, Options};
512
use smallvec::{smallvec, SmallVec};
613

714
use super::{
@@ -29,13 +36,27 @@ pub enum PassDisplayMode {
2936

3037
// TODO(pauls)
3138
#[allow(unused)]
39+
#[derive(Default)]
3240
pub struct IRPrintingConfig {
3341
print_module_scope: bool,
3442
print_after_only_on_change: bool,
3543
print_after_only_on_failure: bool,
44+
// NOTE: Taken from the Options struct
45+
print_ir_after_all: bool,
46+
print_ir_after_pass: Vec<String>,
3647
flags: OpPrintingFlags,
3748
}
3849

50+
impl From<&Options> for IRPrintingConfig {
51+
fn from(options: &Options) -> Self {
52+
let mut irprintconfig = IRPrintingConfig::default();
53+
irprintconfig.print_ir_after_all = options.print_ir_after_all;
54+
irprintconfig.print_ir_after_pass = options.print_ir_after_pass.clone();
55+
56+
irprintconfig
57+
}
58+
}
59+
3960
/// The main pass manager and pipeline builder
4061
pub struct PassManager {
4162
context: Rc<Context>,
@@ -73,6 +94,7 @@ impl PassManager {
7394
///
7495
/// The created pass manager can schedule operations that match type `T`.
7596
pub fn on<T: OpRegistration>(context: Rc<Context>, nesting: Nesting) -> Self {
97+
// let a = context.session().options;
7698
Self::new(context, <T as OpRegistration>::full_name(), nesting)
7799
}
78100

@@ -169,12 +191,9 @@ impl PassManager {
169191
self
170192
}
171193

172-
// pub fn enable_ir_printing(&mut self, _config: IRPrintingConfig) {
173-
pub fn enable_ir_printing(&mut self) {
174-
// self.add_instrumentation(pi)
194+
pub fn enable_ir_printing(&mut self, _config: IRPrintingConfig) {
175195
let p = Box::new(Print::any());
176196
self.add_instrumentation(p);
177-
// todo!()
178197
}
179198

180199
pub fn enable_timing(&mut self, yes: bool) -> &mut Self {

midenc-compile/src/compiler.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,10 @@ impl Compiler {
503503
options.no_link = codegen.no_link;
504504
options.print_cfg_after_all = unstable.print_cfg_after_all;
505505
options.print_cfg_after_pass = unstable.print_cfg_after_pass;
506-
options.print_ir_after_all = unstable.print_ir_after_all;
506+
// options.print_ir_after_all = unstable.print_ir_after_all;
507+
options.print_ir_after_all = true;
507508
options.print_ir_after_pass = unstable.print_ir_after_pass;
509+
std::dbg!(&options);
508510

509511
// Establish --target-dir
510512
let target_dir = if self.target_dir.is_absolute() {

midenc-compile/src/stages/rewrite.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use alloc::boxed::Box;
33
use midenc_dialect_hir::transforms::TransformSpills;
44
use midenc_dialect_scf::transforms::LiftControlFlowToSCF;
55
use midenc_hir::{
6-
pass::{Nesting, PassManager},
6+
pass::{IRPrintingConfig, Nesting, PassManager},
77
patterns::{GreedyRewriteConfig, RegionSimplificationLevel},
88
Op,
99
};
@@ -22,6 +22,7 @@ impl Stage for ApplyRewritesStage {
2222
}
2323

2424
fn run(&mut self, input: Self::Input, context: Rc<Context>) -> CompilerResult<Self::Output> {
25+
let ir_print_config: IRPrintingConfig = (&context.as_ref().session().options).into();
2526
log::debug!(target: "driver", "applying rewrite passes");
2627
// TODO(pauls): Set up pass registration for new pass infra
2728
/*
@@ -49,7 +50,7 @@ impl Stage for ApplyRewritesStage {
4950

5051
// Construct a pass manager with the default pass pipeline
5152
let mut pm = PassManager::on::<builtin::World>(context.clone(), Nesting::Implicit);
52-
pm.enable_ir_printing();
53+
pm.enable_ir_printing(ir_print_config);
5354

5455
let mut rewrite_config = GreedyRewriteConfig::default();
5556
rewrite_config.with_region_simplification_level(RegionSimplificationLevel::Normal);

0 commit comments

Comments
 (0)