Skip to content

[llvm] annotate interfaces in llvm/TargetParser for DLL export #143616

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 11, 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
60 changes: 32 additions & 28 deletions llvm/include/llvm/TargetParser/AArch64TargetParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/SubtargetFeature.h"
Expand Down Expand Up @@ -79,7 +80,7 @@ struct FMVInfo {
: Name(Name), FeatureBit(FeatureBit), PriorityBit(PriorityBit), ID(ID) {};
};

const std::vector<FMVInfo> &getFMVInfo();
LLVM_ABI const std::vector<FMVInfo> &getFMVInfo();

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

// Search for ArchInfo by SubArch name
static std::optional<ArchInfo> findBySubArch(StringRef SubArch);
LLVM_ABI static std::optional<ArchInfo> findBySubArch(StringRef SubArch);
};

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

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

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

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

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

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

// Convert the set of enabled extension to an LLVM feature list, appending
// them to Features.
Expand All @@ -227,7 +230,7 @@ struct ExtensionSet {
}
}

void dump() const;
LLVM_ABI void dump() const;
};

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

const ExtensionInfo &getExtensionByID(ArchExtKind(ExtID));
LLVM_ABI const ExtensionInfo &getExtensionByID(ArchExtKind(ExtID));

bool getExtensionFeatures(
const AArch64::ExtensionBitset &Extensions,
std::vector<StringRef> &Features);
LLVM_ABI bool getExtensionFeatures(const AArch64::ExtensionBitset &Extensions,
std::vector<StringRef> &Features);

StringRef getArchExtFeature(StringRef ArchExt);
StringRef resolveCPUAlias(StringRef CPU);
LLVM_ABI StringRef getArchExtFeature(StringRef ArchExt);
LLVM_ABI StringRef resolveCPUAlias(StringRef CPU);

// Information by Name
const ArchInfo *getArchForCpu(StringRef CPU);
LLVM_ABI const ArchInfo *getArchForCpu(StringRef CPU);

// Parser
const ArchInfo *parseArch(StringRef Arch);
LLVM_ABI const ArchInfo *parseArch(StringRef Arch);

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

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

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

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

bool isX18ReservedByDefault(const Triple &TT);
LLVM_ABI bool isX18ReservedByDefault(const Triple &TT);

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

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

void PrintSupportedExtensions();
LLVM_ABI void PrintSupportedExtensions();

void printEnabledExtensions(const std::set<StringRef> &EnabledFeatureNames);
LLVM_ABI void
printEnabledExtensions(const std::set<StringRef> &EnabledFeatureNames);

} // namespace AArch64
} // namespace llvm
Expand Down
75 changes: 39 additions & 36 deletions llvm/include/llvm/TargetParser/ARMTargetParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ARMBuildAttributes.h"
#include "llvm/Support/Compiler.h"
#include "llvm/TargetParser/ARMTargetParserCommon.h"
#include <vector>

Expand Down Expand Up @@ -223,53 +224,55 @@ inline ArchKind &operator--(ArchKind &Kind) {
}

// Information by ID
StringRef getFPUName(FPUKind FPUKind);
FPUVersion getFPUVersion(FPUKind FPUKind);
NeonSupportLevel getFPUNeonSupportLevel(FPUKind FPUKind);
FPURestriction getFPURestriction(FPUKind FPUKind);

bool getFPUFeatures(FPUKind FPUKind, std::vector<StringRef> &Features);
bool getHWDivFeatures(uint64_t HWDivKind, std::vector<StringRef> &Features);
bool getExtensionFeatures(uint64_t Extensions,
std::vector<StringRef> &Features);

StringRef getArchName(ArchKind AK);
unsigned getArchAttr(ArchKind AK);
StringRef getCPUAttr(ArchKind AK);
StringRef getSubArch(ArchKind AK);
StringRef getArchExtName(uint64_t ArchExtKind);
StringRef getArchExtFeature(StringRef ArchExt);
bool appendArchExtFeatures(StringRef CPU, ARM::ArchKind AK, StringRef ArchExt,
std::vector<StringRef> &Features,
FPUKind &ArgFPUKind);
ArchKind convertV9toV8(ArchKind AK);
LLVM_ABI StringRef getFPUName(FPUKind FPUKind);
LLVM_ABI FPUVersion getFPUVersion(FPUKind FPUKind);
LLVM_ABI NeonSupportLevel getFPUNeonSupportLevel(FPUKind FPUKind);
LLVM_ABI FPURestriction getFPURestriction(FPUKind FPUKind);

LLVM_ABI bool getFPUFeatures(FPUKind FPUKind, std::vector<StringRef> &Features);
LLVM_ABI bool getHWDivFeatures(uint64_t HWDivKind,
std::vector<StringRef> &Features);
LLVM_ABI bool getExtensionFeatures(uint64_t Extensions,
std::vector<StringRef> &Features);

LLVM_ABI StringRef getArchName(ArchKind AK);
LLVM_ABI unsigned getArchAttr(ArchKind AK);
LLVM_ABI StringRef getCPUAttr(ArchKind AK);
LLVM_ABI StringRef getSubArch(ArchKind AK);
LLVM_ABI StringRef getArchExtName(uint64_t ArchExtKind);
LLVM_ABI StringRef getArchExtFeature(StringRef ArchExt);
LLVM_ABI bool appendArchExtFeatures(StringRef CPU, ARM::ArchKind AK,
StringRef ArchExt,
std::vector<StringRef> &Features,
FPUKind &ArgFPUKind);
LLVM_ABI ArchKind convertV9toV8(ArchKind AK);

// Information by Name
FPUKind getDefaultFPU(StringRef CPU, ArchKind AK);
uint64_t getDefaultExtensions(StringRef CPU, ArchKind AK);
StringRef getDefaultCPU(StringRef Arch);
StringRef getCanonicalArchName(StringRef Arch);
StringRef getFPUSynonym(StringRef FPU);
LLVM_ABI FPUKind getDefaultFPU(StringRef CPU, ArchKind AK);
LLVM_ABI uint64_t getDefaultExtensions(StringRef CPU, ArchKind AK);
LLVM_ABI StringRef getDefaultCPU(StringRef Arch);
LLVM_ABI StringRef getFPUSynonym(StringRef FPU);

// Parser
uint64_t parseHWDiv(StringRef HWDiv);
FPUKind parseFPU(StringRef FPU);
ArchKind parseArch(StringRef Arch);
uint64_t parseArchExt(StringRef ArchExt);
ArchKind parseCPUArch(StringRef CPU);
ProfileKind parseArchProfile(StringRef Arch);
unsigned parseArchVersion(StringRef Arch);
LLVM_ABI uint64_t parseHWDiv(StringRef HWDiv);
LLVM_ABI FPUKind parseFPU(StringRef FPU);
LLVM_ABI ArchKind parseArch(StringRef Arch);
LLVM_ABI uint64_t parseArchExt(StringRef ArchExt);
LLVM_ABI ArchKind parseCPUArch(StringRef CPU);
LLVM_ABI ProfileKind parseArchProfile(StringRef Arch);
LLVM_ABI unsigned parseArchVersion(StringRef Arch);

void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);
LLVM_ABI void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
LLVM_ABI StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);

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

void PrintSupportedExtensions(StringMap<StringRef> DescMap);
LLVM_ABI void PrintSupportedExtensions(StringMap<StringRef> DescMap);

} // namespace ARM
} // namespace llvm
Expand Down
13 changes: 7 additions & 6 deletions llvm/include/llvm/TargetParser/ARMTargetParserCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define LLVM_TARGETPARSER_ARMTARGETPARSERCOMMON_H

#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"

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

/// Converts e.g. "armv8" -> "armv8-a"
StringRef getArchSynonym(StringRef Arch);
LLVM_ABI StringRef getArchSynonym(StringRef Arch);

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

// ARM, Thumb, AArch64
ISAKind parseArchISA(StringRef Arch);
LLVM_ABI ISAKind parseArchISA(StringRef Arch);

// Little/Big endian
EndianKind parseArchEndian(StringRef Arch);
LLVM_ABI EndianKind parseArchEndian(StringRef Arch);

struct ParsedBranchProtection {
StringRef Scope;
Expand All @@ -45,8 +46,8 @@ struct ParsedBranchProtection {
bool GuardedControlStack;
};

bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
StringRef &Err, bool EnablePAuthLR = false);
LLVM_ABI bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
StringRef &Err, bool EnablePAuthLR = false);

} // namespace ARM
} // namespace llvm
Expand Down
30 changes: 16 additions & 14 deletions llvm/include/llvm/TargetParser/CSKYTargetParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef LLVM_TARGETPARSER_CSKYTARGETPARSER_H
#define LLVM_TARGETPARSER_CSKYTARGETPARSER_H

#include "llvm/Support/Compiler.h"
#include "llvm/TargetParser/Triple.h"
#include <vector>

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

StringRef getArchName(ArchKind AK);
StringRef getDefaultCPU(StringRef Arch);
StringRef getArchExtName(uint64_t ArchExtKind);
StringRef getArchExtFeature(StringRef ArchExt);
uint64_t getDefaultExtensions(StringRef CPU);
bool getExtensionFeatures(uint64_t Extensions,
std::vector<StringRef> &Features);
LLVM_ABI StringRef getArchName(ArchKind AK);
LLVM_ABI StringRef getDefaultCPU(StringRef Arch);
LLVM_ABI StringRef getArchExtName(uint64_t ArchExtKind);
LLVM_ABI StringRef getArchExtFeature(StringRef ArchExt);
LLVM_ABI uint64_t getDefaultExtensions(StringRef CPU);
LLVM_ABI bool getExtensionFeatures(uint64_t Extensions,
std::vector<StringRef> &Features);

// Information by ID
StringRef getFPUName(unsigned FPUKind);
FPUVersion getFPUVersion(unsigned FPUKind);
LLVM_ABI StringRef getFPUName(unsigned FPUKind);
LLVM_ABI FPUVersion getFPUVersion(unsigned FPUKind);

bool getFPUFeatures(CSKYFPUKind Kind, std::vector<StringRef> &Features);
LLVM_ABI bool getFPUFeatures(CSKYFPUKind Kind,
std::vector<StringRef> &Features);

// Parser
ArchKind parseArch(StringRef Arch);
ArchKind parseCPUArch(StringRef CPU);
uint64_t parseArchExt(StringRef ArchExt);
void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
LLVM_ABI ArchKind parseArch(StringRef Arch);
LLVM_ABI ArchKind parseCPUArch(StringRef CPU);
LLVM_ABI uint64_t parseArchExt(StringRef ArchExt);
LLVM_ABI void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);

} // namespace CSKY

Expand Down
Loading
Loading