diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -133,6 +133,12 @@ "candidate when choosing the best split candidate."), cl::init(false)); +static cl::opt GrowRegionComplexityBudget( + "grow-region-complexity-budget", + cl::desc("growRegion() does not scale with the number of BB edges, so " + "limit its budget and bail out once we reach the limit."), + cl::init(10000), cl::Hidden); + static RegisterRegAlloc greedyRegAlloc("greedy", "greedy register allocator", createGreedyRegisterAllocator); @@ -784,6 +790,7 @@ unsigned Visited = 0; #endif + long Budget = GrowRegionComplexityBudget; while (true) { ArrayRef NewBundles = SpillPlacer->getRecentPositive(); // Find new through blocks in the periphery of PrefRegBundles. @@ -791,6 +798,9 @@ // Look at all blocks connected to Bundle in the full graph. ArrayRef Blocks = Bundles->getBlocks(Bundle); for (unsigned Block : Blocks) { + // Limit compilation time by bailing out after we use all our budget. + if (Budget-- == 0) + return false; if (!Todo.test(Block)) continue; Todo.reset(Block);