Skip to content

[llvm] annotate interfaces in llvm/Option and llvm/Remarks for DLL export #142856

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 2 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
26 changes: 14 additions & 12 deletions llvm/include/llvm/Option/Arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Compiler.h"
#include <string>

namespace llvm {
Expand Down Expand Up @@ -70,15 +71,16 @@ class Arg {
std::unique_ptr<Arg> Alias;

public:
Arg(const Option Opt, StringRef Spelling, unsigned Index,
const Arg *BaseArg = nullptr);
Arg(const Option Opt, StringRef Spelling, unsigned Index,
const char *Value0, const Arg *BaseArg = nullptr);
Arg(const Option Opt, StringRef Spelling, unsigned Index,
const char *Value0, const char *Value1, const Arg *BaseArg = nullptr);
LLVM_ABI Arg(const Option Opt, StringRef Spelling, unsigned Index,
const Arg *BaseArg = nullptr);
LLVM_ABI Arg(const Option Opt, StringRef Spelling, unsigned Index,
const char *Value0, const Arg *BaseArg = nullptr);
LLVM_ABI Arg(const Option Opt, StringRef Spelling, unsigned Index,
const char *Value0, const char *Value1,
const Arg *BaseArg = nullptr);
Arg(const Arg &) = delete;
Arg &operator=(const Arg &) = delete;
~Arg();
LLVM_ABI ~Arg();

const Option &getOption() const { return Opt; }

Expand Down Expand Up @@ -134,23 +136,23 @@ class Arg {
}

/// Append the argument onto the given array as strings.
void render(const ArgList &Args, ArgStringList &Output) const;
LLVM_ABI void render(const ArgList &Args, ArgStringList &Output) const;

/// Append the argument, render as an input, onto the given
/// array as strings.
///
/// The distinction is that some options only render their values
/// when rendered as a input (e.g., Xlinker).
void renderAsInput(const ArgList &Args, ArgStringList &Output) const;
LLVM_ABI void renderAsInput(const ArgList &Args, ArgStringList &Output) const;

void print(raw_ostream &O) const;
void dump() const;
LLVM_ABI void print(raw_ostream &O) const;
LLVM_ABI void dump() const;

/// Return a formatted version of the argument and its values, for
/// diagnostics. Since this is for diagnostics, if this Arg was produced
/// through an alias, this returns the string representation of the alias
/// that the user wrote.
std::string getAsString(const ArgList &Args) const;
LLVM_ABI std::string getAsString(const ArgList &Args) const;
};

} // end namespace opt
Expand Down
64 changes: 35 additions & 29 deletions llvm/include/llvm/Option/ArgList.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/OptSpecifier.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Compiler.h"
#include <algorithm>
#include <cstddef>
#include <initializer_list>
Expand Down Expand Up @@ -139,7 +140,7 @@ class ArgList {

/// Get the range of indexes in which options with the specified IDs might
/// reside, or (0, 0) if there are no such options.
OptRange getRange(std::initializer_list<OptSpecifier> Ids) const;
LLVM_ABI OptRange getRange(std::initializer_list<OptSpecifier> Ids) const;

protected:
// Make the default special members protected so they won't be used to slice
Expand Down Expand Up @@ -178,7 +179,7 @@ class ArgList {
/// @{

/// append - Append \p A to the arg list.
void append(Arg *A);
LLVM_ABI void append(Arg *A);

const arglist_type &getArgs() const { return Args; }

Expand Down Expand Up @@ -227,7 +228,7 @@ class ArgList {
/// @{

/// eraseArg - Remove any option matching \p Id.
void eraseArg(OptSpecifier Id);
LLVM_ABI void eraseArg(OptSpecifier Id);

/// @}
/// @name Arg Access
Expand Down Expand Up @@ -284,11 +285,12 @@ class ArgList {
/// @{

/// getLastArgValue - Return the value of the last argument, or a default.
StringRef getLastArgValue(OptSpecifier Id, StringRef Default = "") const;
LLVM_ABI StringRef getLastArgValue(OptSpecifier Id,
StringRef Default = "") const;

/// getAllArgValues - Get the values of all instances of the given argument
/// as strings.
std::vector<std::string> getAllArgValues(OptSpecifier Id) const;
LLVM_ABI std::vector<std::string> getAllArgValues(OptSpecifier Id) const;

/// @}
/// @name Translation Utilities
Expand All @@ -298,20 +300,21 @@ class ArgList {
/// true if the option is present, false if the negation is present, and
/// \p Default if neither option is given. If both the option and its
/// negation are present, the last one wins.
bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
bool hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
LLVM_ABI bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
LLVM_ABI bool hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg,
bool Default) const;

/// hasFlag - Given an option \p Pos, an alias \p PosAlias and its negative
/// form \p Neg, return true if the option or its alias is present, false if
/// the negation is present, and \p Default if none of the options are
/// given. If multiple options are present, the last one wins.
bool hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,
bool Default) const;
LLVM_ABI bool hasFlag(OptSpecifier Pos, OptSpecifier PosAlias,
OptSpecifier Neg, bool Default) const;

/// Given an option Pos and its negative form Neg, render the option if Pos is
/// present.
void addOptInFlag(ArgStringList &Output, OptSpecifier Pos,
OptSpecifier Neg) const;
LLVM_ABI void addOptInFlag(ArgStringList &Output, OptSpecifier Pos,
OptSpecifier Neg) const;
/// Render the option if Neg is present.
void addOptOutFlag(ArgStringList &Output, OptSpecifier Pos,
OptSpecifier Neg) const {
Expand All @@ -331,32 +334,35 @@ class ArgList {

/// AddAllArgsExcept - Render all arguments matching any of the given ids
/// and not matching any of the excluded ids.
void AddAllArgsExcept(ArgStringList &Output, ArrayRef<OptSpecifier> Ids,
ArrayRef<OptSpecifier> ExcludeIds) const;
LLVM_ABI void AddAllArgsExcept(ArgStringList &Output,
ArrayRef<OptSpecifier> Ids,
ArrayRef<OptSpecifier> ExcludeIds) const;
/// Render all arguments matching any of the given ids.
void addAllArgs(ArgStringList &Output, ArrayRef<OptSpecifier> Ids) const;
LLVM_ABI void addAllArgs(ArgStringList &Output,
ArrayRef<OptSpecifier> Ids) const;

/// AddAllArgs - Render all arguments matching the given ids.
void AddAllArgs(ArgStringList &Output, OptSpecifier Id0) const;
LLVM_ABI void AddAllArgs(ArgStringList &Output, OptSpecifier Id0) const;

/// AddAllArgValues - Render the argument values of all arguments
/// matching the given ids.
void AddAllArgValues(ArgStringList &Output, OptSpecifier Id0,
OptSpecifier Id1 = 0U, OptSpecifier Id2 = 0U) const;
LLVM_ABI void AddAllArgValues(ArgStringList &Output, OptSpecifier Id0,
OptSpecifier Id1 = 0U,
OptSpecifier Id2 = 0U) const;

/// AddAllArgsTranslated - Render all the arguments matching the
/// given ids, but forced to separate args and using the provided
/// name instead of the first option value.
///
/// \param Joined - If true, render the argument as joined with
/// the option specifier.
void AddAllArgsTranslated(ArgStringList &Output, OptSpecifier Id0,
const char *Translation,
bool Joined = false) const;
LLVM_ABI void AddAllArgsTranslated(ArgStringList &Output, OptSpecifier Id0,
const char *Translation,
bool Joined = false) const;

/// ClaimAllArgs - Claim all arguments which match the given
/// option id.
void ClaimAllArgs(OptSpecifier Id0) const;
LLVM_ABI void ClaimAllArgs(OptSpecifier Id0) const;

template <typename... OptSpecifiers>
void claimAllArgs(OptSpecifiers... Ids) const {
Expand All @@ -366,7 +372,7 @@ class ArgList {

/// ClaimAllArgs - Claim all arguments.
///
void ClaimAllArgs() const;
LLVM_ABI void ClaimAllArgs() const;
/// @}
/// @name Arg Synthesis
/// @{
Expand All @@ -381,16 +387,16 @@ class ArgList {

/// Create an arg string for (\p LHS + \p RHS), reusing the
/// string at \p Index if possible.
const char *GetOrMakeJoinedArgString(unsigned Index, StringRef LHS,
StringRef RHS) const;
LLVM_ABI const char *GetOrMakeJoinedArgString(unsigned Index, StringRef LHS,
StringRef RHS) const;

void print(raw_ostream &O) const;
void dump() const;
LLVM_ABI void print(raw_ostream &O) const;
LLVM_ABI void dump() const;

/// @}
};

class InputArgList final : public ArgList {
class LLVM_ABI InputArgList final : public ArgList {
private:
/// List of argument strings used by the contained Args.
///
Expand Down Expand Up @@ -463,7 +469,7 @@ class InputArgList final : public ArgList {

/// DerivedArgList - An ordered collection of driver arguments,
/// whose storage may be in another argument list.
class DerivedArgList final : public ArgList {
class LLVM_ABI DerivedArgList final : public ArgList {
const InputArgList &BaseArgs;

/// The list of arguments we synthesized.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Option/OptSpecifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OptSpecifier {
OptSpecifier() = default;
explicit OptSpecifier(bool) = delete;
/*implicit*/ OptSpecifier(unsigned ID) : ID(ID) {}
/*implicit*/ OptSpecifier(const Option *Opt);
/*implicit*/ LLVM_ABI OptSpecifier(const Option *Opt);

bool isValid() const { return ID != 0; }

Expand Down
9 changes: 5 additions & 4 deletions llvm/include/llvm/Option/OptTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringTable.h"
#include "llvm/Option/OptSpecifier.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/StringSaver.h"
#include <cassert>
#include <string>
Expand Down Expand Up @@ -50,7 +51,7 @@ class Visibility {
/// be needed at runtime; the OptTable class maintains enough information to
/// parse command lines without instantiating Options, while letting other
/// parts of the driver still use Option instances where convenient.
class OptTable {
class LLVM_ABI OptTable {
public:
/// Entry for a single option instance in the option data table.
struct Info {
Expand Down Expand Up @@ -425,9 +426,9 @@ class OptTable {
/// Specialization of OptTable
class GenericOptTable : public OptTable {
protected:
GenericOptTable(const StringTable &StrTable,
ArrayRef<StringTable::Offset> PrefixesTable,
ArrayRef<Info> OptionInfos, bool IgnoreCase = false);
LLVM_ABI GenericOptTable(const StringTable &StrTable,
ArrayRef<StringTable::Offset> PrefixesTable,
ArrayRef<Info> OptionInfos, bool IgnoreCase = false);
};

class PrecomputedOptTable : public OptTable {
Expand Down
14 changes: 8 additions & 6 deletions llvm/include/llvm/Option/Option.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/OptSpecifier.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include <cassert>

Expand Down Expand Up @@ -81,7 +82,7 @@ class Option {
const OptTable *Owner;

public:
Option(const OptTable::Info *Info, const OptTable *Owner);
LLVM_ABI Option(const OptTable::Info *Info, const OptTable *Owner);

bool isValid() const {
return Info != nullptr;
Expand Down Expand Up @@ -213,7 +214,7 @@ class Option {
/// Note that matches against options which are an alias should never be
/// done -- aliases do not participate in matching and so such a query will
/// always be false.
bool matches(OptSpecifier ID) const;
LLVM_ABI bool matches(OptSpecifier ID) const;

/// Potentially accept the current argument, returning a new Arg instance,
/// or 0 if the option does not accept this argument (or the argument is
Expand All @@ -227,16 +228,17 @@ class Option {
/// underlying storage to represent a Joined argument.
/// \p GroupedShortOption If true, we are handling the fallback case of
/// parsing a prefix of the current argument as a short option.
std::unique_ptr<Arg> accept(const ArgList &Args, StringRef CurArg,
bool GroupedShortOption, unsigned &Index) const;
LLVM_ABI std::unique_ptr<Arg> accept(const ArgList &Args, StringRef CurArg,
bool GroupedShortOption,
unsigned &Index) const;

private:
std::unique_ptr<Arg> acceptInternal(const ArgList &Args, StringRef CurArg,
unsigned &Index) const;

public:
void print(raw_ostream &O, bool AddNewLine = true) const;
void dump() const;
LLVM_ABI void print(raw_ostream &O, bool AddNewLine = true) const;
LLVM_ABI void dump() const;
};

} // end namespace opt
Expand Down
13 changes: 7 additions & 6 deletions llvm/include/llvm/Remarks/Remark.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
#include <string>
Expand All @@ -35,7 +36,7 @@ struct RemarkLocation {
unsigned SourceColumn = 0;

/// Implement operator<< on RemarkLocation.
void print(raw_ostream &OS) const;
LLVM_ABI void print(raw_ostream &OS) const;
};

// Create wrappers for C Binding types (see CBindingWrapping.h).
Expand All @@ -51,11 +52,11 @@ struct Argument {
std::optional<RemarkLocation> Loc;

/// Implement operator<< on Argument.
void print(raw_ostream &OS) const;
LLVM_ABI void print(raw_ostream &OS) const;
/// Return the value of argument as int.
std::optional<int> getValAsInt() const;
LLVM_ABI std::optional<int> getValAsInt() const;
/// Check if the argument value can be parsed as int.
bool isValInt() const;
LLVM_ABI bool isValInt() const;
};

// Create wrappers for C Binding types (see CBindingWrapping.h).
Expand Down Expand Up @@ -124,13 +125,13 @@ struct Remark {
Remark &operator=(Remark &&) = default;

/// Return a message composed from the arguments as a string.
std::string getArgsAsMsg() const;
LLVM_ABI std::string getArgsAsMsg() const;

/// Clone this remark to explicitly ask for a copy.
Remark clone() const { return *this; }

/// Implement operator<< on Remark.
void print(raw_ostream &OS) const;
LLVM_ABI void print(raw_ostream &OS) const;

private:
/// In order to avoid unwanted copies, "delete" the copy constructor.
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/Remarks/RemarkFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define LLVM_REMARKS_REMARKFORMAT_H

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

namespace llvm {
Expand All @@ -25,10 +26,10 @@ constexpr StringLiteral Magic("REMARKS");
enum class Format { Unknown, YAML, YAMLStrTab, Bitstream };

/// Parse and validate a string for the remark format.
Expected<Format> parseFormat(StringRef FormatStr);
LLVM_ABI Expected<Format> parseFormat(StringRef FormatStr);

/// Parse and validate a magic number to a remark format.
Expected<Format> magicToFormat(StringRef Magic);
LLVM_ABI Expected<Format> magicToFormat(StringRef Magic);

} // end namespace remarks
} // end namespace llvm
Expand Down
Loading
Loading