Skip to content

Commit 6bd606f

Browse files
authored
[llvm] annotate interfaces in llvm/ProfileData for DLL export (#142861)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/ProfileData` library. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). The bulk of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. The following manual adjustments were also applied after running IDS on Linux: - Manually annotate the file `llvm/include/llvm/ProfileData/InstrProfData.inc` because it is skipped by IDS - Add `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE` to exported instantiated templates. - Add `LLVM_ABI_FRIEND` to friend member functions declared with `LLVM_ABI` - Add `LLVM_ABI` to a small number of symbols that require export but are not declared in headers ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
1 parent 1c8206b commit 6bd606f

28 files changed

+430
-364
lines changed

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ enum class coveragemap_error {
7171
invalid_or_missing_arch_specifier
7272
};
7373

74-
const std::error_category &coveragemap_category();
74+
LLVM_ABI const std::error_category &coveragemap_category();
7575

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

80-
class CoverageMapError : public ErrorInfo<CoverageMapError> {
80+
class LLVM_ABI CoverageMapError : public ErrorInfo<CoverageMapError> {
8181
public:
8282
CoverageMapError(coveragemap_error Err, const Twine &ErrStr = Twine())
8383
: Err(Err), Msg(ErrStr.str()) {
@@ -210,19 +210,19 @@ class CounterExpressionBuilder {
210210
ArrayRef<CounterExpression> getExpressions() const { return Expressions; }
211211

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

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

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

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

228228
using LineColPair = std::pair<unsigned, unsigned>;
@@ -473,7 +473,7 @@ struct MCDCRecord {
473473

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

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

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

687-
void dump(const Counter &C, raw_ostream &OS) const;
688+
LLVM_ABI void dump(const Counter &C, raw_ostream &OS) const;
688689
void dump(const Counter &C) const { dump(C, dbgs()); }
689690

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

694695
/// Return an MCDC record that indicates executed test vectors and condition
695696
/// pairs.
696-
Expected<MCDCRecord>
697+
LLVM_ABI Expected<MCDCRecord>
697698
evaluateMCDCRegion(const CounterMappingRegion &Region,
698699
ArrayRef<const CounterMappingRegion *> Branches,
699700
bool IsVersion11);
700701

701-
unsigned getMaxCounterID(const Counter &C) const;
702+
LLVM_ABI unsigned getMaxCounterID(const Counter &C) const;
702703
};
703704

704705
/// Code coverage information for a single function.
@@ -761,7 +762,7 @@ class FunctionRecordIterator
761762
StringRef Filename;
762763

763764
/// Skip records whose primary file is not \c Filename.
764-
void skipOtherFiles();
765+
LLVM_ABI void skipOtherFiles();
765766

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

10131014
public:
10141015
CoverageMapping(const CoverageMapping &) = delete;
10151016
CoverageMapping &operator=(const CoverageMapping &) = delete;
10161017

10171018
/// Load the coverage mapping using the given readers.
1018-
static Expected<std::unique_ptr<CoverageMapping>>
1019+
LLVM_ABI static Expected<std::unique_ptr<CoverageMapping>>
10191020
load(ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
10201021
IndexedInstrProfReader &ProfileReader);
10211022

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

10461047
/// Returns a lexicographically sorted, unique list of files that are
10471048
/// covered.
1048-
std::vector<StringRef> getUniqueSourceFiles() const;
1049+
LLVM_ABI std::vector<StringRef> getUniqueSourceFiles() const;
10491050

10501051
/// Get the coverage for a particular file.
10511052
///
10521053
/// The given filename must be the name as recorded in the coverage
10531054
/// information. That is, only names returned from getUniqueSourceFiles will
10541055
/// yield a result.
1055-
CoverageData getCoverageForFile(StringRef Filename) const;
1056+
LLVM_ABI CoverageData getCoverageForFile(StringRef Filename) const;
10561057

10571058
/// Get the coverage for a particular function.
1058-
CoverageData getCoverageForFunction(const FunctionRecord &Function) const;
1059+
LLVM_ABI CoverageData
1060+
getCoverageForFunction(const FunctionRecord &Function) const;
10591061

10601062
/// Get the coverage for an expansion within a coverage set.
1061-
CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const;
1063+
LLVM_ABI CoverageData
1064+
getCoverageForExpansion(const ExpansionRecord &Expansion) const;
10621065

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

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

10981101
public:
1099-
LineCoverageStats(ArrayRef<const CoverageSegment *> LineSegments,
1100-
const CoverageSegment *WrappedSegment, unsigned Line);
1102+
LLVM_ABI LineCoverageStats(ArrayRef<const CoverageSegment *> LineSegments,
1103+
const CoverageSegment *WrappedSegment,
1104+
unsigned Line);
11011105

11021106
uint64_t getExecutionCount() const { return ExecutionCount; }
11031107

@@ -1136,7 +1140,7 @@ class LineCoverageIterator
11361140

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

1139-
LineCoverageIterator &operator++();
1143+
LLVM_ABI LineCoverageIterator &operator++();
11401144

11411145
LineCoverageIterator getEnd() const {
11421146
auto EndIt = *this;

llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
2020
#include "llvm/ProfileData/InstrProf.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/Error.h"
2223
#include "llvm/Support/MemoryBuffer.h"
2324
#include <cstddef>
@@ -46,7 +47,7 @@ class CoverageMappingIterator {
4647
CoverageMappingRecord Record;
4748
coveragemap_error ReadErr;
4849

49-
void increment();
50+
LLVM_ABI void increment();
5051

5152
public:
5253
using iterator_category = std::input_iterator_tag;
@@ -112,10 +113,10 @@ class RawCoverageReader {
112113

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

115-
Error readULEB128(uint64_t &Result);
116-
Error readIntMax(uint64_t &Result, uint64_t MaxPlus1);
117-
Error readSize(uint64_t &Result);
118-
Error readString(StringRef &Result);
116+
LLVM_ABI Error readULEB128(uint64_t &Result);
117+
LLVM_ABI Error readIntMax(uint64_t &Result, uint64_t MaxPlus1);
118+
LLVM_ABI Error readSize(uint64_t &Result);
119+
LLVM_ABI Error readString(StringRef &Result);
119120
};
120121

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

128-
Expected<bool> isDummy();
129+
LLVM_ABI Expected<bool> isDummy();
129130
};
130131

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

152-
Error read();
153+
LLVM_ABI Error read();
153154

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

162163
/// Reader for the coverage mapping data that is emitted by the
163164
/// frontend and stored in an object file.
164-
class BinaryCoverageReader : public CoverageMappingReader {
165+
class LLVM_ABI BinaryCoverageReader : public CoverageMappingReader {
165166
public:
166167
struct ProfileMappingRecord {
167168
CovMapVersion Version;
@@ -245,7 +246,7 @@ class RawCoverageFilenamesReader : public RawCoverageReader {
245246
RawCoverageFilenamesReader &
246247
operator=(const RawCoverageFilenamesReader &) = delete;
247248

248-
Error read(CovMapVersion Version);
249+
LLVM_ABI Error read(CovMapVersion Version);
249250
};
250251

251252
} // end namespace coverage

llvm/include/llvm/ProfileData/Coverage/CoverageMappingWriter.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/ArrayRef.h"
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
20+
#include "llvm/Support/Compiler.h"
2021

2122
namespace llvm {
2223

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

3233
public:
33-
CoverageFilenamesSectionWriter(ArrayRef<std::string> Filenames);
34+
LLVM_ABI CoverageFilenamesSectionWriter(ArrayRef<std::string> Filenames);
3435

3536
/// Write encoded filenames to the given output stream. If \p Compress is
3637
/// true, attempt to compress the filenames.
37-
void write(raw_ostream &OS, bool Compress = true);
38+
LLVM_ABI void write(raw_ostream &OS, bool Compress = true);
3839
};
3940

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

5354
/// Write encoded coverage mapping data to the given output stream.
54-
void write(raw_ostream &OS);
55+
LLVM_ABI void write(raw_ostream &OS);
5556
};
5657

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

7273
/// Encode to the given output stream.
73-
void
74+
LLVM_ABI void
7475
write(raw_ostream &OS,
7576
TestingFormatVersion Version = TestingFormatVersion::CurrentVersion);
7677
};

llvm/include/llvm/ProfileData/DataAccessProf.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "llvm/ADT/StringRef.h"
2525
#include "llvm/ProfileData/InstrProf.h"
2626
#include "llvm/Support/Allocator.h"
27+
#include "llvm/Support/Compiler.h"
2728
#include "llvm/Support/Error.h"
2829
#include "llvm/Support/StringSaver.h"
2930

@@ -138,33 +139,35 @@ class DataAccessProfData {
138139
/// - Serialized strings.
139140
/// - The encoded hashes.
140141
/// - Records.
141-
Error serialize(ProfOStream &OS) const;
142+
LLVM_ABI Error serialize(ProfOStream &OS) const;
142143

143144
/// Deserialize this class from the given buffer.
144-
Error deserialize(const unsigned char *&Ptr);
145+
LLVM_ABI Error deserialize(const unsigned char *&Ptr);
145146

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

152153
/// Returns true if \p SymID is seen in profiled binaries and cold.
153-
bool isKnownColdSymbol(const SymbolHandleRef SymID) const;
154+
LLVM_ABI bool isKnownColdSymbol(const SymbolHandleRef SymID) const;
154155

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

169172
/// The following methods return array reference for various internal data
170173
/// structures.

0 commit comments

Comments
 (0)