Repository: JuliaLang/julia
File: src/pipeline.cpp (C++)

Code before:
    //We must recreate the analysis managers every time
    //so that analyses from previous runs of the pass manager
    //do not hang around for the next run
    StandardInstrumentations SI(M.getContext(), /*DebugLogging=*/false);
    PassInstrumentationCallbacks PIC;
    adjustPIC(PIC);
    TimePasses.registerCallbacks(PIC);

    // Register print callbacks if print options are set
    raw_ostream &OS = print_options.out ? *print_options.out : errs();
    bool should_print = print_options.print_before_all || print_options.print_after_all ||
                        !print_options.print_before.empty() || !print_options.print_after.empty();

    if (should_print) {
        if (print_options.print_before_all || !print_options.print_before.empty()) {
            PIC.registerBeforeNonSkippedPassCallback(
                [this, &OS, &M](StringRef PassID, Any IR) {
                    bool should_print_pass = print_options.print_before_all ||
                        PassID.contains(print_options.print_before);
                    if (!should_print_pass)
                        return;

                    // Check function filter if set
                    if (!print_options.filter_print_funcs.empty()) {
                        if (const auto *F = unwrapIR<Function>(IR)) {
                            if (!F->getName().contains(print_options.filter_print_funcs))
                                return;
                        }
                    }

                    OS << "*** IR Dump Before " << PassID << " ***\n";
                    if (print_options.print_module_scope) {
                        M.print(OS, nullptr);
                    } else {
                        printIR(OS, IR);
                    }
                });
        }

        if (print_options.print_after_all || !print_options.print_after.empty()) {
            PIC.registerAfterPassCallback(
                [this, &OS, &M](StringRef PassID, Any IR, const PreservedAnalyses &) {
                    bool should_print_pass = print_options.print_after_all ||
                        PassID.contains(print_options.print_after);
                    if (!should_print_pass)
                        return;

                    // Check function filter if set
                    if (!print_options.filter_print_funcs.empty()) {
                        if (const auto *F = unwrapIR<Function>(IR)) {
                            if (!F->getName().contains(print_options.filter_print_funcs))

Review comment (suggestion):
This should be a comma-separated list (e.g. use split in a loop when parsing, since the user also can pass this flag multiple times). See https://llvm.org/doxygen/CommandLine_8cpp.html#a030478956c379ec2bb71550cb0526fb6 (CommaSeparateAndAddOccurrence)

Code after:
    } else if (const auto *SCC = unwrapIR<LazyCallGraph::SCC>(IR)) {
        for (auto &CGN : *SCC) {
            Function &F = CGN.getFunction();
            F.print(OS);
        }
    } else {
        OS << "Unknown IR type\n";
    }
}

void NewPM::run(Module &M) {
    //We must recreate the analysis managers every time
    //so that analyses from previous runs of the pass manager
    //do not hang around for the next run
    StandardInstrumentations SI(M.getContext(), /*DebugLogging=*/false);
    PassInstrumentationCallbacks PIC;
    adjustPIC(PIC);
    TimePasses.registerCallbacks(PIC);

    // Register print callbacks if print options are set
    raw_ostream &OS = print_options.out ? *print_options.out : errs();

    // Print any errors from option parsing
    if (!print_options.error.empty()) {
        OS << print_options.error;
    }

    bool should_print = print_options.print_before_all || print_options.print_after_all ||
                        !print_options.print_before.empty() || !print_options.print_after.empty();

    // Helper to check if PassID matches any name in a list
    auto matchesAny = [](StringRef PassID, const SmallVector<std::string, 1> &names) JL_NOTSAFEPOINT -> bool {
        for (const auto &name : names) {
            if (PassID.contains(name))
                return true;
        }
        return false;
    };

    if (should_print) {
        if (print_options.print_before_all || !print_options.print_before.empty()) {
            PIC.registerBeforeNonSkippedPassCallback(
                [this, &OS, &M, &matchesAny](StringRef PassID, Any IR) {
                    bool should_print_pass = print_options.print_before_all ||
                        matchesAny(PassID, print_options.print_before);
                    if (!should_print_pass)
                        return;

                    // Check function filter if set
                    if (!print_options.filter_print_funcs.empty()) {
                        const Function *F = unwrapIR<Function>(IR);