Skip to content

[llvm] annotate interfaces in llvm/CGData and llvm/CodeGen for DLL export #140823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions llvm/include/llvm/CGData/CodeGenData.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/IR/Module.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Caching.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/TargetParser/Triple.h"
#include <mutex>
Expand All @@ -34,9 +35,9 @@ enum CGDataSectKind {
#include "llvm/CGData/CodeGenData.inc"
};

std::string getCodeGenDataSectionName(CGDataSectKind CGSK,
Triple::ObjectFormatType OF,
bool AddSegmentInfo = true);
LLVM_ABI std::string getCodeGenDataSectionName(CGDataSectKind CGSK,
Triple::ObjectFormatType OF,
bool AddSegmentInfo = true);

enum class CGDataKind {
Unknown = 0x0,
Expand All @@ -47,7 +48,7 @@ enum class CGDataKind {
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/StableFunctionMergingMap)
};

const std::error_category &cgdata_category();
LLVM_ABI const std::error_category &cgdata_category();

enum class cgdata_error {
success = 0,
Expand All @@ -63,7 +64,7 @@ inline std::error_code make_error_code(cgdata_error E) {
return std::error_code(static_cast<int>(E), cgdata_category());
}

class CGDataError : public ErrorInfo<CGDataError> {
class LLVM_ABI CGDataError : public ErrorInfo<CGDataError> {
public:
CGDataError(cgdata_error Err, const Twine &ErrStr = Twine())
: Err(Err), Msg(ErrStr.str()) {
Expand Down Expand Up @@ -130,7 +131,7 @@ class CodeGenData {
public:
~CodeGenData() = default;

static CodeGenData &getInstance();
LLVM_ABI static CodeGenData &getInstance();

/// Returns true if we have a valid outlined hash tree.
bool hasOutlinedHashTree() {
Expand Down Expand Up @@ -245,27 +246,27 @@ struct StreamCacheData {
/// \p Task represents the partition number in the parallel code generation
/// process. \p AddStream is the callback used to add the serialized module to
/// the stream.
void saveModuleForTwoRounds(const Module &TheModule, unsigned Task,
AddStreamFn AddStream);
LLVM_ABI void saveModuleForTwoRounds(const Module &TheModule, unsigned Task,
AddStreamFn AddStream);

/// Load the optimized bitcode module for the second codegen round.
/// \p OrigModule is the original bitcode module.
/// \p Task identifies the partition number in the parallel code generation
/// process. \p Context provides the environment settings for module operations.
/// \p IRFiles contains optimized bitcode module files needed for loading.
/// \return A unique_ptr to the loaded Module, or nullptr if loading fails.
std::unique_ptr<Module> loadModuleForTwoRounds(BitcodeModule &OrigModule,
unsigned Task,
LLVMContext &Context,
ArrayRef<StringRef> IRFiles);
LLVM_ABI std::unique_ptr<Module>
loadModuleForTwoRounds(BitcodeModule &OrigModule, unsigned Task,
LLVMContext &Context, ArrayRef<StringRef> IRFiles);

/// Merge the codegen data from the scratch objects \p ObjectFiles from the
/// first codegen round.
/// \return the combined hash of the merged codegen data.
Expected<stable_hash> mergeCodeGenData(ArrayRef<StringRef> ObjectFiles);
LLVM_ABI Expected<stable_hash>
mergeCodeGenData(ArrayRef<StringRef> ObjectFiles);

void warn(Error E, StringRef Whence = "");
void warn(Twine Message, StringRef Whence = "", StringRef Hint = "");
LLVM_ABI void warn(Error E, StringRef Whence = "");
LLVM_ABI void warn(Twine Message, StringRef Whence = "", StringRef Hint = "");

} // end namespace cgdata

Expand Down Expand Up @@ -297,7 +298,7 @@ struct Header {
// the new field is read correctly.

// Reads a header struct from the buffer.
static Expected<Header> readFromBuffer(const unsigned char *Curr);
LLVM_ABI static Expected<Header> readFromBuffer(const unsigned char *Curr);
};

} // end namespace IndexedCGData
Expand Down
11 changes: 6 additions & 5 deletions llvm/include/llvm/CGData/CodeGenDataReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/CGData/CodeGenData.h"
#include "llvm/CGData/OutlinedHashTreeRecord.h"
#include "llvm/CGData/StableFunctionMapRecord.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/VirtualFileSystem.h"

Expand Down Expand Up @@ -49,20 +50,20 @@ class CodeGenDataReader {

/// Factory method to create an appropriately typed reader for the given
/// codegen data file path and file system.
static Expected<std::unique_ptr<CodeGenDataReader>>
LLVM_ABI static Expected<std::unique_ptr<CodeGenDataReader>>
create(const Twine &Path, vfs::FileSystem &FS);

/// Factory method to create an appropriately typed reader for the given
/// memory buffer.
static Expected<std::unique_ptr<CodeGenDataReader>>
LLVM_ABI static Expected<std::unique_ptr<CodeGenDataReader>>
create(std::unique_ptr<MemoryBuffer> Buffer);

/// Extract the cgdata embedded in sections from the given object file and
/// merge them into the GlobalOutlineRecord. This is a static helper that
/// is used by `llvm-cgdata --merge` or ThinLTO's two-codegen rounds.
/// Optionally, \p CombinedHash can be used to compuate the combined hash of
/// the merged data.
static Error
LLVM_ABI static Error
mergeFromObjectFile(const object::ObjectFile *Obj,
OutlinedHashTreeRecord &GlobalOutlineRecord,
StableFunctionMapRecord &GlobalFunctionMapRecord,
Expand Down Expand Up @@ -98,7 +99,7 @@ class CodeGenDataReader {
Error success() { return error(cgdata_error::success); }
};

class IndexedCodeGenDataReader : public CodeGenDataReader {
class LLVM_ABI IndexedCodeGenDataReader : public CodeGenDataReader {
/// The codegen data file contents.
std::unique_ptr<MemoryBuffer> DataBuffer;
/// The header
Expand Down Expand Up @@ -139,7 +140,7 @@ class IndexedCodeGenDataReader : public CodeGenDataReader {
/// codegen data is recorded. `#` is used to indicate a comment.
/// The subsequent data is a YAML format per each codegen data in order.
/// Currently, it only has a function outlined hash tree.
class TextCodeGenDataReader : public CodeGenDataReader {
class LLVM_ABI TextCodeGenDataReader : public CodeGenDataReader {
/// The codegen data file contents.
std::unique_ptr<MemoryBuffer> DataBuffer;
/// Iterator over the profile data.
Expand Down
11 changes: 6 additions & 5 deletions llvm/include/llvm/CGData/CodeGenDataWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/CGData/CodeGenData.h"
#include "llvm/CGData/OutlinedHashTreeRecord.h"
#include "llvm/CGData/StableFunctionMapRecord.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/Error.h"

Expand Down Expand Up @@ -45,7 +46,7 @@ class CGDataOStream {
// \c patch can only be called when all data is written and flushed.
// For raw_string_ostream, the patch is done on the target string
// directly and it won't be reflected in the stream's internal buffer.
void patch(ArrayRef<CGDataPatchItem> P);
LLVM_ABI void patch(ArrayRef<CGDataPatchItem> P);

// If \c OS is an instance of \c raw_fd_ostream, this field will be
// true. Otherwise, \c OS will be an raw_string_ostream.
Expand All @@ -69,16 +70,16 @@ class CodeGenDataWriter {
~CodeGenDataWriter() = default;

/// Add the outlined hash tree record. The input hash tree is released.
void addRecord(OutlinedHashTreeRecord &Record);
LLVM_ABI void addRecord(OutlinedHashTreeRecord &Record);

/// Add the stable function map record. The input function map is released.
void addRecord(StableFunctionMapRecord &Record);
LLVM_ABI void addRecord(StableFunctionMapRecord &Record);

/// Write the codegen data to \c OS
Error write(raw_fd_ostream &OS);
LLVM_ABI Error write(raw_fd_ostream &OS);

/// Write the codegen data in text format to \c OS
Error writeText(raw_fd_ostream &OS);
LLVM_ABI Error writeText(raw_fd_ostream &OS);

/// Return the attributes of the current CGData.
CGDataKind getCGDataKind() const { return DataKind; }
Expand Down
17 changes: 9 additions & 8 deletions llvm/include/llvm/CGData/OutlinedHashTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StableHashing.h"
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"

#include <unordered_map>
Expand Down Expand Up @@ -54,9 +55,9 @@ class OutlinedHashTree {
/// the source and the stable_hash of the sink for an edge. These generic
/// callbacks can be used to traverse a OutlinedHashTree for the purpose of
/// print debugging or serializing it.
void walkGraph(NodeCallbackFn CallbackNode,
EdgeCallbackFn CallbackEdge = nullptr,
bool SortedWalk = false) const;
LLVM_ABI void walkGraph(NodeCallbackFn CallbackNode,
EdgeCallbackFn CallbackEdge = nullptr,
bool SortedWalk = false) const;

/// Release all hash nodes except the root hash node.
void clear() {
Expand All @@ -71,24 +72,24 @@ class OutlinedHashTree {
/// \p GetTerminalCountOnly is true, it only counts the terminal nodes
/// (meaning it returns the the number of hash sequences in the
/// OutlinedHashTree).
size_t size(bool GetTerminalCountOnly = false) const;
LLVM_ABI size_t size(bool GetTerminalCountOnly = false) const;

/// \returns the depth of a OutlinedHashTree by traversing it.
size_t depth() const;
LLVM_ABI size_t depth() const;

/// \returns the root hash node of a OutlinedHashTree.
const HashNode *getRoot() const { return &Root; }
HashNode *getRoot() { return &Root; }

/// Inserts a \p Sequence into the this tree. The last node in the sequence
/// will increase Terminals.
void insert(const HashSequencePair &SequencePair);
LLVM_ABI void insert(const HashSequencePair &SequencePair);

/// Merge a \p OtherTree into this Tree.
void merge(const OutlinedHashTree *OtherTree);
LLVM_ABI void merge(const OutlinedHashTree *OtherTree);

/// \returns the matching count if \p Sequence exists in the OutlinedHashTree.
std::optional<unsigned> find(const HashSequence &Sequence) const;
LLVM_ABI std::optional<unsigned> find(const HashSequence &Sequence) const;

private:
HashNode Root;
Expand Down
9 changes: 5 additions & 4 deletions llvm/include/llvm/CGData/OutlinedHashTreeRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define LLVM_CGDATA_OUTLINEDHASHTREERECORD_H

#include "llvm/CGData/OutlinedHashTree.h"
#include "llvm/Support/Compiler.h"

namespace llvm {

Expand All @@ -40,13 +41,13 @@ struct OutlinedHashTreeRecord {
: HashTree(std::move(HashTree)) {};

/// Serialize the outlined hash tree to a raw_ostream.
void serialize(raw_ostream &OS) const;
LLVM_ABI void serialize(raw_ostream &OS) const;
/// Deserialize the outlined hash tree from a raw_ostream.
void deserialize(const unsigned char *&Ptr);
LLVM_ABI void deserialize(const unsigned char *&Ptr);
/// Serialize the outlined hash tree to a YAML stream.
void serializeYAML(yaml::Output &YOS) const;
LLVM_ABI void serializeYAML(yaml::Output &YOS) const;
/// Deserialize the outlined hash tree from a YAML stream.
void deserializeYAML(yaml::Input &YIS);
LLVM_ABI void deserializeYAML(yaml::Input &YIS);

/// Merge the other outlined hash tree into this one.
void merge(const OutlinedHashTreeRecord &Other) {
Expand Down
13 changes: 7 additions & 6 deletions llvm/include/llvm/CGData/StableFunctionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/IR/StructuralHash.h"
#include "llvm/Support/Compiler.h"

namespace llvm {

Expand Down Expand Up @@ -82,18 +83,18 @@ struct StableFunctionMap {

/// Get an existing ID associated with the given name or create a new ID if it
/// doesn't exist.
unsigned getIdOrCreateForName(StringRef Name);
LLVM_ABI unsigned getIdOrCreateForName(StringRef Name);

/// Get the name associated with a given ID
std::optional<std::string> getNameForId(unsigned Id) const;
LLVM_ABI std::optional<std::string> getNameForId(unsigned Id) const;

/// Insert a `StableFunction` object into the function map. This method
/// handles the uniquing of string names and create a `StableFunctionEntry`
/// for insertion.
void insert(const StableFunction &Func);
LLVM_ABI void insert(const StableFunction &Func);

/// Merge a \p OtherMap into this function map.
void merge(const StableFunctionMap &OtherMap);
LLVM_ABI void merge(const StableFunctionMap &OtherMap);

/// \returns true if there is no stable function entry.
bool empty() const { return size() == 0; }
Expand All @@ -107,10 +108,10 @@ struct StableFunctionMap {

/// \returns the size of StableFunctionMap.
/// \p Type is the type of size to return.
size_t size(SizeType Type = UniqueHashCount) const;
LLVM_ABI size_t size(SizeType Type = UniqueHashCount) const;

/// Finalize the stable function map by trimming content.
void finalize(bool SkipTrim = false);
LLVM_ABI void finalize(bool SkipTrim = false);

private:
/// Insert a `StableFunctionEntry` into the function map directly. This
Expand Down
12 changes: 7 additions & 5 deletions llvm/include/llvm/CGData/StableFunctionMapRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "llvm/CGData/StableFunctionMap.h"
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"

namespace llvm {
Expand All @@ -34,19 +35,20 @@ struct StableFunctionMapRecord {

/// A static helper function to serialize the stable function map without
/// owning the stable function map.
static void serialize(raw_ostream &OS, const StableFunctionMap *FunctionMap);
LLVM_ABI static void serialize(raw_ostream &OS,
const StableFunctionMap *FunctionMap);

/// Serialize the stable function map to a raw_ostream.
void serialize(raw_ostream &OS) const;
LLVM_ABI void serialize(raw_ostream &OS) const;

/// Deserialize the stable function map from a raw_ostream.
void deserialize(const unsigned char *&Ptr);
LLVM_ABI void deserialize(const unsigned char *&Ptr);

/// Serialize the stable function map to a YAML stream.
void serializeYAML(yaml::Output &YOS) const;
LLVM_ABI void serializeYAML(yaml::Output &YOS) const;

/// Deserialize the stable function map from a YAML stream.
void deserializeYAML(yaml::Input &YIS);
LLVM_ABI void deserializeYAML(yaml::Input &YIS);

/// Finalize the stable function map by trimming content.
void finalize(bool SkipTrim = false) { FunctionMap->finalize(SkipTrim); }
Expand Down
Loading