<div dir="ltr">Hi,<br><br>I'm wondering how can I write a global optimization pass in the LLVM backend. <br>What I'm going to do is to merge constant pool entries that are shared <br>between different machine functions and emit these shared entries <br>in proper places between the functions. <br><br>For example, if `foo` and `bar` use the same global variable `var`, I'd like to <br>generate something like the following:<br><br>foo:<br>    # code of foo<br>    # ....<br>    load r0, .LCPI_0<br>    load r0, r0    # load var<br>    # other code of foo<br><br>.LCPI_0:<br>    .long var # address of var<br><br>bar:<br>    # code of bar<br>    # ....<br>    load r0, .LCPI_0<br>    load r0, r0    # load var<br>    # other code of bar<br><br>The reason doing this is to reduce the code size as much as possible. <br>Our backend has a very limited PC-relative displacement for load/store instructions.<br>I've tried the way that ARM and MIPS backend do (ConstantIslandPass), <br>but it does not share constant pool entries between functions and <br>increases code size in general.<br><br>It is possible to write a moudle pass in machine instruction level? If possible, <br>how to do it? Any help is welcome. Thanks.<br><br>Cheers,<br>Huang<br></div>