LLVM: Dump Module instead of Function in JIT mode (#16837)
commit0438397b8afc51aac45da55c155162e13e83cf19
authorEgor Bogatov <egorbo@gmail.com>
Mon, 16 Sep 2019 00:43:10 +0000 (16 03:43 +0300)
committerSteve Pfister <steveisok@users.noreply.github.com>
Mon, 16 Sep 2019 00:43:10 +0000 (15 20:43 -0400)
treeaac84b1a8f0d0ff67001d0655005cd14b7ffdcb2
parent304f3add20dcdb32a3c4c095779efba3a8f5bca1
LLVM: Dump Module instead of Function in JIT mode (#16837)

Since each function has its own module (in JIT mode) it makes sense to dump the whole module for MONO_VERBOSE_METHOD instead of just LLVM::Function.
It adds metadata, attributes and global variables (so it will be possible to copy-paste it to godbolt)

Example

static int Test(int x)
{
    return x / 10;
}

Diff for Unoptimized IR: https://www.diffchecker.com/NrF413Ts
Diff for Optimized IR: https://www.diffchecker.com/jbEkeFFS

So now we can see global variables and metadata for each function (and can easily paste them to godbolt.org)

NOTE: optimized IR for this case contains "dead" variables (dump_module allowed us to see such), we probably need some Module-wide optimizations to strip dead code such as -globaldce

NOTE2: why do we emit exceptions in the first place for this case at all?
mono/mini/mini-llvm-cpp.cpp
mono/mini/mini-llvm-cpp.h
mono/mini/mini-llvm.c