Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 1 | //===-- TwoAddressInstructionPass.cpp - Two-Address instruction pass ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Alkis Evlogimenos | 50c047d | 2004-01-04 23:09:24 +0000 | [diff] [blame] | 10 | // This file implements the TwoAddress instruction pass which is used |
| 11 | // by most register allocators. Two-Address instructions are rewritten |
| 12 | // from: |
| 13 | // |
| 14 | // A = B op C |
| 15 | // |
| 16 | // to: |
| 17 | // |
| 18 | // A = B |
Alkis Evlogimenos | 14be640 | 2004-02-04 22:17:40 +0000 | [diff] [blame] | 19 | // A op= C |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 20 | // |
Alkis Evlogimenos | 14be640 | 2004-02-04 22:17:40 +0000 | [diff] [blame] | 21 | // Note that if a register allocator chooses to use this pass, that it |
| 22 | // has to be capable of handling the non-SSA nature of these rewritten |
| 23 | // virtual registers. |
| 24 | // |
| 25 | // It is also worth noting that the duplicate operand of the two |
| 26 | // address instruction is removed. |
Chris Lattner | bd91c1c | 2004-01-31 21:07:15 +0000 | [diff] [blame] | 27 | // |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
| 29 | |
| 30 | #define DEBUG_TYPE "twoaddrinstr" |
Chris Lattner | bd91c1c | 2004-01-31 21:07:15 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/Passes.h" |
Chris Lattner | 1e31363 | 2004-07-21 23:17:57 +0000 | [diff] [blame] | 32 | #include "llvm/Function.h" |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/LiveVariables.h" |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 35 | #include "llvm/CodeGen/MachineInstr.h" |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 38 | #include "llvm/Analysis/AliasAnalysis.h" |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 39 | #include "llvm/Target/TargetRegisterInfo.h" |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 40 | #include "llvm/Target/TargetInstrInfo.h" |
| 41 | #include "llvm/Target/TargetMachine.h" |
Owen Anderson | 95dad83 | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 42 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 43 | #include "llvm/Support/Debug.h" |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 45 | #include "llvm/ADT/BitVector.h" |
| 46 | #include "llvm/ADT/DenseMap.h" |
Dan Gohman | d68a076 | 2009-01-05 17:59:02 +0000 | [diff] [blame] | 47 | #include "llvm/ADT/SmallSet.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 48 | #include "llvm/ADT/Statistic.h" |
| 49 | #include "llvm/ADT/STLExtras.h" |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 50 | using namespace llvm; |
| 51 | |
Chris Lattner | cd3245a | 2006-12-19 22:41:21 +0000 | [diff] [blame] | 52 | STATISTIC(NumTwoAddressInstrs, "Number of two-address instructions"); |
| 53 | STATISTIC(NumCommuted , "Number of instructions commuted to coalesce"); |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 54 | STATISTIC(NumAggrCommuted , "Number of instructions aggressively commuted"); |
Chris Lattner | cd3245a | 2006-12-19 22:41:21 +0000 | [diff] [blame] | 55 | STATISTIC(NumConvertedTo3Addr, "Number of instructions promoted to 3-address"); |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 56 | STATISTIC(Num3AddrSunk, "Number of 3-address instructions sunk"); |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 57 | STATISTIC(NumReMats, "Number of instructions re-materialized"); |
Evan Cheng | 28c7ce3 | 2009-02-21 03:14:25 +0000 | [diff] [blame] | 58 | STATISTIC(NumDeletes, "Number of dead instructions deleted"); |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 59 | |
| 60 | namespace { |
Nick Lewycky | 6726b6d | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 61 | class TwoAddressInstructionPass : public MachineFunctionPass { |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 62 | const TargetInstrInfo *TII; |
| 63 | const TargetRegisterInfo *TRI; |
| 64 | MachineRegisterInfo *MRI; |
| 65 | LiveVariables *LV; |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 66 | AliasAnalysis *AA; |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 67 | |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 68 | // DistanceMap - Keep track the distance of a MI from the start of the |
| 69 | // current basic block. |
| 70 | DenseMap<MachineInstr*, unsigned> DistanceMap; |
| 71 | |
| 72 | // SrcRegMap - A map from virtual registers to physical registers which |
| 73 | // are likely targets to be coalesced to due to copies from physical |
| 74 | // registers to virtual registers. e.g. v1024 = move r0. |
| 75 | DenseMap<unsigned, unsigned> SrcRegMap; |
| 76 | |
| 77 | // DstRegMap - A map from virtual registers to physical registers which |
| 78 | // are likely targets to be coalesced to due to copies to physical |
| 79 | // registers from virtual registers. e.g. r1 = move v1024. |
| 80 | DenseMap<unsigned, unsigned> DstRegMap; |
| 81 | |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 82 | /// RegSequences - Keep track the list of REG_SEQUENCE instructions seen |
| 83 | /// during the initial walk of the machine function. |
| 84 | SmallVector<MachineInstr*, 16> RegSequences; |
| 85 | |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 86 | bool Sink3AddrInstruction(MachineBasicBlock *MBB, MachineInstr *MI, |
| 87 | unsigned Reg, |
| 88 | MachineBasicBlock::iterator OldPos); |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 89 | |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 90 | bool isProfitableToReMat(unsigned Reg, const TargetRegisterClass *RC, |
Evan Cheng | 601ca4b | 2008-06-25 01:16:38 +0000 | [diff] [blame] | 91 | MachineInstr *MI, MachineInstr *DefMI, |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 92 | MachineBasicBlock *MBB, unsigned Loc); |
Evan Cheng | 8191371 | 2009-01-23 23:27:33 +0000 | [diff] [blame] | 93 | |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 94 | bool NoUseAfterLastDef(unsigned Reg, MachineBasicBlock *MBB, unsigned Dist, |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 95 | unsigned &LastDef); |
| 96 | |
Evan Cheng | e9ccb3a | 2009-04-28 02:12:36 +0000 | [diff] [blame] | 97 | MachineInstr *FindLastUseInMBB(unsigned Reg, MachineBasicBlock *MBB, |
| 98 | unsigned Dist); |
| 99 | |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 100 | bool isProfitableToCommute(unsigned regB, unsigned regC, |
| 101 | MachineInstr *MI, MachineBasicBlock *MBB, |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 102 | unsigned Dist); |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 103 | |
Evan Cheng | 8191371 | 2009-01-23 23:27:33 +0000 | [diff] [blame] | 104 | bool CommuteInstruction(MachineBasicBlock::iterator &mi, |
| 105 | MachineFunction::iterator &mbbi, |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 106 | unsigned RegB, unsigned RegC, unsigned Dist); |
| 107 | |
Evan Cheng | e6f350d | 2009-03-30 21:34:07 +0000 | [diff] [blame] | 108 | bool isProfitableToConv3Addr(unsigned RegA); |
| 109 | |
| 110 | bool ConvertInstTo3Addr(MachineBasicBlock::iterator &mi, |
| 111 | MachineBasicBlock::iterator &nmi, |
| 112 | MachineFunction::iterator &mbbi, |
| 113 | unsigned RegB, unsigned Dist); |
| 114 | |
Bob Wilson | 326f438 | 2009-09-01 22:51:08 +0000 | [diff] [blame] | 115 | typedef std::pair<std::pair<unsigned, bool>, MachineInstr*> NewKill; |
| 116 | bool canUpdateDeletedKills(SmallVector<unsigned, 4> &Kills, |
| 117 | SmallVector<NewKill, 4> &NewKills, |
| 118 | MachineBasicBlock *MBB, unsigned Dist); |
| 119 | bool DeleteUnusedInstr(MachineBasicBlock::iterator &mi, |
| 120 | MachineBasicBlock::iterator &nmi, |
Jakob Stoklund Olesen | 0b25ae1 | 2009-11-18 21:33:35 +0000 | [diff] [blame] | 121 | MachineFunction::iterator &mbbi, unsigned Dist); |
Bob Wilson | 326f438 | 2009-09-01 22:51:08 +0000 | [diff] [blame] | 122 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 123 | bool TryInstructionTransform(MachineBasicBlock::iterator &mi, |
| 124 | MachineBasicBlock::iterator &nmi, |
| 125 | MachineFunction::iterator &mbbi, |
| 126 | unsigned SrcIdx, unsigned DstIdx, |
| 127 | unsigned Dist); |
| 128 | |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 129 | void ProcessCopy(MachineInstr *MI, MachineBasicBlock *MBB, |
| 130 | SmallPtrSet<MachineInstr*, 8> &Processed); |
Evan Cheng | 3a3cce5 | 2009-08-07 00:28:58 +0000 | [diff] [blame] | 131 | |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 132 | void CoalesceExtSubRegs(SmallVector<unsigned,4> &Srcs, unsigned DstReg); |
| 133 | |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 134 | /// EliminateRegSequences - Eliminate REG_SEQUENCE instructions as part |
| 135 | /// of the de-ssa process. This replaces sources of REG_SEQUENCE as |
| 136 | /// sub-register references of the register defined by REG_SEQUENCE. |
| 137 | bool EliminateRegSequences(); |
Evan Cheng | c6dcce3 | 2010-05-17 23:24:12 +0000 | [diff] [blame] | 138 | |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 139 | public: |
Nick Lewycky | ecd94c8 | 2007-05-06 13:37:16 +0000 | [diff] [blame] | 140 | static char ID; // Pass identification, replacement for typeid |
Owen Anderson | 081c34b | 2010-10-19 17:21:58 +0000 | [diff] [blame] | 141 | TwoAddressInstructionPass() : MachineFunctionPass(ID) { |
| 142 | initializeTwoAddressInstructionPassPass(*PassRegistry::getPassRegistry()); |
| 143 | } |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 144 | |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 145 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
Dan Gohman | 845012e | 2009-07-31 23:37:33 +0000 | [diff] [blame] | 146 | AU.setPreservesCFG(); |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 147 | AU.addRequired<AliasAnalysis>(); |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 148 | AU.addPreserved<LiveVariables>(); |
| 149 | AU.addPreservedID(MachineLoopInfoID); |
| 150 | AU.addPreservedID(MachineDominatorsID); |
Owen Anderson | 95dad83 | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 151 | if (StrongPHIElim) |
| 152 | AU.addPreservedID(StrongPHIEliminationID); |
| 153 | else |
| 154 | AU.addPreservedID(PHIEliminationID); |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 155 | MachineFunctionPass::getAnalysisUsage(AU); |
| 156 | } |
Alkis Evlogimenos | 4c08086 | 2003-12-18 22:40:24 +0000 | [diff] [blame] | 157 | |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 158 | /// runOnMachineFunction - Pass entry point. |
Misha Brukman | 75fa4e4 | 2004-07-22 15:26:23 +0000 | [diff] [blame] | 159 | bool runOnMachineFunction(MachineFunction&); |
| 160 | }; |
Chris Lattner | d74ea2b | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 161 | } |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 162 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 163 | char TwoAddressInstructionPass::ID = 0; |
Owen Anderson | 2ab36d3 | 2010-10-12 19:48:12 +0000 | [diff] [blame] | 164 | INITIALIZE_PASS_BEGIN(TwoAddressInstructionPass, "twoaddressinstruction", |
| 165 | "Two-Address instruction pass", false, false) |
| 166 | INITIALIZE_AG_DEPENDENCY(AliasAnalysis) |
| 167 | INITIALIZE_PASS_END(TwoAddressInstructionPass, "twoaddressinstruction", |
Owen Anderson | ce665bd | 2010-10-07 22:25:06 +0000 | [diff] [blame] | 168 | "Two-Address instruction pass", false, false) |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 169 | |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 170 | char &llvm::TwoAddressInstructionPassID = TwoAddressInstructionPass::ID; |
Alkis Evlogimenos | 4c08086 | 2003-12-18 22:40:24 +0000 | [diff] [blame] | 171 | |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 172 | /// Sink3AddrInstruction - A two-address instruction has been converted to a |
| 173 | /// three-address instruction to avoid clobbering a register. Try to sink it |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 174 | /// past the instruction that would kill the above mentioned register to reduce |
| 175 | /// register pressure. |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 176 | bool TwoAddressInstructionPass::Sink3AddrInstruction(MachineBasicBlock *MBB, |
| 177 | MachineInstr *MI, unsigned SavedReg, |
| 178 | MachineBasicBlock::iterator OldPos) { |
| 179 | // Check if it's safe to move this instruction. |
| 180 | bool SeenStore = true; // Be conservative. |
Evan Cheng | ac1abde | 2010-03-02 19:03:01 +0000 | [diff] [blame] | 181 | if (!MI->isSafeToMove(TII, AA, SeenStore)) |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 182 | return false; |
| 183 | |
| 184 | unsigned DefReg = 0; |
| 185 | SmallSet<unsigned, 4> UseRegs; |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 186 | |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 187 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 188 | const MachineOperand &MO = MI->getOperand(i); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 189 | if (!MO.isReg()) |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 190 | continue; |
| 191 | unsigned MOReg = MO.getReg(); |
| 192 | if (!MOReg) |
| 193 | continue; |
| 194 | if (MO.isUse() && MOReg != SavedReg) |
| 195 | UseRegs.insert(MO.getReg()); |
| 196 | if (!MO.isDef()) |
| 197 | continue; |
| 198 | if (MO.isImplicit()) |
| 199 | // Don't try to move it if it implicitly defines a register. |
| 200 | return false; |
| 201 | if (DefReg) |
| 202 | // For now, don't move any instructions that define multiple registers. |
| 203 | return false; |
| 204 | DefReg = MO.getReg(); |
| 205 | } |
| 206 | |
| 207 | // Find the instruction that kills SavedReg. |
| 208 | MachineInstr *KillMI = NULL; |
Evan Cheng | f1250ee | 2010-03-23 20:36:12 +0000 | [diff] [blame] | 209 | for (MachineRegisterInfo::use_nodbg_iterator |
| 210 | UI = MRI->use_nodbg_begin(SavedReg), |
| 211 | UE = MRI->use_nodbg_end(); UI != UE; ++UI) { |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 212 | MachineOperand &UseMO = UI.getOperand(); |
| 213 | if (!UseMO.isKill()) |
| 214 | continue; |
| 215 | KillMI = UseMO.getParent(); |
| 216 | break; |
| 217 | } |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 218 | |
Dan Gohman | 97121ba | 2009-04-08 00:15:30 +0000 | [diff] [blame] | 219 | if (!KillMI || KillMI->getParent() != MBB || KillMI == MI) |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 220 | return false; |
| 221 | |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 222 | // If any of the definitions are used by another instruction between the |
| 223 | // position and the kill use, then it's not safe to sink it. |
| 224 | // |
| 225 | // FIXME: This can be sped up if there is an easy way to query whether an |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 226 | // instruction is before or after another instruction. Then we can use |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 227 | // MachineRegisterInfo def / use instead. |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 228 | MachineOperand *KillMO = NULL; |
| 229 | MachineBasicBlock::iterator KillPos = KillMI; |
| 230 | ++KillPos; |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 231 | |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 232 | unsigned NumVisited = 0; |
Chris Lattner | 7896c9f | 2009-12-03 00:50:42 +0000 | [diff] [blame] | 233 | for (MachineBasicBlock::iterator I = llvm::next(OldPos); I != KillPos; ++I) { |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 234 | MachineInstr *OtherMI = I; |
Dale Johannesen | 3bfef03 | 2010-02-11 18:22:31 +0000 | [diff] [blame] | 235 | // DBG_VALUE cannot be counted against the limit. |
| 236 | if (OtherMI->isDebugValue()) |
| 237 | continue; |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 238 | if (NumVisited > 30) // FIXME: Arbitrary limit to reduce compile time cost. |
| 239 | return false; |
| 240 | ++NumVisited; |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 241 | for (unsigned i = 0, e = OtherMI->getNumOperands(); i != e; ++i) { |
| 242 | MachineOperand &MO = OtherMI->getOperand(i); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 243 | if (!MO.isReg()) |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 244 | continue; |
| 245 | unsigned MOReg = MO.getReg(); |
| 246 | if (!MOReg) |
| 247 | continue; |
| 248 | if (DefReg == MOReg) |
| 249 | return false; |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 250 | |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 251 | if (MO.isKill()) { |
| 252 | if (OtherMI == KillMI && MOReg == SavedReg) |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 253 | // Save the operand that kills the register. We want to unset the kill |
| 254 | // marker if we can sink MI past it. |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 255 | KillMO = &MO; |
| 256 | else if (UseRegs.count(MOReg)) |
| 257 | // One of the uses is killed before the destination. |
| 258 | return false; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 263 | // Update kill and LV information. |
| 264 | KillMO->setIsKill(false); |
| 265 | KillMO = MI->findRegisterUseOperand(SavedReg, false, TRI); |
| 266 | KillMO->setIsKill(true); |
Owen Anderson | 802af11 | 2008-07-02 21:28:58 +0000 | [diff] [blame] | 267 | |
Evan Cheng | 9f1c831 | 2008-07-03 09:09:37 +0000 | [diff] [blame] | 268 | if (LV) |
| 269 | LV->replaceKillInstruction(SavedReg, KillMI, MI); |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 270 | |
| 271 | // Move instruction to its destination. |
| 272 | MBB->remove(MI); |
| 273 | MBB->insert(KillPos, MI); |
| 274 | |
| 275 | ++Num3AddrSunk; |
| 276 | return true; |
| 277 | } |
| 278 | |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 279 | /// isTwoAddrUse - Return true if the specified MI is using the specified |
| 280 | /// register as a two-address operand. |
| 281 | static bool isTwoAddrUse(MachineInstr *UseMI, unsigned Reg) { |
| 282 | const TargetInstrDesc &TID = UseMI->getDesc(); |
| 283 | for (unsigned i = 0, e = TID.getNumOperands(); i != e; ++i) { |
| 284 | MachineOperand &MO = UseMI->getOperand(i); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 285 | if (MO.isReg() && MO.getReg() == Reg && |
Evan Cheng | a24752f | 2009-03-19 20:30:06 +0000 | [diff] [blame] | 286 | (MO.isDef() || UseMI->isRegTiedToDefOperand(i))) |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 287 | // Earlier use is a two-address one. |
| 288 | return true; |
| 289 | } |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | /// isProfitableToReMat - Return true if the heuristics determines it is likely |
| 294 | /// to be profitable to re-materialize the definition of Reg rather than copy |
| 295 | /// the register. |
| 296 | bool |
| 297 | TwoAddressInstructionPass::isProfitableToReMat(unsigned Reg, |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 298 | const TargetRegisterClass *RC, |
| 299 | MachineInstr *MI, MachineInstr *DefMI, |
| 300 | MachineBasicBlock *MBB, unsigned Loc) { |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 301 | bool OtherUse = false; |
Evan Cheng | f1250ee | 2010-03-23 20:36:12 +0000 | [diff] [blame] | 302 | for (MachineRegisterInfo::use_nodbg_iterator UI = MRI->use_nodbg_begin(Reg), |
| 303 | UE = MRI->use_nodbg_end(); UI != UE; ++UI) { |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 304 | MachineOperand &UseMO = UI.getOperand(); |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 305 | MachineInstr *UseMI = UseMO.getParent(); |
Evan Cheng | 601ca4b | 2008-06-25 01:16:38 +0000 | [diff] [blame] | 306 | MachineBasicBlock *UseMBB = UseMI->getParent(); |
| 307 | if (UseMBB == MBB) { |
| 308 | DenseMap<MachineInstr*, unsigned>::iterator DI = DistanceMap.find(UseMI); |
| 309 | if (DI != DistanceMap.end() && DI->second == Loc) |
| 310 | continue; // Current use. |
| 311 | OtherUse = true; |
| 312 | // There is at least one other use in the MBB that will clobber the |
| 313 | // register. |
| 314 | if (isTwoAddrUse(UseMI, Reg)) |
| 315 | return true; |
| 316 | } |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 317 | } |
Evan Cheng | 601ca4b | 2008-06-25 01:16:38 +0000 | [diff] [blame] | 318 | |
| 319 | // If other uses in MBB are not two-address uses, then don't remat. |
| 320 | if (OtherUse) |
| 321 | return false; |
| 322 | |
| 323 | // No other uses in the same block, remat if it's defined in the same |
| 324 | // block so it does not unnecessarily extend the live range. |
| 325 | return MBB == DefMI->getParent(); |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 328 | /// NoUseAfterLastDef - Return true if there are no intervening uses between the |
| 329 | /// last instruction in the MBB that defines the specified register and the |
| 330 | /// two-address instruction which is being processed. It also returns the last |
| 331 | /// def location by reference |
| 332 | bool TwoAddressInstructionPass::NoUseAfterLastDef(unsigned Reg, |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 333 | MachineBasicBlock *MBB, unsigned Dist, |
| 334 | unsigned &LastDef) { |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 335 | LastDef = 0; |
| 336 | unsigned LastUse = Dist; |
| 337 | for (MachineRegisterInfo::reg_iterator I = MRI->reg_begin(Reg), |
| 338 | E = MRI->reg_end(); I != E; ++I) { |
| 339 | MachineOperand &MO = I.getOperand(); |
| 340 | MachineInstr *MI = MO.getParent(); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 341 | if (MI->getParent() != MBB || MI->isDebugValue()) |
Dale Johannesen | d94998f | 2010-02-09 02:01:46 +0000 | [diff] [blame] | 342 | continue; |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 343 | DenseMap<MachineInstr*, unsigned>::iterator DI = DistanceMap.find(MI); |
| 344 | if (DI == DistanceMap.end()) |
| 345 | continue; |
| 346 | if (MO.isUse() && DI->second < LastUse) |
| 347 | LastUse = DI->second; |
| 348 | if (MO.isDef() && DI->second > LastDef) |
| 349 | LastDef = DI->second; |
| 350 | } |
| 351 | |
| 352 | return !(LastUse > LastDef && LastUse < Dist); |
| 353 | } |
| 354 | |
Evan Cheng | e9ccb3a | 2009-04-28 02:12:36 +0000 | [diff] [blame] | 355 | MachineInstr *TwoAddressInstructionPass::FindLastUseInMBB(unsigned Reg, |
| 356 | MachineBasicBlock *MBB, |
| 357 | unsigned Dist) { |
Lang Hames | a7c9dea | 2009-05-14 04:26:30 +0000 | [diff] [blame] | 358 | unsigned LastUseDist = 0; |
Evan Cheng | e9ccb3a | 2009-04-28 02:12:36 +0000 | [diff] [blame] | 359 | MachineInstr *LastUse = 0; |
| 360 | for (MachineRegisterInfo::reg_iterator I = MRI->reg_begin(Reg), |
| 361 | E = MRI->reg_end(); I != E; ++I) { |
| 362 | MachineOperand &MO = I.getOperand(); |
| 363 | MachineInstr *MI = MO.getParent(); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 364 | if (MI->getParent() != MBB || MI->isDebugValue()) |
Dale Johannesen | d94998f | 2010-02-09 02:01:46 +0000 | [diff] [blame] | 365 | continue; |
Evan Cheng | e9ccb3a | 2009-04-28 02:12:36 +0000 | [diff] [blame] | 366 | DenseMap<MachineInstr*, unsigned>::iterator DI = DistanceMap.find(MI); |
| 367 | if (DI == DistanceMap.end()) |
| 368 | continue; |
Lang Hames | a7c9dea | 2009-05-14 04:26:30 +0000 | [diff] [blame] | 369 | if (DI->second >= Dist) |
| 370 | continue; |
| 371 | |
| 372 | if (MO.isUse() && DI->second > LastUseDist) { |
Evan Cheng | e9ccb3a | 2009-04-28 02:12:36 +0000 | [diff] [blame] | 373 | LastUse = DI->first; |
| 374 | LastUseDist = DI->second; |
| 375 | } |
| 376 | } |
| 377 | return LastUse; |
| 378 | } |
| 379 | |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 380 | /// isCopyToReg - Return true if the specified MI is a copy instruction or |
| 381 | /// a extract_subreg instruction. It also returns the source and destination |
| 382 | /// registers and whether they are physical registers by reference. |
| 383 | static bool isCopyToReg(MachineInstr &MI, const TargetInstrInfo *TII, |
| 384 | unsigned &SrcReg, unsigned &DstReg, |
| 385 | bool &IsSrcPhys, bool &IsDstPhys) { |
| 386 | SrcReg = 0; |
| 387 | DstReg = 0; |
Jakob Stoklund Olesen | 04c528a | 2010-07-16 04:45:42 +0000 | [diff] [blame] | 388 | if (MI.isCopy()) { |
| 389 | DstReg = MI.getOperand(0).getReg(); |
| 390 | SrcReg = MI.getOperand(1).getReg(); |
| 391 | } else if (MI.isInsertSubreg() || MI.isSubregToReg()) { |
| 392 | DstReg = MI.getOperand(0).getReg(); |
| 393 | SrcReg = MI.getOperand(2).getReg(); |
| 394 | } else |
| 395 | return false; |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 396 | |
Jakob Stoklund Olesen | 04c528a | 2010-07-16 04:45:42 +0000 | [diff] [blame] | 397 | IsSrcPhys = TargetRegisterInfo::isPhysicalRegister(SrcReg); |
| 398 | IsDstPhys = TargetRegisterInfo::isPhysicalRegister(DstReg); |
| 399 | return true; |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Dan Gohman | 97121ba | 2009-04-08 00:15:30 +0000 | [diff] [blame] | 402 | /// isKilled - Test if the given register value, which is used by the given |
| 403 | /// instruction, is killed by the given instruction. This looks through |
| 404 | /// coalescable copies to see if the original value is potentially not killed. |
| 405 | /// |
| 406 | /// For example, in this code: |
| 407 | /// |
| 408 | /// %reg1034 = copy %reg1024 |
| 409 | /// %reg1035 = copy %reg1025<kill> |
| 410 | /// %reg1036 = add %reg1034<kill>, %reg1035<kill> |
| 411 | /// |
| 412 | /// %reg1034 is not considered to be killed, since it is copied from a |
| 413 | /// register which is not killed. Treating it as not killed lets the |
| 414 | /// normal heuristics commute the (two-address) add, which lets |
| 415 | /// coalescing eliminate the extra copy. |
| 416 | /// |
| 417 | static bool isKilled(MachineInstr &MI, unsigned Reg, |
| 418 | const MachineRegisterInfo *MRI, |
| 419 | const TargetInstrInfo *TII) { |
| 420 | MachineInstr *DefMI = &MI; |
| 421 | for (;;) { |
| 422 | if (!DefMI->killsRegister(Reg)) |
| 423 | return false; |
| 424 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
| 425 | return true; |
| 426 | MachineRegisterInfo::def_iterator Begin = MRI->def_begin(Reg); |
| 427 | // If there are multiple defs, we can't do a simple analysis, so just |
| 428 | // go with what the kill flag says. |
Chris Lattner | 7896c9f | 2009-12-03 00:50:42 +0000 | [diff] [blame] | 429 | if (llvm::next(Begin) != MRI->def_end()) |
Dan Gohman | 97121ba | 2009-04-08 00:15:30 +0000 | [diff] [blame] | 430 | return true; |
| 431 | DefMI = &*Begin; |
| 432 | bool IsSrcPhys, IsDstPhys; |
| 433 | unsigned SrcReg, DstReg; |
| 434 | // If the def is something other than a copy, then it isn't going to |
| 435 | // be coalesced, so follow the kill flag. |
| 436 | if (!isCopyToReg(*DefMI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys)) |
| 437 | return true; |
| 438 | Reg = SrcReg; |
| 439 | } |
| 440 | } |
| 441 | |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 442 | /// isTwoAddrUse - Return true if the specified MI uses the specified register |
| 443 | /// as a two-address use. If so, return the destination register by reference. |
| 444 | static bool isTwoAddrUse(MachineInstr &MI, unsigned Reg, unsigned &DstReg) { |
| 445 | const TargetInstrDesc &TID = MI.getDesc(); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 446 | unsigned NumOps = MI.isInlineAsm() ? MI.getNumOperands():TID.getNumOperands(); |
Evan Cheng | e6f350d | 2009-03-30 21:34:07 +0000 | [diff] [blame] | 447 | for (unsigned i = 0; i != NumOps; ++i) { |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 448 | const MachineOperand &MO = MI.getOperand(i); |
| 449 | if (!MO.isReg() || !MO.isUse() || MO.getReg() != Reg) |
| 450 | continue; |
Evan Cheng | a24752f | 2009-03-19 20:30:06 +0000 | [diff] [blame] | 451 | unsigned ti; |
| 452 | if (MI.isRegTiedToDefOperand(i, &ti)) { |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 453 | DstReg = MI.getOperand(ti).getReg(); |
| 454 | return true; |
| 455 | } |
| 456 | } |
| 457 | return false; |
| 458 | } |
| 459 | |
| 460 | /// findOnlyInterestingUse - Given a register, if has a single in-basic block |
| 461 | /// use, return the use instruction if it's a copy or a two-address use. |
| 462 | static |
| 463 | MachineInstr *findOnlyInterestingUse(unsigned Reg, MachineBasicBlock *MBB, |
| 464 | MachineRegisterInfo *MRI, |
| 465 | const TargetInstrInfo *TII, |
Evan Cheng | 87d696a | 2009-04-14 00:32:25 +0000 | [diff] [blame] | 466 | bool &IsCopy, |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 467 | unsigned &DstReg, bool &IsDstPhys) { |
Evan Cheng | 1423c70 | 2010-03-03 21:18:38 +0000 | [diff] [blame] | 468 | if (!MRI->hasOneNonDBGUse(Reg)) |
| 469 | // None or more than one use. |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 470 | return 0; |
Evan Cheng | 1423c70 | 2010-03-03 21:18:38 +0000 | [diff] [blame] | 471 | MachineInstr &UseMI = *MRI->use_nodbg_begin(Reg); |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 472 | if (UseMI.getParent() != MBB) |
| 473 | return 0; |
| 474 | unsigned SrcReg; |
| 475 | bool IsSrcPhys; |
Evan Cheng | 87d696a | 2009-04-14 00:32:25 +0000 | [diff] [blame] | 476 | if (isCopyToReg(UseMI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys)) { |
| 477 | IsCopy = true; |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 478 | return &UseMI; |
Evan Cheng | 87d696a | 2009-04-14 00:32:25 +0000 | [diff] [blame] | 479 | } |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 480 | IsDstPhys = false; |
Evan Cheng | 87d696a | 2009-04-14 00:32:25 +0000 | [diff] [blame] | 481 | if (isTwoAddrUse(UseMI, Reg, DstReg)) { |
| 482 | IsDstPhys = TargetRegisterInfo::isPhysicalRegister(DstReg); |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 483 | return &UseMI; |
Evan Cheng | 87d696a | 2009-04-14 00:32:25 +0000 | [diff] [blame] | 484 | } |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | /// getMappedReg - Return the physical register the specified virtual register |
| 489 | /// might be mapped to. |
| 490 | static unsigned |
| 491 | getMappedReg(unsigned Reg, DenseMap<unsigned, unsigned> &RegMap) { |
| 492 | while (TargetRegisterInfo::isVirtualRegister(Reg)) { |
| 493 | DenseMap<unsigned, unsigned>::iterator SI = RegMap.find(Reg); |
| 494 | if (SI == RegMap.end()) |
| 495 | return 0; |
| 496 | Reg = SI->second; |
| 497 | } |
| 498 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
| 499 | return Reg; |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | /// regsAreCompatible - Return true if the two registers are equal or aliased. |
| 504 | /// |
| 505 | static bool |
| 506 | regsAreCompatible(unsigned RegA, unsigned RegB, const TargetRegisterInfo *TRI) { |
| 507 | if (RegA == RegB) |
| 508 | return true; |
| 509 | if (!RegA || !RegB) |
| 510 | return false; |
| 511 | return TRI->regsOverlap(RegA, RegB); |
| 512 | } |
| 513 | |
| 514 | |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 515 | /// isProfitableToReMat - Return true if it's potentially profitable to commute |
| 516 | /// the two-address instruction that's being processed. |
| 517 | bool |
| 518 | TwoAddressInstructionPass::isProfitableToCommute(unsigned regB, unsigned regC, |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 519 | MachineInstr *MI, MachineBasicBlock *MBB, |
| 520 | unsigned Dist) { |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 521 | // Determine if it's profitable to commute this two address instruction. In |
| 522 | // general, we want no uses between this instruction and the definition of |
| 523 | // the two-address register. |
| 524 | // e.g. |
| 525 | // %reg1028<def> = EXTRACT_SUBREG %reg1027<kill>, 1 |
| 526 | // %reg1029<def> = MOV8rr %reg1028 |
| 527 | // %reg1029<def> = SHR8ri %reg1029, 7, %EFLAGS<imp-def,dead> |
| 528 | // insert => %reg1030<def> = MOV8rr %reg1028 |
| 529 | // %reg1030<def> = ADD8rr %reg1028<kill>, %reg1029<kill>, %EFLAGS<imp-def,dead> |
| 530 | // In this case, it might not be possible to coalesce the second MOV8rr |
| 531 | // instruction if the first one is coalesced. So it would be profitable to |
| 532 | // commute it: |
| 533 | // %reg1028<def> = EXTRACT_SUBREG %reg1027<kill>, 1 |
| 534 | // %reg1029<def> = MOV8rr %reg1028 |
| 535 | // %reg1029<def> = SHR8ri %reg1029, 7, %EFLAGS<imp-def,dead> |
| 536 | // insert => %reg1030<def> = MOV8rr %reg1029 |
| 537 | // %reg1030<def> = ADD8rr %reg1029<kill>, %reg1028<kill>, %EFLAGS<imp-def,dead> |
| 538 | |
| 539 | if (!MI->killsRegister(regC)) |
| 540 | return false; |
| 541 | |
| 542 | // Ok, we have something like: |
| 543 | // %reg1030<def> = ADD8rr %reg1028<kill>, %reg1029<kill>, %EFLAGS<imp-def,dead> |
| 544 | // let's see if it's worth commuting it. |
| 545 | |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 546 | // Look for situations like this: |
| 547 | // %reg1024<def> = MOV r1 |
| 548 | // %reg1025<def> = MOV r0 |
| 549 | // %reg1026<def> = ADD %reg1024, %reg1025 |
| 550 | // r0 = MOV %reg1026 |
| 551 | // Commute the ADD to hopefully eliminate an otherwise unavoidable copy. |
| 552 | unsigned FromRegB = getMappedReg(regB, SrcRegMap); |
| 553 | unsigned FromRegC = getMappedReg(regC, SrcRegMap); |
| 554 | unsigned ToRegB = getMappedReg(regB, DstRegMap); |
| 555 | unsigned ToRegC = getMappedReg(regC, DstRegMap); |
| 556 | if (!regsAreCompatible(FromRegB, ToRegB, TRI) && |
| 557 | (regsAreCompatible(FromRegB, ToRegC, TRI) || |
| 558 | regsAreCompatible(FromRegC, ToRegB, TRI))) |
| 559 | return true; |
| 560 | |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 561 | // If there is a use of regC between its last def (could be livein) and this |
| 562 | // instruction, then bail. |
| 563 | unsigned LastDefC = 0; |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 564 | if (!NoUseAfterLastDef(regC, MBB, Dist, LastDefC)) |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 565 | return false; |
| 566 | |
| 567 | // If there is a use of regB between its last def (could be livein) and this |
| 568 | // instruction, then go ahead and make this transformation. |
| 569 | unsigned LastDefB = 0; |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 570 | if (!NoUseAfterLastDef(regB, MBB, Dist, LastDefB)) |
Evan Cheng | d498c8f | 2009-01-25 03:53:59 +0000 | [diff] [blame] | 571 | return true; |
| 572 | |
| 573 | // Since there are no intervening uses for both registers, then commute |
| 574 | // if the def of regC is closer. Its live interval is shorter. |
| 575 | return LastDefB && LastDefC && LastDefC > LastDefB; |
| 576 | } |
| 577 | |
Evan Cheng | 8191371 | 2009-01-23 23:27:33 +0000 | [diff] [blame] | 578 | /// CommuteInstruction - Commute a two-address instruction and update the basic |
| 579 | /// block, distance map, and live variables if needed. Return true if it is |
| 580 | /// successful. |
| 581 | bool |
| 582 | TwoAddressInstructionPass::CommuteInstruction(MachineBasicBlock::iterator &mi, |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 583 | MachineFunction::iterator &mbbi, |
| 584 | unsigned RegB, unsigned RegC, unsigned Dist) { |
Evan Cheng | 8191371 | 2009-01-23 23:27:33 +0000 | [diff] [blame] | 585 | MachineInstr *MI = mi; |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 586 | DEBUG(dbgs() << "2addr: COMMUTING : " << *MI); |
Evan Cheng | 8191371 | 2009-01-23 23:27:33 +0000 | [diff] [blame] | 587 | MachineInstr *NewMI = TII->commuteInstruction(MI); |
| 588 | |
| 589 | if (NewMI == 0) { |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 590 | DEBUG(dbgs() << "2addr: COMMUTING FAILED!\n"); |
Evan Cheng | 8191371 | 2009-01-23 23:27:33 +0000 | [diff] [blame] | 591 | return false; |
| 592 | } |
| 593 | |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 594 | DEBUG(dbgs() << "2addr: COMMUTED TO: " << *NewMI); |
Evan Cheng | 8191371 | 2009-01-23 23:27:33 +0000 | [diff] [blame] | 595 | // If the instruction changed to commute it, update livevar. |
| 596 | if (NewMI != MI) { |
| 597 | if (LV) |
| 598 | // Update live variables |
| 599 | LV->replaceKillInstruction(RegC, MI, NewMI); |
| 600 | |
| 601 | mbbi->insert(mi, NewMI); // Insert the new inst |
| 602 | mbbi->erase(mi); // Nuke the old inst. |
| 603 | mi = NewMI; |
| 604 | DistanceMap.insert(std::make_pair(NewMI, Dist)); |
| 605 | } |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 606 | |
| 607 | // Update source register map. |
| 608 | unsigned FromRegC = getMappedReg(RegC, SrcRegMap); |
| 609 | if (FromRegC) { |
| 610 | unsigned RegA = MI->getOperand(0).getReg(); |
| 611 | SrcRegMap[RegA] = FromRegC; |
| 612 | } |
| 613 | |
Evan Cheng | 8191371 | 2009-01-23 23:27:33 +0000 | [diff] [blame] | 614 | return true; |
| 615 | } |
| 616 | |
Evan Cheng | e6f350d | 2009-03-30 21:34:07 +0000 | [diff] [blame] | 617 | /// isProfitableToConv3Addr - Return true if it is profitable to convert the |
| 618 | /// given 2-address instruction to a 3-address one. |
| 619 | bool |
| 620 | TwoAddressInstructionPass::isProfitableToConv3Addr(unsigned RegA) { |
| 621 | // Look for situations like this: |
| 622 | // %reg1024<def> = MOV r1 |
| 623 | // %reg1025<def> = MOV r0 |
| 624 | // %reg1026<def> = ADD %reg1024, %reg1025 |
| 625 | // r2 = MOV %reg1026 |
| 626 | // Turn ADD into a 3-address instruction to avoid a copy. |
| 627 | unsigned FromRegA = getMappedReg(RegA, SrcRegMap); |
| 628 | unsigned ToRegA = getMappedReg(RegA, DstRegMap); |
| 629 | return (FromRegA && ToRegA && !regsAreCompatible(FromRegA, ToRegA, TRI)); |
| 630 | } |
| 631 | |
| 632 | /// ConvertInstTo3Addr - Convert the specified two-address instruction into a |
| 633 | /// three address one. Return true if this transformation was successful. |
| 634 | bool |
| 635 | TwoAddressInstructionPass::ConvertInstTo3Addr(MachineBasicBlock::iterator &mi, |
| 636 | MachineBasicBlock::iterator &nmi, |
| 637 | MachineFunction::iterator &mbbi, |
| 638 | unsigned RegB, unsigned Dist) { |
| 639 | MachineInstr *NewMI = TII->convertToThreeAddress(mbbi, mi, LV); |
| 640 | if (NewMI) { |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 641 | DEBUG(dbgs() << "2addr: CONVERTING 2-ADDR: " << *mi); |
| 642 | DEBUG(dbgs() << "2addr: TO 3-ADDR: " << *NewMI); |
Evan Cheng | e6f350d | 2009-03-30 21:34:07 +0000 | [diff] [blame] | 643 | bool Sunk = false; |
| 644 | |
| 645 | if (NewMI->findRegisterUseOperand(RegB, false, TRI)) |
| 646 | // FIXME: Temporary workaround. If the new instruction doesn't |
| 647 | // uses RegB, convertToThreeAddress must have created more |
| 648 | // then one instruction. |
| 649 | Sunk = Sink3AddrInstruction(mbbi, NewMI, RegB, mi); |
| 650 | |
| 651 | mbbi->erase(mi); // Nuke the old inst. |
| 652 | |
| 653 | if (!Sunk) { |
| 654 | DistanceMap.insert(std::make_pair(NewMI, Dist)); |
| 655 | mi = NewMI; |
Chris Lattner | 7896c9f | 2009-12-03 00:50:42 +0000 | [diff] [blame] | 656 | nmi = llvm::next(mi); |
Evan Cheng | e6f350d | 2009-03-30 21:34:07 +0000 | [diff] [blame] | 657 | } |
| 658 | return true; |
| 659 | } |
| 660 | |
| 661 | return false; |
| 662 | } |
| 663 | |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 664 | /// ProcessCopy - If the specified instruction is not yet processed, process it |
| 665 | /// if it's a copy. For a copy instruction, we find the physical registers the |
| 666 | /// source and destination registers might be mapped to. These are kept in |
| 667 | /// point-to maps used to determine future optimizations. e.g. |
| 668 | /// v1024 = mov r0 |
| 669 | /// v1025 = mov r1 |
| 670 | /// v1026 = add v1024, v1025 |
| 671 | /// r1 = mov r1026 |
| 672 | /// If 'add' is a two-address instruction, v1024, v1026 are both potentially |
| 673 | /// coalesced to r0 (from the input side). v1025 is mapped to r1. v1026 is |
| 674 | /// potentially joined with r1 on the output side. It's worthwhile to commute |
| 675 | /// 'add' to eliminate a copy. |
| 676 | void TwoAddressInstructionPass::ProcessCopy(MachineInstr *MI, |
| 677 | MachineBasicBlock *MBB, |
| 678 | SmallPtrSet<MachineInstr*, 8> &Processed) { |
| 679 | if (Processed.count(MI)) |
| 680 | return; |
| 681 | |
| 682 | bool IsSrcPhys, IsDstPhys; |
| 683 | unsigned SrcReg, DstReg; |
| 684 | if (!isCopyToReg(*MI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys)) |
| 685 | return; |
| 686 | |
| 687 | if (IsDstPhys && !IsSrcPhys) |
| 688 | DstRegMap.insert(std::make_pair(SrcReg, DstReg)); |
| 689 | else if (!IsDstPhys && IsSrcPhys) { |
Evan Cheng | 3005ed6 | 2009-04-13 20:04:24 +0000 | [diff] [blame] | 690 | bool isNew = SrcRegMap.insert(std::make_pair(DstReg, SrcReg)).second; |
| 691 | if (!isNew) |
| 692 | assert(SrcRegMap[DstReg] == SrcReg && |
| 693 | "Can't map to two src physical registers!"); |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 694 | |
| 695 | SmallVector<unsigned, 4> VirtRegPairs; |
Evan Cheng | 87d696a | 2009-04-14 00:32:25 +0000 | [diff] [blame] | 696 | bool IsCopy = false; |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 697 | unsigned NewReg = 0; |
| 698 | while (MachineInstr *UseMI = findOnlyInterestingUse(DstReg, MBB, MRI,TII, |
Evan Cheng | 87d696a | 2009-04-14 00:32:25 +0000 | [diff] [blame] | 699 | IsCopy, NewReg, IsDstPhys)) { |
| 700 | if (IsCopy) { |
| 701 | if (!Processed.insert(UseMI)) |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 702 | break; |
| 703 | } |
| 704 | |
| 705 | DenseMap<MachineInstr*, unsigned>::iterator DI = DistanceMap.find(UseMI); |
| 706 | if (DI != DistanceMap.end()) |
| 707 | // Earlier in the same MBB.Reached via a back edge. |
| 708 | break; |
| 709 | |
| 710 | if (IsDstPhys) { |
| 711 | VirtRegPairs.push_back(NewReg); |
| 712 | break; |
| 713 | } |
| 714 | bool isNew = SrcRegMap.insert(std::make_pair(NewReg, DstReg)).second; |
Evan Cheng | 3005ed6 | 2009-04-13 20:04:24 +0000 | [diff] [blame] | 715 | if (!isNew) |
Evan Cheng | 87d696a | 2009-04-14 00:32:25 +0000 | [diff] [blame] | 716 | assert(SrcRegMap[NewReg] == DstReg && |
| 717 | "Can't map to two src physical registers!"); |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 718 | VirtRegPairs.push_back(NewReg); |
| 719 | DstReg = NewReg; |
| 720 | } |
| 721 | |
| 722 | if (!VirtRegPairs.empty()) { |
| 723 | unsigned ToReg = VirtRegPairs.back(); |
| 724 | VirtRegPairs.pop_back(); |
| 725 | while (!VirtRegPairs.empty()) { |
| 726 | unsigned FromReg = VirtRegPairs.back(); |
| 727 | VirtRegPairs.pop_back(); |
| 728 | bool isNew = DstRegMap.insert(std::make_pair(FromReg, ToReg)).second; |
Evan Cheng | 3005ed6 | 2009-04-13 20:04:24 +0000 | [diff] [blame] | 729 | if (!isNew) |
| 730 | assert(DstRegMap[FromReg] == ToReg && |
| 731 | "Can't map to two dst physical registers!"); |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 732 | ToReg = FromReg; |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | Processed.insert(MI); |
| 738 | } |
| 739 | |
Evan Cheng | 28c7ce3 | 2009-02-21 03:14:25 +0000 | [diff] [blame] | 740 | /// isSafeToDelete - If the specified instruction does not produce any side |
| 741 | /// effects and all of its defs are dead, then it's safe to delete. |
Jakob Stoklund Olesen | 0b25ae1 | 2009-11-18 21:33:35 +0000 | [diff] [blame] | 742 | static bool isSafeToDelete(MachineInstr *MI, |
Evan Cheng | e9ccb3a | 2009-04-28 02:12:36 +0000 | [diff] [blame] | 743 | const TargetInstrInfo *TII, |
| 744 | SmallVector<unsigned, 4> &Kills) { |
Evan Cheng | 28c7ce3 | 2009-02-21 03:14:25 +0000 | [diff] [blame] | 745 | const TargetInstrDesc &TID = MI->getDesc(); |
| 746 | if (TID.mayStore() || TID.isCall()) |
| 747 | return false; |
| 748 | if (TID.isTerminator() || TID.hasUnmodeledSideEffects()) |
| 749 | return false; |
| 750 | |
| 751 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 752 | MachineOperand &MO = MI->getOperand(i); |
Evan Cheng | e9ccb3a | 2009-04-28 02:12:36 +0000 | [diff] [blame] | 753 | if (!MO.isReg()) |
Evan Cheng | 28c7ce3 | 2009-02-21 03:14:25 +0000 | [diff] [blame] | 754 | continue; |
Evan Cheng | e9ccb3a | 2009-04-28 02:12:36 +0000 | [diff] [blame] | 755 | if (MO.isDef() && !MO.isDead()) |
Evan Cheng | 28c7ce3 | 2009-02-21 03:14:25 +0000 | [diff] [blame] | 756 | return false; |
Jakob Stoklund Olesen | 0b25ae1 | 2009-11-18 21:33:35 +0000 | [diff] [blame] | 757 | if (MO.isUse() && MO.isKill()) |
Evan Cheng | e9ccb3a | 2009-04-28 02:12:36 +0000 | [diff] [blame] | 758 | Kills.push_back(MO.getReg()); |
Evan Cheng | 28c7ce3 | 2009-02-21 03:14:25 +0000 | [diff] [blame] | 759 | } |
Evan Cheng | 28c7ce3 | 2009-02-21 03:14:25 +0000 | [diff] [blame] | 760 | return true; |
| 761 | } |
| 762 | |
Bob Wilson | 326f438 | 2009-09-01 22:51:08 +0000 | [diff] [blame] | 763 | /// canUpdateDeletedKills - Check if all the registers listed in Kills are |
| 764 | /// killed by instructions in MBB preceding the current instruction at |
| 765 | /// position Dist. If so, return true and record information about the |
| 766 | /// preceding kills in NewKills. |
| 767 | bool TwoAddressInstructionPass:: |
| 768 | canUpdateDeletedKills(SmallVector<unsigned, 4> &Kills, |
| 769 | SmallVector<NewKill, 4> &NewKills, |
| 770 | MachineBasicBlock *MBB, unsigned Dist) { |
| 771 | while (!Kills.empty()) { |
| 772 | unsigned Kill = Kills.back(); |
| 773 | Kills.pop_back(); |
| 774 | if (TargetRegisterInfo::isPhysicalRegister(Kill)) |
| 775 | return false; |
| 776 | |
| 777 | MachineInstr *LastKill = FindLastUseInMBB(Kill, MBB, Dist); |
| 778 | if (!LastKill) |
| 779 | return false; |
| 780 | |
Evan Cheng | 1015ba7 | 2010-05-21 20:53:24 +0000 | [diff] [blame] | 781 | bool isModRef = LastKill->definesRegister(Kill); |
Bob Wilson | 326f438 | 2009-09-01 22:51:08 +0000 | [diff] [blame] | 782 | NewKills.push_back(std::make_pair(std::make_pair(Kill, isModRef), |
| 783 | LastKill)); |
| 784 | } |
| 785 | return true; |
| 786 | } |
| 787 | |
| 788 | /// DeleteUnusedInstr - If an instruction with a tied register operand can |
| 789 | /// be safely deleted, just delete it. |
| 790 | bool |
| 791 | TwoAddressInstructionPass::DeleteUnusedInstr(MachineBasicBlock::iterator &mi, |
| 792 | MachineBasicBlock::iterator &nmi, |
| 793 | MachineFunction::iterator &mbbi, |
Bob Wilson | 326f438 | 2009-09-01 22:51:08 +0000 | [diff] [blame] | 794 | unsigned Dist) { |
| 795 | // Check if the instruction has no side effects and if all its defs are dead. |
| 796 | SmallVector<unsigned, 4> Kills; |
Jakob Stoklund Olesen | 0b25ae1 | 2009-11-18 21:33:35 +0000 | [diff] [blame] | 797 | if (!isSafeToDelete(mi, TII, Kills)) |
Bob Wilson | 326f438 | 2009-09-01 22:51:08 +0000 | [diff] [blame] | 798 | return false; |
| 799 | |
| 800 | // If this instruction kills some virtual registers, we need to |
| 801 | // update the kill information. If it's not possible to do so, |
| 802 | // then bail out. |
| 803 | SmallVector<NewKill, 4> NewKills; |
| 804 | if (!canUpdateDeletedKills(Kills, NewKills, &*mbbi, Dist)) |
| 805 | return false; |
| 806 | |
| 807 | if (LV) { |
| 808 | while (!NewKills.empty()) { |
| 809 | MachineInstr *NewKill = NewKills.back().second; |
| 810 | unsigned Kill = NewKills.back().first.first; |
| 811 | bool isDead = NewKills.back().first.second; |
| 812 | NewKills.pop_back(); |
| 813 | if (LV->removeVirtualRegisterKilled(Kill, mi)) { |
| 814 | if (isDead) |
| 815 | LV->addVirtualRegisterDead(Kill, NewKill); |
| 816 | else |
| 817 | LV->addVirtualRegisterKilled(Kill, NewKill); |
| 818 | } |
| 819 | } |
Bob Wilson | 326f438 | 2009-09-01 22:51:08 +0000 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | mbbi->erase(mi); // Nuke the old inst. |
| 823 | mi = nmi; |
| 824 | return true; |
| 825 | } |
| 826 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 827 | /// TryInstructionTransform - For the case where an instruction has a single |
| 828 | /// pair of tied register operands, attempt some transformations that may |
| 829 | /// either eliminate the tied operands or improve the opportunities for |
| 830 | /// coalescing away the register copy. Returns true if the tied operands |
| 831 | /// are eliminated altogether. |
| 832 | bool TwoAddressInstructionPass:: |
| 833 | TryInstructionTransform(MachineBasicBlock::iterator &mi, |
| 834 | MachineBasicBlock::iterator &nmi, |
| 835 | MachineFunction::iterator &mbbi, |
| 836 | unsigned SrcIdx, unsigned DstIdx, unsigned Dist) { |
| 837 | const TargetInstrDesc &TID = mi->getDesc(); |
| 838 | unsigned regA = mi->getOperand(DstIdx).getReg(); |
| 839 | unsigned regB = mi->getOperand(SrcIdx).getReg(); |
| 840 | |
| 841 | assert(TargetRegisterInfo::isVirtualRegister(regB) && |
| 842 | "cannot make instruction into two-address form"); |
| 843 | |
| 844 | // If regA is dead and the instruction can be deleted, just delete |
| 845 | // it so it doesn't clobber regB. |
| 846 | bool regBKilled = isKilled(*mi, regB, MRI, TII); |
| 847 | if (!regBKilled && mi->getOperand(DstIdx).isDead() && |
Jakob Stoklund Olesen | 0b25ae1 | 2009-11-18 21:33:35 +0000 | [diff] [blame] | 848 | DeleteUnusedInstr(mi, nmi, mbbi, Dist)) { |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 849 | ++NumDeletes; |
| 850 | return true; // Done with this instruction. |
| 851 | } |
| 852 | |
| 853 | // Check if it is profitable to commute the operands. |
| 854 | unsigned SrcOp1, SrcOp2; |
| 855 | unsigned regC = 0; |
| 856 | unsigned regCIdx = ~0U; |
| 857 | bool TryCommute = false; |
| 858 | bool AggressiveCommute = false; |
| 859 | if (TID.isCommutable() && mi->getNumOperands() >= 3 && |
| 860 | TII->findCommutedOpIndices(mi, SrcOp1, SrcOp2)) { |
| 861 | if (SrcIdx == SrcOp1) |
| 862 | regCIdx = SrcOp2; |
| 863 | else if (SrcIdx == SrcOp2) |
| 864 | regCIdx = SrcOp1; |
| 865 | |
| 866 | if (regCIdx != ~0U) { |
| 867 | regC = mi->getOperand(regCIdx).getReg(); |
| 868 | if (!regBKilled && isKilled(*mi, regC, MRI, TII)) |
| 869 | // If C dies but B does not, swap the B and C operands. |
| 870 | // This makes the live ranges of A and C joinable. |
| 871 | TryCommute = true; |
| 872 | else if (isProfitableToCommute(regB, regC, mi, mbbi, Dist)) { |
| 873 | TryCommute = true; |
| 874 | AggressiveCommute = true; |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | // If it's profitable to commute, try to do so. |
| 880 | if (TryCommute && CommuteInstruction(mi, mbbi, regB, regC, Dist)) { |
| 881 | ++NumCommuted; |
| 882 | if (AggressiveCommute) |
| 883 | ++NumAggrCommuted; |
| 884 | return false; |
| 885 | } |
| 886 | |
| 887 | if (TID.isConvertibleTo3Addr()) { |
| 888 | // This instruction is potentially convertible to a true |
| 889 | // three-address instruction. Check if it is profitable. |
| 890 | if (!regBKilled || isProfitableToConv3Addr(regA)) { |
| 891 | // Try to convert it. |
| 892 | if (ConvertInstTo3Addr(mi, nmi, mbbi, regB, Dist)) { |
| 893 | ++NumConvertedTo3Addr; |
| 894 | return true; // Done with this instruction. |
| 895 | } |
| 896 | } |
| 897 | } |
Dan Gohman | 584fedf | 2010-06-21 22:17:20 +0000 | [diff] [blame] | 898 | |
| 899 | // If this is an instruction with a load folded into it, try unfolding |
| 900 | // the load, e.g. avoid this: |
| 901 | // movq %rdx, %rcx |
| 902 | // addq (%rax), %rcx |
| 903 | // in favor of this: |
| 904 | // movq (%rax), %rcx |
| 905 | // addq %rdx, %rcx |
| 906 | // because it's preferable to schedule a load than a register copy. |
| 907 | if (TID.mayLoad() && !regBKilled) { |
| 908 | // Determine if a load can be unfolded. |
| 909 | unsigned LoadRegIndex; |
| 910 | unsigned NewOpc = |
| 911 | TII->getOpcodeAfterMemoryUnfold(mi->getOpcode(), |
| 912 | /*UnfoldLoad=*/true, |
| 913 | /*UnfoldStore=*/false, |
| 914 | &LoadRegIndex); |
| 915 | if (NewOpc != 0) { |
| 916 | const TargetInstrDesc &UnfoldTID = TII->get(NewOpc); |
| 917 | if (UnfoldTID.getNumDefs() == 1) { |
| 918 | MachineFunction &MF = *mbbi->getParent(); |
| 919 | |
| 920 | // Unfold the load. |
| 921 | DEBUG(dbgs() << "2addr: UNFOLDING: " << *mi); |
| 922 | const TargetRegisterClass *RC = |
| 923 | UnfoldTID.OpInfo[LoadRegIndex].getRegClass(TRI); |
| 924 | unsigned Reg = MRI->createVirtualRegister(RC); |
| 925 | SmallVector<MachineInstr *, 2> NewMIs; |
Evan Cheng | 98ec91e | 2010-07-02 20:36:18 +0000 | [diff] [blame] | 926 | if (!TII->unfoldMemoryOperand(MF, mi, Reg, |
| 927 | /*UnfoldLoad=*/true,/*UnfoldStore=*/false, |
| 928 | NewMIs)) { |
| 929 | DEBUG(dbgs() << "2addr: ABANDONING UNFOLD\n"); |
| 930 | return false; |
| 931 | } |
Dan Gohman | 584fedf | 2010-06-21 22:17:20 +0000 | [diff] [blame] | 932 | assert(NewMIs.size() == 2 && |
| 933 | "Unfolded a load into multiple instructions!"); |
| 934 | // The load was previously folded, so this is the only use. |
| 935 | NewMIs[1]->addRegisterKilled(Reg, TRI); |
| 936 | |
| 937 | // Tentatively insert the instructions into the block so that they |
| 938 | // look "normal" to the transformation logic. |
| 939 | mbbi->insert(mi, NewMIs[0]); |
| 940 | mbbi->insert(mi, NewMIs[1]); |
| 941 | |
| 942 | DEBUG(dbgs() << "2addr: NEW LOAD: " << *NewMIs[0] |
| 943 | << "2addr: NEW INST: " << *NewMIs[1]); |
| 944 | |
| 945 | // Transform the instruction, now that it no longer has a load. |
| 946 | unsigned NewDstIdx = NewMIs[1]->findRegisterDefOperandIdx(regA); |
| 947 | unsigned NewSrcIdx = NewMIs[1]->findRegisterUseOperandIdx(regB); |
| 948 | MachineBasicBlock::iterator NewMI = NewMIs[1]; |
| 949 | bool TransformSuccess = |
| 950 | TryInstructionTransform(NewMI, mi, mbbi, |
| 951 | NewSrcIdx, NewDstIdx, Dist); |
| 952 | if (TransformSuccess || |
| 953 | NewMIs[1]->getOperand(NewSrcIdx).isKill()) { |
| 954 | // Success, or at least we made an improvement. Keep the unfolded |
| 955 | // instructions and discard the original. |
| 956 | if (LV) { |
| 957 | for (unsigned i = 0, e = mi->getNumOperands(); i != e; ++i) { |
| 958 | MachineOperand &MO = mi->getOperand(i); |
Dan Gohman | 7aa7bc7 | 2010-06-22 00:32:04 +0000 | [diff] [blame] | 959 | if (MO.isReg() && MO.getReg() != 0 && |
| 960 | TargetRegisterInfo::isVirtualRegister(MO.getReg())) { |
| 961 | if (MO.isUse()) { |
Dan Gohman | cc1ca98 | 2010-06-22 02:07:21 +0000 | [diff] [blame] | 962 | if (MO.isKill()) { |
| 963 | if (NewMIs[0]->killsRegister(MO.getReg())) |
| 964 | LV->replaceKillInstruction(MO.getReg(), mi, NewMIs[0]); |
| 965 | else { |
| 966 | assert(NewMIs[1]->killsRegister(MO.getReg()) && |
| 967 | "Kill missing after load unfold!"); |
| 968 | LV->replaceKillInstruction(MO.getReg(), mi, NewMIs[1]); |
| 969 | } |
| 970 | } |
| 971 | } else if (LV->removeVirtualRegisterDead(MO.getReg(), mi)) { |
| 972 | if (NewMIs[1]->registerDefIsDead(MO.getReg())) |
| 973 | LV->addVirtualRegisterDead(MO.getReg(), NewMIs[1]); |
| 974 | else { |
| 975 | assert(NewMIs[0]->registerDefIsDead(MO.getReg()) && |
| 976 | "Dead flag missing after load unfold!"); |
| 977 | LV->addVirtualRegisterDead(MO.getReg(), NewMIs[0]); |
| 978 | } |
| 979 | } |
Dan Gohman | 7aa7bc7 | 2010-06-22 00:32:04 +0000 | [diff] [blame] | 980 | } |
Dan Gohman | 584fedf | 2010-06-21 22:17:20 +0000 | [diff] [blame] | 981 | } |
| 982 | LV->addVirtualRegisterKilled(Reg, NewMIs[1]); |
| 983 | } |
| 984 | mi->eraseFromParent(); |
| 985 | mi = NewMIs[1]; |
| 986 | if (TransformSuccess) |
| 987 | return true; |
| 988 | } else { |
| 989 | // Transforming didn't eliminate the tie and didn't lead to an |
| 990 | // improvement. Clean up the unfolded instructions and keep the |
| 991 | // original. |
| 992 | DEBUG(dbgs() << "2addr: ABANDONING UNFOLD\n"); |
| 993 | NewMIs[0]->eraseFromParent(); |
| 994 | NewMIs[1]->eraseFromParent(); |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1000 | return false; |
| 1001 | } |
| 1002 | |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 1003 | /// runOnMachineFunction - Reduce two-address instructions to two operands. |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 1004 | /// |
Chris Lattner | 163c1e7 | 2004-01-31 21:14:04 +0000 | [diff] [blame] | 1005 | bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) { |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 1006 | DEBUG(dbgs() << "Machine Function\n"); |
Misha Brukman | 75fa4e4 | 2004-07-22 15:26:23 +0000 | [diff] [blame] | 1007 | const TargetMachine &TM = MF.getTarget(); |
Evan Cheng | 875357d | 2008-03-13 06:37:55 +0000 | [diff] [blame] | 1008 | MRI = &MF.getRegInfo(); |
| 1009 | TII = TM.getInstrInfo(); |
| 1010 | TRI = TM.getRegisterInfo(); |
Duncan Sands | 1465d61 | 2009-01-28 13:14:17 +0000 | [diff] [blame] | 1011 | LV = getAnalysisIfAvailable<LiveVariables>(); |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 1012 | AA = &getAnalysis<AliasAnalysis>(); |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 1013 | |
Misha Brukman | 75fa4e4 | 2004-07-22 15:26:23 +0000 | [diff] [blame] | 1014 | bool MadeChange = false; |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 1015 | |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 1016 | DEBUG(dbgs() << "********** REWRITING TWO-ADDR INSTRS **********\n"); |
| 1017 | DEBUG(dbgs() << "********** Function: " |
Daniel Dunbar | ce63ffb | 2009-07-25 00:23:56 +0000 | [diff] [blame] | 1018 | << MF.getFunction()->getName() << '\n'); |
Alkis Evlogimenos | 3a9986f | 2004-02-18 00:35:06 +0000 | [diff] [blame] | 1019 | |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 1020 | // ReMatRegs - Keep track of the registers whose def's are remat'ed. |
| 1021 | BitVector ReMatRegs; |
| 1022 | ReMatRegs.resize(MRI->getLastVirtReg()+1); |
| 1023 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1024 | typedef DenseMap<unsigned, SmallVector<std::pair<unsigned, unsigned>, 4> > |
| 1025 | TiedOperandMap; |
| 1026 | TiedOperandMap TiedOperands(4); |
| 1027 | |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 1028 | SmallPtrSet<MachineInstr*, 8> Processed; |
Misha Brukman | 75fa4e4 | 2004-07-22 15:26:23 +0000 | [diff] [blame] | 1029 | for (MachineFunction::iterator mbbi = MF.begin(), mbbe = MF.end(); |
| 1030 | mbbi != mbbe; ++mbbi) { |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 1031 | unsigned Dist = 0; |
| 1032 | DistanceMap.clear(); |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 1033 | SrcRegMap.clear(); |
| 1034 | DstRegMap.clear(); |
| 1035 | Processed.clear(); |
Misha Brukman | 75fa4e4 | 2004-07-22 15:26:23 +0000 | [diff] [blame] | 1036 | for (MachineBasicBlock::iterator mi = mbbi->begin(), me = mbbi->end(); |
Evan Cheng | 7a963fa | 2008-03-27 01:27:25 +0000 | [diff] [blame] | 1037 | mi != me; ) { |
Chris Lattner | 7896c9f | 2009-12-03 00:50:42 +0000 | [diff] [blame] | 1038 | MachineBasicBlock::iterator nmi = llvm::next(mi); |
Dale Johannesen | b8ff934 | 2010-02-10 21:47:48 +0000 | [diff] [blame] | 1039 | if (mi->isDebugValue()) { |
| 1040 | mi = nmi; |
| 1041 | continue; |
| 1042 | } |
Evan Cheng | f1250ee | 2010-03-23 20:36:12 +0000 | [diff] [blame] | 1043 | |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1044 | // Remember REG_SEQUENCE instructions, we'll deal with them later. |
| 1045 | if (mi->isRegSequence()) |
| 1046 | RegSequences.push_back(&*mi); |
| 1047 | |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 1048 | const TargetInstrDesc &TID = mi->getDesc(); |
Evan Cheng | 360c2dd | 2006-11-01 23:06:55 +0000 | [diff] [blame] | 1049 | bool FirstTied = true; |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 1050 | |
Evan Cheng | 7543e58 | 2008-06-18 07:49:14 +0000 | [diff] [blame] | 1051 | DistanceMap.insert(std::make_pair(mi, ++Dist)); |
Evan Cheng | 870b807 | 2009-03-01 02:03:43 +0000 | [diff] [blame] | 1052 | |
| 1053 | ProcessCopy(&*mi, &*mbbi, Processed); |
| 1054 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1055 | // First scan through all the tied register uses in this instruction |
| 1056 | // and record a list of pairs of tied operands for each register. |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 1057 | unsigned NumOps = mi->isInlineAsm() |
Evan Cheng | fb11288 | 2009-03-23 08:01:15 +0000 | [diff] [blame] | 1058 | ? mi->getNumOperands() : TID.getNumOperands(); |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1059 | for (unsigned SrcIdx = 0; SrcIdx < NumOps; ++SrcIdx) { |
| 1060 | unsigned DstIdx = 0; |
| 1061 | if (!mi->isRegTiedToDefOperand(SrcIdx, &DstIdx)) |
Evan Cheng | 360c2dd | 2006-11-01 23:06:55 +0000 | [diff] [blame] | 1062 | continue; |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 1063 | |
Evan Cheng | 360c2dd | 2006-11-01 23:06:55 +0000 | [diff] [blame] | 1064 | if (FirstTied) { |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1065 | FirstTied = false; |
Evan Cheng | 360c2dd | 2006-11-01 23:06:55 +0000 | [diff] [blame] | 1066 | ++NumTwoAddressInstrs; |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 1067 | DEBUG(dbgs() << '\t' << *mi); |
Evan Cheng | 360c2dd | 2006-11-01 23:06:55 +0000 | [diff] [blame] | 1068 | } |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 1069 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1070 | assert(mi->getOperand(SrcIdx).isReg() && |
| 1071 | mi->getOperand(SrcIdx).getReg() && |
| 1072 | mi->getOperand(SrcIdx).isUse() && |
| 1073 | "two address instruction invalid"); |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 1074 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1075 | unsigned regB = mi->getOperand(SrcIdx).getReg(); |
| 1076 | TiedOperandMap::iterator OI = TiedOperands.find(regB); |
| 1077 | if (OI == TiedOperands.end()) { |
| 1078 | SmallVector<std::pair<unsigned, unsigned>, 4> TiedPair; |
| 1079 | OI = TiedOperands.insert(std::make_pair(regB, TiedPair)).first; |
| 1080 | } |
| 1081 | OI->second.push_back(std::make_pair(SrcIdx, DstIdx)); |
| 1082 | } |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 1083 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1084 | // Now iterate over the information collected above. |
| 1085 | for (TiedOperandMap::iterator OI = TiedOperands.begin(), |
| 1086 | OE = TiedOperands.end(); OI != OE; ++OI) { |
| 1087 | SmallVector<std::pair<unsigned, unsigned>, 4> &TiedPairs = OI->second; |
Evan Cheng | 360c2dd | 2006-11-01 23:06:55 +0000 | [diff] [blame] | 1088 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1089 | // If the instruction has a single pair of tied operands, try some |
| 1090 | // transformations that may either eliminate the tied operands or |
| 1091 | // improve the opportunities for coalescing away the register copy. |
| 1092 | if (TiedOperands.size() == 1 && TiedPairs.size() == 1) { |
| 1093 | unsigned SrcIdx = TiedPairs[0].first; |
| 1094 | unsigned DstIdx = TiedPairs[0].second; |
Bob Wilson | 4344979 | 2009-08-31 21:54:55 +0000 | [diff] [blame] | 1095 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1096 | // If the registers are already equal, nothing needs to be done. |
| 1097 | if (mi->getOperand(SrcIdx).getReg() == |
| 1098 | mi->getOperand(DstIdx).getReg()) |
| 1099 | break; // Done with this instruction. |
| 1100 | |
| 1101 | if (TryInstructionTransform(mi, nmi, mbbi, SrcIdx, DstIdx, Dist)) |
| 1102 | break; // The tied operands have been eliminated. |
| 1103 | } |
| 1104 | |
| 1105 | bool RemovedKillFlag = false; |
| 1106 | bool AllUsesCopied = true; |
| 1107 | unsigned LastCopiedReg = 0; |
| 1108 | unsigned regB = OI->first; |
| 1109 | for (unsigned tpi = 0, tpe = TiedPairs.size(); tpi != tpe; ++tpi) { |
| 1110 | unsigned SrcIdx = TiedPairs[tpi].first; |
| 1111 | unsigned DstIdx = TiedPairs[tpi].second; |
| 1112 | unsigned regA = mi->getOperand(DstIdx).getReg(); |
| 1113 | // Grab regB from the instruction because it may have changed if the |
| 1114 | // instruction was commuted. |
| 1115 | regB = mi->getOperand(SrcIdx).getReg(); |
| 1116 | |
| 1117 | if (regA == regB) { |
| 1118 | // The register is tied to multiple destinations (or else we would |
| 1119 | // not have continued this far), but this use of the register |
| 1120 | // already matches the tied destination. Leave it. |
| 1121 | AllUsesCopied = false; |
| 1122 | continue; |
| 1123 | } |
| 1124 | LastCopiedReg = regA; |
| 1125 | |
| 1126 | assert(TargetRegisterInfo::isVirtualRegister(regB) && |
| 1127 | "cannot make instruction into two-address form"); |
Chris Lattner | 6b50767 | 2004-01-31 21:21:43 +0000 | [diff] [blame] | 1128 | |
Chris Lattner | 1e31363 | 2004-07-21 23:17:57 +0000 | [diff] [blame] | 1129 | #ifndef NDEBUG |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1130 | // First, verify that we don't have a use of "a" in the instruction |
| 1131 | // (a = b + a for example) because our transformation will not |
| 1132 | // work. This should never occur because we are in SSA form. |
| 1133 | for (unsigned i = 0; i != mi->getNumOperands(); ++i) |
| 1134 | assert(i == DstIdx || |
| 1135 | !mi->getOperand(i).isReg() || |
| 1136 | mi->getOperand(i).getReg() != regA); |
Chris Lattner | 1e31363 | 2004-07-21 23:17:57 +0000 | [diff] [blame] | 1137 | #endif |
Alkis Evlogimenos | 14be640 | 2004-02-04 22:17:40 +0000 | [diff] [blame] | 1138 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1139 | // Emit a copy or rematerialize the definition. |
| 1140 | const TargetRegisterClass *rc = MRI->getRegClass(regB); |
| 1141 | MachineInstr *DefMI = MRI->getVRegDef(regB); |
| 1142 | // If it's safe and profitable, remat the definition instead of |
| 1143 | // copying it. |
| 1144 | if (DefMI && |
| 1145 | DefMI->getDesc().isAsCheapAsAMove() && |
Evan Cheng | ac1abde | 2010-03-02 19:03:01 +0000 | [diff] [blame] | 1146 | DefMI->isSafeToReMat(TII, AA, regB) && |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1147 | isProfitableToReMat(regB, rc, mi, DefMI, mbbi, Dist)){ |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 1148 | DEBUG(dbgs() << "2addr: REMATTING : " << *DefMI << "\n"); |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1149 | unsigned regASubIdx = mi->getOperand(DstIdx).getSubReg(); |
Jakob Stoklund Olesen | 9edf7de | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 1150 | TII->reMaterialize(*mbbi, mi, regA, regASubIdx, DefMI, *TRI); |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1151 | ReMatRegs.set(regB); |
| 1152 | ++NumReMats; |
Bob Wilson | 71124f6 | 2009-09-01 04:18:40 +0000 | [diff] [blame] | 1153 | } else { |
Jakob Stoklund Olesen | 92c1f72 | 2010-07-10 19:08:25 +0000 | [diff] [blame] | 1154 | BuildMI(*mbbi, mi, mi->getDebugLoc(), TII->get(TargetOpcode::COPY), |
| 1155 | regA).addReg(regB); |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | MachineBasicBlock::iterator prevMI = prior(mi); |
| 1159 | // Update DistanceMap. |
| 1160 | DistanceMap.insert(std::make_pair(prevMI, Dist)); |
| 1161 | DistanceMap[mi] = ++Dist; |
| 1162 | |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 1163 | DEBUG(dbgs() << "\t\tprepend:\t" << *prevMI); |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1164 | |
| 1165 | MachineOperand &MO = mi->getOperand(SrcIdx); |
| 1166 | assert(MO.isReg() && MO.getReg() == regB && MO.isUse() && |
| 1167 | "inconsistent operand info for 2-reg pass"); |
| 1168 | if (MO.isKill()) { |
| 1169 | MO.setIsKill(false); |
| 1170 | RemovedKillFlag = true; |
| 1171 | } |
| 1172 | MO.setReg(regA); |
| 1173 | } |
| 1174 | |
| 1175 | if (AllUsesCopied) { |
| 1176 | // Replace other (un-tied) uses of regB with LastCopiedReg. |
| 1177 | for (unsigned i = 0, e = mi->getNumOperands(); i != e; ++i) { |
| 1178 | MachineOperand &MO = mi->getOperand(i); |
| 1179 | if (MO.isReg() && MO.getReg() == regB && MO.isUse()) { |
| 1180 | if (MO.isKill()) { |
| 1181 | MO.setIsKill(false); |
| 1182 | RemovedKillFlag = true; |
| 1183 | } |
| 1184 | MO.setReg(LastCopiedReg); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | // Update live variables for regB. |
| 1189 | if (RemovedKillFlag && LV && LV->getVarInfo(regB).removeKill(mi)) |
| 1190 | LV->addVirtualRegisterKilled(regB, prior(mi)); |
| 1191 | |
| 1192 | } else if (RemovedKillFlag) { |
| 1193 | // Some tied uses of regB matched their destination registers, so |
| 1194 | // regB is still used in this instruction, but a kill flag was |
| 1195 | // removed from a different tied use of regB, so now we need to add |
| 1196 | // a kill flag to one of the remaining uses of regB. |
| 1197 | for (unsigned i = 0, e = mi->getNumOperands(); i != e; ++i) { |
| 1198 | MachineOperand &MO = mi->getOperand(i); |
| 1199 | if (MO.isReg() && MO.getReg() == regB && MO.isUse()) { |
| 1200 | MO.setIsKill(true); |
| 1201 | break; |
Bob Wilson | 71124f6 | 2009-09-01 04:18:40 +0000 | [diff] [blame] | 1202 | } |
| 1203 | } |
Bob Wilson | 4344979 | 2009-08-31 21:54:55 +0000 | [diff] [blame] | 1204 | } |
Evan Cheng | 68fc2da | 2010-06-09 19:26:01 +0000 | [diff] [blame] | 1205 | |
| 1206 | // Schedule the source copy / remat inserted to form two-address |
| 1207 | // instruction. FIXME: Does it matter the distance map may not be |
| 1208 | // accurate after it's scheduled? |
| 1209 | TII->scheduleTwoAddrSource(prior(mi), mi, *TRI); |
| 1210 | |
Bob Wilson | 4344979 | 2009-08-31 21:54:55 +0000 | [diff] [blame] | 1211 | MadeChange = true; |
| 1212 | |
David Greene | eb00b18 | 2010-01-05 01:24:21 +0000 | [diff] [blame] | 1213 | DEBUG(dbgs() << "\t\trewrite to:\t" << *mi); |
Misha Brukman | 75fa4e4 | 2004-07-22 15:26:23 +0000 | [diff] [blame] | 1214 | } |
Bill Wendling | 637980e | 2008-05-10 00:12:52 +0000 | [diff] [blame] | 1215 | |
Jakob Stoklund Olesen | ed2185e | 2010-07-06 23:26:25 +0000 | [diff] [blame] | 1216 | // Rewrite INSERT_SUBREG as COPY now that we no longer need SSA form. |
| 1217 | if (mi->isInsertSubreg()) { |
| 1218 | // From %reg = INSERT_SUBREG %reg, %subreg, subidx |
| 1219 | // To %reg:subidx = COPY %subreg |
| 1220 | unsigned SubIdx = mi->getOperand(3).getImm(); |
| 1221 | mi->RemoveOperand(3); |
| 1222 | assert(mi->getOperand(0).getSubReg() == 0 && "Unexpected subreg idx"); |
| 1223 | mi->getOperand(0).setSubReg(SubIdx); |
| 1224 | mi->RemoveOperand(1); |
| 1225 | mi->setDesc(TII->get(TargetOpcode::COPY)); |
| 1226 | DEBUG(dbgs() << "\t\tconvert to:\t" << *mi); |
| 1227 | } |
| 1228 | |
Bob Wilson | cc80df9 | 2009-09-03 20:58:42 +0000 | [diff] [blame] | 1229 | // Clear TiedOperands here instead of at the top of the loop |
| 1230 | // since most instructions do not have tied operands. |
| 1231 | TiedOperands.clear(); |
Evan Cheng | 7a963fa | 2008-03-27 01:27:25 +0000 | [diff] [blame] | 1232 | mi = nmi; |
Misha Brukman | 75fa4e4 | 2004-07-22 15:26:23 +0000 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
Evan Cheng | 601ca4b | 2008-06-25 01:16:38 +0000 | [diff] [blame] | 1236 | // Some remat'ed instructions are dead. |
| 1237 | int VReg = ReMatRegs.find_first(); |
| 1238 | while (VReg != -1) { |
Evan Cheng | f1250ee | 2010-03-23 20:36:12 +0000 | [diff] [blame] | 1239 | if (MRI->use_nodbg_empty(VReg)) { |
Evan Cheng | 601ca4b | 2008-06-25 01:16:38 +0000 | [diff] [blame] | 1240 | MachineInstr *DefMI = MRI->getVRegDef(VReg); |
| 1241 | DefMI->eraseFromParent(); |
Bill Wendling | a16157a | 2008-05-26 05:49:49 +0000 | [diff] [blame] | 1242 | } |
Evan Cheng | 601ca4b | 2008-06-25 01:16:38 +0000 | [diff] [blame] | 1243 | VReg = ReMatRegs.find_next(VReg); |
Bill Wendling | 48f7f23 | 2008-05-26 05:18:34 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1246 | // Eliminate REG_SEQUENCE instructions. Their whole purpose was to preseve |
| 1247 | // SSA form. It's now safe to de-SSA. |
| 1248 | MadeChange |= EliminateRegSequences(); |
| 1249 | |
Misha Brukman | 75fa4e4 | 2004-07-22 15:26:23 +0000 | [diff] [blame] | 1250 | return MadeChange; |
Alkis Evlogimenos | 71499de | 2003-12-18 13:06:04 +0000 | [diff] [blame] | 1251 | } |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1252 | |
| 1253 | static void UpdateRegSequenceSrcs(unsigned SrcReg, |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 1254 | unsigned DstReg, unsigned SubIdx, |
Jakob Stoklund Olesen | 5a0d4fc | 2010-05-29 00:14:14 +0000 | [diff] [blame] | 1255 | MachineRegisterInfo *MRI, |
| 1256 | const TargetRegisterInfo &TRI) { |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1257 | for (MachineRegisterInfo::reg_iterator RI = MRI->reg_begin(SrcReg), |
Evan Cheng | 3ae56bc | 2010-05-12 01:27:49 +0000 | [diff] [blame] | 1258 | RE = MRI->reg_end(); RI != RE; ) { |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1259 | MachineOperand &MO = RI.getOperand(); |
| 1260 | ++RI; |
Jakob Stoklund Olesen | 5a0d4fc | 2010-05-29 00:14:14 +0000 | [diff] [blame] | 1261 | MO.substVirtReg(DstReg, SubIdx, TRI); |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | /// CoalesceExtSubRegs - If a number of sources of the REG_SEQUENCE are |
| 1266 | /// EXTRACT_SUBREG from the same register and to the same virtual register |
| 1267 | /// with different sub-register indices, attempt to combine the |
| 1268 | /// EXTRACT_SUBREGs and pre-coalesce them. e.g. |
| 1269 | /// %reg1026<def> = VLDMQ %reg1025<kill>, 260, pred:14, pred:%reg0 |
| 1270 | /// %reg1029:6<def> = EXTRACT_SUBREG %reg1026, 6 |
| 1271 | /// %reg1029:5<def> = EXTRACT_SUBREG %reg1026<kill>, 5 |
| 1272 | /// Since D subregs 5, 6 can combine to a Q register, we can coalesce |
| 1273 | /// reg1026 to reg1029. |
| 1274 | void |
| 1275 | TwoAddressInstructionPass::CoalesceExtSubRegs(SmallVector<unsigned,4> &Srcs, |
| 1276 | unsigned DstReg) { |
| 1277 | SmallSet<unsigned, 4> Seen; |
| 1278 | for (unsigned i = 0, e = Srcs.size(); i != e; ++i) { |
| 1279 | unsigned SrcReg = Srcs[i]; |
| 1280 | if (!Seen.insert(SrcReg)) |
| 1281 | continue; |
| 1282 | |
Bob Wilson | 26bf8f9 | 2010-06-03 23:53:58 +0000 | [diff] [blame] | 1283 | // Check that the instructions are all in the same basic block. |
| 1284 | MachineInstr *SrcDefMI = MRI->getVRegDef(SrcReg); |
| 1285 | MachineInstr *DstDefMI = MRI->getVRegDef(DstReg); |
| 1286 | if (SrcDefMI->getParent() != DstDefMI->getParent()) |
| 1287 | continue; |
| 1288 | |
Jakob Stoklund Olesen | 0bc25f4 | 2010-07-08 16:40:22 +0000 | [diff] [blame] | 1289 | // If there are no other uses than copies which feed into |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 1290 | // the reg_sequence, then we might be able to coalesce them. |
| 1291 | bool CanCoalesce = true; |
Bob Wilson | 4ffd22d | 2010-06-15 17:27:54 +0000 | [diff] [blame] | 1292 | SmallVector<unsigned, 4> SrcSubIndices, DstSubIndices; |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 1293 | for (MachineRegisterInfo::use_nodbg_iterator |
| 1294 | UI = MRI->use_nodbg_begin(SrcReg), |
| 1295 | UE = MRI->use_nodbg_end(); UI != UE; ++UI) { |
| 1296 | MachineInstr *UseMI = &*UI; |
Jakob Stoklund Olesen | 0bc25f4 | 2010-07-08 16:40:22 +0000 | [diff] [blame] | 1297 | if (!UseMI->isCopy() || UseMI->getOperand(0).getReg() != DstReg) { |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 1298 | CanCoalesce = false; |
| 1299 | break; |
| 1300 | } |
Jakob Stoklund Olesen | 0bc25f4 | 2010-07-08 16:40:22 +0000 | [diff] [blame] | 1301 | SrcSubIndices.push_back(UseMI->getOperand(1).getSubReg()); |
Bob Wilson | 4ffd22d | 2010-06-15 17:27:54 +0000 | [diff] [blame] | 1302 | DstSubIndices.push_back(UseMI->getOperand(0).getSubReg()); |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
Bob Wilson | 4ffd22d | 2010-06-15 17:27:54 +0000 | [diff] [blame] | 1305 | if (!CanCoalesce || SrcSubIndices.size() < 2) |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 1306 | continue; |
| 1307 | |
Bob Wilson | 4ffd22d | 2010-06-15 17:27:54 +0000 | [diff] [blame] | 1308 | // Check that the source subregisters can be combined. |
| 1309 | std::sort(SrcSubIndices.begin(), SrcSubIndices.end()); |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1310 | unsigned NewSrcSubIdx = 0; |
Bob Wilson | 4ffd22d | 2010-06-15 17:27:54 +0000 | [diff] [blame] | 1311 | if (!TRI->canCombineSubRegIndices(MRI->getRegClass(SrcReg), SrcSubIndices, |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1312 | NewSrcSubIdx)) |
Bob Wilson | 26bf8f9 | 2010-06-03 23:53:58 +0000 | [diff] [blame] | 1313 | continue; |
| 1314 | |
Bob Wilson | 4ffd22d | 2010-06-15 17:27:54 +0000 | [diff] [blame] | 1315 | // Check that the destination subregisters can also be combined. |
| 1316 | std::sort(DstSubIndices.begin(), DstSubIndices.end()); |
| 1317 | unsigned NewDstSubIdx = 0; |
| 1318 | if (!TRI->canCombineSubRegIndices(MRI->getRegClass(DstReg), DstSubIndices, |
| 1319 | NewDstSubIdx)) |
| 1320 | continue; |
| 1321 | |
| 1322 | // If neither source nor destination can be combined to the full register, |
| 1323 | // just give up. This could be improved if it ever matters. |
| 1324 | if (NewSrcSubIdx != 0 && NewDstSubIdx != 0) |
| 1325 | continue; |
| 1326 | |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1327 | // Now that we know that all the uses are extract_subregs and that those |
| 1328 | // subregs can somehow be combined, scan all the extract_subregs again to |
| 1329 | // make sure the subregs are in the right order and can be composed. |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1330 | MachineInstr *SomeMI = 0; |
| 1331 | CanCoalesce = true; |
| 1332 | for (MachineRegisterInfo::use_nodbg_iterator |
| 1333 | UI = MRI->use_nodbg_begin(SrcReg), |
| 1334 | UE = MRI->use_nodbg_end(); UI != UE; ++UI) { |
| 1335 | MachineInstr *UseMI = &*UI; |
Jakob Stoklund Olesen | 0bc25f4 | 2010-07-08 16:40:22 +0000 | [diff] [blame] | 1336 | assert(UseMI->isCopy()); |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1337 | unsigned DstSubIdx = UseMI->getOperand(0).getSubReg(); |
Jakob Stoklund Olesen | 0bc25f4 | 2010-07-08 16:40:22 +0000 | [diff] [blame] | 1338 | unsigned SrcSubIdx = UseMI->getOperand(1).getSubReg(); |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1339 | assert(DstSubIdx != 0 && "missing subreg from RegSequence elimination"); |
Bob Wilson | 4ffd22d | 2010-06-15 17:27:54 +0000 | [diff] [blame] | 1340 | if ((NewDstSubIdx == 0 && |
| 1341 | TRI->composeSubRegIndices(NewSrcSubIdx, DstSubIdx) != SrcSubIdx) || |
| 1342 | (NewSrcSubIdx == 0 && |
| 1343 | TRI->composeSubRegIndices(NewDstSubIdx, SrcSubIdx) != DstSubIdx)) { |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1344 | CanCoalesce = false; |
| 1345 | break; |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 1346 | } |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1347 | // Keep track of one of the uses. |
| 1348 | SomeMI = UseMI; |
| 1349 | } |
| 1350 | if (!CanCoalesce) |
| 1351 | continue; |
| 1352 | |
Jakob Stoklund Olesen | 0bc25f4 | 2010-07-08 16:40:22 +0000 | [diff] [blame] | 1353 | // Insert a copy to replace the original. |
Jakob Stoklund Olesen | 5c00e07 | 2010-07-08 16:40:15 +0000 | [diff] [blame] | 1354 | MachineInstr *CopyMI = BuildMI(*SomeMI->getParent(), SomeMI, |
| 1355 | SomeMI->getDebugLoc(), |
| 1356 | TII->get(TargetOpcode::COPY)) |
| 1357 | .addReg(DstReg, RegState::Define, NewDstSubIdx) |
| 1358 | .addReg(SrcReg, 0, NewSrcSubIdx); |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1359 | |
| 1360 | // Remove all the old extract instructions. |
| 1361 | for (MachineRegisterInfo::use_nodbg_iterator |
| 1362 | UI = MRI->use_nodbg_begin(SrcReg), |
| 1363 | UE = MRI->use_nodbg_end(); UI != UE; ) { |
| 1364 | MachineInstr *UseMI = &*UI; |
| 1365 | ++UI; |
| 1366 | if (UseMI == CopyMI) |
| 1367 | continue; |
Jakob Stoklund Olesen | 0bc25f4 | 2010-07-08 16:40:22 +0000 | [diff] [blame] | 1368 | assert(UseMI->isCopy()); |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1369 | // Move any kills to the new copy or extract instruction. |
| 1370 | if (UseMI->getOperand(1).isKill()) { |
Jakob Stoklund Olesen | 0bc25f4 | 2010-07-08 16:40:22 +0000 | [diff] [blame] | 1371 | CopyMI->getOperand(1).setIsKill(); |
Bob Wilson | 852a7e3 | 2010-06-15 05:56:31 +0000 | [diff] [blame] | 1372 | if (LV) |
| 1373 | // Update live variables |
| 1374 | LV->replaceKillInstruction(SrcReg, UseMI, &*CopyMI); |
| 1375 | } |
| 1376 | UseMI->eraseFromParent(); |
| 1377 | } |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1378 | } |
| 1379 | } |
| 1380 | |
Evan Cheng | c6dcce3 | 2010-05-17 23:24:12 +0000 | [diff] [blame] | 1381 | static bool HasOtherRegSequenceUses(unsigned Reg, MachineInstr *RegSeq, |
| 1382 | MachineRegisterInfo *MRI) { |
| 1383 | for (MachineRegisterInfo::use_iterator UI = MRI->use_begin(Reg), |
| 1384 | UE = MRI->use_end(); UI != UE; ++UI) { |
| 1385 | MachineInstr *UseMI = &*UI; |
| 1386 | if (UseMI != RegSeq && UseMI->isRegSequence()) |
| 1387 | return true; |
| 1388 | } |
| 1389 | return false; |
| 1390 | } |
| 1391 | |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1392 | /// EliminateRegSequences - Eliminate REG_SEQUENCE instructions as part |
| 1393 | /// of the de-ssa process. This replaces sources of REG_SEQUENCE as |
| 1394 | /// sub-register references of the register defined by REG_SEQUENCE. e.g. |
| 1395 | /// |
| 1396 | /// %reg1029<def>, %reg1030<def> = VLD1q16 %reg1024<kill>, ... |
| 1397 | /// %reg1031<def> = REG_SEQUENCE %reg1029<kill>, 5, %reg1030<kill>, 6 |
| 1398 | /// => |
| 1399 | /// %reg1031:5<def>, %reg1031:6<def> = VLD1q16 %reg1024<kill>, ... |
| 1400 | bool TwoAddressInstructionPass::EliminateRegSequences() { |
| 1401 | if (RegSequences.empty()) |
| 1402 | return false; |
| 1403 | |
| 1404 | for (unsigned i = 0, e = RegSequences.size(); i != e; ++i) { |
| 1405 | MachineInstr *MI = RegSequences[i]; |
| 1406 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 1407 | if (MI->getOperand(0).getSubReg() || |
| 1408 | TargetRegisterInfo::isPhysicalRegister(DstReg) || |
| 1409 | !(MI->getNumOperands() & 1)) { |
| 1410 | DEBUG(dbgs() << "Illegal REG_SEQUENCE instruction:" << *MI); |
| 1411 | llvm_unreachable(0); |
| 1412 | } |
Evan Cheng | 0bcccac | 2010-05-11 00:04:31 +0000 | [diff] [blame] | 1413 | |
Evan Cheng | 44bfdd3 | 2010-05-17 22:09:49 +0000 | [diff] [blame] | 1414 | bool IsImpDef = true; |
Evan Cheng | b990a2f | 2010-05-14 23:21:14 +0000 | [diff] [blame] | 1415 | SmallVector<unsigned, 4> RealSrcs; |
Evan Cheng | 0bcccac | 2010-05-11 00:04:31 +0000 | [diff] [blame] | 1416 | SmallSet<unsigned, 4> Seen; |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1417 | for (unsigned i = 1, e = MI->getNumOperands(); i < e; i += 2) { |
| 1418 | unsigned SrcReg = MI->getOperand(i).getReg(); |
| 1419 | if (MI->getOperand(i).getSubReg() || |
| 1420 | TargetRegisterInfo::isPhysicalRegister(SrcReg)) { |
| 1421 | DEBUG(dbgs() << "Illegal REG_SEQUENCE instruction:" << *MI); |
| 1422 | llvm_unreachable(0); |
| 1423 | } |
Evan Cheng | 0bcccac | 2010-05-11 00:04:31 +0000 | [diff] [blame] | 1424 | |
Evan Cheng | 054dbb8 | 2010-05-13 00:00:35 +0000 | [diff] [blame] | 1425 | MachineInstr *DefMI = MRI->getVRegDef(SrcReg); |
Evan Cheng | b990a2f | 2010-05-14 23:21:14 +0000 | [diff] [blame] | 1426 | if (DefMI->isImplicitDef()) { |
| 1427 | DefMI->eraseFromParent(); |
| 1428 | continue; |
| 1429 | } |
Evan Cheng | 44bfdd3 | 2010-05-17 22:09:49 +0000 | [diff] [blame] | 1430 | IsImpDef = false; |
Evan Cheng | b990a2f | 2010-05-14 23:21:14 +0000 | [diff] [blame] | 1431 | |
Jakob Stoklund Olesen | 0bc25f4 | 2010-07-08 16:40:22 +0000 | [diff] [blame] | 1432 | // Remember COPY sources. These might be candidate for coalescing. |
Jakob Stoklund Olesen | c0075cc | 2010-07-10 22:42:53 +0000 | [diff] [blame] | 1433 | if (DefMI->isCopy() && DefMI->getOperand(1).getSubReg()) |
Evan Cheng | b990a2f | 2010-05-14 23:21:14 +0000 | [diff] [blame] | 1434 | RealSrcs.push_back(DefMI->getOperand(1).getReg()); |
| 1435 | |
Jakob Stoklund Olesen | 1e1098c | 2010-07-10 22:42:59 +0000 | [diff] [blame] | 1436 | bool isKill = MI->getOperand(i).isKill(); |
| 1437 | if (!Seen.insert(SrcReg) || MI->getParent() != DefMI->getParent() || |
| 1438 | !isKill || HasOtherRegSequenceUses(SrcReg, MI, MRI)) { |
Evan Cheng | 054dbb8 | 2010-05-13 00:00:35 +0000 | [diff] [blame] | 1439 | // REG_SEQUENCE cannot have duplicated operands, add a copy. |
Jakob Stoklund Olesen | 3437352 | 2010-05-19 20:08:00 +0000 | [diff] [blame] | 1440 | // Also add an copy if the source is live-in the block. We don't want |
Evan Cheng | 054dbb8 | 2010-05-13 00:00:35 +0000 | [diff] [blame] | 1441 | // to end up with a partial-redef of a livein, e.g. |
| 1442 | // BB0: |
| 1443 | // reg1051:10<def> = |
| 1444 | // ... |
| 1445 | // BB1: |
| 1446 | // ... = reg1051:10 |
| 1447 | // BB2: |
| 1448 | // reg1051:9<def> = |
| 1449 | // LiveIntervalAnalysis won't like it. |
Jakob Stoklund Olesen | 3437352 | 2010-05-19 20:08:00 +0000 | [diff] [blame] | 1450 | // |
| 1451 | // If the REG_SEQUENCE doesn't kill its source, keeping live variables |
| 1452 | // correctly up to date becomes very difficult. Insert a copy. |
Jakob Stoklund Olesen | e4b9c4f | 2010-08-09 20:19:16 +0000 | [diff] [blame] | 1453 | |
| 1454 | // Defer any kill flag to the last operand using SrcReg. Otherwise, we |
| 1455 | // might insert a COPY that uses SrcReg after is was killed. |
| 1456 | if (isKill) |
| 1457 | for (unsigned j = i + 2; j < e; j += 2) |
| 1458 | if (MI->getOperand(j).getReg() == SrcReg) { |
| 1459 | MI->getOperand(j).setIsKill(); |
| 1460 | isKill = false; |
| 1461 | break; |
| 1462 | } |
| 1463 | |
Evan Cheng | 054dbb8 | 2010-05-13 00:00:35 +0000 | [diff] [blame] | 1464 | MachineBasicBlock::iterator InsertLoc = MI; |
Jakob Stoklund Olesen | 1e1098c | 2010-07-10 22:42:59 +0000 | [diff] [blame] | 1465 | MachineInstr *CopyMI = BuildMI(*MI->getParent(), InsertLoc, |
| 1466 | MI->getDebugLoc(), TII->get(TargetOpcode::COPY)) |
| 1467 | .addReg(DstReg, RegState::Define, MI->getOperand(i+1).getImm()) |
| 1468 | .addReg(SrcReg, getKillRegState(isKill)); |
| 1469 | MI->getOperand(i).setReg(0); |
| 1470 | if (LV && isKill) |
| 1471 | LV->replaceKillInstruction(SrcReg, MI, CopyMI); |
| 1472 | DEBUG(dbgs() << "Inserted: " << *CopyMI); |
Evan Cheng | 0bcccac | 2010-05-11 00:04:31 +0000 | [diff] [blame] | 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | for (unsigned i = 1, e = MI->getNumOperands(); i < e; i += 2) { |
| 1477 | unsigned SrcReg = MI->getOperand(i).getReg(); |
Jakob Stoklund Olesen | 1e1098c | 2010-07-10 22:42:59 +0000 | [diff] [blame] | 1478 | if (!SrcReg) continue; |
Evan Cheng | 53c779b | 2010-05-17 20:57:12 +0000 | [diff] [blame] | 1479 | unsigned SubIdx = MI->getOperand(i+1).getImm(); |
Jakob Stoklund Olesen | 5a0d4fc | 2010-05-29 00:14:14 +0000 | [diff] [blame] | 1480 | UpdateRegSequenceSrcs(SrcReg, DstReg, SubIdx, MRI, *TRI); |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Evan Cheng | 44bfdd3 | 2010-05-17 22:09:49 +0000 | [diff] [blame] | 1483 | if (IsImpDef) { |
| 1484 | DEBUG(dbgs() << "Turned: " << *MI << " into an IMPLICIT_DEF"); |
| 1485 | MI->setDesc(TII->get(TargetOpcode::IMPLICIT_DEF)); |
| 1486 | for (int j = MI->getNumOperands() - 1, ee = 0; j > ee; --j) |
| 1487 | MI->RemoveOperand(j); |
| 1488 | } else { |
| 1489 | DEBUG(dbgs() << "Eliminated: " << *MI); |
| 1490 | MI->eraseFromParent(); |
| 1491 | } |
Evan Cheng | b990a2f | 2010-05-14 23:21:14 +0000 | [diff] [blame] | 1492 | |
Jakob Stoklund Olesen | fe181f4 | 2010-06-18 23:10:20 +0000 | [diff] [blame] | 1493 | // Try coalescing some EXTRACT_SUBREG instructions. This can create |
| 1494 | // INSERT_SUBREG instructions that must have <undef> flags added by |
| 1495 | // LiveIntervalAnalysis, so only run it when LiveVariables is available. |
| 1496 | if (LV) |
| 1497 | CoalesceExtSubRegs(RealSrcs, DstReg); |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
Evan Cheng | fc6e6a9 | 2010-05-10 21:24:55 +0000 | [diff] [blame] | 1500 | RegSequences.clear(); |
Evan Cheng | 3d720fb | 2010-05-05 18:45:40 +0000 | [diff] [blame] | 1501 | return true; |
| 1502 | } |