<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Sep 21, 2010, at 6:19 AM, Lang Hames wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Author: lhames<br>Date: Tue Sep 21 08:19:36 2010<br>New Revision: 114429<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=114429&view=rev">http://llvm.org/viewvc/llvm-project?rev=114429&view=rev</a><br>Log:<br>Added an additional PBQP problem builder which adds coalescing costs (both between pairs of virtuals, and between virtuals and physicals).<br></div></blockquote><br><blockquote type="cite"><div>+std::auto_ptr<PBQPRAProblem> PBQPBuilderWithCoalescing::build(<br>+                                                MachineFunction *mf,<br>+                                                const LiveIntervals *lis,<br>+                                                const MachineLoopInfo *loopInfo,<br>+                                                const RegSet &vregs) {<br>+<br>+  std::auto_ptr<PBQPRAProblem> p = PBQPBuilder::build(mf, lis, loopInfo, vregs);<br>+  PBQP::Graph &g = p->getGraph();<br>+<br>+  const TargetMachine &tm = mf->getTarget();<br>+  CoalescerPair cp(*tm.getInstrInfo(), *tm.getRegisterInfo());<br></div></blockquote><div><br></div><div>Yay!</div><br><blockquote type="cite"><div>+<br>+  // Scan the machine function and add a coalescing cost whenever CoalescerPair<br>+  // gives the Ok.<br>+  for (MachineFunction::const_iterator mbbItr = mf->begin(),<br>+                                       mbbEnd = mf->end();<br>+       mbbItr != mbbEnd; ++mbbItr) {<br>+    const MachineBasicBlock *mbb = &*mbbItr;<br>+<br>+    for (MachineBasicBlock::const_iterator miItr = mbb->begin(),<br>+                                           miEnd = mbb->end();<br>+         miItr != miEnd; ++miItr) {<br>+      const MachineInstr *mi = &*miItr;<br>+<br>+      if (!mi->isCopy() && !mi->isSubregToReg())<br>+        continue; // Not coalescable.<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><div><br></div><div>This is pretty much the first line of setRegisters(), but it is harmless.</div><br><blockquote type="cite"><div>+      if (!cp.setRegisters(mi))<br>+        continue; // Not coalescable.<br>+<br>+      if (cp.getSrcReg() == cp.getDstReg())<br>+        continue; // Already coalesced.<br>+<br>+      if (cp.isCoalescable(mi)) {<br></div></blockquote><div><br></div><div>Note that isCoalescable(mi) is implied by setRegisters(mi) returning true. This method is intended to check whether a second copy instruction is compatible with the one given to setRegisters. Is is possible to have a copy between src and dst that is not compatible - it may copy different subregisters.</div><br><blockquote type="cite"><div>+<br>+        unsigned dst = cp.getDstReg(),<br>+                 src = cp.getSrcReg();<br>+<br></div></blockquote><div><br></div><div>CoalescerPair can also handle subregister joins. In that case SrcReg is joined with a subregister of DstReg indicated by getSubIdx().</div><div><br></div><div>This is only relevant when joining two virtual registers. When DstReg is a physreg, it is simply adjusted so no SubIdx is necessary.</div></div><br><div><br></div></body></html>