Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- Thumb2ITBlockPass.cpp - Insert Thumb-2 IT blocks ------------------===// |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 10 | #include "ARM.h" |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 11 | #include "ARMMachineFunctionInfo.h" |
Evan Cheng | 017288a | 2009-07-11 07:26:20 +0000 | [diff] [blame] | 12 | #include "Thumb2InstrInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/SmallSet.h" |
| 14 | #include "llvm/ADT/Statistic.h" |
| 15 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineInstr.h" |
| 17 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineInstrBundle.h" |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 21 | #define DEBUG_TYPE "thumb2-it" |
| 22 | |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 23 | STATISTIC(NumITs, "Number of IT blocks inserted"); |
| 24 | STATISTIC(NumMovedInsts, "Number of predicated instructions moved"); |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 25 | |
| 26 | namespace { |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 27 | class Thumb2ITBlockPass : public MachineFunctionPass { |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 28 | public: |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 29 | static char ID; |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 30 | Thumb2ITBlockPass() : MachineFunctionPass(ID) {} |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 31 | |
Weiming Zhao | 0da5cc0 | 2013-11-13 18:29:49 +0000 | [diff] [blame] | 32 | bool restrictIT; |
Evan Cheng | 017288a | 2009-07-11 07:26:20 +0000 | [diff] [blame] | 33 | const Thumb2InstrInfo *TII; |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 34 | const TargetRegisterInfo *TRI; |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 35 | ARMFunctionInfo *AFI; |
| 36 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 37 | bool runOnMachineFunction(MachineFunction &Fn) override; |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 38 | |
Derek Schuff | 1dbf7a5 | 2016-04-04 17:09:25 +0000 | [diff] [blame] | 39 | MachineFunctionProperties getRequiredProperties() const override { |
| 40 | return MachineFunctionProperties().set( |
| 41 | MachineFunctionProperties::Property::AllVRegsAllocated); |
| 42 | } |
| 43 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 44 | const char *getPassName() const override { |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 45 | return "Thumb IT blocks insertion pass"; |
| 46 | } |
| 47 | |
| 48 | private: |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 49 | bool MoveCopyOutOfITBlock(MachineInstr *MI, |
| 50 | ARMCC::CondCodes CC, ARMCC::CondCodes OCC, |
| 51 | SmallSet<unsigned, 4> &Defs, |
| 52 | SmallSet<unsigned, 4> &Uses); |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 53 | bool InsertITInstructions(MachineBasicBlock &MBB); |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 54 | }; |
| 55 | char Thumb2ITBlockPass::ID = 0; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 56 | } |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 57 | |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 58 | /// TrackDefUses - Tracking what registers are being defined and used by |
| 59 | /// instructions in the IT block. This also tracks "dependencies", i.e. uses |
| 60 | /// in the IT block that are defined before the IT instruction. |
| 61 | static void TrackDefUses(MachineInstr *MI, |
| 62 | SmallSet<unsigned, 4> &Defs, |
| 63 | SmallSet<unsigned, 4> &Uses, |
| 64 | const TargetRegisterInfo *TRI) { |
| 65 | SmallVector<unsigned, 4> LocalDefs; |
| 66 | SmallVector<unsigned, 4> LocalUses; |
| 67 | |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 68 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 69 | MachineOperand &MO = MI->getOperand(i); |
| 70 | if (!MO.isReg()) |
| 71 | continue; |
| 72 | unsigned Reg = MO.getReg(); |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 73 | if (!Reg || Reg == ARM::ITSTATE || Reg == ARM::SP) |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 74 | continue; |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 75 | if (MO.isUse()) |
| 76 | LocalUses.push_back(Reg); |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 77 | else |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 78 | LocalDefs.push_back(Reg); |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 79 | } |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 80 | |
| 81 | for (unsigned i = 0, e = LocalUses.size(); i != e; ++i) { |
| 82 | unsigned Reg = LocalUses[i]; |
Chad Rosier | abdb1d6 | 2013-05-22 23:17:36 +0000 | [diff] [blame] | 83 | for (MCSubRegIterator Subreg(Reg, TRI, /*IncludeSelf=*/true); |
| 84 | Subreg.isValid(); ++Subreg) |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 85 | Uses.insert(*Subreg); |
| 86 | } |
| 87 | |
| 88 | for (unsigned i = 0, e = LocalDefs.size(); i != e; ++i) { |
| 89 | unsigned Reg = LocalDefs[i]; |
Chad Rosier | abdb1d6 | 2013-05-22 23:17:36 +0000 | [diff] [blame] | 90 | for (MCSubRegIterator Subreg(Reg, TRI, /*IncludeSelf=*/true); |
| 91 | Subreg.isValid(); ++Subreg) |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 92 | Defs.insert(*Subreg); |
| 93 | if (Reg == ARM::CPSR) |
| 94 | continue; |
| 95 | } |
| 96 | } |
| 97 | |
Pete Cooper | 4dddbcf | 2015-05-04 22:44:47 +0000 | [diff] [blame] | 98 | /// Clear kill flags for any uses in the given set. This will likely |
| 99 | /// conservatively remove more kill flags than are necessary, but removing them |
| 100 | /// is safer than incorrect kill flags remaining on instructions. |
| 101 | static void ClearKillFlags(MachineInstr *MI, SmallSet<unsigned, 4> &Uses) { |
Matthias Braun | e41e146 | 2015-05-29 02:56:46 +0000 | [diff] [blame] | 102 | for (MachineOperand &MO : MI->operands()) { |
| 103 | if (!MO.isReg() || MO.isDef() || !MO.isKill()) |
Pete Cooper | 4dddbcf | 2015-05-04 22:44:47 +0000 | [diff] [blame] | 104 | continue; |
Matthias Braun | e41e146 | 2015-05-29 02:56:46 +0000 | [diff] [blame] | 105 | if (!Uses.count(MO.getReg())) |
Pete Cooper | 4dddbcf | 2015-05-04 22:44:47 +0000 | [diff] [blame] | 106 | continue; |
Matthias Braun | e41e146 | 2015-05-29 02:56:46 +0000 | [diff] [blame] | 107 | MO.setIsKill(false); |
Pete Cooper | 4dddbcf | 2015-05-04 22:44:47 +0000 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
Jakob Stoklund Olesen | 54bcf50 | 2010-07-16 22:35:32 +0000 | [diff] [blame] | 111 | static bool isCopy(MachineInstr *MI) { |
| 112 | switch (MI->getOpcode()) { |
| 113 | default: |
| 114 | return false; |
| 115 | case ARM::MOVr: |
| 116 | case ARM::MOVr_TC: |
| 117 | case ARM::tMOVr: |
Jakob Stoklund Olesen | 54bcf50 | 2010-07-16 22:35:32 +0000 | [diff] [blame] | 118 | case ARM::t2MOVr: |
| 119 | return true; |
| 120 | } |
| 121 | } |
| 122 | |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 123 | bool |
| 124 | Thumb2ITBlockPass::MoveCopyOutOfITBlock(MachineInstr *MI, |
| 125 | ARMCC::CondCodes CC, ARMCC::CondCodes OCC, |
| 126 | SmallSet<unsigned, 4> &Defs, |
| 127 | SmallSet<unsigned, 4> &Uses) { |
Jakob Stoklund Olesen | 54bcf50 | 2010-07-16 22:35:32 +0000 | [diff] [blame] | 128 | if (!isCopy(MI)) |
| 129 | return false; |
| 130 | // llvm models select's as two-address instructions. That means a copy |
| 131 | // is inserted before a t2MOVccr, etc. If the copy is scheduled in |
| 132 | // between selects we would end up creating multiple IT blocks. |
| 133 | assert(MI->getOperand(0).getSubReg() == 0 && |
| 134 | MI->getOperand(1).getSubReg() == 0 && |
| 135 | "Sub-register indices still around?"); |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 136 | |
Jakob Stoklund Olesen | 54bcf50 | 2010-07-16 22:35:32 +0000 | [diff] [blame] | 137 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 138 | unsigned SrcReg = MI->getOperand(1).getReg(); |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 139 | |
Jakob Stoklund Olesen | 54bcf50 | 2010-07-16 22:35:32 +0000 | [diff] [blame] | 140 | // First check if it's safe to move it. |
| 141 | if (Uses.count(DstReg) || Defs.count(SrcReg)) |
| 142 | return false; |
| 143 | |
Bill Wendling | 0a10cdc | 2011-10-10 22:52:53 +0000 | [diff] [blame] | 144 | // If the CPSR is defined by this copy, then we don't want to move it. E.g., |
| 145 | // if we have: |
| 146 | // |
| 147 | // movs r1, r1 |
| 148 | // rsb r1, 0 |
| 149 | // movs r2, r2 |
| 150 | // rsb r2, 0 |
| 151 | // |
| 152 | // we don't want this to be converted to: |
| 153 | // |
| 154 | // movs r1, r1 |
| 155 | // movs r2, r2 |
| 156 | // itt mi |
| 157 | // rsb r1, 0 |
| 158 | // rsb r2, 0 |
| 159 | // |
Bill Wendling | 9870335 | 2011-10-11 00:10:41 +0000 | [diff] [blame] | 160 | const MCInstrDesc &MCID = MI->getDesc(); |
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 161 | if (MI->hasOptionalDef() && |
Bill Wendling | 9870335 | 2011-10-11 00:10:41 +0000 | [diff] [blame] | 162 | MI->getOperand(MCID.getNumOperands() - 1).getReg() == ARM::CPSR) |
| 163 | return false; |
Bill Wendling | 0a10cdc | 2011-10-10 22:52:53 +0000 | [diff] [blame] | 164 | |
Jakob Stoklund Olesen | 54bcf50 | 2010-07-16 22:35:32 +0000 | [diff] [blame] | 165 | // Then peek at the next instruction to see if it's predicated on CC or OCC. |
| 166 | // If not, then there is nothing to be gained by moving the copy. |
| 167 | MachineBasicBlock::iterator I = MI; ++I; |
| 168 | MachineBasicBlock::iterator E = MI->getParent()->end(); |
| 169 | while (I != E && I->isDebugValue()) |
| 170 | ++I; |
| 171 | if (I != E) { |
| 172 | unsigned NPredReg = 0; |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 173 | ARMCC::CondCodes NCC = getITInstrPredicate(*I, NPredReg); |
Jakob Stoklund Olesen | 54bcf50 | 2010-07-16 22:35:32 +0000 | [diff] [blame] | 174 | if (NCC == CC || NCC == OCC) |
| 175 | return true; |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 176 | } |
| 177 | return false; |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | bool Thumb2ITBlockPass::InsertITInstructions(MachineBasicBlock &MBB) { |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 181 | bool Modified = false; |
| 182 | |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 183 | SmallSet<unsigned, 4> Defs; |
| 184 | SmallSet<unsigned, 4> Uses; |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 185 | MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end(); |
| 186 | while (MBBI != E) { |
| 187 | MachineInstr *MI = &*MBBI; |
Evan Cheng | 83e0d48 | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 188 | DebugLoc dl = MI->getDebugLoc(); |
| 189 | unsigned PredReg = 0; |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 190 | ARMCC::CondCodes CC = getITInstrPredicate(*MI, PredReg); |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 191 | if (CC == ARMCC::AL) { |
| 192 | ++MBBI; |
| 193 | continue; |
| 194 | } |
| 195 | |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 196 | Defs.clear(); |
| 197 | Uses.clear(); |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 198 | TrackDefUses(MI, Defs, Uses, TRI); |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 199 | |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 200 | // Insert an IT instruction. |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 201 | MachineInstrBuilder MIB = BuildMI(MBB, MBBI, dl, TII->get(ARM::t2IT)) |
| 202 | .addImm(CC); |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 203 | |
| 204 | // Add implicit use of ITSTATE to IT block instructions. |
| 205 | MI->addOperand(MachineOperand::CreateReg(ARM::ITSTATE, false/*ifDef*/, |
| 206 | true/*isImp*/, false/*isKill*/)); |
| 207 | |
| 208 | MachineInstr *LastITMI = MI; |
Reid Kleckner | da00cf5 | 2014-10-31 23:19:46 +0000 | [diff] [blame] | 209 | MachineBasicBlock::iterator InsertPos = MIB.getInstr(); |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 210 | ++MBBI; |
| 211 | |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 212 | // Form IT block. |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 213 | ARMCC::CondCodes OCC = ARMCC::getOppositeCondition(CC); |
Evan Cheng | 6ddd7bc | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 214 | unsigned Mask = 0, Pos = 3; |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 215 | |
Weiming Zhao | 0da5cc0 | 2013-11-13 18:29:49 +0000 | [diff] [blame] | 216 | // v8 IT blocks are limited to one conditional op unless -arm-no-restrict-it |
| 217 | // is set: skip the loop |
| 218 | if (!restrictIT) { |
Joey Gouly | a5153cb | 2013-09-09 14:21:49 +0000 | [diff] [blame] | 219 | // Branches, including tricky ones like LDM_RET, need to end an IT |
| 220 | // block so check the instruction we just put in the block. |
| 221 | for (; MBBI != E && Pos && |
| 222 | (!MI->isBranch() && !MI->isReturn()) ; ++MBBI) { |
| 223 | if (MBBI->isDebugValue()) |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 224 | continue; |
Joey Gouly | a5153cb | 2013-09-09 14:21:49 +0000 | [diff] [blame] | 225 | |
| 226 | MachineInstr *NMI = &*MBBI; |
| 227 | MI = NMI; |
| 228 | |
| 229 | unsigned NPredReg = 0; |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 230 | ARMCC::CondCodes NCC = getITInstrPredicate(*NMI, NPredReg); |
Joey Gouly | a5153cb | 2013-09-09 14:21:49 +0000 | [diff] [blame] | 231 | if (NCC == CC || NCC == OCC) { |
| 232 | Mask |= (NCC & 1) << Pos; |
| 233 | // Add implicit use of ITSTATE. |
| 234 | NMI->addOperand(MachineOperand::CreateReg(ARM::ITSTATE, false/*ifDef*/, |
| 235 | true/*isImp*/, false/*isKill*/)); |
| 236 | LastITMI = NMI; |
| 237 | } else { |
| 238 | if (NCC == ARMCC::AL && |
| 239 | MoveCopyOutOfITBlock(NMI, CC, OCC, Defs, Uses)) { |
| 240 | --MBBI; |
| 241 | MBB.remove(NMI); |
| 242 | MBB.insert(InsertPos, NMI); |
Pete Cooper | 4dddbcf | 2015-05-04 22:44:47 +0000 | [diff] [blame] | 243 | ClearKillFlags(MI, Uses); |
Joey Gouly | a5153cb | 2013-09-09 14:21:49 +0000 | [diff] [blame] | 244 | ++NumMovedInsts; |
| 245 | continue; |
| 246 | } |
| 247 | break; |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 248 | } |
Joey Gouly | a5153cb | 2013-09-09 14:21:49 +0000 | [diff] [blame] | 249 | TrackDefUses(NMI, Defs, Uses, TRI); |
| 250 | --Pos; |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 251 | } |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 252 | } |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 253 | |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 254 | // Finalize IT mask. |
Evan Cheng | 6ddd7bc | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 255 | Mask |= (1 << Pos); |
Johnny Chen | 0910b5a | 2010-03-17 23:14:23 +0000 | [diff] [blame] | 256 | // Tag along (firstcond[0] << 4) with the mask. |
| 257 | Mask |= (CC & 1) << 4; |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 258 | MIB.addImm(Mask); |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 259 | |
| 260 | // Last instruction in IT block kills ITSTATE. |
| 261 | LastITMI->findRegisterUseOperand(ARM::ITSTATE)->setIsKill(); |
| 262 | |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 263 | // Finalize the bundle. |
Duncan P. N. Exon Smith | d84f600 | 2016-02-22 21:30:15 +0000 | [diff] [blame] | 264 | finalizeBundle(MBB, InsertPos.getInstrIterator(), |
| 265 | ++LastITMI->getIterator()); |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 266 | |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 267 | Modified = true; |
| 268 | ++NumITs; |
| 269 | } |
| 270 | |
| 271 | return Modified; |
| 272 | } |
| 273 | |
| 274 | bool Thumb2ITBlockPass::runOnMachineFunction(MachineFunction &Fn) { |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 275 | const ARMSubtarget &STI = |
| 276 | static_cast<const ARMSubtarget &>(Fn.getSubtarget()); |
Eric Christopher | 63b4488 | 2015-03-05 00:23:40 +0000 | [diff] [blame] | 277 | if (!STI.isThumb2()) |
| 278 | return false; |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 279 | AFI = Fn.getInfo<ARMFunctionInfo>(); |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 280 | TII = static_cast<const Thumb2InstrInfo *>(STI.getInstrInfo()); |
| 281 | TRI = STI.getRegisterInfo(); |
| 282 | restrictIT = STI.restrictIT(); |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 283 | |
| 284 | if (!AFI->isThumbFunction()) |
| 285 | return false; |
| 286 | |
| 287 | bool Modified = false; |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 288 | for (MachineFunction::iterator MFI = Fn.begin(), E = Fn.end(); MFI != E; ) { |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 289 | MachineBasicBlock &MBB = *MFI; |
Evan Cheng | 47cd593 | 2010-06-09 01:46:50 +0000 | [diff] [blame] | 290 | ++MFI; |
Evan Cheng | c3525dc | 2010-07-02 21:07:09 +0000 | [diff] [blame] | 291 | Modified |= InsertITInstructions(MBB); |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Evan Cheng | c3525dc | 2010-07-02 21:07:09 +0000 | [diff] [blame] | 294 | if (Modified) |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 295 | AFI->setHasITBlocks(true); |
| 296 | |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 297 | return Modified; |
| 298 | } |
| 299 | |
Evan Cheng | 4dc201e | 2009-08-08 02:54:37 +0000 | [diff] [blame] | 300 | /// createThumb2ITBlockPass - Returns an instance of the Thumb2 IT blocks |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 301 | /// insertion pass. |
Evan Cheng | c3525dc | 2010-07-02 21:07:09 +0000 | [diff] [blame] | 302 | FunctionPass *llvm::createThumb2ITBlockPass() { |
| 303 | return new Thumb2ITBlockPass(); |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 304 | } |