| 36 | using absl::string_view; |
| 37 | |
| 38 | struct CanonicalDebugOptions { |
| 39 | explicit CanonicalDebugOptions(const DebugOptions& opts) |
| 40 | : dump_to(opts.xla_dump_to()), |
| 41 | dump_as_text(opts.xla_dump_hlo_as_text()), |
| 42 | dump_as_proto(opts.xla_dump_hlo_as_proto()), |
| 43 | dump_as_dot(opts.xla_dump_hlo_as_dot()), |
| 44 | dump_as_html(opts.xla_dump_hlo_as_html()), |
| 45 | dump_as_url(opts.xla_dump_hlo_as_url()), |
| 46 | dump_snapshots(opts.xla_dump_hlo_snapshots()), |
| 47 | dump_include_timestamp(opts.xla_dump_include_timestamp()), |
| 48 | dump_max_hlo_modules(opts.xla_dump_max_hlo_modules()) { |
| 49 | // This constructor examines the values in `opts` and turns on other flags |
| 50 | // based on what we think is the user's intent. To reduce confusion about |
| 51 | // what was a user-specified value versus an extrapolated value, within this |
| 52 | // function we treat this struct's members as write-only, and read only from |
| 53 | // `opts`. |
| 54 | |
| 55 | // Did the user specify an explicit format for dumping? |
| 56 | bool output_format_other_than_url_specified = |
| 57 | opts.xla_dump_hlo_as_text() || opts.xla_dump_hlo_as_proto() || |
| 58 | opts.xla_dump_hlo_as_dot() || opts.xla_dump_hlo_as_html() || |
| 59 | opts.xla_dump_hlo_snapshots(); |
| 60 | bool output_format_specified = |
| 61 | output_format_other_than_url_specified || opts.xla_dump_hlo_as_url(); |
| 62 | |
| 63 | // If we haven't specified an output format, default to dumping as text. |
| 64 | if (!output_format_specified) { |
| 65 | dump_as_text = true; |
| 66 | } |
| 67 | |
| 68 | // If dump_to is empty, default to dumping to stdout, so long as some dump |
| 69 | // format other than dump-as-url was specified. If the user only specified |
| 70 | // --xla_dump_hlo_as_url, then don't dump to stdout, that is likely noise |
| 71 | // they don't want. |
| 72 | if (opts.xla_dump_to().empty() && output_format_other_than_url_specified) { |
| 73 | dump_to = "-"; |
| 74 | } |
| 75 | |
| 76 | // If we specified a regular expression restricting which modules to dump, |
| 77 | // respect that. |
| 78 | // |
| 79 | // If we didn't specify which modules to dump but we passed some other flag |
| 80 | // which implies dumping modules, dump all modules. |
| 81 | // |
| 82 | // Otherwise, don't dump any HLO modules. |
| 83 | if (!opts.xla_dump_hlo_module_re().empty()) { |
| 84 | // RE2 object is not copyable, and we can't capture "by move", so we |
| 85 | // resort to this hack. |
| 86 | string pattern = opts.xla_dump_hlo_module_re(); |
| 87 | should_dump_module = [pattern](string_view module_name) { |
| 88 | return RE2::PartialMatch(string(module_name), pattern); |
| 89 | }; |
| 90 | } else if (!opts.xla_dump_hlo_pass_re().empty() || |
| 91 | !opts.xla_dump_to().empty() || output_format_specified) { |
| 92 | should_dump_module = [](string_view) { return true; }; |
| 93 | } else { |
| 94 | should_dump_module = [](string_view) { return false; }; |
| 95 | } |
no outgoing calls
no test coverage detected