Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/include/llvm/Transforms/IPO/Attributor.h
Show First 20 Lines • Show All 1,183 Lines • ▼ Show 20 Lines | Attributor(SetVector<Function *> &Functions, InformationCache &InfoCache, | ||||
DeleteFns(DeleteFns), RewriteSignatures(RewriteSignatures), | DeleteFns(DeleteFns), RewriteSignatures(RewriteSignatures), | ||||
MaxFixpointIterations(MaxFixpointIterations), | MaxFixpointIterations(MaxFixpointIterations), | ||||
OREGetter(Optional<OptimizationRemarkGetter>(OREGetter)), | OREGetter(Optional<OptimizationRemarkGetter>(OREGetter)), | ||||
PassName(PassName) {} | PassName(PassName) {} | ||||
~Attributor(); | ~Attributor(); | ||||
/// Run the analyses until a fixpoint is reached or enforced (timeout). | /// Run the analyses until a fixpoint is reached or enforced (timeout). | ||||
/// This method will run iteration, and manifest the changes to IR. | |||||
/// | |||||
/// This function runs all Attributor phases, for unrelated sets of | |||||
/// attributes, it would be more efficient to run Attributor in multiple | |||||
/// stages. \see runStage() and \see finalize() | |||||
/// | /// | ||||
/// The attributes registered with this Attributor can be used after as long | /// The attributes registered with this Attributor can be used after as long | ||||
/// as the Attributor is not destroyed (it owns the attributes now). | /// as the Attributor is not destroyed (it owns the attributes now). | ||||
/// | /// | ||||
/// \Returns CHANGED if the IR was changed, otherwise UNCHANGED. | /// \Returns CHANGED if the IR was changed, otherwise UNCHANGED. | ||||
ChangeStatus run(); | ChangeStatus run(); | ||||
/// Run a Attributor stage. | |||||
/// This method will do fixpoint iteration until fixpoint or the | |||||
/// maximum iteration count is reached. | |||||
/// | |||||
/// If the maximum iteration count is reached, This method will | |||||
/// indicate pessimistic fixpoint on attributes that transitively depend | |||||
/// on attributes that were scheduled for an update. | |||||
/// | |||||
/// After calling this function, you can still call `getAAFor` function to | |||||
/// seed more Attributes and then you can call this function again to run the | |||||
/// iteration one more time. Dividing the deduction process for independent | |||||
/// attributes helps with performance. | |||||
/// | |||||
/// The changes won't be manifested to IR until `finalize` function is called. | |||||
void runStage(); | |||||
/// Manifest the changes to IR and clean up deleted functions. | |||||
/// | |||||
/// \Returns CHANGED if the IR was changed, otherwise UNCHANGED. | |||||
ChangeStatus finalize(); | |||||
/// Lookup an abstract attribute of type \p AAType at position \p IRP. While | /// Lookup an abstract attribute of type \p AAType at position \p IRP. While | ||||
/// no abstract attribute is found equivalent positions are checked, see | /// no abstract attribute is found equivalent positions are checked, see | ||||
/// SubsumingPositionIterator. Thus, the returned abstract attribute | /// SubsumingPositionIterator. Thus, the returned abstract attribute | ||||
/// might be anchored at a different position, e.g., the callee if \p IRP is a | /// might be anchored at a different position, e.g., the callee if \p IRP is a | ||||
/// call base. | /// call base. | ||||
/// | /// | ||||
/// This method is the only (supported) way an abstract attribute can retrieve | /// This method is the only (supported) way an abstract attribute can retrieve | ||||
/// information from another abstract attribute. As an example, take an | /// information from another abstract attribute. As an example, take an | ||||
▲ Show 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | return !Functions.empty() && | ||||
Functions.size() == Functions.front()->getParent()->size(); | Functions.size() == Functions.front()->getParent()->size(); | ||||
} | } | ||||
/// Return true if we derive attributes for \p Fn | /// Return true if we derive attributes for \p Fn | ||||
bool isRunOn(Function &Fn) const { | bool isRunOn(Function &Fn) const { | ||||
return Functions.empty() || Functions.count(&Fn); | return Functions.empty() || Functions.count(&Fn); | ||||
} | } | ||||
/// Seed initial Attributes that should be run in the first stage. | |||||
/// Seeding Attributes such as `AAIsDead` before any other attribute, | |||||
/// helps with performance as it reduces wasted updates. | |||||
/// | |||||
/// \param F The function that is checked for attribute opportunities. | |||||
/// | |||||
void identifyFirstStageAttributes(Function &F); | |||||
/// Determine opportunities to derive 'default' attributes in \p F and create | /// Determine opportunities to derive 'default' attributes in \p F and create | ||||
/// abstract attribute objects for them. | /// abstract attribute objects for them. | ||||
/// | /// | ||||
/// \param F The function that is checked for attribute opportunities. | /// \param F The function that is checked for attribute opportunities. | ||||
/// | /// | ||||
/// Note that abstract attribute instances are generally created even if the | /// Note that abstract attribute instances are generally created even if the | ||||
/// IR already contains the information they would deduce. The most important | /// IR already contains the information they would deduce. The most important | ||||
/// reason for this is the single interface, the one of the abstract attribute | /// reason for this is the single interface, the one of the abstract attribute | ||||
▲ Show 20 Lines • Show All 464 Lines • ▼ Show 20 Lines | public: | ||||
/// Return the data layout associated with the anchor scope. | /// Return the data layout associated with the anchor scope. | ||||
const DataLayout &getDataLayout() const { return InfoCache.DL; } | const DataLayout &getDataLayout() const { return InfoCache.DL; } | ||||
/// The allocator used to allocate memory, e.g. for `AbstractAttribute`s. | /// The allocator used to allocate memory, e.g. for `AbstractAttribute`s. | ||||
BumpPtrAllocator &Allocator; | BumpPtrAllocator &Allocator; | ||||
private: | private: | ||||
/// This method will do fixpoint iteration until fixpoint or the | |||||
/// maximum iteration count is reached. | |||||
/// | |||||
/// If the maximum iteration count is reached, This method will | |||||
/// indicate pessimistic fixpoint on attributes that transitively depend | |||||
/// on attributes that were scheduled for an update. | |||||
void runTillFixpoint(); | void runTillFixpoint(); | ||||
/// Gets called after scheduling, manifests attributes to the LLVM IR. | /// Gets called after scheduling, manifests attributes to the LLVM IR. | ||||
ChangeStatus manifestAttributes(); | ChangeStatus manifestAttributes(); | ||||
/// Gets called after attributes have been manifested, cleans up the IR. | /// Gets called after attributes have been manifested, cleans up the IR. | ||||
/// Deletes dead functions, blocks and instructions. | /// Deletes dead functions, blocks and instructions. | ||||
/// Rewrites function signitures and updates the call graph. | /// Rewrites function signitures and updates the call graph. | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | private: | ||||
const bool DeleteFns; | const bool DeleteFns; | ||||
/// Whether to rewrite signatures. | /// Whether to rewrite signatures. | ||||
const bool RewriteSignatures; | const bool RewriteSignatures; | ||||
/// Maximum number of fixedpoint iterations. | /// Maximum number of fixedpoint iterations. | ||||
Optional<unsigned> MaxFixpointIterations; | Optional<unsigned> MaxFixpointIterations; | ||||
/// A set to remember the functions we already assume to be live and visited. | |||||
DenseSet<const Function *> VisitedFunctions; | |||||
/// Uses we replace with a new value after manifest is done. We will remove | /// Uses we replace with a new value after manifest is done. We will remove | ||||
/// then trivially dead instructions as well. | /// then trivially dead instructions as well. | ||||
DenseMap<Use *, Value *> ToBeChangedUses; | DenseMap<Use *, Value *> ToBeChangedUses; | ||||
/// Values we replace with a new value after manifest is done. We will remove | /// Values we replace with a new value after manifest is done. We will remove | ||||
/// then trivially dead instructions as well. | /// then trivially dead instructions as well. | ||||
DenseMap<Value *, std::pair<Value *, bool>> ToBeChangedValues; | DenseMap<Value *, std::pair<Value *, bool>> ToBeChangedValues; | ||||
▲ Show 20 Lines • Show All 2,601 Lines • Show Last 20 Lines |