[llvm] annotate interfaces in llvm/SandboxIR for DLL export (#142863)

## Purpose

This patch is one in a series of code-mods that annotate LLVM’s public
interface for export. This patch annotates the `llvm/SandboxIR` 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:
- Remove explicit `GlobalWithNodeAPI::LLVMGVToGV::operator()` template
function instantiations that were previously added for the dylib build.
Instead, directly annotate the `LLVMGVToGV::operator()` method with
`LLVM_ABI`. This is done so the DLL build works with both MSVC and
clang-cl.
- Explicitly `#include "llvm/SandboxIR/Value.h"` in `Tracker.h` so that
the symbol is available for exported templates in this file. These
templates get fully instantiated on DLL export, so they require the full
definition of `Value`.
- Add extern template instantiation declarations for `GlobalWithNodeAPI`
template types in `Constants.h` and annotate them with
`LLVM_TEMPLATE_ABI`.
- Add `LLVM_EXPORT_TEMPLATE` to `GlobalWithNodeAPI` template
instantiations in `Constants.cpp`.

## 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
This commit is contained in:
Andrew Rogers 2025-06-11 09:19:13 -07:00 committed by GitHub
parent 5188bea9af
commit 8f8ed23c62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 564 additions and 550 deletions

View File

@ -11,6 +11,7 @@
#include "llvm/IR/BasicBlock.h"
#include "llvm/SandboxIR/Value.h"
#include "llvm/Support/Compiler.h"
namespace llvm::sandboxir {
@ -32,20 +33,20 @@ private:
llvm::BasicBlock *BB;
llvm::BasicBlock::iterator It;
Context *Ctx;
pointer getInstr(llvm::BasicBlock::iterator It) const;
LLVM_ABI pointer getInstr(llvm::BasicBlock::iterator It) const;
public:
BBIterator() : BB(nullptr), Ctx(nullptr) {}
BBIterator(llvm::BasicBlock *BB, llvm::BasicBlock::iterator It, Context *Ctx)
: BB(BB), It(It), Ctx(Ctx) {}
reference operator*() const { return *getInstr(It); }
BBIterator &operator++();
LLVM_ABI BBIterator &operator++();
BBIterator operator++(int) {
auto Copy = *this;
++*this;
return Copy;
}
BBIterator &operator--();
LLVM_ABI BBIterator &operator--();
BBIterator operator--(int) {
auto Copy = *this;
--*this;
@ -60,14 +61,14 @@ public:
/// the instruction is not found in the IR-to-SandboxIR tables.
pointer get() const { return getInstr(It); }
/// \Returns the parent BB.
BasicBlock *getNodeParent() const;
LLVM_ABI BasicBlock *getNodeParent() const;
};
/// Contains a list of sandboxir::Instruction's.
class BasicBlock : public Value {
/// Builds a graph that contains all values in \p BB in their original form
/// i.e., no vectorization is taking place here.
void buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB);
LLVM_ABI void buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB);
friend class Context; // For `buildBasicBlockFromIR`
friend class Instruction; // For LLVM Val.
@ -82,9 +83,9 @@ public:
static bool classof(const Value *From) {
return From->getSubclassID() == Value::ClassID::Block;
}
Function *getParent() const;
LLVM_ABI Function *getParent() const;
using iterator = BBIterator;
iterator begin() const;
LLVM_ABI iterator begin() const;
iterator end() const {
auto *BB = cast<llvm::BasicBlock>(Val);
return iterator(BB, BB->end(), &Ctx);
@ -96,10 +97,10 @@ public:
return std::make_reverse_iterator(begin());
}
Context &getContext() const { return Ctx; }
Instruction *getTerminator() const;
LLVM_ABI Instruction *getTerminator() const;
bool empty() const { return begin() == end(); }
Instruction &front() const;
Instruction &back() const;
LLVM_ABI Instruction &front() const;
LLVM_ABI Instruction &back() const;
#ifndef NDEBUG
void verify() const final;

View File

@ -76,16 +76,16 @@ class ConstantInt : public Constant {
}
public:
static ConstantInt *getTrue(Context &Ctx);
static ConstantInt *getFalse(Context &Ctx);
static ConstantInt *getBool(Context &Ctx, bool V);
static Constant *getTrue(Type *Ty);
static Constant *getFalse(Type *Ty);
static Constant *getBool(Type *Ty, bool V);
LLVM_ABI static ConstantInt *getTrue(Context &Ctx);
LLVM_ABI static ConstantInt *getFalse(Context &Ctx);
LLVM_ABI static ConstantInt *getBool(Context &Ctx, bool V);
LLVM_ABI static Constant *getTrue(Type *Ty);
LLVM_ABI static Constant *getFalse(Type *Ty);
LLVM_ABI static Constant *getBool(Type *Ty, bool V);
/// If Ty is a vector type, return a Constant with a splat of the given
/// value. Otherwise return a ConstantInt for the given value.
static ConstantInt *get(Type *Ty, uint64_t V, bool IsSigned = false);
LLVM_ABI static ConstantInt *get(Type *Ty, uint64_t V, bool IsSigned = false);
/// Return a ConstantInt with the specified integer value for the specified
/// type. If the type is wider than 64 bits, the value will be zero-extended
@ -93,27 +93,29 @@ public:
/// be interpreted as a 64-bit signed integer and sign-extended to fit
/// the type.
/// Get a ConstantInt for a specific value.
static ConstantInt *get(IntegerType *Ty, uint64_t V, bool IsSigned = false);
LLVM_ABI static ConstantInt *get(IntegerType *Ty, uint64_t V,
bool IsSigned = false);
/// Return a ConstantInt with the specified value for the specified type. The
/// value V will be canonicalized to a an unsigned APInt. Accessing it with
/// either getSExtValue() or getZExtValue() will yield a correctly sized and
/// signed value for the type Ty.
/// Get a ConstantInt for a specific signed value.
static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
static Constant *getSigned(Type *Ty, int64_t V);
LLVM_ABI static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
LLVM_ABI static Constant *getSigned(Type *Ty, int64_t V);
/// Return a ConstantInt with the specified value and an implied Type. The
/// type is the integer type that corresponds to the bit width of the value.
static ConstantInt *get(Context &Ctx, const APInt &V);
LLVM_ABI static ConstantInt *get(Context &Ctx, const APInt &V);
/// Return a ConstantInt constructed from the string strStart with the given
/// radix.
static ConstantInt *get(IntegerType *Ty, StringRef Str, uint8_t Radix);
LLVM_ABI static ConstantInt *get(IntegerType *Ty, StringRef Str,
uint8_t Radix);
/// If Ty is a vector type, return a Constant with a splat of the given
/// value. Otherwise return a ConstantInt for the given value.
static Constant *get(Type *Ty, const APInt &V);
LLVM_ABI static Constant *get(Type *Ty, const APInt &V);
/// Return the constant as an APInt value reference. This allows clients to
/// obtain a full-precision copy of the value.
@ -166,7 +168,7 @@ public:
/// Variant of the getType() method to always return an IntegerType, which
/// reduces the amount of casting needed in parts of the compiler.
IntegerType *getIntegerType() const;
LLVM_ABI IntegerType *getIntegerType() const;
/// This static method returns true if the type Ty is big enough to
/// represent the value V. This can be used to avoid having the get method
@ -177,8 +179,8 @@ public:
/// to the appropriate unsigned type before calling the method.
/// @returns true if V is a valid value for type Ty
/// Determine if the value is in range for the given type.
static bool isValueValidForType(Type *Ty, uint64_t V);
static bool isValueValidForType(Type *Ty, int64_t V);
LLVM_ABI static bool isValueValidForType(Type *Ty, uint64_t V);
LLVM_ABI static bool isValueValidForType(Type *Ty, int64_t V);
bool isNegative() const { return cast<llvm::ConstantInt>(Val)->isNegative(); }
@ -264,29 +266,29 @@ public:
/// for the specified value in the specified type. This should only be used
/// for simple constant values like 2.0/1.0 etc, that are known-valid both as
/// host double and as the target format.
static Constant *get(Type *Ty, double V);
LLVM_ABI static Constant *get(Type *Ty, double V);
/// If Ty is a vector type, return a Constant with a splat of the given
/// value. Otherwise return a ConstantFP for the given value.
static Constant *get(Type *Ty, const APFloat &V);
LLVM_ABI static Constant *get(Type *Ty, const APFloat &V);
static Constant *get(Type *Ty, StringRef Str);
LLVM_ABI static Constant *get(Type *Ty, StringRef Str);
static ConstantFP *get(const APFloat &V, Context &Ctx);
LLVM_ABI static ConstantFP *get(const APFloat &V, Context &Ctx);
static Constant *getNaN(Type *Ty, bool Negative = false,
uint64_t Payload = 0);
static Constant *getQNaN(Type *Ty, bool Negative = false,
APInt *Payload = nullptr);
static Constant *getSNaN(Type *Ty, bool Negative = false,
APInt *Payload = nullptr);
static Constant *getZero(Type *Ty, bool Negative = false);
LLVM_ABI static Constant *getNaN(Type *Ty, bool Negative = false,
uint64_t Payload = 0);
LLVM_ABI static Constant *getQNaN(Type *Ty, bool Negative = false,
APInt *Payload = nullptr);
LLVM_ABI static Constant *getSNaN(Type *Ty, bool Negative = false,
APInt *Payload = nullptr);
LLVM_ABI static Constant *getZero(Type *Ty, bool Negative = false);
static Constant *getNegativeZero(Type *Ty);
static Constant *getInfinity(Type *Ty, bool Negative = false);
LLVM_ABI static Constant *getNegativeZero(Type *Ty);
LLVM_ABI static Constant *getInfinity(Type *Ty, bool Negative = false);
/// Return true if Ty is big enough to represent V.
static bool isValueValidForType(Type *Ty, const APFloat &V);
LLVM_ABI static bool isValueValidForType(Type *Ty, const APFloat &V);
inline const APFloat &getValueAPF() const {
return cast<llvm::ConstantFP>(Val)->getValueAPF();
@ -362,8 +364,8 @@ class ConstantArray final : public ConstantAggregate {
friend class Context; // For constructor.
public:
static Constant *get(ArrayType *T, ArrayRef<Constant *> V);
ArrayType *getType() const;
LLVM_ABI static Constant *get(ArrayType *T, ArrayRef<Constant *> V);
LLVM_ABI ArrayType *getType() const;
// TODO: Missing functions: getType(), getTypeForElements(), getAnon(), get().
@ -379,7 +381,7 @@ class ConstantStruct final : public ConstantAggregate {
friend class Context; // For constructor.
public:
static Constant *get(StructType *T, ArrayRef<Constant *> V);
LLVM_ABI static Constant *get(StructType *T, ArrayRef<Constant *> V);
template <typename... Csts>
static std::enable_if_t<are_base_of<Constant, Csts...>::value, Constant *>
@ -396,8 +398,8 @@ public:
return get(getTypeForElements(Ctx, V, Packed), V);
}
/// This version of the method allows an empty list.
static StructType *getTypeForElements(Context &Ctx, ArrayRef<Constant *> V,
bool Packed = false);
LLVM_ABI static StructType *
getTypeForElements(Context &Ctx, ArrayRef<Constant *> V, bool Packed = false);
/// Return an anonymous struct type to use for a constant with the specified
/// set of elements. The list must not be empty.
static StructType *getTypeForElements(ArrayRef<Constant *> V,
@ -424,10 +426,10 @@ class ConstantVector final : public ConstantAggregate {
friend class Context; // For constructor.
public:
static Constant *get(ArrayRef<Constant *> V);
LLVM_ABI static Constant *get(ArrayRef<Constant *> V);
/// Return a ConstantVector with the specified constant in each element.
/// Note that this might not return an instance of ConstantVector
static Constant *getSplat(ElementCount EC, Constant *Elt);
LLVM_ABI static Constant *getSplat(ElementCount EC, Constant *Elt);
/// Specialize the getType() method to always return a FixedVectorType,
/// which reduces the amount of casting needed in parts of the compiler.
inline FixedVectorType *getType() const {
@ -436,7 +438,7 @@ public:
/// If all elements of the vector constant have the same value, return that
/// value. Otherwise, return nullptr. Ignore poison elements by setting
/// AllowPoison to true.
Constant *getSplatValue(bool AllowPoison = false) const;
LLVM_ABI Constant *getSplatValue(bool AllowPoison = false) const;
/// For isa/dyn_cast.
static bool classof(const Value *From) {
@ -451,18 +453,18 @@ class ConstantAggregateZero final : public Constant {
friend class Context; // For constructor.
public:
static ConstantAggregateZero *get(Type *Ty);
LLVM_ABI static ConstantAggregateZero *get(Type *Ty);
/// If this CAZ has array or vector type, return a zero with the right element
/// type.
Constant *getSequentialElement() const;
LLVM_ABI Constant *getSequentialElement() const;
/// If this CAZ has struct type, return a zero with the right element type for
/// the specified element.
Constant *getStructElement(unsigned Elt) const;
LLVM_ABI Constant *getStructElement(unsigned Elt) const;
/// Return a zero of the right value for the specified GEP index if we can,
/// otherwise return null (e.g. if C is a ConstantExpr).
Constant *getElementValue(Constant *C) const;
LLVM_ABI Constant *getElementValue(Constant *C) const;
/// Return a zero of the right value for the specified GEP index.
Constant *getElementValue(unsigned Idx) const;
LLVM_ABI Constant *getElementValue(unsigned Idx) const;
/// Return the number of elements in the array, vector, or struct.
ElementCount getElementCount() const {
return cast<llvm::ConstantAggregateZero>(Val)->getElementCount();
@ -769,9 +771,9 @@ class ConstantPointerNull final : public Constant {
friend class Context; // For constructor.
public:
static ConstantPointerNull *get(PointerType *Ty);
LLVM_ABI static ConstantPointerNull *get(PointerType *Ty);
PointerType *getType() const;
LLVM_ABI PointerType *getType() const;
/// For isa/dyn_cast.
static bool classof(const sandboxir::Value *From) {
@ -802,22 +804,22 @@ protected:
public:
/// Static factory methods - Return an 'undef' object of the specified type.
static UndefValue *get(Type *T);
LLVM_ABI static UndefValue *get(Type *T);
/// If this Undef has array or vector type, return a undef with the right
/// element type.
UndefValue *getSequentialElement() const;
LLVM_ABI UndefValue *getSequentialElement() const;
/// If this undef has struct type, return a undef with the right element type
/// for the specified element.
UndefValue *getStructElement(unsigned Elt) const;
LLVM_ABI UndefValue *getStructElement(unsigned Elt) const;
/// Return an undef of the right value for the specified GEP index if we can,
/// otherwise return null (e.g. if C is a ConstantExpr).
UndefValue *getElementValue(Constant *C) const;
LLVM_ABI UndefValue *getElementValue(Constant *C) const;
/// Return an undef of the right value for the specified GEP index.
UndefValue *getElementValue(unsigned Idx) const;
LLVM_ABI UndefValue *getElementValue(unsigned Idx) const;
/// Return the number of elements in the array, vector, or struct.
unsigned getNumElements() const {
@ -850,22 +852,22 @@ class PoisonValue final : public UndefValue {
public:
/// Static factory methods - Return an 'poison' object of the specified type.
static PoisonValue *get(Type *T);
LLVM_ABI static PoisonValue *get(Type *T);
/// If this poison has array or vector type, return a poison with the right
/// element type.
PoisonValue *getSequentialElement() const;
LLVM_ABI PoisonValue *getSequentialElement() const;
/// If this poison has struct type, return a poison with the right element
/// type for the specified element.
PoisonValue *getStructElement(unsigned Elt) const;
LLVM_ABI PoisonValue *getStructElement(unsigned Elt) const;
/// Return an poison of the right value for the specified GEP index if we can,
/// otherwise return null (e.g. if C is a ConstantExpr).
PoisonValue *getElementValue(Constant *C) const;
LLVM_ABI PoisonValue *getElementValue(Constant *C) const;
/// Return an poison of the right value for the specified GEP index.
PoisonValue *getElementValue(unsigned Idx) const;
LLVM_ABI PoisonValue *getElementValue(unsigned Idx) const;
/// For isa/dyn_cast.
static bool classof(const sandboxir::Value *From) {
@ -924,7 +926,7 @@ public:
UnnamedAddr getUnnamedAddr() const {
return cast<llvm::GlobalValue>(Val)->getUnnamedAddr();
}
void setUnnamedAddr(UnnamedAddr V);
LLVM_ABI void setUnnamedAddr(UnnamedAddr V);
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B) {
return llvm::GlobalValue::getMinUnnamedAddr(A, B);
@ -946,7 +948,7 @@ public:
bool hasProtectedVisibility() const {
return cast<llvm::GlobalValue>(Val)->hasProtectedVisibility();
}
void setVisibility(VisibilityTypes V);
LLVM_ABI void setVisibility(VisibilityTypes V);
// TODO: Add missing functions.
};
@ -996,7 +998,7 @@ public:
///
/// Setting the section to the empty string tells LLVM to choose an
/// appropriate default object file section.
void setSection(StringRef S);
LLVM_ABI void setSection(StringRef S);
bool hasComdat() const { return cast<llvm::GlobalObject>(Val)->hasComdat(); }
@ -1031,7 +1033,7 @@ class GlobalWithNodeAPI : public ParentT {
struct LLVMGVToGV {
Context &Ctx;
LLVMGVToGV(Context &Ctx) : Ctx(Ctx) {}
GlobalT &operator()(LLVMGlobalT &LLVMGV) const;
LLVM_ABI GlobalT &operator()(LLVMGlobalT &LLVMGV) const;
};
public:
@ -1060,24 +1062,15 @@ public:
}
};
// These are needed for SandboxIRTest when building with LLVM_BUILD_LLVM_DYLIB
extern template LLVM_TEMPLATE_ABI GlobalIFunc &
GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalIFunc
&LLVMGV)
const;
extern template LLVM_TEMPLATE_ABI Function &
GlobalWithNodeAPI<Function, llvm::Function, GlobalObject, llvm::GlobalObject>::
LLVMGVToGV::operator()(llvm::Function &LLVMGV) const;
extern template LLVM_TEMPLATE_ABI GlobalVariable &GlobalWithNodeAPI<
GlobalVariable, llvm::GlobalVariable, GlobalObject,
llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalVariable &LLVMGV)
const;
extern template LLVM_TEMPLATE_ABI GlobalAlias &
GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
llvm::GlobalValue>::LLVMGVToGV::operator()(llvm::GlobalAlias
&LLVMGV) const;
// Explicit instantiations.
extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
GlobalIFunc, llvm::GlobalIFunc, GlobalObject, llvm::GlobalObject>;
extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
Function, llvm::Function, GlobalObject, llvm::GlobalObject>;
extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
GlobalVariable, llvm::GlobalVariable, GlobalObject, llvm::GlobalObject>;
extern template class LLVM_TEMPLATE_ABI GlobalWithNodeAPI<
GlobalAlias, llvm::GlobalAlias, GlobalValue, llvm::GlobalValue>;
class GlobalIFunc final
: public GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
@ -1097,13 +1090,13 @@ public:
// TODO: Missing functions: copyAttributesFrom(), removeFromParent(),
// eraseFromParent()
void setResolver(Constant *Resolver);
LLVM_ABI void setResolver(Constant *Resolver);
Constant *getResolver() const;
LLVM_ABI Constant *getResolver() const;
// Return the resolver function after peeling off potential ConstantExpr
// indirection.
Function *getResolverFunction();
LLVM_ABI Function *getResolverFunction();
const Function *getResolverFunction() const {
return const_cast<GlobalIFunc *>(this)->getResolverFunction();
}
@ -1136,7 +1129,7 @@ class GlobalVariable final
struct LLVMGVToGV {
Context &Ctx;
LLVMGVToGV(Context &Ctx) : Ctx(Ctx) {}
GlobalVariable &operator()(llvm::GlobalVariable &LLVMGV) const;
LLVM_ABI GlobalVariable &operator()(llvm::GlobalVariable &LLVMGV) const;
};
public:
@ -1181,11 +1174,11 @@ public:
/// illegal to call this method if the global is external, because we cannot
/// tell what the value is initialized to!
///
Constant *getInitializer() const;
LLVM_ABI Constant *getInitializer() const;
/// setInitializer - Sets the initializer for this global variable, removing
/// any existing initializer if InitVal==NULL. The initializer must have the
/// type getValueType().
void setInitializer(Constant *InitVal);
LLVM_ABI void setInitializer(Constant *InitVal);
// TODO: Add missing replaceInitializer(). Requires special tracker
@ -1196,12 +1189,12 @@ public:
bool isConstant() const {
return cast<llvm::GlobalVariable>(Val)->isConstant();
}
void setConstant(bool V);
LLVM_ABI void setConstant(bool V);
bool isExternallyInitialized() const {
return cast<llvm::GlobalVariable>(Val)->isExternallyInitialized();
}
void setExternallyInitialized(bool Val);
LLVM_ABI void setExternallyInitialized(bool Val);
// TODO: Missing copyAttributesFrom()
@ -1278,7 +1271,7 @@ public:
/// Sets the alignment attribute of the GlobalVariable.
/// This method will be deprecated as the alignment property should always be
/// defined.
void setAlignment(MaybeAlign Align);
LLVM_ABI void setAlignment(MaybeAlign Align);
// TODO: Missing setCodeModel(). Requires custom tracker.
@ -1311,10 +1304,10 @@ public:
// TODO: Missing copyAttributresFrom().
// TODO: Missing removeFromParent(), eraseFromParent().
void setAliasee(Constant *Aliasee);
Constant *getAliasee() const;
LLVM_ABI void setAliasee(Constant *Aliasee);
LLVM_ABI Constant *getAliasee() const;
const GlobalObject *getAliaseeObject() const;
LLVM_ABI const GlobalObject *getAliaseeObject() const;
GlobalObject *getAliaseeObject() {
return const_cast<GlobalObject *>(
static_cast<const GlobalAlias *>(this)->getAliaseeObject());
@ -1336,12 +1329,12 @@ class NoCFIValue final : public Constant {
public:
/// Return a NoCFIValue for the specified function.
static NoCFIValue *get(GlobalValue *GV);
LLVM_ABI static NoCFIValue *get(GlobalValue *GV);
GlobalValue *getGlobalValue() const;
LLVM_ABI GlobalValue *getGlobalValue() const;
/// NoCFIValue is always a pointer.
PointerType *getType() const;
LLVM_ABI PointerType *getType() const;
/// For isa/dyn_cast.
static bool classof(const sandboxir::Value *From) {
return From->getSubclassID() == ClassID::NoCFIValue;
@ -1369,21 +1362,21 @@ class ConstantPtrAuth final : public Constant {
public:
/// Return a pointer signed with the specified parameters.
static ConstantPtrAuth *get(Constant *Ptr, ConstantInt *Key,
ConstantInt *Disc, Constant *AddrDisc);
LLVM_ABI static ConstantPtrAuth *get(Constant *Ptr, ConstantInt *Key,
ConstantInt *Disc, Constant *AddrDisc);
/// The pointer that is signed in this ptrauth signed pointer.
Constant *getPointer() const;
LLVM_ABI Constant *getPointer() const;
/// The Key ID, an i32 constant.
ConstantInt *getKey() const;
LLVM_ABI ConstantInt *getKey() const;
/// The integer discriminator, an i64 constant, or 0.
ConstantInt *getDiscriminator() const;
LLVM_ABI ConstantInt *getDiscriminator() const;
/// The address discriminator if any, or the null constant.
/// If present, this must be a value equivalent to the storage location of
/// the only global-initializer user of the ptrauth signed pointer.
Constant *getAddrDiscriminator() const;
LLVM_ABI Constant *getAddrDiscriminator() const;
/// Whether there is any non-null address discriminator.
bool hasAddressDiscriminator() const {
@ -1410,7 +1403,7 @@ public:
/// Produce a new ptrauth expression signing the given value using
/// the same schema as is stored in one.
ConstantPtrAuth *getWithSameSchema(Constant *Pointer) const;
LLVM_ABI ConstantPtrAuth *getWithSameSchema(Constant *Pointer) const;
/// For isa/dyn_cast.
static bool classof(const sandboxir::Value *From) {
@ -1438,19 +1431,19 @@ class BlockAddress final : public Constant {
public:
/// Return a BlockAddress for the specified function and basic block.
static BlockAddress *get(Function *F, BasicBlock *BB);
LLVM_ABI static BlockAddress *get(Function *F, BasicBlock *BB);
/// Return a BlockAddress for the specified basic block. The basic
/// block must be embedded into a function.
static BlockAddress *get(BasicBlock *BB);
LLVM_ABI static BlockAddress *get(BasicBlock *BB);
/// Lookup an existing \c BlockAddress constant for the given BasicBlock.
///
/// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress.
static BlockAddress *lookup(const BasicBlock *BB);
LLVM_ABI static BlockAddress *lookup(const BasicBlock *BB);
Function *getFunction() const;
BasicBlock *getBasicBlock() const;
LLVM_ABI Function *getFunction() const;
LLVM_ABI BasicBlock *getBasicBlock() const;
/// For isa/dyn_cast.
static bool classof(const sandboxir::Value *From) {
@ -1465,9 +1458,9 @@ class DSOLocalEquivalent final : public Constant {
public:
/// Return a DSOLocalEquivalent for the specified global value.
static DSOLocalEquivalent *get(GlobalValue *GV);
LLVM_ABI static DSOLocalEquivalent *get(GlobalValue *GV);
GlobalValue *getGlobalValue() const;
LLVM_ABI GlobalValue *getGlobalValue() const;
/// For isa/dyn_cast.
static bool classof(const sandboxir::Value *From) {
@ -1498,7 +1491,7 @@ class ConstantTokenNone final : public Constant {
public:
/// Return the ConstantTokenNone.
static ConstantTokenNone *get(Context &Ctx);
LLVM_ABI static ConstantTokenNone *get(Context &Ctx);
/// For isa/dyn_cast.
static bool classof(const sandboxir::Value *From) {

View File

@ -15,6 +15,7 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/SandboxIR/Tracker.h"
#include "llvm/SandboxIR/Type.h"
#include "llvm/Support/Compiler.h"
#include <cstdint>
@ -112,32 +113,33 @@ protected:
CallbackID::ValTy NextCallbackID = 1;
/// Remove \p V from the maps and returns the unique_ptr.
std::unique_ptr<Value> detachLLVMValue(llvm::Value *V);
LLVM_ABI std::unique_ptr<Value> detachLLVMValue(llvm::Value *V);
/// Remove \p SBV from all SandboxIR maps and stop owning it. This effectively
/// detaches \p V from the underlying IR.
std::unique_ptr<Value> detach(Value *V);
LLVM_ABI std::unique_ptr<Value> detach(Value *V);
friend class Instruction; // For detach().
/// Take ownership of VPtr and store it in `LLVMValueToValueMap`.
Value *registerValue(std::unique_ptr<Value> &&VPtr);
LLVM_ABI Value *registerValue(std::unique_ptr<Value> &&VPtr);
friend class EraseFromParent; // For registerValue().
/// This is the actual function that creates sandboxir values for \p V,
/// and among others handles all instruction types.
Value *getOrCreateValueInternal(llvm::Value *V, llvm::User *U = nullptr);
LLVM_ABI Value *getOrCreateValueInternal(llvm::Value *V,
llvm::User *U = nullptr);
/// Get or create a sandboxir::Argument for an existing LLVM IR \p LLVMArg.
Argument *getOrCreateArgument(llvm::Argument *LLVMArg);
LLVM_ABI Argument *getOrCreateArgument(llvm::Argument *LLVMArg);
/// Get or create a sandboxir::Value for an existing LLVM IR \p LLVMV.
Value *getOrCreateValue(llvm::Value *LLVMV) {
return getOrCreateValueInternal(LLVMV, 0);
}
/// Get or create a sandboxir::Constant from an existing LLVM IR \p LLVMC.
Constant *getOrCreateConstant(llvm::Constant *LLVMC);
LLVM_ABI Constant *getOrCreateConstant(llvm::Constant *LLVMC);
friend class ConstantDataSequential; // For getOrCreateConstant().
friend class Utils; // For getMemoryBase
void runEraseInstrCallbacks(Instruction *I);
void runCreateInstrCallbacks(Instruction *I);
void runMoveInstrCallbacks(Instruction *I, const BBIterator &Where);
void runSetUseCallbacks(const Use &U, Value *NewSrc);
LLVM_ABI void runEraseInstrCallbacks(Instruction *I);
LLVM_ABI void runCreateInstrCallbacks(Instruction *I);
LLVM_ABI void runMoveInstrCallbacks(Instruction *I, const BBIterator &Where);
LLVM_ABI void runSetUseCallbacks(const Use &U, Value *NewSrc);
friend class User; // For runSetUseCallbacks().
friend class Value; // For runSetUseCallbacks().
@ -148,90 +150,97 @@ protected:
/// Create a sandboxir::BasicBlock for an existing LLVM IR \p BB. This will
/// also create all contents of the block.
BasicBlock *createBasicBlock(llvm::BasicBlock *BB);
LLVM_ABI BasicBlock *createBasicBlock(llvm::BasicBlock *BB);
friend class BasicBlock; // For getOrCreateValue().
IRBuilder<ConstantFolder> LLVMIRBuilder;
auto &getLLVMIRBuilder() { return LLVMIRBuilder; }
VAArgInst *createVAArgInst(llvm::VAArgInst *SI);
LLVM_ABI VAArgInst *createVAArgInst(llvm::VAArgInst *SI);
friend VAArgInst; // For createVAArgInst()
FreezeInst *createFreezeInst(llvm::FreezeInst *SI);
LLVM_ABI FreezeInst *createFreezeInst(llvm::FreezeInst *SI);
friend FreezeInst; // For createFreezeInst()
FenceInst *createFenceInst(llvm::FenceInst *SI);
LLVM_ABI FenceInst *createFenceInst(llvm::FenceInst *SI);
friend FenceInst; // For createFenceInst()
SelectInst *createSelectInst(llvm::SelectInst *SI);
LLVM_ABI SelectInst *createSelectInst(llvm::SelectInst *SI);
friend SelectInst; // For createSelectInst()
InsertElementInst *createInsertElementInst(llvm::InsertElementInst *IEI);
LLVM_ABI InsertElementInst *
createInsertElementInst(llvm::InsertElementInst *IEI);
friend InsertElementInst; // For createInsertElementInst()
ExtractElementInst *createExtractElementInst(llvm::ExtractElementInst *EEI);
LLVM_ABI ExtractElementInst *
createExtractElementInst(llvm::ExtractElementInst *EEI);
friend ExtractElementInst; // For createExtractElementInst()
ShuffleVectorInst *createShuffleVectorInst(llvm::ShuffleVectorInst *SVI);
LLVM_ABI ShuffleVectorInst *
createShuffleVectorInst(llvm::ShuffleVectorInst *SVI);
friend ShuffleVectorInst; // For createShuffleVectorInst()
ExtractValueInst *createExtractValueInst(llvm::ExtractValueInst *IVI);
LLVM_ABI ExtractValueInst *
createExtractValueInst(llvm::ExtractValueInst *IVI);
friend ExtractValueInst; // For createExtractValueInst()
InsertValueInst *createInsertValueInst(llvm::InsertValueInst *IVI);
LLVM_ABI InsertValueInst *createInsertValueInst(llvm::InsertValueInst *IVI);
friend InsertValueInst; // For createInsertValueInst()
BranchInst *createBranchInst(llvm::BranchInst *I);
LLVM_ABI BranchInst *createBranchInst(llvm::BranchInst *I);
friend BranchInst; // For createBranchInst()
LoadInst *createLoadInst(llvm::LoadInst *LI);
LLVM_ABI LoadInst *createLoadInst(llvm::LoadInst *LI);
friend LoadInst; // For createLoadInst()
StoreInst *createStoreInst(llvm::StoreInst *SI);
LLVM_ABI StoreInst *createStoreInst(llvm::StoreInst *SI);
friend StoreInst; // For createStoreInst()
ReturnInst *createReturnInst(llvm::ReturnInst *I);
LLVM_ABI ReturnInst *createReturnInst(llvm::ReturnInst *I);
friend ReturnInst; // For createReturnInst()
CallInst *createCallInst(llvm::CallInst *I);
LLVM_ABI CallInst *createCallInst(llvm::CallInst *I);
friend CallInst; // For createCallInst()
InvokeInst *createInvokeInst(llvm::InvokeInst *I);
LLVM_ABI InvokeInst *createInvokeInst(llvm::InvokeInst *I);
friend InvokeInst; // For createInvokeInst()
CallBrInst *createCallBrInst(llvm::CallBrInst *I);
LLVM_ABI CallBrInst *createCallBrInst(llvm::CallBrInst *I);
friend CallBrInst; // For createCallBrInst()
LandingPadInst *createLandingPadInst(llvm::LandingPadInst *I);
LLVM_ABI LandingPadInst *createLandingPadInst(llvm::LandingPadInst *I);
friend LandingPadInst; // For createLandingPadInst()
CatchPadInst *createCatchPadInst(llvm::CatchPadInst *I);
LLVM_ABI CatchPadInst *createCatchPadInst(llvm::CatchPadInst *I);
friend CatchPadInst; // For createCatchPadInst()
CleanupPadInst *createCleanupPadInst(llvm::CleanupPadInst *I);
LLVM_ABI CleanupPadInst *createCleanupPadInst(llvm::CleanupPadInst *I);
friend CleanupPadInst; // For createCleanupPadInst()
CatchReturnInst *createCatchReturnInst(llvm::CatchReturnInst *I);
LLVM_ABI CatchReturnInst *createCatchReturnInst(llvm::CatchReturnInst *I);
friend CatchReturnInst; // For createCatchReturnInst()
CleanupReturnInst *createCleanupReturnInst(llvm::CleanupReturnInst *I);
LLVM_ABI CleanupReturnInst *
createCleanupReturnInst(llvm::CleanupReturnInst *I);
friend CleanupReturnInst; // For createCleanupReturnInst()
GetElementPtrInst *createGetElementPtrInst(llvm::GetElementPtrInst *I);
LLVM_ABI GetElementPtrInst *
createGetElementPtrInst(llvm::GetElementPtrInst *I);
friend GetElementPtrInst; // For createGetElementPtrInst()
CatchSwitchInst *createCatchSwitchInst(llvm::CatchSwitchInst *I);
LLVM_ABI CatchSwitchInst *createCatchSwitchInst(llvm::CatchSwitchInst *I);
friend CatchSwitchInst; // For createCatchSwitchInst()
ResumeInst *createResumeInst(llvm::ResumeInst *I);
LLVM_ABI ResumeInst *createResumeInst(llvm::ResumeInst *I);
friend ResumeInst; // For createResumeInst()
SwitchInst *createSwitchInst(llvm::SwitchInst *I);
LLVM_ABI SwitchInst *createSwitchInst(llvm::SwitchInst *I);
friend SwitchInst; // For createSwitchInst()
UnaryOperator *createUnaryOperator(llvm::UnaryOperator *I);
LLVM_ABI UnaryOperator *createUnaryOperator(llvm::UnaryOperator *I);
friend UnaryOperator; // For createUnaryOperator()
BinaryOperator *createBinaryOperator(llvm::BinaryOperator *I);
LLVM_ABI BinaryOperator *createBinaryOperator(llvm::BinaryOperator *I);
friend BinaryOperator; // For createBinaryOperator()
AtomicRMWInst *createAtomicRMWInst(llvm::AtomicRMWInst *I);
LLVM_ABI AtomicRMWInst *createAtomicRMWInst(llvm::AtomicRMWInst *I);
friend AtomicRMWInst; // For createAtomicRMWInst()
AtomicCmpXchgInst *createAtomicCmpXchgInst(llvm::AtomicCmpXchgInst *I);
LLVM_ABI AtomicCmpXchgInst *
createAtomicCmpXchgInst(llvm::AtomicCmpXchgInst *I);
friend AtomicCmpXchgInst; // For createAtomicCmpXchgInst()
AllocaInst *createAllocaInst(llvm::AllocaInst *I);
LLVM_ABI AllocaInst *createAllocaInst(llvm::AllocaInst *I);
friend AllocaInst; // For createAllocaInst()
CastInst *createCastInst(llvm::CastInst *I);
LLVM_ABI CastInst *createCastInst(llvm::CastInst *I);
friend CastInst; // For createCastInst()
PHINode *createPHINode(llvm::PHINode *I);
LLVM_ABI PHINode *createPHINode(llvm::PHINode *I);
friend PHINode; // For createPHINode()
UnreachableInst *createUnreachableInst(llvm::UnreachableInst *UI);
LLVM_ABI UnreachableInst *createUnreachableInst(llvm::UnreachableInst *UI);
friend UnreachableInst; // For createUnreachableInst()
CmpInst *createCmpInst(llvm::CmpInst *I);
LLVM_ABI CmpInst *createCmpInst(llvm::CmpInst *I);
friend CmpInst; // For createCmpInst()
ICmpInst *createICmpInst(llvm::ICmpInst *I);
LLVM_ABI ICmpInst *createICmpInst(llvm::ICmpInst *I);
friend ICmpInst; // For createICmpInst()
FCmpInst *createFCmpInst(llvm::FCmpInst *I);
LLVM_ABI FCmpInst *createFCmpInst(llvm::FCmpInst *I);
friend FCmpInst; // For createFCmpInst()
public:
Context(LLVMContext &LLVMCtx);
~Context();
LLVM_ABI Context(LLVMContext &LLVMCtx);
LLVM_ABI ~Context();
/// Clears function-level state.
void clear();
LLVM_ABI void clear();
Tracker &getTracker() { return IRTracker; }
/// Convenience function for `getTracker().save()`
@ -241,14 +250,14 @@ public:
/// Convenience function for `getTracker().accept()`
void accept() { IRTracker.accept(); }
sandboxir::Value *getValue(llvm::Value *V) const;
LLVM_ABI sandboxir::Value *getValue(llvm::Value *V) const;
const sandboxir::Value *getValue(const llvm::Value *V) const {
return getValue(const_cast<llvm::Value *>(V));
}
Module *getModule(llvm::Module *LLVMM) const;
LLVM_ABI Module *getModule(llvm::Module *LLVMM) const;
Module *getOrCreateModule(llvm::Module *LLVMM);
LLVM_ABI Module *getOrCreateModule(llvm::Module *LLVMM);
Type *getType(llvm::Type *LLVMTy) {
if (LLVMTy == nullptr)
@ -265,10 +274,10 @@ public:
/// This is the main API function for creating Sandbox IR.
/// Note: this will not fully populate its parent module. The only globals
/// that will be available are those used within the function.
Function *createFunction(llvm::Function *F);
LLVM_ABI Function *createFunction(llvm::Function *F);
/// Create a sandboxir::Module corresponding to \p LLVMM.
Module *createModule(llvm::Module *LLVMM);
LLVM_ABI Module *createModule(llvm::Module *LLVMM);
/// \Returns the number of values registered with Context.
size_t getNumValues() const { return LLVMValueToValueMap.size(); }
@ -277,26 +286,26 @@ public:
/// to be removed from its parent. Note that this will also be called when
/// reverting the creation of an instruction.
/// \Returns a callback ID for later deregistration.
CallbackID registerEraseInstrCallback(EraseInstrCallback CB);
void unregisterEraseInstrCallback(CallbackID ID);
LLVM_ABI CallbackID registerEraseInstrCallback(EraseInstrCallback CB);
LLVM_ABI void unregisterEraseInstrCallback(CallbackID ID);
/// Register a callback that gets called right after a SandboxIR instruction
/// is created. Note that this will also be called when reverting the removal
/// of an instruction.
/// \Returns a callback ID for later deregistration.
CallbackID registerCreateInstrCallback(CreateInstrCallback CB);
void unregisterCreateInstrCallback(CallbackID ID);
LLVM_ABI CallbackID registerCreateInstrCallback(CreateInstrCallback CB);
LLVM_ABI void unregisterCreateInstrCallback(CallbackID ID);
/// Register a callback that gets called when a SandboxIR instruction is about
/// to be moved. Note that this will also be called when reverting a move.
/// \Returns a callback ID for later deregistration.
CallbackID registerMoveInstrCallback(MoveInstrCallback CB);
void unregisterMoveInstrCallback(CallbackID ID);
LLVM_ABI CallbackID registerMoveInstrCallback(MoveInstrCallback CB);
LLVM_ABI void unregisterMoveInstrCallback(CallbackID ID);
/// Register a callback that gets called when a Use gets set.
/// \Returns a callback ID for later deregistration.
CallbackID registerSetUseCallback(SetUseCallback CB);
void unregisterSetUseCallback(CallbackID ID);
LLVM_ABI CallbackID registerSetUseCallback(SetUseCallback CB);
LLVM_ABI void unregisterSetUseCallback(CallbackID ID);
};
} // namespace sandboxir

View File

@ -11,6 +11,7 @@
#include "llvm/IR/Function.h"
#include "llvm/SandboxIR/Constant.h"
#include "llvm/Support/Compiler.h"
namespace llvm::sandboxir {
@ -56,7 +57,7 @@ public:
LLVMBBToBB BBGetter(Ctx);
return iterator(cast<llvm::Function>(Val)->end(), BBGetter);
}
FunctionType *getFunctionType() const;
LLVM_ABI FunctionType *getFunctionType() const;
/// Returns the alignment of the given function.
MaybeAlign getAlign() const { return cast<llvm::Function>(Val)->getAlign(); }
@ -66,7 +67,7 @@ public:
/// Sets the alignment attribute of the Function.
/// This method will be deprecated as the alignment property should always be
/// defined.
void setAlignment(MaybeAlign Align);
LLVM_ABI void setAlignment(MaybeAlign Align);
#ifndef NDEBUG
void verify() const final {

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Compiler.h"
#include <string>
namespace llvm {
@ -38,7 +39,7 @@ class Module {
public:
Context &getContext() const { return Ctx; }
Function *getFunction(StringRef Name) const;
LLVM_ABI Function *getFunction(StringRef Name) const;
const DataLayout &getDataLayout() const { return LLVMM.getDataLayout(); }
@ -50,7 +51,8 @@ public:
/// does not exist, return null. If AllowInternal is set to true, this
/// function will return types that have InternalLinkage. By default, these
/// types are not returned.
GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal) const;
LLVM_ABI GlobalVariable *getGlobalVariable(StringRef Name,
bool AllowInternal) const;
GlobalVariable *getGlobalVariable(StringRef Name) const {
return getGlobalVariable(Name, /*AllowInternal=*/false);
}
@ -66,12 +68,12 @@ public:
/// Return the global alias in the module with the specified name, of
/// arbitrary type. This method returns null if a global with the specified
/// name is not found.
GlobalAlias *getNamedAlias(StringRef Name) const;
LLVM_ABI GlobalAlias *getNamedAlias(StringRef Name) const;
/// Return the global ifunc in the module with the specified name, of
/// arbitrary type. This method returns null if a global with the specified
/// name is not found.
GlobalIFunc *getNamedIFunc(StringRef Name) const;
LLVM_ABI GlobalIFunc *getNamedIFunc(StringRef Name) const;
// TODO: Missing removeGlobalVariable() eraseGlobalVariable(),
// insertGlobalVariable()

View File

@ -18,6 +18,7 @@
#ifndef LLVM_SANDBOXIR_PASSMANAGER_H
#define LLVM_SANDBOXIR_PASSMANAGER_H
#include "llvm/Support/Compiler.h"
#include <memory>
#include "llvm/ADT/DenseMap.h"
@ -201,7 +202,7 @@ public:
}
};
class FunctionPassManager final
class LLVM_ABI FunctionPassManager final
: public PassManager<FunctionPass, FunctionPass> {
public:
FunctionPassManager(StringRef Name) : PassManager(Name) {}
@ -211,7 +212,8 @@ public:
bool runOnFunction(Function &F, const Analyses &A) final;
};
class RegionPassManager final : public PassManager<RegionPass, RegionPass> {
class LLVM_ABI RegionPassManager final
: public PassManager<RegionPass, RegionPass> {
public:
RegionPassManager(StringRef Name) : PassManager(Name) {}
RegionPassManager(StringRef Name, StringRef Pipeline,

View File

@ -9,6 +9,7 @@
#ifndef LLVM_SANDBOXIR_REGION_H
#define LLVM_SANDBOXIR_REGION_H
#include "llvm/Support/Compiler.h"
#include <memory>
#include "llvm/ADT/SetVector.h"
@ -30,7 +31,7 @@ class ScoreBoard {
/// The cost of all instructions that got removed and replaced by new ones.
InstructionCost BeforeCost = 0;
/// Helper for both add() and remove(). \Returns the TTI cost of \p I.
InstructionCost getCost(Instruction *I) const;
LLVM_ABI InstructionCost getCost(Instruction *I) const;
/// No need to allow copies.
ScoreBoard(const ScoreBoard &) = delete;
const ScoreBoard &operator=(const ScoreBoard &) = delete;
@ -40,7 +41,7 @@ public:
/// Mark \p I as a newly added instruction to the region.
void add(Instruction *I) { AfterCost += getCost(I); }
/// Mark \p I as a deleted instruction from the region.
void remove(Instruction *I);
LLVM_ABI void remove(Instruction *I);
/// \Returns the cost of the newly added instructions.
InstructionCost getAfterCost() const { return AfterCost; }
/// \Returns the cost of the Removed instructions.
@ -122,12 +123,12 @@ class Region {
/// add an instruction to the auxiliary vector it does get tagged as being a
/// member of the region (for ownership reasons), but its cost does not get
/// counted because the instruction hasn't been added in the "normal" way.
void addImpl(Instruction *I, bool IgnoreCost);
LLVM_ABI void addImpl(Instruction *I, bool IgnoreCost);
/// Adds I to the set. This is the main API for adding an instruction to the
/// region.
void add(Instruction *I) { addImpl(I, /*IgnoreCost=*/false); }
/// Removes I from the set.
void remove(Instruction *I);
LLVM_ABI void remove(Instruction *I);
friend class Context; // The callbacks need to call add() and remove().
friend class RegionInternalsAttorney; // For unit tests.
friend class RegionsFromBBs; // For add().
@ -141,8 +142,8 @@ class Region {
void removeFromAux(Instruction *I);
public:
Region(Context &Ctx, TargetTransformInfo &TTI);
~Region();
LLVM_ABI Region(Context &Ctx, TargetTransformInfo &TTI);
LLVM_ABI ~Region();
Context &getContext() const { return Ctx; }
/// Returns true if I is in the Region.
@ -150,18 +151,18 @@ public:
/// Returns true if the Region has no instructions.
bool empty() const { return Insts.empty(); }
/// Set the auxiliary vector.
void setAux(ArrayRef<Instruction *> Aux);
LLVM_ABI void setAux(ArrayRef<Instruction *> Aux);
/// \Returns the auxiliary vector.
const SmallVector<Instruction *> &getAux() const { return Aux; }
/// Clears all auxiliary data.
void clearAux();
LLVM_ABI void clearAux();
using iterator = decltype(Insts.begin());
iterator begin() { return Insts.begin(); }
iterator end() { return Insts.end(); }
iterator_range<iterator> insts() { return make_range(begin(), end()); }
static SmallVector<std::unique_ptr<Region>>
LLVM_ABI static SmallVector<std::unique_ptr<Region>>
createRegionsFromMD(Function &F, TargetTransformInfo &TTI);
/// \Returns the ScoreBoard data structure that keeps track of instr costs.
const ScoreBoard &getScoreboard() const { return Scoreboard; }

View File

@ -46,6 +46,8 @@
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instruction.h"
#include "llvm/SandboxIR/Use.h"
#include "llvm/SandboxIR/Value.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include <memory>
@ -149,7 +151,7 @@ public:
#endif
};
class PHIRemoveIncoming : public IRChangeBase {
class LLVM_ABI PHIRemoveIncoming : public IRChangeBase {
PHINode *PHI;
unsigned RemovedIdx;
Value *RemovedV;
@ -165,7 +167,7 @@ public:
#endif
};
class PHIAddIncoming : public IRChangeBase {
class LLVM_ABI PHIAddIncoming : public IRChangeBase {
PHINode *PHI;
unsigned Idx;
@ -179,7 +181,7 @@ public:
#endif
};
class CmpSwapOperands : public IRChangeBase {
class LLVM_ABI CmpSwapOperands : public IRChangeBase {
CmpInst *Cmp;
public:
@ -210,7 +212,7 @@ public:
#endif
};
class EraseFromParent : public IRChangeBase {
class LLVM_ABI EraseFromParent : public IRChangeBase {
/// Contains all the data we need to restore an "erased" (i.e., detached)
/// instruction: the instruction itself and its operands in order.
struct InstrAndOperands {
@ -242,7 +244,7 @@ public:
#endif
};
class RemoveFromParent : public IRChangeBase {
class LLVM_ABI RemoveFromParent : public IRChangeBase {
/// The instruction that is about to get removed.
Instruction *RemovedI = nullptr;
/// This is either the next instr, or the parent BB if at the end of the BB.
@ -327,7 +329,7 @@ public:
#endif
};
class CatchSwitchAddHandler : public IRChangeBase {
class LLVM_ABI CatchSwitchAddHandler : public IRChangeBase {
CatchSwitchInst *CSI;
unsigned HandlerIdx;
@ -344,7 +346,7 @@ public:
#endif // NDEBUG
};
class SwitchAddCase : public IRChangeBase {
class LLVM_ABI SwitchAddCase : public IRChangeBase {
SwitchInst *Switch;
ConstantInt *Val;
@ -359,7 +361,7 @@ public:
#endif // NDEBUG
};
class SwitchRemoveCase : public IRChangeBase {
class LLVM_ABI SwitchRemoveCase : public IRChangeBase {
SwitchInst *Switch;
struct Case {
ConstantInt *Val;
@ -378,7 +380,7 @@ public:
#endif // NDEBUG
};
class MoveInstr : public IRChangeBase {
class LLVM_ABI MoveInstr : public IRChangeBase {
/// The instruction that moved.
Instruction *MovedI;
/// This is either the next instruction in the block, or the parent BB if at
@ -395,7 +397,7 @@ public:
#endif // NDEBUG
};
class InsertIntoBB final : public IRChangeBase {
class LLVM_ABI InsertIntoBB final : public IRChangeBase {
Instruction *InsertedI = nullptr;
public:
@ -408,7 +410,7 @@ public:
#endif // NDEBUG
};
class CreateAndInsertInst final : public IRChangeBase {
class LLVM_ABI CreateAndInsertInst final : public IRChangeBase {
Instruction *NewI = nullptr;
public:
@ -421,7 +423,7 @@ public:
#endif
};
class ShuffleVectorSetMask final : public IRChangeBase {
class LLVM_ABI ShuffleVectorSetMask final : public IRChangeBase {
ShuffleVectorInst *SVI;
SmallVector<int, 8> PrevMask;
@ -472,7 +474,7 @@ public:
{
}
~Tracker();
LLVM_ABI ~Tracker();
Context &getContext() const { return Ctx; }
/// \Returns true if there are no changes tracked.
bool empty() const { return Changes.empty(); }
@ -506,11 +508,11 @@ public:
/// \Returns the current state of the tracker.
TrackerState getState() const { return State; }
/// Turns on IR tracking.
void save();
LLVM_ABI void save();
/// Stops tracking and accept changes.
void accept();
LLVM_ABI void accept();
/// Stops tracking and reverts to saved state.
void revert();
LLVM_ABI void revert();
#ifndef NDEBUG
void dump(raw_ostream &OS) const;

View File

@ -16,6 +16,7 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@ -264,18 +265,18 @@ public:
/// If this is a vector type, return the element type, otherwise return
/// 'this'.
Type *getScalarType() const;
LLVM_ABI Type *getScalarType() const;
// TODO: ADD MISSING
static Type *getInt64Ty(Context &Ctx);
static Type *getInt32Ty(Context &Ctx);
static Type *getInt16Ty(Context &Ctx);
static Type *getInt8Ty(Context &Ctx);
static Type *getInt1Ty(Context &Ctx);
static Type *getDoubleTy(Context &Ctx);
static Type *getFloatTy(Context &Ctx);
static Type *getHalfTy(Context &Ctx);
LLVM_ABI static Type *getInt64Ty(Context &Ctx);
LLVM_ABI static Type *getInt32Ty(Context &Ctx);
LLVM_ABI static Type *getInt16Ty(Context &Ctx);
LLVM_ABI static Type *getInt8Ty(Context &Ctx);
LLVM_ABI static Type *getInt1Ty(Context &Ctx);
LLVM_ABI static Type *getDoubleTy(Context &Ctx);
LLVM_ABI static Type *getFloatTy(Context &Ctx);
LLVM_ABI static Type *getHalfTy(Context &Ctx);
// TODO: missing get*
/// Get the address space of this pointer or pointer vector type.
@ -293,7 +294,7 @@ class PointerType : public Type {
public:
// TODO: add missing functions
static PointerType *get(Context &Ctx, unsigned AddressSpace);
LLVM_ABI static PointerType *get(Context &Ctx, unsigned AddressSpace);
static bool classof(const Type *From) {
return isa<llvm::PointerType>(From->LLVMTy);
@ -302,7 +303,7 @@ public:
class ArrayType : public Type {
public:
static ArrayType *get(Type *ElementType, uint64_t NumElements);
LLVM_ABI static ArrayType *get(Type *ElementType, uint64_t NumElements);
// TODO: add missing functions
static bool classof(const Type *From) {
return isa<llvm::ArrayType>(From->LLVMTy);
@ -312,8 +313,8 @@ public:
class StructType : public Type {
public:
/// This static method is the primary way to create a literal StructType.
static StructType *get(Context &Ctx, ArrayRef<Type *> Elements,
bool IsPacked = false);
LLVM_ABI static StructType *get(Context &Ctx, ArrayRef<Type *> Elements,
bool IsPacked = false);
bool isPacked() const { return cast<llvm::StructType>(LLVMTy)->isPacked(); }
@ -325,13 +326,13 @@ public:
class VectorType : public Type {
public:
static VectorType *get(Type *ElementType, ElementCount EC);
LLVM_ABI static VectorType *get(Type *ElementType, ElementCount EC);
static VectorType *get(Type *ElementType, unsigned NumElements,
bool Scalable) {
return VectorType::get(ElementType,
ElementCount::get(NumElements, Scalable));
}
Type *getElementType() const;
LLVM_ABI Type *getElementType() const;
static VectorType *get(Type *ElementType, const VectorType *Other) {
return VectorType::get(ElementType, Other->getElementCount());
@ -340,13 +341,14 @@ public:
inline ElementCount getElementCount() const {
return cast<llvm::VectorType>(LLVMTy)->getElementCount();
}
static VectorType *getInteger(VectorType *VTy);
static VectorType *getExtendedElementVectorType(VectorType *VTy);
static VectorType *getTruncatedElementVectorType(VectorType *VTy);
static VectorType *getSubdividedVectorType(VectorType *VTy, int NumSubdivs);
static VectorType *getHalfElementsVectorType(VectorType *VTy);
static VectorType *getDoubleElementsVectorType(VectorType *VTy);
static bool isValidElementType(Type *ElemTy);
LLVM_ABI static VectorType *getInteger(VectorType *VTy);
LLVM_ABI static VectorType *getExtendedElementVectorType(VectorType *VTy);
LLVM_ABI static VectorType *getTruncatedElementVectorType(VectorType *VTy);
LLVM_ABI static VectorType *getSubdividedVectorType(VectorType *VTy,
int NumSubdivs);
LLVM_ABI static VectorType *getHalfElementsVectorType(VectorType *VTy);
LLVM_ABI static VectorType *getDoubleElementsVectorType(VectorType *VTy);
LLVM_ABI static bool isValidElementType(Type *ElemTy);
static bool classof(const Type *From) {
return isa<llvm::VectorType>(From->LLVMTy);
@ -355,7 +357,7 @@ public:
class FixedVectorType : public VectorType {
public:
static FixedVectorType *get(Type *ElementType, unsigned NumElts);
LLVM_ABI static FixedVectorType *get(Type *ElementType, unsigned NumElts);
static FixedVectorType *get(Type *ElementType, const FixedVectorType *FVTy) {
return get(ElementType, FVTy->getNumElements());
@ -399,7 +401,8 @@ public:
class ScalableVectorType : public VectorType {
public:
static ScalableVectorType *get(Type *ElementType, unsigned MinNumElts);
LLVM_ABI static ScalableVectorType *get(Type *ElementType,
unsigned MinNumElts);
static ScalableVectorType *get(Type *ElementType,
const ScalableVectorType *SVTy) {
@ -462,7 +465,7 @@ public:
/// Integer representation type
class IntegerType : public Type {
public:
static IntegerType *get(Context &C, unsigned NumBits);
LLVM_ABI static IntegerType *get(Context &C, unsigned NumBits);
// TODO: add missing functions
static bool classof(const Type *From) {
return isa<llvm::IntegerType>(From->LLVMTy);

View File

@ -14,6 +14,7 @@
#define LLVM_SANDBOXIR_USE_H
#include "llvm/IR/Use.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm::sandboxir {
@ -49,11 +50,11 @@ class Use {
public:
operator Value *() const { return get(); }
Value *get() const;
void set(Value *V);
LLVM_ABI Value *get() const;
LLVM_ABI void set(Value *V);
class User *getUser() const { return Usr; }
unsigned getOperandNo() const;
void swap(Use &OtherUse);
LLVM_ABI unsigned getOperandNo() const;
LLVM_ABI void swap(Use &OtherUse);
Context *getContext() const { return Ctx; }
bool operator==(const Use &Other) const {
assert(Ctx == Other.Ctx && "Contexts differ!");

View File

@ -13,6 +13,7 @@
#include "llvm/IR/Value.h"
#include "llvm/SandboxIR/Use.h"
#include "llvm/SandboxIR/Value.h"
#include "llvm/Support/Compiler.h"
namespace llvm::sandboxir {
@ -36,8 +37,8 @@ public:
using iterator_category = std::input_iterator_tag;
OperandUseIterator() = default;
value_type operator*() const;
OperandUseIterator &operator++();
LLVM_ABI value_type operator*() const;
LLVM_ABI OperandUseIterator &operator++();
OperandUseIterator operator++(int) {
auto Copy = *this;
this->operator++();
@ -49,13 +50,13 @@ public:
bool operator!=(const OperandUseIterator &Other) const {
return !(*this == Other);
}
OperandUseIterator operator+(unsigned Num) const;
OperandUseIterator operator-(unsigned Num) const;
int operator-(const OperandUseIterator &Other) const;
LLVM_ABI OperandUseIterator operator+(unsigned Num) const;
LLVM_ABI OperandUseIterator operator-(unsigned Num) const;
LLVM_ABI int operator-(const OperandUseIterator &Other) const;
};
/// A sandboxir::User has operands.
class User : public Value {
class LLVM_ABI User : public Value {
protected:
User(ClassID ID, llvm::Value *V, Context &Ctx) : Value(ID, V, Ctx) {}

View File

@ -12,6 +12,7 @@
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Value.h"
#include "llvm/SandboxIR/Use.h"
#include "llvm/Support/Compiler.h"
namespace llvm::sandboxir {
@ -50,7 +51,7 @@ public:
UserUseIterator() = default;
value_type operator*() const { return Use; }
UserUseIterator &operator++();
LLVM_ABI UserUseIterator &operator++();
bool operator==(const UserUseIterator &Other) const {
return Use == Other.Use;
}
@ -179,7 +180,7 @@ protected:
void clearValue() { Val = nullptr; }
template <typename ItTy, typename SBTy> friend class LLVMOpUserItToSBTy;
Value(ClassID SubclassID, llvm::Value *Val, Context &Ctx);
LLVM_ABI Value(ClassID SubclassID, llvm::Value *Val, Context &Ctx);
/// Disable copies.
Value(const Value &) = delete;
Value &operator=(const Value &) = delete;
@ -191,7 +192,7 @@ public:
using use_iterator = UserUseIterator;
using const_use_iterator = UserUseIterator;
use_iterator use_begin();
LLVM_ABI use_iterator use_begin();
const_use_iterator use_begin() const {
return const_cast<Value *>(this)->use_begin();
}
@ -215,7 +216,7 @@ public:
using user_iterator = mapped_iterator<sandboxir::UserUseIterator, UseToUser>;
using const_user_iterator = user_iterator;
user_iterator user_begin();
LLVM_ABI user_iterator user_begin();
user_iterator user_end() {
return user_iterator(Use(nullptr, nullptr, Ctx), UseToUser());
}
@ -234,7 +235,7 @@ public:
}
/// \Returns the number of user edges (not necessarily to unique users).
/// WARNING: This is a linear-time operation.
unsigned getNumUses() const;
LLVM_ABI unsigned getNumUses() const;
/// Return true if this value has N uses or more.
/// This is logically equivalent to getNumUses() >= N.
/// WARNING: This can be expensive, as it is linear to the number of users.
@ -256,13 +257,14 @@ public:
return Cnt == Num;
}
Type *getType() const;
LLVM_ABI Type *getType() const;
Context &getContext() const { return Ctx; }
void replaceUsesWithIf(Value *OtherV,
llvm::function_ref<bool(const Use &)> ShouldReplace);
void replaceAllUsesWith(Value *Other);
LLVM_ABI void
replaceUsesWithIf(Value *OtherV,
llvm::function_ref<bool(const Use &)> ShouldReplace);
LLVM_ABI void replaceAllUsesWith(Value *Other);
/// \Returns the LLVM IR name of the bottom-most LLVM value.
StringRef getName() const { return Val->getName(); }

View File

@ -305,35 +305,14 @@ GlobalT &GlobalWithNodeAPI<GlobalT, LLVMGlobalT, ParentT, LLVMParentT>::
}
// Explicit instantiations.
template class GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
llvm::GlobalObject>;
template class GlobalWithNodeAPI<Function, llvm::Function, GlobalObject,
llvm::GlobalObject>;
template class GlobalWithNodeAPI<GlobalVariable, llvm::GlobalVariable,
GlobalObject, llvm::GlobalObject>;
template class GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
llvm::GlobalValue>;
#if defined(_MSC_VER) && !defined(__clang__)
// These are needed for SandboxIRTest when building with LLVM_BUILD_LLVM_DYLIB
template LLVM_EXPORT_TEMPLATE GlobalIFunc &
GlobalWithNodeAPI<GlobalIFunc, llvm::GlobalIFunc, GlobalObject,
llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalIFunc
&LLVMGV)
const;
template LLVM_EXPORT_TEMPLATE Function &
GlobalWithNodeAPI<Function, llvm::Function, GlobalObject, llvm::GlobalObject>::
LLVMGVToGV::operator()(llvm::Function &LLVMGV) const;
template LLVM_EXPORT_TEMPLATE GlobalVariable &GlobalWithNodeAPI<
GlobalVariable, llvm::GlobalVariable, GlobalObject,
llvm::GlobalObject>::LLVMGVToGV::operator()(llvm::GlobalVariable &LLVMGV)
const;
template LLVM_EXPORT_TEMPLATE GlobalAlias &
GlobalWithNodeAPI<GlobalAlias, llvm::GlobalAlias, GlobalValue,
llvm::GlobalValue>::LLVMGVToGV::operator()(llvm::GlobalAlias
&LLVMGV) const;
#endif
template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
GlobalIFunc, llvm::GlobalIFunc, GlobalObject, llvm::GlobalObject>;
template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
Function, llvm::Function, GlobalObject, llvm::GlobalObject>;
template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
GlobalVariable, llvm::GlobalVariable, GlobalObject, llvm::GlobalObject>;
template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
GlobalAlias, llvm::GlobalAlias, GlobalValue, llvm::GlobalValue>;
void GlobalIFunc::setResolver(Constant *Resolver) {
Ctx.getTracker()