Kaarthik Alagapan via llvm-dev
2019-Oct-23 20:27 UTC
[llvm-dev] Inserting instructions when encountered a specific label
Hi Tim, Thank you for the quick response! so you'd probably check you're looking at a BranchInst and check BI->getSuccessor(0)->getName() (& 1 if it's conditional) I initially was printing out the result from getName() (I.getParent()->getName()) and it printed out nothing sadly. when parsing the instructions in SelectionDAGBuilder but it was only visiting instructions in the first/main BB and outputted %2. I'm not sure what's going on there, it would depend on which function you're modifying in SelectionDAG. I am calling it right after each instruction is visited in the visit(…) function. And it prints out the instruction’s number but it prints out only %2 when I call printAsOperand on the instruction’s parent, hence why I assumed that the visit function was going over only the main block. It's probably easier if it's before SelectionDAGBulder (or at the very beginning of its runOnFunction) so you can modify the IR without worrying about whether SelectionDAG will notice the new instructions. That’s true. I’m now trying to detect the specific label in the LLParser and hopefully can insert my instruction there. Would creating a new pseudo instruction be a good way to emit “.byte …” assembly code? Thank you, Kaarthik A. On Oct 23, 2019, 3:20 PM -0400, Tim Northover <t.p.northover at gmail.com>, wrote: Hi Kaarthik, On Wed, 23 Oct 2019 at 11:37, Kaarthik Alagapan via llvm-dev <llvm-dev at lists.llvm.org> wrote: I want to insert a new instruction when I encounter the true, false, and end labels (inside their respective blocks). I tried to detect the label names using " I.printAsOperand(errs(), false);” This function prints an instruction as it would be referred to in another instruction, so for example if the IR was %2 = alloca i32 then printAsOperand would print %2. It sounds like you want to introspect the operands, so you'd probably check you're looking at a BranchInst and check BI->getSuccessor(0)->getName() (& 1 if it's conditional). when parsing the instructions in SelectionDAGBuilder but it was only visiting instructions in the first/main BB and outputted %2. I'm not sure what's going on there, it would depend on which function you're modifying in SelectionDAG. Which pass or phase would be the best to see if the current block’s label matches “true”, “false”, or “end” and insert an instruction inside that block? To be honest, looking at block names is so hacky that it doesn't really matter where you put it (for example release mode compilers often don't add names at all, and generally it's perfectly valid as a transformation to drop them entirely). It's probably easier if it's before SelectionDAGBulder (or at the very beginning of its runOnFunction) so you can modify the IR without worrying about whether SelectionDAG will notice the new instructions. If you decide to keep doing this transformation in a more rigorous way long term, it would probably be put in a new pass (since I'd guess it would be implementing a change in semantics), but it's possible it could belong in an existing pass. Depends on exactly what the new instruction does. Cheers. Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191023/526ac329/attachment.html>
Kaarthik Alagapan via llvm-dev
2019-Oct-23 20:31 UTC
[llvm-dev] Inserting instructions when encountered a specific label
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title></title> </head> <body> </body> </html>
Tim Northover via llvm-dev
2019-Oct-23 20:42 UTC
[llvm-dev] Inserting instructions when encountered a specific label
On Wed, 23 Oct 2019 at 13:27, Kaarthik Alagapan <kaarthik at knights.ucf.edu> wrote:> I initially was printing out the result from getName() (I.getParent()->getName()) and it printed out nothing sadly. > > when parsing the instructions in SelectionDAGBuilder but it was only visiting instructions in the first/main BB and outputted %2.The instruction's parent is the (unnamed) entry block to the function (i.e. the block containing the instruction). By LLVM's automatic numbering system that's %2 in a function with two arguments. So yes, getName would return an empty string in that case.> I'm not sure what's going on there, it would depend on which function > you're modifying in SelectionDAG. > > I am calling it right after each instruction is visited in the visit(…) function. And it prints out the instruction’s number but it prints out only %2 when I call printAsOperand on the instruction’s parent, hence why I assumed that the visit function was going over only the main block.I'm afraid I still don't have anything very helpful to tell you about that.> That’s true. I’m now trying to detect the specific label in the LLParser and hopefully can insert my instruction there. Would creating a new pseudo instruction be a good way to emit “.byte …” assembly code?An intrinsic would probably be simpler. You need to modify a lot of places to invent a new instruction (LL parser, LL printer, Bitcode parser, Bitcode printer, Codegen, ...) Cheers. Tim.
Kaarthik Alagapan via llvm-dev
2019-Oct-23 20:47 UTC
[llvm-dev] Inserting instructions when encountered a specific label
Got it, thank you Tim! Kaarthik A. On Oct 23, 2019, 4:43 PM -0400, Tim Northover <t.p.northover at gmail.com>, wrote: On Wed, 23 Oct 2019 at 13:27, Kaarthik Alagapan <kaarthik at knights.ucf.edu> wrote: I initially was printing out the result from getName() (I.getParent()->getName()) and it printed out nothing sadly. when parsing the instructions in SelectionDAGBuilder but it was only visiting instructions in the first/main BB and outputted %2. The instruction's parent is the (unnamed) entry block to the function (i.e. the block containing the instruction). By LLVM's automatic numbering system that's %2 in a function with two arguments. So yes, getName would return an empty string in that case. I'm not sure what's going on there, it would depend on which function you're modifying in SelectionDAG. I am calling it right after each instruction is visited in the visit(…) function. And it prints out the instruction’s number but it prints out only %2 when I call printAsOperand on the instruction’s parent, hence why I assumed that the visit function was going over only the main block. I'm afraid I still don't have anything very helpful to tell you about that. That’s true. I’m now trying to detect the specific label in the LLParser and hopefully can insert my instruction there. Would creating a new pseudo instruction be a good way to emit “.byte …” assembly code? An intrinsic would probably be simpler. You need to modify a lot of places to invent a new instruction (LL parser, LL printer, Bitcode parser, Bitcode printer, Codegen, ...) Cheers. Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191023/f1857a82/attachment.html>