blob: 224262830b1272444d38c637c26c07473ceea0b2 [file] [log] [blame]
Eugene Zelenko60433b62017-10-05 00:33:50 +00001//===- X86VZeroUpper.cpp - AVX vzeroupper instruction inserter ------------===//
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +00002//
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//
10// This file defines the pass which inserts x86 AVX vzeroupper instructions
11// before calls to SSE encoded functions. This avoids transition latency
Andrea Di Biagio4f8bdcb2015-02-07 13:56:20 +000012// penalty when transferring control between AVX encoded instructions and old
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +000013// SSE encoding mode.
14//
15//===----------------------------------------------------------------------===//
16
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +000017#include "X86.h"
18#include "X86InstrInfo.h"
Elena Demikhovsky52e4a0e2014-01-05 10:46:09 +000019#include "X86Subtarget.h"
Eugene Zelenko60433b62017-10-05 00:33:50 +000020#include "llvm/ADT/SmallVector.h"
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +000021#include "llvm/ADT/Statistic.h"
Eugene Zelenko60433b62017-10-05 00:33:50 +000022#include "llvm/CodeGen/MachineBasicBlock.h"
23#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +000024#include "llvm/CodeGen/MachineFunctionPass.h"
Eugene Zelenko60433b62017-10-05 00:33:50 +000025#include "llvm/CodeGen/MachineInstr.h"
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +000026#include "llvm/CodeGen/MachineInstrBuilder.h"
Eugene Zelenko60433b62017-10-05 00:33:50 +000027#include "llvm/CodeGen/MachineOperand.h"
Eli Friedman8f249602011-11-04 23:46:11 +000028#include "llvm/CodeGen/MachineRegisterInfo.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000029#include "llvm/CodeGen/TargetInstrInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000030#include "llvm/CodeGen/TargetRegisterInfo.h"
Eugene Zelenko60433b62017-10-05 00:33:50 +000031#include "llvm/IR/CallingConv.h"
32#include "llvm/IR/DebugLoc.h"
33#include "llvm/IR/Function.h"
Eli Friedman8f249602011-11-04 23:46:11 +000034#include "llvm/Support/Debug.h"
Eugene Zelenko60433b62017-10-05 00:33:50 +000035#include "llvm/Support/ErrorHandling.h"
Eli Friedman8f249602011-11-04 23:46:11 +000036#include "llvm/Support/raw_ostream.h"
Eugene Zelenko60433b62017-10-05 00:33:50 +000037#include <cassert>
38
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +000039using namespace llvm;
40
Chandler Carruth84e68b22014-04-22 02:41:26 +000041#define DEBUG_TYPE "x86-vzeroupper"
42
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +000043STATISTIC(NumVZU, "Number of vzeroupper instructions inserted");
44
45namespace {
Lang Hames7c8189c2014-03-17 01:22:54 +000046
47 class VZeroUpperInserter : public MachineFunctionPass {
48 public:
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +000049 VZeroUpperInserter() : MachineFunctionPass(ID) {}
Eugene Zelenko60433b62017-10-05 00:33:50 +000050
Craig Topper2d9361e2014-03-09 07:44:38 +000051 bool runOnMachineFunction(MachineFunction &MF) override;
Eugene Zelenko60433b62017-10-05 00:33:50 +000052
Derek Schuff1dbf7a52016-04-04 17:09:25 +000053 MachineFunctionProperties getRequiredProperties() const override {
54 return MachineFunctionProperties().set(
Matthias Braun1eb47362016-08-25 01:27:13 +000055 MachineFunctionProperties::Property::NoVRegs);
Derek Schuff1dbf7a52016-04-04 17:09:25 +000056 }
Eugene Zelenko60433b62017-10-05 00:33:50 +000057
Mehdi Amini117296c2016-10-01 02:56:57 +000058 StringRef getPassName() const override { return "X86 vzeroupper inserter"; }
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +000059
60 private:
Lang Hames7c8189c2014-03-17 01:22:54 +000061 void processBasicBlock(MachineBasicBlock &MBB);
62 void insertVZeroUpper(MachineBasicBlock::iterator I,
63 MachineBasicBlock &MBB);
64 void addDirtySuccessor(MachineBasicBlock &MBB);
Eli Friedman8f249602011-11-04 23:46:11 +000065
Eugene Zelenko60433b62017-10-05 00:33:50 +000066 using BlockExitState = enum { PASS_THROUGH, EXITS_CLEAN, EXITS_DIRTY };
67
Lang Hames7c8189c2014-03-17 01:22:54 +000068 static const char* getBlockExitStateName(BlockExitState ST);
Eli Friedman8f249602011-11-04 23:46:11 +000069
Lang Hames7c8189c2014-03-17 01:22:54 +000070 // Core algorithm state:
71 // BlockState - Each block is either:
Amjad Aboud4f977512017-03-03 09:03:24 +000072 // - PASS_THROUGH: There are neither YMM/ZMM dirtying instructions nor
Lang Hames7c8189c2014-03-17 01:22:54 +000073 // vzeroupper instructions in this block.
74 // - EXITS_CLEAN: There is (or will be) a vzeroupper instruction in this
Amjad Aboud4f977512017-03-03 09:03:24 +000075 // block that will ensure that YMM/ZMM is clean on exit.
76 // - EXITS_DIRTY: An instruction in the block dirties YMM/ZMM and no
Lang Hames7c8189c2014-03-17 01:22:54 +000077 // subsequent vzeroupper in the block clears it.
Eli Friedman8f249602011-11-04 23:46:11 +000078 //
Lang Hames7c8189c2014-03-17 01:22:54 +000079 // AddedToDirtySuccessors - This flag is raised when a block is added to the
80 // DirtySuccessors list to ensure that it's not
81 // added multiple times.
Eli Friedman8f249602011-11-04 23:46:11 +000082 //
Lang Hames7c8189c2014-03-17 01:22:54 +000083 // FirstUnguardedCall - Records the location of the first unguarded call in
84 // each basic block that may need to be guarded by a
85 // vzeroupper. We won't know whether it actually needs
86 // to be guarded until we discover a predecessor that
87 // is DIRTY_OUT.
88 struct BlockState {
Eugene Zelenko60433b62017-10-05 00:33:50 +000089 BlockExitState ExitState = PASS_THROUGH;
90 bool AddedToDirtySuccessors = false;
Lang Hames7c8189c2014-03-17 01:22:54 +000091 MachineBasicBlock::iterator FirstUnguardedCall;
Eugene Zelenko60433b62017-10-05 00:33:50 +000092
93 BlockState() = default;
Eli Friedman8f249602011-11-04 23:46:11 +000094 };
Eugene Zelenko60433b62017-10-05 00:33:50 +000095
96 using BlockStateMap = SmallVector<BlockState, 8>;
97 using DirtySuccessorsWorkList = SmallVector<MachineBasicBlock *, 8>;
Eli Friedman8f249602011-11-04 23:46:11 +000098
Lang Hames7c8189c2014-03-17 01:22:54 +000099 BlockStateMap BlockStates;
100 DirtySuccessorsWorkList DirtySuccessors;
101 bool EverMadeChange;
Amjad Aboud719325fe12016-03-01 11:32:03 +0000102 bool IsX86INTR;
Lang Hames7c8189c2014-03-17 01:22:54 +0000103 const TargetInstrInfo *TII;
Eli Friedman8f249602011-11-04 23:46:11 +0000104
Lang Hames7c8189c2014-03-17 01:22:54 +0000105 static char ID;
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +0000106 };
Lang Hames7c8189c2014-03-17 01:22:54 +0000107
Eugene Zelenko60433b62017-10-05 00:33:50 +0000108} // end anonymous namespace
109
110char VZeroUpperInserter::ID = 0;
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +0000111
112FunctionPass *llvm::createX86IssueVZeroUpperPass() {
113 return new VZeroUpperInserter();
114}
115
Craig Topper3eb6ff92017-03-22 06:07:58 +0000116#ifndef NDEBUG
Lang Hames7c8189c2014-03-17 01:22:54 +0000117const char* VZeroUpperInserter::getBlockExitStateName(BlockExitState ST) {
118 switch (ST) {
119 case PASS_THROUGH: return "Pass-through";
120 case EXITS_DIRTY: return "Exits-dirty";
121 case EXITS_CLEAN: return "Exits-clean";
122 }
123 llvm_unreachable("Invalid block exit state.");
124}
Craig Topper3eb6ff92017-03-22 06:07:58 +0000125#endif
Lang Hames7c8189c2014-03-17 01:22:54 +0000126
Amjad Aboud4f977512017-03-03 09:03:24 +0000127/// VZEROUPPER cleans state that is related to Y/ZMM0-15 only.
128/// Thus, there is no need to check for Y/ZMM16 and above.
129static bool isYmmOrZmmReg(unsigned Reg) {
130 return (Reg >= X86::YMM0 && Reg <= X86::YMM15) ||
131 (Reg >= X86::ZMM0 && Reg <= X86::ZMM15);
Eli Friedman8f249602011-11-04 23:46:11 +0000132}
133
Amjad Aboud4f977512017-03-03 09:03:24 +0000134static bool checkFnHasLiveInYmmOrZmm(MachineRegisterInfo &MRI) {
Krzysztof Parzyszek72518ea2017-10-16 19:08:41 +0000135 for (std::pair<unsigned, unsigned> LI : MRI.liveins())
136 if (isYmmOrZmmReg(LI.first))
Eli Friedman8f249602011-11-04 23:46:11 +0000137 return true;
138
139 return false;
140}
141
Amjad Aboud4f977512017-03-03 09:03:24 +0000142static bool clobbersAllYmmAndZmmRegs(const MachineOperand &MO) {
Elena Demikhovsky52e4a0e2014-01-05 10:46:09 +0000143 for (unsigned reg = X86::YMM0; reg <= X86::YMM15; ++reg) {
Elena Demikhovsky9e0df7c2013-02-13 08:02:04 +0000144 if (!MO.clobbersPhysReg(reg))
145 return false;
146 }
Amjad Aboud4f977512017-03-03 09:03:24 +0000147 for (unsigned reg = X86::ZMM0; reg <= X86::ZMM15; ++reg) {
148 if (!MO.clobbersPhysReg(reg))
149 return false;
150 }
Elena Demikhovsky9e0df7c2013-02-13 08:02:04 +0000151 return true;
152}
153
Amjad Aboud4f977512017-03-03 09:03:24 +0000154static bool hasYmmOrZmmReg(MachineInstr &MI) {
Duncan P. N. Exon Smith7b4c18e2016-07-12 03:18:50 +0000155 for (const MachineOperand &MO : MI.operands()) {
Amjad Aboud4f977512017-03-03 09:03:24 +0000156 if (MI.isCall() && MO.isRegMask() && !clobbersAllYmmAndZmmRegs(MO))
Elena Demikhovsky9e0df7c2013-02-13 08:02:04 +0000157 return true;
Eli Friedman8f249602011-11-04 23:46:11 +0000158 if (!MO.isReg())
159 continue;
160 if (MO.isDebug())
161 continue;
Amjad Aboud4f977512017-03-03 09:03:24 +0000162 if (isYmmOrZmmReg(MO.getReg()))
Eli Friedman8f249602011-11-04 23:46:11 +0000163 return true;
164 }
165 return false;
166}
167
Amjad Aboud4f977512017-03-03 09:03:24 +0000168/// Check if given call instruction has a RegMask operand.
169static bool callHasRegMask(MachineInstr &MI) {
Duncan P. N. Exon Smith7b4c18e2016-07-12 03:18:50 +0000170 assert(MI.isCall() && "Can only be called on call instructions.");
171 for (const MachineOperand &MO : MI.operands()) {
Amjad Aboud4f977512017-03-03 09:03:24 +0000172 if (MO.isRegMask())
173 return true;
Michael Liao14b02842013-12-03 09:17:32 +0000174 }
175 return false;
176}
177
Sanjay Patel8bc63b22016-05-20 16:46:01 +0000178/// Insert a vzeroupper instruction before I.
Lang Hames7c8189c2014-03-17 01:22:54 +0000179void VZeroUpperInserter::insertVZeroUpper(MachineBasicBlock::iterator I,
Sanjay Patel8bc63b22016-05-20 16:46:01 +0000180 MachineBasicBlock &MBB) {
Lang Hames7c8189c2014-03-17 01:22:54 +0000181 DebugLoc dl = I->getDebugLoc();
182 BuildMI(MBB, I, dl, TII->get(X86::VZEROUPPER));
183 ++NumVZU;
184 EverMadeChange = true;
185}
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +0000186
Sanjay Patel8bc63b22016-05-20 16:46:01 +0000187/// Add MBB to the DirtySuccessors list if it hasn't already been added.
Lang Hames7c8189c2014-03-17 01:22:54 +0000188void VZeroUpperInserter::addDirtySuccessor(MachineBasicBlock &MBB) {
189 if (!BlockStates[MBB.getNumber()].AddedToDirtySuccessors) {
190 DirtySuccessors.push_back(&MBB);
191 BlockStates[MBB.getNumber()].AddedToDirtySuccessors = true;
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +0000192 }
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +0000193}
194
Sanjay Patel8bc63b22016-05-20 16:46:01 +0000195/// Loop over all of the instructions in the basic block, inserting vzeroupper
196/// instructions before function calls.
Lang Hames7c8189c2014-03-17 01:22:54 +0000197void VZeroUpperInserter::processBasicBlock(MachineBasicBlock &MBB) {
Sanjay Patel5496a232016-05-20 17:07:19 +0000198 // Start by assuming that the block is PASS_THROUGH which implies no unguarded
Lang Hames7c8189c2014-03-17 01:22:54 +0000199 // calls.
200 BlockExitState CurState = PASS_THROUGH;
201 BlockStates[MBB.getNumber()].FirstUnguardedCall = MBB.end();
Eli Friedman8f249602011-11-04 23:46:11 +0000202
Duncan P. N. Exon Smith7b4c18e2016-07-12 03:18:50 +0000203 for (MachineInstr &MI : MBB) {
Amjad Aboud4f977512017-03-03 09:03:24 +0000204 bool IsCall = MI.isCall();
205 bool IsReturn = MI.isReturn();
206 bool IsControlFlow = IsCall || IsReturn;
207
Amjad Aboud719325fe12016-03-01 11:32:03 +0000208 // No need for vzeroupper before iret in interrupt handler function,
Amjad Aboud4f977512017-03-03 09:03:24 +0000209 // epilogue will restore YMM/ZMM registers if needed.
210 if (IsX86INTR && IsReturn)
211 continue;
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +0000212
Sanjay Patel39553602016-05-25 16:39:47 +0000213 // An existing VZERO* instruction resets the state.
Duncan P. N. Exon Smith7b4c18e2016-07-12 03:18:50 +0000214 if (MI.getOpcode() == X86::VZEROALL || MI.getOpcode() == X86::VZEROUPPER) {
Sanjay Patel39553602016-05-25 16:39:47 +0000215 CurState = EXITS_CLEAN;
216 continue;
217 }
218
Chad Rosier24c19d22012-08-01 18:39:17 +0000219 // Shortcut: don't need to check regular instructions in dirty state.
Amjad Aboud4f977512017-03-03 09:03:24 +0000220 if (!IsControlFlow && CurState == EXITS_DIRTY)
Eli Friedman8f249602011-11-04 23:46:11 +0000221 continue;
222
Amjad Aboud4f977512017-03-03 09:03:24 +0000223 if (hasYmmOrZmmReg(MI)) {
224 // We found a ymm/zmm-using instruction; this could be an AVX/AVX512
225 // instruction, or it could be control flow.
Lang Hames7c8189c2014-03-17 01:22:54 +0000226 CurState = EXITS_DIRTY;
Eli Friedman8f249602011-11-04 23:46:11 +0000227 continue;
228 }
229
230 // Check for control-flow out of the current function (which might
231 // indirectly execute SSE instructions).
Amjad Aboud4f977512017-03-03 09:03:24 +0000232 if (!IsControlFlow)
Eli Friedman8f249602011-11-04 23:46:11 +0000233 continue;
234
Amjad Aboud4f977512017-03-03 09:03:24 +0000235 // If the call has no RegMask, skip it as well. It usually happens on
236 // helper function calls (such as '_chkstk', '_ftol2') where standard
237 // calling convention is not used (RegMask is not used to mark register
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +0000238 // clobbered and register usage (def/implicit-def/use) is well-defined and
Amjad Aboud4f977512017-03-03 09:03:24 +0000239 // explicitly specified.
240 if (IsCall && !callHasRegMask(MI))
Michael Liao14b02842013-12-03 09:17:32 +0000241 continue;
242
Amjad Aboud4f977512017-03-03 09:03:24 +0000243 // The VZEROUPPER instruction resets the upper 128 bits of YMM0-YMM15
Sanjay Patel5496a232016-05-20 17:07:19 +0000244 // registers. In addition, the processor changes back to Clean state, after
245 // which execution of SSE instructions or AVX instructions has no transition
246 // penalty. Add the VZEROUPPER instruction before any function call/return
247 // that might execute SSE code.
Eli Friedman8f249602011-11-04 23:46:11 +0000248 // FIXME: In some cases, we may want to move the VZEROUPPER into a
249 // predecessor block.
Lang Hames7c8189c2014-03-17 01:22:54 +0000250 if (CurState == EXITS_DIRTY) {
Eli Friedman8f249602011-11-04 23:46:11 +0000251 // After the inserted VZEROUPPER the state becomes clean again, but
Amjad Aboud4f977512017-03-03 09:03:24 +0000252 // other YMM/ZMM may appear before other subsequent calls or even before
Eli Friedman8f249602011-11-04 23:46:11 +0000253 // the end of the BB.
Duncan P. N. Exon Smith7b4c18e2016-07-12 03:18:50 +0000254 insertVZeroUpper(MI, MBB);
Lang Hames7c8189c2014-03-17 01:22:54 +0000255 CurState = EXITS_CLEAN;
256 } else if (CurState == PASS_THROUGH) {
257 // If this block is currently in pass-through state and we encounter a
258 // call then whether we need a vzeroupper or not depends on whether this
259 // block has successors that exit dirty. Record the location of the call,
260 // and set the state to EXITS_CLEAN, but do not insert the vzeroupper yet.
261 // It will be inserted later if necessary.
Duncan P. N. Exon Smith7b4c18e2016-07-12 03:18:50 +0000262 BlockStates[MBB.getNumber()].FirstUnguardedCall = MI;
Lang Hames7c8189c2014-03-17 01:22:54 +0000263 CurState = EXITS_CLEAN;
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +0000264 }
265 }
266
Lang Hames7c8189c2014-03-17 01:22:54 +0000267 DEBUG(dbgs() << "MBB #" << MBB.getNumber() << " exit state: "
268 << getBlockExitStateName(CurState) << '\n');
Eli Friedman8f249602011-11-04 23:46:11 +0000269
Lang Hames7c8189c2014-03-17 01:22:54 +0000270 if (CurState == EXITS_DIRTY)
271 for (MachineBasicBlock::succ_iterator SI = MBB.succ_begin(),
272 SE = MBB.succ_end();
273 SI != SE; ++SI)
274 addDirtySuccessor(**SI);
Eli Friedman8f249602011-11-04 23:46:11 +0000275
Lang Hames7c8189c2014-03-17 01:22:54 +0000276 BlockStates[MBB.getNumber()].ExitState = CurState;
277}
Eli Friedman8f249602011-11-04 23:46:11 +0000278
Sanjay Patel8bc63b22016-05-20 16:46:01 +0000279/// Loop over all of the basic blocks, inserting vzeroupper instructions before
280/// function calls.
Lang Hames7c8189c2014-03-17 01:22:54 +0000281bool VZeroUpperInserter::runOnMachineFunction(MachineFunction &MF) {
Eric Christopher05b81972015-02-02 17:38:43 +0000282 const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
Amjad Aboud4f977512017-03-03 09:03:24 +0000283 if (!ST.hasAVX() || ST.hasFastPartialYMMorZMMWrite())
Lang Hames7c8189c2014-03-17 01:22:54 +0000284 return false;
Eric Christopher05b81972015-02-02 17:38:43 +0000285 TII = ST.getInstrInfo();
Lang Hames7c8189c2014-03-17 01:22:54 +0000286 MachineRegisterInfo &MRI = MF.getRegInfo();
287 EverMadeChange = false;
Matthias Braunf1caa282017-12-15 22:22:58 +0000288 IsX86INTR = MF.getFunction().getCallingConv() == CallingConv::X86_INTR;
Lang Hames7c8189c2014-03-17 01:22:54 +0000289
Amjad Aboud4f977512017-03-03 09:03:24 +0000290 bool FnHasLiveInYmmOrZmm = checkFnHasLiveInYmmOrZmm(MRI);
Matthias Braunada0adf2015-01-08 00:33:48 +0000291
Amjad Aboud4f977512017-03-03 09:03:24 +0000292 // Fast check: if the function doesn't use any ymm/zmm registers, we don't
293 // need to insert any VZEROUPPER instructions. This is constant-time, so it
294 // is cheap in the common case of no ymm/zmm use.
295 bool YmmOrZmmUsed = FnHasLiveInYmmOrZmm;
296 const TargetRegisterClass *RCs[2] = {&X86::VR256RegClass, &X86::VR512RegClass};
297 for (auto *RC : RCs) {
298 if (!YmmOrZmmUsed) {
299 for (TargetRegisterClass::iterator i = RC->begin(), e = RC->end(); i != e;
300 i++) {
301 if (!MRI.reg_nodbg_empty(*i)) {
302 YmmOrZmmUsed = true;
303 break;
304 }
Matthias Braunada0adf2015-01-08 00:33:48 +0000305 }
Lang Hames7c8189c2014-03-17 01:22:54 +0000306 }
307 }
Amjad Aboud4f977512017-03-03 09:03:24 +0000308 if (!YmmOrZmmUsed) {
Lang Hames7c8189c2014-03-17 01:22:54 +0000309 return false;
310 }
311
312 assert(BlockStates.empty() && DirtySuccessors.empty() &&
313 "X86VZeroUpper state should be clear");
314 BlockStates.resize(MF.getNumBlockIDs());
315
316 // Process all blocks. This will compute block exit states, record the first
317 // unguarded call in each block, and add successors of dirty blocks to the
318 // DirtySuccessors list.
Sanjay Patelfbca70d2015-05-05 21:20:52 +0000319 for (MachineBasicBlock &MBB : MF)
320 processBasicBlock(MBB);
Lang Hames7c8189c2014-03-17 01:22:54 +0000321
Amjad Aboud4f977512017-03-03 09:03:24 +0000322 // If any YMM/ZMM regs are live-in to this function, add the entry block to
323 // the DirtySuccessors list
324 if (FnHasLiveInYmmOrZmm)
Lang Hames7c8189c2014-03-17 01:22:54 +0000325 addDirtySuccessor(MF.front());
326
Sanjay Patel8099fb7e2016-05-23 18:01:20 +0000327 // Re-visit all blocks that are successors of EXITS_DIRTY blocks. Add
Lang Hames7c8189c2014-03-17 01:22:54 +0000328 // vzeroupper instructions to unguarded calls, and propagate EXITS_DIRTY
329 // through PASS_THROUGH blocks.
330 while (!DirtySuccessors.empty()) {
331 MachineBasicBlock &MBB = *DirtySuccessors.back();
332 DirtySuccessors.pop_back();
333 BlockState &BBState = BlockStates[MBB.getNumber()];
334
335 // MBB is a successor of a dirty block, so its first call needs to be
336 // guarded.
337 if (BBState.FirstUnguardedCall != MBB.end())
338 insertVZeroUpper(BBState.FirstUnguardedCall, MBB);
339
Sanjay Patel5496a232016-05-20 17:07:19 +0000340 // If this successor was a pass-through block, then it is now dirty. Its
Lang Hames7c8189c2014-03-17 01:22:54 +0000341 // successors need to be added to the worklist (if they haven't been
342 // already).
343 if (BBState.ExitState == PASS_THROUGH) {
344 DEBUG(dbgs() << "MBB #" << MBB.getNumber()
345 << " was Pass-through, is now Dirty-out.\n");
Sanjay Patel13a0d492016-05-23 18:00:50 +0000346 for (MachineBasicBlock *Succ : MBB.successors())
347 addDirtySuccessor(*Succ);
Lang Hames7c8189c2014-03-17 01:22:54 +0000348 }
349 }
350
351 BlockStates.clear();
352 return EverMadeChange;
Bruno Cardoso Lopes2a3ffb52011-08-23 01:14:17 +0000353}