[llvm-dev] Question about opt-report strings

Kaylor, Andrew via llvm-dev llvm-dev at lists.llvm.org
Mon Jan 6 12:51:17 PST 2020


Hi all,

I tried to poke my head into opt-report a while ago and didn't get very far. Now I'm looking at it again. I'm not sure I understand everything that's in place so my question here may be misguided.

I'm trying to understand the way strings are handled. When a remark is emitted, it seems that the string is constructed on the fly based on streaming inputs. For example,

  ORE->emit([&]() {
    return OptimizationRemark(DEBUG_TYPE, "LoadElim", LI)
           << "load of type " << NV("Type", LI->getType()) << " eliminated"
           << setExtraArgs() << " in favor of "
           << NV("InfavorOfValue", AvailableValue);
  });

There is some C++ magic going on behind the scenes here, and it makes for a nice interface, but I'm not clear about what ends up being stored where. I think within DiagnosticInfoOptimizationBase all the string parts of this get stored in a vector of name-value pairs with the unnamed strings just having an empty name. At some point, I guess this gets assembled into a single string? I've also found references to string tables for the bitstream serializer and a YAML format that uses a string table, but I'm not clear how and when these are constructed.

What I'm wondering is whether it would make sense to introduce a sort of message catalog, similar to the way diagnostics are handled in clang (which I must admit I also have only a partial understanding of). It seems like the RemarkName for optimization remarks somewhat serves as a unique identifier (?) but I would think an integer value of some sort would be better, so maybe I'm misunderstanding what RemarkName is being used for. I'm imagining something that would end up looking like this:

  ORE->emit([&]() {
    return OptimizationRemark(DEBUG_TYPE, diag::remark_gvn_load_elim, LI)
           << NV("Type", LI->getType())
           << setExtraArgs() << NV("InfavorOfValue", AvailableValue);
  });

with a tablegen file somewhere containing this:

def remark_gvn_load_elim: OptRemark<
  "LoadElim",                    // RemarkName (if this is needed for YAML output or whatever)
  "load of type %0 eliminated",  // Base format string for the remark (%Type instead of %0 maybe?)
  "in favor of %1">;             // Extra args format string for verbose output


Has this been discussed before?

Thanks,
Andy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200106/c748d22b/attachment.html>


More information about the llvm-dev mailing list