Skip to content

Commit 5188bea

Browse files
authored
[llvm] annotate interfaces in llvm/TargetParser for DLL export (#143616)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/TargetParser` 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). Most of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. Additionally, I manually removed the redundant declaration of `getCanonicalArchName` from llvm/include/llvm/TargetParser/ARMTargetParser.h because IDS only auto-annotates the first declaration it encounters, and the second un-annotated declaration results in an MSVC warning. ## 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 38fb011 commit 5188bea

13 files changed

+274
-243
lines changed

llvm/include/llvm/TargetParser/AArch64TargetParser.h

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/StringExtras.h"
2020
#include "llvm/ADT/StringMap.h"
2121
#include "llvm/ADT/StringRef.h"
22+
#include "llvm/Support/Compiler.h"
2223
#include "llvm/Support/VersionTuple.h"
2324
#include "llvm/Support/raw_ostream.h"
2425
#include "llvm/TargetParser/SubtargetFeature.h"
@@ -79,7 +80,7 @@ struct FMVInfo {
7980
: Name(Name), FeatureBit(FeatureBit), PriorityBit(PriorityBit), ID(ID) {};
8081
};
8182

82-
const std::vector<FMVInfo> &getFMVInfo();
83+
LLVM_ABI const std::vector<FMVInfo> &getFMVInfo();
8384

8485
// Represents a dependency between two architecture extensions. Later is the
8586
// feature which was added to the architecture after Earlier, and expands the
@@ -146,7 +147,7 @@ struct ArchInfo {
146147
StringRef getSubArch() const { return ArchFeature.substr(1); }
147148

148149
// Search for ArchInfo by SubArch name
149-
static std::optional<ArchInfo> findBySubArch(StringRef SubArch);
150+
LLVM_ABI static std::optional<ArchInfo> findBySubArch(StringRef SubArch);
150151
};
151152

152153
#define EMIT_ARCHITECTURES
@@ -182,34 +183,36 @@ struct ExtensionSet {
182183
// Enable the given architecture extension, and any other extensions it
183184
// depends on. Does not change the base architecture, or follow dependencies
184185
// between features which are only related by required arcitecture versions.
185-
void enable(ArchExtKind E);
186+
LLVM_ABI void enable(ArchExtKind E);
186187

187188
// Disable the given architecture extension, and any other extensions which
188189
// depend on it. Does not change the base architecture, or follow
189190
// dependencies between features which are only related by required
190191
// arcitecture versions.
191-
void disable(ArchExtKind E);
192+
LLVM_ABI void disable(ArchExtKind E);
192193

193194
// Add default extensions for the given CPU. Records the base architecture,
194195
// to later resolve dependencies which depend on it.
195-
void addCPUDefaults(const CpuInfo &CPU);
196+
LLVM_ABI void addCPUDefaults(const CpuInfo &CPU);
196197

197198
// Add default extensions for the given architecture version. Records the
198199
// base architecture, to later resolve dependencies which depend on it.
199-
void addArchDefaults(const ArchInfo &Arch);
200+
LLVM_ABI void addArchDefaults(const ArchInfo &Arch);
200201

201202
// Add or remove a feature based on a modifier string. The string must be of
202203
// the form "<name>" to enable a feature or "no<name>" to disable it. This
203204
// will also enable or disable any features as required by the dependencies
204205
// between them.
205-
bool parseModifier(StringRef Modifier, const bool AllowNoDashForm = false);
206+
LLVM_ABI bool parseModifier(StringRef Modifier,
207+
const bool AllowNoDashForm = false);
206208

207209
// Constructs a new ExtensionSet by toggling the corresponding bits for every
208210
// feature in the \p Features list without expanding their dependencies. Used
209211
// for reconstructing an ExtensionSet from the output of toLLVMFeatures().
210212
// Features that are not recognized are pushed back to \p NonExtensions.
211-
void reconstructFromParsedFeatures(const std::vector<std::string> &Features,
212-
std::vector<std::string> &NonExtensions);
213+
LLVM_ABI void
214+
reconstructFromParsedFeatures(const std::vector<std::string> &Features,
215+
std::vector<std::string> &NonExtensions);
213216

214217
// Convert the set of enabled extension to an LLVM feature list, appending
215218
// them to Features.
@@ -227,7 +230,7 @@ struct ExtensionSet {
227230
}
228231
}
229232

230-
void dump() const;
233+
LLVM_ABI void dump() const;
231234
};
232235

233236
// Name alias.
@@ -239,52 +242,53 @@ struct Alias {
239242
#define EMIT_CPU_ALIAS
240243
#include "llvm/TargetParser/AArch64TargetParserDef.inc"
241244

242-
const ExtensionInfo &getExtensionByID(ArchExtKind(ExtID));
245+
LLVM_ABI const ExtensionInfo &getExtensionByID(ArchExtKind(ExtID));
243246

244-
bool getExtensionFeatures(
245-
const AArch64::ExtensionBitset &Extensions,
246-
std::vector<StringRef> &Features);
247+
LLVM_ABI bool getExtensionFeatures(const AArch64::ExtensionBitset &Extensions,
248+
std::vector<StringRef> &Features);
247249

248-
StringRef getArchExtFeature(StringRef ArchExt);
249-
StringRef resolveCPUAlias(StringRef CPU);
250+
LLVM_ABI StringRef getArchExtFeature(StringRef ArchExt);
251+
LLVM_ABI StringRef resolveCPUAlias(StringRef CPU);
250252

251253
// Information by Name
252-
const ArchInfo *getArchForCpu(StringRef CPU);
254+
LLVM_ABI const ArchInfo *getArchForCpu(StringRef CPU);
253255

254256
// Parser
255-
const ArchInfo *parseArch(StringRef Arch);
257+
LLVM_ABI const ArchInfo *parseArch(StringRef Arch);
256258

257259
// Return the extension which has the given -target-feature name.
258-
std::optional<ExtensionInfo> targetFeatureToExtension(StringRef TargetFeature);
260+
LLVM_ABI std::optional<ExtensionInfo>
261+
targetFeatureToExtension(StringRef TargetFeature);
259262

260263
// Parse a name as defined by the Extension class in tablegen.
261-
std::optional<ExtensionInfo> parseArchExtension(StringRef Extension);
264+
LLVM_ABI std::optional<ExtensionInfo> parseArchExtension(StringRef Extension);
262265

263266
// Parse a name as defined by the FMVInfo class in tablegen.
264-
std::optional<FMVInfo> parseFMVExtension(StringRef Extension);
267+
LLVM_ABI std::optional<FMVInfo> parseFMVExtension(StringRef Extension);
265268

266269
// Given the name of a CPU or alias, return the correponding CpuInfo.
267-
std::optional<CpuInfo> parseCpu(StringRef Name);
270+
LLVM_ABI std::optional<CpuInfo> parseCpu(StringRef Name);
268271
// Used by target parser tests
269-
void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
272+
LLVM_ABI void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
270273

271-
bool isX18ReservedByDefault(const Triple &TT);
274+
LLVM_ABI bool isX18ReservedByDefault(const Triple &TT);
272275

273276
// For a given set of feature names, which can be either target-features, or
274277
// fmv-features metadata, expand their dependencies and then return a bitmask
275278
// corresponding to the entries of AArch64::FeatPriorities.
276-
uint64_t getFMVPriority(ArrayRef<StringRef> Features);
279+
LLVM_ABI uint64_t getFMVPriority(ArrayRef<StringRef> Features);
277280

278281
// For a given set of FMV feature names, expand their dependencies and then
279282
// return a bitmask corresponding to the entries of AArch64::CPUFeatures.
280283
// The values in CPUFeatures are not bitmasks themselves, they are sequential
281284
// (0, 1, 2, 3, ...). The resulting bitmask is used at runtime to test whether
282285
// a certain FMV feature is available on the host.
283-
uint64_t getCpuSupportsMask(ArrayRef<StringRef> Features);
286+
LLVM_ABI uint64_t getCpuSupportsMask(ArrayRef<StringRef> Features);
284287

285-
void PrintSupportedExtensions();
288+
LLVM_ABI void PrintSupportedExtensions();
286289

287-
void printEnabledExtensions(const std::set<StringRef> &EnabledFeatureNames);
290+
LLVM_ABI void
291+
printEnabledExtensions(const std::set<StringRef> &EnabledFeatureNames);
288292

289293
} // namespace AArch64
290294
} // namespace llvm

llvm/include/llvm/TargetParser/ARMTargetParser.h

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/StringMap.h"
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/Support/ARMBuildAttributes.h"
20+
#include "llvm/Support/Compiler.h"
2021
#include "llvm/TargetParser/ARMTargetParserCommon.h"
2122
#include <vector>
2223

@@ -223,53 +224,55 @@ inline ArchKind &operator--(ArchKind &Kind) {
223224
}
224225

225226
// Information by ID
226-
StringRef getFPUName(FPUKind FPUKind);
227-
FPUVersion getFPUVersion(FPUKind FPUKind);
228-
NeonSupportLevel getFPUNeonSupportLevel(FPUKind FPUKind);
229-
FPURestriction getFPURestriction(FPUKind FPUKind);
230-
231-
bool getFPUFeatures(FPUKind FPUKind, std::vector<StringRef> &Features);
232-
bool getHWDivFeatures(uint64_t HWDivKind, std::vector<StringRef> &Features);
233-
bool getExtensionFeatures(uint64_t Extensions,
234-
std::vector<StringRef> &Features);
235-
236-
StringRef getArchName(ArchKind AK);
237-
unsigned getArchAttr(ArchKind AK);
238-
StringRef getCPUAttr(ArchKind AK);
239-
StringRef getSubArch(ArchKind AK);
240-
StringRef getArchExtName(uint64_t ArchExtKind);
241-
StringRef getArchExtFeature(StringRef ArchExt);
242-
bool appendArchExtFeatures(StringRef CPU, ARM::ArchKind AK, StringRef ArchExt,
243-
std::vector<StringRef> &Features,
244-
FPUKind &ArgFPUKind);
245-
ArchKind convertV9toV8(ArchKind AK);
227+
LLVM_ABI StringRef getFPUName(FPUKind FPUKind);
228+
LLVM_ABI FPUVersion getFPUVersion(FPUKind FPUKind);
229+
LLVM_ABI NeonSupportLevel getFPUNeonSupportLevel(FPUKind FPUKind);
230+
LLVM_ABI FPURestriction getFPURestriction(FPUKind FPUKind);
231+
232+
LLVM_ABI bool getFPUFeatures(FPUKind FPUKind, std::vector<StringRef> &Features);
233+
LLVM_ABI bool getHWDivFeatures(uint64_t HWDivKind,
234+
std::vector<StringRef> &Features);
235+
LLVM_ABI bool getExtensionFeatures(uint64_t Extensions,
236+
std::vector<StringRef> &Features);
237+
238+
LLVM_ABI StringRef getArchName(ArchKind AK);
239+
LLVM_ABI unsigned getArchAttr(ArchKind AK);
240+
LLVM_ABI StringRef getCPUAttr(ArchKind AK);
241+
LLVM_ABI StringRef getSubArch(ArchKind AK);
242+
LLVM_ABI StringRef getArchExtName(uint64_t ArchExtKind);
243+
LLVM_ABI StringRef getArchExtFeature(StringRef ArchExt);
244+
LLVM_ABI bool appendArchExtFeatures(StringRef CPU, ARM::ArchKind AK,
245+
StringRef ArchExt,
246+
std::vector<StringRef> &Features,
247+
FPUKind &ArgFPUKind);
248+
LLVM_ABI ArchKind convertV9toV8(ArchKind AK);
246249

247250
// Information by Name
248-
FPUKind getDefaultFPU(StringRef CPU, ArchKind AK);
249-
uint64_t getDefaultExtensions(StringRef CPU, ArchKind AK);
250-
StringRef getDefaultCPU(StringRef Arch);
251-
StringRef getCanonicalArchName(StringRef Arch);
252-
StringRef getFPUSynonym(StringRef FPU);
251+
LLVM_ABI FPUKind getDefaultFPU(StringRef CPU, ArchKind AK);
252+
LLVM_ABI uint64_t getDefaultExtensions(StringRef CPU, ArchKind AK);
253+
LLVM_ABI StringRef getDefaultCPU(StringRef Arch);
254+
LLVM_ABI StringRef getFPUSynonym(StringRef FPU);
253255

254256
// Parser
255-
uint64_t parseHWDiv(StringRef HWDiv);
256-
FPUKind parseFPU(StringRef FPU);
257-
ArchKind parseArch(StringRef Arch);
258-
uint64_t parseArchExt(StringRef ArchExt);
259-
ArchKind parseCPUArch(StringRef CPU);
260-
ProfileKind parseArchProfile(StringRef Arch);
261-
unsigned parseArchVersion(StringRef Arch);
257+
LLVM_ABI uint64_t parseHWDiv(StringRef HWDiv);
258+
LLVM_ABI FPUKind parseFPU(StringRef FPU);
259+
LLVM_ABI ArchKind parseArch(StringRef Arch);
260+
LLVM_ABI uint64_t parseArchExt(StringRef ArchExt);
261+
LLVM_ABI ArchKind parseCPUArch(StringRef CPU);
262+
LLVM_ABI ProfileKind parseArchProfile(StringRef Arch);
263+
LLVM_ABI unsigned parseArchVersion(StringRef Arch);
262264

263-
void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
264-
StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);
265+
LLVM_ABI void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
266+
LLVM_ABI StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);
265267

266268
/// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
267269
///
268270
/// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
269271
/// string then the triple's arch name is used.
270-
StringRef getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch = {});
272+
LLVM_ABI StringRef getARMCPUForArch(const llvm::Triple &Triple,
273+
StringRef MArch = {});
271274

272-
void PrintSupportedExtensions(StringMap<StringRef> DescMap);
275+
LLVM_ABI void PrintSupportedExtensions(StringMap<StringRef> DescMap);
273276

274277
} // namespace ARM
275278
} // namespace llvm

llvm/include/llvm/TargetParser/ARMTargetParserCommon.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_TARGETPARSER_ARMTARGETPARSERCOMMON_H
1515

1616
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/Support/Compiler.h"
1718

1819
namespace llvm {
1920
namespace ARM {
@@ -23,19 +24,19 @@ enum class ISAKind { INVALID = 0, ARM, THUMB, AARCH64 };
2324
enum class EndianKind { INVALID = 0, LITTLE, BIG };
2425

2526
/// Converts e.g. "armv8" -> "armv8-a"
26-
StringRef getArchSynonym(StringRef Arch);
27+
LLVM_ABI StringRef getArchSynonym(StringRef Arch);
2728

2829
/// MArch is expected to be of the form (arm|thumb)?(eb)?(v.+)?(eb)?, but
2930
/// (iwmmxt|xscale)(eb)? is also permitted. If the former, return
3031
/// "v.+", if the latter, return unmodified string, minus 'eb'.
3132
/// If invalid, return empty string.
32-
StringRef getCanonicalArchName(StringRef Arch);
33+
LLVM_ABI StringRef getCanonicalArchName(StringRef Arch);
3334

3435
// ARM, Thumb, AArch64
35-
ISAKind parseArchISA(StringRef Arch);
36+
LLVM_ABI ISAKind parseArchISA(StringRef Arch);
3637

3738
// Little/Big endian
38-
EndianKind parseArchEndian(StringRef Arch);
39+
LLVM_ABI EndianKind parseArchEndian(StringRef Arch);
3940

4041
struct ParsedBranchProtection {
4142
StringRef Scope;
@@ -45,8 +46,8 @@ struct ParsedBranchProtection {
4546
bool GuardedControlStack;
4647
};
4748

48-
bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
49-
StringRef &Err, bool EnablePAuthLR = false);
49+
LLVM_ABI bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
50+
StringRef &Err, bool EnablePAuthLR = false);
5051

5152
} // namespace ARM
5253
} // namespace llvm

llvm/include/llvm/TargetParser/CSKYTargetParser.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef LLVM_TARGETPARSER_CSKYTARGETPARSER_H
1616
#define LLVM_TARGETPARSER_CSKYTARGETPARSER_H
1717

18+
#include "llvm/Support/Compiler.h"
1819
#include "llvm/TargetParser/Triple.h"
1920
#include <vector>
2021

@@ -176,25 +177,26 @@ const ArchNames<CSKY::ArchKind> ARCHNames[] = {
176177
#include "llvm/TargetParser/CSKYTargetParser.def"
177178
};
178179

179-
StringRef getArchName(ArchKind AK);
180-
StringRef getDefaultCPU(StringRef Arch);
181-
StringRef getArchExtName(uint64_t ArchExtKind);
182-
StringRef getArchExtFeature(StringRef ArchExt);
183-
uint64_t getDefaultExtensions(StringRef CPU);
184-
bool getExtensionFeatures(uint64_t Extensions,
185-
std::vector<StringRef> &Features);
180+
LLVM_ABI StringRef getArchName(ArchKind AK);
181+
LLVM_ABI StringRef getDefaultCPU(StringRef Arch);
182+
LLVM_ABI StringRef getArchExtName(uint64_t ArchExtKind);
183+
LLVM_ABI StringRef getArchExtFeature(StringRef ArchExt);
184+
LLVM_ABI uint64_t getDefaultExtensions(StringRef CPU);
185+
LLVM_ABI bool getExtensionFeatures(uint64_t Extensions,
186+
std::vector<StringRef> &Features);
186187

187188
// Information by ID
188-
StringRef getFPUName(unsigned FPUKind);
189-
FPUVersion getFPUVersion(unsigned FPUKind);
189+
LLVM_ABI StringRef getFPUName(unsigned FPUKind);
190+
LLVM_ABI FPUVersion getFPUVersion(unsigned FPUKind);
190191

191-
bool getFPUFeatures(CSKYFPUKind Kind, std::vector<StringRef> &Features);
192+
LLVM_ABI bool getFPUFeatures(CSKYFPUKind Kind,
193+
std::vector<StringRef> &Features);
192194

193195
// Parser
194-
ArchKind parseArch(StringRef Arch);
195-
ArchKind parseCPUArch(StringRef CPU);
196-
uint64_t parseArchExt(StringRef ArchExt);
197-
void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
196+
LLVM_ABI ArchKind parseArch(StringRef Arch);
197+
LLVM_ABI ArchKind parseCPUArch(StringRef CPU);
198+
LLVM_ABI uint64_t parseArchExt(StringRef ArchExt);
199+
LLVM_ABI void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
198200

199201
} // namespace CSKY
200202

0 commit comments

Comments
 (0)