Rust · 2363 bytes Raw Blame History
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_loop_with_remainder() {
32 let source = fixture("loop_partial_unroll_runtime.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 runtime partial-unroll path emits an `imod` in the preheader
42 // for the head_bound computation, and a `partial_remain_*` block
43 // for the scalar remainder loop.
44 assert!(
45 opt_ir.contains("imod"),
46 "expected imod in preheader (head_bound computation):\n{}",
47 opt_ir
48 );
49 assert!(
50 opt_ir.contains("partial_remain_"),
51 "expected partial_remain_* block (scalar remainder loop):\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], "33 561 33",
68 "runtime trip partial unroll wrong: {:?}",
69 trimmed[0]
70 );
71 }
72