<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<div name="messageBodySection">
<div dir="auto">Hi Tim,
<div dir="auto">Thank you for the quick response!</div>
<div dir="auto"><br>
</div>
<div dir="auto">
<blockquote type="cite" class="spark_quote" style="caret-color: rgb(213, 218, 222); margin: 5px; padding-left: 10px; border-left-width: thin; border-left-style: solid; border-left-color: rgb(26, 188, 156);">
so you'd probably check you're looking at a<br>
BranchInst and check BI->getSuccessor(0)->getName() (& 1 if it's<br>
conditional)</blockquote>
I initially was printing out the result from getName() (I.getParent()->getName()) and it printed out nothing sadly.</div>
<div dir="auto"><br>
</div>
<div dir="auto">
<blockquote type="cite" class="spark_quote" style="caret-color: rgb(213, 218, 222); margin: 5px; padding-left: 10px; border-left-width: thin; border-left-style: solid; border-left-color: rgb(26, 188, 156);">
<blockquote type="cite" class="spark_quote" style="margin: 5px; padding-left: 10px; border-left-width: thin; border-left-style: solid; border-left-color: rgb(230, 126, 34);">
when parsing the instructions in SelectionDAGBuilder but it was only visiting instructions in the first/main BB and outputted %2.<br>
</blockquote>
<br>
I'm not sure what's going on there, it would depend on which function<br>
you're modifying in SelectionDAG.</blockquote>
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.</div>
<div dir="auto"><br>
</div>
<div dir="auto">
<blockquote type="cite" class="spark_quote" style="caret-color: rgb(213, 218, 222); margin: 5px; padding-left: 10px; border-left-width: thin; border-left-style: solid; border-left-color: rgb(26, 188, 156);">
It's probably easier if it's<br>
before SelectionDAGBulder (or at the very beginning of its<br>
runOnFunction) so you can modify the IR without worrying about whether<br>
SelectionDAG will notice the new instructions.</blockquote>
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?</div>
<div dir="auto"><br>
</div>
<div dir="auto">Thank you,</div>
<div dir="auto">Kaarthik A.</div>
</div>
</div>
<div name="messageReplySection">On Oct 23, 2019, 3:20 PM -0400, Tim Northover <t.p.northover@gmail.com>, wrote:<br>
<blockquote type="cite" class="spark_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
Hi Kaarthik,<br>
<br>
On Wed, 23 Oct 2019 at 11:37, Kaarthik Alagapan via llvm-dev<br>
<llvm-dev@lists.llvm.org> wrote:<br>
<blockquote type="cite" class="spark_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
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);”<br>
</blockquote>
<br>
This function prints an instruction as it would be referred to in<br>
another instruction, so for example if the IR was<br>
<br>
%2 = alloca i32<br>
<br>
then printAsOperand would print %2. It sounds like you want to<br>
introspect the operands, so you'd probably check you're looking at a<br>
BranchInst and check BI->getSuccessor(0)->getName() (& 1 if it's<br>
conditional).<br>
<br>
<blockquote type="cite" class="spark_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
when parsing the instructions in SelectionDAGBuilder but it was only visiting instructions in the first/main BB and outputted %2.<br>
</blockquote>
<br>
I'm not sure what's going on there, it would depend on which function<br>
you're modifying in SelectionDAG.<br>
<br>
<blockquote type="cite" class="spark_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
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?<br>
</blockquote>
<br>
To be honest, looking at block names is so hacky that it doesn't<br>
really matter where you put it (for example release mode compilers<br>
often don't add names at all, and generally it's perfectly valid as a<br>
transformation to drop them entirely). It's probably easier if it's<br>
before SelectionDAGBulder (or at the very beginning of its<br>
runOnFunction) so you can modify the IR without worrying about whether<br>
SelectionDAG will notice the new instructions.<br>
<br>
If you decide to keep doing this transformation in a more rigorous way<br>
long term, it would probably be put in a new pass (since I'd guess it<br>
would be implementing a change in semantics), but it's possible it<br>
could belong in an existing pass. Depends on exactly what the new<br>
instruction does.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
</blockquote>
</div>
</body>
</html>