14 #define DEBUG_TYPE "isel"
62 STATISTIC(NumFastIselFailures,
"Number of instructions fast isel failed on");
63 STATISTIC(NumFastIselSuccess,
"Number of instructions fast isel selected");
64 STATISTIC(NumFastIselBlocks,
"Number of blocks selected entirely by fast isel");
65 STATISTIC(NumDAGBlocks,
"Number of blocks selected using DAG");
66 STATISTIC(NumDAGIselRetries,
"Number of times dag isel has to try another path");
67 STATISTIC(NumEntryBlocks,
"Number of entry blocks encountered");
69 "Number of entry blocks where fast isel failed to lower arguments");
74 cl::desc(
"Enable extra verbose messages in the \"fast\" "
75 "instruction selector"));
78 STATISTIC(NumFastIselFailRet,
"Fast isel fails on Ret");
79 STATISTIC(NumFastIselFailBr,
"Fast isel fails on Br");
80 STATISTIC(NumFastIselFailSwitch,
"Fast isel fails on Switch");
81 STATISTIC(NumFastIselFailIndirectBr,
"Fast isel fails on IndirectBr");
82 STATISTIC(NumFastIselFailInvoke,
"Fast isel fails on Invoke");
83 STATISTIC(NumFastIselFailResume,
"Fast isel fails on Resume");
84 STATISTIC(NumFastIselFailUnreachable,
"Fast isel fails on Unreachable");
87 STATISTIC(NumFastIselFailAdd,
"Fast isel fails on Add");
88 STATISTIC(NumFastIselFailFAdd,
"Fast isel fails on FAdd");
89 STATISTIC(NumFastIselFailSub,
"Fast isel fails on Sub");
90 STATISTIC(NumFastIselFailFSub,
"Fast isel fails on FSub");
91 STATISTIC(NumFastIselFailMul,
"Fast isel fails on Mul");
92 STATISTIC(NumFastIselFailFMul,
"Fast isel fails on FMul");
93 STATISTIC(NumFastIselFailUDiv,
"Fast isel fails on UDiv");
94 STATISTIC(NumFastIselFailSDiv,
"Fast isel fails on SDiv");
95 STATISTIC(NumFastIselFailFDiv,
"Fast isel fails on FDiv");
96 STATISTIC(NumFastIselFailURem,
"Fast isel fails on URem");
97 STATISTIC(NumFastIselFailSRem,
"Fast isel fails on SRem");
98 STATISTIC(NumFastIselFailFRem,
"Fast isel fails on FRem");
101 STATISTIC(NumFastIselFailAnd,
"Fast isel fails on And");
102 STATISTIC(NumFastIselFailOr,
"Fast isel fails on Or");
103 STATISTIC(NumFastIselFailXor,
"Fast isel fails on Xor");
106 STATISTIC(NumFastIselFailAlloca,
"Fast isel fails on Alloca");
107 STATISTIC(NumFastIselFailLoad,
"Fast isel fails on Load");
108 STATISTIC(NumFastIselFailStore,
"Fast isel fails on Store");
109 STATISTIC(NumFastIselFailAtomicCmpXchg,
"Fast isel fails on AtomicCmpXchg");
110 STATISTIC(NumFastIselFailAtomicRMW,
"Fast isel fails on AtomicRWM");
111 STATISTIC(NumFastIselFailFence,
"Fast isel fails on Frence");
112 STATISTIC(NumFastIselFailGetElementPtr,
"Fast isel fails on GetElementPtr");
115 STATISTIC(NumFastIselFailTrunc,
"Fast isel fails on Trunc");
116 STATISTIC(NumFastIselFailZExt,
"Fast isel fails on ZExt");
117 STATISTIC(NumFastIselFailSExt,
"Fast isel fails on SExt");
118 STATISTIC(NumFastIselFailFPTrunc,
"Fast isel fails on FPTrunc");
119 STATISTIC(NumFastIselFailFPExt,
"Fast isel fails on FPExt");
120 STATISTIC(NumFastIselFailFPToUI,
"Fast isel fails on FPToUI");
121 STATISTIC(NumFastIselFailFPToSI,
"Fast isel fails on FPToSI");
122 STATISTIC(NumFastIselFailUIToFP,
"Fast isel fails on UIToFP");
123 STATISTIC(NumFastIselFailSIToFP,
"Fast isel fails on SIToFP");
124 STATISTIC(NumFastIselFailIntToPtr,
"Fast isel fails on IntToPtr");
125 STATISTIC(NumFastIselFailPtrToInt,
"Fast isel fails on PtrToInt");
126 STATISTIC(NumFastIselFailBitCast,
"Fast isel fails on BitCast");
129 STATISTIC(NumFastIselFailICmp,
"Fast isel fails on ICmp");
130 STATISTIC(NumFastIselFailFCmp,
"Fast isel fails on FCmp");
131 STATISTIC(NumFastIselFailPHI,
"Fast isel fails on PHI");
132 STATISTIC(NumFastIselFailSelect,
"Fast isel fails on Select");
133 STATISTIC(NumFastIselFailCall,
"Fast isel fails on Call");
134 STATISTIC(NumFastIselFailShl,
"Fast isel fails on Shl");
135 STATISTIC(NumFastIselFailLShr,
"Fast isel fails on LShr");
136 STATISTIC(NumFastIselFailAShr,
"Fast isel fails on AShr");
137 STATISTIC(NumFastIselFailVAArg,
"Fast isel fails on VAArg");
138 STATISTIC(NumFastIselFailExtractElement,
"Fast isel fails on ExtractElement");
139 STATISTIC(NumFastIselFailInsertElement,
"Fast isel fails on InsertElement");
140 STATISTIC(NumFastIselFailShuffleVector,
"Fast isel fails on ShuffleVector");
141 STATISTIC(NumFastIselFailExtractValue,
"Fast isel fails on ExtractValue");
142 STATISTIC(NumFastIselFailInsertValue,
"Fast isel fails on InsertValue");
143 STATISTIC(NumFastIselFailLandingPad,
"Fast isel fails on LandingPad");
148 cl::desc(
"Enable verbose messages in the \"fast\" "
149 "instruction selector"));
152 cl::desc(
"Enable abort calls when \"fast\" instruction selection "
153 "fails to lower an instruction"));
156 cl::desc(
"Enable abort calls when \"fast\" instruction selection "
157 "fails to lower a formal argument"));
161 cl::desc(
"use Machine Branch Probability Info"),
167 cl::desc(
"Pop up a window to show dags before the first "
168 "dag combine pass"));
171 cl::desc(
"Pop up a window to show dags before legalize types"));
174 cl::desc(
"Pop up a window to show dags before legalize"));
177 cl::desc(
"Pop up a window to show dags before the second "
178 "dag combine pass"));
181 cl::desc(
"Pop up a window to show dags before the post legalize types"
182 " dag combine pass"));
185 cl::desc(
"Pop up a window to show isel dags as they are selected"));
188 cl::desc(
"Pop up a window to show sched dags as they are processed"));
191 cl::desc(
"Pop up a window to show SUnit dags after they are processed"));
217 cl::desc(
"Instruction schedulers available (before register"
237 if (NewOptLevel == SavedOptLevel)
244 DEBUG(
dbgs() <<
"\nChanging optimization level for Function "
246 DEBUG(
dbgs() <<
"\tBefore: -O" << SavedOptLevel
247 <<
" ; After: -O" << NewOptLevel <<
"\n");
253 DEBUG(
dbgs() <<
"\nRestoring optimization level for Function "
256 <<
" ; After: -O" << SavedOptLevel <<
"\n");
281 "Unknown sched type!");
299 dbgs() <<
"If a target marks an instruction with "
300 "'usesCustomInserter', it must implement "
301 "TargetLowering::EmitInstrWithCustomInserter!";
309 "If a target marks an instruction with 'hasPostISelHook', "
310 "it must implement TargetLowering::AdjustInstrPostInstrSelection!");
360 if (PN == 0)
continue;
370 if (CE == 0 || !CE->
canTrap())
continue;
390 "-fast-isel-verbose requires -fast-isel");
392 "-fast-isel-abort requires -fast-isel");
401 AA = &getAnalysis<AliasAnalysis>();
402 LibInfo = &getAnalysis<TargetLibraryInfo>();
403 TTI = getAnalysisIfAvailable<TargetTransformInfo>();
404 GFI = Fn.
hasGC() ? &getAnalysis<GCModuleInfo>().getFunctionInfo(Fn) : 0;
425 FuncInfo->
BPI = &getAnalysis<BranchProbabilityInfo>();
432 SelectAllBasicBlocks(Fn);
445 LiveInMap.
insert(std::make_pair(
LI->first,
LI->second));
461 DEBUG(
dbgs() <<
"Dropping debug info for dead vreg"
467 if (LDI != LiveInMap.
end()) {
468 assert(!hasFI &&
"There's no handling of frame pointer updating here yet "
480 LDI->second, Offset, Variable);
491 CopyUseMI = UseMI;
continue;
494 CopyUseMI = NULL;
break;
501 CopyUseMI->getOperand(0).getReg(),
522 II->isStackAligningInlineAsm()) {
525 if (II->isMSInlineAsm()) {
540 unsigned From =
I->first;
541 unsigned To =
I->second;
587 void SelectionDAGISel::ComputeLiveOutVRegInfo() {
600 if (!VisitedNodes.
insert(N))
625 }
while (!Worklist.
empty());
628 void SelectionDAGISel::CodeGenAndEmitDAG() {
629 std::string GroupName;
631 GroupName =
"Instruction Selection and Scheduling";
632 std::string BlockName;
633 int BlockNumber = -1;
645 DEBUG(
dbgs() <<
"Initial selection DAG: BB#" << BlockNumber
646 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
656 DEBUG(
dbgs() <<
"Optimized lowered selection DAG: BB#" << BlockNumber
657 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
670 DEBUG(
dbgs() <<
"Type-legalized selection DAG: BB#" << BlockNumber
671 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
686 DEBUG(
dbgs() <<
"Optimized type-legalized selection DAG: BB#" << BlockNumber
687 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
712 DEBUG(
dbgs() <<
"Optimized vector-legalized selection DAG: BB#"
713 << BlockNumber <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
723 DEBUG(
dbgs() <<
"Legalized selection DAG: BB#" << BlockNumber
724 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
734 DEBUG(
dbgs() <<
"Optimized legalized selection DAG: BB#" << BlockNumber
735 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
738 ComputeLiveOutVRegInfo();
746 DoInstructionSelection();
749 DEBUG(
dbgs() <<
"Selected selection DAG: BB#" << BlockNumber
750 <<
" '" << BlockName <<
"'\n";
CurDAG->
dump());
777 if (FirstMBB != LastMBB)
798 :
SelectionDAG::DAGUpdateListener(DAG), ISelPosition(isp) {}
810 void SelectionDAGISel::DoInstructionSelection() {
811 DEBUG(
dbgs() <<
"===== Instruction selection begins: BB#"
831 ISelUpdater ISU(*
CurDAG, ISelPosition);
838 SDNode *Node = --ISelPosition;
867 DEBUG(
dbgs() <<
"===== Instruction selection ends:\n");
874 void SelectionDAGISel::PrepareEHLandingPad() {
905 !isa<TerminatorInst>(
I) &&
906 !isa<DbgInfoIntrinsic>(I) &&
907 !isa<LandingPadInst>(
I) &&
918 default: assert (0 &&
"<Invalid operator> ");
922 case Instruction::Br: NumFastIselFailBr++;
return;
923 case Instruction::Switch: NumFastIselFailSwitch++;
return;
924 case Instruction::IndirectBr: NumFastIselFailIndirectBr++;
return;
925 case Instruction::Invoke: NumFastIselFailInvoke++;
return;
926 case Instruction::Resume: NumFastIselFailResume++;
return;
927 case Instruction::Unreachable: NumFastIselFailUnreachable++;
return;
930 case Instruction::Add: NumFastIselFailAdd++;
return;
931 case Instruction::FAdd: NumFastIselFailFAdd++;
return;
932 case Instruction::Sub: NumFastIselFailSub++;
return;
933 case Instruction::FSub: NumFastIselFailFSub++;
return;
934 case Instruction::Mul: NumFastIselFailMul++;
return;
935 case Instruction::FMul: NumFastIselFailFMul++;
return;
936 case Instruction::UDiv: NumFastIselFailUDiv++;
return;
937 case Instruction::SDiv: NumFastIselFailSDiv++;
return;
938 case Instruction::FDiv: NumFastIselFailFDiv++;
return;
939 case Instruction::URem: NumFastIselFailURem++;
return;
940 case Instruction::SRem: NumFastIselFailSRem++;
return;
941 case Instruction::FRem: NumFastIselFailFRem++;
return;
949 case Instruction::Alloca: NumFastIselFailAlloca++;
return;
952 case Instruction::AtomicCmpXchg: NumFastIselFailAtomicCmpXchg++;
return;
953 case Instruction::AtomicRMW: NumFastIselFailAtomicRMW++;
return;
954 case Instruction::Fence: NumFastIselFailFence++;
return;
955 case Instruction::GetElementPtr: NumFastIselFailGetElementPtr++;
return;
958 case Instruction::Trunc: NumFastIselFailTrunc++;
return;
959 case Instruction::ZExt: NumFastIselFailZExt++;
return;
960 case Instruction::SExt: NumFastIselFailSExt++;
return;
961 case Instruction::FPTrunc: NumFastIselFailFPTrunc++;
return;
962 case Instruction::FPExt: NumFastIselFailFPExt++;
return;
963 case Instruction::FPToUI: NumFastIselFailFPToUI++;
return;
964 case Instruction::FPToSI: NumFastIselFailFPToSI++;
return;
965 case Instruction::UIToFP: NumFastIselFailUIToFP++;
return;
966 case Instruction::SIToFP: NumFastIselFailSIToFP++;
return;
967 case Instruction::IntToPtr: NumFastIselFailIntToPtr++;
return;
968 case Instruction::PtrToInt: NumFastIselFailPtrToInt++;
return;
969 case Instruction::BitCast: NumFastIselFailBitCast++;
return;
972 case Instruction::ICmp: NumFastIselFailICmp++;
return;
973 case Instruction::FCmp: NumFastIselFailFCmp++;
return;
977 case Instruction::Shl: NumFastIselFailShl++;
return;
978 case Instruction::LShr: NumFastIselFailLShr++;
return;
979 case Instruction::AShr: NumFastIselFailAShr++;
return;
980 case Instruction::VAArg: NumFastIselFailVAArg++;
return;
982 case Instruction::InsertElement: NumFastIselFailInsertElement++;
return;
983 case Instruction::ShuffleVector: NumFastIselFailShuffleVector++;
return;
984 case Instruction::ExtractValue: NumFastIselFailExtractValue++;
return;
985 case Instruction::InsertValue: NumFastIselFailInsertValue++;
return;
986 case Instruction::LandingPad: NumFastIselFailLandingPad++;
return;
991 void SelectionDAGISel::SelectAllBasicBlocks(
const Function &Fn) {
1000 I = RPOT.begin(), E = RPOT.end();
I != E; ++
I) {
1004 bool AllPredsVisited =
true;
1008 AllPredsVisited =
false;
1013 if (AllPredsVisited) {
1037 PrepareEHLandingPad();
1051 ++NumFastIselFailLowerArguments;
1059 CodeGenAndEmitDAG();
1071 unsigned NumFastIselRemaining = std::distance(Begin, End);
1073 for (; BI != Begin; --BI) {
1078 --NumFastIselRemaining;
1088 --NumFastIselRemaining;
1089 ++NumFastIselSuccess;
1094 while (BeforeInst != Begin) {
1099 if (BeforeInst != Inst && isa<LoadInst>(BeforeInst) &&
1104 --NumFastIselRemaining;
1105 ++NumFastIselSuccess;
1116 if (isa<CallInst>(Inst)) {
1119 dbgs() <<
"FastISel missed call: ";
1129 bool HadTailCall =
false;
1131 SelectBasicBlock(Inst, BI, HadTailCall);
1143 unsigned RemainingNow = std::distance(Begin, BI);
1144 NumFastIselFailures += NumFastIselRemaining - RemainingNow;
1145 NumFastIselRemaining = RemainingNow;
1149 if (isa<TerminatorInst>(Inst) && !isa<BranchInst>(Inst)) {
1151 NumFastIselFailures += NumFastIselRemaining;
1153 dbgs() <<
"FastISel missed terminator: ";
1157 NumFastIselFailures += NumFastIselRemaining;
1159 dbgs() <<
"FastISel miss: ";
1182 ++NumFastIselBlocks;
1189 SelectBasicBlock(Begin, BI, HadTailCall);
1239 &&
"Should have a copy implying we should have 2 arguments.");
1243 if (!OPI2->
isReg() ||
1268 if (SplitPoint == BB->
begin())
1276 SplitPoint = Previous;
1277 if (Previous == Start)
1286 SelectionDAGISel::FinishBasicBlock() {
1288 DEBUG(
dbgs() <<
"Total amount of phi nodes to update: "
1291 dbgs() <<
"Node " << i <<
" : ("
1301 if (MustUpdatePHINodes) {
1304 assert(
PHI->isPHI() &&
1305 "This is not a machine PHI node that we are updating!");
1327 SuccessMBB->
splice(SuccessMBB->
end(), ParentMBB,
1337 CodeGenAndEmitDAG();
1341 if (!FailureMBB->
size()) {
1347 CodeGenAndEmitDAG();
1355 if (MustUpdatePHINodes)
1368 CodeGenAndEmitDAG();
1371 uint32_t UnhandledWeight = 0;
1372 for (
unsigned j = 0, ej =
SDB->
BitTestCases[i].Cases.size(); j != ej; ++j)
1399 CodeGenAndEmitDAG();
1407 assert(
PHI->isPHI() &&
1408 "This is not a machine PHI node that we are updating!");
1430 for (
unsigned i = 0, e =
SDB->
JTCases.size(); i != e; ++i) {
1441 CodeGenAndEmitDAG();
1451 CodeGenAndEmitDAG();
1458 assert(
PHI->isPHI() &&
1459 "This is not a machine PHI node that we are updating!");
1475 assert(
PHI->isPHI() &&
1476 "This is not a machine PHI node that we are updating!");
1498 CodeGenAndEmitDAG();
1508 for (
unsigned i = 0, e = Succs.
size(); i != e; ++i) {
1516 MBBI != MBBE && MBBI->isPHI(); ++MBBI) {
1519 for (
unsigned pn = 0; ; ++pn) {
1521 "Didn't find PHI entry!");
1560 int64_t DesiredMaskS)
const {
1565 if (ActualMask == DesiredMask)
1574 APInt NeededMask = DesiredMask & ~ActualMask;
1589 int64_t DesiredMaskS)
const {
1594 if (ActualMask == DesiredMask)
1603 APInt NeededMask = DesiredMask & ~ActualMask;
1605 APInt KnownZero, KnownOne;
1609 if ((NeededMask & KnownOne) == NeededMask)
1623 std::vector<SDValue> InOps;
1626 Ops.push_back(InOps[InlineAsm::Op_InputChain]);
1627 Ops.push_back(InOps[InlineAsm::Op_AsmString]);
1628 Ops.push_back(InOps[InlineAsm::Op_MDNode]);
1629 Ops.push_back(InOps[InlineAsm::Op_ExtraInfo]);
1631 unsigned i = InlineAsm::Op_FirstOperand, e = InOps.size();
1632 if (InOps[e-1].getValueType() ==
MVT::Glue)
1636 unsigned Flags = cast<ConstantSDNode>(InOps[i])->getZExtValue();
1639 Ops.insert(Ops.end(), InOps.begin()+i,
1644 "Memory operand with multiple values?");
1646 std::vector<SDValue> SelOps;
1655 Ops.insert(Ops.end(), SelOps.begin(), SelOps.end());
1661 if (e != InOps.size())
1662 Ops.push_back(InOps.back());
1683 bool IgnoreChains) {
1697 if (!Visited.
insert(Use))
1707 if (Use == ImmedUse || Use == Root)
1714 if (
findNonImmUse(N, Def, ImmedUse, Root, Visited, IgnoreChains))
1732 bool IgnoreChains) {
1791 IgnoreChains =
false;
1799 SDNode *SelectionDAGISel::Select_INLINEASM(
SDNode *N) {
1805 VTs, &Ops[0], Ops.size());
1816 GetVBR(uint64_t Val,
const unsigned char *MatcherTable,
unsigned &Idx) {
1817 assert(Val >= 128 &&
"Not a VBR");
1823 NextBits = MatcherTable[Idx++];
1824 Val |= (NextBits&127) << Shift;
1826 }
while (NextBits & 128);
1834 void SelectionDAGISel::
1835 UpdateChainsAndGlue(
SDNode *NodeToMatch,
SDValue InputChain,
1839 bool isMorphNodeTo) {
1844 if (!ChainNodesMatched.
empty()) {
1845 assert(InputChain.
getNode() != 0 &&
1846 "Matched input chains but didn't produce a chain");
1849 for (
unsigned i = 0, e = ChainNodesMatched.
size(); i != e; ++i) {
1850 SDNode *ChainNode = ChainNodesMatched[i];
1858 if (ChainNode == NodeToMatch && isMorphNodeTo)
1869 !std::count(NowDeadNodes.
begin(), NowDeadNodes.
end(), ChainNode))
1876 if (InputGlue.
getNode() != 0) {
1878 for (
unsigned i = 0, e = GlueResultNodesMatched.
size(); i != e; ++i) {
1879 SDNode *FRN = GlueResultNodesMatched[i];
1886 "Doesn't have a glue result");
1892 !std::count(NowDeadNodes.
begin(), NowDeadNodes.
end(), FRN))
1897 if (!NowDeadNodes.
empty())
1900 DEBUG(
dbgs() <<
"ISEL: Match complete!\n");
1925 E = ChainedNode->
use_end(); UI != E; ++UI) {
1927 if (UI.getUse().getValueType() !=
MVT::Other)
continue;
1937 unsigned UserOpcode = User->
getOpcode();
1963 if (!std::count(ChainedNodesInPattern.
begin(),
1964 ChainedNodesInPattern.
end(), User))
2002 switch (
WalkChainUsers(User, ChainedNodesInPattern, InteriorChainedNodes)) {
2043 for (
unsigned i = 0, e = ChainNodesMatched.
size(); i != e; ++i) {
2052 for (
unsigned i = 0, e = ChainNodesMatched.
size(); i != e; ++i) {
2055 SDNode *N = ChainNodesMatched[i];
2057 if (std::count(InteriorChainedNodes.
begin(),InteriorChainedNodes.
end(),
N))
2061 SDValue InChain = ChainNodesMatched[i]->getOperand(0);
2070 if (!std::count(ChainNodesMatched.
begin(), ChainNodesMatched.
end(),
2076 if (InputChains.
size() == 1)
2077 return InputChains[0];
2083 SDNode *SelectionDAGISel::
2085 const SDValue *Ops,
unsigned NumOps,
unsigned EmitNodeInfo) {
2092 int OldGlueResultNo = -1, OldChainResultNo = -1;
2096 OldGlueResultNo = NTMNumResults-1;
2097 if (NTMNumResults != 1 &&
2099 OldChainResultNo = NTMNumResults-2;
2101 OldChainResultNo = NTMNumResults-1;
2119 (
unsigned)OldGlueResultNo != ResNumResults-1)
2121 SDValue(Res, ResNumResults-1));
2123 if ((EmitNodeInfo & OPFL_GlueOutput) != 0)
2127 if ((EmitNodeInfo &
OPFL_Chain) && OldChainResultNo != -1 &&
2128 (
unsigned)OldChainResultNo != ResNumResults-1)
2130 SDValue(Res, ResNumResults-1));
2142 CheckSame(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2146 unsigned RecNo = MatcherTable[MatcherIndex++];
2147 assert(RecNo < RecordedNodes.size() &&
"Invalid CheckSame");
2148 return N == RecordedNodes[RecNo].first;
2178 CheckOpcode(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2180 uint16_t Opc = MatcherTable[MatcherIndex++];
2181 Opc |= (
unsigned short)MatcherTable[MatcherIndex++] << 8;
2186 CheckType(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2207 return cast<CondCodeSDNode>(
N)->
get() ==
2215 if (cast<VTSDNode>(N)->getVT() == VT)
2225 int64_t Val = MatcherTable[MatcherIndex++];
2227 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2234 CheckAndImm(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2236 int64_t Val = MatcherTable[MatcherIndex++];
2238 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2247 CheckOrImm(
const unsigned char *MatcherTable,
unsigned &MatcherIndex,
2249 int64_t Val = MatcherTable[MatcherIndex++];
2251 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2270 switch (Table[Index++]) {
2275 Result = !
::CheckSame(Table, Index, N, RecordedNodes);
2335 unsigned NumRecordedNodes;
2338 unsigned NumMatchedMemRefs;
2341 SDValue InputChain, InputGlue;
2344 bool HasChainNodesMatched, HasGlueResultNodesMatched;
2351 unsigned TableSize) {
2387 case ISD::UNDEF:
return Select_UNDEF(NodeToMatch);
2395 NodeStack.push_back(N);
2413 SDValue InputChain, InputGlue;
2422 DEBUG(
dbgs() <<
"ISEL: Starting pattern match on root node: ";
2430 unsigned MatcherIndex = 0;
2432 if (!OpcodeOffset.empty()) {
2434 if (N.
getOpcode() < OpcodeOffset.size())
2435 MatcherIndex = OpcodeOffset[N.
getOpcode()];
2436 DEBUG(
dbgs() <<
" Initial Opcode index to " << MatcherIndex <<
"\n");
2445 unsigned CaseSize = MatcherTable[Idx++];
2447 CaseSize =
GetVBR(CaseSize, MatcherTable, Idx);
2448 if (CaseSize == 0)
break;
2451 uint16_t Opc = MatcherTable[Idx++];
2452 Opc |= (
unsigned short)MatcherTable[Idx++] << 8;
2453 if (Opc >= OpcodeOffset.size())
2454 OpcodeOffset.resize((Opc+1)*2);
2455 OpcodeOffset[Opc] = Idx;
2460 if (N.
getOpcode() < OpcodeOffset.size())
2461 MatcherIndex = OpcodeOffset[N.
getOpcode()];
2465 assert(MatcherIndex < TableSize &&
"Invalid index");
2467 unsigned CurrentOpcodeIndex = MatcherIndex;
2480 unsigned NumToSkip = MatcherTable[MatcherIndex++];
2481 if (NumToSkip & 128)
2482 NumToSkip =
GetVBR(NumToSkip, MatcherTable, MatcherIndex);
2484 if (NumToSkip == 0) {
2489 FailIndex = MatcherIndex+NumToSkip;
2491 unsigned MatcherIndexOfPredicate = MatcherIndex;
2492 (void)MatcherIndexOfPredicate;
2499 Result, *
this, RecordedNodes);
2503 DEBUG(
dbgs() <<
" Skipped scope entry (due to false predicate) at "
2504 <<
"index " << MatcherIndexOfPredicate
2505 <<
", continuing at " << FailIndex <<
"\n");
2506 ++NumDAGIselRetries;
2510 MatcherIndex = FailIndex;
2514 if (FailIndex == 0)
break;
2518 MatchScope NewEntry;
2519 NewEntry.FailIndex = FailIndex;
2520 NewEntry.NodeStack.append(NodeStack.begin(), NodeStack.end());
2521 NewEntry.NumRecordedNodes = RecordedNodes.
size();
2522 NewEntry.NumMatchedMemRefs = MatchedMemRefs.
size();
2523 NewEntry.InputChain = InputChain;
2524 NewEntry.InputGlue = InputGlue;
2525 NewEntry.HasChainNodesMatched = !ChainNodesMatched.
empty();
2526 NewEntry.HasGlueResultNodesMatched = !GlueResultNodesMatched.
empty();
2533 if (NodeStack.size() > 1)
2534 Parent = NodeStack[NodeStack.size()-2].getNode();
2535 RecordedNodes.
push_back(std::make_pair(N, Parent));
2552 MatchedMemRefs.
push_back(cast<MemSDNode>(N)->getMemOperand());
2563 unsigned ChildNo = MatcherTable[MatcherIndex++];
2567 NodeStack.push_back(N);
2573 NodeStack.pop_back();
2574 assert(!NodeStack.empty() &&
"Node stack imbalance!");
2575 N = NodeStack.back();
2579 if (!::
CheckSame(MatcherTable, MatcherIndex, N, RecordedNodes))
break;
2584 if (!::
CheckChildSame(MatcherTable, MatcherIndex, N, RecordedNodes,
2598 unsigned CPNum = MatcherTable[MatcherIndex++];
2599 unsigned RecNo = MatcherTable[MatcherIndex++];
2600 assert(RecNo < RecordedNodes.
size() &&
"Invalid CheckComplexPat");
2602 RecordedNodes[RecNo].first, CPNum,
2608 if (!::
CheckOpcode(MatcherTable, MatcherIndex, N.getNode()))
break;
2617 unsigned CurNodeOpcode = N.getOpcode();
2618 unsigned SwitchStart = MatcherIndex-1; (void)SwitchStart;
2622 CaseSize = MatcherTable[MatcherIndex++];
2624 CaseSize =
GetVBR(CaseSize, MatcherTable, MatcherIndex);
2625 if (CaseSize == 0)
break;
2627 uint16_t Opc = MatcherTable[MatcherIndex++];
2628 Opc |= (
unsigned short)MatcherTable[MatcherIndex++] << 8;
2631 if (CurNodeOpcode == Opc)
2635 MatcherIndex += CaseSize;
2639 if (CaseSize == 0)
break;
2642 DEBUG(
dbgs() <<
" OpcodeSwitch from " << SwitchStart
2643 <<
" to " << MatcherIndex <<
"\n");
2648 MVT CurNodeVT = N.getSimpleValueType();
2649 unsigned SwitchStart = MatcherIndex-1; (void)SwitchStart;
2653 CaseSize = MatcherTable[MatcherIndex++];
2655 CaseSize =
GetVBR(CaseSize, MatcherTable, MatcherIndex);
2656 if (CaseSize == 0)
break;
2663 if (CurNodeVT == CaseVT)
2667 MatcherIndex += CaseSize;
2671 if (CaseSize == 0)
break;
2674 DEBUG(
dbgs() <<
" TypeSwitch[" <<
EVT(CurNodeVT).getEVTString()
2675 <<
"] from " << SwitchStart <<
" to " << MatcherIndex<<
'\n');
2694 if (!::
CheckInteger(MatcherTable, MatcherIndex, N))
break;
2697 if (!::
CheckAndImm(MatcherTable, MatcherIndex, N, *
this))
break;
2700 if (!::
CheckOrImm(MatcherTable, MatcherIndex, N, *
this))
break;
2704 assert(NodeStack.size() != 1 &&
"No parent node");
2707 bool HasMultipleUses =
false;
2708 for (
unsigned i = 1, e = NodeStack.size()-1; i != e; ++i)
2709 if (!NodeStack[i].hasOneUse()) {
2710 HasMultipleUses =
true;
2713 if (HasMultipleUses)
break;
2729 int64_t Val = MatcherTable[MatcherIndex++];
2731 Val =
GetVBR(Val, MatcherTable, MatcherIndex);
2732 RecordedNodes.
push_back(std::pair<SDValue, SDNode*>(
2739 unsigned RegNo = MatcherTable[MatcherIndex++];
2740 RecordedNodes.
push_back(std::pair<SDValue, SDNode*>(
2750 unsigned RegNo = MatcherTable[MatcherIndex++];
2751 RegNo |= MatcherTable[MatcherIndex++] << 8;
2752 RecordedNodes.
push_back(std::pair<SDValue, SDNode*>(
2759 unsigned RecNo = MatcherTable[MatcherIndex++];
2760 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitConvertToTarget");
2761 SDValue Imm = RecordedNodes[RecNo].first;
2764 const ConstantInt *Val=cast<ConstantSDNode>(Imm)->getConstantIntValue();
2767 const ConstantFP *Val=cast<ConstantFPSDNode>(Imm)->getConstantFPValue();
2771 RecordedNodes.
push_back(std::make_pair(Imm, RecordedNodes[RecNo].second));
2778 assert(InputChain.
getNode() == 0 &&
2779 "EmitMergeInputChains should be the first chain producing node");
2780 assert(ChainNodesMatched.
empty() &&
2781 "Should only have one EmitMergeInputChains per match");
2785 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitMergeInputChains");
2786 ChainNodesMatched.
push_back(RecordedNodes[RecNo].first.getNode());
2790 if (ChainNodesMatched.
back() != NodeToMatch &&
2791 !RecordedNodes[RecNo].first.hasOneUse()) {
2792 ChainNodesMatched.
clear();
2799 if (InputChain.
getNode() == 0)
2805 assert(InputChain.
getNode() == 0 &&
2806 "EmitMergeInputChains should be the first chain producing node");
2813 unsigned NumChains = MatcherTable[MatcherIndex++];
2814 assert(NumChains != 0 &&
"Can't TF zero chains");
2816 assert(ChainNodesMatched.
empty() &&
2817 "Should only have one EmitMergeInputChains per match");
2820 for (
unsigned i = 0; i != NumChains; ++i) {
2821 unsigned RecNo = MatcherTable[MatcherIndex++];
2822 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitMergeInputChains");
2823 ChainNodesMatched.
push_back(RecordedNodes[RecNo].first.getNode());
2827 if (ChainNodesMatched.
back() != NodeToMatch &&
2828 !RecordedNodes[RecNo].first.hasOneUse()) {
2829 ChainNodesMatched.
clear();
2835 if (ChainNodesMatched.
empty())
2841 if (InputChain.
getNode() == 0)
2848 unsigned RecNo = MatcherTable[MatcherIndex++];
2849 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitCopyToReg");
2850 unsigned DestPhysReg = MatcherTable[MatcherIndex++];
2852 if (InputChain.
getNode() == 0)
2856 DestPhysReg, RecordedNodes[RecNo].first,
2859 InputGlue = InputChain.
getValue(1);
2864 unsigned XFormNo = MatcherTable[MatcherIndex++];
2865 unsigned RecNo = MatcherTable[MatcherIndex++];
2866 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitNodeXForm");
2868 RecordedNodes.
push_back(std::pair<SDValue,SDNode*>(Res, (
SDNode*) 0));
2874 uint16_t TargetOpc = MatcherTable[MatcherIndex++];
2875 TargetOpc |= (
unsigned short)MatcherTable[MatcherIndex++] << 8;
2876 unsigned EmitNodeInfo = MatcherTable[MatcherIndex++];
2878 unsigned NumVTs = MatcherTable[MatcherIndex++];
2880 for (
unsigned i = 0; i != NumVTs; ++i) {
2887 if (EmitNodeInfo & OPFL_Chain)
2889 if (EmitNodeInfo & OPFL_GlueOutput)
2895 if (VTs.
size() == 1)
2897 else if (VTs.
size() == 2)
2903 unsigned NumOps = MatcherTable[MatcherIndex++];
2905 for (
unsigned i = 0; i != NumOps; ++i) {
2906 unsigned RecNo = MatcherTable[MatcherIndex++];
2908 RecNo =
GetVBR(RecNo, MatcherTable, MatcherIndex);
2910 assert(RecNo < RecordedNodes.
size() &&
"Invalid EmitNode");
2911 Ops.
push_back(RecordedNodes[RecNo].first);
2918 FirstOpToCopy += (EmitNodeInfo &
OPFL_Chain) ? 1 : 0;
2920 "Invalid variadic node");
2923 for (
unsigned i = FirstOpToCopy, e = NodeToMatch->
getNumOperands();
2932 if (EmitNodeInfo & OPFL_Chain)
2946 for (
unsigned i = 0, e = VTs.
size(); i != e; ++i) {
2953 Res = MorphNode(NodeToMatch, TargetOpc, VTList, Ops.
data(), Ops.
size(),
2958 DEBUG(
dbgs() <<
"Node was eliminated by CSE\n");
2964 if (EmitNodeInfo & OPFL_GlueOutput) {
2966 if (EmitNodeInfo & OPFL_Chain)
2968 }
else if (EmitNodeInfo & OPFL_Chain)
2981 bool mayLoad = MCID.
mayLoad();
2984 unsigned NumMemRefs = 0;
2986 MatchedMemRefs.
begin(), E = MatchedMemRefs.
end();
I != E; ++
I) {
2987 if ((*I)->isLoad()) {
2990 }
else if ((*I)->isStore()) {
3003 MatchedMemRefs.
begin(), E = MatchedMemRefs.
end();
I != E; ++
I) {
3004 if ((*I)->isLoad()) {
3007 }
else if ((*I)->isStore()) {
3015 cast<MachineSDNode>(Res)
3016 ->setMemRefs(MemRefs, MemRefs + NumMemRefs);
3026 UpdateChainsAndGlue(NodeToMatch, InputChain, ChainNodesMatched,
3027 InputGlue, GlueResultNodesMatched,
true);
3035 unsigned NumNodes = MatcherTable[MatcherIndex++];
3038 for (
unsigned i = 0; i != NumNodes; ++i) {
3039 unsigned RecNo = MatcherTable[MatcherIndex++];
3041 RecNo =
GetVBR(RecNo, MatcherTable, MatcherIndex);
3043 assert(RecNo < RecordedNodes.
size() &&
"Invalid MarkGlueResults");
3044 GlueResultNodesMatched.
push_back(RecordedNodes[RecNo].first.getNode());
3053 unsigned NumResults = MatcherTable[MatcherIndex++];
3055 for (
unsigned i = 0; i != NumResults; ++i) {
3056 unsigned ResSlot = MatcherTable[MatcherIndex++];
3058 ResSlot =
GetVBR(ResSlot, MatcherTable, MatcherIndex);
3060 assert(ResSlot < RecordedNodes.
size() &&
"Invalid CompleteMatch");
3061 SDValue Res = RecordedNodes[ResSlot].first;
3063 assert(i < NodeToMatch->getNumValues() &&
3066 "Invalid number of results to complete!");
3067 assert((NodeToMatch->
getValueType(i) == Res.getValueType() ||
3071 Res.getValueType().getSizeInBits()) &&
3072 "invalid replacement");
3078 GlueResultNodesMatched.
push_back(NodeToMatch);
3081 UpdateChainsAndGlue(NodeToMatch, InputChain, ChainNodesMatched,
3082 InputGlue, GlueResultNodesMatched,
false);
3085 "Didn't replace all uses of the node?");
3096 DEBUG(
dbgs() <<
" Match failed at index " << CurrentOpcodeIndex <<
"\n");
3097 ++NumDAGIselRetries;
3099 if (MatchScopes.
empty()) {
3100 CannotYetSelect(NodeToMatch);
3106 MatchScope &LastScope = MatchScopes.
back();
3107 RecordedNodes.
resize(LastScope.NumRecordedNodes);
3109 NodeStack.append(LastScope.NodeStack.begin(), LastScope.NodeStack.end());
3110 N = NodeStack.back();
3112 if (LastScope.NumMatchedMemRefs != MatchedMemRefs.
size())
3113 MatchedMemRefs.
resize(LastScope.NumMatchedMemRefs);
3114 MatcherIndex = LastScope.FailIndex;
3116 DEBUG(
dbgs() <<
" Continuing at " << MatcherIndex <<
"\n");
3118 InputChain = LastScope.InputChain;
3119 InputGlue = LastScope.InputGlue;
3120 if (!LastScope.HasChainNodesMatched)
3121 ChainNodesMatched.
clear();
3122 if (!LastScope.HasGlueResultNodesMatched)
3123 GlueResultNodesMatched.
clear();
3128 unsigned NumToSkip = MatcherTable[MatcherIndex++];
3129 if (NumToSkip & 128)
3130 NumToSkip =
GetVBR(NumToSkip, MatcherTable, MatcherIndex);
3134 if (NumToSkip != 0) {
3135 LastScope.FailIndex = MatcherIndex+NumToSkip;
3148 void SelectionDAGISel::CannotYetSelect(
SDNode *N) {
3151 Msg <<
"Cannot select: ";
3157 Msg <<
"\nIn function: " <<
MF->
getName();
3161 cast<ConstantSDNode>(N->
getOperand(HasInputChain))->getZExtValue();
3165 Msg <<
"target intrinsic %" <<
TII->getName(iid);
3167 Msg <<
"unknown intrinsic #" << iid;
static bool findNonImmUse(SDNode *Use, SDNode *Def, SDNode *ImmedUse, SDNode *Root, SmallPtrSet< SDNode *, 16 > &Visited, bool IgnoreChains)
std::vector< BitTestBlock > BitTestCases
void push_back(const T &Elt)
SelectionDAGBuilder * SDB
SDValue getConstant(uint64_t Val, EVT VT, bool isTarget=false)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckAndImm(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const SelectionDAGISel &SDISel)
mop_iterator operands_end()
SDValue getValue(unsigned R) const
bool hasPostISelHook(QueryType Type=IgnoreBundle) const
virtual const TargetLowering * getTargetLowering() const
static SDNode * findGlueUse(SDNode *N)
void EmitLiveInCopies(MachineBasicBlock *EntryMBB, const TargetRegisterInfo &TRI, const TargetInstrInfo &TII)
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckCondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N)
AnalysisUsage & addPreserved()
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckChildType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, unsigned ChildNo)
static PassRegistry * getPassRegistry()
static int getNumFixedFromVariadicInfo(unsigned Flags)
SDValue getCopyToReg(SDValue Chain, SDLoc dl, unsigned Reg, SDValue N)
void dump() const
dump - Dump this node, for debugging.
static unsigned virtReg2Index(unsigned Reg)
livein_iterator livein_end() 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"))
static MachineBasicBlock::iterator FindSplitPointForStackProtector(MachineBasicBlock *BB, DebugLoc DL)
static cl::opt< bool > EnableFastISelAbortArgs("fast-isel-abort-args", cl::Hidden, cl::desc("Enable abort calls when \"fast\" instruction selection ""fails to lower a formal argument"))
void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef< unsigned > Sites)
void ReplaceUses(SDValue F, SDValue T)
BasicBlock * SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P=0, bool MergeIdenticalEdges=false, bool DontDeleteUselessPHIs=false, bool SplitLandingPads=false)
ScheduleDAGSDNodes *(* FunctionPassCtor)(SelectionDAGISel *, CodeGenOpt::Level)
bool isReturn() const
Return true if the instruction is a return.
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool mayStore() const
Return true if this instruction could possibly modify memory. Instructions with this flag set are not...
iterator getFirstTerminator()
static unsigned getFlagWord(unsigned Kind, unsigned NumOps)
static bool isVirtualRegister(unsigned Reg)
static cl::opt< RegisterScheduler::FunctionPassCtor, false, RegisterPassParser< RegisterScheduler > > ISHeuristic("pre-RA-sched", cl::init(&createDefaultScheduler), cl::desc("Instruction schedulers available (before register"" allocation):"))
virtual ~SelectionDAGISel()
unsigned getOpcode() const
void addLiveIn(unsigned Reg)
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)
bool NewNodesMustHaveLegalTypes
std::string str() const
str - Get the contents as an std::string.
unsigned getNumOperands() const
unsigned getNumOperands() const
unsigned getValueSizeInBits() const
MDNode - a tuple of other values.
const SDValue & getOperand(unsigned Num) const
const Function * getFunction() const
unsigned GetSuccessorNumber(BasicBlock *BB, BasicBlock *Succ)
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode, std::vector< SDValue > &OutOps)
void setNodeId(int Id)
setNodeId - Set unique node id.
void ComputeMaskedBits(SDValue Op, APInt &KnownZero, APInt &KnownOne, unsigned Depth=0) const
const SDValue & setRoot(SDValue N)
void printrFull(raw_ostream &O, const SelectionDAG *G=0) const
void viewGraph(const std::string &Title)
DebugLoc getCurDebugLoc() const
virtual void AdjustInstrPostInstrSelection(MachineInstr *MI, SDNode *Node) const
EntryToken - This is the marker used to indicate the start of a region.
const TargetLibraryInfo * LibInfo
LoopInfoBase< BlockT, LoopT > * LI
void init(MachineFunction &mf, const TargetTransformInfo *TTI, const TargetLowering *TLI)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
StringRef getName() const
void initializeBranchProbabilityInfoPass(PassRegistry &)
static bool isFoldedOrDeadInstruction(const Instruction *I, FunctionLoweringInfo *FuncInfo)
StackProtectorDescriptor SPDescriptor
bool isVector() const
isVector - Return true if this is a vector value type.
void visitSPDescriptorParent(StackProtectorDescriptor &SPD, MachineBasicBlock *ParentBB)
AnalysisUsage & addRequired()
void setLastLocalValue(MachineInstr *I)
void resetTargetOptions(const MachineFunction *MF) const
Reset the target options based on the function's attributes.
void dump() const
dump - Support for debugging, callable in GDB: V->dump()
void setOptLevel(CodeGenOpt::Level Level) const
Overrides the optimization level.
SDNode * MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps)
bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS, int64_t DesiredMaskS) const
void visitSwitchCase(CaseBlock &CB, MachineBasicBlock *SwitchBB)
const HexagonInstrInfo * TII
static bool IsLegalToFold(SDValue N, SDNode *U, SDNode *Root, CodeGenOpt::Level OptLevel, bool IgnoreChains=false)
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
void AddLiveOutRegInfo(unsigned Reg, unsigned NumSignBits, const APInt &KnownZero, const APInt &KnownOne)
AddLiveOutRegInfo - Adds LiveOutInfo for a register.
#define llvm_unreachable(msg)
EVT getValueType(unsigned ResNo) const
static SDValue HandleMergeInputChains(SmallVectorImpl< SDNode * > &ChainNodesMatched, SelectionDAG *CurDAG)
void visitJumpTable(JumpTable &JT)
visitJumpTable - Emit JumpTable node in the current MBB
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
bool isCall() const
Return true if the instruction is a call.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Instruction * getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const TargetLowering * getTargetLowering() const
static MachinePassRegistry Registry
const TargetRegisterClass * getRegClass(unsigned Reg) const
void freezeReservedRegs(const MachineFunction &)
SDNode * SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable, unsigned TableSize)
Abstract Stack Frame Information.
SDVTList getVTList(EVT VT)
virtual MVT getPointerTy(uint32_t=0) const
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckOpcode(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDNode *N)
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
ID
LLVM Calling Convention Representation.
Sched::Preference getSchedulingPreference() const
Return target scheduling preference.
bool isInteger() const
isInteger - Return true if this is an integer, or a vector integer type.
virtual bool runOnMachineFunction(MachineFunction &MF)
unsigned getNumOperands() const
SDValue getConstantFP(double Val, EVT VT, bool isTarget=false)
static cl::opt< bool > EnableFastISelVerbose("fast-isel-verbose", cl::Hidden, cl::desc("Enable verbose messages in the \"fast\" ""instruction selector"))
unsigned AssignTopologicalOrder()
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
unsigned getNumValues() const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
ScheduleDAGSDNodes * createHybridListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level)
void initializeAliasAnalysisAnalysisGroup(PassRegistry &)
const APInt & getAPIntValue() const
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)
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
const BasicBlock * getBasicBlock() const
UNDEF - An undefined node.
unsigned getNumIncomingValues() const
const MachineBasicBlock * getParent() const
MachineRegisterInfo * RegInfo
bool isDebugValue() const
bool isImplicitDef() const
unsigned getNumSuccessors() const
SDNode * getNode() const
get the SDNode which holds the desired result
bundle_iterator< MachineInstr, instr_iterator > iterator
virtual bool IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const
initializer< Ty > init(const Ty &Val)
virtual FastISel * createFastISel(FunctionLoweringInfo &, const TargetLibraryInfo *) const
bool SelectInstruction(const Instruction *I)
CodeGenOpt::Level OptLevel
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckValueType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI)
std::vector< std::pair< MachineInstr *, unsigned > > PHINodesToUpdate
virtual bool CheckNodePredicate(SDNode *N, unsigned PredNo) const
bool intersects(const APInt &RHS) const
ScheduleDAGSDNodes * createVLIWDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createVLIWDAGScheduler - This creates a top-down list scheduler.
static void setDefault(FunctionPassCtor C)
ScheduleDAGSDNodes * createDefaultScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
LLVM Basic Block Representation.
const SDValue & getOperand(unsigned i) const
ScheduleDAGSDNodes * createBURRListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
void Combine(CombineLevel Level, AliasAnalysis &AA, CodeGenOpt::Level OptLevel)
void removeDeadCode(MachineBasicBlock::iterator I, MachineBasicBlock::iterator E)
Remove all dead instructions between the I and E.
bool isIndirectDebugValue() const
const MachineOperand & getOperand(unsigned i) const
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
Interval::pred_iterator pred_begin(Interval *I)
static unsigned getNumOperandRegisters(unsigned Flag)
BasicBlock * getIncomingBlock(unsigned i) const
ItTy next(ItTy it, Dist n)
void SelectInlineAsmMemoryOperands(std::vector< SDValue > &Ops)
void visitBitTestCase(BitTestBlock &BB, MachineBasicBlock *NextMBB, uint32_t BranchWeightToNext, unsigned Reg, BitTestCase &B, MachineBasicBlock *SwitchBB)
visitBitTestCase - this function produces one "bit test"
bool tryToFoldLoad(const LoadInst *LI, const Instruction *FoldInst)
We're checking to see if we can fold LI into FoldInst. Note that we could have a sequence where multi...
virtual void getAnalysisUsage(AnalysisUsage &AU) const
static void collectFailStats(const Instruction *I)
unsigned getOpcode() const
static cl::opt< bool > UseMBPI("use-mbpi", cl::desc("use Machine Branch Probability Info"), cl::init(true), cl::Hidden)
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
Interval::pred_iterator pred_end(Interval *I)
virtual void resetSubtargetFeatures(const MachineFunction *MF)
Reset the features for the subtarget.
MCSymbol * addLandingPad(MachineBasicBlock *LandingPad)
virtual void PostprocessISelDAG()
void RemoveDeadNode(SDNode *N)
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"))
use_iterator use_begin() const
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
unsigned ExceptionPointerVirtReg
SmallPtrSet< const BasicBlock *, 4 > VisitedBBs
static bool isMemKind(unsigned Flag)
unsigned getExceptionPointerRegister() const
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckOrImm(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const SelectionDAGISel &SDISel)
void ComputePHILiveOutRegInfo(const PHINode *)
HANDLENODE node - Used as a handle for various purposes.
const SDValue & getRoot() const
const MCInstrDesc & get(unsigned Opcode) const
MachineBasicBlock * MBB
MBB - The current block.
bool mayWriteToMemory() const
std::vector< NodeType * >::reverse_iterator rpo_iterator
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)
virtual SDNode * Select(SDNode *N)=0
Select - Main hook targets implement to select a node.
bool hasCalls() const
hasCalls - Return true if the current function has any function calls.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
virtual const TargetInstrInfo * getInstrInfo() const
void visitSPDescriptorFailure(StackProtectorDescriptor &SPD)
virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr *MI, MachineBasicBlock *MBB) const
Class for constant integers.
ScheduleDAGSDNodes * createILPListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level)
const STC & getSubtarget() const
allnodes_const_iterator allnodes_begin() const
Value * getIncomingValue(unsigned i) const
static FunctionPassCtor getDefault()
DenseMap< unsigned, unsigned > RegFixups
RegFixups - Registers which need to be replaced after isel is done.
SDNode * SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT)
SmallVector< MachineInstr *, 8 > ArgDbgValues
void setFastISel(bool Enable)
SelectionDAGISel(TargetMachine &tm, CodeGenOpt::Level OL=CodeGenOpt::Default)
bool isSuccessor(const MachineBasicBlock *MBB) const
void visit(const Instruction &I)
bool mayLoad() const
Return true if this instruction could possibly read memory. Instructions with this flag set are not n...
livein_iterator livein_begin() const
MachineFrameInfo * getFrameInfo()
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckNodePredicate(const unsigned char *MatcherTable, unsigned &MatcherIndex, const SelectionDAGISel &SDISel, SDNode *N)
CheckNodePredicate - Implements OP_CheckNodePredicate.
const BasicBlock & getEntryBlock() const
virtual bool CheckComplexPattern(SDNode *Root, SDNode *Parent, SDValue N, unsigned PatternNo, SmallVectorImpl< std::pair< SDValue, SDNode * > > &Result)
void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last)
static cl::opt< bool > ViewLegalizeTypesDAGs("view-legalize-types-dags", cl::Hidden, cl::desc("Pop up a window to show dags before legalize types"))
unsigned CreateRegs(Type *Ty)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
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"))
StringRef getName() const
Class for arbitrary precision integers.
static bool MIIsInTerminatorSequence(const MachineInstr *MI)
static unsigned IsPredicateKnownToFail(const unsigned char *Table, unsigned Index, SDValue N, bool &Result, const SelectionDAGISel &SDISel, SmallVectorImpl< std::pair< SDValue, SDNode * > > &RecordedNodes)
BranchProbabilityInfo * BPI
Function must not be optimized.
int64_t getSExtValue() const
op_iterator op_begin() const
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
static use_iterator use_end()
STATISTIC(NumFastIselFailures,"Number of instructions fast isel failed on")
std::vector< JumpTableBlock > JTCases
SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT)
void replaceRegWith(unsigned FromReg, unsigned ToReg)
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.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
void set(const Function &Fn, MachineFunction &MF)
bundle_iterator< const MachineInstr, const_instr_iterator > const_iterator
static ChainResult WalkChainUsers(const SDNode *ChainedNode, SmallVectorImpl< SDNode * > &ChainedNodesInPattern, SmallVectorImpl< SDNode * > &InteriorChainedNodes)
static bool isPhysicalRegister(unsigned Reg)
unsigned ExceptionSelectorVirtReg
bool isLandingPad() const
Analysis pass providing branch probability information.
Bitwise operators - logical and, logical or, logical xor.
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
std::string getName(ID id, ArrayRef< Type * > Tys=None)
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
MachineRegisterInfo & getRegInfo()
virtual const TargetIntrinsicInfo * getIntrinsicInfo() const
virtual void getAnalysisUsage(AnalysisUsage &AU) const
use_iterator use_begin(unsigned RegNo) const
virtual void viewGraph(const Twine &Name, const Twine &Title)
IMPLICIT_DEF - This is the MachineInstr-level equivalent of undef.
void initializeTargetLibraryInfoPass(PassRegistry &)
unsigned getSizeInBits() const
getSizeInBits - Return the size of the specified value type in bits.
void ReplaceAllUsesWith(SDValue From, SDValue Op)
DBG_VALUE - a mapping of the llvm.dbg.value intrinsic.
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"))
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI)
bool callsFunctionThatReturnsTwice() const
bool hasMSInlineAsm() const
Returns true if the function contains any MS-style inline assembly.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
MachineBasicBlock::iterator InsertPt
MBB - The current insert position inside the current block.
op_iterator op_end() const
instr_iterator insert(instr_iterator I, MachineInstr *M)
void Run(SelectionDAG *dag, MachineBasicBlock *bb)
MachineSDNode * getMachineNode(unsigned Opcode, SDLoc dl, EVT VT)
OptLevelChanger(SelectionDAGISel &ISel, CodeGenOpt::Level NewOptLevel)
virtual const TargetRegisterInfo * getRegisterInfo() const
iterator getFirstNonPHI()
void setExposesReturnsTwice(bool B)
bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS, int64_t DesiredMaskS) const
MachineInstr * getVRegDef(unsigned Reg) const
std::vector< std::pair< unsigned, unsigned > >::const_iterator livein_iterator
unsigned getReg() const
getReg - Returns the register number.
virtual bool CheckPatternPredicate(unsigned PredNo) const
void InvalidatePHILiveOutRegInfo(const PHINode *PN)
SDValue getRegister(unsigned Reg, EVT VT)
mop_iterator operands_begin()
void init(GCFunctionInfo *gfi, AliasAnalysis &aa, const TargetLibraryInfo *li)
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
virtual MachineBasicBlock * EmitSchedule(MachineBasicBlock::iterator &InsertPos)
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.
unsigned ComputeNumSignBits(SDValue Op, unsigned Depth=0) const
static cl::opt< bool > ViewSchedDAGs("view-sched-dags", cl::Hidden, cl::desc("Pop up a window to show sched dags as they are processed"))
ItTy prior(ItTy it, Dist n)
std::vector< CaseBlock > SwitchCases
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Machine Instruction Scheduler
DenseMap< const BasicBlock *, MachineBasicBlock * > MBBMap
MBBMap - A mapping from LLVM basic blocks to their machine code entry.
MachineModuleInfo & getMMI() const
void clearDanglingDebugInfo()
const MCRegisterInfo & MRI
virtual void PreprocessISelDAG()
static cl::opt< bool > EnableFastISelVerbose2("fast-isel-verbose2", cl::Hidden, cl::desc("Enable extra verbose messages in the \"fast\" ""instruction selector"))
SDValue getTargetConstant(uint64_t Val, EVT VT)
DenseMap< MachineBasicBlock *, SmallVector< unsigned, 4 > > LPadToCallSiteMap
LPadToCallSiteMap - Map a landing pad to the call site indexes.
unsigned getExceptionSelectorRegister() const
StringRef getName() const
const TargetTransformInfo * TTI
SDValue getEntryNode() const
bool TimePassesIsEnabled
This is the storage for the -time-passes option.
SDNode * getUser()
getUser - This returns the SDNode that contains this Use.
bool useMachineScheduler() const
Temporary API to test migration to MI scheduler.
void setHasMSInlineAsm(bool B)
iterator find(const KeyT &Val)
static cl::opt< bool > EnableFastISelAbort("fast-isel-abort", cl::Hidden, cl::desc("Enable abort calls when \"fast\" instruction selection ""fails to lower an instruction"))
DenseMap< const Value *, unsigned > ValueMap
MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num)
void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB)
static void SplitCriticalSideEffectEdges(Function &Fn, Pass *SDISel)
bool isExportedInst(const Value *V)
unsigned getResNo() const
getResNo - 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"))
DebugLoc getDebugLoc() const
static RegisterScheduler defaultListDAGScheduler("default","Best scheduler for the target", createDefaultScheduler)
bool isMachineOpcode() const
virtual SDValue RunSDNodeXForm(SDValue V, unsigned XFormNo)
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
This class is used by SelectionDAGISel to temporarily override the optimization level on a per-functi...