@@ -293,6 +293,10 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
293293 // numbered and this vector keeps track of the mapping from ID's to MBB's.
294294 std::vector<MachineBasicBlock*> MBBNumbering;
295295
296+ // MBBNumbering epoch, incremented after renumbering to detect use of old
297+ // block numbers.
298+ unsigned MBBNumberingEpoch = 0 ;
299+
296300 // Pool-allocate MachineFunction-lifetime and IR objects.
297301 BumpPtrAllocator Allocator;
298302
@@ -856,6 +860,11 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
856860 // / getNumBlockIDs - Return the number of MBB ID's allocated.
857861 unsigned getNumBlockIDs () const { return (unsigned )MBBNumbering.size (); }
858862
863+ // / Return the numbering "epoch" of block numbers, incremented after each
864+ // / numbering. Intended for asserting that no renumbering was performed when
865+ // / used by, e.g., preserved analyses.
866+ unsigned getBlockNumberEpoch () const { return MBBNumberingEpoch; }
867+
859868 // / RenumberBlocks - This discards all of the MachineBasicBlock numbers and
860869 // / recomputes them. This guarantees that the MBB numbers are sequential,
861870 // / dense, and match the ordering of the blocks within the function. If a
@@ -1404,6 +1413,13 @@ template <> struct GraphTraits<MachineFunction*> :
14041413 }
14051414
14061415 static unsigned size (MachineFunction *F) { return F->size (); }
1416+
1417+ static unsigned getMaxNumber (MachineFunction *F) {
1418+ return F->getNumBlockIDs ();
1419+ }
1420+ static unsigned getNumberEpoch (MachineFunction *F) {
1421+ return F->getBlockNumberEpoch ();
1422+ }
14071423};
14081424template <> struct GraphTraits <const MachineFunction*> :
14091425 public GraphTraits<const MachineBasicBlock*> {
@@ -1423,6 +1439,13 @@ template <> struct GraphTraits<const MachineFunction*> :
14231439 static unsigned size (const MachineFunction *F) {
14241440 return F->size ();
14251441 }
1442+
1443+ static unsigned getMaxNumber (const MachineFunction *F) {
1444+ return F->getNumBlockIDs ();
1445+ }
1446+ static unsigned getNumberEpoch (const MachineFunction *F) {
1447+ return F->getBlockNumberEpoch ();
1448+ }
14261449};
14271450
14281451// Provide specializations of GraphTraits to be able to treat a function as a
@@ -1435,12 +1458,26 @@ template <> struct GraphTraits<Inverse<MachineFunction*>> :
14351458 static NodeRef getEntryNode (Inverse<MachineFunction *> G) {
14361459 return &G.Graph ->front ();
14371460 }
1461+
1462+ static unsigned getMaxNumber (MachineFunction *F) {
1463+ return F->getNumBlockIDs ();
1464+ }
1465+ static unsigned getNumberEpoch (MachineFunction *F) {
1466+ return F->getBlockNumberEpoch ();
1467+ }
14381468};
14391469template <> struct GraphTraits <Inverse<const MachineFunction*>> :
14401470 public GraphTraits<Inverse<const MachineBasicBlock*>> {
14411471 static NodeRef getEntryNode (Inverse<const MachineFunction *> G) {
14421472 return &G.Graph ->front ();
14431473 }
1474+
1475+ static unsigned getMaxNumber (const MachineFunction *F) {
1476+ return F->getNumBlockIDs ();
1477+ }
1478+ static unsigned getNumberEpoch (const MachineFunction *F) {
1479+ return F->getBlockNumberEpoch ();
1480+ }
14441481};
14451482
14461483void verifyMachineFunction (const std::string &Banner,
0 commit comments