@@ -75,28 +75,34 @@ template <typename ContextT> class GenericCycle {
7575 unsigned Depth = 0 ;
7676
7777 // / Cache for the results of GetExitBlocks
78- std::unique_ptr< SmallVector<BlockT *, 4 > > ExitBlocksCache;
78+ mutable SmallVector<BlockT *, 4 > ExitBlocksCache;
7979
8080 void clear () {
8181 Entries.clear ();
8282 Children.clear ();
8383 Blocks.clear ();
8484 Depth = 0 ;
8585 ParentCycle = nullptr ;
86- ExitBlocksCache-> clear ();
86+ clearCache ();
8787 }
8888
89- void appendEntry (BlockT *Block) { Entries.push_back (Block); }
90- void appendBlock (BlockT *Block) { Blocks.insert (Block); }
89+ void appendEntry (BlockT *Block) {
90+ Entries.push_back (Block);
91+ clearCache ();
92+ }
93+
94+ void appendBlock (BlockT *Block) {
95+ Blocks.insert (Block);
96+ clearCache ();
97+ }
9198
9299 GenericCycle (const GenericCycle &) = delete ;
93100 GenericCycle &operator =(const GenericCycle &) = delete ;
94101 GenericCycle (GenericCycle &&Rhs) = delete ;
95102 GenericCycle &operator =(GenericCycle &&Rhs) = delete ;
96103
97104public:
98- GenericCycle ()
99- : ExitBlocksCache(std::make_unique<SmallVector<BlockT *, 4 >>()) {};
105+ GenericCycle () = default ;
100106
101107 // / \brief Whether the cycle is a natural loop.
102108 bool isReducible () const { return Entries.size () == 1 ; }
@@ -107,6 +113,13 @@ template <typename ContextT> class GenericCycle {
107113 return Entries;
108114 }
109115
116+ // / Clear the cache of the cycle.
117+ // / This should be run in all non-const function in GenericCycle
118+ // / and GenericCycleInfo.
119+ void clearCache () const {
120+ ExitBlocksCache.clear ();
121+ }
122+
110123 // / \brief Return whether \p Block is an entry block of the cycle.
111124 bool isEntry (const BlockT *Block) const {
112125 return is_contained (Entries, Block);
@@ -117,6 +130,7 @@ template <typename ContextT> class GenericCycle {
117130 assert (contains (Block));
118131 Entries.clear ();
119132 Entries.push_back (Block);
133+ clearCache ();
120134 }
121135
122136 // / \brief Return whether \p Block is contained in the cycle.
@@ -129,7 +143,12 @@ template <typename ContextT> class GenericCycle {
129143 bool contains (const GenericCycle *C) const ;
130144
131145 const GenericCycle *getParentCycle () const { return ParentCycle; }
132- GenericCycle *getParentCycle () { return ParentCycle; }
146+
147+ GenericCycle *getParentCycle () {
148+ clearCache ();
149+ return ParentCycle;
150+ }
151+
133152 unsigned getDepth () const { return Depth; }
134153
135154 // / Return all of the successor blocks of this cycle.
0 commit comments