Hi Carlos, Jakob,<div><br></div><div>The PBQP allocator was designed to support a very wide range of constraints, and can handle something like this easily.</div><div><br></div><div>Say you have 4 of these orX/irX registers, then for any pair of virtual registers used in such an add instruction you would add the following constraint matrix to the PBQP instance:</div>
<div><br></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">[ 0 inf inf inf ]</span></div><div><font class="Apple-style-span" face="'courier new', monospace">[ inf 0 inf inf ]</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">[ inf inf 0 inf ]</font></div><div><font class="Apple-style-span" face="'courier new', monospace">[ inf inf inf 0 ]</font></div><div>
<br></div><div>The rows and columns of this matrix reflect the storage locations that the allocator can assign, and the elements represent the cost of a specific assignment. Say the rows represent the set { or1, or2, or3, or4 } and the columns represent { ir1, ir2, ir3, ir4 }. The infinite cost elements constrain the valid assignments to matching pairs.</div>
<div><br></div><div><br></div><div>Representing the constraint is dead easy, the trick would be making the allocator aware of the constraint. At present the PBQP allocator only "knows" about the basic RA constraints (aliasing, classes, interference, coalescing) described in LiveIntervals, MachineRegisterInfo and TargetRegisterInfo. I have been meaning to generalize this though.</div>
<div><br></div><div>The design I have in mind is this: We add a method to TargetRegisterInfo which returns a PBQPProblemBuilder for the target architectures. I implement a base PBQPProblemBuilder by simply lifting the current construction process out of the PBQP allocator and into its own class. Anyone (such as yourself, Carlos) who wants to represent more esoteric constraints in their architecture just extends this class, calls the base class to handle all the basic constraints, then performs their own pass over the function to add in their constraints:</div>
<div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">struct MyTargetPBQPProblemBuilder : public PBQPProblemBuilder {</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> PBQP::Graph* buildProblemFor(MachineFunction *mf) {</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> PBQP::Graph* g = PBQPProblemBuilder::buildProblemFor(mf);</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> // Add additional constraints for my architecture here.</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> return g;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div><div><font class="Apple-style-span" face="'courier new', monospace">}</font></div>
<div><br></div><div>Any thoughts or comments? I think this should be a very straightforward extension.</div><div><br></div><div>Cheers,</div><div>Lang.</div><div><br></div><div><br></div><div><br></div><div><br></div><div>
<br><br><div class="gmail_quote">On Wed, Sep 8, 2010 at 8:38 AM, Jakob Stoklund Olesen <span dir="ltr"><<a href="mailto:stoklund@2pi.dk">stoklund@2pi.dk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Sep 7, 2010, at 3:01 AM, Carlos Sanchez de La Lama wrote:<br>
<br>
> The machine I am targeting has some special requirements for some<br>
> operations, say:<br>
><br>
> ADD or1, ir1, r5<br>
><br>
> would add ir1 (input reg 1) and r5 and put the result in or1 (output reg<br>
> 1). The point id that input and output regs have to go paired (this<br>
> meaning an addition of ir1 with whatever always goes to or1, or an in<br>
> general irX + whatever goes to orX).<br>
><br>
> AFAIK, InstrInfo.td only allow "$src = $dst" type constraints. Is it<br>
> possible to describe more complex src/dst relations, like the one I<br>
> need?<br>
<br>
</div>No, that is the only type of constraint supported (besides register classes).<br>
<div class="im"><br>
> This latter way is probably too hackish and that's why I am having so<br>
> weird problems, but I have found no other way to achieve this. Is there<br>
> one?<br>
<br>
</div>It sounds like you need to present a more abstract architecture to the LLVM register allocator, but it is difficult to suggest one from the description you have given.<br>
<font color="#888888"><br>
/jakob<br>
</font><div><div></div><div class="h5"><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div>