llvm.org GIT mirror llvm / 0bf56c8
Further improvements to pre-RA-sched=list-ilp. This change uses the MaxReorderWindow for both height and depth, which tends to limit the negative effects of high register pressure. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127203 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 8 years ago
1 changed file(s) with 62 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
9898 #ifndef NDEBUG
9999 namespace {
100100 // For sched=list-ilp, Count the number of times each factor comes into play.
101 enum { FactPressureDiff, FactRegUses, FactHeight, FactDepth, FactUllman,
102 NumFactors };
101 enum { FactPressureDiff, FactRegUses, FactHeight, FactDepth, FactStatic,
102 FactOther, NumFactors };
103103 }
104104 static const char *FactorName[NumFactors] =
105 {"PressureDiff", "RegUses", "Height", "Depth","Ullman"};
105 {"PressureDiff", "RegUses", "Height", "Depth","Static", "Other"};
106106 static int FactorCount[NumFactors];
107107 #endif //!NDEBUG
108108
21022102 unsigned LPriority = SPQ->getNodePriority(left);
21032103 unsigned RPriority = SPQ->getNodePriority(right);
21042104 if (LPriority != RPriority) {
2105 DEBUG(++FactorCount[FactUllman]);
2105 DEBUG(++FactorCount[FactStatic]);
21062106 return LPriority > RPriority;
21072107 }
2108 DEBUG(++FactorCount[FactOther]);
2109
21082110 // Try schedule def + use closer when Sethi-Ullman numbers are the same.
21092111 // e.g.
21102112 // t1 = op t2, c1
22272229 return true;
22282230 }
22292231
2232 bool canEnableCoaelscing(SUnit *SU) {
2233 unsigned Opc = SU->getNode() ? SU->getNode()->getOpcode() : 0;
2234 if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg)
2235 // CopyToReg should be close to its uses to facilitate coalescing and
2236 // avoid spilling.
2237 return true;
2238
2239 if (Opc == TargetOpcode::EXTRACT_SUBREG ||
2240 Opc == TargetOpcode::SUBREG_TO_REG ||
2241 Opc == TargetOpcode::INSERT_SUBREG)
2242 // EXTRACT_SUBREG, INSERT_SUBREG, and SUBREG_TO_REG nodes should be
2243 // close to their uses to facilitate coalescing.
2244 return true;
2245
2246 if (SU->NumPreds == 0 && SU->NumSuccs != 0)
2247 // If SU does not have a register def, schedule it close to its uses
2248 // because it does not lengthen any live ranges.
2249 return true;
2250
2251 return false;
2252 }
2253
22302254 // list-ilp is currently an experimental scheduler that allows various
22312255 // heuristics to be enabled prior to the normal register reduction logic.
22322256 bool ilp_ls_rr_sort::operator()(SUnit *left, SUnit *right) const {
22342258 // No way to compute latency of calls.
22352259 return BURRSort(left, right, SPQ);
22362260
2237 unsigned LLiveUses, RLiveUses;
2238 int LPDiff = SPQ->RegPressureDiff(left, LLiveUses);
2239 int RPDiff = SPQ->RegPressureDiff(right, RLiveUses);
2261 unsigned LLiveUses = 0, RLiveUses = 0;
2262 int LPDiff = 0, RPDiff = 0;
2263 if (!DisableSchedRegPressure || !DisableSchedLiveUses) {
2264 LPDiff = SPQ->RegPressureDiff(left, LLiveUses);
2265 RPDiff = SPQ->RegPressureDiff(right, RLiveUses);
2266 }
22402267 if (!DisableSchedRegPressure && LPDiff != RPDiff) {
22412268 DEBUG(++FactorCount[FactPressureDiff]);
2269 DEBUG(dbgs() << "RegPressureDiff SU(" << left->NodeNum << "): " << LPDiff
2270 << " != SU(" << right->NodeNum << "): " << RPDiff << "\n");
22422271 return LPDiff > RPDiff;
22432272 }
22442273
2245 if (!DisableSchedLiveUses && LLiveUses != RLiveUses) {
2246 DEBUG(dbgs() << "Live uses " << left->NodeNum << " = " << LLiveUses
2247 << " != " << right->NodeNum << " = " << RLiveUses << "\n");
2274 if (!DisableSchedRegPressure && (LPDiff > 0 || RPDiff > 0)) {
2275 bool LReduce = canEnableCoaelscing(left);
2276 bool RReduce = canEnableCoaelscing(right);
2277 DEBUG(if (LReduce != RReduce) ++FactorCount[FactPressureDiff]);
2278 if (LReduce && !RReduce) return false;
2279 if (RReduce && !LReduce) return true;
2280 }
2281
2282 if (!DisableSchedLiveUses && (LLiveUses != RLiveUses)) {
2283 DEBUG(dbgs() << "Live uses SU(" << left->NodeNum << "): " << LLiveUses
2284 << " != SU(" << right->NodeNum << "): " << RLiveUses << "\n");
22482285 DEBUG(++FactorCount[FactRegUses]);
22492286 return LLiveUses < RLiveUses;
22502287 }
22512288
2252 bool LStall = BUHasStall(left, left->getHeight(), SPQ);
2253 bool RStall = BUHasStall(right, right->getHeight(), SPQ);
2254 if (!DisableSchedStalls && LStall != RStall) {
2255 DEBUG(++FactorCount[FactHeight]);
2256 return left->getHeight() > right->getHeight();
2289 if (!DisableSchedStalls) {
2290 bool LStall = BUHasStall(left, left->getHeight(), SPQ);
2291 bool RStall = BUHasStall(right, right->getHeight(), SPQ);
2292 if (LStall != RStall) {
2293 DEBUG(++FactorCount[FactHeight]);
2294 return left->getHeight() > right->getHeight();
2295 }
22572296 }
22582297
22592298 if (!DisableSchedCriticalPath) {
22602299 int spread = (int)left->getDepth() - (int)right->getDepth();
22612300 if (std::abs(spread) > MaxReorderWindow) {
2301 DEBUG(dbgs() << "Depth of SU(" << left->NodeNum << "): "
2302 << left->getDepth() << " != SU(" << right->NodeNum << "): "
2303 << right->getDepth() << "\n");
22622304 DEBUG(++FactorCount[FactDepth]);
22632305 return left->getDepth() < right->getDepth();
22642306 }
22652307 }
22662308
22672309 if (!DisableSchedHeight && left->getHeight() != right->getHeight()) {
2268 DEBUG(++FactorCount[FactHeight]);
2269 return left->getHeight() > right->getHeight();
2310 int spread = (int)left->getHeight() - (int)right->getHeight();
2311 if (std::abs(spread) > MaxReorderWindow) {
2312 DEBUG(++FactorCount[FactHeight]);
2313 return left->getHeight() > right->getHeight();
2314 }
22702315 }
22712316
22722317 return BURRSort(left, right, SPQ);