101 using namespace llvm;
103 #define DEBUG_TYPE "isel"
105 STATISTIC(NumFastIselFailures,
"Number of instructions fast isel failed on");
106 STATISTIC(NumFastIselSuccess,
"Number of instructions fast isel selected");
107 STATISTIC(NumFastIselBlocks,
"Number of blocks selected entirely by fast isel");
108 STATISTIC(NumDAGBlocks,
"Number of blocks selected using DAG");
109 STATISTIC(NumDAGIselRetries,
"Number of times dag isel has to try another path");
110 STATISTIC(NumEntryBlocks,
"Number of entry blocks encountered");
112 "Number of entry blocks where fast isel failed to lower arguments");
116 cl::desc(
"Enable abort calls when \"fast\" instruction selection "
117 "fails to lower an instruction: 0 disable the abort, 1 will "
118 "abort but for args, calls and terminators, 2 will also "
119 "abort for argument lowering, and 3 will never fallback "
120 "to SelectionDAG."));
124 cl::desc(
"Emit a diagnostic when \"fast\" instruction selection "
125 "falls back to SelectionDAG."));
129 cl::desc(
"use Machine Branch Probability Info"),
135 cl::desc(
"Only display the basic block whose name "
136 "matches this for all view-*-dags options"));
139 cl::desc(
"Pop up a window to show dags before the first "
140 "dag combine pass"));
143 cl::desc(
"Pop up a window to show dags before legalize types"));
146 cl::desc(
"Pop up a window to show dags before legalize"));
149 cl::desc(
"Pop up a window to show dags before the second "
150 "dag combine pass"));
153 cl::desc(
"Pop up a window to show dags before the post legalize types"
154 " dag combine pass"));
157 cl::desc(
"Pop up a window to show isel dags as they are selected"));
160 cl::desc(
"Pop up a window to show sched dags as they are processed"));
163 cl::desc(
"Pop up a window to show SUnit dags after they are processed"));
189 cl::desc(
"Instruction schedulers available (before register"
210 if (NewOptLevel == SavedOptLevel)
214 DEBUG(
dbgs() <<
"\nChanging optimization level for Function "
216 DEBUG(
dbgs() <<
"\tBefore: -O" << SavedOptLevel
217 <<
" ; After: -O" << NewOptLevel <<
"\n");
230 DEBUG(
dbgs() <<
"\nRestoring optimization level for Function "
233 <<
" ; After: -O" << SavedOptLevel <<
"\n");
250 return SchedulerCtor(IS, OptLevel);
264 "Unknown sched type!");
283 dbgs() <<
"If a target marks an instruction with "
284 "'usesCustomInserter', it must implement "
285 "TargetLowering::EmitInstrWithCustomInserter!";
293 "If a target marks an instruction with 'hasPostISelHook', "
294 "it must implement TargetLowering::AdjustInstrPostInstrSelection!");
360 if (!CE || !CE->
canTrap())
continue;
385 "-fast-isel-abort > 0 requires -fast-isel");
405 LibInfo = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
406 GFI = Fn.
hasGC() ? &getAnalysis<GCModuleInfo>().getFunctionInfo(Fn) :
nullptr;
407 ORE = make_unique<OptimizationRemarkEmitter>(&Fn);
408 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
410 auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
411 LoopInfo *LI = LIWP ? &LIWP->getLoopInfo() :
nullptr;
426 FuncInfo->
BPI = &getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI();
431 AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
452 if (isa<UnreachableInst>(Term) || isa<ReturnInst>(Term))
466 SelectAllBasicBlocks(Fn);
483 if (!MBB.succ_empty())
487 if (Term != MBB.end() && Term->isReturn()) {
500 LiveInMap.
insert(std::make_pair(LI->first, LI->second));
517 DEBUG(
dbgs() <<
"Dropping debug info for dead vreg"
523 if (LDI != LiveInMap.
end()) {
524 assert(!hasFI &&
"There's no handling of frame pointer updating here yet "
533 assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
534 "Expected inlined-at fields to agree");
536 BuildMI(*EntryMBB, ++InsertPos, DL,
TII->
get(TargetOpcode::DBG_VALUE),
537 IsIndirect, LDI->second,
Offset, Variable, Expr);
549 CopyUseMI =
UseMI;
continue;
552 CopyUseMI =
nullptr;
break;
559 CopyUseMI->getOperand(0).getReg(),
Offset, Variable, Expr);
568 for (
const auto &MBB : *
MF) {
569 if (MFI.
hasCalls() && MF->hasInlineAsm())
572 for (
const auto &
MI : MBB) {
575 MI.isStackAligningInlineAsm()) {
578 if (
MI.isInlineAsm()) {
579 MF->setHasInlineAsm(
true);
593 unsigned From =
I->first;
594 unsigned To =
I->second;
623 DEBUG(
dbgs() <<
"*** MachineFunction at end of ISel ***\n");
636 R << (
" (in function: " + MF.
getName() +
")").str();
663 void SelectionDAGISel::ComputeLiveOutVRegInfo() {
675 if (!VisitedNodes.
insert(N).second)
700 }
while (!Worklist.
empty());
703 void SelectionDAGISel::CodeGenAndEmitDAG() {
705 StringRef GroupDescription =
"Instruction Selection and Scheduling";
706 std::string BlockName;
707 int BlockNumber = -1;
709 bool MatchFilterBB =
false; (void)MatchFilterBB;
729 DEBUG(
dbgs() <<
"Initial selection DAG: BB#" << BlockNumber
730 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
742 DEBUG(
dbgs() <<
"Optimized lowered selection DAG: BB#" << BlockNumber
743 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
757 DEBUG(
dbgs() <<
"Type-legalized selection DAG: BB#" << BlockNumber
758 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
774 DEBUG(
dbgs() <<
"Optimized type-legalized selection DAG: BB#" << BlockNumber
775 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
785 DEBUG(
dbgs() <<
"Vector-legalized selection DAG: BB#" << BlockNumber
786 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
794 DEBUG(
dbgs() <<
"Vector/type-legalized selection DAG: BB#" << BlockNumber
795 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
807 DEBUG(
dbgs() <<
"Optimized vector-legalized selection DAG: BB#"
808 << BlockNumber <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
820 DEBUG(
dbgs() <<
"Legalized selection DAG: BB#" << BlockNumber
821 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
833 DEBUG(
dbgs() <<
"Optimized legalized selection DAG: BB#" << BlockNumber
834 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
837 ComputeLiveOutVRegInfo();
847 DoInstructionSelection();
850 DEBUG(
dbgs() <<
"Selected selection DAG: BB#" << BlockNumber
851 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
881 if (FirstMBB != LastMBB)
904 :
SelectionDAG::DAGUpdateListener(DAG), ISelPosition(isp) {}
917 void SelectionDAGISel::DoInstructionSelection() {
918 DEBUG(
dbgs() <<
"===== Instruction selection begins: BB#"
938 ISelUpdater ISU(*
CurDAG, ISelPosition);
945 SDNode *Node = &*--ISelPosition;
971 DEBUG(
dbgs() <<
"===== Instruction selection ends:\n");
978 if (
const IntrinsicInst *EHPtrCall = dyn_cast<IntrinsicInst>(U)) {
980 if (IID == Intrinsic::eh_exceptionpointer ||
981 IID == Intrinsic::eh_exceptioncode)
990 bool SelectionDAGISel::PrepareEHLandingPad() {
999 if (
const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->
getFirstNonPHI())) {
1004 assert(EHPhysReg &&
"target lacks exception pointer register");
1008 TII->
get(TargetOpcode::COPY), VReg)
1045 !isa<TerminatorInst>(
I) &&
1046 !isa<DbgInfoIntrinsic>(I) &&
1065 bool HaveSeenSwiftErrorArg =
false;
1068 if (AI->hasSwiftErrorAttr()) {
1069 assert(!HaveSeenSwiftErrorArg &&
1070 "Must have only one swifterror parameter");
1071 (void)HaveSeenSwiftErrorArg;
1072 HaveSeenSwiftErrorArg =
true;
1077 for (
const auto &LLVMBB : Fn)
1078 for (
const auto &Inst : LLVMBB) {
1079 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(&Inst))
1080 if (Alloca->isSwiftError())
1099 "expected to insert into entry block");
1142 Address = Address->stripAndAccumulateInBoundsConstantOffsets(DL,
Offset);
1148 if (
const auto *AI = dyn_cast<AllocaInst>(Address)) {
1152 }
else if (
const auto *Arg = dyn_cast<Argument>(Address))
1159 if (
Offset.getBoolValue())
1169 auto *TLI = FuncInfo->
TLI;
1170 if (!TLI->supportSwiftError())
1188 auto Key = std::make_pair(MBB, SwiftErrorVal);
1192 unsigned UUseVReg = UpwardsUse ? UUseIt->second : 0;
1194 assert(!(UpwardsUse && !DownwardDef) &&
1195 "We can't have an upwards use but no downwards def");
1200 if (!UpwardsUse && DownwardDef)
1211 if (!Visited.
insert(Pred).second)
1224 UUseVReg = UUseIt->second;
1231 VRegs.
size() >= 1 &&
1234 [&](
const std::pair<const MachineBasicBlock *, unsigned> &V)
1235 ->
bool {
return V.second != VRegs[0].second; }) !=
1240 if (!UpwardsUse && !needPHI) {
1242 "No predecessors? The entry block should bail out earlier");
1248 auto DLoc = isa<Instruction>(SwiftErrorVal)
1249 ? dyn_cast<Instruction>(SwiftErrorVal)->getDebugLoc()
1256 unsigned DestReg = UUseVReg;
1259 .addReg(VRegs[0].
second);
1266 auto const *RC = TLI->getRegClassFor(TLI->getPointerTy(
DL));
1268 UpwardsUse ? UUseVReg
1272 TII->get(TargetOpcode::PHI), PHIVReg);
1273 for (
auto BBRegPair : VRegs) {
1274 SwiftErrorPHI.
addReg(BBRegPair.second).
addMBB(BBRegPair.first);
1293 for (
auto It = Begin; It !=
End; ++It) {
1297 const Value *SwiftErrorAddr =
nullptr;
1298 for (
auto &Arg : CS.
args()) {
1299 if (!Arg->isSwiftError())
1302 assert(!SwiftErrorAddr &&
"Cannot have multiple swifterror arguments");
1303 SwiftErrorAddr = &*Arg;
1305 "Must have a swifterror value argument");
1306 unsigned VReg;
bool CreatedReg;
1308 &*It, FuncInfo->
MBB, SwiftErrorAddr);
1311 if (!SwiftErrorAddr)
1315 unsigned VReg;
bool CreatedReg;
1316 std::tie(VReg, CreatedReg) =
1322 }
else if (
const LoadInst *LI = dyn_cast<const LoadInst>(&*It)) {
1323 const Value *V = LI->getOperand(0);
1327 unsigned VReg;
bool CreatedReg;
1328 std::tie(VReg, CreatedReg) =
1333 }
else if (
const StoreInst *
SI = dyn_cast<const StoreInst>(&*It)) {
1334 const Value *SwiftErrorAddr =
SI->getOperand(1);
1339 unsigned VReg;
bool CreatedReg;
1340 std::tie(VReg, CreatedReg) =
1346 }
else if (
const ReturnInst *R = dyn_cast<const ReturnInst>(&*It)) {
1347 const Function *
F = R->getParent()->getParent();
1351 unsigned VReg;
bool CreatedReg;
1359 void SelectionDAGISel::SelectAllBasicBlocks(
const Function &Fn) {
1387 ++NumFastIselFailLowerArguments;
1392 R <<
"FastISel didn't lower all arguments: "
1400 CodeGenAndEmitDAG();
1418 bool AllPredsVisited =
true;
1422 AllPredsVisited =
false;
1427 if (AllPredsVisited) {
1456 if (!PrepareEHLandingPad())
1464 unsigned NumFastIselRemaining = std::distance(Begin, End);
1470 for (; BI != Begin; --BI) {
1476 --NumFastIselRemaining;
1486 --NumFastIselRemaining;
1487 ++NumFastIselSuccess;
1492 while (BeforeInst != &*Begin) {
1497 if (BeforeInst != Inst && isa<LoadInst>(BeforeInst) &&
1502 --NumFastIselRemaining;
1503 ++NumFastIselSuccess;
1519 R <<
"FastISel missed call";
1522 std::string InstStrStorage;
1526 R <<
": " << InstStr.str();
1531 if (!Inst->getType()->isVoidTy() && !Inst->getType()->isTokenTy() &&
1532 !Inst->use_empty()) {
1538 bool HadTailCall =
false;
1540 SelectBasicBlock(Inst->getIterator(), BI, HadTailCall);
1552 unsigned RemainingNow = std::distance(Begin, BI);
1553 NumFastIselFailures += NumFastIselRemaining - RemainingNow;
1554 NumFastIselRemaining = RemainingNow;
1559 Inst->getDebugLoc(), LLVMBB);
1562 if (isa<TerminatorInst>(Inst)) {
1564 R <<
"FastISel missed terminator";
1568 R <<
"FastISel missed";
1572 std::string InstStrStorage;
1575 R <<
": " << InstStr.str();
1580 NumFastIselFailures += NumFastIselRemaining;
1587 if (getAnalysis<StackProtector>().shouldEmitSDCheck(*LLVMBB)) {
1588 bool FunctionBasedInstrumentation =
1591 FunctionBasedInstrumentation);
1597 ++NumFastIselBlocks;
1604 SelectBasicBlock(Begin, BI, HadTailCall);
1663 &&
"Should have a copy implying we should have 2 arguments.");
1667 if (!OPI2->
isReg() ||
1692 if (SplitPoint == BB->
begin())
1700 SplitPoint = Previous;
1701 if (Previous == Start)
1710 SelectionDAGISel::FinishBasicBlock() {
1711 DEBUG(
dbgs() <<
"Total amount of phi nodes to update: "
1714 dbgs() <<
"Node " << i <<
" : ("
1723 "This is not a machine PHI node that we are updating!");
1742 CodeGenAndEmitDAG();
1760 SuccessMBB->
splice(SuccessMBB->
end(), ParentMBB,
1770 CodeGenAndEmitDAG();
1774 if (FailureMBB->
empty()) {
1780 CodeGenAndEmitDAG();
1798 CodeGenAndEmitDAG();
1802 for (
unsigned j = 0, ej = BTB.Cases.size(); j != ej; ++j) {
1803 UnhandledProb -= BTB.Cases[j].ExtraProb;
1818 if (BTB.ContiguousRange && j + 2 == ej) {
1821 NextMBB = BTB.Cases[j + 1].TargetBB;
1822 }
else if (j + 1 == ej) {
1824 NextMBB = BTB.Default;
1827 NextMBB = BTB.Cases[j + 1].ThisBB;
1835 CodeGenAndEmitDAG();
1837 if (BTB.ContiguousRange && j + 2 == ej) {
1839 BTB.Cases.pop_back();
1850 "This is not a machine PHI node that we are updating!");
1853 if (PHIBB == BTB.Default) {
1855 if (!BTB.ContiguousRange) {
1857 .addMBB(BTB.Cases.back().ThisBB);
1861 for (
unsigned j = 0, ej = BTB.Cases.size();
1874 for (
unsigned i = 0, e =
SDB->
JTCases.size(); i != e; ++i) {
1885 CodeGenAndEmitDAG();
1895 CodeGenAndEmitDAG();
1903 "This is not a machine PHI node that we are updating!");
1932 CodeGenAndEmitDAG();
1942 for (
unsigned i = 0, e = Succs.
size(); i != e; ++i) {
1950 MBBI != MBBE && MBBI->isPHI(); ++MBBI) {
1953 for (
unsigned pn = 0; ; ++pn) {
1955 "Didn't find PHI entry!");
1986 int64_t DesiredMaskS)
const {
1991 if (ActualMask == DesiredMask)
2000 APInt NeededMask = DesiredMask & ~ActualMask;
2015 int64_t DesiredMaskS)
const {
2020 if (ActualMask == DesiredMask)
2029 APInt NeededMask = DesiredMask & ~ActualMask;
2048 std::vector<SDValue> InOps;
2057 if (InOps[e-1].getValueType() ==
MVT::Glue)
2061 unsigned Flags = cast<ConstantSDNode>(InOps[i])->getZExtValue();
2064 Ops.insert(Ops.end(), InOps.begin()+i,
2069 "Memory operand with multiple values?");
2071 unsigned TiedToOperand;
2075 Flags = cast<ConstantSDNode>(InOps[CurOp])->getZExtValue();
2076 for (; TiedToOperand; --TiedToOperand) {
2078 Flags = cast<ConstantSDNode>(InOps[CurOp])->getZExtValue();
2083 std::vector<SDValue> SelOps;
2094 Ops.insert(Ops.end(), SelOps.begin(), SelOps.end());
2100 if (e != InOps.size())
2101 Ops.push_back(InOps.back());
2122 bool IgnoreChains) {
2131 std::vector<SDNode *> WorkList;
2132 WorkList.push_back(Use);
2134 while (!WorkList.empty()) {
2135 Use = WorkList.back();
2136 WorkList.pop_back();
2142 if (!Visited.
insert(Use).second)
2152 if (Use == ImmedUse || Use == Root)
2159 WorkList.push_back(N);
2177 bool IgnoreChains) {
2236 IgnoreChains =
false;
2243 void SelectionDAGISel::Select_INLINEASM(
SDNode *N) {
2256 void SelectionDAGISel::Select_READ_REGISTER(
SDNode *
Op) {
2270 void SelectionDAGISel::Select_WRITE_REGISTER(
SDNode *Op) {
2284 void SelectionDAGISel::Select_UNDEF(
SDNode *N) {
2290 GetVBR(uint64_t Val,
const unsigned char *MatcherTable,
unsigned &Idx) {
2291 assert(Val >= 128 &&
"Not a VBR");
2297 NextBits = MatcherTable[Idx++];
2298 Val |= (NextBits&127) << Shift;
2300 }
while (NextBits & 128);
2307 void SelectionDAGISel::UpdateChains(
2314 if (!ChainNodesMatched.
empty()) {
2316 "Matched input chains but didn't produce a chain");
2319 for (
unsigned i = 0, e = ChainNodesMatched.
size(); i != e; ++i) {
2320 SDNode *ChainNode = ChainNodesMatched[i];
2327 "Deleted node left in chain");
2331 if (ChainNode == NodeToMatch && isMorphNodeTo)
2341 static_cast<SDNode *
>(
nullptr));
2346 if (ChainNode != NodeToMatch && ChainNode->
use_empty() &&
2352 if (!NowDeadNodes.
empty())
2355 DEBUG(
dbgs() <<
"ISEL: Match complete!\n");
2381 E = ChainedNode->
use_end(); UI !=
E; ++UI) {
2383 if (UI.getUse().getValueType() !=
MVT::Other)
continue;
2393 unsigned UserOpcode = User->
getOpcode();
2420 ChainedNodesInPattern.
end(), User))
2458 auto MemoizeResult = TokenFactorResult.
find(User);
2459 bool Visited = MemoizeResult != TokenFactorResult.
end();
2462 auto Res =
WalkChainUsers(User, ChainedNodesInPattern, TokenFactorResult,
2463 InteriorChainedNodes);
2464 MemoizeResult = TokenFactorResult.
insert(std::make_pair(User, Res)).first;
2466 switch (MemoizeResult->second) {
2511 for (
unsigned i = 0, e = ChainNodesMatched.
size(); i != e; ++i) {
2521 for (
unsigned i = 0, e = ChainNodesMatched.
size(); i != e; ++i) {
2524 SDNode *N = ChainNodesMatched[i];
2530 SDValue InChain = ChainNodesMatched[i]->getOperand(0);
2545 if (InputChains.
size() == 1)
2546 return InputChains[0];
2552 SDNode *SelectionDAGISel::
2561 int OldGlueResultNo = -1, OldChainResultNo = -1;
2565 OldGlueResultNo = NTMNumResults-1;
2566 if (NTMNumResults != 1 &&
2568 OldChainResultNo = NTMNumResults-2;
2570 OldChainResultNo = NTMNumResults-1;
2588 (
unsigned)OldGlueResultNo != ResNumResults-1)
2590 SDValue(Res, ResNumResults-1));
2592 if ((EmitNodeInfo & OPFL_GlueOutput) != 0)
2596 if ((EmitNodeInfo &
OPFL_Chain) && OldChainResultNo != -1 &&
2597 (
unsigned)OldChainResultNo != ResNumResults-1)
2599 SDValue(Res, ResNumResults-1));
2613 CheckSame(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2617 unsigned RecNo = MatcherTable[MatcherIndex++];
2618 assert(RecNo < RecordedNodes.size() &&
"Invalid CheckSame");
2619 return N == RecordedNodes[RecNo].first;
2649 CheckOpcode(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2651 uint16_t Opc = MatcherTable[MatcherIndex++];
2652 Opc |= (
unsigned short)MatcherTable[MatcherIndex++] << 8;
2679 return cast<CondCodeSDNode>(
N)->
get() ==
2687 if (cast<VTSDNode>(N)->getVT() == VT)
2697 int64_t Val = MatcherTable[MatcherIndex++];
2699 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2707 SDValue N,
unsigned ChildNo) {
2714 CheckAndImm(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2716 int64_t Val = MatcherTable[MatcherIndex++];
2718 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2727 CheckOrImm(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2729 int64_t Val = MatcherTable[MatcherIndex++];
2731 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2750 switch (Table[Index++]) {
2755 Result = !
::CheckSame(Table, Index, N, RecordedNodes);
2826 unsigned NumRecordedNodes;
2829 unsigned NumMatchedMemRefs;
2832 SDValue InputChain, InputGlue;
2835 bool HasChainNodesMatched;
2852 :
SelectionDAG::DAGUpdateListener(DAG), NodeToMatch(NodeToMatch),
2853 RecordedNodes(
RN), MatchScopes(MS) {}
2864 if (N == *NodeToMatch)
2869 for (
auto &
I : RecordedNodes)
2870 if (
I.first.getNode() ==
N)
2873 for (
auto &
I : MatchScopes)
2874 for (
auto &J :
I.NodeStack)
2875 if (J.getNode() ==
N)
2883 const unsigned char *MatcherTable,
2884 unsigned TableSize) {
2920 Select_INLINEASM(NodeToMatch);
2923 Select_READ_REGISTER(NodeToMatch);
2926 Select_WRITE_REGISTER(NodeToMatch);
2929 Select_UNDEF(NodeToMatch);
2938 NodeStack.push_back(N);
2956 SDValue InputChain, InputGlue;
2964 DEBUG(
dbgs() <<
"ISEL: Starting pattern match on root node: ";
2972 unsigned MatcherIndex = 0;
2974 if (!OpcodeOffset.empty()) {
2976 if (N.
getOpcode() < OpcodeOffset.size())
2977 MatcherIndex = OpcodeOffset[N.
getOpcode()];
2978 DEBUG(
dbgs() <<
" Initial Opcode index to " << MatcherIndex <<
"\n");
2987 unsigned CaseSize = MatcherTable[Idx++];
2989 CaseSize =
GetVBR(CaseSize, MatcherTable, Idx);
2990 if (CaseSize == 0)
break;
2993 uint16_t Opc = MatcherTable[Idx++];
2994 Opc |= (
unsigned short)MatcherTable[Idx++] << 8;
2995 if (Opc >= OpcodeOffset.size())
2996 OpcodeOffset.resize((Opc+1)*2);
2997 OpcodeOffset[Opc] = Idx;
3002 if (N.
getOpcode() < OpcodeOffset.size())
3003 MatcherIndex = OpcodeOffset[N.
getOpcode()];
3007 assert(MatcherIndex < TableSize &&
"Invalid index");
3009 unsigned CurrentOpcodeIndex = MatcherIndex;
3022 unsigned NumToSkip = MatcherTable[MatcherIndex++];
3023 if (NumToSkip & 128)
3024 NumToSkip =
GetVBR(NumToSkip, MatcherTable, MatcherIndex);
3026 if (NumToSkip == 0) {
3031 FailIndex = MatcherIndex+NumToSkip;
3033 unsigned MatcherIndexOfPredicate = MatcherIndex;
3034 (void)MatcherIndexOfPredicate;
3041 Result, *
this, RecordedNodes);
3045 DEBUG(
dbgs() <<
" Skipped scope entry (due to false predicate) at "
3046 <<
"index " << MatcherIndexOfPredicate
3047 <<
", continuing at " << FailIndex <<
"\n");
3048 ++NumDAGIselRetries;
3052 MatcherIndex = FailIndex;
3056 if (FailIndex == 0)
break;
3060 MatchScope NewEntry;
3061 NewEntry.FailIndex = FailIndex;
3062 NewEntry.NodeStack.append(NodeStack.begin(), NodeStack.end());
3063 NewEntry.NumRecordedNodes = RecordedNodes.
size();
3064 NewEntry.NumMatchedMemRefs = MatchedMemRefs.
size();
3065 NewEntry.InputChain = InputChain;
3066 NewEntry.InputGlue = InputGlue;
3067 NewEntry.HasChainNodesMatched = !ChainNodesMatched.
empty();
3073 SDNode *Parent =
nullptr;
3074 if (NodeStack.size() > 1)
3075 Parent = NodeStack[NodeStack.size()-2].getNode();
3076 RecordedNodes.
push_back(std::make_pair(N, Parent));
3093 MatchedMemRefs.
push_back(cast<MemSDNode>(N)->getMemOperand());
3104 unsigned ChildNo = MatcherTable[MatcherIndex++];
3108 NodeStack.push_back(N);
3120 NodeStack.push_back(N);
3126 NodeStack.pop_back();
3127 assert(!NodeStack.empty() &&
"Node stack imbalance!");
3128 N = NodeStack.back();
3132 if (!::
CheckSame(MatcherTable, MatcherIndex, N, RecordedNodes))
break;
3137 if (!::
CheckChildSame(MatcherTable, MatcherIndex, N, RecordedNodes,
3151 unsigned CPNum = MatcherTable[MatcherIndex++];
3152 unsigned RecNo = MatcherTable[MatcherIndex++];
3153 assert(RecNo < RecordedNodes.
size() &&
"Invalid CheckComplexPat");
3157 std::unique_ptr<MatchStateUpdater> MSU;
3159 MSU.reset(
new MatchStateUpdater(*
CurDAG, &NodeToMatch, RecordedNodes,
3163 RecordedNodes[RecNo].
first, CPNum,
3169 if (!::
CheckOpcode(MatcherTable, MatcherIndex, N.getNode()))
break;
3179 unsigned CurNodeOpcode = N.getOpcode();
3180 unsigned SwitchStart = MatcherIndex-1; (void)SwitchStart;
3184 CaseSize = MatcherTable[MatcherIndex++];
3186 CaseSize =
GetVBR(CaseSize, MatcherTable, MatcherIndex);
3187 if (CaseSize == 0)
break;
3189 uint16_t Opc = MatcherTable[MatcherIndex++];
3190 Opc |= (
unsigned short)MatcherTable[MatcherIndex++] << 8;
3193 if (CurNodeOpcode == Opc)
3197 MatcherIndex += CaseSize;
3201 if (CaseSize == 0)
break;
3204 DEBUG(
dbgs() <<
" OpcodeSwitch from " << SwitchStart
3205 <<
" to " << MatcherIndex <<
"\n");
3210 MVT CurNodeVT = N.getSimpleValueType();
3211 unsigned SwitchStart = MatcherIndex-1; (void)SwitchStart;
3215 CaseSize = MatcherTable[MatcherIndex++];
3217 CaseSize =
GetVBR(CaseSize, MatcherTable, MatcherIndex);
3218 if (CaseSize == 0)
break;
3225 if (CurNodeVT == CaseVT)
3229 MatcherIndex += CaseSize;
3233 if (CaseSize == 0)
break;
3236 DEBUG(
dbgs() <<
" TypeSwitch[" <<
EVT(CurNodeVT).getEVTString()
3237 <<
"] from " << SwitchStart <<
" to " << MatcherIndex<<
'\n');
3258 if (!::
CheckInteger(MatcherTable, MatcherIndex, N))
break;
3267 if (!::
CheckAndImm(MatcherTable, MatcherIndex, N, *
this))
break;
3270 if (!::
CheckOrImm(MatcherTable, MatcherIndex, N, *
this))
break;
3274 assert(NodeStack.size() != 1 &&
"No parent node");
3277 bool HasMultipleUses =
false;
3278 for (
unsigned i = 1, e = NodeStack.size()-1; i != e; ++i)
3279 if (!NodeStack[i].getNode()->hasOneUse()) {
3280 HasMultipleUses =
true;
3283 if (HasMultipleUses)
break;
3299 int64_t Val = MatcherTable[MatcherIndex++];
3301 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
3302 RecordedNodes.
push_back(std::pair<SDValue, SDNode*>(
3310 unsigned RegNo = MatcherTable[MatcherIndex++];
3311 RecordedNodes.
push_back(std::pair<SDValue, SDNode*>(
3321 unsigned RegNo = MatcherTable[MatcherIndex++];
3322 RegNo |= MatcherTable[MatcherIndex++] << 8;
3323 RecordedNodes.
push_back(std::pair<SDValue, SDNode*>(
3330 unsigned RecNo = MatcherTable[MatcherIndex++];
3331 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitConvertToTarget");
3332 SDValue Imm = RecordedNodes[RecNo].first;
3335 const ConstantInt *Val=cast<ConstantSDNode>(Imm)->getConstantIntValue();
3337 Imm.getValueType());
3339 const ConstantFP *Val=cast<ConstantFPSDNode>(Imm)->getConstantFPValue();
3341 Imm.getValueType());
3344 RecordedNodes.
push_back(std::make_pair(Imm, RecordedNodes[RecNo].
second));
3353 "EmitMergeInputChains should be the first chain producing node");
3355 "Should only have one EmitMergeInputChains per match");
3359 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitMergeInputChains");
3360 ChainNodesMatched.
push_back(RecordedNodes[RecNo].
first.getNode());
3364 if (ChainNodesMatched.
back() != NodeToMatch &&
3365 !RecordedNodes[RecNo].first.hasOneUse()) {
3366 ChainNodesMatched.
clear();
3380 "EmitMergeInputChains should be the first chain producing node");
3387 unsigned NumChains = MatcherTable[MatcherIndex++];
3388 assert(NumChains != 0 &&
"Can't TF zero chains");
3391 "Should only have one EmitMergeInputChains per match");
3394 for (
unsigned i = 0; i != NumChains; ++i) {
3395 unsigned RecNo = MatcherTable[MatcherIndex++];
3396 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitMergeInputChains");
3397 ChainNodesMatched.
push_back(RecordedNodes[RecNo].
first.getNode());
3401 if (ChainNodesMatched.
back() != NodeToMatch &&
3402 !RecordedNodes[RecNo].first.hasOneUse()) {
3403 ChainNodesMatched.
clear();
3409 if (ChainNodesMatched.
empty())
3422 unsigned RecNo = MatcherTable[MatcherIndex++];
3423 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitCopyToReg");
3424 unsigned DestPhysReg = MatcherTable[MatcherIndex++];
3430 DestPhysReg, RecordedNodes[RecNo].
first,
3433 InputGlue = InputChain.
getValue(1);
3438 unsigned XFormNo = MatcherTable[MatcherIndex++];
3439 unsigned RecNo = MatcherTable[MatcherIndex++];
3440 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitNodeXForm");
3442 RecordedNodes.
push_back(std::pair<SDValue,SDNode*>(Res,
nullptr));
3448 unsigned index = MatcherTable[MatcherIndex++];
3449 index |= (MatcherTable[MatcherIndex++] << 8);
3458 uint16_t TargetOpc = MatcherTable[MatcherIndex++];
3459 TargetOpc |= (
unsigned short)MatcherTable[MatcherIndex++] << 8;
3460 unsigned EmitNodeInfo = MatcherTable[MatcherIndex++];
3470 NumVTs = MatcherTable[MatcherIndex++];
3472 for (
unsigned i = 0; i != NumVTs; ++i) {
3480 if (EmitNodeInfo & OPFL_Chain)
3482 if (EmitNodeInfo & OPFL_GlueOutput)
3488 if (VTs.
size() == 1)
3490 else if (VTs.
size() == 2)
3496 unsigned NumOps = MatcherTable[MatcherIndex++];
3498 for (
unsigned i = 0; i != NumOps; ++i) {
3499 unsigned RecNo = MatcherTable[MatcherIndex++];
3501 RecNo =
GetVBR(RecNo, MatcherTable, MatcherIndex);
3503 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitNode");
3511 FirstOpToCopy += (EmitNodeInfo &
OPFL_Chain) ? 1 : 0;
3513 "Invalid variadic node");
3516 for (
unsigned i = FirstOpToCopy, e = NodeToMatch->
getNumOperands();
3525 if (EmitNodeInfo & OPFL_Chain)
3534 if (!IsMorphNodeTo) {
3541 for (
unsigned i = 0, e = VTs.
size(); i != e; ++i) {
3548 "NodeToMatch was removed partway through selection");
3551 auto &Chain = ChainNodesMatched;
3553 "Chain node replaced during MorphNode");
3554 Chain.erase(
std::remove(Chain.begin(), Chain.end(),
N), Chain.end());
3556 Res = MorphNode(NodeToMatch, TargetOpc, VTList, Ops, EmitNodeInfo);
3561 if (EmitNodeInfo & OPFL_GlueOutput) {
3563 if (EmitNodeInfo & OPFL_Chain)
3565 }
else if (EmitNodeInfo & OPFL_Chain)
3578 bool mayLoad = MCID.
mayLoad();
3581 unsigned NumMemRefs = 0;
3583 MatchedMemRefs.
begin(), E = MatchedMemRefs.
end();
I !=
E; ++
I) {
3584 if ((*I)->isLoad()) {
3587 }
else if ((*I)->isStore()) {
3600 MatchedMemRefs.
begin(), E = MatchedMemRefs.
end();
I !=
E; ++
I) {
3601 if ((*I)->isLoad()) {
3604 }
else if ((*I)->isStore()) {
3612 cast<MachineSDNode>(Res)
3613 ->setMemRefs(MemRefs, MemRefs + NumMemRefs);
3617 << (IsMorphNodeTo ?
"Morphed" :
"Created")
3621 if (IsMorphNodeTo) {
3623 UpdateChains(Res, InputChain, ChainNodesMatched,
true);
3633 unsigned NumResults = MatcherTable[MatcherIndex++];
3635 for (
unsigned i = 0; i != NumResults; ++i) {
3636 unsigned ResSlot = MatcherTable[MatcherIndex++];
3638 ResSlot =
GetVBR(ResSlot, MatcherTable, MatcherIndex);
3640 assert(ResSlot < RecordedNodes.
size() &&
"Invalid CompleteMatch");
3641 SDValue Res = RecordedNodes[ResSlot].first;
3643 assert(i < NodeToMatch->getNumValues() &&
3646 "Invalid number of results to complete!");
3651 Res.getValueSizeInBits()) &&
3652 "invalid replacement");
3657 UpdateChains(NodeToMatch, InputChain, ChainNodesMatched,
false);
3670 "Didn't replace all uses of the node?");
3680 DEBUG(
dbgs() <<
" Match failed at index " << CurrentOpcodeIndex <<
"\n");
3681 ++NumDAGIselRetries;
3683 if (MatchScopes.
empty()) {
3684 CannotYetSelect(NodeToMatch);
3690 MatchScope &LastScope = MatchScopes.
back();
3691 RecordedNodes.
resize(LastScope.NumRecordedNodes);
3693 NodeStack.append(LastScope.NodeStack.begin(), LastScope.NodeStack.end());
3694 N = NodeStack.back();
3696 if (LastScope.NumMatchedMemRefs != MatchedMemRefs.
size())
3697 MatchedMemRefs.
resize(LastScope.NumMatchedMemRefs);
3698 MatcherIndex = LastScope.FailIndex;
3700 DEBUG(
dbgs() <<
" Continuing at " << MatcherIndex <<
"\n");
3702 InputChain = LastScope.InputChain;
3703 InputGlue = LastScope.InputGlue;
3704 if (!LastScope.HasChainNodesMatched)
3705 ChainNodesMatched.
clear();
3710 unsigned NumToSkip = MatcherTable[MatcherIndex++];
3711 if (NumToSkip & 128)
3712 NumToSkip =
GetVBR(NumToSkip, MatcherTable, MatcherIndex);
3716 if (NumToSkip != 0) {
3717 LastScope.FailIndex = MatcherIndex+NumToSkip;
3728 void SelectionDAGISel::CannotYetSelect(
SDNode *N) {
3731 Msg <<
"Cannot select: ";
3737 Msg <<
"\nIn function: " <<
MF->
getName();
3741 cast<ConstantSDNode>(N->
getOperand(HasInputChain))->getZExtValue();
3745 Msg <<
"target intrinsic %" <<
TII->
getName(iid);
3747 Msg <<
"unknown intrinsic #" << iid;
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.
bool use_empty() const
Return true if there are no uses of this node.
std::vector< BitTestBlock > BitTestCases
BitTestCases - Vector of BitTestBlock structures used to communicate SwitchInst code generation infor...
Diagnostic information for ISel fallback path.
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
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()
SDValue getValue(unsigned R) const
bool hasPostISelHook(QueryType Type=IgnoreBundle) const
Return true if this instruction requires adjustment after instruction selection by calling a target h...
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)
virtual bool enableMachineScheduler() const
True if the subtarget should run MachineScheduler after aggressive coalescing.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, unsigned Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable.
void preassignSwiftErrorRegs(const TargetLowering *TLI, FunctionLoweringInfo *FuncInfo, BasicBlock::const_iterator Begin, BasicBlock::const_iterator End)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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
typename SuperClass::const_iterator const_iterator
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.
STATISTIC(NumFunctions,"Total number of functions")
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.
virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
livein_iterator livein_end() const
MCSymbol * addLandingPad(MachineBasicBlock *LandingPad)
Add a new panding pad. Returns the label ID for the landing pad entry.
bool hasProperty(Property P) const
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)
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.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
void ReplaceUses(SDValue F, SDValue T)
ReplaceUses - replace all uses of the old node F with the use of the new node T.
virtual void insertCopiesSplitCSR(MachineBasicBlock *Entry, const SmallVectorImpl< MachineBasicBlock * > &Exits) const
Insert explicit copies in entry and exit blocks.
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
bool isReturn() const
Return true if the instruction is a return.
SelectionDAGBuilder - This is the common target-independent lowering implementation that is parameter...
bool mayStore() const
Return true if this instruction could possibly modify memory.
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...
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 ...
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckPatternPredicate(const unsigned char *MatcherTable, unsigned &MatcherIndex, const SelectionDAGISel &SDISel)
CheckPatternPredicate - Implements OP_CheckPatternPredicate.
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...
static const MCPhysReg VRegs[32]
unsigned getNumOperands() const
Return the number of values used by this operation.
bool isEHPad() const
Return true if this basic block is an exception handling block.
unsigned getNumOperands() const
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned Num) const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
An instruction for reading from memory.
RegisterPassParser class - Handle the addition of new machine passes.
void setNodeId(int Id)
Set unique node id.
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 ...
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.
virtual unsigned getExceptionPointerRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception address on entry to an ...
void viewGraph(const std::string &Title)
Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE)
Prepare this SelectionDAG to process code in the given MachineFunction.
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckChildType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL, unsigned ChildNo)
DebugLoc getCurDebugLoc() const
EntryToken - This is the marker used to indicate the start of a region.
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...
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.
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
StringRef getName() const
Return a constant reference to the value's name.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
AttributeList getAttributes() const
Return the attribute list for this Function.
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)
bool isVector() const
Return true if this is a vector value type.
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 ...
Value * getAddress() const
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.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
static bool findNonImmUse(SDNode *Use, SDNode *Def, SDNode *ImmedUse, SDNode *Root, SmallPtrSetImpl< SDNode * > &Visited, bool IgnoreChains)
findNonImmUse - Return true if "Use" is a non-immediate use of "Def".
bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS, int64_t DesiredMaskS) const
CheckAndMask - The isel is trying to match something like (and X, 255).
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...
const HexagonInstrInfo * TII
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 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.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
A Use represents the edge between a Value definition and its users.
static SDValue HandleMergeInputChains(SmallVectorImpl< SDNode * > &ChainNodesMatched, SelectionDAG *CurDAG)
HandleMergeInputChains - This implements the OPC_EmitMergeInputChains operation for when the pattern ...
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...
use_instr_iterator use_instr_begin(unsigned RegNo) const
const TargetLowering * TLI
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
bool isCall() const
Return true if the instruction is a call.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
CopyToReg - This node has three operands: a chain, a register number to set to this value...
static MachinePassRegistry Registry
RegisterScheduler class - Track the registration of instruction schedulers.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
const MachineFunctionProperties & getProperties() const
Get the function properties.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Reg
All possible values of the reg field in the ModR/M byte.
virtual void Select(SDNode *N)=0
Main hook for targets to transform nodes into machine nodes.
ScheduleDAGSDNodes *(*)(SelectionDAGISel *, CodeGenOpt::Level) FunctionPassCtor
void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const
Return location information for this diagnostic in three parts: the source file name, line number and column.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
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)
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...
Sched::Preference getSchedulingPreference() const
Return target scheduling preference.
bool isInteger() const
Return true if this is an integer or a vector integer type.
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.
LLVM_NODISCARD bool empty() const
unsigned DAGSize
DAGSize - Size of DAG being instruction selected.
void initializeAAResultsWrapperPassPass(PassRegistry &)
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.
const MachineBasicBlock & front() const
virtual StringRef getPatternForIndex(unsigned index)
getPatternForIndex - Patterns selected by tablegen during ISEL
static bool hasExceptionPointerOrCodeUser(const CatchPadInst *CPI)
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.
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
ScheduleDAGSDNodes * createHybridListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level)
createHybridListDAGScheduler - This creates a bottom up register pressure aware list scheduler that m...
SDNode * mutateStrictFPToFP(SDNode *Node)
Mutate the specified strict FP node to its non-strict equivalent, unlinking the node from its chain a...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
virtual void AdjustInstrPostInstrSelection(MachineInstr &MI, SDNode *Node) const
This method should be implemented by targets that mark instructions with the 'hasPostISelHook' flag...
An instruction for storing to memory.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
const APInt & getAPIntValue() const
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
MachinePassRegistry - Track the registration of machine passes.
void init(GCFunctionInfo *gfi, AliasAnalysis *AA, const TargetLibraryInfo *li)
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 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.
ScheduleDAGSDNodes * createSourceListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createBURRListDAGScheduler - This creates a bottom up list scheduler that schedules nodes in source c...
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
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 DataLayout & getDataLayout() const
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.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
UNDEF - An undefined node.
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.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
virtual bool supportSwiftError() const
Return true if the target supports swifterror attribute.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
const MachineBasicBlock * getParent() const
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)
virtual void initializeSplitCSR(MachineBasicBlock *Entry) const
Perform necessary initialization to handle a subset of CSRs explicitly via copies.
bool isDebugValue() const
bool isImplicitDef() const
SDNode * getNode() const
get the SDNode which holds the desired result
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.
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 void finalizeLowering(MachineFunction &MF) const
Execute target specific actions to finalize target lowering.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
BasicBlock * SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
If this edge is a critical edge, insert a new node to split the critical edge.
CriticalEdgeSplittingOptions & setMergeIdenticalEdges()
initializer< Ty > init(const Ty &Val)
virtual FastISel * createFastISel(FunctionLoweringInfo &, const TargetLibraryInfo *) const
This method returns a target specific FastISel object, or null if the target does not support "fast" ...
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.
iterator_range< IterTy > args() const
ScheduleDAGSDNodes - A ScheduleDAG for scheduling SDNode-based DAGs.
READ_REGISTER, WRITE_REGISTER - This node represents llvm.register on the DAG, which implements the 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."))
Subclasses of this class are all able to terminate a basic block.
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
virtual bool CheckNodePredicate(SDNode *N, unsigned PredNo) const
CheckNodePredicate - This function is generated by tblgen in the target.
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
ScheduleDAGSDNodes * createVLIWDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createVLIWDAGScheduler - Scheduler for VLIW targets.
bool HasTailCall
HasTailCall - This is set to true if a call in the current block has been translated as a tail call...
bool getO0WantsFastISel()
void Legalize()
This transforms the SelectionDAG into a SelectionDAG that is compatible with the target instruction s...
ScheduleDAGSDNodes * createDefaultScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createDefaultScheduler - This creates an instruction scheduler appropriate for the target...
LLVM Basic Block Representation.
const SDValue & getOperand(unsigned i) const
bool canTrap() const
Return true if evaluation of this constant could trap.
DIExpression * getExpression() const
ScheduleDAGSDNodes * createBURRListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createBURRListDAGScheduler - This creates a bottom up register usage reduction list scheduler...
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
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...
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
bool isIndirectDebugValue() const
A DBG_VALUE is indirect iff the first operand is a register and the second operand is an immediate...
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...
const MachineOperand & getOperand(unsigned i) const
bool succ_empty(const BasicBlock *BB)
static ChainResult WalkChainUsers(const SDNode *ChainedNode, SmallVectorImpl< SDNode * > &ChainedNodesInPattern, DenseMap< const SDNode *, ChainResult > &TokenFactorResult, SmallVectorImpl< SDNode * > &InteriorChainedNodes)
WalkChainUsers - Walk down the users of the specified chained node that is part of the pattern we're ...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
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...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
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.
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...
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.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
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)
void printrFull(raw_ostream &O, const SelectionDAG *G=nullptr) const
Print a SelectionDAG node and all children down to the leaves.
bool lowerArguments()
Do "fast" instruction selection for function arguments and append the machine instructions to the cur...
std::vector< std::pair< unsigned, unsigned >>::const_iterator livein_iterator
virtual unsigned getRegisterByName(const char *RegName, EVT VT, SelectionDAG &DAG) const
Return the register ID of the name passed in.
static const unsigned End
unsigned getOpcode() const
static cl::opt< bool > UseMBPI("use-mbpi", cl::desc("use Machine Branch Probability Info"), cl::init(true), cl::Hidden)
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.
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
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"))
iterator_range< pred_iterator > predecessors()
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
static unsigned getFlagWordForMem(unsigned InputFlag, unsigned Constraint)
Augment an existing flag word returned by getFlagWord with the constraint code for a memory constrain...
const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
unsigned ExceptionPointerVirtReg
If the current MBB is a landing pad, the exception pointer and exception selector registers are copie...
SmallPtrSet< const BasicBlock *, 4 > VisitedBBs
VisitedBBs - The set of basic blocks visited thus far by instruction selection.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
static void reportFastISelFailure(MachineFunction &MF, OptimizationRemarkEmitter &ORE, OptimizationRemarkMissed &R, bool ShouldAbort)
static bool isMemKind(unsigned Flag)
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...
void ComputePHILiveOutRegInfo(const PHINode *)
ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination register based on the LiveOutI...
static void SplitCriticalSideEffectEdges(Function &Fn, DominatorTree *DT, LoopInfo *LI)
SplitCriticalSideEffectEdges - Look for critical edges with a PHI value that may trap on it...
HANDLENODE node - Used as a handle for various purposes.
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
MachineBasicBlock * MBB
MBB - The current block.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
virtual bool enableMachineSchedDefaultSched() const
True if the machine scheduler should disable the TLI preference for preRA scheduling with the source ...
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
TargetIntrinsicInfo - Interface to description of machine instruction set.
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 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.
virtual Value * getSSPStackGuardCheck(const Module &M) const
If the target has a standard stack protection check function that performs validation and error handl...
bool hasCalls() const
Return true if the current function has any function calls.
bool SplitCSR
True if part of the CSRs will be handled via explicit copies.
TokenFactor - This node takes multiple tokens as input and produces a single token result...
void visitSPDescriptorFailure(StackProtectorDescriptor &SPD)
Codegen the failure basic block for a stack protector check.
const MDOperand & getOperand(unsigned I) const
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
ScheduleDAGSDNodes * createILPListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level)
createILPListDAGScheduler - This creates a bottom up register pressure aware list scheduler that trie...
void dump() const
Dump this node, for debugging.
allnodes_const_iterator allnodes_begin() const
void computeKnownBits(SDValue Op, KnownBits &Known, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
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...
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...
SDNode * SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT)
These are used for target selectors to mutate the specified node to have the specified return type...
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...
virtual const TargetLowering * getTargetLowering() const
void setFastISel(bool Enable)
static void createSwiftErrorEntriesInEntryBlock(FunctionLoweringInfo *FuncInfo, FastISel *FastIS, const TargetLowering *TLI, const TargetInstrInfo *TII, SelectionDAGBuilder *SDB)
SelectionDAGISel(TargetMachine &tm, CodeGenOpt::Level OL=CodeGenOpt::Default)
bool isSwiftError() const
Return true if this value is a swifterror value.
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
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...
bool mayLoad() const
Return true if this instruction could possibly read memory.
livein_iterator livein_begin() const
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckNodePredicate(const unsigned char *MatcherTable, unsigned &MatcherIndex, const SelectionDAGISel &SDISel, SDNode *N)
CheckNodePredicate - Implements OP_CheckNodePredicate.
Represents one node in the SelectionDAG.
const BasicBlock & getEntryBlock() const
virtual bool CheckComplexPattern(SDNode *Root, SDNode *Parent, SDValue N, unsigned PatternNo, SmallVectorImpl< std::pair< SDValue, SDNode * > > &Result)
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 ...
static cl::opt< bool > ViewLegalizeTypesDAGs("view-legalize-types-dags", cl::Hidden, cl::desc("Pop up a window to show dags before legalize types"))
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N)
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, and clear the local C...
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.
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
Class for arbitrary precision integers.
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"
DISubprogram * getSubprogram() const
Get the attached subprogram.
BranchProbabilityInfo * BPI
int64_t getSExtValue() const
op_iterator op_begin() const
This file defines the FastISel class.
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
Return the register class that should be used for the specified value type.
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...
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
iterator_range< value_op_iterator > op_values() const
llvm_unreachable("Unknown RegBank!")
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.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
static std::vector< std::string > Flags
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Represents a use of a SDNode.
PointerType * getType() const
Global values are always pointers.
unsigned ExceptionSelectorVirtReg
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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...
std::string getMsg() const
Bitwise operators - logical and, logical or, logical xor.
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.
virtual const TargetIntrinsicInfo * getIntrinsicInfo() const
If intrinsic information is available, return it. If not, return null.
virtual void viewGraph(const Twine &Name, const Twine &Title)
Pops up a GraphViz/gv window with the ScheduleDAG rendered using 'dot'.
Establish a view to a call site for examination.
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 ...
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
void ReplaceAllUsesWith(SDValue From, SDValue Op)
Modify anything using 'From' to use 'To' instead.
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"))
bool isLandingPad() const
Return true if this basic block is a landing pad.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
bool callsFunctionThatReturnsTwice() const
callsFunctionThatReturnsTwice - Return true if the function has a call to setjmp or other function th...
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
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."))
typename std::vector< NodeRef >::reverse_iterator rpo_iterator
void clearKillFlags(unsigned Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
MachineBasicBlock::iterator InsertPt
MBB - The current insert position inside the current block.
op_iterator op_end() const
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)
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
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.
bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS, int64_t DesiredMaskS) const
CheckOrMask - The isel is trying to match something like (or X, 255).
std::unique_ptr< OptimizationRemarkEmitter > ORE
Current optimization remark emitter.
int getNodeId() const
Return the unique node id.
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
EVT getValueType() const
Return the ValueType of the referenced return value.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID, std::vector< SDValue > &OutOps)
SelectInlineAsmMemoryOperand - Select the specified address as a target addressing mode...
const DILocalVariable * getDebugVariable() const
Return the debug variable referenced by this DBG_VALUE instruction.
bool isStatepoint(ImmutableCallSite CS)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
unsigned getReg() const
getReg - Returns the register number.
const MDNode * getMD() const
DILocalVariable * getVariable() const
virtual bool CheckPatternPredicate(unsigned PredNo) const
CheckPatternPredicate - This function is generated by tblgen in the target.
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())
A raw_ostream that writes to an std::string.
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...
void InvalidatePHILiveOutRegInfo(const PHINode *PN)
InvalidatePHILiveOutRegInfo - Invalidates a PHI's LiveOutInfo, to be called when a block is visited b...
virtual const TargetInstrInfo * getInstrInfo() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
SDValue getRegister(unsigned Reg, EVT VT)
mop_iterator operands_begin()
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...
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
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...
static DIExpression * prepend(const DIExpression *DIExpr, bool Deref, int64_t Offset=0, bool StackValue=false)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value...
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...
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...
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.Val alone...
Primary interface to the complete machine description for the target machine.
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...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
static Expected< std::string > replace(StringRef S, StringRef From, StringRef To)
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...
void clearDanglingDebugInfo()
Clear the dangling debug information map.
SwiftErrorValues SwiftErrorVals
A function can only have a single swifterror argument.
const TargetLowering * TLI
virtual void PreprocessISelDAG()
PreprocessISelDAG - This hook allows targets to hack on the graph before instruction selection starts...
DenseMap< MachineBasicBlock *, SmallVector< unsigned, 4 > > LPadToCallSiteMap
LPadToCallSiteMap - Map a landing pad to the call site indexes.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool isStrictFPOpcode()
Test if this node is a strict floating point pseudo-op.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
SDNode * getUser()
This returns the SDNode that contains this Use.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
virtual RegisterScheduler::FunctionPassCtor getDAGScheduler(CodeGenOpt::Level) const
Target can subclass this hook to select a different DAG scheduler.
virtual bool ComplexPatternFuncMutatesDAG() const
Return true if complex patterns for this target can mutate the DAG.
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...
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"))
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const TargetInstrInfo * TII
This represents the llvm.dbg.declare instruction.
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...
MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num)
allocateMemRefsArray - Allocate an array to hold MachineMemOperand pointers.
void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB)
visitBitTestHeader - This function emits necessary code to produce value suitable for "bit tests" ...
bool isExportedInst(const Value *V)
isExportedInst - Return true if the specified value is an instruction exported from its block...
unsigned getResNo() const
Convenience function for get().getResNo().
FunctionLoweringInfo * FuncInfo
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 RegisterScheduler defaultListDAGScheduler("default","Best scheduler for the target", createDefaultScheduler)
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
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)
an instruction to allocate memory on the stack
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.
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.