llvm.org GIT mirror llvm / 631ee4b
Use the EdgeBundles analysis in X86FloatingPoint instead of recomputing CFG bundles in the pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122833 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 9 years ago
2 changed file(s) with 18 addition(s) and 88 deletion(s). Raw diff Collapse all Expand all
3636 /// bundle number for basic block #N
3737 unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
3838
39 /// getNumBundles - Return the total number of bundles in the CFG.
40 unsigned getNumBundles() const { return EC.getNumClasses(); }
41
3942 /// getMachineFunction - Return the last machine function computed.
4043 const MachineFunction *getMachineFunction() const { return MF; }
4144
9696 // FixStack[i] == getStackEntry(i) for all i < FixCount.
9797 unsigned char FixStack[8];
9898
99 LiveBundle(unsigned m = 0) : Mask(m), FixCount(0) {}
99 LiveBundle() : Mask(0), FixCount(0) {}
100100
101101 // Have the live registers been assigned a stack order yet?
102102 bool isFixed() const { return !Mask || FixCount; }
106106 // with no live FP registers.
107107 SmallVector LiveBundles;
108108
109 // Map each MBB in the current function to an (ingoing, outgoing) index into
110 // LiveBundles. Blocks with no FP registers live in or out map to (0, 0)
111 // and are not actually stored in the map.
112 DenseMap > BlockBundle;
109 // The edge bundle analysis provides indices into the LiveBundles vector.
110 EdgeBundles *Bundles;
113111
114112 // Return a bitmask of FP registers in block's live-in list.
115113 unsigned calcLiveInMask(MachineBasicBlock *MBB) {
286284 // Early exit.
287285 if (!FPIsUsed) return false;
288286
287 Bundles = &getAnalysis();
289288 TII = MF.getTarget().getInstrInfo();
290289
291290 // Prepare cross-MBB liveness.
310309 if (Processed.insert(BB))
311310 Changed |= processBasicBlock(MF, *BB);
312311
313 BlockBundle.clear();
314312 LiveBundles.clear();
315313
316314 return Changed;
323321 /// registers may be implicitly defined, or not used by all successors.
324322 void FPS::bundleCFG(MachineFunction &MF) {
325323 assert(LiveBundles.empty() && "Stale data in LiveBundles");
326 assert(BlockBundle.empty() && "Stale data in BlockBundle");
327 SmallPtrSet PropDown, PropUp;
328
329 // LiveBundle[0] is the empty live-in set.
330 LiveBundles.resize(1);
331
332 // First gather the actual live-in masks for all MBBs.
324 LiveBundles.resize(Bundles->getNumBundles());
325
326 // Gather the actual live-in masks for all MBBs.
333327 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
334328 MachineBasicBlock *MBB = I;
335329 const unsigned Mask = calcLiveInMask(MBB);
336330 if (!Mask)
337331 continue;
338 // Ingoing bundle index.
339 unsigned &Idx = BlockBundle[MBB].first;
340 // Already assigned an ingoing bundle?
341 if (Idx)
342 continue;
343 // Allocate a new LiveBundle struct for this block's live-ins.
344 const unsigned BundleIdx = Idx = LiveBundles.size();
345 DEBUG(dbgs() << "Creating LB#" << BundleIdx << ": in:BB#"
346 << MBB->getNumber());
347 LiveBundles.push_back(Mask);
348 LiveBundle &Bundle = LiveBundles.back();
349
350 // Make sure all predecessors have the same live-out set.
351 PropUp.insert(MBB);
352
353 // Keep pushing liveness up and down the CFG until convergence.
354 // Only critical edges cause iteration here, but when they do, multiple
355 // blocks can be assigned to the same LiveBundle index.
356 do {
357 // Assign BundleIdx as liveout from predecessors in PropUp.
358 for (SmallPtrSet::iterator I = PropUp.begin(),
359 E = PropUp.end(); I != E; ++I) {
360 MachineBasicBlock *MBB = *I;
361 for (MachineBasicBlock::const_pred_iterator LinkI = MBB->pred_begin(),
362 LinkE = MBB->pred_end(); LinkI != LinkE; ++LinkI) {
363 MachineBasicBlock *PredMBB = *LinkI;
364 // PredMBB's liveout bundle should be set to LIIdx.
365 unsigned &Idx = BlockBundle[PredMBB].second;
366 if (Idx) {
367 assert(Idx == BundleIdx && "Inconsistent CFG");
368 continue;
369 }
370 Idx = BundleIdx;
371 DEBUG(dbgs() << " out:BB#" << PredMBB->getNumber());
372 // Propagate to siblings.
373 if (PredMBB->succ_size() > 1)
374 PropDown.insert(PredMBB);
375 }
376 }
377 PropUp.clear();
378
379 // Assign BundleIdx as livein to successors in PropDown.
380 for (SmallPtrSet::iterator I = PropDown.begin(),
381 E = PropDown.end(); I != E; ++I) {
382 MachineBasicBlock *MBB = *I;
383 for (MachineBasicBlock::const_succ_iterator LinkI = MBB->succ_begin(),
384 LinkE = MBB->succ_end(); LinkI != LinkE; ++LinkI) {
385 MachineBasicBlock *SuccMBB = *LinkI;
386 // LinkMBB's livein bundle should be set to BundleIdx.
387 unsigned &Idx = BlockBundle[SuccMBB].first;
388 if (Idx) {
389 assert(Idx == BundleIdx && "Inconsistent CFG");
390 continue;
391 }
392 Idx = BundleIdx;
393 DEBUG(dbgs() << " in:BB#" << SuccMBB->getNumber());
394 // Propagate to siblings.
395 if (SuccMBB->pred_size() > 1)
396 PropUp.insert(SuccMBB);
397 // Also accumulate the bundle liveness mask from the liveins here.
398 Bundle.Mask |= calcLiveInMask(SuccMBB);
399 }
400 }
401 PropDown.clear();
402 } while (!PropUp.empty());
403 DEBUG({
404 dbgs() << " live:";
405 for (unsigned i = 0; i < 8; ++i)
406 if (Bundle.Mask & (1<
407 dbgs() << " %FP" << i;
408 dbgs() << '\n';
409 });
332 // Update MBB ingoing bundle mask.
333 LiveBundles[Bundles->getBundle(MBB->getNumber(), false)].Mask |= Mask;
410334 }
411335 }
412336
494418 return Changed;
495419 }
496420
497 /// setupBlockStack - Use the BlockBundle map to set up our model of the stack
421 /// setupBlockStack - Use the live bundles to set up our model of the stack
498422 /// to match predecessors' live out stack.
499423 void FPS::setupBlockStack() {
500424 DEBUG(dbgs() << "\nSetting up live-ins for BB#" << MBB->getNumber()
501425 << " derived from " << MBB->getName() << ".\n");
502426 StackTop = 0;
503 const LiveBundle &Bundle = LiveBundles[BlockBundle.lookup(MBB).first];
427 // Get the live-in bundle for MBB.
428 const LiveBundle &Bundle =
429 LiveBundles[Bundles->getBundle(MBB->getNumber(), false)];
504430
505431 if (!Bundle.Mask) {
506432 DEBUG(dbgs() << "Block has no FP live-ins.\n");
537463 DEBUG(dbgs() << "Setting up live-outs for BB#" << MBB->getNumber()
538464 << " derived from " << MBB->getName() << ".\n");
539465
540 unsigned BundleIdx = BlockBundle.lookup(MBB).second;
466 // Get MBB's live-out bundle.
467 unsigned BundleIdx = Bundles->getBundle(MBB->getNumber(), true);
541468 LiveBundle &Bundle = LiveBundles[BundleIdx];
542469
543470 // We may need to kill and define some registers to match successors.