[llvm] Add option to dump IR to files intstead of stderr (PR #66412)

Nuri Amari via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 11:46:03 PDT 2023


================
@@ -684,9 +686,64 @@ PrintIRInstrumentation::~PrintIRInstrumentation() {
   assert(ModuleDescStack.empty() && "ModuleDescStack is not empty at exit");
 }
 
-void PrintIRInstrumentation::pushModuleDesc(StringRef PassID, Any IR) {
+static SmallString<32> getIRDisplayName(Any IR) {
+
+  auto hashName = [](StringRef name) {
----------------
NuriAmari wrote:

Hashing creates less readable log names, but serves two purposes:

- Ensures file names are of a legal length
- Without hashing you must truncate the module name etc, which leads to name collisions (ie. two modules with a similar name processed by different threads during thinLTO can have the same log file name)
- We could ensure unique filenames by checking which files already exist, and picking a new random available name, but this can quickly bloat the ir dump directory between successive runs
- Hashing is not guaranteed to be stable between executions, so the output files aren't necessarily the same between runs

It is quite easy to find the file you care about with grep, so I think this is a good compromise between the options

https://github.com/llvm/llvm-project/pull/66412


More information about the llvm-commits mailing list