@@ -0,0 +1,71 @@ |
| | 1 | +use std::collections::BTreeSet; |
| | 2 | +use std::path::PathBuf; |
| | 3 | + |
| | 4 | +use armfortas::driver::OptLevel; |
| | 5 | +use armfortas::testing::{capture_from_path, CaptureRequest, CapturedStage, Stage}; |
| | 6 | + |
| | 7 | +fn fixture(name: &str) -> PathBuf { |
| | 8 | + let path = PathBuf::from("test_programs").join(name); |
| | 9 | + assert!(path.exists(), "missing test fixture {}", path.display()); |
| | 10 | + path |
| | 11 | +} |
| | 12 | + |
| | 13 | +fn capture_text(request: CaptureRequest, stage: Stage) -> String { |
| | 14 | + let result = capture_from_path(&request).expect("capture should succeed"); |
| | 15 | + match result.get(stage) { |
| | 16 | + Some(CapturedStage::Text(text)) => text.clone(), |
| | 17 | + Some(CapturedStage::Run(_)) => panic!("expected text stage for {}", stage.as_str()), |
| | 18 | + None => panic!("missing requested stage {}", stage.as_str()), |
| | 19 | + } |
| | 20 | +} |
| | 21 | + |
| | 22 | +fn capture_run_stdout(request: CaptureRequest) -> String { |
| | 23 | + let result = capture_from_path(&request).expect("capture should succeed"); |
| | 24 | + match result.get(Stage::Run) { |
| | 25 | + Some(CapturedStage::Run(run)) => run.stdout.clone(), |
| | 26 | + _ => panic!("missing run stage"), |
| | 27 | + } |
| | 28 | +} |
| | 29 | + |
| | 30 | +#[test] |
| | 31 | +fn o2_partial_unrolls_runtime_trip_reduction_with_remainder() { |
| | 32 | + let source = fixture("loop_partial_unroll_runtime_red.f90"); |
| | 33 | + let opt_ir = capture_text( |
| | 34 | + CaptureRequest { |
| | 35 | + input: source.clone(), |
| | 36 | + requested: BTreeSet::from([Stage::OptIr]), |
| | 37 | + opt_level: OptLevel::O2, |
| | 38 | + }, |
| | 39 | + Stage::OptIr, |
| | 40 | + ); |
| | 41 | + // The reduction loop's remainder header takes 2 params (iv + |
| | 42 | + // acc); the iv-only store loop's remainder header takes only 1. |
| | 43 | + // Both should appear in the IR. |
| | 44 | + let two_param_remain = opt_ir |
| | 45 | + .lines() |
| | 46 | + .filter(|l| l.contains("partial_remain_header")) |
| | 47 | + .filter(|l| l.matches(": i32").count() == 2) |
| | 48 | + .count(); |
| | 49 | + assert!( |
| | 50 | + two_param_remain >= 1, |
| | 51 | + "expected a 2-param partial_remain_header (iv + acc):\n{}", |
| | 52 | + opt_ir |
| | 53 | + ); |
| | 54 | + |
| | 55 | + let stdout = capture_run_stdout(CaptureRequest { |
| | 56 | + input: source, |
| | 57 | + requested: BTreeSet::from([Stage::Run]), |
| | 58 | + opt_level: OptLevel::O2, |
| | 59 | + }); |
| | 60 | + let trimmed: Vec<&str> = stdout |
| | 61 | + .lines() |
| | 62 | + .map(|l| l.trim()) |
| | 63 | + .filter(|l| !l.is_empty()) |
| | 64 | + .collect(); |
| | 65 | + assert_eq!(trimmed.len(), 1, "expected one print line:\n{}", stdout); |
| | 66 | + assert_eq!( |
| | 67 | + trimmed[0], "35 14910 1225", |
| | 68 | + "runtime reduction partial unroll wrong: {:?}", |
| | 69 | + trimmed[0] |
| | 70 | + ); |
| | 71 | +} |