#ifndef LLVM_IR_MODULE_H
#define LLVM_IR_MODULE_H
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/DataLayout.h"
class RandomNumberGenerator;
class StructType;
-template<> struct ilist_traits<Function>
- : public SymbolTableListTraits<Function, Module> {
-
- // createSentinel is used to get hold of the node that marks the end of the
- // list... (same trick used here as in ilist_traits<Instruction>)
- Function *createSentinel() const {
- return static_cast<Function*>(&Sentinel);
- }
- static void destroySentinel(Function*) {}
-
- Function *provideInitialHead() const { return createSentinel(); }
- Function *ensureHead(Function*) const { return createSentinel(); }
- static void noteHead(Function*, Function*) {}
-
-private:
- mutable ilist_node<Function> Sentinel;
-};
-
-template<> struct ilist_traits<GlobalVariable>
- : public SymbolTableListTraits<GlobalVariable, Module> {
- // createSentinel is used to create a node that marks the end of the list.
- GlobalVariable *createSentinel() const {
- return static_cast<GlobalVariable*>(&Sentinel);
- }
- static void destroySentinel(GlobalVariable*) {}
-
- GlobalVariable *provideInitialHead() const { return createSentinel(); }
- GlobalVariable *ensureHead(GlobalVariable *) const {
- return createSentinel();
- }
- static void noteHead(GlobalVariable *, GlobalVariable *) {}
-
-private:
- mutable ilist_node<GlobalVariable> Sentinel;
-};
-
-template<> struct ilist_traits<GlobalAlias>
- : public SymbolTableListTraits<GlobalAlias, Module> {
- // createSentinel is used to create a node that marks the end of the list.
- GlobalAlias *createSentinel() const {
- return static_cast<GlobalAlias*>(&Sentinel);
- }
- static void destroySentinel(GlobalAlias*) {}
-
- GlobalAlias *provideInitialHead() const { return createSentinel(); }
- GlobalAlias *ensureHead(GlobalAlias *) const { return createSentinel(); }
- static void noteHead(GlobalAlias *, GlobalAlias *) {}
-
-private:
- mutable ilist_node<GlobalAlias> Sentinel;
-};
-
template<> struct ilist_traits<NamedMDNode>
: public ilist_default_traits<NamedMDNode> {
// createSentinel is used to get hold of a node that marks the end of
/// @{
public:
/// The type for the list of global variables.
- typedef iplist<GlobalVariable> GlobalListType;
+ typedef SymbolTableList<GlobalVariable> GlobalListType;
/// The type for the list of functions.
- typedef iplist<Function> FunctionListType;
+ typedef SymbolTableList<Function> FunctionListType;
/// The type for the list of aliases.
- typedef iplist<GlobalAlias> AliasListType;
+ typedef SymbolTableList<GlobalAlias> AliasListType;
/// The type for the list of named metadata.
typedef ilist<NamedMDNode> NamedMDListType;
/// The type of the comdat "symbol" table.
/// Sets the GVMaterializer to GVM. This module must not yet have a
/// Materializer. To reset the materializer for a module that already has one,
- /// call MaterializeAllPermanently first. Destroying this module will destroy
+ /// call materializeAll first. Destroying this module will destroy
/// its materializer without materializing any more GlobalValues. Without
/// destroying the Module, there is no way to detach or destroy a materializer
/// without materializing all the GVs it controls, to avoid leaving orphan
void setMaterializer(GVMaterializer *GVM);
/// Retrieves the GVMaterializer, if any, for this Module.
GVMaterializer *getMaterializer() const { return Materializer.get(); }
-
- /// Returns true if this GV was loaded from this Module's GVMaterializer and
- /// the GVMaterializer knows how to dematerialize the GV.
- bool isDematerializable(const GlobalValue *GV) const;
+ bool isMaterialized() const { return !getMaterializer(); }
/// Make sure the GlobalValue is fully read. If the module is corrupt, this
/// returns true and fills in the optional string with information about the
/// problem. If successful, this returns false.
std::error_code materialize(GlobalValue *GV);
- /// If the GlobalValue is read in, and if the GVMaterializer supports it,
- /// release the memory for the function, and set it up to be materialized
- /// lazily. If !isDematerializable(), this method is a no-op.
- void dematerialize(GlobalValue *GV);
-
- /// Make sure all GlobalValues in this Module are fully read.
- std::error_code materializeAll();
/// Make sure all GlobalValues in this Module are fully read and clear the
- /// Materializer. If the module is corrupt, this DOES NOT clear the old
/// Materializer.
- std::error_code materializeAllPermanently();
+ std::error_code materializeAll();
std::error_code materializeMetadata();
bool global_empty() const { return GlobalList.empty(); }
iterator_range<global_iterator> globals() {
- return iterator_range<global_iterator>(global_begin(), global_end());
+ return make_range(global_begin(), global_end());
}
iterator_range<const_global_iterator> globals() const {
- return iterator_range<const_global_iterator>(global_begin(), global_end());
+ return make_range(global_begin(), global_end());
}
/// @}
bool empty() const { return FunctionList.empty(); }
iterator_range<iterator> functions() {
- return iterator_range<iterator>(begin(), end());
+ return make_range(begin(), end());
}
iterator_range<const_iterator> functions() const {
- return iterator_range<const_iterator>(begin(), end());
+ return make_range(begin(), end());
}
/// @}
bool alias_empty() const { return AliasList.empty(); }
iterator_range<alias_iterator> aliases() {
- return iterator_range<alias_iterator>(alias_begin(), alias_end());
+ return make_range(alias_begin(), alias_end());
}
iterator_range<const_alias_iterator> aliases() const {
- return iterator_range<const_alias_iterator>(alias_begin(), alias_end());
+ return make_range(alias_begin(), alias_end());
}
/// @}
bool named_metadata_empty() const { return NamedMDList.empty(); }
iterator_range<named_metadata_iterator> named_metadata() {
- return iterator_range<named_metadata_iterator>(named_metadata_begin(),
- named_metadata_end());
+ return make_range(named_metadata_begin(), named_metadata_end());
}
iterator_range<const_named_metadata_iterator> named_metadata() const {
- return iterator_range<const_named_metadata_iterator>(named_metadata_begin(),
- named_metadata_end());
+ return make_range(named_metadata_begin(), named_metadata_end());
}
/// Destroy ConstantArrays in LLVMContext if they are not used.
/// \brief Set the PIC level (small or large model)
void setPICLevel(PICLevel::Level PL);
/// @}
+
+ /// @name Utility functions for querying and setting PGO counts
+ /// @{
+
+ /// \brief Set maximum function count in PGO mode
+ void setMaximumFunctionCount(uint64_t);
+
+ /// \brief Returns maximum function count in PGO mode
+ Optional<uint64_t> getMaximumFunctionCount();
+ /// @}
};
/// An raw_ostream inserter for modules.