LLVM 19.0.0git
SelectionDAGISel.cpp
Go to the documentation of this file.
1//===- SelectionDAGISel.cpp - Implement the SelectionDAGISel class --------===//
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//
9// This implements the SelectionDAGISel class.
10//
11//===----------------------------------------------------------------------===//
12
14#include "ScheduleDAGSDNodes.h"
15#include "SelectionDAGBuilder.h"
16#include "llvm/ADT/APInt.h"
17#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/Statistic.h"
23#include "llvm/ADT/StringRef.h"
27#include "llvm/Analysis/CFG.h"
64#include "llvm/IR/BasicBlock.h"
65#include "llvm/IR/Constants.h"
66#include "llvm/IR/DataLayout.h"
67#include "llvm/IR/DebugInfo.h"
69#include "llvm/IR/DebugLoc.h"
72#include "llvm/IR/Function.h"
73#include "llvm/IR/InlineAsm.h"
75#include "llvm/IR/Instruction.h"
78#include "llvm/IR/Intrinsics.h"
79#include "llvm/IR/IntrinsicsWebAssembly.h"
80#include "llvm/IR/Metadata.h"
81#include "llvm/IR/PrintPasses.h"
82#include "llvm/IR/Statepoint.h"
83#include "llvm/IR/Type.h"
84#include "llvm/IR/User.h"
85#include "llvm/IR/Value.h"
87#include "llvm/MC/MCInstrDesc.h"
88#include "llvm/Pass.h"
94#include "llvm/Support/Debug.h"
97#include "llvm/Support/Timer.h"
103#include <algorithm>
104#include <cassert>
105#include <cstdint>
106#include <iterator>
107#include <limits>
108#include <memory>
109#include <optional>
110#include <string>
111#include <utility>
112#include <vector>
113
114using namespace llvm;
115
116#define DEBUG_TYPE "isel"
117#define ISEL_DUMP_DEBUG_TYPE DEBUG_TYPE "-dump"
118
119STATISTIC(NumFastIselFailures, "Number of instructions fast isel failed on");
120STATISTIC(NumFastIselSuccess, "Number of instructions fast isel selected");
121STATISTIC(NumFastIselBlocks, "Number of blocks selected entirely by fast isel");
122STATISTIC(NumDAGBlocks, "Number of blocks selected using DAG");
123STATISTIC(NumDAGIselRetries,"Number of times dag isel has to try another path");
124STATISTIC(NumEntryBlocks, "Number of entry blocks encountered");
125STATISTIC(NumFastIselFailLowerArguments,
126 "Number of entry blocks where fast isel failed to lower arguments");
127
129 "fast-isel-abort", cl::Hidden,
130 cl::desc("Enable abort calls when \"fast\" instruction selection "
131 "fails to lower an instruction: 0 disable the abort, 1 will "
132 "abort but for args, calls and terminators, 2 will also "
133 "abort for argument lowering, and 3 will never fallback "
134 "to SelectionDAG."));
135
137 "fast-isel-report-on-fallback", cl::Hidden,
138 cl::desc("Emit a diagnostic when \"fast\" instruction selection "
139 "falls back to SelectionDAG."));
140
141static cl::opt<bool>
142UseMBPI("use-mbpi",
143 cl::desc("use Machine Branch Probability Info"),
144 cl::init(true), cl::Hidden);
145
146#ifndef NDEBUG
149 cl::desc("Only display the basic block whose name "
150 "matches this for all view-*-dags options"));
151static cl::opt<bool>
152ViewDAGCombine1("view-dag-combine1-dags", cl::Hidden,
153 cl::desc("Pop up a window to show dags before the first "
154 "dag combine pass"));
155static cl::opt<bool>
156ViewLegalizeTypesDAGs("view-legalize-types-dags", cl::Hidden,
157 cl::desc("Pop up a window to show dags before legalize types"));
158static cl::opt<bool>
159 ViewDAGCombineLT("view-dag-combine-lt-dags", cl::Hidden,
160 cl::desc("Pop up a window to show dags before the post "
161 "legalize types dag combine pass"));
162static cl::opt<bool>
163 ViewLegalizeDAGs("view-legalize-dags", cl::Hidden,
164 cl::desc("Pop up a window to show dags before legalize"));
165static cl::opt<bool>
166ViewDAGCombine2("view-dag-combine2-dags", cl::Hidden,
167 cl::desc("Pop up a window to show dags before the second "
168 "dag combine pass"));
169static cl::opt<bool>
170ViewISelDAGs("view-isel-dags", cl::Hidden,
171 cl::desc("Pop up a window to show isel dags as they are selected"));
172static cl::opt<bool>
173ViewSchedDAGs("view-sched-dags", cl::Hidden,
174 cl::desc("Pop up a window to show sched dags as they are processed"));
175static cl::opt<bool>
176ViewSUnitDAGs("view-sunit-dags", cl::Hidden,
177 cl::desc("Pop up a window to show SUnit dags after they are processed"));
178#else
179static const bool ViewDAGCombine1 = false, ViewLegalizeTypesDAGs = false,
180 ViewDAGCombineLT = false, ViewLegalizeDAGs = false,
181 ViewDAGCombine2 = false, ViewISelDAGs = false,
182 ViewSchedDAGs = false, ViewSUnitDAGs = false;
183#endif
184
185#ifndef NDEBUG
186#define ISEL_DUMP(X) \
187 do { \
188 if (llvm::DebugFlag && \
189 (isCurrentDebugType(DEBUG_TYPE) || \
190 (isCurrentDebugType(ISEL_DUMP_DEBUG_TYPE) && MatchFilterFuncName))) { \
191 X; \
192 } \
193 } while (false)
194#else
195#define ISEL_DUMP(X) do { } while (false)
196#endif
197
198//===---------------------------------------------------------------------===//
199///
200/// RegisterScheduler class - Track the registration of instruction schedulers.
201///
202//===---------------------------------------------------------------------===//
205
206//===---------------------------------------------------------------------===//
207///
208/// ISHeuristic command line option for instruction schedulers.
209///
210//===---------------------------------------------------------------------===//
213ISHeuristic("pre-RA-sched",
215 cl::desc("Instruction schedulers available (before register"
216 " allocation):"));
217
219defaultListDAGScheduler("default", "Best scheduler for the target",
221
222static bool dontUseFastISelFor(const Function &Fn) {
223 // Don't enable FastISel for functions with swiftasync Arguments.
224 // Debug info on those is reliant on good Argument lowering, and FastISel is
225 // not capable of lowering the entire function. Mixing the two selectors tend
226 // to result in poor lowering of Arguments.
227 return any_of(Fn.args(), [](const Argument &Arg) {
228 return Arg.hasAttribute(Attribute::AttrKind::SwiftAsync);
229 });
230}
231
232namespace llvm {
233
234 //===--------------------------------------------------------------------===//
235 /// This class is used by SelectionDAGISel to temporarily override
236 /// the optimization level on a per-function basis.
239 CodeGenOptLevel SavedOptLevel;
240 bool SavedFastISel;
241
242 public:
244 : IS(ISel) {
245 SavedOptLevel = IS.OptLevel;
246 SavedFastISel = IS.TM.Options.EnableFastISel;
247 if (NewOptLevel != SavedOptLevel) {
248 IS.OptLevel = NewOptLevel;
249 IS.TM.setOptLevel(NewOptLevel);
250 LLVM_DEBUG(dbgs() << "\nChanging optimization level for Function "
251 << IS.MF->getFunction().getName() << "\n");
252 LLVM_DEBUG(dbgs() << "\tBefore: -O" << static_cast<int>(SavedOptLevel)
253 << " ; After: -O" << static_cast<int>(NewOptLevel)
254 << "\n");
255 if (NewOptLevel == CodeGenOptLevel::None)
257 }
259 IS.TM.setFastISel(false);
261 dbgs() << "\tFastISel is "
262 << (IS.TM.Options.EnableFastISel ? "enabled" : "disabled")
263 << "\n");
264 }
265
267 if (IS.OptLevel == SavedOptLevel)
268 return;
269 LLVM_DEBUG(dbgs() << "\nRestoring optimization level for Function "
270 << IS.MF->getFunction().getName() << "\n");
271 LLVM_DEBUG(dbgs() << "\tBefore: -O" << static_cast<int>(IS.OptLevel)
272 << " ; After: -O" << static_cast<int>(SavedOptLevel) << "\n");
273 IS.OptLevel = SavedOptLevel;
274 IS.TM.setOptLevel(SavedOptLevel);
275 IS.TM.setFastISel(SavedFastISel);
276 }
277 };
278
279 //===--------------------------------------------------------------------===//
280 /// createDefaultScheduler - This creates an instruction scheduler appropriate
281 /// for the target.
283 CodeGenOptLevel OptLevel) {
284 const TargetLowering *TLI = IS->TLI;
285 const TargetSubtargetInfo &ST = IS->MF->getSubtarget();
286
287 // Try first to see if the Target has its own way of selecting a scheduler
288 if (auto *SchedulerCtor = ST.getDAGScheduler(OptLevel)) {
289 return SchedulerCtor(IS, OptLevel);
290 }
291
292 if (OptLevel == CodeGenOptLevel::None ||
293 (ST.enableMachineScheduler() && ST.enableMachineSchedDefaultSched()) ||
295 return createSourceListDAGScheduler(IS, OptLevel);
297 return createBURRListDAGScheduler(IS, OptLevel);
299 return createHybridListDAGScheduler(IS, OptLevel);
301 return createVLIWDAGScheduler(IS, OptLevel);
303 return createFastDAGScheduler(IS, OptLevel);
305 return createDAGLinearizer(IS, OptLevel);
307 "Unknown sched type!");
308 return createILPListDAGScheduler(IS, OptLevel);
309 }
310
311} // end namespace llvm
312
313// EmitInstrWithCustomInserter - This method should be implemented by targets
314// that mark instructions with the 'usesCustomInserter' flag. These
315// instructions are special in various ways, which require special support to
316// insert. The specified MachineInstr is created but not inserted into any
317// basic blocks, and this method is called to expand it into a sequence of
318// instructions, potentially also creating new basic blocks and control flow.
319// When new basic blocks are inserted and the edges from MBB to its successors
320// are modified, the method should insert pairs of <OldSucc, NewSucc> into the
321// DenseMap.
324 MachineBasicBlock *MBB) const {
325#ifndef NDEBUG
326 dbgs() << "If a target marks an instruction with "
327 "'usesCustomInserter', it must implement "
328 "TargetLowering::EmitInstrWithCustomInserter!\n";
329#endif
330 llvm_unreachable(nullptr);
331}
332
334 SDNode *Node) const {
335 assert(!MI.hasPostISelHook() &&
336 "If a target marks an instruction with 'hasPostISelHook', "
337 "it must implement TargetLowering::AdjustInstrPostInstrSelection!");
338}
339
340//===----------------------------------------------------------------------===//
341// SelectionDAGISel code
342//===----------------------------------------------------------------------===//
343
346 : MachineFunctionPass(ID), TM(tm), FuncInfo(new FunctionLoweringInfo()),
347 SwiftError(new SwiftErrorValueTracking()),
348 CurDAG(new SelectionDAG(tm, OL)),
349 SDB(std::make_unique<SelectionDAGBuilder>(*CurDAG, *FuncInfo, *SwiftError,
350 OL)),
351 OptLevel(OL) {
357}
358
360 delete CurDAG;
361 delete SwiftError;
362}
363
376 // AssignmentTrackingAnalysis only runs if assignment tracking is enabled for
377 // the module.
383}
384
385static void computeUsesMSVCFloatingPoint(const Triple &TT, const Function &F,
386 MachineModuleInfo &MMI) {
387 // Only needed for MSVC
388 if (!TT.isWindowsMSVCEnvironment())
389 return;
390
391 // If it's already set, nothing to do.
392 if (MMI.usesMSVCFloatingPoint())
393 return;
394
395 for (const Instruction &I : instructions(F)) {
396 if (I.getType()->isFPOrFPVectorTy()) {
397 MMI.setUsesMSVCFloatingPoint(true);
398 return;
399 }
400 for (const auto &Op : I.operands()) {
401 if (Op->getType()->isFPOrFPVectorTy()) {
402 MMI.setUsesMSVCFloatingPoint(true);
403 return;
404 }
405 }
406 }
407}
408
410 // If we already selected that function, we do not need to run SDISel.
411 if (mf.getProperties().hasProperty(
413 return false;
414 // Do some sanity-checking on the command-line options.
416 "-fast-isel-abort > 0 requires -fast-isel");
417
418 const Function &Fn = mf.getFunction();
419 MF = &mf;
420
421#ifndef NDEBUG
422 StringRef FuncName = Fn.getName();
424#else
426#endif
427
428 // Decide what flavour of variable location debug-info will be used, before
429 // we change the optimisation level.
430 bool InstrRef = mf.shouldUseDebugInstrRef();
431 mf.setUseDebugInstrRef(InstrRef);
432
433 // Reset the target options before resetting the optimization
434 // level below.
435 // FIXME: This is a horrible hack and should be processed via
436 // codegen looking at the optimization level explicitly when
437 // it wants to look at it.
439 // Reset OptLevel to None for optnone functions.
440 CodeGenOptLevel NewOptLevel = OptLevel;
442 NewOptLevel = CodeGenOptLevel::None;
443 OptLevelChanger OLC(*this, NewOptLevel);
444
447 RegInfo = &MF->getRegInfo();
448 LibInfo = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(Fn);
449 GFI = Fn.hasGC() ? &getAnalysis<GCModuleInfo>().getFunctionInfo(Fn) : nullptr;
450 ORE = std::make_unique<OptimizationRemarkEmitter>(&Fn);
451 AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(mf.getFunction());
452 auto *PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
453 BlockFrequencyInfo *BFI = nullptr;
454 if (PSI && PSI->hasProfileSummary() && OptLevel != CodeGenOptLevel::None)
455 BFI = &getAnalysis<LazyBlockFrequencyInfoPass>().getBFI();
456
457 FunctionVarLocs const *FnVarLocs = nullptr;
459 FnVarLocs = getAnalysis<AssignmentTrackingAnalysis>().getResults();
460
461 ISEL_DUMP(dbgs() << "\n\n\n=== " << FuncName << "\n");
462
463 UniformityInfo *UA = nullptr;
464 if (auto *UAPass = getAnalysisIfAvailable<UniformityInfoWrapperPass>())
465 UA = &UAPass->getUniformityInfo();
466 CurDAG->init(*MF, *ORE, this, LibInfo, UA, PSI, BFI, FnVarLocs);
467 FuncInfo->set(Fn, *MF, CurDAG);
469
470 // Now get the optional analyzes if we want to.
471 // This is based on the possibly changed OptLevel (after optnone is taken
472 // into account). That's unfortunate but OK because it just means we won't
473 // ask for passes that have been required anyway.
474
476 FuncInfo->BPI = &getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI();
477 else
478 FuncInfo->BPI = nullptr;
479
481 AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
482 else
483 AA = nullptr;
484
485 SDB->init(GFI, AA, AC, LibInfo);
486
487 MF->setHasInlineAsm(false);
488
489 FuncInfo->SplitCSR = false;
490
491 // We split CSR if the target supports it for the given function
492 // and the function has only return exits.
494 FuncInfo->SplitCSR = true;
495
496 // Collect all the return blocks.
497 for (const BasicBlock &BB : Fn) {
498 if (!succ_empty(&BB))
499 continue;
500
501 const Instruction *Term = BB.getTerminator();
502 if (isa<UnreachableInst>(Term) || isa<ReturnInst>(Term))
503 continue;
504
505 // Bail out if the exit block is not Return nor Unreachable.
506 FuncInfo->SplitCSR = false;
507 break;
508 }
509 }
510
511 MachineBasicBlock *EntryMBB = &MF->front();
512 if (FuncInfo->SplitCSR)
513 // This performs initialization so lowering for SplitCSR will be correct.
514 TLI->initializeSplitCSR(EntryMBB);
515
516 SelectAllBasicBlocks(Fn);
518 DiagnosticInfoISelFallback DiagFallback(Fn);
519 Fn.getContext().diagnose(DiagFallback);
520 }
521
522 // Replace forward-declared registers with the registers containing
523 // the desired value.
524 // Note: it is important that this happens **before** the call to
525 // EmitLiveInCopies, since implementations can skip copies of unused
526 // registers. If we don't apply the reg fixups before, some registers may
527 // appear as unused and will be skipped, resulting in bad MI.
529 for (DenseMap<Register, Register>::iterator I = FuncInfo->RegFixups.begin(),
530 E = FuncInfo->RegFixups.end();
531 I != E; ++I) {
532 Register From = I->first;
533 Register To = I->second;
534 // If To is also scheduled to be replaced, find what its ultimate
535 // replacement is.
536 while (true) {
537 DenseMap<Register, Register>::iterator J = FuncInfo->RegFixups.find(To);
538 if (J == E)
539 break;
540 To = J->second;
541 }
542 // Make sure the new register has a sufficiently constrained register class.
543 if (From.isVirtual() && To.isVirtual())
544 MRI.constrainRegClass(To, MRI.getRegClass(From));
545 // Replace it.
546
547 // Replacing one register with another won't touch the kill flags.
548 // We need to conservatively clear the kill flags as a kill on the old
549 // register might dominate existing uses of the new register.
550 if (!MRI.use_empty(To))
551 MRI.clearKillFlags(From);
552 MRI.replaceRegWith(From, To);
553 }
554
555 // If the first basic block in the function has live ins that need to be
556 // copied into vregs, emit the copies into the top of the block before
557 // emitting the code for the block.
559 RegInfo->EmitLiveInCopies(EntryMBB, TRI, *TII);
560
561 // Insert copies in the entry block and the return blocks.
562 if (FuncInfo->SplitCSR) {
564 // Collect all the return blocks.
565 for (MachineBasicBlock &MBB : mf) {
566 if (!MBB.succ_empty())
567 continue;
568
570 if (Term != MBB.end() && Term->isReturn()) {
571 Returns.push_back(&MBB);
572 continue;
573 }
574 }
575 TLI->insertCopiesSplitCSR(EntryMBB, Returns);
576 }
577
579 if (!FuncInfo->ArgDbgValues.empty())
580 for (std::pair<unsigned, unsigned> LI : RegInfo->liveins())
581 if (LI.second)
582 LiveInMap.insert(LI);
583
584 // Insert DBG_VALUE instructions for function arguments to the entry block.
585 for (unsigned i = 0, e = FuncInfo->ArgDbgValues.size(); i != e; ++i) {
586 MachineInstr *MI = FuncInfo->ArgDbgValues[e - i - 1];
587 assert(MI->getOpcode() != TargetOpcode::DBG_VALUE_LIST &&
588 "Function parameters should not be described by DBG_VALUE_LIST.");
589 bool hasFI = MI->getDebugOperand(0).isFI();
590 Register Reg =
591 hasFI ? TRI.getFrameRegister(*MF) : MI->getDebugOperand(0).getReg();
592 if (Reg.isPhysical())
593 EntryMBB->insert(EntryMBB->begin(), MI);
594 else {
595 MachineInstr *Def = RegInfo->getVRegDef(Reg);
596 if (Def) {
597 MachineBasicBlock::iterator InsertPos = Def;
598 // FIXME: VR def may not be in entry block.
599 Def->getParent()->insert(std::next(InsertPos), MI);
600 } else
601 LLVM_DEBUG(dbgs() << "Dropping debug info for dead vreg"
602 << Register::virtReg2Index(Reg) << "\n");
603 }
604
605 // Don't try and extend through copies in instruction referencing mode.
606 if (InstrRef)
607 continue;
608
609 // If Reg is live-in then update debug info to track its copy in a vreg.
610 DenseMap<unsigned, unsigned>::iterator LDI = LiveInMap.find(Reg);
611 if (LDI != LiveInMap.end()) {
612 assert(!hasFI && "There's no handling of frame pointer updating here yet "
613 "- add if needed");
614 MachineInstr *Def = RegInfo->getVRegDef(LDI->second);
615 MachineBasicBlock::iterator InsertPos = Def;
616 const MDNode *Variable = MI->getDebugVariable();
617 const MDNode *Expr = MI->getDebugExpression();
618 DebugLoc DL = MI->getDebugLoc();
619 bool IsIndirect = MI->isIndirectDebugValue();
620 if (IsIndirect)
621 assert(MI->getDebugOffset().getImm() == 0 &&
622 "DBG_VALUE with nonzero offset");
623 assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
624 "Expected inlined-at fields to agree");
625 assert(MI->getOpcode() != TargetOpcode::DBG_VALUE_LIST &&
626 "Didn't expect to see a DBG_VALUE_LIST here");
627 // Def is never a terminator here, so it is ok to increment InsertPos.
628 BuildMI(*EntryMBB, ++InsertPos, DL, TII->get(TargetOpcode::DBG_VALUE),
629 IsIndirect, LDI->second, Variable, Expr);
630
631 // If this vreg is directly copied into an exported register then
632 // that COPY instructions also need DBG_VALUE, if it is the only
633 // user of LDI->second.
634 MachineInstr *CopyUseMI = nullptr;
636 UI = RegInfo->use_instr_begin(LDI->second),
637 E = RegInfo->use_instr_end(); UI != E; ) {
638 MachineInstr *UseMI = &*(UI++);
639 if (UseMI->isDebugValue()) continue;
640 if (UseMI->isCopy() && !CopyUseMI && UseMI->getParent() == EntryMBB) {
641 CopyUseMI = UseMI; continue;
642 }
643 // Otherwise this is another use or second copy use.
644 CopyUseMI = nullptr; break;
645 }
646 if (CopyUseMI &&
647 TRI.getRegSizeInBits(LDI->second, MRI) ==
648 TRI.getRegSizeInBits(CopyUseMI->getOperand(0).getReg(), MRI)) {
649 // Use MI's debug location, which describes where Variable was
650 // declared, rather than whatever is attached to CopyUseMI.
651 MachineInstr *NewMI =
652 BuildMI(*MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsIndirect,
653 CopyUseMI->getOperand(0).getReg(), Variable, Expr);
654 MachineBasicBlock::iterator Pos = CopyUseMI;
655 EntryMBB->insertAfter(Pos, NewMI);
656 }
657 }
658 }
659
660 // For debug-info, in instruction referencing mode, we need to perform some
661 // post-isel maintenence.
662 if (MF->useDebugInstrRef())
664
665 // Determine if there are any calls in this machine function.
667 for (const auto &MBB : *MF) {
668 if (MFI.hasCalls() && MF->hasInlineAsm())
669 break;
670
671 for (const auto &MI : MBB) {
672 const MCInstrDesc &MCID = TII->get(MI.getOpcode());
673 if ((MCID.isCall() && !MCID.isReturn()) ||
674 MI.isStackAligningInlineAsm()) {
675 MFI.setHasCalls(true);
676 }
677 if (MI.isInlineAsm()) {
678 MF->setHasInlineAsm(true);
679 }
680 }
681 }
682
683 // Determine if there is a call to setjmp in the machine function.
685
686 // Determine if floating point is used for msvc
688
689 // Release function-specific state. SDB and CurDAG are already cleared
690 // at this point.
691 FuncInfo->clear();
692
693 ISEL_DUMP(dbgs() << "*** MachineFunction at end of ISel ***\n");
694 ISEL_DUMP(MF->print(dbgs()));
695
696 return true;
697}
698
702 bool ShouldAbort) {
703 // Print the function name explicitly if we don't have a debug location (which
704 // makes the diagnostic less useful) or if we're going to emit a raw error.
705 if (!R.getLocation().isValid() || ShouldAbort)
706 R << (" (in function: " + MF.getName() + ")").str();
707
708 if (ShouldAbort)
709 report_fatal_error(Twine(R.getMsg()));
710
711 ORE.emit(R);
712 LLVM_DEBUG(dbgs() << R.getMsg() << "\n");
713}
714
715void SelectionDAGISel::SelectBasicBlock(BasicBlock::const_iterator Begin,
717 bool &HadTailCall) {
718 // Allow creating illegal types during DAG building for the basic block.
720
721 // Lower the instructions. If a call is emitted as a tail call, cease emitting
722 // nodes for this block. If an instruction is elided, don't emit it, but do
723 // handle any debug-info attached to it.
724 for (BasicBlock::const_iterator I = Begin; I != End && !SDB->HasTailCall; ++I) {
725 if (!ElidedArgCopyInstrs.count(&*I))
726 SDB->visit(*I);
727 else
728 SDB->visitDbgInfo(*I);
729 }
730
731 // Make sure the root of the DAG is up-to-date.
732 CurDAG->setRoot(SDB->getControlRoot());
733 HadTailCall = SDB->HasTailCall;
734 SDB->resolveOrClearDbgInfo();
735 SDB->clear();
736
737 // Final step, emit the lowered DAG as machine code.
738 CodeGenAndEmitDAG();
739}
740
741void SelectionDAGISel::ComputeLiveOutVRegInfo() {
744
745 Worklist.push_back(CurDAG->getRoot().getNode());
746 Added.insert(CurDAG->getRoot().getNode());
747
748 KnownBits Known;
749
750 do {
751 SDNode *N = Worklist.pop_back_val();
752
753 // Otherwise, add all chain operands to the worklist.
754 for (const SDValue &Op : N->op_values())
755 if (Op.getValueType() == MVT::Other && Added.insert(Op.getNode()).second)
756 Worklist.push_back(Op.getNode());
757
758 // If this is a CopyToReg with a vreg dest, process it.
759 if (N->getOpcode() != ISD::CopyToReg)
760 continue;
761
762 unsigned DestReg = cast<RegisterSDNode>(N->getOperand(1))->getReg();
763 if (!Register::isVirtualRegister(DestReg))
764 continue;
765
766 // Ignore non-integer values.
767 SDValue Src = N->getOperand(2);
768 EVT SrcVT = Src.getValueType();
769 if (!SrcVT.isInteger())
770 continue;
771
772 unsigned NumSignBits = CurDAG->ComputeNumSignBits(Src);
773 Known = CurDAG->computeKnownBits(Src);
774 FuncInfo->AddLiveOutRegInfo(DestReg, NumSignBits, Known);
775 } while (!Worklist.empty());
776}
777
778void SelectionDAGISel::CodeGenAndEmitDAG() {
779 StringRef GroupName = "sdag";
780 StringRef GroupDescription = "Instruction Selection and Scheduling";
781 std::string BlockName;
782 bool MatchFilterBB = false; (void)MatchFilterBB;
783#ifndef NDEBUG
785 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(*FuncInfo->Fn);
786#endif
787
788 // Pre-type legalization allow creation of any node types.
790
791#ifndef NDEBUG
792 MatchFilterBB = (FilterDAGBasicBlockName.empty() ||
794 FuncInfo->MBB->getBasicBlock()->getName());
795#endif
796#ifdef NDEBUG
800#endif
801 {
802 BlockName =
803 (MF->getName() + ":" + FuncInfo->MBB->getBasicBlock()->getName()).str();
804 }
805 ISEL_DUMP(dbgs() << "\nInitial selection DAG: "
806 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
807 << "'\n";
808 CurDAG->dump());
809
810#ifndef NDEBUG
813#endif
814
815 if (ViewDAGCombine1 && MatchFilterBB)
816 CurDAG->viewGraph("dag-combine1 input for " + BlockName);
817
818 // Run the DAG combiner in pre-legalize mode.
819 {
820 NamedRegionTimer T("combine1", "DAG Combining 1", GroupName,
821 GroupDescription, TimePassesIsEnabled);
823 }
824
825 ISEL_DUMP(dbgs() << "\nOptimized lowered selection DAG: "
826 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
827 << "'\n";
828 CurDAG->dump());
829
830#ifndef NDEBUG
833#endif
834
835 // Second step, hack on the DAG until it only uses operations and types that
836 // the target supports.
837 if (ViewLegalizeTypesDAGs && MatchFilterBB)
838 CurDAG->viewGraph("legalize-types input for " + BlockName);
839
840 bool Changed;
841 {
842 NamedRegionTimer T("legalize_types", "Type Legalization", GroupName,
843 GroupDescription, TimePassesIsEnabled);
844 Changed = CurDAG->LegalizeTypes();
845 }
846
847 ISEL_DUMP(dbgs() << "\nType-legalized selection DAG: "
848 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
849 << "'\n";
850 CurDAG->dump());
851
852#ifndef NDEBUG
855#endif
856
857 // Only allow creation of legal node types.
859
860 if (Changed) {
861 if (ViewDAGCombineLT && MatchFilterBB)
862 CurDAG->viewGraph("dag-combine-lt input for " + BlockName);
863
864 // Run the DAG combiner in post-type-legalize mode.
865 {
866 NamedRegionTimer T("combine_lt", "DAG Combining after legalize types",
867 GroupName, GroupDescription, TimePassesIsEnabled);
869 }
870
871 ISEL_DUMP(dbgs() << "\nOptimized type-legalized selection DAG: "
872 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
873 << "'\n";
874 CurDAG->dump());
875
876#ifndef NDEBUG
879#endif
880 }
881
882 {
883 NamedRegionTimer T("legalize_vec", "Vector Legalization", GroupName,
884 GroupDescription, TimePassesIsEnabled);
885 Changed = CurDAG->LegalizeVectors();
886 }
887
888 if (Changed) {
889 ISEL_DUMP(dbgs() << "\nVector-legalized selection DAG: "
890 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
891 << "'\n";
892 CurDAG->dump());
893
894#ifndef NDEBUG
897#endif
898
899 {
900 NamedRegionTimer T("legalize_types2", "Type Legalization 2", GroupName,
901 GroupDescription, TimePassesIsEnabled);
903 }
904
905 ISEL_DUMP(dbgs() << "\nVector/type-legalized selection DAG: "
906 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
907 << "'\n";
908 CurDAG->dump());
909
910#ifndef NDEBUG
913#endif
914
915 if (ViewDAGCombineLT && MatchFilterBB)
916 CurDAG->viewGraph("dag-combine-lv input for " + BlockName);
917
918 // Run the DAG combiner in post-type-legalize mode.
919 {
920 NamedRegionTimer T("combine_lv", "DAG Combining after legalize vectors",
921 GroupName, GroupDescription, TimePassesIsEnabled);
923 }
924
925 ISEL_DUMP(dbgs() << "\nOptimized vector-legalized selection DAG: "
926 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
927 << "'\n";
928 CurDAG->dump());
929
930#ifndef NDEBUG
933#endif
934 }
935
936 if (ViewLegalizeDAGs && MatchFilterBB)
937 CurDAG->viewGraph("legalize input for " + BlockName);
938
939 {
940 NamedRegionTimer T("legalize", "DAG Legalization", GroupName,
941 GroupDescription, TimePassesIsEnabled);
942 CurDAG->Legalize();
943 }
944
945 ISEL_DUMP(dbgs() << "\nLegalized selection DAG: "
946 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
947 << "'\n";
948 CurDAG->dump());
949
950#ifndef NDEBUG
953#endif
954
955 if (ViewDAGCombine2 && MatchFilterBB)
956 CurDAG->viewGraph("dag-combine2 input for " + BlockName);
957
958 // Run the DAG combiner in post-legalize mode.
959 {
960 NamedRegionTimer T("combine2", "DAG Combining 2", GroupName,
961 GroupDescription, TimePassesIsEnabled);
963 }
964
965 ISEL_DUMP(dbgs() << "\nOptimized legalized selection DAG: "
966 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
967 << "'\n";
968 CurDAG->dump());
969
970#ifndef NDEBUG
973#endif
974
976 ComputeLiveOutVRegInfo();
977
978 if (ViewISelDAGs && MatchFilterBB)
979 CurDAG->viewGraph("isel input for " + BlockName);
980
981 // Third, instruction select all of the operations to machine code, adding the
982 // code to the MachineBasicBlock.
983 {
984 NamedRegionTimer T("isel", "Instruction Selection", GroupName,
985 GroupDescription, TimePassesIsEnabled);
986 DoInstructionSelection();
987 }
988
989 ISEL_DUMP(dbgs() << "\nSelected selection DAG: "
990 << printMBBReference(*FuncInfo->MBB) << " '" << BlockName
991 << "'\n";
992 CurDAG->dump());
993
994 if (ViewSchedDAGs && MatchFilterBB)
995 CurDAG->viewGraph("scheduler input for " + BlockName);
996
997 // Schedule machine code.
998 ScheduleDAGSDNodes *Scheduler = CreateScheduler();
999 {
1000 NamedRegionTimer T("sched", "Instruction Scheduling", GroupName,
1001 GroupDescription, TimePassesIsEnabled);
1002 Scheduler->Run(CurDAG, FuncInfo->MBB);
1003 }
1004
1005 if (ViewSUnitDAGs && MatchFilterBB)
1006 Scheduler->viewGraph();
1007
1008 // Emit machine code to BB. This can change 'BB' to the last block being
1009 // inserted into.
1010 MachineBasicBlock *FirstMBB = FuncInfo->MBB, *LastMBB;
1011 {
1012 NamedRegionTimer T("emit", "Instruction Creation", GroupName,
1013 GroupDescription, TimePassesIsEnabled);
1014
1015 // FuncInfo->InsertPt is passed by reference and set to the end of the
1016 // scheduled instructions.
1017 LastMBB = FuncInfo->MBB = Scheduler->EmitSchedule(FuncInfo->InsertPt);
1018 }
1019
1020 // If the block was split, make sure we update any references that are used to
1021 // update PHI nodes later on.
1022 if (FirstMBB != LastMBB)
1023 SDB->UpdateSplitBlock(FirstMBB, LastMBB);
1024
1025 // Free the scheduler state.
1026 {
1027 NamedRegionTimer T("cleanup", "Instruction Scheduling Cleanup", GroupName,
1028 GroupDescription, TimePassesIsEnabled);
1029 delete Scheduler;
1030 }
1031
1032 // Free the SelectionDAG state, now that we're finished with it.
1033 CurDAG->clear();
1034}
1035
1036namespace {
1037
1038/// ISelUpdater - helper class to handle updates of the instruction selection
1039/// graph.
1040class ISelUpdater : public SelectionDAG::DAGUpdateListener {
1041 SelectionDAG::allnodes_iterator &ISelPosition;
1042
1043public:
1044 ISelUpdater(SelectionDAG &DAG, SelectionDAG::allnodes_iterator &isp)
1045 : SelectionDAG::DAGUpdateListener(DAG), ISelPosition(isp) {}
1046
1047 /// NodeDeleted - Handle nodes deleted from the graph. If the node being
1048 /// deleted is the current ISelPosition node, update ISelPosition.
1049 ///
1050 void NodeDeleted(SDNode *N, SDNode *E) override {
1051 if (ISelPosition == SelectionDAG::allnodes_iterator(N))
1052 ++ISelPosition;
1053 }
1054
1055 /// NodeInserted - Handle new nodes inserted into the graph: propagate
1056 /// metadata from root nodes that also applies to new nodes, in case the root
1057 /// is later deleted.
1058 void NodeInserted(SDNode *N) override {
1059 SDNode *CurNode = &*ISelPosition;
1060 if (MDNode *MD = DAG.getPCSections(CurNode))
1061 DAG.addPCSections(N, MD);
1062 if (MDNode *MMRA = DAG.getMMRAMetadata(CurNode))
1063 DAG.addMMRAMetadata(N, MMRA);
1064 }
1065};
1066
1067} // end anonymous namespace
1068
1069// This function is used to enforce the topological node id property
1070// leveraged during instruction selection. Before the selection process all
1071// nodes are given a non-negative id such that all nodes have a greater id than
1072// their operands. As this holds transitively we can prune checks that a node N
1073// is a predecessor of M another by not recursively checking through M's
1074// operands if N's ID is larger than M's ID. This significantly improves
1075// performance of various legality checks (e.g. IsLegalToFold / UpdateChains).
1076
1077// However, when we fuse multiple nodes into a single node during the
1078// selection we may induce a predecessor relationship between inputs and
1079// outputs of distinct nodes being merged, violating the topological property.
1080// Should a fused node have a successor which has yet to be selected,
1081// our legality checks would be incorrect. To avoid this we mark all unselected
1082// successor nodes, i.e. id != -1, as invalid for pruning by bit-negating (x =>
1083// (-(x+1))) the ids and modify our pruning check to ignore negative Ids of M.
1084// We use bit-negation to more clearly enforce that node id -1 can only be
1085// achieved by selected nodes. As the conversion is reversable to the original
1086// Id, topological pruning can still be leveraged when looking for unselected
1087// nodes. This method is called internally in all ISel replacement related
1088// functions.
1091 Nodes.push_back(Node);
1092
1093 while (!Nodes.empty()) {
1094 SDNode *N = Nodes.pop_back_val();
1095 for (auto *U : N->uses()) {
1096 auto UId = U->getNodeId();
1097 if (UId > 0) {
1099 Nodes.push_back(U);
1100 }
1101 }
1102 }
1103}
1104
1105// InvalidateNodeId - As explained in EnforceNodeIdInvariant, mark a
1106// NodeId with the equivalent node id which is invalid for topological
1107// pruning.
1109 int InvalidId = -(N->getNodeId() + 1);
1110 N->setNodeId(InvalidId);
1111}
1112
1113// getUninvalidatedNodeId - get original uninvalidated node id.
1115 int Id = N->getNodeId();
1116 if (Id < -1)
1117 return -(Id + 1);
1118 return Id;
1119}
1120
1121void SelectionDAGISel::DoInstructionSelection() {
1122 LLVM_DEBUG(dbgs() << "===== Instruction selection begins: "
1123 << printMBBReference(*FuncInfo->MBB) << " '"
1124 << FuncInfo->MBB->getName() << "'\n");
1125
1127
1128 // Select target instructions for the DAG.
1129 {
1130 // Number all nodes with a topological order and set DAGSize.
1132
1133 // Create a dummy node (which is not added to allnodes), that adds
1134 // a reference to the root node, preventing it from being deleted,
1135 // and tracking any changes of the root.
1136 HandleSDNode Dummy(CurDAG->getRoot());
1138 ++ISelPosition;
1139
1140 // Make sure that ISelPosition gets properly updated when nodes are deleted
1141 // in calls made from this function. New nodes inherit relevant metadata.
1142 ISelUpdater ISU(*CurDAG, ISelPosition);
1143
1144 // The AllNodes list is now topological-sorted. Visit the
1145 // nodes by starting at the end of the list (the root of the
1146 // graph) and preceding back toward the beginning (the entry
1147 // node).
1148 while (ISelPosition != CurDAG->allnodes_begin()) {
1149 SDNode *Node = &*--ISelPosition;
1150 // Skip dead nodes. DAGCombiner is expected to eliminate all dead nodes,
1151 // but there are currently some corner cases that it misses. Also, this
1152 // makes it theoretically possible to disable the DAGCombiner.
1153 if (Node->use_empty())
1154 continue;
1155
1156#ifndef NDEBUG
1158 Nodes.push_back(Node);
1159
1160 while (!Nodes.empty()) {
1161 auto N = Nodes.pop_back_val();
1162 if (N->getOpcode() == ISD::TokenFactor || N->getNodeId() < 0)
1163 continue;
1164 for (const SDValue &Op : N->op_values()) {
1165 if (Op->getOpcode() == ISD::TokenFactor)
1166 Nodes.push_back(Op.getNode());
1167 else {
1168 // We rely on topological ordering of node ids for checking for
1169 // cycles when fusing nodes during selection. All unselected nodes
1170 // successors of an already selected node should have a negative id.
1171 // This assertion will catch such cases. If this assertion triggers
1172 // it is likely you using DAG-level Value/Node replacement functions
1173 // (versus equivalent ISEL replacement) in backend-specific
1174 // selections. See comment in EnforceNodeIdInvariant for more
1175 // details.
1176 assert(Op->getNodeId() != -1 &&
1177 "Node has already selected predecessor node");
1178 }
1179 }
1180 }
1181#endif
1182
1183 // When we are using non-default rounding modes or FP exception behavior
1184 // FP operations are represented by StrictFP pseudo-operations. For
1185 // targets that do not (yet) understand strict FP operations directly,
1186 // we convert them to normal FP opcodes instead at this point. This
1187 // will allow them to be handled by existing target-specific instruction
1188 // selectors.
1189 if (!TLI->isStrictFPEnabled() && Node->isStrictFPOpcode()) {
1190 // For some opcodes, we need to call TLI->getOperationAction using
1191 // the first operand type instead of the result type. Note that this
1192 // must match what SelectionDAGLegalize::LegalizeOp is doing.
1193 EVT ActionVT;
1194 switch (Node->getOpcode()) {
1197 case ISD::STRICT_LRINT:
1198 case ISD::STRICT_LLRINT:
1199 case ISD::STRICT_LROUND:
1201 case ISD::STRICT_FSETCC:
1203 ActionVT = Node->getOperand(1).getValueType();
1204 break;
1205 default:
1206 ActionVT = Node->getValueType(0);
1207 break;
1208 }
1209 if (TLI->getOperationAction(Node->getOpcode(), ActionVT)
1212 }
1213
1214 LLVM_DEBUG(dbgs() << "\nISEL: Starting selection on root node: ";
1215 Node->dump(CurDAG));
1216
1217 Select(Node);
1218 }
1219
1220 CurDAG->setRoot(Dummy.getValue());
1221 }
1222
1223 LLVM_DEBUG(dbgs() << "\n===== Instruction selection ends:\n");
1224
1226}
1227
1229 for (const User *U : CPI->users()) {
1230 if (const IntrinsicInst *EHPtrCall = dyn_cast<IntrinsicInst>(U)) {
1231 Intrinsic::ID IID = EHPtrCall->getIntrinsicID();
1232 if (IID == Intrinsic::eh_exceptionpointer ||
1233 IID == Intrinsic::eh_exceptioncode)
1234 return true;
1235 }
1236 }
1237 return false;
1238}
1239
1240// wasm.landingpad.index intrinsic is for associating a landing pad index number
1241// with a catchpad instruction. Retrieve the landing pad index in the intrinsic
1242// and store the mapping in the function.
1244 const CatchPadInst *CPI) {
1245 MachineFunction *MF = MBB->getParent();
1246 // In case of single catch (...), we don't emit LSDA, so we don't need
1247 // this information.
1248 bool IsSingleCatchAllClause =
1249 CPI->arg_size() == 1 &&
1250 cast<Constant>(CPI->getArgOperand(0))->isNullValue();
1251 // cathchpads for longjmp use an empty type list, e.g. catchpad within %0 []
1252 // and they don't need LSDA info
1253 bool IsCatchLongjmp = CPI->arg_size() == 0;
1254 if (!IsSingleCatchAllClause && !IsCatchLongjmp) {
1255 // Create a mapping from landing pad label to landing pad index.
1256 bool IntrFound = false;
1257 for (const User *U : CPI->users()) {
1258 if (const auto *Call = dyn_cast<IntrinsicInst>(U)) {
1259 Intrinsic::ID IID = Call->getIntrinsicID();
1260 if (IID == Intrinsic::wasm_landingpad_index) {
1261 Value *IndexArg = Call->getArgOperand(1);
1262 int Index = cast<ConstantInt>(IndexArg)->getZExtValue();
1264 IntrFound = true;
1265 break;
1266 }
1267 }
1268 }
1269 assert(IntrFound && "wasm.landingpad.index intrinsic not found!");
1270 (void)IntrFound;
1271 }
1272}
1273
1274/// PrepareEHLandingPad - Emit an EH_LABEL, set up live-in registers, and
1275/// do other setup for EH landing-pad blocks.
1276bool SelectionDAGISel::PrepareEHLandingPad() {
1278 const Constant *PersonalityFn = FuncInfo->Fn->getPersonalityFn();
1279 const BasicBlock *LLVMBB = MBB->getBasicBlock();
1280 const TargetRegisterClass *PtrRC =
1282
1283 auto Pers = classifyEHPersonality(PersonalityFn);
1284
1285 // Catchpads have one live-in register, which typically holds the exception
1286 // pointer or code.
1287 if (isFuncletEHPersonality(Pers)) {
1288 if (const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->getFirstNonPHI())) {
1290 // Get or create the virtual register to hold the pointer or code. Mark
1291 // the live in physreg and copy into the vreg.
1292 MCPhysReg EHPhysReg = TLI->getExceptionPointerRegister(PersonalityFn);
1293 assert(EHPhysReg && "target lacks exception pointer register");
1294 MBB->addLiveIn(EHPhysReg);
1295 unsigned VReg = FuncInfo->getCatchPadExceptionPointerVReg(CPI, PtrRC);
1296 BuildMI(*MBB, FuncInfo->InsertPt, SDB->getCurDebugLoc(),
1297 TII->get(TargetOpcode::COPY), VReg)
1298 .addReg(EHPhysReg, RegState::Kill);
1299 }
1300 }
1301 return true;
1302 }
1303
1304 // Add a label to mark the beginning of the landing pad. Deletion of the
1305 // landing pad can thus be detected via the MachineModuleInfo.
1307
1308 const MCInstrDesc &II = TII->get(TargetOpcode::EH_LABEL);
1309 BuildMI(*MBB, FuncInfo->InsertPt, SDB->getCurDebugLoc(), II)
1310 .addSym(Label);
1311
1312 // If the unwinder does not preserve all registers, ensure that the
1313 // function marks the clobbered registers as used.
1315 if (auto *RegMask = TRI.getCustomEHPadPreservedMask(*MF))
1317
1318 if (Pers == EHPersonality::Wasm_CXX) {
1319 if (const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->getFirstNonPHI()))
1321 } else {
1322 // Assign the call site to the landing pad's begin label.
1323 MF->setCallSiteLandingPad(Label, SDB->LPadToCallSiteMap[MBB]);
1324 // Mark exception register as live in.
1325 if (unsigned Reg = TLI->getExceptionPointerRegister(PersonalityFn))
1326 FuncInfo->ExceptionPointerVirtReg = MBB->addLiveIn(Reg, PtrRC);
1327 // Mark exception selector register as live in.
1328 if (unsigned Reg = TLI->getExceptionSelectorRegister(PersonalityFn))
1329 FuncInfo->ExceptionSelectorVirtReg = MBB->addLiveIn(Reg, PtrRC);
1330 }
1331
1332 return true;
1333}
1334
1335// Mark and Report IPToState for each Block under IsEHa
1336void SelectionDAGISel::reportIPToStateForBlocks(MachineFunction *MF) {
1337 MachineModuleInfo &MMI = MF->getMMI();
1339 if (!EHInfo)
1340 return;
1341 for (auto MBBI = MF->begin(), E = MF->end(); MBBI != E; ++MBBI) {
1343 const BasicBlock *BB = MBB->getBasicBlock();
1344 int State = EHInfo->BlockToStateMap[BB];
1345 if (BB->getFirstMayFaultInst()) {
1346 // Report IP range only for blocks with Faulty inst
1347 auto MBBb = MBB->getFirstNonPHI();
1348 MachineInstr *MIb = &*MBBb;
1349 if (MIb->isTerminator())
1350 continue;
1351
1352 // Insert EH Labels
1353 MCSymbol *BeginLabel = MMI.getContext().createTempSymbol();
1354 MCSymbol *EndLabel = MMI.getContext().createTempSymbol();
1355 EHInfo->addIPToStateRange(State, BeginLabel, EndLabel);
1356 BuildMI(*MBB, MBBb, SDB->getCurDebugLoc(),
1357 TII->get(TargetOpcode::EH_LABEL))
1358 .addSym(BeginLabel);
1359 auto MBBe = MBB->instr_end();
1360 MachineInstr *MIe = &*(--MBBe);
1361 // insert before (possible multiple) terminators
1362 while (MIe->isTerminator())
1363 MIe = &*(--MBBe);
1364 ++MBBe;
1365 BuildMI(*MBB, MBBe, SDB->getCurDebugLoc(),
1366 TII->get(TargetOpcode::EH_LABEL))
1367 .addSym(EndLabel);
1368 }
1369 }
1370}
1371
1372/// isFoldedOrDeadInstruction - Return true if the specified instruction is
1373/// side-effect free and is either dead or folded into a generated instruction.
1374/// Return false if it needs to be emitted.
1376 const FunctionLoweringInfo &FuncInfo) {
1377 return !I->mayWriteToMemory() && // Side-effecting instructions aren't folded.
1378 !I->isTerminator() && // Terminators aren't folded.
1379 !isa<DbgInfoIntrinsic>(I) && // Debug instructions aren't folded.
1380 !I->isEHPad() && // EH pad instructions aren't folded.
1381 !FuncInfo.isExportedInst(I); // Exported instrs must be computed.
1382}
1383
1385 const Value *Arg, DIExpression *Expr,
1386 DILocalVariable *Var,
1387 DebugLoc DbgLoc) {
1388 if (!Expr->isEntryValue() || !isa<Argument>(Arg))
1389 return false;
1390
1391 auto ArgIt = FuncInfo.ValueMap.find(Arg);
1392 if (ArgIt == FuncInfo.ValueMap.end())
1393 return false;
1394 Register ArgVReg = ArgIt->getSecond();
1395
1396 // Find the corresponding livein physical register to this argument.
1397 for (auto [PhysReg, VirtReg] : FuncInfo.RegInfo->liveins())
1398 if (VirtReg == ArgVReg) {
1399 // Append an op deref to account for the fact that this is a dbg_declare.
1400 Expr = DIExpression::append(Expr, dwarf::DW_OP_deref);
1401 FuncInfo.MF->setVariableDbgInfo(Var, Expr, PhysReg, DbgLoc);
1402 LLVM_DEBUG(dbgs() << "processDbgDeclare: setVariableDbgInfo Var=" << *Var
1403 << ", Expr=" << *Expr << ", MCRegister=" << PhysReg
1404 << ", DbgLoc=" << DbgLoc << "\n");
1405 return true;
1406 }
1407 return false;
1408}
1409
1411 const Value *Address, DIExpression *Expr,
1412 DILocalVariable *Var, DebugLoc DbgLoc) {
1413 if (!Address) {
1414 LLVM_DEBUG(dbgs() << "processDbgDeclares skipping " << *Var
1415 << " (bad address)\n");
1416 return false;
1417 }
1418
1419 if (processIfEntryValueDbgDeclare(FuncInfo, Address, Expr, Var, DbgLoc))
1420 return true;
1421
1422 MachineFunction *MF = FuncInfo.MF;
1423 const DataLayout &DL = MF->getDataLayout();
1424
1425 assert(Var && "Missing variable");
1426 assert(DbgLoc && "Missing location");
1427
1428 // Look through casts and constant offset GEPs. These mostly come from
1429 // inalloca.
1430 APInt Offset(DL.getTypeSizeInBits(Address->getType()), 0);
1431 Address = Address->stripAndAccumulateInBoundsConstantOffsets(DL, Offset);
1432
1433 // Check if the variable is a static alloca or a byval or inalloca
1434 // argument passed in memory. If it is not, then we will ignore this
1435 // intrinsic and handle this during isel like dbg.value.
1436 int FI = std::numeric_limits<int>::max();
1437 if (const auto *AI = dyn_cast<AllocaInst>(Address)) {
1438 auto SI = FuncInfo.StaticAllocaMap.find(AI);
1439 if (SI != FuncInfo.StaticAllocaMap.end())
1440 FI = SI->second;
1441 } else if (const auto *Arg = dyn_cast<Argument>(Address))
1442 FI = FuncInfo.getArgumentFrameIndex(Arg);
1443
1444 if (FI == std::numeric_limits<int>::max())
1445 return false;
1446
1447 if (Offset.getBoolValue())
1449 Offset.getZExtValue());
1450
1451 LLVM_DEBUG(dbgs() << "processDbgDeclare: setVariableDbgInfo Var=" << *Var
1452 << ", Expr=" << *Expr << ", FI=" << FI
1453 << ", DbgLoc=" << DbgLoc << "\n");
1454 MF->setVariableDbgInfo(Var, Expr, FI, DbgLoc);
1455 return true;
1456}
1457
1458/// Collect llvm.dbg.declare information. This is done after argument lowering
1459/// in case the declarations refer to arguments.
1461 for (const auto &I : instructions(*FuncInfo.Fn)) {
1462 const auto *DI = dyn_cast<DbgDeclareInst>(&I);
1463 if (DI && processDbgDeclare(FuncInfo, DI->getAddress(), DI->getExpression(),
1464 DI->getVariable(), DI->getDebugLoc()))
1465 FuncInfo.PreprocessedDbgDeclares.insert(DI);
1466 for (const DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
1468 processDbgDeclare(FuncInfo, DVR.getVariableLocationOp(0),
1469 DVR.getExpression(), DVR.getVariable(),
1470 DVR.getDebugLoc()))
1471 FuncInfo.PreprocessedDVRDeclares.insert(&DVR);
1472 }
1473 }
1474}
1475
1476/// Collect single location variable information generated with assignment
1477/// tracking. This is done after argument lowering in case the declarations
1478/// refer to arguments.
1480 FunctionVarLocs const *FnVarLocs) {
1481 for (auto It = FnVarLocs->single_locs_begin(),
1482 End = FnVarLocs->single_locs_end();
1483 It != End; ++It) {
1484 assert(!It->Values.hasArgList() && "Single loc variadic ops not supported");
1485 processDbgDeclare(FuncInfo, It->Values.getVariableLocationOp(0), It->Expr,
1486 FnVarLocs->getDILocalVariable(It->VariableID), It->DL);
1487 }
1488}
1489
1490void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
1491 FastISelFailed = false;
1492 // Initialize the Fast-ISel state, if needed.
1493 FastISel *FastIS = nullptr;
1495 LLVM_DEBUG(dbgs() << "Enabling fast-isel\n");
1496 FastIS = TLI->createFastISel(*FuncInfo, LibInfo);
1497 }
1498
1500
1501 // Lower arguments up front. An RPO iteration always visits the entry block
1502 // first.
1503 assert(*RPOT.begin() == &Fn.getEntryBlock());
1504 ++NumEntryBlocks;
1505
1506 // Set up FuncInfo for ISel. Entry blocks never have PHIs.
1507 FuncInfo->MBB = FuncInfo->MBBMap[&Fn.getEntryBlock()];
1508 FuncInfo->InsertPt = FuncInfo->MBB->begin();
1509
1511
1512 if (!FastIS) {
1513 LowerArguments(Fn);
1514 } else {
1515 // See if fast isel can lower the arguments.
1516 FastIS->startNewBlock();
1517 if (!FastIS->lowerArguments()) {
1518 FastISelFailed = true;
1519 // Fast isel failed to lower these arguments
1520 ++NumFastIselFailLowerArguments;
1521
1522 OptimizationRemarkMissed R("sdagisel", "FastISelFailure",
1523 Fn.getSubprogram(),
1524 &Fn.getEntryBlock());
1525 R << "FastISel didn't lower all arguments: "
1526 << ore::NV("Prototype", Fn.getFunctionType());
1528
1529 // Use SelectionDAG argument lowering
1530 LowerArguments(Fn);
1531 CurDAG->setRoot(SDB->getControlRoot());
1532 SDB->clear();
1533 CodeGenAndEmitDAG();
1534 }
1535
1536 // If we inserted any instructions at the beginning, make a note of
1537 // where they are, so we can be sure to emit subsequent instructions
1538 // after them.
1539 if (FuncInfo->InsertPt != FuncInfo->MBB->begin())
1540 FastIS->setLastLocalValue(&*std::prev(FuncInfo->InsertPt));
1541 else
1542 FastIS->setLastLocalValue(nullptr);
1543 }
1544
1545 bool Inserted = SwiftError->createEntriesInEntryBlock(SDB->getCurDebugLoc());
1546
1547 if (FastIS && Inserted)
1548 FastIS->setLastLocalValue(&*std::prev(FuncInfo->InsertPt));
1549
1552 "expected AssignmentTrackingAnalysis pass results");
1554 } else {
1556 }
1557
1558 // Iterate over all basic blocks in the function.
1559 StackProtector &SP = getAnalysis<StackProtector>();
1560 for (const BasicBlock *LLVMBB : RPOT) {
1562 bool AllPredsVisited = true;
1563 for (const BasicBlock *Pred : predecessors(LLVMBB)) {
1564 if (!FuncInfo->VisitedBBs.count(Pred)) {
1565 AllPredsVisited = false;
1566 break;
1567 }
1568 }
1569
1570 if (AllPredsVisited) {
1571 for (const PHINode &PN : LLVMBB->phis())
1572 FuncInfo->ComputePHILiveOutRegInfo(&PN);
1573 } else {
1574 for (const PHINode &PN : LLVMBB->phis())
1575 FuncInfo->InvalidatePHILiveOutRegInfo(&PN);
1576 }
1577
1578 FuncInfo->VisitedBBs.insert(LLVMBB);
1579 }
1580
1581 BasicBlock::const_iterator const Begin =
1582 LLVMBB->getFirstNonPHI()->getIterator();
1583 BasicBlock::const_iterator const End = LLVMBB->end();
1585
1586 FuncInfo->MBB = FuncInfo->MBBMap[LLVMBB];
1587 if (!FuncInfo->MBB)
1588 continue; // Some blocks like catchpads have no code or MBB.
1589
1590 // Insert new instructions after any phi or argument setup code.
1591 FuncInfo->InsertPt = FuncInfo->MBB->end();
1592
1593 // Setup an EH landing-pad block.
1594 FuncInfo->ExceptionPointerVirtReg = 0;
1595 FuncInfo->ExceptionSelectorVirtReg = 0;
1596 if (LLVMBB->isEHPad())
1597 if (!PrepareEHLandingPad())
1598 continue;
1599
1600 // Before doing SelectionDAG ISel, see if FastISel has been requested.
1601 if (FastIS) {
1602 if (LLVMBB != &Fn.getEntryBlock())
1603 FastIS->startNewBlock();
1604
1605 unsigned NumFastIselRemaining = std::distance(Begin, End);
1606
1607 // Pre-assign swifterror vregs.
1608 SwiftError->preassignVRegs(FuncInfo->MBB, Begin, End);
1609
1610 // Do FastISel on as many instructions as possible.
1611 for (; BI != Begin; --BI) {
1612 const Instruction *Inst = &*std::prev(BI);
1613
1614 // If we no longer require this instruction, skip it.
1615 if (isFoldedOrDeadInstruction(Inst, *FuncInfo) ||
1616 ElidedArgCopyInstrs.count(Inst)) {
1617 --NumFastIselRemaining;
1618 FastIS->handleDbgInfo(Inst);
1619 continue;
1620 }
1621
1622 // Bottom-up: reset the insert pos at the top, after any local-value
1623 // instructions.
1624 FastIS->recomputeInsertPt();
1625
1626 // Try to select the instruction with FastISel.
1627 if (FastIS->selectInstruction(Inst)) {
1628 --NumFastIselRemaining;
1629 ++NumFastIselSuccess;
1630
1631 FastIS->handleDbgInfo(Inst);
1632 // If fast isel succeeded, skip over all the folded instructions, and
1633 // then see if there is a load right before the selected instructions.
1634 // Try to fold the load if so.
1635 const Instruction *BeforeInst = Inst;
1636 while (BeforeInst != &*Begin) {
1637 BeforeInst = &*std::prev(BasicBlock::const_iterator(BeforeInst));
1638 if (!isFoldedOrDeadInstruction(BeforeInst, *FuncInfo))
1639 break;
1640 }
1641 if (BeforeInst != Inst && isa<LoadInst>(BeforeInst) &&
1642 BeforeInst->hasOneUse() &&
1643 FastIS->tryToFoldLoad(cast<LoadInst>(BeforeInst), Inst)) {
1644 // If we succeeded, don't re-select the load.
1646 << "FastISel folded load: " << *BeforeInst << "\n");
1647 FastIS->handleDbgInfo(BeforeInst);
1648 BI = std::next(BasicBlock::const_iterator(BeforeInst));
1649 --NumFastIselRemaining;
1650 ++NumFastIselSuccess;
1651 }
1652 continue;
1653 }
1654
1655 FastISelFailed = true;
1656
1657 // Then handle certain instructions as single-LLVM-Instruction blocks.
1658 // We cannot separate out GCrelocates to their own blocks since we need
1659 // to keep track of gc-relocates for a particular gc-statepoint. This is
1660 // done by SelectionDAGBuilder::LowerAsSTATEPOINT, called before
1661 // visitGCRelocate.
1662 if (isa<CallInst>(Inst) && !isa<GCStatepointInst>(Inst) &&
1663 !isa<GCRelocateInst>(Inst) && !isa<GCResultInst>(Inst)) {
1664 OptimizationRemarkMissed R("sdagisel", "FastISelFailure",
1665 Inst->getDebugLoc(), LLVMBB);
1666
1667 R << "FastISel missed call";
1668
1669 if (R.isEnabled() || EnableFastISelAbort) {
1670 std::string InstStrStorage;
1671 raw_string_ostream InstStr(InstStrStorage);
1672 InstStr << *Inst;
1673
1674 R << ": " << InstStr.str();
1675 }
1676
1678
1679 if (!Inst->getType()->isVoidTy() && !Inst->getType()->isTokenTy() &&
1680 !Inst->use_empty()) {
1681 Register &R = FuncInfo->ValueMap[Inst];
1682 if (!R)
1683 R = FuncInfo->CreateRegs(Inst);
1684 }
1685
1686 bool HadTailCall = false;
1687 MachineBasicBlock::iterator SavedInsertPt = FuncInfo->InsertPt;
1688 SelectBasicBlock(Inst->getIterator(), BI, HadTailCall);
1689
1690 // If the call was emitted as a tail call, we're done with the block.
1691 // We also need to delete any previously emitted instructions.
1692 if (HadTailCall) {
1693 FastIS->removeDeadCode(SavedInsertPt, FuncInfo->MBB->end());
1694 --BI;
1695 break;
1696 }
1697
1698 // Recompute NumFastIselRemaining as Selection DAG instruction
1699 // selection may have handled the call, input args, etc.
1700 unsigned RemainingNow = std::distance(Begin, BI);
1701 NumFastIselFailures += NumFastIselRemaining - RemainingNow;
1702 NumFastIselRemaining = RemainingNow;
1703 continue;
1704 }
1705
1706 OptimizationRemarkMissed R("sdagisel", "FastISelFailure",
1707 Inst->getDebugLoc(), LLVMBB);
1708
1709 bool ShouldAbort = EnableFastISelAbort;
1710 if (Inst->isTerminator()) {
1711 // Use a different message for terminator misses.
1712 R << "FastISel missed terminator";
1713 // Don't abort for terminator unless the level is really high
1714 ShouldAbort = (EnableFastISelAbort > 2);
1715 } else {
1716 R << "FastISel missed";
1717 }
1718
1719 if (R.isEnabled() || EnableFastISelAbort) {
1720 std::string InstStrStorage;
1721 raw_string_ostream InstStr(InstStrStorage);
1722 InstStr << *Inst;
1723 R << ": " << InstStr.str();
1724 }
1725
1726 reportFastISelFailure(*MF, *ORE, R, ShouldAbort);
1727
1728 NumFastIselFailures += NumFastIselRemaining;
1729 break;
1730 }
1731
1732 FastIS->recomputeInsertPt();
1733 }
1734
1735 if (SP.shouldEmitSDCheck(*LLVMBB)) {
1736 bool FunctionBasedInstrumentation =
1738 SDB->SPDescriptor.initialize(LLVMBB, FuncInfo->MBBMap[LLVMBB],
1739 FunctionBasedInstrumentation);
1740 }
1741
1742 if (Begin != BI)
1743 ++NumDAGBlocks;
1744 else
1745 ++NumFastIselBlocks;
1746
1747 if (Begin != BI) {
1748 // Run SelectionDAG instruction selection on the remainder of the block
1749 // not handled by FastISel. If FastISel is not run, this is the entire
1750 // block.
1751 bool HadTailCall;
1752 SelectBasicBlock(Begin, BI, HadTailCall);
1753
1754 // But if FastISel was run, we already selected some of the block.
1755 // If we emitted a tail-call, we need to delete any previously emitted
1756 // instruction that follows it.
1757 if (FastIS && HadTailCall && FuncInfo->InsertPt != FuncInfo->MBB->end())
1758 FastIS->removeDeadCode(FuncInfo->InsertPt, FuncInfo->MBB->end());
1759 }
1760
1761 if (FastIS)
1762 FastIS->finishBasicBlock();
1763 FinishBasicBlock();
1764 FuncInfo->PHINodesToUpdate.clear();
1765 ElidedArgCopyInstrs.clear();
1766 }
1767
1768 // AsynchEH: Report Block State under -AsynchEH
1769 if (Fn.getParent()->getModuleFlag("eh-asynch"))
1770 reportIPToStateForBlocks(MF);
1771
1773
1775
1776 delete FastIS;
1777 SDB->clearDanglingDebugInfo();
1778 SDB->SPDescriptor.resetPerFunctionState();
1779}
1780
1781void
1782SelectionDAGISel::FinishBasicBlock() {
1783 LLVM_DEBUG(dbgs() << "Total amount of phi nodes to update: "
1784 << FuncInfo->PHINodesToUpdate.size() << "\n";
1785 for (unsigned i = 0, e = FuncInfo->PHINodesToUpdate.size(); i != e;
1786 ++i) dbgs()
1787 << "Node " << i << " : (" << FuncInfo->PHINodesToUpdate[i].first
1788 << ", " << FuncInfo->PHINodesToUpdate[i].second << ")\n");
1789
1790 // Next, now that we know what the last MBB the LLVM BB expanded is, update
1791 // PHI nodes in successors.
1792 for (unsigned i = 0, e = FuncInfo->PHINodesToUpdate.size(); i != e; ++i) {
1793 MachineInstrBuilder PHI(*MF, FuncInfo->PHINodesToUpdate[i].first);
1794 assert(PHI->isPHI() &&
1795 "This is not a machine PHI node that we are updating!");
1796 if (!FuncInfo->MBB->isSuccessor(PHI->getParent()))
1797 continue;
1798 PHI.addReg(FuncInfo->PHINodesToUpdate[i].second).addMBB(FuncInfo->MBB);
1799 }
1800
1801 // Handle stack protector.
1802 if (SDB->SPDescriptor.shouldEmitFunctionBasedCheckStackProtector()) {
1803 // The target provides a guard check function. There is no need to
1804 // generate error handling code or to split current basic block.
1805 MachineBasicBlock *ParentMBB = SDB->SPDescriptor.getParentMBB();
1806
1807 // Add load and check to the basicblock.
1808 FuncInfo->MBB = ParentMBB;
1809 FuncInfo->InsertPt =
1811 SDB->visitSPDescriptorParent(SDB->SPDescriptor, ParentMBB);
1812 CurDAG->setRoot(SDB->getRoot());
1813 SDB->clear();
1814 CodeGenAndEmitDAG();
1815
1816 // Clear the Per-BB State.
1817 SDB->SPDescriptor.resetPerBBState();
1818 } else if (SDB->SPDescriptor.shouldEmitStackProtector()) {
1819 MachineBasicBlock *ParentMBB = SDB->SPDescriptor.getParentMBB();
1820 MachineBasicBlock *SuccessMBB = SDB->SPDescriptor.getSuccessMBB();
1821
1822 // Find the split point to split the parent mbb. At the same time copy all
1823 // physical registers used in the tail of parent mbb into virtual registers
1824 // before the split point and back into physical registers after the split
1825 // point. This prevents us needing to deal with Live-ins and many other
1826 // register allocation issues caused by us splitting the parent mbb. The
1827 // register allocator will clean up said virtual copies later on.
1828 MachineBasicBlock::iterator SplitPoint =
1830
1831 // Splice the terminator of ParentMBB into SuccessMBB.
1832 SuccessMBB->splice(SuccessMBB->end(), ParentMBB,
1833 SplitPoint,
1834 ParentMBB->end());
1835
1836 // Add compare/jump on neq/jump to the parent BB.
1837 FuncInfo->MBB = ParentMBB;
1838 FuncInfo->InsertPt = ParentMBB->end();
1839 SDB->visitSPDescriptorParent(SDB->SPDescriptor, ParentMBB);
1840 CurDAG->setRoot(SDB->getRoot());
1841 SDB->clear();
1842 CodeGenAndEmitDAG();
1843
1844 // CodeGen Failure MBB if we have not codegened it yet.
1845 MachineBasicBlock *FailureMBB = SDB->SPDescriptor.getFailureMBB();
1846 if (FailureMBB->empty()) {
1847 FuncInfo->MBB = FailureMBB;
1848 FuncInfo->InsertPt = FailureMBB->end();
1849 SDB->visitSPDescriptorFailure(SDB->SPDescriptor);
1850 CurDAG->setRoot(SDB->getRoot());
1851 SDB->clear();
1852 CodeGenAndEmitDAG();
1853 }
1854
1855 // Clear the Per-BB State.
1856 SDB->SPDescriptor.resetPerBBState();
1857 }
1858
1859 // Lower each BitTestBlock.
1860 for (auto &BTB : SDB->SL->BitTestCases) {
1861 // Lower header first, if it wasn't already lowered
1862 if (!BTB.Emitted) {
1863 // Set the current basic block to the mbb we wish to insert the code into
1864 FuncInfo->MBB = BTB.Parent;
1865 FuncInfo->InsertPt = FuncInfo->MBB->end();
1866 // Emit the code
1867 SDB->visitBitTestHeader(BTB, FuncInfo->MBB);
1868 CurDAG->setRoot(SDB->getRoot());
1869 SDB->clear();
1870 CodeGenAndEmitDAG();
1871 }
1872
1873 BranchProbability UnhandledProb = BTB.Prob;
1874 for (unsigned j = 0, ej = BTB.Cases.size(); j != ej; ++j) {
1875 UnhandledProb -= BTB.Cases[j].ExtraProb;
1876 // Set the current basic block to the mbb we wish to insert the code into
1877 FuncInfo->MBB = BTB.Cases[j].ThisBB;
1878 FuncInfo->InsertPt = FuncInfo->MBB->end();
1879 // Emit the code
1880
1881 // If all cases cover a contiguous range, it is not necessary to jump to
1882 // the default block after the last bit test fails. This is because the
1883 // range check during bit test header creation has guaranteed that every
1884 // case here doesn't go outside the range. In this case, there is no need
1885 // to perform the last bit test, as it will always be true. Instead, make
1886 // the second-to-last bit-test fall through to the target of the last bit
1887 // test, and delete the last bit test.
1888
1889 MachineBasicBlock *NextMBB;
1890 if ((BTB.ContiguousRange || BTB.FallthroughUnreachable) && j + 2 == ej) {
1891 // Second-to-last bit-test with contiguous range or omitted range
1892 // check: fall through to the target of the final bit test.
1893 NextMBB = BTB.Cases[j + 1].TargetBB;
1894 } else if (j + 1 == ej) {
1895 // For the last bit test, fall through to Default.
1896 NextMBB = BTB.Default;
1897 } else {
1898 // Otherwise, fall through to the next bit test.
1899 NextMBB = BTB.Cases[j + 1].ThisBB;
1900 }
1901
1902 SDB->visitBitTestCase(BTB, NextMBB, UnhandledProb, BTB.Reg, BTB.Cases[j],
1903 FuncInfo->MBB);
1904
1905 CurDAG->setRoot(SDB->getRoot());
1906 SDB->clear();
1907 CodeGenAndEmitDAG();
1908
1909 if ((BTB.ContiguousRange || BTB.FallthroughUnreachable) && j + 2 == ej) {
1910 // Since we're not going to use the final bit test, remove it.
1911 BTB.Cases.pop_back();
1912 break;
1913 }
1914 }
1915
1916 // Update PHI Nodes
1917 for (const std::pair<MachineInstr *, unsigned> &P :
1918 FuncInfo->PHINodesToUpdate) {
1919 MachineInstrBuilder PHI(*MF, P.first);
1920 MachineBasicBlock *PHIBB = PHI->getParent();
1921 assert(PHI->isPHI() &&
1922 "This is not a machine PHI node that we are updating!");
1923 // This is "default" BB. We have two jumps to it. From "header" BB and
1924 // from last "case" BB, unless the latter was skipped.
1925 if (PHIBB == BTB.Default) {
1926 PHI.addReg(P.second).addMBB(BTB.Parent);
1927 if (!BTB.ContiguousRange) {
1928 PHI.addReg(P.second).addMBB(BTB.Cases.back().ThisBB);
1929 }
1930 }
1931 // One of "cases" BB.
1932 for (const SwitchCG::BitTestCase &BT : BTB.Cases) {
1933 MachineBasicBlock* cBB = BT.ThisBB;
1934 if (cBB->isSuccessor(PHIBB))
1935 PHI.addReg(P.second).addMBB(cBB);
1936 }
1937 }
1938 }
1939 SDB->SL->BitTestCases.clear();
1940
1941 // If the JumpTable record is filled in, then we need to emit a jump table.
1942 // Updating the PHI nodes is tricky in this case, since we need to determine
1943 // whether the PHI is a successor of the range check MBB or the jump table MBB
1944 for (unsigned i = 0, e = SDB->SL->JTCases.size(); i != e; ++i) {
1945 // Lower header first, if it wasn't already lowered
1946 if (!SDB->SL->JTCases[i].first.Emitted) {
1947 // Set the current basic block to the mbb we wish to insert the code into
1948 FuncInfo->MBB = SDB->SL->JTCases[i].first.HeaderBB;
1949 FuncInfo->InsertPt = FuncInfo->MBB->end();
1950 // Emit the code
1951 SDB->visitJumpTableHeader(SDB->SL->JTCases[i].second,
1952 SDB->SL->JTCases[i].first, FuncInfo->MBB);
1953 CurDAG->setRoot(SDB->getRoot());
1954 SDB->clear();
1955 CodeGenAndEmitDAG();
1956 }
1957
1958 // Set the current basic block to the mbb we wish to insert the code into
1959 FuncInfo->MBB = SDB->SL->JTCases[i].second.MBB;
1960 FuncInfo->InsertPt = FuncInfo->MBB->end();
1961 // Emit the code
1962 SDB->visitJumpTable(SDB->SL->JTCases[i].second);
1963 CurDAG->setRoot(SDB->getRoot());
1964 SDB->clear();
1965 CodeGenAndEmitDAG();
1966
1967 // Update PHI Nodes
1968 for (unsigned pi = 0, pe = FuncInfo->PHINodesToUpdate.size();
1969 pi != pe; ++pi) {
1970 MachineInstrBuilder PHI(*MF, FuncInfo->PHINodesToUpdate[pi].first);
1971 MachineBasicBlock *PHIBB = PHI->getParent();
1972 assert(PHI->isPHI() &&
1973 "This is not a machine PHI node that we are updating!");
1974 // "default" BB. We can go there only from header BB.
1975 if (PHIBB == SDB->SL->JTCases[i].second.Default)
1976 PHI.addReg(FuncInfo->PHINodesToUpdate[pi].second)
1977 .addMBB(SDB->SL->JTCases[i].first.HeaderBB);
1978 // JT BB. Just iterate over successors here
1979 if (FuncInfo->MBB->isSuccessor(PHIBB))
1980 PHI.addReg(FuncInfo->PHINodesToUpdate[pi].second).addMBB(FuncInfo->MBB);
1981 }
1982 }
1983 SDB->SL->JTCases.clear();
1984
1985 // If we generated any switch lowering information, build and codegen any
1986 // additional DAGs necessary.
1987 for (unsigned i = 0, e = SDB->SL->SwitchCases.size(); i != e; ++i) {
1988 // Set the current basic block to the mbb we wish to insert the code into
1989 FuncInfo->MBB = SDB->SL->SwitchCases[i].ThisBB;
1990 FuncInfo->InsertPt = FuncInfo->MBB->end();
1991
1992 // Determine the unique successors.
1994 Succs.push_back(SDB->SL->SwitchCases[i].TrueBB);
1995 if (SDB->SL->SwitchCases[i].TrueBB != SDB->SL->SwitchCases[i].FalseBB)
1996 Succs.push_back(SDB->SL->SwitchCases[i].FalseBB);
1997
1998 // Emit the code. Note that this could result in FuncInfo->MBB being split.
1999 SDB->visitSwitchCase(SDB->SL->SwitchCases[i], FuncInfo->MBB);
2000 CurDAG->setRoot(SDB->getRoot());
2001 SDB->clear();
2002 CodeGenAndEmitDAG();
2003
2004 // Remember the last block, now that any splitting is done, for use in
2005 // populating PHI nodes in successors.
2006 MachineBasicBlock *ThisBB = FuncInfo->MBB;
2007
2008 // Handle any PHI nodes in successors of this chunk, as if we were coming
2009 // from the original BB before switch expansion. Note that PHI nodes can
2010 // occur multiple times in PHINodesToUpdate. We have to be very careful to
2011 // handle them the right number of times.
2012 for (unsigned i = 0, e = Succs.size(); i != e; ++i) {
2013 FuncInfo->MBB = Succs[i];
2014 FuncInfo->InsertPt = FuncInfo->MBB->end();
2015 // FuncInfo->MBB may have been removed from the CFG if a branch was
2016 // constant folded.
2017 if (ThisBB->isSuccessor(FuncInfo->MBB)) {
2019 MBBI = FuncInfo->MBB->begin(), MBBE = FuncInfo->MBB->end();
2020 MBBI != MBBE && MBBI->isPHI(); ++MBBI) {
2022 // This value for this PHI node is recorded in PHINodesToUpdate.
2023 for (unsigned pn = 0; ; ++pn) {
2024 assert(pn != FuncInfo->PHINodesToUpdate.size() &&
2025 "Didn't find PHI entry!");
2026 if (FuncInfo->PHINodesToUpdate[pn].first == PHI) {
2027 PHI.addReg(FuncInfo->PHINodesToUpdate[pn].second).addMBB(ThisBB);
2028 break;
2029 }
2030 }
2031 }
2032 }
2033 }
2034 }
2035 SDB->SL->SwitchCases.clear();
2036}
2037
2038/// Create the scheduler. If a specific scheduler was specified
2039/// via the SchedulerRegistry, use it, otherwise select the
2040/// one preferred by the target.
2041///
2042ScheduleDAGSDNodes *SelectionDAGISel::CreateScheduler() {
2043 return ISHeuristic(this, OptLevel);
2044}
2045
2046//===----------------------------------------------------------------------===//
2047// Helper functions used by the generated instruction selector.
2048//===----------------------------------------------------------------------===//
2049// Calls to these methods are generated by tblgen.
2050
2051/// CheckAndMask - The isel is trying to match something like (and X, 255). If
2052/// the dag combiner simplified the 255, we still want to match. RHS is the
2053/// actual value in the DAG on the RHS of an AND, and DesiredMaskS is the value
2054/// specified in the .td file (e.g. 255).
2056 int64_t DesiredMaskS) const {
2057 const APInt &ActualMask = RHS->getAPIntValue();
2058 const APInt &DesiredMask = APInt(LHS.getValueSizeInBits(), DesiredMaskS);
2059
2060 // If the actual mask exactly matches, success!
2061 if (ActualMask == DesiredMask)
2062 return true;
2063
2064 // If the actual AND mask is allowing unallowed bits, this doesn't match.
2065 if (!ActualMask.isSubsetOf(DesiredMask))
2066 return false;
2067
2068 // Otherwise, the DAG Combiner may have proven that the value coming in is
2069 // either already zero or is not demanded. Check for known zero input bits.
2070 APInt NeededMask = DesiredMask & ~ActualMask;
2071 if (CurDAG->MaskedValueIsZero(LHS, NeededMask))
2072 return true;
2073
2074 // TODO: check to see if missing bits are just not demanded.
2075
2076 // Otherwise, this pattern doesn't match.
2077 return false;
2078}
2079
2080/// CheckOrMask - The isel is trying to match something like (or X, 255). If
2081/// the dag combiner simplified the 255, we still want to match. RHS is the
2082/// actual value in the DAG on the RHS of an OR, and DesiredMaskS is the value
2083/// specified in the .td file (e.g. 255).
2085 int64_t DesiredMaskS) const {
2086 const APInt &ActualMask = RHS->getAPIntValue();
2087 const APInt &DesiredMask = APInt(LHS.getValueSizeInBits(), DesiredMaskS);
2088
2089 // If the actual mask exactly matches, success!
2090 if (ActualMask == DesiredMask)
2091 return true;
2092
2093 // If the actual AND mask is allowing unallowed bits, this doesn't match.
2094 if (!ActualMask.isSubsetOf(DesiredMask))
2095 return false;
2096
2097 // Otherwise, the DAG Combiner may have proven that the value coming in is
2098 // either already zero or is not demanded. Check for known zero input bits.
2099 APInt NeededMask = DesiredMask & ~ActualMask;
2101
2102 // If all the missing bits in the or are already known to be set, match!
2103 if (NeededMask.isSubsetOf(Known.One))
2104 return true;
2105
2106 // TODO: check to see if missing bits are just not demanded.
2107
2108 // Otherwise, this pattern doesn't match.
2109 return false;
2110}
2111
2112/// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
2113/// by tblgen. Others should not call it.
2115 const SDLoc &DL) {
2116 std::vector<SDValue> InOps;
2117 std::swap(InOps, Ops);
2118
2119 Ops.push_back(InOps[InlineAsm::Op_InputChain]); // 0
2120 Ops.push_back(InOps[InlineAsm::Op_AsmString]); // 1
2121 Ops.push_back(InOps[InlineAsm::Op_MDNode]); // 2, !srcloc
2122 Ops.push_back(InOps[InlineAsm::Op_ExtraInfo]); // 3 (SideEffect, AlignStack)
2123
2124 unsigned i = InlineAsm::Op_FirstOperand, e = InOps.size();
2125 if (InOps[e-1].getValueType() == MVT::Glue)
2126 --e; // Don't process a glue operand if it is here.
2127
2128 while (i != e) {
2129 InlineAsm::Flag Flags(InOps[i]->getAsZExtVal());
2130 if (!Flags.isMemKind() && !Flags.isFuncKind()) {
2131 // Just skip over this operand, copying the operands verbatim.
2132 Ops.insert(Ops.end(), InOps.begin() + i,
2133 InOps.begin() + i + Flags.getNumOperandRegisters() + 1);
2134 i += Flags.getNumOperandRegisters() + 1;
2135 } else {
2136 assert(Flags.getNumOperandRegisters() == 1 &&
2137 "Memory operand with multiple values?");
2138
2139 unsigned TiedToOperand;
2140 if (Flags.isUseOperandTiedToDef(TiedToOperand)) {
2141 // We need the constraint ID from the operand this is tied to.
2142 unsigned CurOp = InlineAsm::Op_FirstOperand;
2143 Flags = InlineAsm::Flag(InOps[CurOp]->getAsZExtVal());
2144 for (; TiedToOperand; --TiedToOperand) {
2145 CurOp += Flags.getNumOperandRegisters() + 1;
2146 Flags = InlineAsm::Flag(InOps[CurOp]->getAsZExtVal());
2147 }
2148 }
2149
2150 // Otherwise, this is a memory operand. Ask the target to select it.
2151 std::vector<SDValue> SelOps;
2152 const InlineAsm::ConstraintCode ConstraintID =
2153 Flags.getMemoryConstraintID();
2154 if (SelectInlineAsmMemoryOperand(InOps[i+1], ConstraintID, SelOps))
2155 report_fatal_error("Could not match memory address. Inline asm"
2156 " failure!");
2157
2158 // Add this to the output node.
2159 Flags = InlineAsm::Flag(Flags.isMemKind() ? InlineAsm::Kind::Mem
2161 SelOps.size());
2162 Flags.setMemConstraint(ConstraintID);
2163 Ops.push_back(CurDAG->getTargetConstant(Flags, DL, MVT::i32));
2164 llvm::append_range(Ops, SelOps);
2165 i += 2;
2166 }
2167 }
2168
2169 // Add the glue input back if present.
2170 if (e != InOps.size())
2171 Ops.push_back(InOps.back());
2172}
2173
2174/// findGlueUse - Return use of MVT::Glue value produced by the specified
2175/// SDNode.
2176///
2178 unsigned FlagResNo = N->getNumValues()-1;
2179 for (SDNode::use_iterator I = N->use_begin(), E = N->use_end(); I != E; ++I) {
2180 SDUse &Use = I.getUse();
2181 if (Use.getResNo() == FlagResNo)
2182 return Use.getUser();
2183 }
2184 return nullptr;
2185}
2186
2187/// findNonImmUse - Return true if "Def" is a predecessor of "Root" via a path
2188/// beyond "ImmedUse". We may ignore chains as they are checked separately.
2189static bool findNonImmUse(SDNode *Root, SDNode *Def, SDNode *ImmedUse,
2190 bool IgnoreChains) {
2193 // Only check if we have non-immediate uses of Def.
2194 if (ImmedUse->isOnlyUserOf(Def))
2195 return false;
2196
2197 // We don't care about paths to Def that go through ImmedUse so mark it
2198 // visited and mark non-def operands as used.
2199 Visited.insert(ImmedUse);
2200 for (const SDValue &Op : ImmedUse->op_values()) {
2201 SDNode *N = Op.getNode();
2202 // Ignore chain deps (they are validated by
2203 // HandleMergeInputChains) and immediate uses
2204 if ((Op.getValueType() == MVT::Other && IgnoreChains) || N == Def)
2205 continue;
2206 if (!Visited.insert(N).second)
2207 continue;
2208 WorkList.push_back(N);
2209 }
2210
2211 // Initialize worklist to operands of Root.
2212 if (Root != ImmedUse) {
2213 for (const SDValue &Op : Root->op_values()) {
2214 SDNode *N = Op.getNode();
2215 // Ignore chains (they are validated by HandleMergeInputChains)
2216 if ((Op.getValueType() == MVT::Other && IgnoreChains) || N == Def)
2217 continue;
2218 if (!Visited.insert(N).second)
2219 continue;
2220 WorkList.push_back(N);
2221 }
2222 }
2223
2224 return SDNode::hasPredecessorHelper(Def, Visited, WorkList, 0, true);
2225}
2226
2227/// IsProfitableToFold - Returns true if it's profitable to fold the specific
2228/// operand node N of U during instruction selection that starts at Root.
2230 SDNode *Root) const {
2232 return false;
2233 return N.hasOneUse();
2234}
2235
2236/// IsLegalToFold - Returns true if the specific operand node N of
2237/// U can be folded during instruction selection that starts at Root.
2239 CodeGenOptLevel OptLevel,
2240 bool IgnoreChains) {
2242 return false;
2243
2244 // If Root use can somehow reach N through a path that doesn't contain
2245 // U then folding N would create a cycle. e.g. In the following
2246 // diagram, Root can reach N through X. If N is folded into Root, then
2247 // X is both a predecessor and a successor of U.
2248 //
2249 // [N*] //
2250 // ^ ^ //
2251 // / \ //
2252 // [U*] [X]? //
2253 // ^ ^ //
2254 // \ / //
2255 // \ / //
2256 // [Root*] //
2257 //
2258 // * indicates nodes to be folded together.
2259 //
2260 // If Root produces glue, then it gets (even more) interesting. Since it
2261 // will be "glued" together with its glue use in the scheduler, we need to
2262 // check if it might reach N.
2263 //
2264 // [N*] //
2265 // ^ ^ //
2266 // / \ //
2267 // [U*] [X]? //
2268 // ^ ^ //
2269 // \ \ //
2270 // \ | //
2271 // [Root*] | //
2272 // ^ | //
2273 // f | //
2274 // | / //
2275 // [Y] / //
2276 // ^ / //
2277 // f / //
2278 // | / //
2279 // [GU] //
2280 //
2281 // If GU (glue use) indirectly reaches N (the load), and Root folds N
2282 // (call it Fold), then X is a predecessor of GU and a successor of
2283 // Fold. But since Fold and GU are glued together, this will create
2284 // a cycle in the scheduling graph.
2285
2286 // If the node has glue, walk down the graph to the "lowest" node in the
2287 // glueged set.
2288 EVT VT = Root->getValueType(Root->getNumValues()-1);
2289 while (VT == MVT::Glue) {
2290 SDNode *GU = findGlueUse(Root);
2291 if (!GU)
2292 break;
2293 Root = GU;
2294 VT = Root->getValueType(Root->getNumValues()-1);
2295
2296 // If our query node has a glue result with a use, we've walked up it. If
2297 // the user (which has already been selected) has a chain or indirectly uses
2298 // the chain, HandleMergeInputChains will not consider it. Because of
2299 // this, we cannot ignore chains in this predicate.
2300 IgnoreChains = false;
2301 }
2302
2303 return !findNonImmUse(Root, N.getNode(), U, IgnoreChains);
2304}
2305
2306void SelectionDAGISel::Select_INLINEASM(SDNode *N) {
2307 SDLoc DL(N);
2308
2309 std::vector<SDValue> Ops(N->op_begin(), N->op_end());
2311
2312 const EVT VTs[] = {MVT::Other, MVT::Glue};
2313 SDValue New = CurDAG->getNode(N->getOpcode(), DL, VTs, Ops);
2314 New->setNodeId(-1);
2315 ReplaceUses(N, New.getNode());
2317}
2318
2319void SelectionDAGISel::Select_READ_REGISTER(SDNode *Op) {
2320 SDLoc dl(Op);
2321 MDNodeSDNode *MD = cast<MDNodeSDNode>(Op->getOperand(1));
2322 const MDString *RegStr = cast<MDString>(MD->getMD()->getOperand(0));
2323
2324 EVT VT = Op->getValueType(0);
2325 LLT Ty = VT.isSimple() ? getLLTForMVT(VT.getSimpleVT()) : LLT();
2326 Register Reg =
2327 TLI->getRegisterByName(RegStr->getString().data(), Ty,
2330 Op->getOperand(0), dl, Reg, Op->getValueType(0));
2331 New->setNodeId(-1);
2332 ReplaceUses(Op, New.getNode());
2334}
2335
2336void SelectionDAGISel::Select_WRITE_REGISTER(SDNode *Op) {
2337 SDLoc dl(Op);
2338 MDNodeSDNode *MD = cast<MDNodeSDNode>(Op->getOperand(1));
2339 const MDString *RegStr = cast<MDString>(MD->getMD()->getOperand(0));
2340
2341 EVT VT = Op->getOperand(2).getValueType();
2342 LLT Ty = VT.isSimple() ? getLLTForMVT(VT.getSimpleVT()) : LLT();
2343
2344 Register Reg = TLI->getRegisterByName(RegStr->getString().data(), Ty,
2347 Op->getOperand(0), dl, Reg, Op->getOperand(2));
2348 New->setNodeId(-1);
2349 ReplaceUses(Op, New.getNode());
2351}
2352
2353void SelectionDAGISel::Select_UNDEF(SDNode *N) {
2354 CurDAG->SelectNodeTo(N, TargetOpcode::IMPLICIT_DEF, N->getValueType(0));
2355}
2356
2357void SelectionDAGISel::Select_FREEZE(SDNode *N) {
2358 // TODO: We don't have FREEZE pseudo-instruction in MachineInstr-level now.
2359 // If FREEZE instruction is added later, the code below must be changed as
2360 // well.
2361 CurDAG->SelectNodeTo(N, TargetOpcode::COPY, N->getValueType(0),
2362 N->getOperand(0));
2363}
2364
2365void SelectionDAGISel::Select_ARITH_FENCE(SDNode *N) {
2366 CurDAG->SelectNodeTo(N, TargetOpcode::ARITH_FENCE, N->getValueType(0),
2367 N->getOperand(0));
2368}
2369
2370void SelectionDAGISel::Select_MEMBARRIER(SDNode *N) {
2371 CurDAG->SelectNodeTo(N, TargetOpcode::MEMBARRIER, N->getValueType(0),
2372 N->getOperand(0));
2373}
2374
2375void SelectionDAGISel::Select_CONVERGENCECTRL_ANCHOR(SDNode *N) {
2376 CurDAG->SelectNodeTo(N, TargetOpcode::CONVERGENCECTRL_ANCHOR,
2377 N->getValueType(0));
2378}
2379
2380void SelectionDAGISel::Select_CONVERGENCECTRL_ENTRY(SDNode *N) {
2381 CurDAG->SelectNodeTo(N, TargetOpcode::CONVERGENCECTRL_ENTRY,
2382 N->getValueType(0));
2383}
2384
2385void SelectionDAGISel::Select_CONVERGENCECTRL_LOOP(SDNode *N) {
2386 CurDAG->SelectNodeTo(N, TargetOpcode::CONVERGENCECTRL_LOOP,
2387 N->getValueType(0), N->getOperand(0));
2388}
2389
2390void SelectionDAGISel::pushStackMapLiveVariable(SmallVectorImpl<SDValue> &Ops,
2391 SDValue OpVal, SDLoc DL) {
2392 SDNode *OpNode = OpVal.getNode();
2393
2394 // FrameIndex nodes should have been directly emitted to TargetFrameIndex
2395 // nodes at DAG-construction time.
2396 assert(OpNode->getOpcode() != ISD::FrameIndex);
2397
2398 if (OpNode->getOpcode() == ISD::Constant) {
2399 Ops.push_back(
2400 CurDAG->getTargetConstant(StackMaps::ConstantOp, DL, MVT::i64));
2402 OpVal.getValueType()));
2403 } else {
2404 Ops.push_back(OpVal);
2405 }
2406}
2407
2408void SelectionDAGISel::Select_STACKMAP(SDNode *N) {
2410 auto *It = N->op_begin();
2411 SDLoc DL(N);
2412
2413 // Stash the chain and glue operands so we can move them to the end.
2414 SDValue Chain = *It++;
2415 SDValue InGlue = *It++;
2416
2417 // <id> operand.
2418 SDValue ID = *It++;
2419 assert(ID.getValueType() == MVT::i64);
2420 Ops.push_back(ID);
2421
2422 // <numShadowBytes> operand.
2423 SDValue Shad = *It++;
2424 assert(Shad.getValueType() == MVT::i32);
2425 Ops.push_back(Shad);
2426
2427 // Live variable operands.
2428 for (; It != N->op_end(); It++)
2429 pushStackMapLiveVariable(Ops, *It, DL);
2430
2431 Ops.push_back(Chain);
2432 Ops.push_back(InGlue);
2433
2434 SDVTList NodeTys = CurDAG->getVTList(MVT::Other, MVT::Glue);
2435 CurDAG->SelectNodeTo(N, TargetOpcode::STACKMAP, NodeTys, Ops);
2436}
2437
2438void SelectionDAGISel::Select_PATCHPOINT(SDNode *N) {
2440 auto *It = N->op_begin();
2441 SDLoc DL(N);
2442
2443 // Cache arguments that will be moved to the end in the target node.
2444 SDValue Chain = *It++;
2445 std::optional<SDValue> Glue;
2446 if (It->getValueType() == MVT::Glue)
2447 Glue = *It++;
2448 SDValue RegMask = *It++;
2449
2450 // <id> operand.
2451 SDValue ID = *It++;
2452 assert(ID.getValueType() == MVT::i64);
2453 Ops.push_back(ID);
2454
2455 // <numShadowBytes> operand.
2456 SDValue Shad = *It++;
2457 assert(Shad.getValueType() == MVT::i32);
2458 Ops.push_back(Shad);
2459
2460 // Add the callee.
2461 Ops.push_back(*It++);
2462
2463 // Add <numArgs>.
2464 SDValue NumArgs = *It++;
2465 assert(NumArgs.getValueType() == MVT::i32);
2466 Ops.push_back(NumArgs);
2467
2468 // Calling convention.
2469 Ops.push_back(*It++);
2470
2471 // Push the args for the call.
2472 for (uint64_t I = NumArgs->getAsZExtVal(); I != 0; I--)
2473 Ops.push_back(*It++);
2474
2475 // Now push the live variables.
2476 for (; It != N->op_end(); It++)
2477 pushStackMapLiveVariable(Ops, *It, DL);
2478
2479 // Finally, the regmask, chain and (if present) glue are moved to the end.
2480 Ops.push_back(RegMask);
2481 Ops.push_back(Chain);
2482 if (Glue.has_value())
2483 Ops.push_back(*Glue);
2484
2485 SDVTList NodeTys = N->getVTList();
2486 CurDAG->SelectNodeTo(N, TargetOpcode::PATCHPOINT, NodeTys, Ops);
2487}
2488
2489/// GetVBR - decode a vbr encoding whose top bit is set.
2491GetVBR(uint64_t Val, const unsigned char *MatcherTable, unsigned &Idx) {
2492 assert(Val >= 128 && "Not a VBR");
2493 Val &= 127; // Remove first vbr bit.
2494
2495 unsigned Shift = 7;
2496 uint64_t NextBits;
2497 do {
2498 NextBits = MatcherTable[Idx++];
2499 Val |= (NextBits&127) << Shift;
2500 Shift += 7;
2501 } while (NextBits & 128);
2502
2503 return Val;
2504}
2505
2506void SelectionDAGISel::Select_JUMP_TABLE_DEBUG_INFO(SDNode *N) {
2507 SDLoc dl(N);
2508 CurDAG->SelectNodeTo(N, TargetOpcode::JUMP_TABLE_DEBUG_INFO, MVT::Glue,
2509 CurDAG->getTargetConstant(N->getConstantOperandVal(1),
2510 dl, MVT::i64, true));
2511}
2512
2513/// When a match is complete, this method updates uses of interior chain results
2514/// to use the new results.
2515void SelectionDAGISel::UpdateChains(
2516 SDNode *NodeToMatch, SDValue InputChain,
2517 SmallVectorImpl<SDNode *> &ChainNodesMatched, bool isMorphNodeTo) {
2518 SmallVector<SDNode*, 4> NowDeadNodes;
2519
2520 // Now that all the normal results are replaced, we replace the chain and
2521 // glue results if present.
2522 if (!ChainNodesMatched.empty()) {
2523 assert(InputChain.getNode() &&
2524 "Matched input chains but didn't produce a chain");
2525 // Loop over all of the nodes we matched that produced a chain result.
2526 // Replace all the chain results with the final chain we ended up with.
2527 for (unsigned i = 0, e = ChainNodesMatched.size(); i != e; ++i) {
2528 SDNode *ChainNode = ChainNodesMatched[i];
2529 // If ChainNode is null, it's because we replaced it on a previous
2530 // iteration and we cleared it out of the map. Just skip it.
2531 if (!ChainNode)
2532 continue;
2533
2534 assert(ChainNode->getOpcode() != ISD::DELETED_NODE &&
2535 "Deleted node left in chain");
2536
2537 // Don't replace the results of the root node if we're doing a
2538 // MorphNodeTo.
2539 if (ChainNode == NodeToMatch && isMorphNodeTo)
2540 continue;
2541
2542 SDValue ChainVal = SDValue(ChainNode, ChainNode->getNumValues()-1);
2543 if (ChainVal.getValueType() == MVT::Glue)
2544 ChainVal = ChainVal.getValue(ChainVal->getNumValues()-2);
2545 assert(ChainVal.getValueType() == MVT::Other && "Not a chain?");
2547 *CurDAG, [&](SDNode *N, SDNode *E) {
2548 std::replace(ChainNodesMatched.begin(), ChainNodesMatched.end(), N,
2549 static_cast<SDNode *>(nullptr));
2550 });
2551 if (ChainNode->getOpcode() != ISD::TokenFactor)
2552 ReplaceUses(ChainVal, InputChain);
2553
2554 // If the node became dead and we haven't already seen it, delete it.
2555 if (ChainNode != NodeToMatch && ChainNode->use_empty() &&
2556 !llvm::is_contained(NowDeadNodes, ChainNode))
2557 NowDeadNodes.push_back(ChainNode);
2558 }
2559 }
2560
2561 if (!NowDeadNodes.empty())
2562 CurDAG->RemoveDeadNodes(NowDeadNodes);
2563
2564 LLVM_DEBUG(dbgs() << "ISEL: Match complete!\n");
2565}
2566
2567/// HandleMergeInputChains - This implements the OPC_EmitMergeInputChains
2568/// operation for when the pattern matched at least one node with a chains. The
2569/// input vector contains a list of all of the chained nodes that we match. We
2570/// must determine if this is a valid thing to cover (i.e. matching it won't
2571/// induce cycles in the DAG) and if so, creating a TokenFactor node. that will
2572/// be used as the input node chain for the generated nodes.
2573static SDValue
2575 SelectionDAG *CurDAG) {
2576
2579 SmallVector<SDValue, 3> InputChains;
2580 unsigned int Max = 8192;
2581
2582 // Quick exit on trivial merge.
2583 if (ChainNodesMatched.size() == 1)
2584 return ChainNodesMatched[0]->getOperand(0);
2585
2586 // Add chains that aren't already added (internal). Peek through
2587 // token factors.
2588 std::function<void(const SDValue)> AddChains = [&](const SDValue V) {
2589 if (V.getValueType() != MVT::Other)
2590 return;
2591 if (V->getOpcode() == ISD::EntryToken)
2592 return;
2593 if (!Visited.insert(V.getNode()).second)
2594 return;
2595 if (V->getOpcode() == ISD::TokenFactor) {
2596 for (const SDValue &Op : V->op_values())
2597 AddChains(Op);
2598 } else
2599 InputChains.push_back(V);
2600 };
2601
2602 for (auto *N : ChainNodesMatched) {
2603 Worklist.push_back(N);
2604 Visited.insert(N);
2605 }
2606
2607 while (!Worklist.empty())
2608 AddChains(Worklist.pop_back_val()->getOperand(0));
2609
2610 // Skip the search if there are no chain dependencies.
2611 if (InputChains.size() == 0)
2612 return CurDAG->getEntryNode();
2613
2614 // If one of these chains is a successor of input, we must have a
2615 // node that is both the predecessor and successor of the
2616 // to-be-merged nodes. Fail.
2617 Visited.clear();
2618 for (SDValue V : InputChains)
2619 Worklist.push_back(V.getNode());
2620
2621 for (auto *N : ChainNodesMatched)
2622 if (SDNode::hasPredecessorHelper(N, Visited, Worklist, Max, true))
2623 return SDValue();
2624
2625 // Return merged chain.
2626 if (InputChains.size() == 1)
2627 return InputChains[0];
2628 return CurDAG->getNode(ISD::TokenFactor, SDLoc(ChainNodesMatched[0]),
2629 MVT::Other, InputChains);
2630}
2631
2632/// MorphNode - Handle morphing a node in place for the selector.
2633SDNode *SelectionDAGISel::
2634MorphNode(SDNode *Node, unsigned TargetOpc, SDVTList VTList,
2635 ArrayRef<SDValue> Ops, unsigned EmitNodeInfo) {
2636 // It is possible we're using MorphNodeTo to replace a node with no
2637 // normal results with one that has a normal result (or we could be
2638 // adding a chain) and the input could have glue and chains as well.
2639 // In this case we need to shift the operands down.
2640 // FIXME: This is a horrible hack and broken in obscure cases, no worse
2641 // than the old isel though.
2642 int OldGlueResultNo = -1, OldChainResultNo = -1;
2643
2644 unsigned NTMNumResults = Node->getNumValues();
2645 if (Node->getValueType(NTMNumResults-1) == MVT::Glue) {
2646 OldGlueResultNo = NTMNumResults-1;
2647 if (NTMNumResults != 1 &&
2648 Node->getValueType(NTMNumResults-2) == MVT::Other)
2649 OldChainResultNo = NTMNumResults-2;
2650 } else if (Node->getValueType(NTMNumResults-1) == MVT::Other)
2651 OldChainResultNo = NTMNumResults-1;
2652
2653 // Call the underlying SelectionDAG routine to do the transmogrification. Note
2654 // that this deletes operands of the old node that become dead.
2655 SDNode *Res = CurDAG->MorphNodeTo(Node, ~TargetOpc, VTList, Ops);
2656
2657 // MorphNodeTo can operate in two ways: if an existing node with the
2658 // specified operands exists, it can just return it. Otherwise, it
2659 // updates the node in place to have the requested operands.
2660 if (Res == Node) {
2661 // If we updated the node in place, reset the node ID. To the isel,
2662 // this should be just like a newly allocated machine node.
2663 Res->setNodeId(-1);
2664 }
2665
2666 unsigned ResNumResults = Res->getNumValues();
2667 // Move the glue if needed.
2668 if ((EmitNodeInfo & OPFL_GlueOutput) && OldGlueResultNo != -1 &&
2669 static_cast<unsigned>(OldGlueResultNo) != ResNumResults - 1)
2670 ReplaceUses(SDValue(Node, OldGlueResultNo),
2671 SDValue(Res, ResNumResults - 1));
2672
2673 if ((EmitNodeInfo & OPFL_GlueOutput) != 0)
2674 --ResNumResults;
2675
2676 // Move the chain reference if needed.
2677 if ((EmitNodeInfo & OPFL_Chain) && OldChainResultNo != -1 &&
2678 static_cast<unsigned>(OldChainResultNo) != ResNumResults - 1)
2679 ReplaceUses(SDValue(Node, OldChainResultNo),
2680 SDValue(Res, ResNumResults - 1));
2681
2682 // Otherwise, no replacement happened because the node already exists. Replace
2683 // Uses of the old node with the new one.
2684 if (Res != Node) {
2685 ReplaceNode(Node, Res);
2686 } else {
2688 }
2689
2690 return Res;
2691}
2692
2693/// CheckSame - Implements OP_CheckSame.
2695CheckSame(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
2696 const SmallVectorImpl<std::pair<SDValue, SDNode *>> &RecordedNodes) {
2697 // Accept if it is exactly the same as a previously recorded node.
2698 unsigned RecNo = MatcherTable[MatcherIndex++];
2699 assert(RecNo < RecordedNodes.size() && "Invalid CheckSame");
2700 return N == RecordedNodes[RecNo].first;
2701}
2702
2703/// CheckChildSame - Implements OP_CheckChildXSame.
2705 const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
2706 const SmallVectorImpl<std::pair<SDValue, SDNode *>> &RecordedNodes,
2707 unsigned ChildNo) {
2708 if (ChildNo >= N.getNumOperands())
2709 return false; // Match fails if out of range child #.
2710 return ::CheckSame(MatcherTable, MatcherIndex, N.getOperand(ChildNo),
2711 RecordedNodes);
2712}
2713
2714/// CheckPatternPredicate - Implements OP_CheckPatternPredicate.
2716CheckPatternPredicate(unsigned Opcode, const unsigned char *MatcherTable,
2717 unsigned &MatcherIndex, const SelectionDAGISel &SDISel) {
2718 bool TwoBytePredNo =
2720 unsigned PredNo =
2721 TwoBytePredNo || Opcode == SelectionDAGISel::OPC_CheckPatternPredicate
2722 ? MatcherTable[MatcherIndex++]
2724 if (TwoBytePredNo)
2725 PredNo |= MatcherTable[MatcherIndex++] << 8;
2726 return SDISel.CheckPatternPredicate(PredNo);
2727}
2728
2729/// CheckNodePredicate - Implements OP_CheckNodePredicate.
2731CheckNodePredicate(unsigned Opcode, const unsigned char *MatcherTable,
2732 unsigned &MatcherIndex, const SelectionDAGISel &SDISel,
2733 SDNode *N) {
2734 unsigned PredNo = Opcode == SelectionDAGISel::OPC_CheckPredicate
2735 ? MatcherTable[MatcherIndex++]
2737 return SDISel.CheckNodePredicate(N, PredNo);
2738}
2739
2741CheckOpcode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
2742 SDNode *N) {
2743 uint16_t Opc = MatcherTable[MatcherIndex++];
2744 Opc |= static_cast<uint16_t>(MatcherTable[MatcherIndex++]) << 8;
2745 return N->getOpcode() == Opc;
2746}
2747
2749 SDValue N,
2750 const TargetLowering *TLI,
2751 const DataLayout &DL) {
2752 if (N.getValueType() == VT)
2753 return true;
2754
2755 // Handle the case when VT is iPTR.
2756 return VT == MVT::iPTR && N.getValueType() == TLI->getPointerTy(DL);
2757}
2758
2761 const DataLayout &DL, unsigned ChildNo) {
2762 if (ChildNo >= N.getNumOperands())
2763 return false; // Match fails if out of range child #.
2764 return ::CheckType(VT, N.getOperand(ChildNo), TLI, DL);
2765}
2766
2768CheckCondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
2769 SDValue N) {
2770 return cast<CondCodeSDNode>(N)->get() ==
2771 static_cast<ISD::CondCode>(MatcherTable[MatcherIndex++]);
2772}
2773
2775CheckChild2CondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
2776 SDValue N) {
2777 if (2 >= N.getNumOperands())
2778 return false;
2779 return ::CheckCondCode(MatcherTable, MatcherIndex, N.getOperand(2));
2780}
2781
2783CheckValueType(const unsigned char *MatcherTable, unsigned &MatcherIndex,
2784 SDValue N, const TargetLowering *TLI, const DataLayout &DL) {
2786 static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
2787 if (cast<VTSDNode>(N)->getVT() == VT)
2788 return true;
2789
2790 // Handle the case when VT is iPTR.
2791 return VT == MVT::iPTR && cast<VTSDNode>(N)->getVT() == TLI->getPointerTy(DL);
2792}
2793
2794// Bit 0 stores the sign of the immediate. The upper bits contain the magnitude
2795// shifted left by 1.
2797 if ((V & 1) == 0)
2798 return V >> 1;
2799 if (V != 1)
2800 return -(V >> 1);
2801 // There is no such thing as -0 with integers. "-0" really means MININT.
2802 return 1ULL << 63;
2803}
2804
2806CheckInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex,
2807 SDValue N) {
2808 int64_t Val = MatcherTable[MatcherIndex++];
2809 if (Val & 128)
2810 Val = GetVBR(Val, MatcherTable, MatcherIndex);
2811
2812 Val = decodeSignRotatedValue(Val);
2813
2814 ConstantSDNode *C = dyn_cast<ConstantSDNode>(N);
2815 return C && C->getAPIntValue().trySExtValue() == Val;
2816}
2817
2819CheckChildInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex,
2820 SDValue N, unsigned ChildNo) {
2821 if (ChildNo >= N.getNumOperands())
2822 return false; // Match fails if out of range child #.
2823 return ::CheckInteger(MatcherTable, MatcherIndex, N.getOperand(ChildNo));
2824}
2825
2827CheckAndImm(const unsigned char *MatcherTable, unsigned &MatcherIndex,
2828 SDValue N, const SelectionDAGISel &SDISel) {
2829 int64_t Val = MatcherTable[MatcherIndex++];
2830 if (Val & 128)
2831 Val = GetVBR(Val, MatcherTable, MatcherIndex);
2832
2833 if (N->getOpcode() != ISD::AND) return false;
2834
2835 ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1));
2836 return C && SDISel.CheckAndMask(N.getOperand(0), C, Val);
2837}
2838
2840CheckOrImm(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
2841 const SelectionDAGISel &SDISel) {
2842 int64_t Val = MatcherTable[MatcherIndex++];
2843 if (Val & 128)
2844 Val = GetVBR(Val, MatcherTable, MatcherIndex);
2845
2846 if (N->getOpcode() != ISD::OR) return false;
2847
2848 ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1));
2849 return C && SDISel.CheckOrMask(N.getOperand(0), C, Val);
2850}
2851
2852/// IsPredicateKnownToFail - If we know how and can do so without pushing a
2853/// scope, evaluate the current node. If the current predicate is known to
2854/// fail, set Result=true and return anything. If the current predicate is
2855/// known to pass, set Result=false and return the MatcherIndex to continue
2856/// with. If the current predicate is unknown, set Result=false and return the
2857/// MatcherIndex to continue with.
2858static unsigned IsPredicateKnownToFail(const unsigned char *Table,
2859 unsigned Index, SDValue N,
2860 bool &Result,
2861 const SelectionDAGISel &SDISel,
2862 SmallVectorImpl<std::pair<SDValue, SDNode*>> &RecordedNodes) {
2863 unsigned Opcode = Table[Index++];
2864 switch (Opcode) {
2865 default:
2866 Result = false;
2867 return Index-1; // Could not evaluate this predicate.
2869 Result = !::CheckSame(Table, Index, N, RecordedNodes);
2870 return Index;
2875 Result = !::CheckChildSame(Table, Index, N, RecordedNodes,
2877 return Index;
2888 Result = !::CheckPatternPredicate(Opcode, Table, Index, SDISel);
2889 return Index;
2899 Result = !::CheckNodePredicate(Opcode, Table, Index, SDISel, N.getNode());
2900 return Index;
2902 Result = !::CheckOpcode(Table, Index, N.getNode());
2903 return Index;
2908 switch (Opcode) {
2910 VT = MVT::i32;
2911 break;
2913 VT = MVT::i64;
2914 break;
2915 default:
2916 VT = static_cast<MVT::SimpleValueType>(Table[Index++]);
2917 break;
2918 }
2919 Result = !::CheckType(VT, N, SDISel.TLI, SDISel.CurDAG->getDataLayout());
2920 return Index;
2921 }
2923 unsigned Res = Table[Index++];
2924 Result = !::CheckType(static_cast<MVT::SimpleValueType>(Table[Index++]),
2925 N.getValue(Res), SDISel.TLI,
2926 SDISel.CurDAG->getDataLayout());
2927 return Index;
2928 }
2954 unsigned ChildNo;
2957 VT = MVT::i32;
2959 } else if (Opcode >= SelectionDAGISel::OPC_CheckChild0TypeI64 &&
2961 VT = MVT::i64;
2963 } else {
2964 VT = static_cast<MVT::SimpleValueType>(Table[Index++]);
2965 ChildNo = Opcode - SelectionDAGISel::OPC_CheckChild0Type;
2966 }
2967 Result = !::CheckChildType(VT, N, SDISel.TLI,
2968 SDISel.CurDAG->getDataLayout(), ChildNo);
2969 return Index;
2970 }
2972 Result = !::CheckCondCode(Table, Index, N);
2973 return Index;
2975 Result = !::CheckChild2CondCode(Table, Index, N);
2976 return Index;
2978 Result = !::CheckValueType(Table, Index, N, SDISel.TLI,
2979 SDISel.CurDAG->getDataLayout());
2980 return Index;
2982 Result = !::CheckInteger(Table, Index, N);
2983 return Index;
2989 Result = !::CheckChildInteger(Table, Index, N,
2991 return Index;
2993 Result = !::CheckAndImm(Table, Index, N, SDISel);
2994 return Index;
2996 Result = !::CheckOrImm(Table, Index, N, SDISel);
2997 return Index;
2998 }
2999}
3000
3001namespace {
3002
3003struct MatchScope {
3004 /// FailIndex - If this match fails, this is the index to continue with.
3005 unsigned FailIndex;
3006
3007 /// NodeStack - The node stack when the scope was formed.
3008 SmallVector<SDValue, 4> NodeStack;
3009
3010 /// NumRecordedNodes - The number of recorded nodes when the scope was formed.
3011 unsigned NumRecordedNodes;
3012
3013 /// NumMatchedMemRefs - The number of matched memref entries.
3014 unsigned NumMatchedMemRefs;
3015
3016 /// InputChain/InputGlue - The current chain/glue
3017 SDValue InputChain, InputGlue;
3018
3019 /// HasChainNodesMatched - True if the ChainNodesMatched list is non-empty.
3020 bool HasChainNodesMatched;
3021};
3022
3023/// \A DAG update listener to keep the matching state
3024/// (i.e. RecordedNodes and MatchScope) uptodate if the target is allowed to
3025/// change the DAG while matching. X86 addressing mode matcher is an example
3026/// for this.
3027class MatchStateUpdater : public SelectionDAG::DAGUpdateListener
3028{
3029 SDNode **NodeToMatch;
3031 SmallVectorImpl<MatchScope> &MatchScopes;
3032
3033public:
3034 MatchStateUpdater(SelectionDAG &DAG, SDNode **NodeToMatch,
3035 SmallVectorImpl<std::pair<SDValue, SDNode *>> &RN,
3037 : SelectionDAG::DAGUpdateListener(DAG), NodeToMatch(NodeToMatch),
3038 RecordedNodes(RN), MatchScopes(MS) {}
3039
3040 void NodeDeleted(SDNode *N, SDNode *E) override {
3041 // Some early-returns here to avoid the search if we deleted the node or
3042 // if the update comes from MorphNodeTo (MorphNodeTo is the last thing we
3043 // do, so it's unnecessary to update matching state at that point).
3044 // Neither of these can occur currently because we only install this
3045 // update listener during matching a complex patterns.
3046 if (!E || E->isMachineOpcode())
3047 return;
3048 // Check if NodeToMatch was updated.
3049 if (N == *NodeToMatch)
3050 *NodeToMatch = E;
3051 // Performing linear search here does not matter because we almost never
3052 // run this code. You'd have to have a CSE during complex pattern
3053 // matching.
3054 for (auto &I : RecordedNodes)
3055 if (I.first.getNode() == N)
3056 I.first.setNode(E);
3057
3058 for (auto &I : MatchScopes)
3059 for (auto &J : I.NodeStack)
3060 if (J.getNode() == N)
3061 J.setNode(E);
3062 }
3063};
3064
3065} // end anonymous namespace
3066
3068 const unsigned char *MatcherTable,
3069 unsigned TableSize) {
3070 // FIXME: Should these even be selected? Handle these cases in the caller?
3071 switch (NodeToMatch->getOpcode()) {
3072 default:
3073 break;
3074 case ISD::EntryToken: // These nodes remain the same.
3075 case ISD::BasicBlock:
3076 case ISD::Register:
3077 case ISD::RegisterMask:
3078 case ISD::HANDLENODE:
3079 case ISD::MDNODE_SDNODE:
3085 case ISD::MCSymbol:
3090 case ISD::TokenFactor:
3091 case ISD::CopyFromReg:
3092 case ISD::CopyToReg:
3093 case ISD::EH_LABEL:
3096 case ISD::LIFETIME_END:
3097 case ISD::PSEUDO_PROBE:
3098 NodeToMatch->setNodeId(-1); // Mark selected.
3099 return;
3100 case ISD::AssertSext:
3101 case ISD::AssertZext:
3102 case ISD::AssertAlign:
3103 ReplaceUses(SDValue(NodeToMatch, 0), NodeToMatch->getOperand(0));
3104 CurDAG->RemoveDeadNode(NodeToMatch);
3105 return;
3106 case ISD::INLINEASM:
3107 case ISD::INLINEASM_BR:
3108 Select_INLINEASM(NodeToMatch);
3109 return;
3110 case ISD::READ_REGISTER:
3111 Select_READ_REGISTER(NodeToMatch);
3112 return;
3114 Select_WRITE_REGISTER(NodeToMatch);
3115 return;
3116 case ISD::UNDEF:
3117 Select_UNDEF(NodeToMatch);
3118 return;
3119 case ISD::FREEZE:
3120 Select_FREEZE(NodeToMatch);
3121 return;
3122 case ISD::ARITH_FENCE:
3123 Select_ARITH_FENCE(NodeToMatch);
3124 return;
3125 case ISD::MEMBARRIER:
3126 Select_MEMBARRIER(NodeToMatch);
3127 return;
3128 case ISD::STACKMAP:
3129 Select_STACKMAP(NodeToMatch);
3130 return;
3131 case ISD::PATCHPOINT:
3132 Select_PATCHPOINT(NodeToMatch);
3133 return;
3135 Select_JUMP_TABLE_DEBUG_INFO(NodeToMatch);
3136 return;
3138 Select_CONVERGENCECTRL_ANCHOR(NodeToMatch);
3139 return;
3141 Select_CONVERGENCECTRL_ENTRY(NodeToMatch);
3142 return;
3144 Select_CONVERGENCECTRL_LOOP(NodeToMatch);
3145 return;
3146 }
3147
3148 assert(!NodeToMatch->isMachineOpcode() && "Node already selected!");
3149
3150 // Set up the node stack with NodeToMatch as the only node on the stack.
3151 SmallVector<SDValue, 8> NodeStack;
3152 SDValue N = SDValue(NodeToMatch, 0);
3153 NodeStack.push_back(N);
3154
3155 // MatchScopes - Scopes used when matching, if a match failure happens, this
3156 // indicates where to continue checking.
3157 SmallVector<MatchScope, 8> MatchScopes;
3158
3159 // RecordedNodes - This is the set of nodes that have been recorded by the
3160 // state machine. The second value is the parent of the node, or null if the
3161 // root is recorded.
3163
3164 // MatchedMemRefs - This is the set of MemRef's we've seen in the input
3165 // pattern.
3167
3168 // These are the current input chain and glue for use when generating nodes.
3169 // Various Emit operations change these. For example, emitting a copytoreg
3170 // uses and updates these.
3171 SDValue InputChain, InputGlue;
3172
3173 // ChainNodesMatched - If a pattern matches nodes that have input/output
3174 // chains, the OPC_EmitMergeInputChains operation is emitted which indicates
3175 // which ones they are. The result is captured into this list so that we can
3176 // update the chain results when the pattern is complete.
3177 SmallVector<SDNode*, 3> ChainNodesMatched;
3178
3179 LLVM_DEBUG(dbgs() << "ISEL: Starting pattern match\n");
3180
3181 // Determine where to start the interpreter. Normally we start at opcode #0,
3182 // but if the state machine starts with an OPC_SwitchOpcode, then we
3183 // accelerate the first lookup (which is guaranteed to be hot) with the
3184 // OpcodeOffset table.
3185 unsigned MatcherIndex = 0;
3186
3187 if (!OpcodeOffset.empty()) {
3188 // Already computed the OpcodeOffset table, just index into it.
3189 if (N.getOpcode() < OpcodeOffset.size())
3190 MatcherIndex = OpcodeOffset[N.getOpcode()];
3191 LLVM_DEBUG(dbgs() << " Initial Opcode index to " << MatcherIndex << "\n");
3192
3193 } else if (MatcherTable[0] == OPC_SwitchOpcode) {
3194 // Otherwise, the table isn't computed, but the state machine does start
3195 // with an OPC_SwitchOpcode instruction. Populate the table now, since this
3196 // is the first time we're selecting an instruction.
3197 unsigned Idx = 1;
3198 while (true) {
3199 // Get the size of this case.
3200 unsigned CaseSize = MatcherTable[Idx++];
3201 if (CaseSize & 128)
3202 CaseSize = GetVBR(CaseSize, MatcherTable, Idx);
3203 if (CaseSize == 0) break;
3204
3205 // Get the opcode, add the index to the table.
3206 uint16_t Opc = MatcherTable[Idx++];
3207 Opc |= static_cast<uint16_t>(MatcherTable[Idx++]) << 8;
3208 if (Opc >= OpcodeOffset.size())
3209 OpcodeOffset.resize((Opc+1)*2);
3210 OpcodeOffset[Opc] = Idx;
3211 Idx += CaseSize;
3212 }
3213
3214 // Okay, do the lookup for the first opcode.
3215 if (N.getOpcode() < OpcodeOffset.size())
3216 MatcherIndex = OpcodeOffset[N.getOpcode()];
3217 }
3218
3219 while (true) {
3220 assert(MatcherIndex < TableSize && "Invalid index");
3221#ifndef NDEBUG
3222 unsigned CurrentOpcodeIndex = MatcherIndex;
3223#endif
3224 BuiltinOpcodes Opcode =
3225 static_cast<BuiltinOpcodes>(MatcherTable[MatcherIndex++]);
3226 switch (Opcode) {
3227 case OPC_Scope: {
3228 // Okay, the semantics of this operation are that we should push a scope
3229 // then evaluate the first child. However, pushing a scope only to have
3230 // the first check fail (which then pops it) is inefficient. If we can
3231 // determine immediately that the first check (or first several) will
3232 // immediately fail, don't even bother pushing a scope for them.
3233 unsigned FailIndex;
3234
3235 while (true) {
3236 unsigned NumToSkip = MatcherTable[MatcherIndex++];
3237 if (NumToSkip & 128)
3238 NumToSkip = GetVBR(NumToSkip, MatcherTable, MatcherIndex);
3239 // Found the end of the scope with no match.
3240 if (NumToSkip == 0) {
3241 FailIndex = 0;
3242 break;
3243 }
3244
3245 FailIndex = MatcherIndex+NumToSkip;
3246
3247 unsigned MatcherIndexOfPredicate = MatcherIndex;
3248 (void)MatcherIndexOfPredicate; // silence warning.
3249
3250 // If we can't evaluate this predicate without pushing a scope (e.g. if
3251 // it is a 'MoveParent') or if the predicate succeeds on this node, we
3252 // push the scope and evaluate the full predicate chain.
3253 bool Result;
3254 MatcherIndex = IsPredicateKnownToFail(MatcherTable, MatcherIndex, N,
3255 Result, *this, RecordedNodes);
3256 if (!Result)
3257 break;
3258
3259 LLVM_DEBUG(
3260 dbgs() << " Skipped scope entry (due to false predicate) at "
3261 << "index " << MatcherIndexOfPredicate << ", continuing at "
3262 << FailIndex << "\n");
3263 ++NumDAGIselRetries;
3264
3265 // Otherwise, we know that this case of the Scope is guaranteed to fail,
3266 // move to the next case.
3267 MatcherIndex = FailIndex;
3268 }
3269
3270 // If the whole scope failed to match, bail.
3271 if (FailIndex == 0) break;
3272
3273 // Push a MatchScope which indicates where to go if the first child fails
3274 // to match.
3275 MatchScope NewEntry;
3276 NewEntry.FailIndex = FailIndex;
3277 NewEntry.NodeStack.append(NodeStack.begin(), NodeStack.end());
3278 NewEntry.NumRecordedNodes = RecordedNodes.size();
3279 NewEntry.NumMatchedMemRefs = MatchedMemRefs.size();
3280 NewEntry.InputChain = InputChain;
3281 NewEntry.InputGlue = InputGlue;
3282 NewEntry.HasChainNodesMatched = !ChainNodesMatched.empty();
3283 MatchScopes.push_back(NewEntry);
3284 continue;
3285 }
3286 case OPC_RecordNode: {
3287 // Remember this node, it may end up being an operand in the pattern.
3288 SDNode *Parent = nullptr;
3289 if (NodeStack.size() > 1)
3290 Parent = NodeStack[NodeStack.size()-2].getNode();
3291 RecordedNodes.push_back(std::make_pair(N, Parent));
3292 continue;
3293 }
3294
3299 unsigned ChildNo = Opcode-OPC_RecordChild0;
3300 if (ChildNo >= N.getNumOperands())
3301 break; // Match fails if out of range child #.
3302
3303 RecordedNodes.push_back(std::make_pair(N->getOperand(ChildNo),
3304 N.getNode()));
3305 continue;
3306 }
3307 case OPC_RecordMemRef:
3308 if (auto *MN = dyn_cast<MemSDNode>(N))
3309 MatchedMemRefs.push_back(MN->getMemOperand());
3310 else {
3311 LLVM_DEBUG(dbgs() << "Expected MemSDNode "; N->dump(CurDAG);
3312 dbgs() << '\n');
3313 }
3314
3315 continue;
3316
3318 // If the current node has an input glue, capture it in InputGlue.
3319 if (N->getNumOperands() != 0 &&
3320 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Glue)
3321 InputGlue = N->getOperand(N->getNumOperands()-1);
3322 continue;
3323
3324 case OPC_MoveChild: {
3325 unsigned ChildNo = MatcherTable[MatcherIndex++];
3326 if (ChildNo >= N.getNumOperands())
3327 break; // Match fails if out of range child #.
3328 N = N.getOperand(ChildNo);
3329 NodeStack.push_back(N);
3330 continue;
3331 }
3332
3333 case OPC_MoveChild0: case OPC_MoveChild1:
3334 case OPC_MoveChild2: case OPC_MoveChild3:
3335 case OPC_MoveChild4: case OPC_MoveChild5:
3336 case OPC_MoveChild6: case OPC_MoveChild7: {
3337 unsigned ChildNo = Opcode-OPC_MoveChild0;
3338 if (ChildNo >= N.getNumOperands())
3339 break; // Match fails if out of range child #.
3340 N = N.getOperand(ChildNo);
3341 NodeStack.push_back(N);
3342 continue;
3343 }
3344
3345 case OPC_MoveSibling:
3346 case OPC_MoveSibling0:
3347 case OPC_MoveSibling1:
3348 case OPC_MoveSibling2:
3349 case OPC_MoveSibling3:
3350 case OPC_MoveSibling4:
3351 case OPC_MoveSibling5:
3352 case OPC_MoveSibling6:
3353 case OPC_MoveSibling7: {
3354 // Pop the current node off the NodeStack.
3355 NodeStack.pop_back();
3356 assert(!NodeStack.empty() && "Node stack imbalance!");
3357 N = NodeStack.back();
3358
3359 unsigned SiblingNo = Opcode == OPC_MoveSibling
3360 ? MatcherTable[MatcherIndex++]
3361 : Opcode - OPC_MoveSibling0;
3362 if (SiblingNo >= N.getNumOperands())
3363 break; // Match fails if out of range sibling #.
3364 N = N.getOperand(SiblingNo);
3365 NodeStack.push_back(N);
3366 continue;
3367 }
3368 case OPC_MoveParent:
3369 // Pop the current node off the NodeStack.
3370 NodeStack.pop_back();
3371 assert(!NodeStack.empty() && "Node stack imbalance!");
3372 N = NodeStack.back();
3373 continue;
3374
3375 case OPC_CheckSame:
3376 if (!::CheckSame(MatcherTable, MatcherIndex, N, RecordedNodes)) break;
3377 continue;
3378
3381 if (!::CheckChildSame(MatcherTable, MatcherIndex, N, RecordedNodes,
3382 Opcode-OPC_CheckChild0Same))
3383 break;
3384 continue;
3385
3396 if (!::CheckPatternPredicate(Opcode, MatcherTable, MatcherIndex, *this))
3397 break;
3398 continue;
3407 case OPC_CheckPredicate:
3408 if (!::CheckNodePredicate(Opcode, MatcherTable, MatcherIndex, *this,
3409 N.getNode()))
3410 break;
3411 continue;
3413 unsigned OpNum = MatcherTable[MatcherIndex++];
3415
3416 for (unsigned i = 0; i < OpNum; ++i)
3417 Operands.push_back(RecordedNodes[MatcherTable[MatcherIndex++]].first);
3418
3419 unsigned PredNo = MatcherTable[MatcherIndex++];
3420 if (!CheckNodePredicateWithOperands(N.getNode(), PredNo, Operands))
3421 break;
3422 continue;
3423 }
3432 case OPC_CheckComplexPat7: {
3433 unsigned CPNum = Opcode == OPC_CheckComplexPat
3434 ? MatcherTable[MatcherIndex++]
3435 : Opcode - OPC_CheckComplexPat0;
3436 unsigned RecNo = MatcherTable[MatcherIndex++];
3437 assert(RecNo < RecordedNodes.size() && "Invalid CheckComplexPat");
3438
3439 // If target can modify DAG during matching, keep the matching state
3440 // consistent.
3441 std::unique_ptr<MatchStateUpdater> MSU;
3443 MSU.reset(new MatchStateUpdater(*CurDAG, &NodeToMatch, RecordedNodes,
3444 MatchScopes));
3445
3446 if (!CheckComplexPattern(NodeToMatch, RecordedNodes[RecNo].second,
3447 RecordedNodes[RecNo].first, CPNum,
3448 RecordedNodes))
3449 break;
3450 continue;
3451 }
3452 case OPC_CheckOpcode:
3453 if (!::CheckOpcode(MatcherTable, MatcherIndex, N.getNode())) break;
3454 continue;
3455
3456 case OPC_CheckType:
3457 case OPC_CheckTypeI32:
3458 case OPC_CheckTypeI64:
3460 switch (Opcode) {
3461 case OPC_CheckTypeI32:
3462 VT = MVT::i32;
3463 break;
3464 case OPC_CheckTypeI64:
3465 VT = MVT::i64;
3466 break;
3467 default:
3468 VT = static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
3469 break;
3470 }
3471 if (!::CheckType(VT, N, TLI, CurDAG->getDataLayout()))
3472 break;
3473 continue;
3474
3475 case OPC_CheckTypeRes: {
3476 unsigned Res = MatcherTable[MatcherIndex++];
3477 if (!::CheckType(
3478 static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]),
3479 N.getValue(Res), TLI, CurDAG->getDataLayout()))
3480 break;
3481 continue;
3482 }
3483
3484 case OPC_SwitchOpcode: {
3485 unsigned CurNodeOpcode = N.getOpcode();
3486 unsigned SwitchStart = MatcherIndex-1; (void)SwitchStart;
3487 unsigned CaseSize;
3488 while (true) {
3489 // Get the size of this case.
3490 CaseSize = MatcherTable[MatcherIndex++];
3491 if (CaseSize & 128)
3492 CaseSize = GetVBR(CaseSize, MatcherTable, MatcherIndex);
3493 if (CaseSize == 0) break;
3494
3495 uint16_t Opc = MatcherTable[MatcherIndex++];
3496 Opc |= static_cast<uint16_t>(MatcherTable[MatcherIndex++]) << 8;
3497
3498 // If the opcode matches, then we will execute this case.
3499 if (CurNodeOpcode == Opc)
3500 break;
3501
3502 // Otherwise, skip over this case.
3503 MatcherIndex += CaseSize;
3504 }
3505
3506 // If no cases matched, bail out.
3507 if (CaseSize == 0) break;
3508
3509 // Otherwise, execute the case we found.
3510 LLVM_DEBUG(dbgs() << " OpcodeSwitch from " << SwitchStart << " to "
3511 << MatcherIndex << "\n");
3512 continue;
3513 }
3514
3515 case OPC_SwitchType: {
3516 MVT CurNodeVT = N.getSimpleValueType();
3517 unsigned SwitchStart = MatcherIndex-1; (void)SwitchStart;
3518 unsigned CaseSize;
3519 while (true) {
3520 // Get the size of this case.
3521 CaseSize = MatcherTable[MatcherIndex++];
3522 if (CaseSize & 128)
3523 CaseSize = GetVBR(CaseSize, MatcherTable, MatcherIndex);
3524 if (CaseSize == 0) break;
3525
3526 MVT CaseVT =
3527 static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
3528 if (CaseVT == MVT::iPTR)
3529 CaseVT = TLI->getPointerTy(CurDAG->getDataLayout());
3530
3531 // If the VT matches, then we will execute this case.
3532 if (CurNodeVT == CaseVT)
3533 break;
3534
3535 // Otherwise, skip over this case.
3536 MatcherIndex += CaseSize;
3537 }
3538
3539 // If no cases matched, bail out.
3540 if (CaseSize == 0) break;
3541
3542 // Otherwise, execute the case we found.
3543 LLVM_DEBUG(dbgs() << " TypeSwitch[" << CurNodeVT
3544 << "] from " << SwitchStart << " to " << MatcherIndex
3545 << '\n');
3546 continue;
3547 }
3573 unsigned ChildNo;
3576 VT = MVT::i32;
3578 } else if (Opcode >= SelectionDAGISel::OPC_CheckChild0TypeI64 &&
3580 VT = MVT::i64;
3582 } else {
3583 VT = static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
3584 ChildNo = Opcode - SelectionDAGISel::OPC_CheckChild0Type;
3585 }
3586 if (!::CheckChildType(VT, N, TLI, CurDAG->getDataLayout(), ChildNo))
3587 break;
3588 continue;
3589 }
3590 case OPC_CheckCondCode:
3591 if (!::CheckCondCode(MatcherTable, MatcherIndex, N)) break;
3592 continue;
3594 if (!::CheckChild2CondCode(MatcherTable, MatcherIndex, N)) break;
3595 continue;
3596 case OPC_CheckValueType:
3597 if (!::CheckValueType(MatcherTable, MatcherIndex, N, TLI,
3599 break;
3600 continue;
3601 case OPC_CheckInteger:
3602 if (!::CheckInteger(MatcherTable, MatcherIndex, N)) break;
3603 continue;
3607 if (!::CheckChildInteger(MatcherTable, MatcherIndex, N,
3608 Opcode-OPC_CheckChild0Integer)) break;
3609 continue;
3610 case OPC_CheckAndImm:
3611 if (!::CheckAndImm(MatcherTable, MatcherIndex, N, *this)) break;
3612 continue;
3613 case OPC_CheckOrImm:
3614 if (!::CheckOrImm(MatcherTable, MatcherIndex, N, *this)) break;
3615 continue;
3617 if (!ISD::isConstantSplatVectorAllOnes(N.getNode()))
3618 break;
3619 continue;
3621 if (!ISD::isConstantSplatVectorAllZeros(N.getNode()))
3622 break;
3623 continue;
3624
3626 assert(NodeStack.size() != 1 && "No parent node");
3627 // Verify that all intermediate nodes between the root and this one have
3628 // a single use (ignoring chains, which are handled in UpdateChains).
3629 bool HasMultipleUses = false;
3630 for (unsigned i = 1, e = NodeStack.size()-1; i != e; ++i) {
3631 unsigned NNonChainUses = 0;
3632 SDNode *NS = NodeStack[i].getNode();
3633 for (auto UI = NS->use_begin(), UE = NS->use_end(); UI != UE; ++UI)
3634 if (UI.getUse().getValueType() != MVT::Other)
3635 if (++NNonChainUses > 1) {
3636 HasMultipleUses = true;
3637 break;
3638 }
3639 if (HasMultipleUses) break;
3640 }
3641 if (HasMultipleUses) break;
3642
3643 // Check to see that the target thinks this is profitable to fold and that
3644 // we can fold it without inducing cycles in the graph.
3645 if (!IsProfitableToFold(N, NodeStack[NodeStack.size()-2].getNode(),
3646 NodeToMatch) ||
3647 !IsLegalToFold(N, NodeStack[NodeStack.size()-2].getNode(),
3648 NodeToMatch, OptLevel,
3649 true/*We validate our own chains*/))
3650 break;
3651
3652 continue;
3653 }
3654 case OPC_EmitInteger:
3655 case OPC_EmitInteger8:
3656 case OPC_EmitInteger16:
3657 case OPC_EmitInteger32:
3658 case OPC_EmitInteger64:
3662 switch (Opcode) {
3663 case OPC_EmitInteger8:
3664 VT = MVT::i8;
3665 break;
3666 case OPC_EmitInteger16:
3667 VT = MVT::i16;
3668 break;
3669 case OPC_EmitInteger32:
3671 VT = MVT::i32;
3672 break;
3673 case OPC_EmitInteger64:
3674 VT = MVT::i64;
3675 break;
3676 default:
3677 VT = static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
3678 break;
3679 }
3680 int64_t Val = MatcherTable[MatcherIndex++];
3681 if (Val & 128)
3682 Val = GetVBR(Val, MatcherTable, MatcherIndex);
3683 if (Opcode >= OPC_EmitInteger && Opcode <= OPC_EmitInteger64)
3684 Val = decodeSignRotatedValue(Val);
3685 RecordedNodes.push_back(std::pair<SDValue, SDNode *>(
3686 CurDAG->getTargetConstant(Val, SDLoc(NodeToMatch), VT), nullptr));
3687 continue;
3688 }
3689 case OPC_EmitRegister:
3691 case OPC_EmitRegisterI64: {
3693 switch (Opcode) {
3695 VT = MVT::i32;
3696 break;
3698 VT = MVT::i64;
3699 break;
3700 default:
3701 VT = static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
3702 break;
3703 }
3704 unsigned RegNo = MatcherTable[MatcherIndex++];
3705 RecordedNodes.push_back(std::pair<SDValue, SDNode *>(
3706 CurDAG->getRegister(RegNo, VT), nullptr));
3707 continue;
3708 }
3709 case OPC_EmitRegister2: {
3710 // For targets w/ more than 256 register names, the register enum
3711 // values are stored in two bytes in the matcher table (just like
3712 // opcodes).
3714 static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
3715 unsigned RegNo = MatcherTable[MatcherIndex++];
3716 RegNo |= MatcherTable[MatcherIndex++] << 8;
3717 RecordedNodes.push_back(std::pair<SDValue, SDNode*>(
3718 CurDAG->getRegister(RegNo, VT), nullptr));
3719 continue;
3720 }
3721
3731 // Convert from IMM/FPIMM to target version.
3732 unsigned RecNo = Opcode == OPC_EmitConvertToTarget
3733 ? MatcherTable[MatcherIndex++]
3734 : Opcode - OPC_EmitConvertToTarget0;
3735 assert(RecNo < RecordedNodes.size() && "Invalid EmitConvertToTarget");
3736 SDValue Imm = RecordedNodes[RecNo].first;
3737
3738 if (Imm->getOpcode() == ISD::Constant) {
3739 const ConstantInt *Val=cast<ConstantSDNode>(Imm)->getConstantIntValue();
3740 Imm = CurDAG->getTargetConstant(*Val, SDLoc(NodeToMatch),
3741 Imm.getValueType());
3742 } else if (Imm->getOpcode() == ISD::ConstantFP) {
3743 const ConstantFP *Val=cast<ConstantFPSDNode>(Imm)->getConstantFPValue();
3744 Imm = CurDAG->getTargetConstantFP(*Val, SDLoc(NodeToMatch),
3745 Imm.getValueType());
3746 }
3747
3748 RecordedNodes.push_back(std::make_pair(Imm, RecordedNodes[RecNo].second));
3749 continue;
3750 }
3751
3752 case OPC_EmitMergeInputChains1_0: // OPC_EmitMergeInputChains, 1, 0
3753 case OPC_EmitMergeInputChains1_1: // OPC_EmitMergeInputChains, 1, 1
3754 case OPC_EmitMergeInputChains1_2: { // OPC_EmitMergeInputChains, 1, 2
3755 // These are space-optimized forms of OPC_EmitMergeInputChains.
3756 assert(!InputChain.getNode() &&
3757 "EmitMergeInputChains should be the first chain producing node");
3758 assert(ChainNodesMatched.empty() &&
3759 "Should only have one EmitMergeInputChains per match");
3760
3761 // Read all of the chained nodes.
3762 unsigned RecNo = Opcode - OPC_EmitMergeInputChains1_0;
3763 assert(RecNo < RecordedNodes.size() && "Invalid EmitMergeInputChains");
3764 ChainNodesMatched.push_back(RecordedNodes[RecNo].first.getNode());
3765
3766 // If the chained node is not the root, we can't fold it if it has
3767 // multiple uses.
3768 // FIXME: What if other value results of the node have uses not matched
3769 // by this pattern?
3770 if (ChainNodesMatched.back() != NodeToMatch &&
3771 !RecordedNodes[RecNo].first.hasOneUse()) {
3772 ChainNodesMatched.clear();
3773 break;
3774 }
3775
3776 // Merge the input chains if they are not intra-pattern references.
3777 InputChain = HandleMergeInputChains(ChainNodesMatched, CurDAG);
3778
3779 if (!InputChain.getNode())
3780 break; // Failed to merge.
3781 continue;
3782 }
3783
3785 assert(!InputChain.getNode() &&
3786 "EmitMergeInputChains should be the first chain producing node");
3787 // This node gets a list of nodes we matched in the input that have
3788 // chains. We want to token factor all of the input chains to these nodes
3789 // together. However, if any of the input chains is actually one of the
3790 // nodes matched in this pattern, then we have an intra-match reference.
3791 // Ignore these because the newly token factored chain should not refer to
3792 // the old nodes.
3793 unsigned NumChains = MatcherTable[MatcherIndex++];
3794 assert(NumChains != 0 && "Can't TF zero chains");
3795
3796 assert(ChainNodesMatched.empty() &&
3797 "Should only have one EmitMergeInputChains per match");
3798
3799 // Read all of the chained nodes.
3800 for (unsigned i = 0; i != NumChains; ++i) {
3801 unsigned RecNo = MatcherTable[MatcherIndex++];
3802 assert(RecNo < RecordedNodes.size() && "Invalid EmitMergeInputChains");
3803 ChainNodesMatched.push_back(RecordedNodes[RecNo].first.getNode());
3804
3805 // If the chained node is not the root, we can't fold it if it has
3806 // multiple uses.
3807 // FIXME: What if other value results of the node have uses not matched
3808 // by this pattern?
3809 if (ChainNodesMatched.back() != NodeToMatch &&
3810 !RecordedNodes[RecNo].first.hasOneUse()) {
3811 ChainNodesMatched.clear();
3812 break;
3813 }
3814 }
3815
3816 // If the inner loop broke out, the match fails.
3817 if (ChainNodesMatched.empty())
3818 break;
3819
3820 // Merge the input chains if they are not intra-pattern references.
3821 InputChain = HandleMergeInputChains(ChainNodesMatched, CurDAG);
3822
3823 if (!InputChain.getNode())
3824 break; // Failed to merge.
3825
3826 continue;
3827 }
3828
3829 case OPC_EmitCopyToReg:
3830 case OPC_EmitCopyToReg0:
3831 case OPC_EmitCopyToReg1:
3832 case OPC_EmitCopyToReg2:
3833 case OPC_EmitCopyToReg3:
3834 case OPC_EmitCopyToReg4:
3835 case OPC_EmitCopyToReg5:
3836 case OPC_EmitCopyToReg6:
3837 case OPC_EmitCopyToReg7:
3839 unsigned RecNo =
3840 Opcode >= OPC_EmitCopyToReg0 && Opcode <= OPC_EmitCopyToReg7
3841 ? Opcode - OPC_EmitCopyToReg0
3842 : MatcherTable[MatcherIndex++];
3843 assert(RecNo < RecordedNodes.size() && "Invalid EmitCopyToReg");
3844 unsigned DestPhysReg = MatcherTable[MatcherIndex++];
3845 if (Opcode == OPC_EmitCopyToRegTwoByte)
3846 DestPhysReg |= MatcherTable[MatcherIndex++] << 8;
3847
3848 if (!InputChain.getNode())
3849 InputChain = CurDAG->getEntryNode();
3850
3851 InputChain = CurDAG->getCopyToReg(InputChain, SDLoc(NodeToMatch),
3852 DestPhysReg, RecordedNodes[RecNo].first,
3853 InputGlue);
3854
3855 InputGlue = InputChain.getValue(1);
3856 continue;
3857 }
3858
3859 case OPC_EmitNodeXForm: {
3860 unsigned XFormNo = MatcherTable[MatcherIndex++];
3861 unsigned RecNo = MatcherTable[MatcherIndex++];
3862 assert(RecNo < RecordedNodes.size() && "Invalid EmitNodeXForm");
3863 SDValue Res = RunSDNodeXForm(RecordedNodes[RecNo].first, XFormNo);
3864 RecordedNodes.push_back(std::pair<SDValue,SDNode*>(Res, nullptr));
3865 continue;
3866 }
3867 case OPC_Coverage: {
3868 // This is emitted right before MorphNode/EmitNode.
3869 // So it should be safe to assume that this node has been selected
3870 unsigned index = MatcherTable[MatcherIndex++];
3871 index |= (MatcherTable[MatcherIndex++] << 8);
3872 dbgs() << "COVERED: " << getPatternForIndex(index) << "\n";
3873 dbgs() << "INCLUDED: " << getIncludePathForIndex(index) << "\n";
3874 continue;
3875 }
3876
3877 case OPC_EmitNode:
3878 case OPC_EmitNode0:
3879 case OPC_EmitNode1:
3880 case OPC_EmitNode2:
3881 case OPC_EmitNode0None:
3882 case OPC_EmitNode1None:
3883 case OPC_EmitNode2None:
3884 case OPC_EmitNode0Chain:
3885 case OPC_EmitNode1Chain:
3886 case OPC_EmitNode2Chain:
3887 case OPC_MorphNodeTo:
3888 case OPC_MorphNodeTo0:
3889 case OPC_MorphNodeTo1:
3890 case OPC_MorphNodeTo2:
3903 uint16_t TargetOpc = MatcherTable[MatcherIndex++];
3904 TargetOpc |= static_cast<uint16_t>(MatcherTable[MatcherIndex++]) << 8;
3905 unsigned EmitNodeInfo;
3906 if (Opcode >= OPC_EmitNode0None && Opcode <= OPC_EmitNode2Chain) {
3907 if (Opcode >= OPC_EmitNode0Chain && Opcode <= OPC_EmitNode2Chain)
3908 EmitNodeInfo = OPFL_Chain;
3909 else
3910 EmitNodeInfo = OPFL_None;
3911 } else if (Opcode >= OPC_MorphNodeTo0None &&
3912 Opcode <= OPC_MorphNodeTo2GlueOutput) {
3913 if (Opcode >= OPC_MorphNodeTo0Chain && Opcode <= OPC_MorphNodeTo2Chain)
3914 EmitNodeInfo = OPFL_Chain;
3915 else if (Opcode >= OPC_MorphNodeTo0GlueInput &&
3916 Opcode <= OPC_MorphNodeTo2GlueInput)
3917 EmitNodeInfo = OPFL_GlueInput;
3918 else if (Opcode >= OPC_MorphNodeTo0GlueOutput &&
3920 EmitNodeInfo = OPFL_GlueOutput;
3921 else
3922 EmitNodeInfo = OPFL_None;
3923 } else
3924 EmitNodeInfo = MatcherTable[MatcherIndex++];
3925 // Get the result VT list.
3926 unsigned NumVTs;
3927 // If this is one of the compressed forms, get the number of VTs based
3928 // on the Opcode. Otherwise read the next byte from the table.
3929 if (Opcode >= OPC_MorphNodeTo0 && Opcode <= OPC_MorphNodeTo2)
3930 NumVTs = Opcode - OPC_MorphNodeTo0;
3931 else if (Opcode >= OPC_MorphNodeTo0None && Opcode <= OPC_MorphNodeTo2None)
3932 NumVTs = Opcode - OPC_MorphNodeTo0None;
3933 else if (Opcode >= OPC_MorphNodeTo0Chain &&
3934 Opcode <= OPC_MorphNodeTo2Chain)
3935 NumVTs = Opcode - OPC_MorphNodeTo0Chain;
3936 else if (Opcode >= OPC_MorphNodeTo0GlueInput &&
3937 Opcode <= OPC_MorphNodeTo2GlueInput)
3938 NumVTs = Opcode - OPC_MorphNodeTo0GlueInput;
3939 else if (Opcode >= OPC_MorphNodeTo0GlueOutput &&
3941 NumVTs = Opcode - OPC_MorphNodeTo0GlueOutput;
3942 else if (Opcode >= OPC_EmitNode0 && Opcode <= OPC_EmitNode2)
3943 NumVTs = Opcode - OPC_EmitNode0;
3944 else if (Opcode >= OPC_EmitNode0None && Opcode <= OPC_EmitNode2None)
3945 NumVTs = Opcode - OPC_EmitNode0None;
3946 else if (Opcode >= OPC_EmitNode0Chain && Opcode <= OPC_EmitNode2Chain)
3947 NumVTs = Opcode - OPC_EmitNode0Chain;
3948 else
3949 NumVTs = MatcherTable[MatcherIndex++];
3951 for (unsigned i = 0; i != NumVTs; ++i) {
3953 static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
3954 if (VT == MVT::iPTR)
3955 VT = TLI->getPointerTy(CurDAG->getDataLayout()).SimpleTy;
3956 VTs.push_back(VT);
3957 }
3958
3959 if (EmitNodeInfo & OPFL_Chain)
3960 VTs.push_back(MVT::Other);
3961 if (EmitNodeInfo & OPFL_GlueOutput)
3962 VTs.push_back(MVT::Glue);
3963
3964 // This is hot code, so optimize the two most common cases of 1 and 2
3965 // results.
3966 SDVTList VTList;
3967 if (VTs.size() == 1)
3968 VTList = CurDAG->getVTList(VTs[0]);
3969 else if (VTs.size() == 2)
3970 VTList = CurDAG->getVTList(VTs[0], VTs[1]);
3971 else
3972 VTList = CurDAG->getVTList(VTs);
3973
3974 // Get the operand list.
3975 unsigned NumOps = MatcherTable[MatcherIndex++];
3977 for (unsigned i = 0; i != NumOps; ++i) {
3978 unsigned RecNo = MatcherTable[MatcherIndex++];
3979 if (RecNo & 128)
3980 RecNo = GetVBR(RecNo, MatcherTable, MatcherIndex);
3981
3982 assert(RecNo < RecordedNodes.size() && "Invalid EmitNode");
3983 Ops.push_back(RecordedNodes[RecNo].first);
3984 }
3985
3986 // If there are variadic operands to add, handle them now.
3987 if (EmitNodeInfo & OPFL_VariadicInfo) {
3988 // Determine the start index to copy from.
3989 unsigned FirstOpToCopy = getNumFixedFromVariadicInfo(EmitNodeInfo);
3990 FirstOpToCopy += (EmitNodeInfo & OPFL_Chain) ? 1 : 0;
3991 assert(NodeToMatch->getNumOperands() >= FirstOpToCopy &&
3992 "Invalid variadic node");
3993 // Copy all of the variadic operands, not including a potential glue
3994 // input.
3995 for (unsigned i = FirstOpToCopy, e = NodeToMatch->getNumOperands();
3996 i != e; ++i) {
3997 SDValue V = NodeToMatch->getOperand(i);
3998 if (V.getValueType() == MVT::Glue) break;
3999 Ops.push_back(V);
4000 }
4001 }
4002
4003 // If this has chain/glue inputs, add them.
4004 if (EmitNodeInfo & OPFL_Chain)
4005 Ops.push_back(InputChain);
4006 if ((EmitNodeInfo & OPFL_GlueInput) && InputGlue.getNode() != nullptr)
4007 Ops.push_back(InputGlue);
4008
4009 // Check whether any matched node could raise an FP exception. Since all
4010 // such nodes must have a chain, it suffices to check ChainNodesMatched.
4011 // We need to perform this check before potentially modifying one of the
4012 // nodes via MorphNode.
4013 bool MayRaiseFPException =
4014 llvm::any_of(ChainNodesMatched, [this](SDNode *N) {
4015 return mayRaiseFPException(N) && !N->getFlags().hasNoFPExcept();
4016 });
4017
4018 // Create the node.
4019 MachineSDNode *Res = nullptr;
4020 bool IsMorphNodeTo =
4021 Opcode == OPC_MorphNodeTo ||
4022 (Opcode >= OPC_MorphNodeTo0 && Opcode <= OPC_MorphNodeTo2GlueOutput);
4023 if (!IsMorphNodeTo) {
4024 // If this is a normal EmitNode command, just create the new node and
4025 // add the results to the RecordedNodes list.
4026 Res = CurDAG->getMachineNode(TargetOpc, SDLoc(NodeToMatch),
4027 VTList, Ops);
4028
4029 // Add all the non-glue/non-chain results to the RecordedNodes list.
4030 for (unsigned i = 0, e = VTs.size(); i != e; ++i) {
4031 if (VTs[i] == MVT::Other || VTs[i] == MVT::Glue) break;
4032 RecordedNodes.push_back(std::pair<SDValue,SDNode*>(SDValue(Res, i),
4033 nullptr));
4034 }
4035 } else {
4036 assert(NodeToMatch->getOpcode() != ISD::DELETED_NODE &&
4037 "NodeToMatch was removed partway through selection");
4039 SDNode *E) {
4041 auto &Chain = ChainNodesMatched;
4042 assert((!E || !is_contained(Chain, N)) &&
4043 "Chain node replaced during MorphNode");
4044 llvm::erase(Chain, N);
4045 });
4046 Res = cast<MachineSDNode>(MorphNode(NodeToMatch, TargetOpc, VTList,
4047 Ops, EmitNodeInfo));
4048 }
4049
4050 // Set the NoFPExcept flag when no original matched node could
4051 // raise an FP exception, but the new node potentially might.
4052 if (!MayRaiseFPException && mayRaiseFPException(Res)) {
4053 SDNodeFlags Flags = Res->getFlags();
4054 Flags.setNoFPExcept(true);
4055 Res->setFlags(Flags);
4056 }
4057
4058 // If the node had chain/glue results, update our notion of the current
4059 // chain and glue.
4060 if (EmitNodeInfo & OPFL_GlueOutput) {
4061 InputGlue = SDValue(Res, VTs.size()-1);
4062 if (EmitNodeInfo & OPFL_Chain)
4063 InputChain = SDValue(Res, VTs.size()-2);
4064 } else if (EmitNodeInfo & OPFL_Chain)
4065 InputChain = SDValue(Res, VTs.size()-1);
4066
4067 // If the OPFL_MemRefs glue is set on this node, slap all of the
4068 // accumulated memrefs onto it.
4069 //
4070 // FIXME: This is vastly incorrect for patterns with multiple outputs
4071 // instructions that access memory and for ComplexPatterns that match
4072 // loads.
4073 if (EmitNodeInfo & OPFL_MemRefs) {
4074 // Only attach load or store memory operands if the generated
4075 // instruction may load or store.
4076 const MCInstrDesc &MCID = TII->get(TargetOpc);
4077 bool mayLoad = MCID.mayLoad();
4078 bool mayStore = MCID.mayStore();
4079
4080 // We expect to have relatively few of these so just filter them into a
4081 // temporary buffer so that we can easily add them to the instruction.
4083 for (MachineMemOperand *MMO : MatchedMemRefs) {
4084 if (MMO->isLoad()) {
4085 if (mayLoad)
4086 FilteredMemRefs.push_back(MMO);
4087 } else if (MMO->isStore()) {
4088 if (mayStore)
4089 FilteredMemRefs.push_back(MMO);
4090 } else {
4091 FilteredMemRefs.push_back(MMO);
4092 }
4093 }
4094
4095 CurDAG->setNodeMemRefs(Res, FilteredMemRefs);
4096 }
4097
4098 LLVM_DEBUG(if (!MatchedMemRefs.empty() && Res->memoperands_empty()) dbgs()
4099 << " Dropping mem operands\n";
4100 dbgs() << " " << (IsMorphNodeTo ? "Morphed" : "Created")
4101 << " node: ";
4102 Res->dump(CurDAG););
4103
4104 // If this was a MorphNodeTo then we're completely done!
4105 if (IsMorphNodeTo) {
4106 // Update chain uses.
4107 UpdateChains(Res, InputChain, ChainNodesMatched, true);
4108 return;
4109 }
4110 continue;
4111 }
4112
4113 case OPC_CompleteMatch: {
4114 // The match has been completed, and any new nodes (if any) have been
4115 // created. Patch up references to the matched dag to use the newly
4116 // created nodes.
4117 unsigned NumResults = MatcherTable[MatcherIndex++];
4118
4119 for (unsigned i = 0; i != NumResults; ++i) {
4120 unsigned ResSlot = MatcherTable[MatcherIndex++];
4121 if (ResSlot & 128)
4122 ResSlot = GetVBR(ResSlot, MatcherTable, MatcherIndex);
4123
4124 assert(ResSlot < RecordedNodes.size() && "Invalid CompleteMatch");
4125 SDValue Res = RecordedNodes[ResSlot].first;
4126
4127 assert(i < NodeToMatch->getNumValues() &&
4128 NodeToMatch->getValueType(i) != MVT::Other &&
4129 NodeToMatch->getValueType(i) != MVT::Glue &&
4130 "Invalid number of results to complete!");
4131 assert((NodeToMatch->getValueType(i) == Res.getValueType() ||
4132 NodeToMatch->getValueType(i) == MVT::iPTR ||
4133 Res.getValueType() == MVT::iPTR ||
4134 NodeToMatch->getValueType(i).getSizeInBits() ==
4135 Res.getValueSizeInBits()) &&
4136 "invalid replacement");
4137 ReplaceUses(SDValue(NodeToMatch, i), Res);
4138 }
4139
4140 // Update chain uses.
4141 UpdateChains(NodeToMatch, InputChain, ChainNodesMatched, false);
4142
4143 // If the root node defines glue, we need to update it to the glue result.
4144 // TODO: This never happens in our tests and I think it can be removed /
4145 // replaced with an assert, but if we do it this the way the change is
4146 // NFC.
4147 if (NodeToMatch->getValueType(NodeToMatch->getNumValues() - 1) ==
4148 MVT::Glue &&
4149 InputGlue.getNode())
4150 ReplaceUses(SDValue(NodeToMatch, NodeToMatch->getNumValues() - 1),
4151 InputGlue);
4152
4153 assert(NodeToMatch->use_empty() &&
4154 "Didn't replace all uses of the node?");
4155 CurDAG->RemoveDeadNode(NodeToMatch);
4156
4157 return;
4158 }
4159 }
4160
4161 // If the code reached this point, then the match failed. See if there is
4162 // another child to try in the current 'Scope', otherwise pop it until we
4163 // find a case to check.
4164 LLVM_DEBUG(dbgs() << " Match failed at index " << CurrentOpcodeIndex
4165 << "\n");
4166 ++NumDAGIselRetries;
4167 while (true) {
4168 if (MatchScopes.empty()) {
4169 CannotYetSelect(NodeToMatch);
4170 return;
4171 }
4172
4173 // Restore the interpreter state back to the point where the scope was
4174 // formed.
4175 MatchScope &LastScope = MatchScopes.back();
4176 RecordedNodes.resize(LastScope.NumRecordedNodes);
4177 NodeStack.clear();
4178 NodeStack.append(LastScope.NodeStack.begin(), LastScope.NodeStack.end());
4179 N = NodeStack.back();
4180
4181 if (LastScope.NumMatchedMemRefs != MatchedMemRefs.size())
4182 MatchedMemRefs.resize(LastScope.NumMatchedMemRefs);
4183 MatcherIndex = LastScope.FailIndex;
4184
4185 LLVM_DEBUG(dbgs() << " Continuing at " << MatcherIndex << "\n");
4186
4187 InputChain = LastScope.InputChain;
4188 InputGlue = LastScope.InputGlue;
4189 if (!LastScope.HasChainNodesMatched)
4190 ChainNodesMatched.clear();
4191
4192 // Check to see what the offset is at the new MatcherIndex. If it is zero
4193 // we have reached the end of this scope, otherwise we have another child
4194 // in the current scope to try.
4195 unsigned NumToSkip = MatcherTable[MatcherIndex++];
4196 if (NumToSkip & 128)
4197 NumToSkip = GetVBR(NumToSkip, MatcherTable, MatcherIndex);
4198
4199 // If we have another child in this scope to match, update FailIndex and
4200 // try it.
4201 if (NumToSkip != 0) {
4202 LastScope.FailIndex = MatcherIndex+NumToSkip;
4203 break;
4204 }
4205
4206 // End of this scope, pop it and try the next child in the containing
4207 // scope.
4208 MatchScopes.pop_back();
4209 }
4210 }
4211}
4212
4213/// Return whether the node may raise an FP exception.
4215 // For machine opcodes, consult the MCID flag.
4216 if (N->isMachineOpcode()) {
4217 const MCInstrDesc &MCID = TII->get(N->getMachineOpcode());
4218 return MCID.mayRaiseFPException();
4219 }
4220
4221 // For ISD opcodes, only StrictFP opcodes may raise an FP
4222 // exception.
4223 if (N->isTargetOpcode())
4224 return N->isTargetStrictFPOpcode();
4225 return N->isStrictFPOpcode();
4226}
4227
4229 assert(N->getOpcode() == ISD::OR && "Unexpected opcode");
4230 auto *C = dyn_cast<ConstantSDNode>(N->getOperand(1));
4231 if (!C)
4232 return false;
4233
4234 // Detect when "or" is used to add an offset to a stack object.
4235 if (auto *FN = dyn_cast<FrameIndexSDNode>(N->getOperand(0))) {
4237 Align A = MFI.getObjectAlign(FN->getIndex());
4238 int32_t Off = C->getSExtValue();
4239 // If the alleged offset fits in the zero bits guaranteed by
4240 // the alignment, then this or is really an add.
4241 return (Off >= 0) && (((A.value() - 1) & Off) == unsigned(Off));
4242 }
4243 return false;
4244}
4245
4246void SelectionDAGISel::CannotYetSelect(SDNode *N) {
4247 std::string msg;
4248 raw_string_ostream Msg(msg);
4249 Msg << "Cannot select: ";
4250
4251 if (N->getOpcode() != ISD::INTRINSIC_W_CHAIN &&
4252 N->getOpcode() != ISD::INTRINSIC_WO_CHAIN &&
4253 N->getOpcode() != ISD::INTRINSIC_VOID) {
4254 N->printrFull(Msg, CurDAG);
4255 Msg << "\nIn function: " << MF->getName();
4256 } else {
4257 bool HasInputChain = N->getOperand(0).getValueType() == MVT::Other;
4258 unsigned iid = N->getConstantOperandVal(HasInputChain);
4259 if (iid < Intrinsic::num_intrinsics)
4260 Msg << "intrinsic %" << Intrinsic::getBaseName((Intrinsic::ID)iid);
4261 else if (const TargetIntrinsicInfo *TII = TM.getIntrinsicInfo())
4262 Msg << "target intrinsic %" << TII->getName(iid);
4263 else
4264 Msg << "unknown intrinsic #" << iid;
4265 }
4267}
unsigned const MachineRegisterInfo * MRI
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
MachineInstrBuilder & UseMI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
amdgpu AMDGPU Register Bank Select
Rewrite undef for PHI
This file implements a class to represent arbitrary precision integral constant values and operations...
Expand Atomic instructions
BlockVerifier::State From
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
Definition: Compiler.h:261
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define LLVM_DEBUG(X)
Definition: Debug.h:101
This file defines the DenseMap class.
bool End
Definition: ELF_riscv.cpp:480
This file defines the FastISel class.
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
Machine Instruction Scheduler
unsigned const TargetRegisterInfo * TRI
This file contains the declarations for metadata subclasses.
#define P(N)
const char LLVMTargetMachineRef TM
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckValueType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
static cl::opt< bool > ViewSUnitDAGs("view-sunit-dags", cl::Hidden, cl::desc("Pop up a window to show SUnit dags after they are processed"))
static cl::opt< bool > ViewDAGCombineLT("view-dag-combine-lt-dags", cl::Hidden, cl::desc("Pop up a window to show dags before the post " "legalize types dag combine pass"))
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckPatternPredicate(unsigned Opcode, const unsigned char *MatcherTable, unsigned &MatcherIndex, const SelectionDAGISel &SDISel)
CheckPatternPredicate - Implements OP_CheckPatternPredicate.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckChildSame(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const SmallVectorImpl< std::pair< SDValue, SDNode * > > &RecordedNodes, unsigned ChildNo)
CheckChildSame - Implements OP_CheckChildXSame.
static uint64_t decodeSignRotatedValue(uint64_t V)
Decode a signed value stored with the sign bit in the LSB for dense VBR encoding.
static cl::opt< bool > ViewISelDAGs("view-isel-dags", cl::Hidden, cl::desc("Pop up a window to show isel dags as they are selected"))
static LLVM_ATTRIBUTE_ALWAYS_INLINE uint64_t GetVBR(uint64_t Val, const unsigned char *MatcherTable, unsigned &Idx)
GetVBR - decode a vbr encoding whose top bit is set.
static void computeUsesMSVCFloatingPoint(const Triple &TT, const Function &F, MachineModuleInfo &MMI)
static void reportFastISelFailure(MachineFunction &MF, OptimizationRemarkEmitter &ORE, OptimizationRemarkMissed &R, bool ShouldAbort)
static cl::opt< bool > ViewDAGCombine2("view-dag-combine2-dags", cl::Hidden, cl::desc("Pop up a window to show dags before the second " "dag combine pass"))
static RegisterScheduler defaultListDAGScheduler("default", "Best scheduler for the target", createDefaultScheduler)
static unsigned IsPredicateKnownToFail(const unsigned char *Table, unsigned Index, SDValue N, bool &Result, const SelectionDAGISel &SDISel, SmallVectorImpl< std::pair< SDValue, SDNode * > > &RecordedNodes)
IsPredicateKnownToFail - If we know how and can do so without pushing a scope, evaluate the current n...
static cl::opt< int > EnableFastISelAbort("fast-isel-abort", cl::Hidden, cl::desc("Enable abort calls when \"fast\" instruction selection " "fails to lower an instruction: 0 disable the abort, 1 will " "abort but for args, calls and terminators, 2 will also " "abort for argument lowering, and 3 will never fallback " "to SelectionDAG."))
static void mapWasmLandingPadIndex(MachineBasicBlock *MBB, const CatchPadInst *CPI)
#define ISEL_DUMP(X)
static void processSingleLocVars(FunctionLoweringInfo &FuncInfo, FunctionVarLocs const *FnVarLocs)
Collect single location variable information generated with assignment tracking.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckAndImm(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const SelectionDAGISel &SDISel)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckOrImm(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const SelectionDAGISel &SDISel)
static cl::opt< bool > UseMBPI("use-mbpi", cl::desc("use Machine Branch Probability Info"), cl::init(true), cl::Hidden)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckChildType(MVT::SimpleValueType VT, SDValue N, const TargetLowering *TLI, const DataLayout &DL, unsigned ChildNo)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckSame(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const SmallVectorImpl< std::pair< SDValue, SDNode * > > &RecordedNodes)
CheckSame - Implements OP_CheckSame.
static bool dontUseFastISelFor(const Function &Fn)
static bool findNonImmUse(SDNode *Root, SDNode *Def, SDNode *ImmedUse, bool IgnoreChains)
findNonImmUse - Return true if "Def" is a predecessor of "Root" via a path beyond "ImmedUse".
static cl::opt< bool > ViewDAGCombine1("view-dag-combine1-dags", cl::Hidden, cl::desc("Pop up a window to show dags before the first " "dag combine pass"))
static bool processIfEntryValueDbgDeclare(FunctionLoweringInfo &FuncInfo, const Value *Arg, DIExpression *Expr, DILocalVariable *Var, DebugLoc DbgLoc)
static cl::opt< bool > ViewSchedDAGs("view-sched-dags", cl::Hidden, cl::desc("Pop up a window to show sched dags as they are processed"))
static void processDbgDeclares(FunctionLoweringInfo &FuncInfo)
Collect llvm.dbg.declare information.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckType(MVT::SimpleValueType VT, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckCondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N)
static bool hasExceptionPointerOrCodeUser(const CatchPadInst *CPI)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckChild2CondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N)
static cl::opt< bool > ViewLegalizeDAGs("view-legalize-dags", cl::Hidden, cl::desc("Pop up a window to show dags before legalize"))
static cl::opt< bool > ViewLegalizeTypesDAGs("view-legalize-types-dags", cl::Hidden, cl::desc("Pop up a window to show dags before legalize types"))
static SDNode * findGlueUse(SDNode *N)
findGlueUse - Return use of MVT::Glue value produced by the specified SDNode.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckNodePredicate(unsigned Opcode, const unsigned char *MatcherTable, unsigned &MatcherIndex, const SelectionDAGISel &SDISel, SDNode *N)
CheckNodePredicate - Implements OP_CheckNodePredicate.
static cl::opt< RegisterScheduler::FunctionPassCtor, false, RegisterPassParser< RegisterScheduler > > ISHeuristic("pre-RA-sched", cl::init(&createDefaultScheduler), cl::Hidden, cl::desc("Instruction schedulers available (before register" " allocation):"))
ISHeuristic command line option for instruction schedulers.
static cl::opt< bool > EnableFastISelFallbackReport("fast-isel-report-on-fallback", cl::Hidden, cl::desc("Emit a diagnostic when \"fast\" instruction selection " "falls back to SelectionDAG."))
static bool processDbgDeclare(FunctionLoweringInfo &FuncInfo, const Value *Address, DIExpression *Expr, DILocalVariable *Var, DebugLoc DbgLoc)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckOpcode(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDNode *N)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckChildInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, unsigned ChildNo)
static cl::opt< std::string > FilterDAGBasicBlockName("filter-view-dags", cl::Hidden, cl::desc("Only display the basic block whose name " "matches this for all view-*-dags options"))
static SDValue HandleMergeInputChains(SmallVectorImpl< SDNode * > &ChainNodesMatched, SelectionDAG *CurDAG)
HandleMergeInputChains - This implements the OPC_EmitMergeInputChains operation for when the pattern ...
static bool isFoldedOrDeadInstruction(const Instruction *I, const FunctionLoweringInfo &FuncInfo)
isFoldedOrDeadInstruction - Return true if the specified instruction is side-effect free and is eithe...
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
This file describes how to lower LLVM code to machine code.
This pass exposes codegen information to IR-level passes.
LLVM IR instance of the generic uniformity analysis.
Value * RHS
Value * LHS
DEMANGLE_DUMP_METHOD void dump() const
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
Class for arbitrary precision integers.
Definition: APInt.h:76
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
Definition: APInt.h:1235
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
An immutable pass that tracks lazily created AssumptionCache objects.
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
iterator end()
Definition: BasicBlock.h:443
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:499
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:166
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:360
bool isEHPad() const
Return true if this basic block is an exception handling block.
Definition: BasicBlock.h:657
const Instruction * getFirstMayFaultInst() const
Returns the first potential AsynchEH faulty instruction currently it checks for loads/stores (which m...
Definition: BasicBlock.cpp:351
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Legacy analysis pass which computes BranchProbabilityInfo.
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:268
This is the shared class of boolean and integer constants.
Definition: Constants.h:80
This is an important base class in LLVM.
Definition: Constant.h:41
DWARF expression.
bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
static DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
static DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
Record of a variable value-assignment, aka a non instruction representation of the dbg....
A debug info location.
Definition: DebugLoc.h:33
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
Diagnostic information for ISel fallback path.
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Definition: FastISel.h:66
void setLastLocalValue(MachineInstr *I)
Update the position of the last instruction emitted for materializing constants for use in the curren...
Definition: FastISel.h:237
void handleDbgInfo(const Instruction *II)
Target-independent lowering of non-instruction debug info associated with this instruction.
Definition: FastISel.cpp:1192
bool tryToFoldLoad(const LoadInst *LI, const Instruction *FoldInst)
We're checking to see if we can fold LI into FoldInst.
Definition: FastISel.cpp:2315
void removeDeadCode(MachineBasicBlock::iterator I, MachineBasicBlock::iterator E)
Remove all dead instructions between the I and E.
Definition: FastISel.cpp:410
void startNewBlock()
Set the current block to which generated machine instructions will be appended.
Definition: FastISel.cpp:123
bool selectInstruction(const Instruction *I)
Do "fast" instruction selection for the given LLVM IR instruction and append the generated machine in...
Definition: FastISel.cpp:1597
void finishBasicBlock()
Flush the local value map.
Definition: FastISel.cpp:136
void recomputeInsertPt()
Reset InsertPt to prepare for inserting instructions into the current block.
Definition: FastISel.cpp:401
bool lowerArguments()
Do "fast" instruction selection for function arguments and append the machine instructions to the cur...
Definition: FastISel.cpp:138
unsigned arg_size() const
arg_size - Return the number of funcletpad arguments.
Definition: InstrTypes.h:2703
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
Definition: InstrTypes.h:2719
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
SmallPtrSet< const DbgVariableRecord *, 8 > PreprocessedDVRDeclares
DenseMap< const AllocaInst *, int > StaticAllocaMap
StaticAllocaMap - Keep track of frame indices for fixed sized allocas in the entry block.
int getArgumentFrameIndex(const Argument *A)
getArgumentFrameIndex - Get frame index for the byval argument.
bool isExportedInst(const Value *V) const
isExportedInst - Return true if the specified value is an instruction exported from its block.
SmallPtrSet< const DbgDeclareInst *, 8 > PreprocessedDbgDeclares
Collection of dbg.declare instructions handled after argument lowering and before ISel proper.
DenseMap< const Value *, Register > ValueMap
ValueMap - Since we emit code for the function a basic block at a time, we must remember which virtua...
MachineRegisterInfo * RegInfo
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
Definition: Pass.cpp:178
Data structure describing the variable locations in a function.
const VarLocInfo * single_locs_begin() const
DILocalVariable * getDILocalVariable(const VarLocInfo *Loc) const
Return the DILocalVariable for the location definition represented by ID.
const VarLocInfo * single_locs_end() const
One past the last single-location variable location definition.
const BasicBlock & getEntryBlock() const
Definition: Function.h:787
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:202
iterator_range< arg_iterator > args()
Definition: Function.h:842
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1831
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.h:332
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:356
bool callsFunctionThatReturnsTwice() const
callsFunctionThatReturnsTwice - Return true if the function has a call to setjmp or other function th...
Definition: Function.cpp:1898
An analysis pass which caches information about the entire Module.
Definition: GCMetadata.h:203
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:656
This class is used to form a handle around another node that is persistent and is updated across invo...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:454
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:47
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
static void getLazyBFIAnalysisUsage(AnalysisUsage &AU)
Helper for client passes to set up the analysis usage on behalf of this pass.
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:322
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:198
bool mayStore() const
Return true if this instruction could possibly modify memory.
Definition: MCInstrDesc.h:444
bool mayLoad() const
Return true if this instruction could possibly read memory.
Definition: MCInstrDesc.h:438
bool mayRaiseFPException() const
Return true if this instruction may raise a floating-point exception.
Definition: MCInstrDesc.h:447
bool isCall() const
Return true if the instruction is a call.
Definition: MCInstrDesc.h:288
bool isReturn() const
Return true if the instruction is a return.
Definition: MCInstrDesc.h:276
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition: MCInstrInfo.h:63
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
Definition: MCInstrInfo.h:70
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
const MDNode * getMD() const
Metadata node.
Definition: Metadata.h:1067
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1428
A single uniqued string.
Definition: Metadata.h:720
StringRef getString() const
Definition: Metadata.cpp:610
Machine Value Type.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
instr_iterator instr_end()
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
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 '...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasCalls() const
Return true if the current function has any function calls.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
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.
bool hasProperty(Property P) const
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
bool useDebugInstrRef() const
Returns true if the function's variable locations are tracked with instruction referencing.
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there's a call to a "returns twice" function.
void setHasInlineAsm(bool B)
Set a flag that indicates that the function contains inline assembly.
void setWasmLandingPadIndex(const MachineBasicBlock *LPad, unsigned Index)
Map the landing pad to its index. Used for Wasm exception handling.
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.
bool hasInlineAsm() const
Returns true if the function contains any inline assembly.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void finalizeDebugInstrRefs()
Finalise any partially emitted debug instructions.
void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef< unsigned > Sites)
Map the landing pad's EH symbol to the call site indexes.
void setUseDebugInstrRef(bool UseInstrRef)
Set whether this function will use instruction referencing or not.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
MCSymbol * addLandingPad(MachineBasicBlock *LandingPad)
Add a new panding pad, and extract the exception handling information from the landingpad instruction...
Function & getFunction()
Return the LLVM function that this machine code represents.
MachineModuleInfo & getMMI() const
bool shouldUseDebugInstrRef() const
Determine whether, in the current machine configuration, we should use instruction referencing or not...
const MachineFunctionProperties & getProperties() const
Get the function properties.
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, int Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable in a stack slot.
const MachineBasicBlock & front() const
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
Definition: MachineInstr.h:69
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
Definition: MachineInstr.h:963
bool isCopy() const
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:341
bool isDebugValue() const
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:568
A description of a memory reference used in the backend.
This class contains meta information specific to a module.
const MCContext & getContext() const
bool usesMSVCFloatingPoint() const
void setUsesMSVCFloatingPoint(bool b)
Register getReg() const
getReg - Returns the register number.
MachinePassRegistry - Track the registration of machine passes.
defusechain_iterator - This class provides iterator support for machine operands in the function that...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
void EmitLiveInCopies(MachineBasicBlock *EntryMBB, const TargetRegisterInfo &TRI, const TargetInstrInfo &TII)
EmitLiveInCopies - Emit copies to initialize livein virtual registers into the given entry block.
use_instr_iterator use_instr_begin(Register RegNo) const
ArrayRef< std::pair< MCRegister, Register > > liveins() const
static use_instr_iterator use_instr_end()
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask)
addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
An SDNode that represents everything that will be needed to construct a MachineInstr.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:331
This class is used by SelectionDAGISel to temporarily override the optimization level on a per-functi...
OptLevelChanger(SelectionDAGISel &ISel, CodeGenOptLevel NewOptLevel)
The optimization diagnostic interface.
void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file.
Diagnostic information for missed-optimization remarks.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
RegisterPassParser class - Handle the addition of new machine passes.
ScheduleDAGSDNodes *(*)(SelectionDAGISel *, CodeGenOptLevel) FunctionPassCtor
static MachinePassRegistry< FunctionPassCtor > Registry
RegisterScheduler class - Track the registration of instruction schedulers.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
Definition: Register.h:77
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:91
static constexpr bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:71
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
This class provides iterator support for SDUse operands that use a specific SDNode.
Represents one node in the SelectionDAG.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool isOnlyUserOf(const SDNode *N) const
Return true if this node is the only use of N.
iterator_range< value_op_iterator > op_values() const
void setNodeId(int Id)
Set unique node id.
static bool hasPredecessorHelper(const SDNode *N, SmallPtrSetImpl< const SDNode * > &Visited, SmallVectorImpl< const SDNode * > &Worklist, unsigned int MaxSteps=0, bool TopologicalPrune=false)
Returns true if N is a predecessor of any node in Worklist.
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
bool use_empty() const
Return true if there are no uses of this node.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
unsigned getNumOperands() const
Return the number of values used by this operation.
const SDValue & getOperand(unsigned Num) const
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
static use_iterator use_end()
Represents a use of a SDNode.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
ScheduleDAGSDNodes - A ScheduleDAG for scheduling SDNode-based DAGs.
SelectionDAGBuilder - This is the common target-independent lowering implementation that is parameter...
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
std::unique_ptr< FunctionLoweringInfo > FuncInfo
SmallPtrSet< const Instruction *, 4 > ElidedArgCopyInstrs
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, InlineAsm::ConstraintCode ConstraintID, std::vector< SDValue > &OutOps)
SelectInlineAsmMemoryOperand - Select the specified address as a target addressing mode,...
bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS, int64_t DesiredMaskS) const
CheckOrMask - The isel is trying to match something like (or X, 255).
AssumptionCache * AC
const TargetLowering * TLI
virtual void PostprocessISelDAG()
PostprocessISelDAG() - This hook allows the target to hack on the graph right after selection.
MachineFunction * MF
virtual bool CheckNodePredicate(SDNode *N, unsigned PredNo) const
CheckNodePredicate - This function is generated by tblgen in the target.
std::unique_ptr< OptimizationRemarkEmitter > ORE
Current optimization remark emitter.
MachineRegisterInfo * RegInfo
unsigned DAGSize
DAGSize - Size of DAG being instruction selected.
bool isOrEquivalentToAdd(const SDNode *N) const
virtual bool CheckComplexPattern(SDNode *Root, SDNode *Parent, SDValue N, unsigned PatternNo, SmallVectorImpl< std::pair< SDValue, SDNode * > > &Result)
virtual bool CheckPatternPredicate(unsigned PredNo) const
CheckPatternPredicate - This function is generated by tblgen in the target.
static int getNumFixedFromVariadicInfo(unsigned Flags)
getNumFixedFromVariadicInfo - Transform an EmitNode flags word into the number of fixed arity values ...
const TargetLibraryInfo * LibInfo
static int getUninvalidatedNodeId(SDNode *N)
const TargetInstrInfo * TII
CodeGenOptLevel OptLevel
virtual bool CheckNodePredicateWithOperands(SDNode *N, unsigned PredNo, const SmallVectorImpl< SDValue > &Operands) const
CheckNodePredicateWithOperands - This function is generated by tblgen in the target.
GCFunctionInfo * GFI
void SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable, unsigned TableSize)
static void EnforceNodeIdInvariant(SDNode *N)
void ReplaceUses(SDValue F, SDValue T)
ReplaceUses - replace all uses of the old node F with the use of the new node T.
virtual bool IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const
IsProfitableToFold - Returns true if it's profitable to fold the specific operand node N of U during ...
virtual SDValue RunSDNodeXForm(SDValue V, unsigned XFormNo)
bool MatchFilterFuncName
True if the function currently processing is in the function printing list (i.e.
void SelectInlineAsmMemoryOperands(std::vector< SDValue > &Ops, const SDLoc &DL)
SelectInlineAsmMemoryOperands - Calls to this are automatically generated by tblgen.
static bool IsLegalToFold(SDValue N, SDNode *U, SDNode *Root, CodeGenOptLevel OptLevel, bool IgnoreChains=false)
IsLegalToFold - Returns true if the specific operand node N of U can be folded during instruction sel...
virtual bool ComplexPatternFuncMutatesDAG() const
Return true if complex patterns for this target can mutate the DAG.
virtual void PreprocessISelDAG()
PreprocessISelDAG - This hook allows targets to hack on the graph before instruction selection starts...
bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS, int64_t DesiredMaskS) const
CheckAndMask - The isel is trying to match something like (and X, 255).
SwiftErrorValueTracking * SwiftError
SelectionDAGISel(char &ID, TargetMachine &tm, CodeGenOptLevel OL=CodeGenOptLevel::Default)
virtual StringRef getPatternForIndex(unsigned index)
getPatternForIndex - Patterns selected by tablegen during ISEL
bool mayRaiseFPException(SDNode *Node) const
Return whether the node may raise an FP exception.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
std::unique_ptr< SelectionDAGBuilder > SDB
void ReplaceNode(SDNode *F, SDNode *T)
Replace all uses of F with T, then remove F from the DAG.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static void InvalidateNodeId(SDNode *N)
virtual StringRef getIncludePathForIndex(unsigned index)
getIncludePathForIndex - get the td source location of pattern instantiation
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:225
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
Definition: SelectionDAG.h:551
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
bool LegalizeVectors()
This transforms the SelectionDAG into a SelectionDAG that only uses vector math operations supported ...
SDNode * SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT)
These are used for target selectors to mutate the specified node to have the specified return type,...
void setFunctionLoweringInfo(FunctionLoweringInfo *FuncInfo)
Definition: SelectionDAG.h:461
SDNode * mutateStrictFPToFP(SDNode *Node)
Mutate the specified strict FP node to its non-strict equivalent, unlinking the node from its chain a...
bool NewNodesMustHaveLegalTypes
When true, additional steps are taken to ensure that getConstant() and similar functions return DAG n...
Definition: SelectionDAG.h:387
void salvageDebugInfo(SDNode &N)
To be invoked on an SDNode that is slated to be erased.
SDNode * MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs, ArrayRef< SDValue > Ops)
This mutates the specified node to have the specified return type, opcode, and operands.
allnodes_const_iterator allnodes_begin() const
Definition: SelectionDAG.h:531
void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:472
void viewGraph(const std::string &Title)
Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
void Legalize()
This transforms the SelectionDAG into a SelectionDAG that is compatible with the target instruction s...
void Combine(CombineLevel Level, AAResults *AA, CodeGenOptLevel OptLevel)
This iterates over the nodes in the SelectionDAG, folding certain types of nodes together,...
void clear()
Clear state and free memory necessary to make this SelectionDAG ready to process a new block.
SDValue getRegister(unsigned Reg, EVT VT)
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE, Pass *PassPtr, const TargetLibraryInfo *LibraryInfo, UniformityInfo *UA, ProfileSummaryInfo *PSIin, BlockFrequencyInfo *BFIin, FunctionVarLocs const *FnVarLocs)
Prepare this SelectionDAG to process code in the given MachineFunction.
void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N)
Definition: SelectionDAG.h:773
SDValue getTargetConstantFP(double Val, const SDLoc &DL, EVT VT)
Definition: SelectionDAG.h:708
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
unsigned AssignTopologicalOrder()
Topological-sort the AllNodes list and a assign a unique node id for each node in the DAG based on th...
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:676
unsigned ComputeNumSignBits(SDValue Op, unsigned Depth=0) const
Return the number of times the sign bit of the register is replicated into the other bits.
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:469
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT)
Definition: SelectionDAG.h:799
const FunctionVarLocs * getFunctionVarLocs() const
Returns the result of the AssignmentTrackingAnalysis pass if it's available, otherwise return nullptr...
Definition: SelectionDAG.h:484
KnownBits computeKnownBits(SDValue Op, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
Definition: SelectionDAG.h:560
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:554
ilist< SDNode >::iterator allnodes_iterator
Definition: SelectionDAG.h:534
bool LegalizeTypes()
This transforms the SelectionDAG into a SelectionDAG that only uses types natively supported by the t...
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
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:696
void resize(size_type N)
Definition: SmallVector.h:651
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
bool shouldEmitSDCheck(const BasicBlock &BB) const
void copyToMachineFrameInfo(MachineFrameInfo &MFI) const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:131
bool createEntriesInEntryBlock(DebugLoc DbgLoc)
Create initial definitions of swifterror values in the entry block of the current function.
void setFunction(MachineFunction &MF)
Initialize data structures for specified new function.
void preassignVRegs(MachineBasicBlock *MBB, BasicBlock::const_iterator Begin, BasicBlock::const_iterator End)
void propagateVRegs()
Propagate assigned swifterror vregs through a function, synthesizing PHI nodes when needed to maintai...
TargetIntrinsicInfo - Interface to description of machine instruction set.
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
virtual Function * getSSPStackGuardCheck(const Module &M) const
If the target has a standard stack protection check function that performs validation and error handl...
Sched::Preference getSchedulingPreference() const
Return target scheduling preference.
bool isStrictFPEnabled() const
Return true if the target support strict float operation.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
virtual Register getExceptionPointerRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception address on entry to an ...
virtual Register getExceptionSelectorRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception typeid on entry to a la...
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
virtual Register getRegisterByName(const char *RegName, LLT Ty, const MachineFunction &MF) const
Return the register ID of the name passed in.
virtual void insertCopiesSplitCSR(MachineBasicBlock *Entry, const SmallVectorImpl< MachineBasicBlock * > &Exits) const
Insert explicit copies in entry and exit blocks.
virtual void AdjustInstrPostInstrSelection(MachineInstr &MI, SDNode *Node) const
This method should be implemented by targets that mark instructions with the 'hasPostISelHook' flag.
virtual void initializeSplitCSR(MachineBasicBlock *Entry) const
Perform necessary initialization to handle a subset of CSRs explicitly via copies.
virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
virtual FastISel * createFastISel(FunctionLoweringInfo &, const TargetLibraryInfo *) const
This method returns a target specific FastISel object, or null if the target does not support "fast" ...
virtual bool supportSplitCSR(MachineFunction *MF) const
Return true if the target supports that a subset of CSRs for the given machine function is handled ex...
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
virtual const TargetIntrinsicInfo * getIntrinsicInfo() const
If intrinsic information is available, return it. If not, return null.
const Triple & getTargetTriple() const
void setFastISel(bool Enable)
TargetOptions Options
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
void setOptLevel(CodeGenOptLevel Level)
Overrides the optimization level.
unsigned EnableFastISel
EnableFastISel - This flag enables fast-path instruction selection which trades away generated code q...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetLowering * getTargetLowering() const
Wrapper pass for TargetTransformInfo.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
bool hasBranchDivergence(const Function *F=nullptr) const
Return true if branch divergence exists.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
User * getUser() const
Returns the User that contains this Use.
Definition: Use.h:72
LLVM Value Representation.
Definition: Value.h:74
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition: Value.h:434
iterator_range< user_iterator > users()
Definition: Value.h:421
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
self_iterator getIterator()
Definition: ilist_node.h:109
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:660
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const CustomOperand< const MCSubtargetInfo & > Msg[]
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
bool isConstantSplatVectorAllOnes(const SDNode *N, bool BuildVectorOnly=false)
Return true if the specified node is a BUILD_VECTOR or SPLAT_VECTOR where all of the elements are ~0 ...
@ TargetConstantPool
Definition: ISDOpcodes.h:168
@ CONVERGENCECTRL_ANCHOR
Definition: ISDOpcodes.h:1396
@ MDNODE_SDNODE
MDNODE_SDNODE - This is a node that holdes an MDNode*, which is used to reference metadata in the IR.
Definition: ISDOpcodes.h:1177
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
Definition: ISDOpcodes.h:476
@ DELETED_NODE
DELETED_NODE - This is an illegal value that is used to catch errors.
Definition: ISDOpcodes.h:44
@ JUMP_TABLE_DEBUG_INFO
JUMP_TABLE_DEBUG_INFO - Jumptable debug info.
Definition: ISDOpcodes.h:1066
@ TargetBlockAddress
Definition: ISDOpcodes.h:170
@ ConstantFP
Definition: ISDOpcodes.h:77
@ INTRINSIC_VOID
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
Definition: ISDOpcodes.h:199
@ MEMBARRIER
MEMBARRIER - Compiler barrier only; generate a no-op.
Definition: ISDOpcodes.h:1234
@ STRICT_FSETCCS
Definition: ISDOpcodes.h:477
@ FrameIndex
Definition: ISDOpcodes.h:80
@ EH_LABEL
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
Definition: ISDOpcodes.h:1108
@ ANNOTATION_LABEL
ANNOTATION_LABEL - Represents a mid basic block label used by annotations.
Definition: ISDOpcodes.h:1114
@ STRICT_UINT_TO_FP
Definition: ISDOpcodes.h:450
@ TargetExternalSymbol
Definition: ISDOpcodes.h:169
@ CONVERGENCECTRL_ENTRY
Definition: ISDOpcodes.h:1397
@ TargetJumpTable
Definition: ISDOpcodes.h:167
@ WRITE_REGISTER
Definition: ISDOpcodes.h:119
@ STRICT_LROUND
Definition: ISDOpcodes.h:431
@ UNDEF
UNDEF - An undefined node.
Definition: ISDOpcodes.h:211
@ RegisterMask
Definition: ISDOpcodes.h:75
@ AssertAlign
AssertAlign - These nodes record if a register contains a value that has a known alignment and the tr...
Definition: ISDOpcodes.h:68
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
Definition: ISDOpcodes.h:208
@ TargetGlobalAddress
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
Definition: ISDOpcodes.h:164
@ ARITH_FENCE
ARITH_FENCE - This corresponds to a arithmetic fence intrinsic.
Definition: ISDOpcodes.h:1231
@ EntryToken
EntryToken - This is the marker used to indicate the start of a region.
Definition: ISDOpcodes.h:47
@ READ_REGISTER
READ_REGISTER, WRITE_REGISTER - This node represents llvm.register on the DAG, which implements the n...
Definition: ISDOpcodes.h:118
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
Definition: ISDOpcodes.h:203
@ TargetConstantFP
Definition: ISDOpcodes.h:159
@ STRICT_LRINT
Definition: ISDOpcodes.h:433
@ TargetFrameIndex
Definition: ISDOpcodes.h:166
@ LIFETIME_START
This corresponds to the llvm.lifetime.
Definition: ISDOpcodes.h:1310
@ STRICT_SINT_TO_FP
STRICT_[US]INT_TO_FP - Convert a signed or unsigned integer to a floating point value.
Definition: ISDOpcodes.h:449
@ HANDLENODE
HANDLENODE node - Used as a handle for various purposes.
Definition: ISDOpcodes.h:1197
@ INLINEASM_BR
INLINEASM_BR - Branching version of inline asm. Used by asm-goto.
Definition: ISDOpcodes.h:1103
@ TargetConstant
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification,...
Definition: ISDOpcodes.h:158
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:680
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition: ISDOpcodes.h:184
@ PSEUDO_PROBE
Pseudo probe for AutoFDO, as a place holder in a basic block to improve the sample counts quality.
Definition: ISDOpcodes.h:1330
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition: ISDOpcodes.h:52
@ STRICT_LLRINT
Definition: ISDOpcodes.h:434
@ STRICT_LLROUND
Definition: ISDOpcodes.h:432
@ CONVERGENCECTRL_LOOP
Definition: ISDOpcodes.h:1398
@ INLINEASM
INLINEASM - Represents an inline asm block.
Definition: ISDOpcodes.h:1100
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:61
@ AssertZext
Definition: ISDOpcodes.h:62
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
Definition: ISDOpcodes.h:192
@ TargetGlobalTLSAddress
Definition: ISDOpcodes.h:165
bool isConstantSplatVectorAllZeros(const SDNode *N, bool BuildVectorOnly=false)
Return true if the specified node is a BUILD_VECTOR or SPLAT_VECTOR where all of the elements are 0 o...
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1529
StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
Definition: Function.cpp:1022
@ Kill
The last use of a register.
Reg
All possible values of the reg field in the ModR/M byte.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:450
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ScheduleDAGSDNodes * createDefaultScheduler(SelectionDAGISel *IS, CodeGenOptLevel OptLevel)
createDefaultScheduler - This creates an instruction scheduler appropriate for the target.
@ Offset
Definition: DWP.cpp:456
bool succ_empty(const Instruction *I)
Definition: CFG.h:255
ScheduleDAGSDNodes * createBURRListDAGScheduler(SelectionDAGISel *IS, CodeGenOptLevel OptLevel)
createBURRListDAGScheduler - This creates a bottom up register usage reduction list scheduler.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
ScheduleDAGSDNodes * createHybridListDAGScheduler(SelectionDAGISel *IS, CodeGenOptLevel)
createHybridListDAGScheduler - This creates a bottom up register pressure aware list scheduler that m...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition: STLExtras.h:2073
MachineBasicBlock::iterator findSplitPointForStackProtector(MachineBasicBlock *BB, const TargetInstrInfo &TII)
Find the split point at which to splice the end of BB into its success stack protector check machine ...
bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
LLT getLLTForMVT(MVT Ty)
Get a rough equivalent of an LLT for a given MVT.
void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry &)
ScheduleDAGSDNodes * createFastDAGScheduler(SelectionDAGISel *IS, CodeGenOptLevel OptLevel)
createFastDAGScheduler - This creates a "fast" scheduler.
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
Definition: STLExtras.h:2059
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
ScheduleDAGSDNodes * createDAGLinearizer(SelectionDAGISel *IS, CodeGenOptLevel OptLevel)
createDAGLinearizer - This creates a "no-scheduling" scheduler which linearize the DAG using topologi...
void initializeAAResultsWrapperPassPass(PassRegistry &)
void initializeGCModuleInfoPass(PassRegistry &)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
bool isFunctionInPrintList(StringRef FunctionName)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:156
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
@ AfterLegalizeDAG
Definition: DAGCombine.h:19
@ AfterLegalizeVectorOps
Definition: DAGCombine.h:18
@ BeforeLegalizeTypes
Definition: DAGCombine.h:16
@ AfterLegalizeTypes
Definition: DAGCombine.h:17
ScheduleDAGSDNodes * createSourceListDAGScheduler(SelectionDAGISel *IS, CodeGenOptLevel OptLevel)
createSourceListDAGScheduler - This creates a bottom up list scheduler that schedules nodes in source...
bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
Definition: DebugInfo.cpp:2433
ScheduleDAGSDNodes * createILPListDAGScheduler(SelectionDAGISel *IS, CodeGenOptLevel)
createILPListDAGScheduler - This creates a bottom up register pressure aware list scheduler that trie...
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1879
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
ScheduleDAGSDNodes * createVLIWDAGScheduler(SelectionDAGISel *IS, CodeGenOptLevel OptLevel)
createVLIWDAGScheduler - Scheduler for VLIW targets.
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Extended Value Type.
Definition: ValueTypes.h:34
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition: ValueTypes.h:136
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:358
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:306
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:151
This class is basically a combination of TimeRegion and Timer.
Definition: Timer.h:163
These are IR-level optimization flags that may be propagated to SDNodes.
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
Clients of various APIs that cause global effects on the DAG can optionally implement this interface.
Definition: SelectionDAG.h:307
void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin, MCSymbol *InvokeEnd)
DenseMap< const BasicBlock *, int > BlockToStateMap
Definition: WinEHFuncInfo.h:95