[llvm] [llvm] Fix most LLVM_ABI annotations in IR (PR #203244)

Fabrice de Gans via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 11 04:12:12 PDT 2026


https://github.com/Steelskin created https://github.com/llvm/llvm-project/pull/203244

This updates most LLVM_ABI annotations in the IR headers to match expected usage:
* All public APIs should be properly annotated.
* Inlined functions should not be annotated.

These changes were done by a script fixing annotations on LLVM public headers and manually checked.

This effort is tracked in #109483.

>From c2c72b11f31a2ce0e6da0e834e89cf98ee918377 Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <steelskin at gmail.com>
Date: Thu, 11 Jun 2026 12:19:03 +0200
Subject: [PATCH] [llvm] Fix most LLVM_ABI annotations in IR

This updates most LLVM_ABI annotations in the IR headers to
match expected usage:
* All public APIs should be properly annotated.
* Inlined functions should not be annotated.

These changes were done by a script fixing annotations on LLVM public
headers and manually checked.

This effort is tracked in #109483.
---
 llvm/include/llvm/IR/Attributes.h          |  3 +-
 llvm/include/llvm/IR/AutoUpgrade.h         |  2 +-
 llvm/include/llvm/IR/DebugInfoMetadata.h   | 10 +++---
 llvm/include/llvm/IR/GVMaterializer.h      |  3 +-
 llvm/include/llvm/IR/Instruction.h         |  2 +-
 llvm/include/llvm/IR/Instructions.h        |  3 +-
 llvm/include/llvm/IR/NVVMIntrinsicUtils.h  | 24 ++++++++-----
 llvm/include/llvm/IR/PatternMatch.h        |  2 +-
 llvm/include/llvm/IR/PrintPasses.h         | 42 +++++++++++-----------
 llvm/include/llvm/IR/ProfDataUtils.h       |  2 +-
 llvm/include/llvm/IR/RuntimeLibcalls.h     | 11 +++---
 llvm/include/llvm/IR/SafepointIRVerifier.h |  6 ++--
 llvm/include/llvm/IR/Statepoint.h          |  5 +--
 llvm/include/llvm/IR/TypeFinder.h          |  4 +--
 14 files changed, 65 insertions(+), 54 deletions(-)

diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index 6250dde919341..833f2a033a067 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -447,7 +447,8 @@ class AttributeSet {
 
   /// Add attributes to the attribute set. Returns a new set because attribute
   /// sets are immutable.
-  AttributeSet addAttributes(LLVMContext &C, const AttrBuilder &B) const;
+  LLVM_ABI AttributeSet addAttributes(LLVMContext &C,
+                                      const AttrBuilder &B) const;
 
   /// Remove the specified attribute from this set. Returns a new set because
   /// attribute sets are immutable.
diff --git a/llvm/include/llvm/IR/AutoUpgrade.h b/llvm/include/llvm/IR/AutoUpgrade.h
index 420671905aee1..feb19e69389a9 100644
--- a/llvm/include/llvm/IR/AutoUpgrade.h
+++ b/llvm/include/llvm/IR/AutoUpgrade.h
@@ -108,7 +108,7 @@ namespace llvm {
   ///  - guarded-control-stack
   ///  - sign-return-address
   ///  - sign-return-address-with-bkey
-  void copyModuleAttrToFunctions(Module &M);
+  LLVM_ABI void copyModuleAttrToFunctions(Module &M);
 
   /// Check whether a string looks like an old loop attachment tag.
   inline bool mayBeOldLoopAttachmentTag(StringRef Name) {
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index bca7dc125b499..6dfbb2c7e1bc5 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2576,11 +2576,11 @@ class DISubprogram : public DILocalScope {
   }
 
   /// Returns the scope of subprogram's retainedNodes.
-  static const DILocalScope *getRetainedNodeScope(const MDNode *N);
-  static DILocalScope *getRetainedNodeScope(MDNode *N);
+  LLVM_ABI static const DILocalScope *getRetainedNodeScope(const MDNode *N);
+  LLVM_ABI static DILocalScope *getRetainedNodeScope(MDNode *N);
   // For use in Verifier.
-  static const DIScope *getRawRetainedNodeScope(const MDNode *N);
-  static DIScope *getRawRetainedNodeScope(MDNode *N);
+  LLVM_ABI static const DIScope *getRawRetainedNodeScope(const MDNode *N);
+  LLVM_ABI static DIScope *getRawRetainedNodeScope(MDNode *N);
 
   /// For each retained node, applies one of the given functions depending
   /// on the type of a node.
@@ -2620,7 +2620,7 @@ class DISubprogram : public DILocalScope {
   /// when a subprogram refers to types that are local to another subprogram,
   /// it is more complicated for debugger to properly discover local types
   /// of a current scope for expression evaluation.
-  void cleanupRetainedNodes();
+  LLVM_ABI void cleanupRetainedNodes();
 
   /// Calls SP->cleanupRetainedNodes() for a range of DISubprograms.
   template <typename RangeT>
diff --git a/llvm/include/llvm/IR/GVMaterializer.h b/llvm/include/llvm/IR/GVMaterializer.h
index d62da41ebc296..b535671c2b81a 100644
--- a/llvm/include/llvm/IR/GVMaterializer.h
+++ b/llvm/include/llvm/IR/GVMaterializer.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_IR_GVMATERIALIZER_H
 #define LLVM_IR_GVMATERIALIZER_H
 
+#include "llvm/Support/Compiler.h"
 #include <vector>
 
 namespace llvm {
@@ -25,7 +26,7 @@ class Error;
 class GlobalValue;
 class StructType;
 
-class GVMaterializer {
+class LLVM_ABI GVMaterializer {
 protected:
   GVMaterializer() = default;
 
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 3c245e262fd67..86843b339117f 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -1020,7 +1020,7 @@ class Instruction : public User,
   LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *BB);
 
   LLVM_ABI iterator_range<const_succ_iterator> successors() const LLVM_READONLY;
-  LLVM_ABI iterator_range<succ_iterator> successors() {
+  iterator_range<succ_iterator> successors() {
     auto Ops = static_cast<const Instruction *>(this)->successors();
     Use *Begin = const_cast<Use *>(Ops.begin().getUse());
     Use *End = const_cast<Use *>(Ops.end().getUse());
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index e2e9b3ee880e0..f43a9b5c1acc2 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -5162,10 +5162,11 @@ class PtrToAddrInst : public CastInst {
   friend class Instruction;
 
   /// Clone an identical PtrToAddrInst.
-  PtrToAddrInst *cloneImpl() const;
+  LLVM_ABI PtrToAddrInst *cloneImpl() const;
 
 public:
   /// Constructor with insert-before-instruction semantics
+  LLVM_ABI
   PtrToAddrInst(Value *S,                  ///< The value to be converted
                 Type *Ty,                  ///< The type to convert to
                 const Twine &NameStr = "", ///< A name for the new instruction
diff --git a/llvm/include/llvm/IR/NVVMIntrinsicUtils.h b/llvm/include/llvm/IR/NVVMIntrinsicUtils.h
index 067290e57245a..083be6d4247c1 100644
--- a/llvm/include/llvm/IR/NVVMIntrinsicUtils.h
+++ b/llvm/include/llvm/IR/NVVMIntrinsicUtils.h
@@ -104,15 +104,21 @@ enum class TensormapFillMode : uint8_t {
   OOB_NAN_FILL = 1,
 };
 
-void printTcgen05MMAKind(raw_ostream &OS, const Constant *ImmArgVal);
-
-void printTcgen05CollectorUsageOp(raw_ostream &OS, const Constant *ImmArgVal);
-
-void printTensormapElemType(raw_ostream &OS, const Constant *ImmArgVal);
-void printTensormapInterleaveLayout(raw_ostream &OS, const Constant *ImmArgVal);
-void printTensormapSwizzleMode(raw_ostream &OS, const Constant *ImmArgVal);
-void printTensormapSwizzleAtomicity(raw_ostream &OS, const Constant *ImmArgVal);
-void printTensormapFillMode(raw_ostream &OS, const Constant *ImmArgVal);
+LLVM_ABI void printTcgen05MMAKind(raw_ostream &OS, const Constant *ImmArgVal);
+
+LLVM_ABI void printTcgen05CollectorUsageOp(raw_ostream &OS,
+                                           const Constant *ImmArgVal);
+
+LLVM_ABI void printTensormapElemType(raw_ostream &OS,
+                                     const Constant *ImmArgVal);
+LLVM_ABI void printTensormapInterleaveLayout(raw_ostream &OS,
+                                             const Constant *ImmArgVal);
+LLVM_ABI void printTensormapSwizzleMode(raw_ostream &OS,
+                                        const Constant *ImmArgVal);
+LLVM_ABI void printTensormapSwizzleAtomicity(raw_ostream &OS,
+                                             const Constant *ImmArgVal);
+LLVM_ABI void printTensormapFillMode(raw_ostream &OS,
+                                     const Constant *ImmArgVal);
 
 inline bool FPToIntegerIntrinsicShouldFTZ(Intrinsic::ID IntrinsicID) {
   switch (IntrinsicID) {
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 1930503efec93..4ff324deeb026 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -148,7 +148,7 @@ inline auto m_AnyIntrinsic() { return m_Isa<IntrinsicInst>(); }
 
 struct undef_match {
 private:
-  static bool checkAggregate(const ConstantAggregate *CA);
+  LLVM_ABI static bool checkAggregate(const ConstantAggregate *CA);
 
 public:
   static bool check(const Value *V) {
diff --git a/llvm/include/llvm/IR/PrintPasses.h b/llvm/include/llvm/IR/PrintPasses.h
index 6c724bf76fe6c..fabf7ca440c80 100644
--- a/llvm/include/llvm/IR/PrintPasses.h
+++ b/llvm/include/llvm/IR/PrintPasses.h
@@ -27,59 +27,61 @@ enum class ChangePrinter {
   DotCfgQuiet
 };
 
-extern cl::opt<ChangePrinter> PrintChanged;
+extern LLVM_ABI cl::opt<ChangePrinter> PrintChanged;
 
 // Returns true if printing before/after some pass is enabled, whether all
 // passes or a specific pass.
-bool shouldPrintBeforeSomePass();
-bool shouldPrintAfterSomePass();
+LLVM_ABI bool shouldPrintBeforeSomePass();
+LLVM_ABI bool shouldPrintAfterSomePass();
 
 // Returns true if we should print before/after a specific pass. The argument
 // should be the pass ID, e.g. "instcombine".
-bool shouldPrintBeforePass(StringRef PassID);
-bool shouldPrintAfterPass(StringRef PassID);
+LLVM_ABI bool shouldPrintBeforePass(StringRef PassID);
+LLVM_ABI bool shouldPrintAfterPass(StringRef PassID);
 
 // Returns true if we should print before/after all passes.
-bool shouldPrintBeforeAll();
-bool shouldPrintAfterAll();
+LLVM_ABI bool shouldPrintBeforeAll();
+LLVM_ABI bool shouldPrintAfterAll();
 
 // The list of passes to print before/after, if we only want to print
 // before/after specific passes.
-std::vector<std::string> printBeforePasses();
-std::vector<std::string> printAfterPasses();
+LLVM_ABI std::vector<std::string> printBeforePasses();
+LLVM_ABI std::vector<std::string> printAfterPasses();
 
 // Returns true if we should always print the entire module.
-bool forcePrintModuleIR();
+LLVM_ABI bool forcePrintModuleIR();
 
 // Returns true if we should print the entire function for loop passes.
-bool forcePrintFuncIR();
+LLVM_ABI bool forcePrintFuncIR();
 
 // Return true if -filter-passes is empty or contains the pass name.
-bool isPassInPrintList(StringRef PassName);
-bool isFilterPassesEmpty();
+LLVM_ABI bool isPassInPrintList(StringRef PassName);
+LLVM_ABI bool isFilterPassesEmpty();
 
 // Returns true if we should print the function.
-bool isFunctionInPrintList(StringRef FunctionName);
+LLVM_ABI bool isFunctionInPrintList(StringRef FunctionName);
 
 // Ensure temporary files exist, creating or re-using them.  \p FD contains
 // file descriptors (-1 indicates that the file should be created) and
 // \p SR contains the corresponding initial content.  \p FileName will have
 // the filenames filled in when creating files.  Return first error code (if
 // any) and stop.
-std::error_code prepareTempFiles(SmallVector<int> &FD, ArrayRef<StringRef> SR,
-                                 SmallVector<std::string> &FileName);
+LLVM_ABI std::error_code prepareTempFiles(SmallVector<int> &FD,
+                                          ArrayRef<StringRef> SR,
+                                          SmallVector<std::string> &FileName);
 
 // Remove the temporary files in \p FileName.  Typically used in conjunction
 // with prepareTempFiles.  Return first error code (if any) and stop..
-std::error_code cleanUpTempFiles(ArrayRef<std::string> FileName);
+LLVM_ABI std::error_code cleanUpTempFiles(ArrayRef<std::string> FileName);
 
 // Perform a system based diff between \p Before and \p After, using \p
 // OldLineFormat, \p NewLineFormat, and \p UnchangedLineFormat to control the
 // formatting of the output. Return an error message for any failures instead
 // of the diff.
-std::string doSystemDiff(StringRef Before, StringRef After,
-                         StringRef OldLineFormat, StringRef NewLineFormat,
-                         StringRef UnchangedLineFormat);
+LLVM_ABI std::string doSystemDiff(StringRef Before, StringRef After,
+                                  StringRef OldLineFormat,
+                                  StringRef NewLineFormat,
+                                  StringRef UnchangedLineFormat);
 
 // Report a -print-changed diff for one pass over one IR unit (function or
 // module). IsInteresting is isPassInPrintList(PassID); ShouldReport is whether
diff --git a/llvm/include/llvm/IR/ProfDataUtils.h b/llvm/include/llvm/IR/ProfDataUtils.h
index 9d297c1b91a1d..2d77ef33e7056 100644
--- a/llvm/include/llvm/IR/ProfDataUtils.h
+++ b/llvm/include/llvm/IR/ProfDataUtils.h
@@ -33,7 +33,7 @@ struct MDProfLabels {
   LLVM_ABI static const char *UnknownBranchWeightsMarker;
 };
 
-extern cl::opt<bool> ProfcheckDisableMetadataFixes;
+extern LLVM_ABI cl::opt<bool> ProfcheckDisableMetadataFixes;
 
 /// Profile-based loop metadata that should be accessed only by using
 /// \c llvm::getLoopEstimatedTripCount and \c llvm::setLoopEstimatedTripCount.
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index fa092909d630d..f43e09ada394e 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -87,7 +87,7 @@ struct RuntimeLibcallsInfo {
       EABI EABIVersion = EABI::Default, StringRef ABIName = "",
       VectorLibrary VecLib = VectorLibrary::NoLibrary);
 
-  explicit RuntimeLibcallsInfo(const Module &M);
+  LLVM_ABI explicit RuntimeLibcallsInfo(const Module &M);
 
   LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
                            ModuleAnalysisManager::Invalidator &);
@@ -136,7 +136,7 @@ struct RuntimeLibcallsInfo {
   /// name may exist but differ in interpretation based on the target context.
   ///
   /// Generated by tablegen.
-  LLVM_ABI static inline iota_range<RTLIB::LibcallImpl>
+  static inline iota_range<RTLIB::LibcallImpl>
   lookupLibcallImplName(StringRef Name){
   // Inlining the early exit on the string name appears to be worthwhile when
   // querying a real set of symbols
@@ -146,8 +146,7 @@ struct RuntimeLibcallsInfo {
 
   /// Check if this is valid libcall for the current module, otherwise
   /// RTLIB::Unsupported.
-  LLVM_ABI RTLIB::LibcallImpl
-      getSupportedLibcallImpl(StringRef FuncName) const {
+  RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const {
     for (RTLIB::LibcallImpl Impl : lookupLibcallImplName(FuncName)) {
       if (isAvailable(Impl))
         return Impl;
@@ -159,13 +158,13 @@ struct RuntimeLibcallsInfo {
   /// \returns the function type and attributes for the \p LibcallImpl,
   /// depending on the target \p TT. If the function has incomplete type
   /// information, return nullptr for the function type.
-  std::pair<FunctionType *, AttributeList>
+  LLVM_ABI std::pair<FunctionType *, AttributeList>
   getFunctionTy(LLVMContext &Ctx, const Triple &TT, const DataLayout &DL,
                 RTLIB::LibcallImpl LibcallImpl) const;
 
   /// Returns true if the function has a vector mask argument, which is assumed
   /// to be the last argument.
-  static bool hasVectorMaskArgument(RTLIB::LibcallImpl Impl);
+  LLVM_ABI static bool hasVectorMaskArgument(RTLIB::LibcallImpl Impl);
 
 private:
   LLVM_ABI static iota_range<RTLIB::LibcallImpl>
diff --git a/llvm/include/llvm/IR/SafepointIRVerifier.h b/llvm/include/llvm/IR/SafepointIRVerifier.h
index ca4511b1ab8c8..9742ab3714fe0 100644
--- a/llvm/include/llvm/IR/SafepointIRVerifier.h
+++ b/llvm/include/llvm/IR/SafepointIRVerifier.h
@@ -26,11 +26,11 @@ class Function;
 class FunctionPass;
 
 /// Run the safepoint verifier over a single function.  Crashes on failure.
-void verifySafepointIR(Function &F);
+LLVM_ABI void verifySafepointIR(Function &F);
 
 /// Create an instance of the safepoint verifier pass which can be added to
 /// a pass pipeline to check for relocation bugs.
-FunctionPass *createSafepointIRVerifierPass();
+LLVM_ABI FunctionPass *createSafepointIRVerifierPass();
 
 /// Create an instance of the safepoint verifier pass which can be added to
 /// a pass pipeline to check for relocation bugs.
@@ -40,7 +40,7 @@ class SafepointIRVerifierPass
 public:
   explicit SafepointIRVerifierPass() = default;
 
-  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+  LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
 };
 }
 
diff --git a/llvm/include/llvm/IR/Statepoint.h b/llvm/include/llvm/IR/Statepoint.h
index 8c508492f704a..d05969162687c 100644
--- a/llvm/include/llvm/IR/Statepoint.h
+++ b/llvm/include/llvm/IR/Statepoint.h
@@ -242,11 +242,12 @@ struct StatepointDirectives {
 
 /// Parse out statepoint directives from the function attributes present in \p
 /// AS.
-StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeList AS);
+LLVM_ABI StatepointDirectives
+parseStatepointDirectivesFromAttrs(AttributeList AS);
 
 /// Return \c true if the \p Attr is an attribute that is a statepoint
 /// directive.
-bool isStatepointDirectiveAttr(Attribute Attr);
+LLVM_ABI bool isStatepointDirectiveAttr(Attribute Attr);
 
 } // end namespace llvm
 
diff --git a/llvm/include/llvm/IR/TypeFinder.h b/llvm/include/llvm/IR/TypeFinder.h
index dd2b70c65c2d2..bf5e889509302 100644
--- a/llvm/include/llvm/IR/TypeFinder.h
+++ b/llvm/include/llvm/IR/TypeFinder.h
@@ -42,8 +42,8 @@ class TypeFinder {
 public:
   TypeFinder() = default;
 
-  void run(const Module &M, bool onlyNamed);
-  void clear();
+  LLVM_ABI void run(const Module &M, bool onlyNamed);
+  LLVM_ABI void clear();
 
   using iterator = std::vector<StructType*>::iterator;
   using const_iterator = std::vector<StructType*>::const_iterator;



More information about the llvm-commits mailing list