LLVM 19.0.0git
X86FlagsCopyLowering.cpp
Go to the documentation of this file.
1//====- X86FlagsCopyLowering.cpp - Lowers COPY nodes of EFLAGS ------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// Lowers COPY nodes of EFLAGS by directly extracting and preserving individual
11/// flag bits.
12///
13/// We have to do this by carefully analyzing and rewriting the usage of the
14/// copied EFLAGS register because there is no general way to rematerialize the
15/// entire EFLAGS register safely and efficiently. Using `popf` both forces
16/// dynamic stack adjustment and can create correctness issues due to IF, TF,
17/// and other non-status flags being overwritten. Using sequences involving
18/// SAHF don't work on all x86 processors and are often quite slow compared to
19/// directly testing a single status preserved in its own GPR.
20///
21//===----------------------------------------------------------------------===//
22
23#include "X86.h"
24#include "X86InstrBuilder.h"
25#include "X86InstrInfo.h"
26#include "X86Subtarget.h"
28#include "llvm/ADT/STLExtras.h"
29#include "llvm/ADT/ScopeExit.h"
32#include "llvm/ADT/Statistic.h"
48#include "llvm/IR/DebugLoc.h"
49#include "llvm/MC/MCSchedule.h"
50#include "llvm/Pass.h"
52#include "llvm/Support/Debug.h"
54#include <algorithm>
55#include <cassert>
56#include <iterator>
57#include <utility>
58
59using namespace llvm;
60
61#define PASS_KEY "x86-flags-copy-lowering"
62#define DEBUG_TYPE PASS_KEY
63
64STATISTIC(NumCopiesEliminated, "Number of copies of EFLAGS eliminated");
65STATISTIC(NumSetCCsInserted, "Number of setCC instructions inserted");
66STATISTIC(NumTestsInserted, "Number of test instructions inserted");
67STATISTIC(NumAddsInserted, "Number of adds instructions inserted");
68
69namespace {
70
71// Convenient array type for storing registers associated with each condition.
72using CondRegArray = std::array<unsigned, X86::LAST_VALID_COND + 1>;
73
74class X86FlagsCopyLoweringPass : public MachineFunctionPass {
75public:
76 X86FlagsCopyLoweringPass() : MachineFunctionPass(ID) { }
77
78 StringRef getPassName() const override { return "X86 EFLAGS copy lowering"; }
79 bool runOnMachineFunction(MachineFunction &MF) override;
80 void getAnalysisUsage(AnalysisUsage &AU) const override;
81
82 /// Pass identification, replacement for typeid.
83 static char ID;
84
85private:
86 MachineRegisterInfo *MRI = nullptr;
87 const X86Subtarget *Subtarget = nullptr;
88 const X86InstrInfo *TII = nullptr;
89 const TargetRegisterInfo *TRI = nullptr;
90 const TargetRegisterClass *PromoteRC = nullptr;
91 MachineDominatorTree *MDT = nullptr;
92
93 CondRegArray collectCondsInRegs(MachineBasicBlock &MBB,
95
96 Register promoteCondToReg(MachineBasicBlock &MBB,
98 const DebugLoc &TestLoc, X86::CondCode Cond);
99 std::pair<unsigned, bool> getCondOrInverseInReg(
101 const DebugLoc &TestLoc, X86::CondCode Cond, CondRegArray &CondRegs);
103 const DebugLoc &Loc, unsigned Reg);
104
105 void rewriteArithmetic(MachineBasicBlock &TestMBB,
107 const DebugLoc &TestLoc, MachineInstr &MI,
108 MachineOperand &FlagUse, CondRegArray &CondRegs);
109 void rewriteCMov(MachineBasicBlock &TestMBB,
110 MachineBasicBlock::iterator TestPos, const DebugLoc &TestLoc,
111 MachineInstr &CMovI, MachineOperand &FlagUse,
112 CondRegArray &CondRegs);
113 void rewriteFCMov(MachineBasicBlock &TestMBB,
115 const DebugLoc &TestLoc, MachineInstr &CMovI,
116 MachineOperand &FlagUse, CondRegArray &CondRegs);
117 void rewriteCondJmp(MachineBasicBlock &TestMBB,
119 const DebugLoc &TestLoc, MachineInstr &JmpI,
120 CondRegArray &CondRegs);
121 void rewriteCopy(MachineInstr &MI, MachineOperand &FlagUse,
122 MachineInstr &CopyDefI);
123 void rewriteSetCC(MachineBasicBlock &TestMBB,
125 const DebugLoc &TestLoc, MachineInstr &SetCCI,
126 MachineOperand &FlagUse, CondRegArray &CondRegs);
127};
128
129} // end anonymous namespace
130
131INITIALIZE_PASS_BEGIN(X86FlagsCopyLoweringPass, DEBUG_TYPE,
132 "X86 EFLAGS copy lowering", false, false)
133INITIALIZE_PASS_END(X86FlagsCopyLoweringPass, DEBUG_TYPE,
134 "X86 EFLAGS copy lowering", false, false)
135
137 return new X86FlagsCopyLoweringPass();
138}
139
140char X86FlagsCopyLoweringPass::ID = 0;
141
142void X86FlagsCopyLoweringPass::getAnalysisUsage(AnalysisUsage &AU) const {
145}
146
147namespace {
148/// An enumeration of the arithmetic instruction mnemonics which have
149/// interesting flag semantics.
150///
151/// We can map instruction opcodes into these mnemonics to make it easy to
152/// dispatch with specific functionality.
153enum class FlagArithMnemonic {
154 ADC,
155 RCL,
156 RCR,
157 SBB,
158 SETB,
159};
160} // namespace
161
162static FlagArithMnemonic getMnemonicFromOpcode(unsigned Opcode) {
163 switch (Opcode) {
164 default:
165 report_fatal_error("No support for lowering a copy into EFLAGS when used "
166 "by this instruction!");
167
168#define CASE_ND(OP) \
169 case X86::OP: \
170 case X86::OP##_ND:
171
172#define LLVM_EXPAND_INSTR_SIZES(MNEMONIC, SUFFIX) \
173 CASE_ND(MNEMONIC##8##SUFFIX) \
174 CASE_ND(MNEMONIC##16##SUFFIX) \
175 CASE_ND(MNEMONIC##32##SUFFIX) \
176 CASE_ND(MNEMONIC##64##SUFFIX)
177
178#define LLVM_EXPAND_ADC_SBB_INSTR(MNEMONIC) \
179 LLVM_EXPAND_INSTR_SIZES(MNEMONIC, rr) \
180 LLVM_EXPAND_INSTR_SIZES(MNEMONIC, rm) \
181 LLVM_EXPAND_INSTR_SIZES(MNEMONIC, mr) \
182 CASE_ND(MNEMONIC##8ri) \
183 CASE_ND(MNEMONIC##16ri8) \
184 CASE_ND(MNEMONIC##32ri8) \
185 CASE_ND(MNEMONIC##64ri8) \
186 CASE_ND(MNEMONIC##16ri) \
187 CASE_ND(MNEMONIC##32ri) \
188 CASE_ND(MNEMONIC##64ri32) \
189 CASE_ND(MNEMONIC##8mi) \
190 CASE_ND(MNEMONIC##16mi8) \
191 CASE_ND(MNEMONIC##32mi8) \
192 CASE_ND(MNEMONIC##64mi8) \
193 CASE_ND(MNEMONIC##16mi) \
194 CASE_ND(MNEMONIC##32mi) \
195 CASE_ND(MNEMONIC##64mi32) \
196 case X86::MNEMONIC##8i8: \
197 case X86::MNEMONIC##16i16: \
198 case X86::MNEMONIC##32i32: \
199 case X86::MNEMONIC##64i32:
200
202 return FlagArithMnemonic::ADC;
203
205 return FlagArithMnemonic::SBB;
206
207#undef LLVM_EXPAND_ADC_SBB_INSTR
208
212 return FlagArithMnemonic::RCL;
213
217 return FlagArithMnemonic::RCR;
218
219#undef LLVM_EXPAND_INSTR_SIZES
220#undef CASE_ND
221
222 case X86::SETB_C32r:
223 case X86::SETB_C64r:
224 return FlagArithMnemonic::SETB;
225 }
226}
227
229 MachineInstr &SplitI,
230 const X86InstrInfo &TII) {
232
233 assert(SplitI.getParent() == &MBB &&
234 "Split instruction must be in the split block!");
235 assert(SplitI.isBranch() &&
236 "Only designed to split a tail of branch instructions!");
238 "Must split on an actual jCC instruction!");
239
240 // Dig out the previous instruction to the split point.
241 MachineInstr &PrevI = *std::prev(SplitI.getIterator());
242 assert(PrevI.isBranch() && "Must split after a branch!");
244 "Must split after an actual jCC instruction!");
245 assert(!std::prev(PrevI.getIterator())->isTerminator() &&
246 "Must only have this one terminator prior to the split!");
247
248 // Grab the one successor edge that will stay in `MBB`.
249 MachineBasicBlock &UnsplitSucc = *PrevI.getOperand(0).getMBB();
250
251 // Analyze the original block to see if we are actually splitting an edge
252 // into two edges. This can happen when we have multiple conditional jumps to
253 // the same successor.
254 bool IsEdgeSplit =
255 std::any_of(SplitI.getIterator(), MBB.instr_end(),
256 [&](MachineInstr &MI) {
257 assert(MI.isTerminator() &&
258 "Should only have spliced terminators!");
259 return llvm::any_of(
260 MI.operands(), [&](MachineOperand &MOp) {
261 return MOp.isMBB() && MOp.getMBB() == &UnsplitSucc;
262 });
263 }) ||
264 MBB.getFallThrough() == &UnsplitSucc;
265
266 MachineBasicBlock &NewMBB = *MF.CreateMachineBasicBlock();
267
268 // Insert the new block immediately after the current one. Any existing
269 // fallthrough will be sunk into this new block anyways.
270 MF.insert(std::next(MachineFunction::iterator(&MBB)), &NewMBB);
271
272 // Splice the tail of instructions into the new block.
273 NewMBB.splice(NewMBB.end(), &MBB, SplitI.getIterator(), MBB.end());
274
275 // Copy the necessary succesors (and their probability info) into the new
276 // block.
277 for (auto SI = MBB.succ_begin(), SE = MBB.succ_end(); SI != SE; ++SI)
278 if (IsEdgeSplit || *SI != &UnsplitSucc)
279 NewMBB.copySuccessor(&MBB, SI);
280 // Normalize the probabilities if we didn't end up splitting the edge.
281 if (!IsEdgeSplit)
282 NewMBB.normalizeSuccProbs();
283
284 // Now replace all of the moved successors in the original block with the new
285 // block. This will merge their probabilities.
286 for (MachineBasicBlock *Succ : NewMBB.successors())
287 if (Succ != &UnsplitSucc)
288 MBB.replaceSuccessor(Succ, &NewMBB);
289
290 // We should always end up replacing at least one successor.
291 assert(MBB.isSuccessor(&NewMBB) &&
292 "Failed to make the new block a successor!");
293
294 // Now update all the PHIs.
295 for (MachineBasicBlock *Succ : NewMBB.successors()) {
296 for (MachineInstr &MI : *Succ) {
297 if (!MI.isPHI())
298 break;
299
300 for (int OpIdx = 1, NumOps = MI.getNumOperands(); OpIdx < NumOps;
301 OpIdx += 2) {
302 MachineOperand &OpV = MI.getOperand(OpIdx);
303 MachineOperand &OpMBB = MI.getOperand(OpIdx + 1);
304 assert(OpMBB.isMBB() && "Block operand to a PHI is not a block!");
305 if (OpMBB.getMBB() != &MBB)
306 continue;
307
308 // Replace the operand for unsplit successors
309 if (!IsEdgeSplit || Succ != &UnsplitSucc) {
310 OpMBB.setMBB(&NewMBB);
311
312 // We have to continue scanning as there may be multiple entries in
313 // the PHI.
314 continue;
315 }
316
317 // When we have split the edge append a new successor.
318 MI.addOperand(MF, OpV);
319 MI.addOperand(MF, MachineOperand::CreateMBB(&NewMBB));
320 break;
321 }
322 }
323 }
324
325 return NewMBB;
326}
327
328static X86::CondCode getCondFromFCMOV(unsigned Opcode) {
329 switch (Opcode) {
330 default: return X86::COND_INVALID;
331 case X86::CMOVBE_Fp32: case X86::CMOVBE_Fp64: case X86::CMOVBE_Fp80:
332 return X86::COND_BE;
333 case X86::CMOVB_Fp32: case X86::CMOVB_Fp64: case X86::CMOVB_Fp80:
334 return X86::COND_B;
335 case X86::CMOVE_Fp32: case X86::CMOVE_Fp64: case X86::CMOVE_Fp80:
336 return X86::COND_E;
337 case X86::CMOVNBE_Fp32: case X86::CMOVNBE_Fp64: case X86::CMOVNBE_Fp80:
338 return X86::COND_A;
339 case X86::CMOVNB_Fp32: case X86::CMOVNB_Fp64: case X86::CMOVNB_Fp80:
340 return X86::COND_AE;
341 case X86::CMOVNE_Fp32: case X86::CMOVNE_Fp64: case X86::CMOVNE_Fp80:
342 return X86::COND_NE;
343 case X86::CMOVNP_Fp32: case X86::CMOVNP_Fp64: case X86::CMOVNP_Fp80:
344 return X86::COND_NP;
345 case X86::CMOVP_Fp32: case X86::CMOVP_Fp64: case X86::CMOVP_Fp80:
346 return X86::COND_P;
347 }
348}
349
350bool X86FlagsCopyLoweringPass::runOnMachineFunction(MachineFunction &MF) {
351 LLVM_DEBUG(dbgs() << "********** " << getPassName() << " : " << MF.getName()
352 << " **********\n");
353
354 Subtarget = &MF.getSubtarget<X86Subtarget>();
355 MRI = &MF.getRegInfo();
356 TII = Subtarget->getInstrInfo();
357 TRI = Subtarget->getRegisterInfo();
358 MDT = &getAnalysis<MachineDominatorTree>();
359 PromoteRC = &X86::GR8RegClass;
360
361 if (MF.begin() == MF.end())
362 // Nothing to do for a degenerate empty function...
363 return false;
364
365 // Collect the copies in RPO so that when there are chains where a copy is in
366 // turn copied again we visit the first one first. This ensures we can find
367 // viable locations for testing the original EFLAGS that dominate all the
368 // uses across complex CFGs.
371 for (MachineBasicBlock *MBB : RPOT)
372 for (MachineInstr &MI : *MBB)
373 if (MI.getOpcode() == TargetOpcode::COPY &&
374 MI.getOperand(0).getReg() == X86::EFLAGS)
375 Copies.push_back(&MI);
376
377 for (MachineInstr *CopyI : Copies) {
378 MachineBasicBlock &MBB = *CopyI->getParent();
379
380 MachineOperand &VOp = CopyI->getOperand(1);
381 assert(VOp.isReg() &&
382 "The input to the copy for EFLAGS should always be a register!");
383 MachineInstr &CopyDefI = *MRI->getVRegDef(VOp.getReg());
384 if (CopyDefI.getOpcode() != TargetOpcode::COPY) {
385 // FIXME: The big likely candidate here are PHI nodes. We could in theory
386 // handle PHI nodes, but it gets really, really hard. Insanely hard. Hard
387 // enough that it is probably better to change every other part of LLVM
388 // to avoid creating them. The issue is that once we have PHIs we won't
389 // know which original EFLAGS value we need to capture with our setCCs
390 // below. The end result will be computing a complete set of setCCs that
391 // we *might* want, computing them in every place where we copy *out* of
392 // EFLAGS and then doing SSA formation on all of them to insert necessary
393 // PHI nodes and consume those here. Then hoping that somehow we DCE the
394 // unnecessary ones. This DCE seems very unlikely to be successful and so
395 // we will almost certainly end up with a glut of dead setCC
396 // instructions. Until we have a motivating test case and fail to avoid
397 // it by changing other parts of LLVM's lowering, we refuse to handle
398 // this complex case here.
400 dbgs() << "ERROR: Encountered unexpected def of an eflags copy: ";
401 CopyDefI.dump());
403 "Cannot lower EFLAGS copy unless it is defined in turn by a copy!");
404 }
405
406 auto Cleanup = make_scope_exit([&] {
407 // All uses of the EFLAGS copy are now rewritten, kill the copy into
408 // eflags and if dead the copy from.
409 CopyI->eraseFromParent();
410 if (MRI->use_empty(CopyDefI.getOperand(0).getReg()))
411 CopyDefI.eraseFromParent();
412 ++NumCopiesEliminated;
413 });
414
415 MachineOperand &DOp = CopyI->getOperand(0);
416 assert(DOp.isDef() && "Expected register def!");
417 assert(DOp.getReg() == X86::EFLAGS && "Unexpected copy def register!");
418 if (DOp.isDead())
419 continue;
420
421 MachineBasicBlock *TestMBB = CopyDefI.getParent();
422 auto TestPos = CopyDefI.getIterator();
423 DebugLoc TestLoc = CopyDefI.getDebugLoc();
424
425 LLVM_DEBUG(dbgs() << "Rewriting copy: "; CopyI->dump());
426
427 // Walk up across live-in EFLAGS to find where they were actually def'ed.
428 //
429 // This copy's def may just be part of a region of blocks covered by
430 // a single def of EFLAGS and we want to find the top of that region where
431 // possible.
432 //
433 // This is essentially a search for a *candidate* reaching definition
434 // location. We don't need to ever find the actual reaching definition here,
435 // but we want to walk up the dominator tree to find the highest point which
436 // would be viable for such a definition.
437 auto HasEFLAGSClobber = [&](MachineBasicBlock::iterator Begin,
439 // Scan backwards as we expect these to be relatively short and often find
440 // a clobber near the end.
441 return llvm::any_of(
443 // Flag any instruction (other than the copy we are
444 // currently rewriting) that defs EFLAGS.
445 return &MI != CopyI && MI.findRegisterDefOperand(X86::EFLAGS);
446 });
447 };
448 auto HasEFLAGSClobberPath = [&](MachineBasicBlock *BeginMBB,
449 MachineBasicBlock *EndMBB) {
450 assert(MDT->dominates(BeginMBB, EndMBB) &&
451 "Only support paths down the dominator tree!");
454 // We terminate at the beginning. No need to scan it.
455 Visited.insert(BeginMBB);
456 Worklist.push_back(EndMBB);
457 do {
458 auto *MBB = Worklist.pop_back_val();
459 for (auto *PredMBB : MBB->predecessors()) {
460 if (!Visited.insert(PredMBB).second)
461 continue;
462 if (HasEFLAGSClobber(PredMBB->begin(), PredMBB->end()))
463 return true;
464 // Enqueue this block to walk its predecessors.
465 Worklist.push_back(PredMBB);
466 }
467 } while (!Worklist.empty());
468 // No clobber found along a path from the begin to end.
469 return false;
470 };
471 while (TestMBB->isLiveIn(X86::EFLAGS) && !TestMBB->pred_empty() &&
472 !HasEFLAGSClobber(TestMBB->begin(), TestPos)) {
473 // Find the nearest common dominator of the predecessors, as
474 // that will be the best candidate to hoist into.
475 MachineBasicBlock *HoistMBB =
476 std::accumulate(std::next(TestMBB->pred_begin()), TestMBB->pred_end(),
477 *TestMBB->pred_begin(),
478 [&](MachineBasicBlock *LHS, MachineBasicBlock *RHS) {
479 return MDT->findNearestCommonDominator(LHS, RHS);
480 });
481
482 // Now we need to scan all predecessors that may be reached along paths to
483 // the hoist block. A clobber anywhere in any of these blocks the hoist.
484 // Note that this even handles loops because we require *no* clobbers.
485 if (HasEFLAGSClobberPath(HoistMBB, TestMBB))
486 break;
487
488 // We also need the terminators to not sneakily clobber flags.
489 if (HasEFLAGSClobber(HoistMBB->getFirstTerminator()->getIterator(),
490 HoistMBB->instr_end()))
491 break;
492
493 // We found a viable location, hoist our test position to it.
494 TestMBB = HoistMBB;
495 TestPos = TestMBB->getFirstTerminator()->getIterator();
496 // Clear the debug location as it would just be confusing after hoisting.
497 TestLoc = DebugLoc();
498 }
499 LLVM_DEBUG({
500 auto DefIt = llvm::find_if(
501 llvm::reverse(llvm::make_range(TestMBB->instr_begin(), TestPos)),
502 [&](MachineInstr &MI) {
503 return MI.findRegisterDefOperand(X86::EFLAGS);
504 });
505 if (DefIt.base() != TestMBB->instr_begin()) {
506 dbgs() << " Using EFLAGS defined by: ";
507 DefIt->dump();
508 } else {
509 dbgs() << " Using live-in flags for BB:\n";
510 TestMBB->dump();
511 }
512 });
513
514 // While rewriting uses, we buffer jumps and rewrite them in a second pass
515 // because doing so will perturb the CFG that we are walking to find the
516 // uses in the first place.
518
519 // Gather the condition flags that have already been preserved in
520 // registers. We do this from scratch each time as we expect there to be
521 // very few of them and we expect to not revisit the same copy definition
522 // many times. If either of those change sufficiently we could build a map
523 // of these up front instead.
524 CondRegArray CondRegs = collectCondsInRegs(*TestMBB, TestPos);
525
526 // Collect the basic blocks we need to scan. Typically this will just be
527 // a single basic block but we may have to scan multiple blocks if the
528 // EFLAGS copy lives into successors.
531 Blocks.push_back(&MBB);
532
533 do {
534 MachineBasicBlock &UseMBB = *Blocks.pop_back_val();
535
536 // Track when if/when we find a kill of the flags in this block.
537 bool FlagsKilled = false;
538
539 // In most cases, we walk from the beginning to the end of the block. But
540 // when the block is the same block as the copy is from, we will visit it
541 // twice. The first time we start from the copy and go to the end. The
542 // second time we start from the beginning and go to the copy. This lets
543 // us handle copies inside of cycles.
544 // FIXME: This loop is *super* confusing. This is at least in part
545 // a symptom of all of this routine needing to be refactored into
546 // documentable components. Once done, there may be a better way to write
547 // this loop.
548 for (auto MII = (&UseMBB == &MBB && !VisitedBlocks.count(&UseMBB))
549 ? std::next(CopyI->getIterator())
550 : UseMBB.instr_begin(),
551 MIE = UseMBB.instr_end();
552 MII != MIE;) {
553 MachineInstr &MI = *MII++;
554 // If we are in the original copy block and encounter either the copy
555 // def or the copy itself, break so that we don't re-process any part of
556 // the block or process the instructions in the range that was copied
557 // over.
558 if (&MI == CopyI || &MI == &CopyDefI) {
559 assert(&UseMBB == &MBB && VisitedBlocks.count(&MBB) &&
560 "Should only encounter these on the second pass over the "
561 "original block.");
562 break;
563 }
564
565 MachineOperand *FlagUse = MI.findRegisterUseOperand(X86::EFLAGS);
566 if (!FlagUse) {
567 if (MI.findRegisterDefOperand(X86::EFLAGS)) {
568 // If EFLAGS are defined, it's as-if they were killed. We can stop
569 // scanning here.
570 //
571 // NB!!! Many instructions only modify some flags. LLVM currently
572 // models this as clobbering all flags, but if that ever changes
573 // this will need to be carefully updated to handle that more
574 // complex logic.
575 FlagsKilled = true;
576 break;
577 }
578 continue;
579 }
580
581 LLVM_DEBUG(dbgs() << " Rewriting use: "; MI.dump());
582
583 // Check the kill flag before we rewrite as that may change it.
584 if (FlagUse->isKill())
585 FlagsKilled = true;
586
587 // Once we encounter a branch, the rest of the instructions must also be
588 // branches. We can't rewrite in place here, so we handle them below.
589 //
590 // Note that we don't have to handle tail calls here, even conditional
591 // tail calls, as those are not introduced into the X86 MI until post-RA
592 // branch folding or black placement. As a consequence, we get to deal
593 // with the simpler formulation of conditional branches followed by tail
594 // calls.
596 auto JmpIt = MI.getIterator();
597 do {
598 JmpIs.push_back(&*JmpIt);
599 ++JmpIt;
600 } while (JmpIt != UseMBB.instr_end() &&
601 X86::getCondFromBranch(*JmpIt) !=
603 break;
604 }
605
606 // Otherwise we can just rewrite in-place.
609 rewriteCMov(*TestMBB, TestPos, TestLoc, MI, *FlagUse, CondRegs);
610 } else if (getCondFromFCMOV(MI.getOpcode()) != X86::COND_INVALID) {
611 rewriteFCMov(*TestMBB, TestPos, TestLoc, MI, *FlagUse, CondRegs);
613 rewriteSetCC(*TestMBB, TestPos, TestLoc, MI, *FlagUse, CondRegs);
614 } else if (MI.getOpcode() == TargetOpcode::COPY) {
615 rewriteCopy(MI, *FlagUse, CopyDefI);
616 } else {
617 // We assume all other instructions that use flags also def them.
618 assert(MI.findRegisterDefOperand(X86::EFLAGS) &&
619 "Expected a def of EFLAGS for this instruction!");
620
621 // NB!!! Several arithmetic instructions only *partially* update
622 // flags. Theoretically, we could generate MI code sequences that
623 // would rely on this fact and observe different flags independently.
624 // But currently LLVM models all of these instructions as clobbering
625 // all the flags in an undef way. We rely on that to simplify the
626 // logic.
627 FlagsKilled = true;
628
629 // Generically handle remaining uses as arithmetic instructions.
630 rewriteArithmetic(*TestMBB, TestPos, TestLoc, MI, *FlagUse,
631 CondRegs);
632 }
633
634 // If this was the last use of the flags, we're done.
635 if (FlagsKilled)
636 break;
637 }
638
639 // If the flags were killed, we're done with this block.
640 if (FlagsKilled)
641 continue;
642
643 // Otherwise we need to scan successors for ones where the flags live-in
644 // and queue those up for processing.
645 for (MachineBasicBlock *SuccMBB : UseMBB.successors())
646 if (SuccMBB->isLiveIn(X86::EFLAGS) &&
647 VisitedBlocks.insert(SuccMBB).second) {
648 // We currently don't do any PHI insertion and so we require that the
649 // test basic block dominates all of the use basic blocks. Further, we
650 // can't have a cycle from the test block back to itself as that would
651 // create a cycle requiring a PHI to break it.
652 //
653 // We could in theory do PHI insertion here if it becomes useful by
654 // just taking undef values in along every edge that we don't trace
655 // this EFLAGS copy along. This isn't as bad as fully general PHI
656 // insertion, but still seems like a great deal of complexity.
657 //
658 // Because it is theoretically possible that some earlier MI pass or
659 // other lowering transformation could induce this to happen, we do
660 // a hard check even in non-debug builds here.
661 if (SuccMBB == TestMBB || !MDT->dominates(TestMBB, SuccMBB)) {
662 LLVM_DEBUG({
663 dbgs()
664 << "ERROR: Encountered use that is not dominated by our test "
665 "basic block! Rewriting this would require inserting PHI "
666 "nodes to track the flag state across the CFG.\n\nTest "
667 "block:\n";
668 TestMBB->dump();
669 dbgs() << "Use block:\n";
670 SuccMBB->dump();
671 });
673 "Cannot lower EFLAGS copy when original copy def "
674 "does not dominate all uses.");
675 }
676
677 Blocks.push_back(SuccMBB);
678
679 // After this, EFLAGS will be recreated before each use.
680 SuccMBB->removeLiveIn(X86::EFLAGS);
681 }
682 } while (!Blocks.empty());
683
684 // Now rewrite the jumps that use the flags. These we handle specially
685 // because if there are multiple jumps in a single basic block we'll have
686 // to do surgery on the CFG.
687 MachineBasicBlock *LastJmpMBB = nullptr;
688 for (MachineInstr *JmpI : JmpIs) {
689 // Past the first jump within a basic block we need to split the blocks
690 // apart.
691 if (JmpI->getParent() == LastJmpMBB)
692 splitBlock(*JmpI->getParent(), *JmpI, *TII);
693 else
694 LastJmpMBB = JmpI->getParent();
695
696 rewriteCondJmp(*TestMBB, TestPos, TestLoc, *JmpI, CondRegs);
697 }
698
699 // FIXME: Mark the last use of EFLAGS before the copy's def as a kill if
700 // the copy's def operand is itself a kill.
701 }
702
703#ifndef NDEBUG
704 for (MachineBasicBlock &MBB : MF)
705 for (MachineInstr &MI : MBB)
706 if (MI.getOpcode() == TargetOpcode::COPY &&
707 (MI.getOperand(0).getReg() == X86::EFLAGS ||
708 MI.getOperand(1).getReg() == X86::EFLAGS)) {
709 LLVM_DEBUG(dbgs() << "ERROR: Found a COPY involving EFLAGS: ";
710 MI.dump());
711 llvm_unreachable("Unlowered EFLAGS copy!");
712 }
713#endif
714
715 return true;
716}
717
718/// Collect any conditions that have already been set in registers so that we
719/// can re-use them rather than adding duplicates.
720CondRegArray X86FlagsCopyLoweringPass::collectCondsInRegs(
722 CondRegArray CondRegs = {};
723
724 // Scan backwards across the range of instructions with live EFLAGS.
725 for (MachineInstr &MI :
728 if (Cond != X86::COND_INVALID && !MI.mayStore() &&
729 MI.getOperand(0).isReg() && MI.getOperand(0).getReg().isVirtual()) {
730 assert(MI.getOperand(0).isDef() &&
731 "A non-storing SETcc should always define a register!");
732 CondRegs[Cond] = MI.getOperand(0).getReg();
733 }
734
735 // Stop scanning when we see the first definition of the EFLAGS as prior to
736 // this we would potentially capture the wrong flag state.
737 if (MI.findRegisterDefOperand(X86::EFLAGS))
738 break;
739 }
740 return CondRegs;
741}
742
743Register X86FlagsCopyLoweringPass::promoteCondToReg(
745 const DebugLoc &TestLoc, X86::CondCode Cond) {
746 Register Reg = MRI->createVirtualRegister(PromoteRC);
747 auto SetI = BuildMI(TestMBB, TestPos, TestLoc,
748 TII->get(X86::SETCCr), Reg).addImm(Cond);
749 (void)SetI;
750 LLVM_DEBUG(dbgs() << " save cond: "; SetI->dump());
751 ++NumSetCCsInserted;
752 return Reg;
753}
754
755std::pair<unsigned, bool> X86FlagsCopyLoweringPass::getCondOrInverseInReg(
757 const DebugLoc &TestLoc, X86::CondCode Cond, CondRegArray &CondRegs) {
758 unsigned &CondReg = CondRegs[Cond];
759 unsigned &InvCondReg = CondRegs[X86::GetOppositeBranchCondition(Cond)];
760 if (!CondReg && !InvCondReg)
761 CondReg = promoteCondToReg(TestMBB, TestPos, TestLoc, Cond);
762
763 if (CondReg)
764 return {CondReg, false};
765 else
766 return {InvCondReg, true};
767}
768
769void X86FlagsCopyLoweringPass::insertTest(MachineBasicBlock &MBB,
771 const DebugLoc &Loc, unsigned Reg) {
772 auto TestI =
773 BuildMI(MBB, Pos, Loc, TII->get(X86::TEST8rr)).addReg(Reg).addReg(Reg);
774 (void)TestI;
775 LLVM_DEBUG(dbgs() << " test cond: "; TestI->dump());
776 ++NumTestsInserted;
777}
778
779void X86FlagsCopyLoweringPass::rewriteArithmetic(
781 const DebugLoc &TestLoc, MachineInstr &MI, MachineOperand &FlagUse,
782 CondRegArray &CondRegs) {
783 // Arithmetic is either reading CF or OF. Figure out which condition we need
784 // to preserve in a register.
786
787 // The addend to use to reset CF or OF when added to the flag value.
788 int Addend = 0;
789
790 switch (getMnemonicFromOpcode(MI.getOpcode())) {
791 case FlagArithMnemonic::ADC:
792 case FlagArithMnemonic::RCL:
793 case FlagArithMnemonic::RCR:
794 case FlagArithMnemonic::SBB:
795 case FlagArithMnemonic::SETB:
796 Cond = X86::COND_B; // CF == 1
797 // Set up an addend that when one is added will need a carry due to not
798 // having a higher bit available.
799 Addend = 255;
800 break;
801 }
802
803 // Now get a register that contains the value of the flag input to the
804 // arithmetic. We require exactly this flag to simplify the arithmetic
805 // required to materialize it back into the flag.
806 unsigned &CondReg = CondRegs[Cond];
807 if (!CondReg)
808 CondReg = promoteCondToReg(TestMBB, TestPos, TestLoc, Cond);
809
810 MachineBasicBlock &MBB = *MI.getParent();
811
812 // Insert an instruction that will set the flag back to the desired value.
813 Register TmpReg = MRI->createVirtualRegister(PromoteRC);
814 auto AddI =
815 BuildMI(MBB, MI.getIterator(), MI.getDebugLoc(),
816 TII->get(Subtarget->hasNDD() ? X86::ADD8ri_ND : X86::ADD8ri))
817 .addDef(TmpReg, RegState::Dead)
818 .addReg(CondReg)
819 .addImm(Addend);
820 (void)AddI;
821 LLVM_DEBUG(dbgs() << " add cond: "; AddI->dump());
822 ++NumAddsInserted;
823 FlagUse.setIsKill(true);
824}
825
826void X86FlagsCopyLoweringPass::rewriteCMov(MachineBasicBlock &TestMBB,
828 const DebugLoc &TestLoc,
829 MachineInstr &CMovI,
830 MachineOperand &FlagUse,
831 CondRegArray &CondRegs) {
832 // First get the register containing this specific condition.
835 : X86::getCondFromCMov(CMovI);
836 unsigned CondReg;
837 bool Inverted;
838 std::tie(CondReg, Inverted) =
839 getCondOrInverseInReg(TestMBB, TestPos, TestLoc, Cond, CondRegs);
840
841 MachineBasicBlock &MBB = *CMovI.getParent();
842
843 // Insert a direct test of the saved register.
844 insertTest(MBB, CMovI.getIterator(), CMovI.getDebugLoc(), CondReg);
845
846 // Rewrite the CMov to use the !ZF flag from the test, and then kill its use
847 // of the flags afterward.
848 CMovI.getOperand(CMovI.getDesc().getNumOperands() - 1)
849 .setImm(Inverted ? X86::COND_E : X86::COND_NE);
850 FlagUse.setIsKill(true);
851 LLVM_DEBUG(dbgs() << " fixed cmov: "; CMovI.dump());
852}
853
854void X86FlagsCopyLoweringPass::rewriteFCMov(MachineBasicBlock &TestMBB,
856 const DebugLoc &TestLoc,
857 MachineInstr &CMovI,
858 MachineOperand &FlagUse,
859 CondRegArray &CondRegs) {
860 // First get the register containing this specific condition.
862 unsigned CondReg;
863 bool Inverted;
864 std::tie(CondReg, Inverted) =
865 getCondOrInverseInReg(TestMBB, TestPos, TestLoc, Cond, CondRegs);
866
867 MachineBasicBlock &MBB = *CMovI.getParent();
868
869 // Insert a direct test of the saved register.
870 insertTest(MBB, CMovI.getIterator(), CMovI.getDebugLoc(), CondReg);
871
872 auto getFCMOVOpcode = [](unsigned Opcode, bool Inverted) {
873 switch (Opcode) {
874 default: llvm_unreachable("Unexpected opcode!");
875 case X86::CMOVBE_Fp32: case X86::CMOVNBE_Fp32:
876 case X86::CMOVB_Fp32: case X86::CMOVNB_Fp32:
877 case X86::CMOVE_Fp32: case X86::CMOVNE_Fp32:
878 case X86::CMOVP_Fp32: case X86::CMOVNP_Fp32:
879 return Inverted ? X86::CMOVE_Fp32 : X86::CMOVNE_Fp32;
880 case X86::CMOVBE_Fp64: case X86::CMOVNBE_Fp64:
881 case X86::CMOVB_Fp64: case X86::CMOVNB_Fp64:
882 case X86::CMOVE_Fp64: case X86::CMOVNE_Fp64:
883 case X86::CMOVP_Fp64: case X86::CMOVNP_Fp64:
884 return Inverted ? X86::CMOVE_Fp64 : X86::CMOVNE_Fp64;
885 case X86::CMOVBE_Fp80: case X86::CMOVNBE_Fp80:
886 case X86::CMOVB_Fp80: case X86::CMOVNB_Fp80:
887 case X86::CMOVE_Fp80: case X86::CMOVNE_Fp80:
888 case X86::CMOVP_Fp80: case X86::CMOVNP_Fp80:
889 return Inverted ? X86::CMOVE_Fp80 : X86::CMOVNE_Fp80;
890 }
891 };
892
893 // Rewrite the CMov to use the !ZF flag from the test.
894 CMovI.setDesc(TII->get(getFCMOVOpcode(CMovI.getOpcode(), Inverted)));
895 FlagUse.setIsKill(true);
896 LLVM_DEBUG(dbgs() << " fixed fcmov: "; CMovI.dump());
897}
898
899void X86FlagsCopyLoweringPass::rewriteCondJmp(
901 const DebugLoc &TestLoc, MachineInstr &JmpI, CondRegArray &CondRegs) {
902 // First get the register containing this specific condition.
904 unsigned CondReg;
905 bool Inverted;
906 std::tie(CondReg, Inverted) =
907 getCondOrInverseInReg(TestMBB, TestPos, TestLoc, Cond, CondRegs);
908
909 MachineBasicBlock &JmpMBB = *JmpI.getParent();
910
911 // Insert a direct test of the saved register.
912 insertTest(JmpMBB, JmpI.getIterator(), JmpI.getDebugLoc(), CondReg);
913
914 // Rewrite the jump to use the !ZF flag from the test, and kill its use of
915 // flags afterward.
916 JmpI.getOperand(1).setImm(Inverted ? X86::COND_E : X86::COND_NE);
917 JmpI.findRegisterUseOperand(X86::EFLAGS)->setIsKill(true);
918 LLVM_DEBUG(dbgs() << " fixed jCC: "; JmpI.dump());
919}
920
921void X86FlagsCopyLoweringPass::rewriteCopy(MachineInstr &MI,
922 MachineOperand &FlagUse,
923 MachineInstr &CopyDefI) {
924 // Just replace this copy with the original copy def.
925 MRI->replaceRegWith(MI.getOperand(0).getReg(),
926 CopyDefI.getOperand(0).getReg());
927 MI.eraseFromParent();
928}
929
930void X86FlagsCopyLoweringPass::rewriteSetCC(MachineBasicBlock &TestMBB,
932 const DebugLoc &TestLoc,
933 MachineInstr &SetCCI,
934 MachineOperand &FlagUse,
935 CondRegArray &CondRegs) {
937 // Note that we can't usefully rewrite this to the inverse without complex
938 // analysis of the users of the setCC. Largely we rely on duplicates which
939 // could have been avoided already being avoided here.
940 unsigned &CondReg = CondRegs[Cond];
941 if (!CondReg)
942 CondReg = promoteCondToReg(TestMBB, TestPos, TestLoc, Cond);
943
944 // Rewriting a register def is trivial: we just replace the register and
945 // remove the setcc.
946 if (!SetCCI.mayStore()) {
947 assert(SetCCI.getOperand(0).isReg() &&
948 "Cannot have a non-register defined operand to SETcc!");
949 Register OldReg = SetCCI.getOperand(0).getReg();
950 // Drop Kill flags on the old register before replacing. CondReg may have
951 // a longer live range.
952 MRI->clearKillFlags(OldReg);
953 MRI->replaceRegWith(OldReg, CondReg);
954 SetCCI.eraseFromParent();
955 return;
956 }
957
958 // Otherwise, we need to emit a store.
959 auto MIB = BuildMI(*SetCCI.getParent(), SetCCI.getIterator(),
960 SetCCI.getDebugLoc(), TII->get(X86::MOV8mr));
961 // Copy the address operands.
962 for (int i = 0; i < X86::AddrNumOperands; ++i)
963 MIB.add(SetCCI.getOperand(i));
964
965 MIB.addReg(CondReg);
966
967 MIB.setMemRefs(SetCCI.memoperands());
968
969 SetCCI.eraseFromParent();
970}
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock & MBB
#define LLVM_DEBUG(X)
Definition: Debug.h:101
bool End
Definition: ELF_riscv.cpp:480
DenseMap< Block *, BlockRelaxAux > Blocks
Definition: ELF_riscv.cpp:507
static const HTTPClientCleanup Cleanup
Definition: HTTPClient.cpp:42
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:59
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
const SmallVectorImpl< MachineOperand > & Cond
static void r1(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
Definition: SHA1.cpp:45
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SI Lower i1 Copies
This file contains some templates that are useful if you are working with the STL at all.
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:167
static X86::CondCode getCondFromFCMOV(unsigned Opcode)
#define LLVM_EXPAND_INSTR_SIZES(MNEMONIC, SUFFIX)
static MachineBasicBlock & splitBlock(MachineBasicBlock &MBB, MachineInstr &SplitI, const X86InstrInfo &TII)
static FlagArithMnemonic getMnemonicFromOpcode(unsigned Opcode)
#define DEBUG_TYPE
#define LLVM_EXPAND_ADC_SBB_INSTR(MNEMONIC)
X86 EFLAGS copy lowering
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
A debug info location.
Definition: DebugLoc.h:33
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
Definition: MCInstrDesc.h:237
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
instr_iterator instr_begin()
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
Replace successor OLD with NEW and update probability info.
MachineBasicBlock * getFallThrough(bool JumpToFallThrough=true)
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
void copySuccessor(const MachineBasicBlock *Orig, succ_iterator I)
Copy a successor (and any probability info) from original block to this block's.
instr_iterator instr_end()
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< succ_iterator > successors()
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
iterator_range< pred_iterator > predecessors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
Definition: MachineInstr.h:69
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:546
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:329
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
Definition: MachineInstr.h:950
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Definition: MachineInstr.h:543
void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
Definition: MachineInstr.h:759
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:475
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:556
MachineOperand * findRegisterUseOperand(Register Reg, bool isKill=false, const TargetRegisterInfo *TRI=nullptr)
Wrapper for findRegisterUseOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
MachineOperand class - Representation of each machine instruction operand.
void setImm(int64_t immVal)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
void setIsKill(bool Val=true)
void setMBB(MachineBasicBlock *MBB)
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0)
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void dump() const
Definition: Pass.cpp:136
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:360
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:342
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:427
bool empty() const
Definition: SmallVector.h:94
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
self_iterator getIterator()
Definition: ilist_node.h:109
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ Dead
Unused definition.
@ X86
Windows x64, Windows Itanium (IA-64)
Reg
All possible values of the reg field in the ModR/M byte.
CondCode getCondFromBranch(const MachineInstr &MI)
CondCode getCondFromCFCMov(const MachineInstr &MI)
CondCode GetOppositeBranchCondition(CondCode CC)
GetOppositeBranchCondition - Return the inverse of the specified cond, e.g.
@ AddrNumOperands
Definition: X86BaseInfo.h:36
CondCode getCondFromSETCC(const MachineInstr &MI)
CondCode getCondFromCMov(const MachineInstr &MI)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
Definition: ScopeExit.h:59
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionPass * createX86FlagsCopyLoweringPass()
Return a pass that lowers EFLAGS copy pseudo instructions.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1729
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:419
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:156
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1824
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1749