@@ -582,71 +582,10 @@ class AnalysisState {
582582// / bufferization process.
583583class BufferizationState {
584584public:
585- // / Base class for BufferizationState extensions that allow BufferizationState
586- // / to contain user-specified information in the state object. The extension
587- // / mechanism of BufferizationState mirrors the one of OneShotAnalysisState.
588- class Extension {
589- public:
590- // / Base virtual destructor.
591- // Out-of-line definition ensures symbols are emitted in a single object
592- // file.
593- virtual ~Extension ();
594-
595- protected:
596- // / Constructs an extension of the given state object.
597- Extension (BufferizationState &state) : state(state) {}
598-
599- // / Provides read-only access to the parent OneShotAnalysisState object.
600- const BufferizationState &getBufferizationState () const { return state; }
601-
602- private:
603- // / Back-reference to the state that is being extended.
604- BufferizationState &state;
605- };
606-
607- // / Adds a new Extension of the type specified as template parameter,
608- // / constructing it with the arguments provided. The extension is owned by the
609- // / BufferizationState. It is expected that the state does not already have an
610- // / extension of the same type. Extension constructors are expected to take a
611- // / reference to BufferizationState as first argument, automatically supplied
612- // / by this call.
613- template <typename Ty, typename ... Args>
614- Ty &addExtension (Args &&...args) {
615- static_assert (std::is_base_of<Extension, Ty>::value,
616- " only a class derived from "
617- " BufferizationState::Extension is allowed" );
618- auto ptr = std::make_unique<Ty>(*this , std::forward<Args>(args)...);
619- auto result = extensions.try_emplace (TypeID::get<Ty>(), std::move (ptr));
620- assert (result.second && " extension already added" );
621- return *static_cast <Ty *>(result.first ->second .get ());
622- }
623-
624- // / Returns the extension of the specified type.
625- template <typename Ty>
626- Ty *getExtension () {
627- static_assert (std::is_base_of<Extension, Ty>::value,
628- " only a class derived from "
629- " BufferizationState::Extension is allowed" );
630- auto iter = extensions.find (TypeID::get<Ty>());
631- if (iter == extensions.end ())
632- return nullptr ;
633- return static_cast <Ty *>(iter->second .get ());
634- }
635-
636- // / Returns the extension of the specified type.
637- template <typename Ty>
638- const Ty *getExtension () const {
639- return const_cast <BufferizationState *>(this )->getExtension <Ty>();
640- }
641-
642585 // / Get a reference to the collection of cached symbol tables.
643586 SymbolTableCollection &getSymbolTables ();
644587
645588private:
646- // / Extensions attached to the state, identified by the TypeID of their type.
647- // / Only one extension of any given type is allowed.
648- DenseMap<TypeID, std::unique_ptr<Extension>> extensions;
649-
650589 // / The cached symbol tables.
651590 // / The user is expected to update / invalidate the cached symbol tables if
652591 // / the bufferized operation has the Symbol or SymbolTable traits.
0 commit comments