Instrument IL while doing AOT compilation #104522
-
Hi, I'd like to ask for some hints about the following. I want to modify the building process when So far, I understand that no API can register an IL transformation when native code is generated. Where could I start looking to hack this? Finding a place where I could hook this is more than enough for my purpose. To provide more context, I want to do a simple CFG analysis and add a few instructions before control-flow instructions on all lowered IL methods. Any help or advice is appreciated! Best, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
There are two possible approaches: after the IL is produced, or before the IL was processed to JIT. IL in assembly files are compiled in the Another approach is to hook everything passed into JIT. The entry point of compiling method in ILCompiler is at runtime/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/RyuJitCompilation.cs Lines 179 to 183 in 4addcaa You can insert some hook here and try to do transformations on the IL. Anyway, there's no direct interface provided and may require custom built toolchains. It should be OK for research projects. /cc @dotnet/ilc-contrib |
Beta Was this translation helpful? Give feedback.
There are two possible approaches: after the IL is produced, or before the IL was processed to JIT.
IL in assembly files are compiled in the
IlcCompile
msbuild target. Insert a msbuild target before it can get all referenced assembly files, and transform all of them. There are some special methods provided by the execution engine, like methods of array and delegates, but generally they can be considered as trusted.Another approach is to hook everything passed into JIT. The entry point of compiling method in ILCompiler is at
RyuJitCompilation.CompileSingleMethod
:runtime/src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/RyuJitCompilation.cs
Lines 179 to 183 in 4addcaa