Rust · 1847 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 #[test]
23 fn o2_fully_unrolls_small_do_concurrent_loop() {
24 let source = fixture("audit6_do_concurrent.f90");
25
26 let raw_ir = capture_text(
27 CaptureRequest {
28 input: source.clone(),
29 requested: BTreeSet::from([Stage::Ir]),
30 opt_level: OptLevel::O2,
31 },
32 Stage::Ir,
33 );
34 let opt_ir = capture_text(
35 CaptureRequest {
36 input: source,
37 requested: BTreeSet::from([Stage::OptIr]),
38 opt_level: OptLevel::O2,
39 },
40 Stage::OptIr,
41 );
42
43 assert!(
44 raw_ir.contains("doconc_check_")
45 && raw_ir.contains("doconc_body_")
46 && raw_ir.contains("doconc_incr_")
47 && raw_ir.contains("doconc_exit_"),
48 "lowered IR should preserve DO CONCURRENT loop identity:\n{}",
49 raw_ir
50 );
51 assert!(
52 !opt_ir.contains("doconc_check_")
53 && !opt_ir.contains("doconc_body_")
54 && !opt_ir.contains("doconc_incr_"),
55 "O2 optimized IR should fully unroll the small DO CONCURRENT loop:\n{}",
56 opt_ir
57 );
58 }
59