103 using namespace llvm;
105 #define DEBUG_TYPE "isel" 107 STATISTIC(NumFastIselFailures,
"Number of instructions fast isel failed on");
108 STATISTIC(NumFastIselSuccess,
"Number of instructions fast isel selected");
109 STATISTIC(NumFastIselBlocks,
"Number of blocks selected entirely by fast isel");
110 STATISTIC(NumDAGBlocks,
"Number of blocks selected using DAG");
111 STATISTIC(NumDAGIselRetries,
"Number of times dag isel has to try another path");
112 STATISTIC(NumEntryBlocks,
"Number of entry blocks encountered");
114 "Number of entry blocks where fast isel failed to lower arguments");
118 cl::desc(
"Enable abort calls when \"fast\" instruction selection " 119 "fails to lower an instruction: 0 disable the abort, 1 will " 120 "abort but for args, calls and terminators, 2 will also " 121 "abort for argument lowering, and 3 will never fallback " 122 "to SelectionDAG."));
126 cl::desc(
"Emit a diagnostic when \"fast\" instruction selection " 127 "falls back to SelectionDAG."));
131 cl::desc(
"use Machine Branch Probability Info"),
137 cl::desc(
"Only display the basic block whose name " 138 "matches this for all view-*-dags options"));
141 cl::desc(
"Pop up a window to show dags before the first " 142 "dag combine pass"));
145 cl::desc(
"Pop up a window to show dags before legalize types"));
148 cl::desc(
"Pop up a window to show dags before legalize"));
151 cl::desc(
"Pop up a window to show dags before the second " 152 "dag combine pass"));
155 cl::desc(
"Pop up a window to show dags before the post legalize types" 156 " dag combine pass"));
159 cl::desc(
"Pop up a window to show isel dags as they are selected"));
162 cl::desc(
"Pop up a window to show sched dags as they are processed"));
165 cl::desc(
"Pop up a window to show SUnit dags after they are processed"));
192 cl::desc(
"Instruction schedulers available (before register" 213 if (NewOptLevel == SavedOptLevel)
217 LLVM_DEBUG(
dbgs() <<
"\nChanging optimization level for Function " 219 LLVM_DEBUG(
dbgs() <<
"\tBefore: -O" << SavedOptLevel <<
" ; After: -O" 220 << NewOptLevel <<
"\n");
225 dbgs() <<
"\tFastISel is " 234 LLVM_DEBUG(
dbgs() <<
"\nRestoring optimization level for Function " 237 << SavedOptLevel <<
"\n");
254 return SchedulerCtor(IS, OptLevel);
268 "Unknown sched type!");
287 dbgs() <<
"If a target marks an instruction with " 288 "'usesCustomInserter', it must implement " 289 "TargetLowering::EmitInstrWithCustomInserter!";
297 "If a target marks an instruction with 'hasPostISelHook', " 298 "it must implement TargetLowering::AdjustInstrPostInstrSelection!");
364 if (!CE || !CE->
canTrap())
continue;
389 "-fast-isel-abort > 0 requires -fast-isel");
409 LibInfo = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
410 GFI = Fn.
hasGC() ? &getAnalysis<GCModuleInfo>().getFunctionInfo(Fn) :
nullptr;
411 ORE = make_unique<OptimizationRemarkEmitter>(&Fn);
412 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
414 auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
415 LoopInfo *LI = LIWP ? &LIWP->getLoopInfo() :
nullptr;
422 getAnalysisIfAvailable<LegacyDivergenceAnalysis>());
431 FuncInfo->
BPI = &getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI();
436 AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
457 if (isa<UnreachableInst>(Term) || isa<ReturnInst>(Term))
471 SelectAllBasicBlocks(Fn);
488 if (!MBB.succ_empty())
492 if (Term != MBB.end() && Term->isReturn()) {
527 if (LDI != LiveInMap.
end()) {
528 assert(!hasFI &&
"There's no handling of frame pointer updating here yet " 538 "DBG_VALUE with nonzero offset");
539 assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
540 "Expected inlined-at fields to agree");
542 BuildMI(*EntryMBB, ++InsertPos, DL,
TII->
get(TargetOpcode::DBG_VALUE),
543 IsIndirect, LDI->second, Variable, Expr);
555 CopyUseMI =
UseMI;
continue;
558 CopyUseMI =
nullptr;
break;
565 CopyUseMI->getOperand(0).getReg(), Variable, Expr);
574 for (
const auto &MBB : *
MF) {
575 if (MFI.
hasCalls() && MF->hasInlineAsm())
578 for (
const auto &
MI : MBB) {
581 MI.isStackAligningInlineAsm()) {
584 if (
MI.isInlineAsm()) {
585 MF->setHasInlineAsm(
true);
599 unsigned From =
I->first;
600 unsigned To =
I->second;
642 R << (
" (in function: " + MF.
getName() +
")").str();
672 void SelectionDAGISel::ComputeLiveOutVRegInfo() {
684 if (!VisitedNodes.
insert(N).second)
709 }
while (!Worklist.
empty());
712 void SelectionDAGISel::CodeGenAndEmitDAG() {
714 StringRef GroupDescription =
"Instruction Selection and Scheduling";
715 std::string BlockName;
716 int BlockNumber = -1;
718 bool MatchFilterBB =
false; (void)MatchFilterBB;
721 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(*
FuncInfo->
Fn);
747 if (ViewDAGCombine1 && MatchFilterBB)
898 ComputeLiveOutVRegInfo();
908 DoInstructionSelection();
944 if (FirstMBB != LastMBB)
1004 while (!Nodes.
empty()) {
1006 for (
auto *U : N->
uses()) {
1032 void SelectionDAGISel::DoInstructionSelection() {
1053 ISelUpdater ISU(*
CurDAG, ISelPosition);
1060 SDNode *Node = &*--ISelPosition;
1071 while (!Nodes.
empty()) {
1088 "Node has already selected predecessor node");
1107 LLVM_DEBUG(
dbgs() <<
"\nISEL: Starting selection on root node: ";
1123 if (
const IntrinsicInst *EHPtrCall = dyn_cast<IntrinsicInst>(U)) {
1141 bool IsSingleCatchAllClause =
1144 if (!IsSingleCatchAllClause) {
1146 bool IntrFound =
false;
1148 if (
const auto *Call = dyn_cast<IntrinsicInst>(U)) {
1151 Value *IndexArg = Call->getArgOperand(1);
1152 int Index = cast<ConstantInt>(IndexArg)->getZExtValue();
1159 assert(IntrFound &&
"wasm.landingpad.index intrinsic not found!");
1166 bool SelectionDAGISel::PrepareEHLandingPad() {
1178 if (
const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->
getFirstNonPHI())) {
1183 assert(EHPhysReg &&
"target lacks exception pointer register");
1187 TII->
get(TargetOpcode::COPY), VReg)
1203 if (
const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->
getFirstNonPHI()))
1226 !isa<DbgInfoIntrinsic>(
I) &&
1245 bool HaveSeenSwiftErrorArg =
false;
1248 if (AI->hasSwiftErrorAttr()) {
1249 assert(!HaveSeenSwiftErrorArg &&
1250 "Must have only one swifterror parameter");
1251 (void)HaveSeenSwiftErrorArg;
1252 HaveSeenSwiftErrorArg =
true;
1257 for (
const auto &LLVMBB : Fn)
1258 for (
const auto &Inst : LLVMBB) {
1259 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(&Inst))
1260 if (Alloca->isSwiftError())
1279 "expected to insert into entry block");
1322 Address = Address->stripAndAccumulateInBoundsConstantOffsets(DL, Offset);
1328 if (
const auto *AI = dyn_cast<AllocaInst>(Address)) {
1332 }
else if (
const auto *
Arg = dyn_cast<Argument>(Address))
1349 auto *
TLI = FuncInfo->
TLI;
1363 auto Key = std::make_pair(MBB, SwiftErrorVal);
1367 unsigned UUseVReg = UpwardsUse ? UUseIt->second : 0;
1369 assert(!(UpwardsUse && !DownwardDef) &&
1370 "We can't have an upwards use but no downwards def");
1375 if (!UpwardsUse && DownwardDef)
1385 for (
auto *Pred : MBB->predecessors()) {
1386 if (!Visited.
insert(Pred).second)
1399 UUseVReg = UUseIt->second;
1406 VRegs.
size() >= 1 &&
1409 [&](
const std::pair<const MachineBasicBlock *, unsigned> &V)
1410 ->
bool {
return V.second != VRegs[0].second; }) !=
1415 if (!UpwardsUse && !needPHI) {
1417 "No predecessors? The entry block should bail out earlier");
1423 auto DLoc = isa<Instruction>(SwiftErrorVal)
1424 ? cast<Instruction>(SwiftErrorVal)->getDebugLoc()
1432 "No predecessors? Is the Calling Convention correct?");
1433 unsigned DestReg = UUseVReg;
1434 BuildMI(*MBB, MBB->getFirstNonPHI(), DLoc,
TII->
get(TargetOpcode::COPY),
1436 .addReg(VRegs[0].
second);
1445 UpwardsUse ? UUseVReg
1448 BuildMI(*MBB, MBB->getFirstNonPHI(), DLoc,
1449 TII->
get(TargetOpcode::PHI), PHIVReg);
1450 for (
auto BBRegPair : VRegs) {
1451 SwiftErrorPHI.
addReg(BBRegPair.second).
addMBB(BBRegPair.first);
1470 for (
auto It = Begin; It != End; ++It) {
1474 const Value *SwiftErrorAddr =
nullptr;
1479 assert(!SwiftErrorAddr &&
"Cannot have multiple swifterror arguments");
1480 SwiftErrorAddr = &*
Arg;
1482 "Must have a swifterror value argument");
1483 unsigned VReg;
bool CreatedReg;
1485 &*It, FuncInfo->
MBB, SwiftErrorAddr);
1488 if (!SwiftErrorAddr)
1492 unsigned VReg;
bool CreatedReg;
1493 std::tie(VReg, CreatedReg) =
1499 }
else if (
const LoadInst *LI = dyn_cast<const LoadInst>(&*It)) {
1500 const Value *V = LI->getOperand(0);
1504 unsigned VReg;
bool CreatedReg;
1505 std::tie(VReg, CreatedReg) =
1510 }
else if (
const StoreInst *
SI = dyn_cast<const StoreInst>(&*It)) {
1511 const Value *SwiftErrorAddr =
SI->getOperand(1);
1516 unsigned VReg;
bool CreatedReg;
1517 std::tie(VReg, CreatedReg) =
1523 }
else if (
const ReturnInst *R = dyn_cast<const ReturnInst>(&*It)) {
1524 const Function *
F = R->getParent()->getParent();
1528 unsigned VReg;
bool CreatedReg;
1536 void SelectionDAGISel::SelectAllBasicBlocks(
const Function &Fn) {
1568 ++NumFastIselFailLowerArguments;
1573 R <<
"FastISel didn't lower all arguments: " 1581 CodeGenAndEmitDAG();
1600 bool AllPredsVisited =
true;
1604 AllPredsVisited =
false;
1609 if (AllPredsVisited) {
1610 for (
const PHINode &PN : LLVMBB->phis())
1613 for (
const PHINode &PN : LLVMBB->phis())
1621 LLVMBB->getFirstNonPHI()->getIterator();
1635 if (LLVMBB->isEHPad())
1636 if (!PrepareEHLandingPad())
1644 unsigned NumFastIselRemaining = std::distance(Begin, End);
1650 for (; BI != Begin; --BI) {
1656 --NumFastIselRemaining;
1666 --NumFastIselRemaining;
1667 ++NumFastIselSuccess;
1672 while (BeforeInst != &*Begin) {
1677 if (BeforeInst != Inst && isa<LoadInst>(BeforeInst) &&
1682 --NumFastIselRemaining;
1683 ++NumFastIselSuccess;
1699 R <<
"FastISel missed call";
1702 std::string InstStrStorage;
1706 R <<
": " << InstStr.
str();
1718 bool HadTailCall =
false;
1720 SelectBasicBlock(Inst->
getIterator(), BI, HadTailCall);
1732 unsigned RemainingNow = std::distance(Begin, BI);
1733 NumFastIselFailures += NumFastIselRemaining - RemainingNow;
1734 NumFastIselRemaining = RemainingNow;
1744 R <<
"FastISel missed terminator";
1748 R <<
"FastISel missed";
1752 std::string InstStrStorage;
1755 R <<
": " << InstStr.
str();
1760 NumFastIselFailures += NumFastIselRemaining;
1768 bool FunctionBasedInstrumentation =
1771 FunctionBasedInstrumentation);
1777 ++NumFastIselBlocks;
1784 SelectBasicBlock(Begin, BI, HadTailCall);
1847 &&
"Should have a copy implying we should have 2 arguments.");
1851 if (!OPI2->
isReg() ||
1876 if (SplitPoint == BB->
begin())
1884 SplitPoint = Previous;
1885 if (Previous == Start)
1894 SelectionDAGISel::FinishBasicBlock() {
1907 "This is not a machine PHI node that we are updating!");
1926 CodeGenAndEmitDAG();
1944 SuccessMBB->
splice(SuccessMBB->
end(), ParentMBB,
1954 CodeGenAndEmitDAG();
1958 if (FailureMBB->
empty()) {
1964 CodeGenAndEmitDAG();
1982 CodeGenAndEmitDAG();
1986 for (
unsigned j = 0, ej = BTB.Cases.size(); j != ej; ++j) {
1987 UnhandledProb -= BTB.Cases[j].ExtraProb;
2002 if (BTB.ContiguousRange && j + 2 == ej) {
2005 NextMBB = BTB.Cases[j + 1].TargetBB;
2006 }
else if (j + 1 == ej) {
2008 NextMBB = BTB.Default;
2011 NextMBB = BTB.Cases[j + 1].ThisBB;
2019 CodeGenAndEmitDAG();
2021 if (BTB.ContiguousRange && j + 2 == ej) {
2023 BTB.Cases.pop_back();
2034 "This is not a machine PHI node that we are updating!");
2037 if (PHIBB == BTB.Default) {
2039 if (!BTB.ContiguousRange) {
2041 .
addMBB(BTB.Cases.back().ThisBB);
2045 for (
unsigned j = 0, ej = BTB.Cases.size();
2058 for (
unsigned i = 0, e =
SDB->
JTCases.size(); i != e; ++i) {
2069 CodeGenAndEmitDAG();
2079 CodeGenAndEmitDAG();
2087 "This is not a machine PHI node that we are updating!");
2116 CodeGenAndEmitDAG();
2126 for (
unsigned i = 0, e = Succs.
size(); i != e; ++i) {
2134 MBBI != MBBE && MBBI->isPHI(); ++MBBI) {
2137 for (
unsigned pn = 0; ; ++pn) {
2139 "Didn't find PHI entry!");
2170 int64_t DesiredMaskS)
const {
2175 if (ActualMask == DesiredMask)
2184 APInt NeededMask = DesiredMask & ~ActualMask;
2199 int64_t DesiredMaskS)
const {
2204 if (ActualMask == DesiredMask)
2213 APInt NeededMask = DesiredMask & ~ActualMask;
2230 std::vector<SDValue> InOps;
2239 if (InOps[e-1].getValueType() ==
MVT::Glue)
2243 unsigned Flags = cast<ConstantSDNode>(InOps[i])->getZExtValue();
2246 Ops.insert(Ops.end(), InOps.begin()+i,
2251 "Memory operand with multiple values?");
2253 unsigned TiedToOperand;
2257 Flags = cast<ConstantSDNode>(InOps[CurOp])->getZExtValue();
2258 for (; TiedToOperand; --TiedToOperand) {
2260 Flags = cast<ConstantSDNode>(InOps[CurOp])->getZExtValue();
2265 std::vector<SDValue> SelOps;
2276 Ops.insert(Ops.end(), SelOps.begin(), SelOps.end());
2282 if (e != InOps.size())
2283 Ops.push_back(InOps.back());
2302 bool IgnoreChains) {
2311 Visited.
insert(ImmedUse);
2316 if ((
Op.getValueType() ==
MVT::Other && IgnoreChains) || N == Def)
2318 if (!Visited.
insert(N).second)
2324 if (Root != ImmedUse) {
2328 if ((
Op.getValueType() ==
MVT::Other && IgnoreChains) || N == Def)
2330 if (!Visited.
insert(N).second)
2351 bool IgnoreChains) {
2410 IgnoreChains =
false;
2416 void SelectionDAGISel::Select_INLINEASM(
SDNode *
N) {
2429 void SelectionDAGISel::Select_READ_REGISTER(
SDNode *
Op) {
2443 void SelectionDAGISel::Select_WRITE_REGISTER(
SDNode *Op) {
2457 void SelectionDAGISel::Select_UNDEF(
SDNode *N) {
2463 GetVBR(uint64_t Val,
const unsigned char *MatcherTable,
unsigned &Idx) {
2464 assert(Val >= 128 &&
"Not a VBR");
2470 NextBits = MatcherTable[Idx++];
2471 Val |= (NextBits&127) << Shift;
2473 }
while (NextBits & 128);
2480 void SelectionDAGISel::UpdateChains(
2487 if (!ChainNodesMatched.
empty()) {
2489 "Matched input chains but didn't produce a chain");
2492 for (
unsigned i = 0, e = ChainNodesMatched.
size(); i != e; ++i) {
2493 SDNode *ChainNode = ChainNodesMatched[i];
2500 "Deleted node left in chain");
2504 if (ChainNode == NodeToMatch && isMorphNodeTo)
2514 static_cast<SDNode *
>(
nullptr));
2520 if (ChainNode != NodeToMatch && ChainNode->
use_empty() &&
2526 if (!NowDeadNodes.
empty())
2545 unsigned int Max = 8192;
2548 if (ChainNodesMatched.
size() == 1)
2549 return ChainNodesMatched[0]->getOperand(0);
2553 std::function<void(const SDValue)> AddChains = [&](
const SDValue V) {
2567 for (
auto *N : ChainNodesMatched) {
2572 while (!Worklist.
empty())
2576 if (InputChains.
size() == 0)
2586 for (
auto *N : ChainNodesMatched)
2591 if (InputChains.size() == 1)
2592 return InputChains[0];
2598 SDNode *SelectionDAGISel::
2607 int OldGlueResultNo = -1, OldChainResultNo = -1;
2611 OldGlueResultNo = NTMNumResults-1;
2612 if (NTMNumResults != 1 &&
2614 OldChainResultNo = NTMNumResults-2;
2616 OldChainResultNo = NTMNumResults-1;
2634 (
unsigned)OldGlueResultNo != ResNumResults-1)
2636 SDValue(Res, ResNumResults - 1));
2638 if ((EmitNodeInfo & OPFL_GlueOutput) != 0)
2642 if ((EmitNodeInfo &
OPFL_Chain) && OldChainResultNo != -1 &&
2643 (
unsigned)OldChainResultNo != ResNumResults-1)
2645 SDValue(Res, ResNumResults - 1));
2660 CheckSame(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2664 unsigned RecNo = MatcherTable[MatcherIndex++];
2665 assert(RecNo < RecordedNodes.size() &&
"Invalid CheckSame");
2666 return N == RecordedNodes[RecNo].first;
2696 CheckOpcode(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2698 uint16_t Opc = MatcherTable[MatcherIndex++];
2699 Opc |= (
unsigned short)MatcherTable[MatcherIndex++] << 8;
2726 return cast<CondCodeSDNode>(
N)->
get() ==
2734 if (cast<VTSDNode>(N)->getVT() == VT)
2744 int64_t Val = MatcherTable[MatcherIndex++];
2746 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2754 SDValue N,
unsigned ChildNo) {
2761 CheckAndImm(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2763 int64_t Val = MatcherTable[MatcherIndex++];
2765 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2774 CheckOrImm(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2776 int64_t Val = MatcherTable[MatcherIndex++];
2778 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2797 switch (Table[Index++]) {
2802 Result = !
::CheckSame(Table, Index, N, RecordedNodes);
2825 unsigned Res = Table[Index++];
2879 unsigned NumRecordedNodes;
2882 unsigned NumMatchedMemRefs;
2885 SDValue InputChain, InputGlue;
2888 bool HasChainNodesMatched;
2906 RecordedNodes(
RN), MatchScopes(MS) {}
2917 if (N == *NodeToMatch)
2922 for (
auto &
I : RecordedNodes)
2923 if (
I.first.getNode() ==
N)
2926 for (
auto &
I : MatchScopes)
2927 for (
auto &J :
I.NodeStack)
2928 if (J.getNode() ==
N)
2936 const unsigned char *MatcherTable,
2937 unsigned TableSize) {
2973 Select_INLINEASM(NodeToMatch);
2976 Select_READ_REGISTER(NodeToMatch);
2979 Select_WRITE_REGISTER(NodeToMatch);
2982 Select_UNDEF(NodeToMatch);
2991 NodeStack.push_back(N);
3009 SDValue InputChain, InputGlue;
3023 unsigned MatcherIndex = 0;
3025 if (!OpcodeOffset.empty()) {
3027 if (N.
getOpcode() < OpcodeOffset.size())
3028 MatcherIndex = OpcodeOffset[N.
getOpcode()];
3029 LLVM_DEBUG(
dbgs() <<
" Initial Opcode index to " << MatcherIndex <<
"\n");
3038 unsigned CaseSize = MatcherTable[Idx++];
3040 CaseSize =
GetVBR(CaseSize, MatcherTable, Idx);
3041 if (CaseSize == 0)
break;
3044 uint16_t Opc = MatcherTable[Idx++];
3045 Opc |= (
unsigned short)MatcherTable[Idx++] << 8;
3046 if (Opc >= OpcodeOffset.size())
3047 OpcodeOffset.resize((Opc+1)*2);
3048 OpcodeOffset[Opc] = Idx;
3053 if (N.
getOpcode() < OpcodeOffset.size())
3054 MatcherIndex = OpcodeOffset[N.
getOpcode()];
3058 assert(MatcherIndex < TableSize &&
"Invalid index");
3060 unsigned CurrentOpcodeIndex = MatcherIndex;
3073 unsigned NumToSkip = MatcherTable[MatcherIndex++];
3074 if (NumToSkip & 128)
3075 NumToSkip =
GetVBR(NumToSkip, MatcherTable, MatcherIndex);
3077 if (NumToSkip == 0) {
3082 FailIndex = MatcherIndex+NumToSkip;
3084 unsigned MatcherIndexOfPredicate = MatcherIndex;
3085 (void)MatcherIndexOfPredicate;
3092 Result, *
this, RecordedNodes);
3097 dbgs() <<
" Skipped scope entry (due to false predicate) at " 3098 <<
"index " << MatcherIndexOfPredicate <<
", continuing at " 3099 << FailIndex <<
"\n");
3100 ++NumDAGIselRetries;
3104 MatcherIndex = FailIndex;
3108 if (FailIndex == 0)
break;
3112 MatchScope NewEntry;
3113 NewEntry.FailIndex = FailIndex;
3114 NewEntry.NodeStack.append(NodeStack.begin(), NodeStack.end());
3115 NewEntry.NumRecordedNodes = RecordedNodes.
size();
3116 NewEntry.NumMatchedMemRefs = MatchedMemRefs.
size();
3117 NewEntry.InputChain = InputChain;
3118 NewEntry.InputGlue = InputGlue;
3119 NewEntry.HasChainNodesMatched = !ChainNodesMatched.
empty();
3125 SDNode *Parent =
nullptr;
3126 if (NodeStack.size() > 1)
3127 Parent = NodeStack[NodeStack.size()-2].getNode();
3128 RecordedNodes.
push_back(std::make_pair(N, Parent));
3145 if (
auto *MN = dyn_cast<MemSDNode>(N))
3146 MatchedMemRefs.
push_back(MN->getMemOperand());
3162 unsigned ChildNo = MatcherTable[MatcherIndex++];
3166 NodeStack.push_back(N);
3178 NodeStack.push_back(N);
3184 NodeStack.pop_back();
3185 assert(!NodeStack.empty() &&
"Node stack imbalance!");
3186 N = NodeStack.back();
3190 if (!::
CheckSame(MatcherTable, MatcherIndex, N, RecordedNodes))
break;
3195 if (!::
CheckChildSame(MatcherTable, MatcherIndex, N, RecordedNodes,
3209 unsigned OpNum = MatcherTable[MatcherIndex++];
3212 for (
unsigned i = 0; i < OpNum; ++i)
3213 Operands.
push_back(RecordedNodes[MatcherTable[MatcherIndex++]].first);
3215 unsigned PredNo = MatcherTable[MatcherIndex++];
3221 unsigned CPNum = MatcherTable[MatcherIndex++];
3222 unsigned RecNo = MatcherTable[MatcherIndex++];
3223 assert(RecNo < RecordedNodes.
size() &&
"Invalid CheckComplexPat");
3227 std::unique_ptr<MatchStateUpdater> MSU;
3229 MSU.reset(
new MatchStateUpdater(*
CurDAG, &NodeToMatch, RecordedNodes,
3233 RecordedNodes[RecNo].
first, CPNum,
3239 if (!::
CheckOpcode(MatcherTable, MatcherIndex, N.getNode()))
break;
3249 unsigned Res = MatcherTable[MatcherIndex++];
3250 if (!::
CheckType(MatcherTable, MatcherIndex, N.getValue(Res),
TLI,
3257 unsigned CurNodeOpcode = N.getOpcode();
3258 unsigned SwitchStart = MatcherIndex-1; (void)SwitchStart;
3262 CaseSize = MatcherTable[MatcherIndex++];
3264 CaseSize =
GetVBR(CaseSize, MatcherTable, MatcherIndex);
3265 if (CaseSize == 0)
break;
3267 uint16_t Opc = MatcherTable[MatcherIndex++];
3268 Opc |= (
unsigned short)MatcherTable[MatcherIndex++] << 8;
3271 if (CurNodeOpcode == Opc)
3275 MatcherIndex += CaseSize;
3279 if (CaseSize == 0)
break;
3282 LLVM_DEBUG(
dbgs() <<
" OpcodeSwitch from " << SwitchStart <<
" to " 3283 << MatcherIndex <<
"\n");
3288 MVT CurNodeVT = N.getSimpleValueType();
3289 unsigned SwitchStart = MatcherIndex-1; (void)SwitchStart;
3293 CaseSize = MatcherTable[MatcherIndex++];
3295 CaseSize =
GetVBR(CaseSize, MatcherTable, MatcherIndex);
3296 if (CaseSize == 0)
break;
3303 if (CurNodeVT == CaseVT)
3307 MatcherIndex += CaseSize;
3311 if (CaseSize == 0)
break;
3315 <<
"] from " << SwitchStart <<
" to " << MatcherIndex
3337 if (!::
CheckInteger(MatcherTable, MatcherIndex, N))
break;
3346 if (!::
CheckAndImm(MatcherTable, MatcherIndex, N, *
this))
break;
3349 if (!::
CheckOrImm(MatcherTable, MatcherIndex, N, *
this))
break;
3353 assert(NodeStack.size() != 1 &&
"No parent node");
3356 bool HasMultipleUses =
false;
3357 for (
unsigned i = 1, e = NodeStack.size()-1; i != e; ++i)
3358 if (!NodeStack[i].getNode()->hasOneUse()) {
3359 HasMultipleUses =
true;
3362 if (HasMultipleUses)
break;
3378 int64_t Val = MatcherTable[MatcherIndex++];
3380 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
3381 RecordedNodes.
push_back(std::pair<SDValue, SDNode*>(
3389 unsigned RegNo = MatcherTable[MatcherIndex++];
3390 RecordedNodes.
push_back(std::pair<SDValue, SDNode*>(
3400 unsigned RegNo = MatcherTable[MatcherIndex++];
3401 RegNo |= MatcherTable[MatcherIndex++] << 8;
3402 RecordedNodes.
push_back(std::pair<SDValue, SDNode*>(
3409 unsigned RecNo = MatcherTable[MatcherIndex++];
3410 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitConvertToTarget");
3411 SDValue Imm = RecordedNodes[RecNo].first;
3414 const ConstantInt *Val=cast<ConstantSDNode>(Imm)->getConstantIntValue();
3416 Imm.getValueType());
3418 const ConstantFP *Val=cast<ConstantFPSDNode>(Imm)->getConstantFPValue();
3420 Imm.getValueType());
3423 RecordedNodes.
push_back(std::make_pair(Imm, RecordedNodes[RecNo].
second));
3432 "EmitMergeInputChains should be the first chain producing node");
3434 "Should only have one EmitMergeInputChains per match");
3438 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitMergeInputChains");
3439 ChainNodesMatched.
push_back(RecordedNodes[RecNo].
first.getNode());
3443 if (ChainNodesMatched.
back() != NodeToMatch &&
3444 !RecordedNodes[RecNo].first.hasOneUse()) {
3445 ChainNodesMatched.
clear();
3459 "EmitMergeInputChains should be the first chain producing node");
3466 unsigned NumChains = MatcherTable[MatcherIndex++];
3467 assert(NumChains != 0 &&
"Can't TF zero chains");
3470 "Should only have one EmitMergeInputChains per match");
3473 for (
unsigned i = 0; i != NumChains; ++i) {
3474 unsigned RecNo = MatcherTable[MatcherIndex++];
3475 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitMergeInputChains");
3476 ChainNodesMatched.
push_back(RecordedNodes[RecNo].
first.getNode());
3480 if (ChainNodesMatched.
back() != NodeToMatch &&
3481 !RecordedNodes[RecNo].first.hasOneUse()) {
3482 ChainNodesMatched.
clear();
3488 if (ChainNodesMatched.
empty())
3501 unsigned RecNo = MatcherTable[MatcherIndex++];
3502 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitCopyToReg");
3503 unsigned DestPhysReg = MatcherTable[MatcherIndex++];
3509 DestPhysReg, RecordedNodes[RecNo].
first,
3512 InputGlue = InputChain.
getValue(1);
3517 unsigned XFormNo = MatcherTable[MatcherIndex++];
3518 unsigned RecNo = MatcherTable[MatcherIndex++];
3519 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitNodeXForm");
3521 RecordedNodes.
push_back(std::pair<SDValue,SDNode*>(Res,
nullptr));
3527 unsigned index = MatcherTable[MatcherIndex++];
3528 index |= (MatcherTable[MatcherIndex++] << 8);
3537 uint16_t TargetOpc = MatcherTable[MatcherIndex++];
3538 TargetOpc |= (
unsigned short)MatcherTable[MatcherIndex++] << 8;
3539 unsigned EmitNodeInfo = MatcherTable[MatcherIndex++];
3549 NumVTs = MatcherTable[MatcherIndex++];
3551 for (
unsigned i = 0; i != NumVTs; ++i) {
3567 if (VTs.
size() == 1)
3569 else if (VTs.
size() == 2)
3575 unsigned NumOps = MatcherTable[MatcherIndex++];
3577 for (
unsigned i = 0; i != NumOps; ++i) {
3578 unsigned RecNo = MatcherTable[MatcherIndex++];
3580 RecNo =
GetVBR(RecNo, MatcherTable, MatcherIndex);
3582 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitNode");
3590 FirstOpToCopy += (EmitNodeInfo &
OPFL_Chain) ? 1 : 0;
3592 "Invalid variadic node");
3595 for (
unsigned i = FirstOpToCopy, e = NodeToMatch->
getNumOperands();
3604 if (EmitNodeInfo & OPFL_Chain)
3613 if (!IsMorphNodeTo) {
3620 for (
unsigned i = 0, e = VTs.
size(); i != e; ++i) {
3627 "NodeToMatch was removed partway through selection");
3631 auto &Chain = ChainNodesMatched;
3633 "Chain node replaced during MorphNode");
3634 Chain.erase(
std::remove(Chain.begin(), Chain.end(),
N), Chain.end());
3636 Res = cast<MachineSDNode>(MorphNode(NodeToMatch, TargetOpc, VTList,
3637 Ops, EmitNodeInfo));
3642 if (EmitNodeInfo & OPFL_GlueOutput) {
3644 if (EmitNodeInfo & OPFL_Chain)
3646 }
else if (EmitNodeInfo & OPFL_Chain)
3659 bool mayLoad = MCID.
mayLoad();
3666 if (MMO->isLoad()) {
3669 }
else if (MMO->isStore()) {
3681 <<
" Dropping mem operands\n";
3682 dbgs() <<
" " << (IsMorphNodeTo ?
"Morphed" :
"Created")
3687 if (IsMorphNodeTo) {
3689 UpdateChains(Res, InputChain, ChainNodesMatched,
true);
3699 unsigned NumResults = MatcherTable[MatcherIndex++];
3701 for (
unsigned i = 0; i != NumResults; ++i) {
3702 unsigned ResSlot = MatcherTable[MatcherIndex++];
3704 ResSlot =
GetVBR(ResSlot, MatcherTable, MatcherIndex);
3706 assert(ResSlot < RecordedNodes.
size() &&
"Invalid CompleteMatch");
3707 SDValue Res = RecordedNodes[ResSlot].first;
3709 assert(i < NodeToMatch->getNumValues() &&
3712 "Invalid number of results to complete!");
3717 Res.getValueSizeInBits()) &&
3718 "invalid replacement");
3723 UpdateChains(NodeToMatch, InputChain, ChainNodesMatched,
false);
3736 "Didn't replace all uses of the node?");
3746 LLVM_DEBUG(
dbgs() <<
" Match failed at index " << CurrentOpcodeIndex
3748 ++NumDAGIselRetries;
3750 if (MatchScopes.
empty()) {
3751 CannotYetSelect(NodeToMatch);
3757 MatchScope &LastScope = MatchScopes.
back();
3758 RecordedNodes.
resize(LastScope.NumRecordedNodes);
3760 NodeStack.append(LastScope.NodeStack.begin(), LastScope.NodeStack.end());
3761 N = NodeStack.back();
3763 if (LastScope.NumMatchedMemRefs != MatchedMemRefs.
size())
3764 MatchedMemRefs.
resize(LastScope.NumMatchedMemRefs);
3765 MatcherIndex = LastScope.FailIndex;
3769 InputChain = LastScope.InputChain;
3770 InputGlue = LastScope.InputGlue;
3771 if (!LastScope.HasChainNodesMatched)
3772 ChainNodesMatched.
clear();
3777 unsigned NumToSkip = MatcherTable[MatcherIndex++];
3778 if (NumToSkip & 128)
3779 NumToSkip =
GetVBR(NumToSkip, MatcherTable, MatcherIndex);
3783 if (NumToSkip != 0) {
3784 LastScope.FailIndex = MatcherIndex+NumToSkip;
3802 if (
auto *FN = dyn_cast<FrameIndexSDNode>(N->
getOperand(0))) {
3806 int32_t Off = C->getSExtValue();
3809 return (Off >= 0) && (((A - 1) & Off) ==
unsigned(Off));
3814 void SelectionDAGISel::CannotYetSelect(
SDNode *N) {
3817 Msg <<
"Cannot select: ";
3823 Msg <<
"\nIn function: " <<
MF->
getName();
3827 cast<ConstantSDNode>(N->
getOperand(HasInputChain))->getZExtValue();
3831 Msg <<
"target intrinsic %" <<
TII->
getName(iid);
3833 Msg <<
"unknown intrinsic #" << iid;
ANNOTATION_LABEL - Represents a mid basic block label used by annotations.
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.
Return a value (possibly void), from a function.
std::vector< BitTestBlock > BitTestCases
BitTestCases - Vector of BitTestBlock structures used to communicate SwitchInst code generation infor...
Diagnostic information for ISel fallback path.
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...
SelectionDAGBuilder * SDB
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckAndImm(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const SelectionDAGISel &SDISel)
A parsed version of the target data layout string in and methods for querying it. ...
mop_iterator operands_end()
EVT getValueType() const
Return the ValueType of the referenced return value.
static SDNode * findGlueUse(SDNode *N)
findGlueUse - Return use of MVT::Glue value produced by the specified SDNode.
void EmitLiveInCopies(MachineBasicBlock *EntryMBB, const TargetRegisterInfo &TRI, const TargetInstrInfo &TII)
EmitLiveInCopies - Emit copies to initialize livein virtual registers into the given entry block...
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckCondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
bool hasPostISelHook(QueryType Type=IgnoreBundle) const
Return true if this instruction requires adjustment after instruction selection by calling a target h...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
uint64_t getZExtValue() const
Get zero extended value.
DebugLoc getCurDebugLoc() const
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
static int getNumFixedFromVariadicInfo(unsigned Flags)
getNumFixedFromVariadicInfo - Transform an EmitNode flags word into the number of fixed arity values ...
This class represents an incoming formal argument to a Function.
bool LegalizeTypes()
This transforms the SelectionDAG into a SelectionDAG that only uses types natively supported by the t...
DiagnosticInfoOptimizationBase::Argument NV
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
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 ...
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckValueType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
DELETED_NODE - This is an illegal value that is used to catch errors.
MDNODE_SDNODE - This is a node that holdes an MDNode*, which is used to reference metadata in the IR...
static unsigned virtReg2Index(unsigned Reg)
Convert a virtual register number to a 0-based index.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
MCSymbol * addLandingPad(MachineBasicBlock *LandingPad)
Add a new panding pad, and extract the exception handling information from the landingpad instruction...
void VerifyDAGDiverence()
static cl::opt< bool > ViewISelDAGs("view-isel-dags", cl::Hidden, cl::desc("Pop up a window to show isel dags as they are selected"))
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
unsigned getCatchPadExceptionPointerVReg(const Value *CPI, const TargetRegisterClass *RC)
DenseMap< MachineBasicBlock *, SmallVector< unsigned, 4 > > LPadToCallSiteMap
LPadToCallSiteMap - Map a landing pad to the call site indexes.
unsigned EnableFastISel
EnableFastISel - This flag enables fast-path instruction selection which trades away generated code q...
static void propagateSwiftErrorVRegs(FunctionLoweringInfo *FuncInfo)
Propagate swifterror values through the machine function CFG.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void ReplaceUses(SDValue F, SDValue T)
ReplaceUses - replace all uses of the old node F with the use of the new node T.
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
Sched::Preference getSchedulingPreference() const
Return target scheduling preference.
bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS, int64_t DesiredMaskS) const
CheckAndMask - The isel is trying to match something like (and X, 255).
const MachineFunctionProperties & getProperties() const
Get the function properties.
virtual unsigned getRegisterByName(const char *RegName, EVT VT, SelectionDAG &DAG) const
Return the register ID of the name passed in.
SelectionDAGBuilder - This is the common target-independent lowering implementation that is parameter...
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
virtual bool CheckNodePredicateWithOperands(SDNode *N, unsigned PredNo, const SmallVectorImpl< SDValue > &Operands) const
CheckNodePredicateWithOperands - This function is generated by tblgen in the target.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
static unsigned getFlagWord(unsigned Kind, unsigned NumOps)
Describe properties that are true of each instruction in the target description file.
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
Clients of various APIs that cause global effects on the DAG can optionally implement this interface...
unsigned getReg() const
getReg - Returns the register number.
friend struct DAGUpdateListener
DAGUpdateListener is a friend so it can manipulate the listener stack.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
bool LegalizeVectors()
This transforms the SelectionDAG into a SelectionDAG that only uses vector math operations supported ...
virtual const TargetLowering * getTargetLowering() const
iterator_range< IterTy > args() const
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
void copyToMachineFrameInfo(MachineFrameInfo &MFI) const
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
unsigned getResNo() const
Convenience function for get().getResNo().
void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH, MachineBasicBlock *SwitchBB)
visitJumpTableHeader - This function emits necessary code to produce index in the JumpTable from swit...
bool NewNodesMustHaveLegalTypes
When true, additional steps are taken to ensure that getConstant() and similar functions return DAG n...
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
bool isTerminator() const
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
Return the register class that should be used for the specified value type.
STATISTIC(NumFunctions, "Total number of functions")
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"...
unsigned const TargetRegisterInfo * TRI
bool isInteger() const
Return true if this is an integer or a vector integer type.
const MDOperand & getOperand(unsigned I) const
An instruction for reading from memory.
RegisterPassParser class - Handle the addition of new machine passes.
void setNodeId(int Id)
Set unique node id.
SDNode * getNode() const
get the SDNode which holds the desired result
static MachineBasicBlock::iterator FindSplitPointForStackProtector(MachineBasicBlock *BB)
Find the split point at which to splice the end of BB into its success stack protector check machine ...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
bool mayLoad() const
Return true if this instruction could possibly read memory.
void viewGraph(const std::string &Title)
Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckChildType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL, unsigned ChildNo)
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
EntryToken - This is the marker used to indicate the start of a region.
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE, Pass *PassPtr, const TargetLibraryInfo *LibraryInfo, LegacyDivergenceAnalysis *Divergence)
Prepare this SelectionDAG to process code in the given MachineFunction.
void setCurrentSwiftErrorVReg(const MachineBasicBlock *MBB, const Value *, unsigned)
Set the swifterror virtual register in the SwiftErrorVRegDefMap for this basic block.
static bool isUseOperandTiedToDef(unsigned Flag, unsigned &Idx)
isUseOperandTiedToDef - Return true if the flag of the inline asm operand indicates it is an use oper...
bool isReturn() const
Return true if the instruction is a return.
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
ScheduleDAGSDNodes * createHybridListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level)
createHybridListDAGScheduler - This creates a bottom up register pressure aware list scheduler that m...
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.
const TargetLibraryInfo * LibInfo
void set(const Function &Fn, MachineFunction &MF, SelectionDAG *DAG)
set - Initialize this FunctionLoweringInfo with the given Function and its associated MachineFunction...
bool isGCRelocate(ImmutableCallSite CS)
static void setupSwiftErrorVals(const Function &Fn, const TargetLowering *TLI, FunctionLoweringInfo *FuncInfo)
Set up SwiftErrorVals by going through the function.
static DIExpression * prepend(const DIExpression *Expr, bool DerefBefore, int64_t Offset=0, bool DerefAfter=false, bool StackValue=false)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value...
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
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.
bool selectInstruction(const Instruction *I)
Do "fast" instruction selection for the given LLVM IR instruction and append the generated machine in...
static bool isFoldedOrDeadInstruction(const Instruction *I, FunctionLoweringInfo *FuncInfo)
isFoldedOrDeadInstruction - Return true if the specified instruction is side-effect free and is eithe...
StackProtectorDescriptor SPDescriptor
A StackProtectorDescriptor structure used to communicate stack protector information in between Selec...
std::pair< unsigned, bool > getOrCreateSwiftErrorVRegDefAt(const Instruction *)
Get or create the swifterror value virtual register for a def of a swifterror by an instruction...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
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.
void visitSPDescriptorParent(StackProtectorDescriptor &SPD, MachineBasicBlock *ParentBB)
Codegen a new tail for a stack protector check ParentMBB which has had its tail spliced into a stack ...
SDValue getRoot()
Return the current virtual root of the Selection DAG, flushing any PendingLoad items.
void clear()
Clear state and free memory necessary to make this SelectionDAG ready to process a new block...
AnalysisUsage & addRequired()
void setLastLocalValue(MachineInstr *I)
Update the position of the last instruction emitted for materializing constants for use in the curren...
A description of a memory reference used in the backend.
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
void visitSwitchCase(CaseBlock &CB, MachineBasicBlock *SwitchBB)
visitSwitchCase - Emits the necessary code to represent a single node in the binary search tree resul...
Option class for critical edge splitting.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
virtual bool ComplexPatternFuncMutatesDAG() const
Return true if complex patterns for this target can mutate the DAG.
static bool IsLegalToFold(SDValue N, SDNode *U, SDNode *Root, CodeGenOpt::Level OptLevel, bool IgnoreChains=false)
IsLegalToFold - Returns true if the specific operand node N of U can be folded during instruction sel...
This class is basically a combination of TimeRegion and Timer.
A Use represents the edge between a Value definition and its users.
const Value * SwiftErrorArg
The swifterror argument of the current function.
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), MachineInstr opcode, and operands.
void visitJumpTable(JumpTable &JT)
visitJumpTable - Emit JumpTable node in the current MBB
DenseMap< const Value *, unsigned > ValueMap
ValueMap - Since we emit code for the function a basic block at a time, we must remember which virtua...
const TargetLowering * TLI
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
CopyToReg - This node has three operands: a chain, a register number to set to this value...
const MDNode * getMD() const
virtual bool enableMachineSchedDefaultSched() const
True if the machine scheduler should disable the TLI preference for preRA scheduling with the source ...
op_iterator op_end() const
virtual void Select(SDNode *N)=0
Main hook for targets to transform nodes into machine nodes.
ScheduleDAGSDNodes *(*)(SelectionDAGISel *, CodeGenOpt::Level) FunctionPassCtor
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
static void EnforceNodeIdInvariant(SDNode *N)
const DataLayout & getDataLayout() const
An analysis pass which caches information about the entire Module.
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckOpcode(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDNode *N)
void setFunctionLoweringInfo(FunctionLoweringInfo *FuncInfo)
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This file implements a class to represent arbitrary precision integral constant values and operations...
INLINEASM - Represents an inline asm block.
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
unsigned DAGSize
DAGSize - Size of DAG being instruction selected.
void initializeAAResultsWrapperPassPass(PassRegistry &)
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
defusechain_iterator - This class provides iterator support for machine operands in the function that...
unsigned AssignTopologicalOrder()
Topological-sort the AllNodes list and a assign a unique node id for each node in the DAG based on th...
int getArgumentFrameIndex(const Argument *A)
getArgumentFrameIndex - Get frame index for the byval argument.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
int64_t getSExtValue() const
virtual StringRef getPatternForIndex(unsigned index)
getPatternForIndex - Patterns selected by tablegen during ISEL
static bool hasExceptionPointerOrCodeUser(const CatchPadInst *CPI)
static void InvalidateNodeId(SDNode *N)
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
A constant value that is initialized with an expression using other constant values.
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Type * getType() const
All values are typed, get the type of this value.
bool getBoolValue() const
Convert APInt to a boolean value.
bool canTrap() const
Return true if evaluation of this constant could trap.
void clearKillFlags(unsigned Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
virtual bool supportSwiftError() const
Return true if the target supports swifterror attribute.
bool isSwiftError() const
Return true if this value is a swifterror value.
SDNode * mutateStrictFPToFP(SDNode *Node)
Mutate the specified strict FP node to its non-strict equivalent, unlinking the node from its chain a...
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
ScheduleDAGSDNodes * createBURRListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createBURRListDAGScheduler - This creates a bottom up register usage reduction list scheduler...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
If this edge is a critical edge, insert a new node to split the critical edge.
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...
AttributeList getAttributes() const
Return the attribute list for this Function.
An instruction for storing to memory.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
op_iterator op_begin() const
MachinePassRegistry - Track the registration of machine passes.
void init(GCFunctionInfo *gfi, AliasAnalysis *AA, const TargetLibraryInfo *li)
virtual const TargetInstrInfo * getInstrInfo() const
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification, or lowering of the constant.
~SelectionDAGISel() override
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
static MachinePassRegistry< FunctionPassCtor > Registry
RegisterScheduler class - Track the registration of instruction schedulers.
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.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
SDValue getTargetConstantFP(double Val, const SDLoc &DL, EVT VT)
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
Legacy analysis pass which computes BranchProbabilityInfo.
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
void printrFull(raw_ostream &O, const SelectionDAG *G=nullptr) const
Print a SelectionDAG node and all children down to the leaves.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
static cl::opt< bool > EnableFastISelFallbackReport("fast-isel-report-on-fallback", cl::Hidden, cl::desc("Emit a diagnostic when \ast\instruction selection " "falls back to SelectionDAG."))
UNDEF - An undefined node.
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"))
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
void finishBasicBlock()
Flush the local value map and sink local values if possible.
TargetInstrInfo - Interface to description of machine instruction set.
This corresponds to the llvm.lifetime.
MachineRegisterInfo * RegInfo
void clear()
clear - Clear out all the function-specific state.
iterator find(const_arg_type_t< KeyT > Val)
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...
bool isVoidTy() const
Return true if this is 'void'.
const BasicBlock & getEntryBlock() const
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value...
static SDValue HandleMergeInputChains(SmallVectorImpl< SDNode *> &ChainNodesMatched, SelectionDAG *CurDAG)
HandleMergeInputChains - This implements the OPC_EmitMergeInputChains operation for when the pattern ...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
CriticalEdgeSplittingOptions & setMergeIdenticalEdges()
virtual bool CheckPatternPredicate(unsigned PredNo) const
CheckPatternPredicate - This function is generated by tblgen in the target.
initializer< Ty > init(const Ty &Val)
SmallPtrSet< const Instruction *, 4 > ElidedArgCopyInstrs
void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry &)
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
CodeGenOpt::Level OptLevel
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
ScheduleDAGSDNodes - A ScheduleDAG for scheduling SDNode-based DAGs.
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
READ_REGISTER, WRITE_REGISTER - This node represents llvm.register on the DAG, which implements the n...
std::vector< std::pair< MachineInstr *, unsigned > > PHINodesToUpdate
PHINodesToUpdate - A list of phi instructions whose operand list will be updated after processing the...
unsigned const MachineRegisterInfo * MRI
ScheduleDAGSDNodes * createVLIWDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createVLIWDAGScheduler - Scheduler for VLIW targets.
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
bool HasTailCall
HasTailCall - This is set to true if a call in the current block has been translated as a tail call...
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...
bool getO0WantsFastISel()
static void preassignSwiftErrorRegs(const TargetLowering *TLI, FunctionLoweringInfo *FuncInfo, BasicBlock::const_iterator Begin, BasicBlock::const_iterator End)
void Legalize()
This transforms the SelectionDAG into a SelectionDAG that is compatible with the target instruction s...
virtual unsigned getExceptionPointerRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception address on entry to an ...
ScheduleDAGSDNodes * createDefaultScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createDefaultScheduler - This creates an instruction scheduler appropriate for the target...
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM Basic Block Representation.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
DISubprogram * getSubprogram() const
Get the attached subprogram.
Value * getAddress() const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
std::pair< unsigned, bool > getOrCreateSwiftErrorVRegUseAt(const Instruction *, const MachineBasicBlock *, const Value *)
MachineInstrBuilder & UseMI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
void removeDeadCode(MachineBasicBlock::iterator I, MachineBasicBlock::iterator E)
Remove all dead instructions between the I and E.
iterator_range< value_op_iterator > op_values() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
const SDValue & getOperand(unsigned Num) const
ScheduleDAGSDNodes * createILPListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level)
createILPListDAGScheduler - This creates a bottom up register pressure aware list scheduler that trie...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ConstantFP - Floating Point Values [float, double].
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
DIExpression * getExpression() const
virtual unsigned getExceptionSelectorRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception typeid on entry to a la...
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag...
void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Represent the analysis usage information of a pass.
void Combine(CombineLevel Level, AliasAnalysis *AA, CodeGenOpt::Level OptLevel)
This iterates over the nodes in the SelectionDAG, folding certain types of nodes together, or eliminating superfluous nodes.
This class provides iterator support for SDUse operands that use a specific SDNode.
use_instr_iterator use_instr_begin(unsigned RegNo) const
bool tryToFoldLoad(const LoadInst *LI, const Instruction *FoldInst)
We're checking to see if we can fold LI into FoldInst.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckChildInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, unsigned ChildNo)
static unsigned getMemoryConstraintID(unsigned Flag)
bool lowerArguments()
Do "fast" instruction selection for function arguments and append the machine instructions to the cur...
static void replace(Module &M, GlobalVariable *Old, GlobalVariable *New)
static cl::opt< bool > UseMBPI("use-mbpi", cl::desc("use Machine Branch Probability Info"), cl::init(true), cl::Hidden)
const APInt & getAPIntValue() const
Interval::pred_iterator pred_end(Interval *I)
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
void setHasInlineAsm(bool B)
Set a flag that indicates that the function contains inline assembly.
virtual void PostprocessISelDAG()
PostprocessISelDAG() - This hook allows the target to hack on the graph right after selection...
void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
self_iterator getIterator()
void AddLiveOutRegInfo(unsigned Reg, unsigned NumSignBits, const KnownBits &Known)
AddLiveOutRegInfo - Adds LiveOutInfo for a register.
virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void getLocation(StringRef &RelativePath, unsigned &Line, unsigned &Column) const
Return location information for this diagnostic in three parts: the relative source file path...
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
static unsigned getFlagWordForMem(unsigned InputFlag, unsigned Constraint)
Augment an existing flag word returned by getFlagWord with the constraint code for a memory constrain...
static cl::opt< int > EnableFastISelAbort("fast-isel-abort", cl::Hidden, cl::desc("Enable abort calls when \ast\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."))
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
unsigned ExceptionPointerVirtReg
If the current MBB is a landing pad, the exception pointer and exception selector registers are copie...
bool succ_empty(const Instruction *I)
SmallPtrSet< const BasicBlock *, 4 > VisitedBBs
VisitedBBs - The set of basic blocks visited thus far by instruction selection.
static void reportFastISelFailure(MachineFunction &MF, OptimizationRemarkEmitter &ORE, OptimizationRemarkMissed &R, bool ShouldAbort)
static bool isMemKind(unsigned Flag)
bool isImplicitDef() const
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckOrImm(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const SelectionDAGISel &SDISel)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
void ComputePHILiveOutRegInfo(const PHINode *)
ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination register based on the LiveOutI...
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
static void SplitCriticalSideEffectEdges(Function &Fn, DominatorTree *DT, LoopInfo *LI)
SplitCriticalSideEffectEdges - Look for critical edges with a PHI value that may trap on it...
unsigned getNumOperands() const
Return the number of values used by this operation.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
HANDLENODE node - Used as a handle for various purposes.
const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
MachineBasicBlock * MBB
MBB - The current block.
virtual bool enableMachineScheduler() const
True if the subtarget should run MachineScheduler after aggressive coalescing.
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
bool isOrEquivalentToAdd(const SDNode *N) const
TargetIntrinsicInfo - Interface to description of machine instruction set.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N)
void recomputeInsertPt()
Reset InsertPt to prepare for inserting instructions into the current block.
bool use_empty() const
Return true if there are no uses of this node.
bool SplitCSR
True if part of the CSRs will be handled via explicit copies.
static void mapWasmLandingPadIndex(MachineBasicBlock *MBB, const CatchPadInst *CPI)
TokenFactor - This node takes multiple tokens as input and produces a single token result...
void dump() const
Dump this node, for debugging.
void visitSPDescriptorFailure(StackProtectorDescriptor &SPD)
Codegen the failure basic block for a stack protector check.
ScheduleDAGSDNodes * createSourceListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createBURRListDAGScheduler - This creates a bottom up list scheduler that schedules nodes in source c...
bool memoperands_empty() const
Iterator for intrusive lists based on ilist_node.
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...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
virtual void initializeSplitCSR(MachineBasicBlock *Entry) const
Perform necessary initialization to handle a subset of CSRs explicitly via copies.
This is the shared class of boolean and integer constants.
BlockVerifier::State From
virtual bool CheckComplexPattern(SDNode *Root, SDNode *Parent, SDValue N, unsigned PatternNo, SmallVectorImpl< std::pair< SDValue, SDNode *> > &Result)
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
DenseMap< std::pair< const MachineBasicBlock *, const Value * >, unsigned > SwiftErrorVRegDefMap
A map from swifterror value in a basic block to the virtual register it is currently represented by...
std::string getMsg() const
DenseMap< unsigned, unsigned > RegFixups
RegFixups - Registers which need to be replaced after isel is done.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
bool isDebugValue() const
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
SmallVector< MachineInstr *, 8 > ArgDbgValues
ArgDbgValues - A list of DBG_VALUE instructions created during isel for function arguments that are i...
void clear()
Clear out the current SelectionDAG and the associated state and prepare this SelectionDAGBuilder obje...
void setFastISel(bool Enable)
static void createSwiftErrorEntriesInEntryBlock(FunctionLoweringInfo *FuncInfo, FastISel *FastIS, const TargetLowering *TLI, const TargetInstrInfo *TII, SelectionDAGBuilder *SDB)
An SDNode that represents everything that will be needed to construct a MachineInstr.
SelectionDAGISel(TargetMachine &tm, CodeGenOpt::Level OL=CodeGenOpt::Default)
void visit(const Instruction &I)
LLVM_NODISCARD T pop_back_val()
static void processDbgDeclares(FunctionLoweringInfo *FuncInfo)
Collect llvm.dbg.declare information.
DenseMap< std::pair< const MachineBasicBlock *, const Value * >, unsigned > SwiftErrorVRegUpwardsUse
A list of upward exposed vreg uses that need to be satisfied by either a copy def or a phi node at th...
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last)
UpdateSplitBlock - When an MBB was split during scheduling, update the references that need to refer ...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static cl::opt< bool > ViewLegalizeTypesDAGs("view-legalize-types-dags", cl::Hidden, cl::desc("Pop up a window to show dags before legalize types"))
allnodes_const_iterator allnodes_begin() const
virtual void AdjustInstrPostInstrSelection(MachineInstr &MI, SDNode *Node) const
This method should be implemented by targets that mark instructions with the 'hasPostISelHook' flag...
unsigned getNumArgOperands() const
getNumArgOperands - Return the number of funcletpad arguments.
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N)
const Function & getFunction() const
Return the LLVM function that this machine code represents.
unsigned CreateRegs(Type *Ty)
CreateRegs - Allocate the appropriate number of virtual registers of the correctly promoted or expand...
void startNewBlock()
Set the current block to which generated machine instructions will be appended.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static cl::opt< bool > ViewLegalizeDAGs("view-legalize-dags", cl::Hidden, cl::desc("Pop up a window to show dags before legalize"))
void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef< unsigned > Sites)
Map the landing pad's EH symbol to the call site indexes.
Class for arbitrary precision integers.
iterator_range< use_iterator > uses()
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
void visitBitTestCase(BitTestBlock &BB, MachineBasicBlock *NextMBB, BranchProbability BranchProbToNext, unsigned Reg, BitTestCase &B, MachineBasicBlock *SwitchBB)
visitBitTestCase - this function produces one "bit test"
BranchProbabilityInfo * BPI
This file defines the FastISel class.
ArrayRef< std::pair< unsigned, unsigned > > liveins() const
static use_iterator use_end()
iterator_range< user_iterator > users()
std::vector< JumpTableBlock > JTCases
JTCases - Vector of JumpTable structures used to communicate SwitchInst code generation information...
bool mayStore() const
Return true if this instruction could possibly modify memory.
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
virtual Value * getSSPStackGuardCheck(const Module &M) const
If the target has a standard stack protection check function that performs validation and error handl...
amdgpu Simplify well known AMD library false Value Value * Arg
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
TargetSubtargetInfo - Generic base class for all target subtargets.
int getNodeId() const
Return the unique node id.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Represents a use of a SDNode.
unsigned ExceptionSelectorVirtReg
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Bitwise operators - logical and, logical or, logical xor.
bool isOnlyUserOf(const SDNode *N) const
Return true if this node is the only use of N.
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 '...
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
LLVM_NODISCARD bool empty() const
bool isTokenTy() const
Return true if this is 'token'.
virtual void viewGraph(const Twine &Name, const Twine &Title)
Pops up a GraphViz/gv window with the ScheduleDAG rendered using 'dot'.
virtual void insertCopiesSplitCSR(MachineBasicBlock *Entry, const SmallVectorImpl< MachineBasicBlock *> &Exits) const
Insert explicit copies in entry and exit blocks.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
StringRef getName() const
Return a constant reference to the value's name.
virtual const TargetIntrinsicInfo * getIntrinsicInfo() const
If intrinsic information is available, return it. If not, return null.
Establish a view to a call site for examination.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
static bool MIIsInTerminatorSequence(const MachineInstr &MI)
Given that the input MI is before a partial terminator sequence TSeq, return true if M + TSeq also a ...
void initializeGCModuleInfoPass(PassRegistry &)
static cl::opt< bool > ViewSUnitDAGs("view-sunit-dags", cl::Hidden, cl::desc("Pop up a window to show SUnit dags after they are processed"))
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
bool isCall() const
Return true if the instruction is a call.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
MachineBasicBlock::iterator InsertPt
MBB - The current insert position inside the current block.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void Run(SelectionDAG *dag, MachineBasicBlock *bb)
Run - perform scheduling.
OptLevelChanger(SelectionDAGISel &ISel, CodeGenOpt::Level NewOptLevel)
DILocalVariable * getVariable() const
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
unsigned getOpcode() const
SDValue getValue(unsigned R) const
virtual bool CheckNodePredicate(SDNode *N, unsigned PredNo) const
CheckNodePredicate - This function is generated by tblgen in the target.
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
DenseMap< const AllocaInst *, int > StaticAllocaMap
StaticAllocaMap - Keep track of frame indices for fixed sized allocas in the entry block...
void setOptLevel(CodeGenOpt::Level Level)
Overrides the optimization level.
std::unique_ptr< OptimizationRemarkEmitter > ORE
Current optimization remark emitter.
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID, std::vector< SDValue > &OutOps)
SelectInlineAsmMemoryOperand - Select the specified address as a target addressing mode...
bool isStatepoint(ImmutableCallSite CS)
bool callsFunctionThatReturnsTwice() const
callsFunctionThatReturnsTwice - Return true if the function has a call to setjmp or other function th...
void setWasmLandingPadIndex(const MachineBasicBlock *LPad, unsigned Index)
Map the landing pad to its index. Used for Wasm exception handling.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS, int64_t DesiredMaskS) const
CheckOrMask - The isel is trying to match something like (or X, 255).
This class is used to form a handle around another node that is persistent and is updated across invo...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasProperty(Property P) const
A raw_ostream that writes to an std::string.
void InvalidatePHILiveOutRegInfo(const PHINode *PN)
InvalidatePHILiveOutRegInfo - Invalidates a PHI's LiveOutInfo, to be called when a block is visited b...
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"))
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
SDValue getRegister(unsigned Reg, EVT VT)
mop_iterator operands_begin()
virtual FastISel * createFastISel(FunctionLoweringInfo &, const TargetLibraryInfo *) const
This method returns a target specific FastISel object, or null if the target does not support "fast" ...
void SelectInlineAsmMemoryOperands(std::vector< SDValue > &Ops, const SDLoc &DL)
SelectInlineAsmMemoryOperands - Calls to this are automatically generated by tblgen.
virtual MachineBasicBlock * EmitSchedule(MachineBasicBlock::iterator &InsertPos)
EmitSchedule - Insert MachineInstrs into the MachineBasicBlock according to the order specified in Se...
virtual void finalizeLowering(MachineFunction &MF) const
Execute target specific actions to finalize target lowering.
static use_instr_iterator use_instr_end()
llvm::DenseMap< PointerIntPair< const Instruction *, 1, bool >, unsigned > SwiftErrorVRegDefUses
A map from instructions that define/use a swifterror value to the virtual register that represents th...
const DILocalVariable * getDebugVariable() const
Return the debug variable referenced by this DBG_VALUE instruction.
static cl::opt< bool > ViewSchedDAGs("view-sched-dags", cl::Hidden, cl::desc("Pop up a window to show sched dags as they are processed"))
std::vector< CaseBlock > SwitchCases
SwitchCases - Vector of CaseBlock structures used to communicate SwitchInst code generation informati...
Primary interface to the complete machine description for the target machine.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Machine Instruction Scheduler
DenseMap< const BasicBlock *, MachineBasicBlock * > MBBMap
MBBMap - A mapping from LLVM basic blocks to their machine code entry.
SDValue getControlRoot()
Similar to getRoot, but instead of flushing all the PendingLoad items, flush all the PendingExports i...
bool hasOneUse() const
Return true if there is exactly one user of this value.
void ReplaceNode(SDNode *F, SDNode *T)
Replace all uses of F with T, then remove F from the DAG.
StringRef - Represent a constant reference to a string, i.e.
void clearDanglingDebugInfo()
Clear the dangling debug information map.
SwiftErrorValues SwiftErrorVals
A function can only have a single swifterror argument.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
const TargetLowering * TLI
void salvageDebugInfo(SDNode &N)
To be invoked on an SDNode that is slated to be erased.
virtual void PreprocessISelDAG()
PreprocessISelDAG - This hook allows targets to hack on the graph before instruction selection starts...
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.
unsigned getNumOperands() const
bool isStrictFPOpcode()
Test if this node is a strict floating point pseudo-op.
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"))
const SDValue & getOperand(unsigned i) const
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
SDNode * getUser()
This returns the SDNode that contains this Use.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
virtual RegisterScheduler::FunctionPassCtor getDAGScheduler(CodeGenOpt::Level) const
Target can subclass this hook to select a different DAG scheduler.
bool shouldEmitSDCheck(const BasicBlock &BB) const
void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand *> NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
const MachineOperand & getOperand(unsigned i) const
virtual StringRef getIncludePathForIndex(unsigned index)
getIncludePathForIndex - get the td source location of pattern instantiation
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
const TargetInstrInfo * TII
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, int Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable.
This represents the llvm.dbg.declare instruction.
bool isIndirectDebugValue() const
A DBG_VALUE is indirect iff the first operand is a register and the second operand is an immediate...
void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB)
visitBitTestHeader - This function emits necessary code to produce value suitable for "bit tests" ...
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.
bool isExportedInst(const Value *V)
isExportedInst - Return true if the specified value is an instruction exported from its block...
PointerType * getType() const
Global values are always pointers.
FunctionLoweringInfo * FuncInfo
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
A wrapper class for inspecting calls to intrinsic functions.
This file describes how to lower LLVM code to machine code.
virtual SDValue RunSDNodeXForm(SDValue V, unsigned XFormNo)
bool hasCalls() const
Return true if the current function has any function calls.
an instruction to allocate memory on the stack
This class is used by SelectionDAGISel to temporarily override the optimization level on a per-functi...
void SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable, unsigned TableSize)
unsigned getOrCreateSwiftErrorVReg(const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register in SwiftErrorVRegDefMap for this basic block...
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
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 int getUninvalidatedNodeId(SDNode *N)
static RegisterScheduler defaultListDAGScheduler("default", "Best scheduler for the target", createDefaultScheduler)