[llvm-dev] Passing inormation from pass to lowering

Reid Kleckner via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 30 15:55:18 PDT 2020


I'd recommend looking at how tail call lowering is implemented. The
TAILJMP* family of pseudo instructions are modelled as calls throughout
CodeGen, but later in X86MCInstLower.cpp they are translated to plain JMP
instructions. This avoids branch folding and the like from assuming things
about the control flow of blocks ending in JMP_1. Similarly, you probably
need to define a family of such call-like pseudo instructions, and lower
them later.

Alternatively, you could try to get by without new instructions, and
instead staple a bunch of extra special operands to the regular CALL*
family of instructions. Later, you would change the way such instructions
are "printed" depending on the presence of your operand. CALL* is a
variadic instruction, so you can put more or less anything in the operand
list, such as perhaps metadata. This approach runs the risk of rewriting
CALL instructions that didn't carry your special annotations, or having
other CodeGen passes fold call instructions in ways that are incompatible
with your transformation.

On Mon, Mar 30, 2020 at 1:04 PM Felix Berlakovich <felix at berlakovich.at>
wrote:

> The one thing I can‘t seem to figure out is how to lower a jump to another
> function at any stage before AsmPrinter. The methods to construct an
> unconditional branch always seem to expect a (machine) basic block and I
> don’t know how to get the first basic block of **another** function.
>
>
>
> Is DAG.getNode(ISD::BR, dl, MVT::Other, ???) the right approach?
>
> And why isn’t there a X86::BR, but only a X86::BRCOND?
>
>
>
> The only implementation I could find that actually creates a jump to a
> function is Readactor (https://github.com/securesystemslab/multicompiler),
> but it does it in the AsmPrinter.
>
>
>
> Thanks for your help!
>
>
>
> Regards
>
>
>
> Felix
>
>
>
> *Von:* Reid Kleckner <rnk at google.com>
> *Gesendet:* Samstag, 28. März 2020 17:42
> *An:* Felix Berlakovich <felix at berlakovich.at>
> *Cc:* llvm-dev at lists.llvm.org
> *Betreff:* Re: [llvm-dev] Passing inormation from pass to lowering
>
>
>
> I would encourage you to look at the "cfguard" bundle added for Windows
> Control Flow Integrity. AsmPrinter is probably far too late for the
> transform you want to do. You probably need to implement it somewhere in
> call lowering, so assuming this is for x86, you would implement this in
> X86ISelLowering::LowerCall.
>
>
>
> I think it would be less invasive to attach your metadata to the existing
> call instructions, and then change code generation later, rather than
> replacing the IR instructions completely.
>
> The implementation for cfguard is mostly here:
>
>
> http://github.com/llvm/llvm-project/commit/d157a9bc8ba1085cc4808c6941412322a7fd884e
>
>
>
>
> On Fri, Mar 27, 2020 at 1:28 AM Felix Berlakovich via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
> Hi!
>
>
>
> I have written a ModulePass that calculates various things and adds custom
> metadata attributes to certain instructions. Depending on the attributes, I
> would like to change the machine code of these instructions. For example, I
> would like to replace certain calls with jumps, but as far as I can tell
> the IR metadata is not accessible anymore on the level of machine
> instructions (e.g. in the AsmPrinter). What is the best way to pass the
> information calculated by the pass (e.g the attributes) to the part where
> the target specific instructions are emitted?
>
>
>
> Regards
>
>
>
> Felix
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200330/9bbff398/attachment-0001.html>


More information about the llvm-dev mailing list