Skip to content

[llvm] annotate interfaces in llvm/ProfileData for DLL export #142861

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

Merged
merged 3 commits into from
Jun 10, 2025
Merged
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
50 changes: 27 additions & 23 deletions llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ enum class coveragemap_error {
invalid_or_missing_arch_specifier
};

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

inline std::error_code make_error_code(coveragemap_error E) {
return std::error_code(static_cast<int>(E), coveragemap_category());
}

class CoverageMapError : public ErrorInfo<CoverageMapError> {
class LLVM_ABI CoverageMapError : public ErrorInfo<CoverageMapError> {
public:
CoverageMapError(coveragemap_error Err, const Twine &ErrStr = Twine())
: Err(Err), Msg(ErrStr.str()) {
Expand Down Expand Up @@ -210,19 +210,19 @@ class CounterExpressionBuilder {
ArrayRef<CounterExpression> getExpressions() const { return Expressions; }

/// Return a counter that represents the expression that adds LHS and RHS.
Counter add(Counter LHS, Counter RHS, bool Simplify = true);
LLVM_ABI Counter add(Counter LHS, Counter RHS, bool Simplify = true);

/// Return a counter that represents the expression that subtracts RHS from
/// LHS.
Counter subtract(Counter LHS, Counter RHS, bool Simplify = true);
LLVM_ABI Counter subtract(Counter LHS, Counter RHS, bool Simplify = true);

/// K to V map. K will be Counter in most cases. V may be Counter or
/// Expression.
using SubstMap = std::map<Counter, Counter>;

/// \return A counter equivalent to \C, with each term in its
/// expression replaced with term from \p Map.
Counter subst(Counter C, const SubstMap &Map);
LLVM_ABI Counter subst(Counter C, const SubstMap &Map);
};

using LineColPair = std::pair<unsigned, unsigned>;
Expand Down Expand Up @@ -473,7 +473,7 @@ struct MCDCRecord {

// Compare executed test vectors against each other to find an independence
// pairs for each condition. This processing takes the most time.
void findIndependencePairs();
LLVM_ABI void findIndependencePairs();

const CounterMappingRegion &getDecisionRegion() const { return Region; }
unsigned getNumConditions() const {
Expand Down Expand Up @@ -665,7 +665,8 @@ class TVIdxBuilder {
/// \param NextIDs The list of {FalseID, TrueID} indexed by ID
/// The first element [0] should be the root node.
/// \param Offset Offset of index to final decisions.
TVIdxBuilder(const SmallVectorImpl<ConditionIDs> &NextIDs, int Offset = 0);
LLVM_ABI TVIdxBuilder(const SmallVectorImpl<ConditionIDs> &NextIDs,
int Offset = 0);
};
} // namespace mcdc

Expand All @@ -684,21 +685,21 @@ class CounterMappingContext {
void setCounts(ArrayRef<uint64_t> Counts) { CounterValues = Counts; }
void setBitmap(BitVector &&Bitmap_) { Bitmap = std::move(Bitmap_); }

void dump(const Counter &C, raw_ostream &OS) const;
LLVM_ABI void dump(const Counter &C, raw_ostream &OS) const;
void dump(const Counter &C) const { dump(C, dbgs()); }

/// Return the number of times that a region of code associated with this
/// counter was executed.
Expected<int64_t> evaluate(const Counter &C) const;
LLVM_ABI Expected<int64_t> evaluate(const Counter &C) const;

/// Return an MCDC record that indicates executed test vectors and condition
/// pairs.
Expected<MCDCRecord>
LLVM_ABI Expected<MCDCRecord>
evaluateMCDCRegion(const CounterMappingRegion &Region,
ArrayRef<const CounterMappingRegion *> Branches,
bool IsVersion11);

unsigned getMaxCounterID(const Counter &C) const;
LLVM_ABI unsigned getMaxCounterID(const Counter &C) const;
};

/// Code coverage information for a single function.
Expand Down Expand Up @@ -761,7 +762,7 @@ class FunctionRecordIterator
StringRef Filename;

/// Skip records whose primary file is not \c Filename.
void skipOtherFiles();
LLVM_ABI void skipOtherFiles();

public:
FunctionRecordIterator(ArrayRef<FunctionRecord> Records_,
Expand Down Expand Up @@ -1007,22 +1008,22 @@ class CoverageMapping {
/// defined in the specified file. This is guaranteed to return a superset of
/// such records: extra records not in the file may be included if there is
/// a hash collision on the filename. Clients must be robust to collisions.
ArrayRef<unsigned>
LLVM_ABI ArrayRef<unsigned>
getImpreciseRecordIndicesForFilename(StringRef Filename) const;

public:
CoverageMapping(const CoverageMapping &) = delete;
CoverageMapping &operator=(const CoverageMapping &) = delete;

/// Load the coverage mapping using the given readers.
static Expected<std::unique_ptr<CoverageMapping>>
LLVM_ABI static Expected<std::unique_ptr<CoverageMapping>>
load(ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
IndexedInstrProfReader &ProfileReader);

/// Load the coverage mapping from the given object files and profile. If
/// \p Arches is non-empty, it must specify an architecture for each object.
/// Ignores non-instrumented object files unless all are not instrumented.
static Expected<std::unique_ptr<CoverageMapping>>
LLVM_ABI static Expected<std::unique_ptr<CoverageMapping>>
load(ArrayRef<StringRef> ObjectFilenames, StringRef ProfileFilename,
vfs::FileSystem &FS, ArrayRef<StringRef> Arches = {},
StringRef CompilationDir = "",
Expand All @@ -1045,20 +1046,22 @@ class CoverageMapping {

/// Returns a lexicographically sorted, unique list of files that are
/// covered.
std::vector<StringRef> getUniqueSourceFiles() const;
LLVM_ABI std::vector<StringRef> getUniqueSourceFiles() const;

/// Get the coverage for a particular file.
///
/// The given filename must be the name as recorded in the coverage
/// information. That is, only names returned from getUniqueSourceFiles will
/// yield a result.
CoverageData getCoverageForFile(StringRef Filename) const;
LLVM_ABI CoverageData getCoverageForFile(StringRef Filename) const;

/// Get the coverage for a particular function.
CoverageData getCoverageForFunction(const FunctionRecord &Function) const;
LLVM_ABI CoverageData
getCoverageForFunction(const FunctionRecord &Function) const;

/// Get the coverage for an expansion within a coverage set.
CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const;
LLVM_ABI CoverageData
getCoverageForExpansion(const ExpansionRecord &Expansion) const;

/// Gets all of the functions covered by this profile.
iterator_range<FunctionRecordIterator> getCoveredFunctions() const {
Expand All @@ -1079,7 +1082,7 @@ class CoverageMapping {
///
/// Every instantiation group in a program is attributed to exactly one file:
/// the file in which the definition for the common function begins.
std::vector<InstantiationGroup>
LLVM_ABI std::vector<InstantiationGroup>
getInstantiationGroups(StringRef Filename) const;
};

Expand All @@ -1096,8 +1099,9 @@ class LineCoverageStats {
LineCoverageStats() = default;

public:
LineCoverageStats(ArrayRef<const CoverageSegment *> LineSegments,
const CoverageSegment *WrappedSegment, unsigned Line);
LLVM_ABI LineCoverageStats(ArrayRef<const CoverageSegment *> LineSegments,
const CoverageSegment *WrappedSegment,
unsigned Line);

uint64_t getExecutionCount() const { return ExecutionCount; }

Expand Down Expand Up @@ -1136,7 +1140,7 @@ class LineCoverageIterator

const LineCoverageStats &operator*() const { return Stats; }

LineCoverageIterator &operator++();
LLVM_ABI LineCoverageIterator &operator++();

LineCoverageIterator getEnd() const {
auto EndIt = *this;
Expand Down
19 changes: 10 additions & 9 deletions llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include <cstddef>
Expand Down Expand Up @@ -46,7 +47,7 @@ class CoverageMappingIterator {
CoverageMappingRecord Record;
coveragemap_error ReadErr;

void increment();
LLVM_ABI void increment();

public:
using iterator_category = std::input_iterator_tag;
Expand Down Expand Up @@ -112,10 +113,10 @@ class RawCoverageReader {

RawCoverageReader(StringRef Data) : Data(Data) {}

Error readULEB128(uint64_t &Result);
Error readIntMax(uint64_t &Result, uint64_t MaxPlus1);
Error readSize(uint64_t &Result);
Error readString(StringRef &Result);
LLVM_ABI Error readULEB128(uint64_t &Result);
LLVM_ABI Error readIntMax(uint64_t &Result, uint64_t MaxPlus1);
LLVM_ABI Error readSize(uint64_t &Result);
LLVM_ABI Error readString(StringRef &Result);
};

/// Checks if the given coverage mapping data is exported for
Expand All @@ -125,7 +126,7 @@ class RawCoverageMappingDummyChecker : public RawCoverageReader {
RawCoverageMappingDummyChecker(StringRef MappingData)
: RawCoverageReader(MappingData) {}

Expected<bool> isDummy();
LLVM_ABI Expected<bool> isDummy();
};

/// Reader for the raw coverage mapping data.
Expand All @@ -149,7 +150,7 @@ class RawCoverageMappingReader : public RawCoverageReader {
RawCoverageMappingReader &
operator=(const RawCoverageMappingReader &) = delete;

Error read();
LLVM_ABI Error read();

private:
Error decodeCounter(unsigned Value, Counter &C);
Expand All @@ -161,7 +162,7 @@ class RawCoverageMappingReader : public RawCoverageReader {

/// Reader for the coverage mapping data that is emitted by the
/// frontend and stored in an object file.
class BinaryCoverageReader : public CoverageMappingReader {
class LLVM_ABI BinaryCoverageReader : public CoverageMappingReader {
public:
struct ProfileMappingRecord {
CovMapVersion Version;
Expand Down Expand Up @@ -245,7 +246,7 @@ class RawCoverageFilenamesReader : public RawCoverageReader {
RawCoverageFilenamesReader &
operator=(const RawCoverageFilenamesReader &) = delete;

Error read(CovMapVersion Version);
LLVM_ABI Error read(CovMapVersion Version);
};

} // end namespace coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
#include "llvm/Support/Compiler.h"

namespace llvm {

Expand All @@ -30,11 +31,11 @@ class CoverageFilenamesSectionWriter {
ArrayRef<std::string> Filenames;

public:
CoverageFilenamesSectionWriter(ArrayRef<std::string> Filenames);
LLVM_ABI CoverageFilenamesSectionWriter(ArrayRef<std::string> Filenames);

/// Write encoded filenames to the given output stream. If \p Compress is
/// true, attempt to compress the filenames.
void write(raw_ostream &OS, bool Compress = true);
LLVM_ABI void write(raw_ostream &OS, bool Compress = true);
};

/// Writer for instrumentation based coverage mapping data.
Expand All @@ -51,7 +52,7 @@ class CoverageMappingWriter {
MappingRegions(MappingRegions) {}

/// Write encoded coverage mapping data to the given output stream.
void write(raw_ostream &OS);
LLVM_ABI void write(raw_ostream &OS);
};

/// Writer for the coverage mapping testing format.
Expand All @@ -70,7 +71,7 @@ class TestingFormatWriter {
CoverageRecordsData(CoverageRecordsData) {}

/// Encode to the given output stream.
void
LLVM_ABI void
write(raw_ostream &OS,
TestingFormatVersion Version = TestingFormatVersion::CurrentVersion);
};
Expand Down
19 changes: 11 additions & 8 deletions llvm/include/llvm/ProfileData/DataAccessProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/StringSaver.h"

Expand Down Expand Up @@ -138,33 +139,35 @@ class DataAccessProfData {
/// - Serialized strings.
/// - The encoded hashes.
/// - Records.
Error serialize(ProfOStream &OS) const;
LLVM_ABI Error serialize(ProfOStream &OS) const;

/// Deserialize this class from the given buffer.
Error deserialize(const unsigned char *&Ptr);
LLVM_ABI Error deserialize(const unsigned char *&Ptr);

/// Returns a profile record for \p SymbolID, or std::nullopt if there
/// isn't a record. Internally, this function will canonicalize the symbol
/// name before the lookup.
std::optional<DataAccessProfRecord>
LLVM_ABI std::optional<DataAccessProfRecord>
getProfileRecord(const SymbolHandleRef SymID) const;

/// Returns true if \p SymID is seen in profiled binaries and cold.
bool isKnownColdSymbol(const SymbolHandleRef SymID) const;
LLVM_ABI bool isKnownColdSymbol(const SymbolHandleRef SymID) const;

/// Methods to set symbolized data access profile. Returns error if
/// duplicated symbol names or content hashes are seen. The user of this
/// class should aggregate counters that correspond to the same symbol name
/// or with the same string literal hash before calling 'set*' methods.
Error setDataAccessProfile(SymbolHandleRef SymbolID, uint64_t AccessCount);
LLVM_ABI Error setDataAccessProfile(SymbolHandleRef SymbolID,
uint64_t AccessCount);
/// Similar to the method above, for records with \p Locations representing
/// the `filename:line` where this symbol shows up. Note because of linker's
/// merge of identical symbols (e.g., unnamed_addr string literals), one
/// symbol is likely to have multiple locations.
Error setDataAccessProfile(SymbolHandleRef SymbolID, uint64_t AccessCount,
ArrayRef<SourceLocation> Locations);
LLVM_ABI Error setDataAccessProfile(SymbolHandleRef SymbolID,
uint64_t AccessCount,
ArrayRef<SourceLocation> Locations);
/// Add a symbol that's seen in the profiled binary without samples.
Error addKnownSymbolWithoutSamples(SymbolHandleRef SymbolID);
LLVM_ABI Error addKnownSymbolWithoutSamples(SymbolHandleRef SymbolID);

/// The following methods return array reference for various internal data
/// structures.
Expand Down
Loading