Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/MetadataTracking.h | //===- llvm/IR/MetadataTracking.h - Metadata tracking ---------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Low-level functions to enable tracking of metadata that could RAUW.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_METADATATRACKING_H
#define LLVM_IR_METADATATRACKING_H
#include "llvm/ADT/PointerUnion.h"
#include "llvm/Support/Casting.h"
#include <type_traits>
namespace llvm {
class Metadata;
class MetadataAsValue;
/// \brief API for tracking metadata references through RAUW and deletion.
///
/// Shared API for updating \a Metadata pointers in subclasses that support
/// RAUW.
///
/// This API is not meant to be used directly. See \a TrackingMDRef for a
/// user-friendly tracking reference.
class MetadataTracking {
public:
/// \brief Track the reference to metadata.
///
/// Register \c MD with \c *MD, if the subclass supports tracking. If \c *MD
/// gets RAUW'ed, \c MD will be updated to the new address. If \c *MD gets
/// deleted, \c MD will be set to \c nullptr.
///
/// If tracking isn't supported, \c *MD will not change.
///
/// \return true iff tracking is supported by \c MD.
static bool track(Metadata *&MD) {
return track(&MD, *MD, static_cast<Metadata *>(nullptr));
}
/// \brief Track the reference to metadata for \a Metadata.
///
/// As \a track(Metadata*&), but with support for calling back to \c Owner to
/// tell it that its operand changed. This could trigger \c Owner being
/// re-uniqued.
static bool track(void *Ref, Metadata &MD, Metadata &Owner) {
return track(Ref, MD, &Owner);
}
/// \brief Track the reference to metadata for \a MetadataAsValue.
///
/// As \a track(Metadata*&), but with support for calling back to \c Owner to
/// tell it that its operand changed. This could trigger \c Owner being
/// re-uniqued.
static bool track(void *Ref, Metadata &MD, MetadataAsValue &Owner) {
return track(Ref, MD, &Owner);
}
/// \brief Stop tracking a reference to metadata.
///
/// Stops \c *MD from tracking \c MD.
static void untrack(Metadata *&MD) { untrack(&MD, *MD); }
static void untrack(void *Ref, Metadata &MD);
/// \brief Move tracking from one reference to another.
///
/// Semantically equivalent to \c untrack(MD) followed by \c track(New),
/// except that ownership callbacks are maintained.
///
/// Note: it is an error if \c *MD does not equal \c New.
///
/// \return true iff tracking is supported by \c MD.
static bool retrack(Metadata *&MD, Metadata *&New) {
return retrack(&MD, *MD, &New);
}
static bool retrack(void *Ref, Metadata &MD, void *New);
/// \brief Check whether metadata is replaceable.
static bool isReplaceable(const Metadata &MD);
typedef PointerUnion<MetadataAsValue *, Metadata *> OwnerTy;
private:
/// \brief Track a reference to metadata for an owner.
///
/// Generalized version of tracking.
static bool track(void *Ref, Metadata &MD, OwnerTy Owner);
};
} // end namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/Constant.h | //===-- llvm/Constant.h - Constant class definition -------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the declaration of the Constant class.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_CONSTANT_H
#define LLVM_IR_CONSTANT_H
#include "llvm/IR/User.h"
namespace llvm {
class APInt;
template<typename T> class SmallVectorImpl;
/// This is an important base class in LLVM. It provides the common facilities
/// of all constant values in an LLVM program. A constant is a value that is
/// immutable at runtime. Functions are constants because their address is
/// immutable. Same with global variables.
///
/// All constants share the capabilities provided in this class. All constants
/// can have a null value. They can have an operand list. Constants can be
/// simple (integer and floating point values), complex (arrays and structures),
/// or expression based (computations yielding a constant value composed of
/// only certain operators and other constant values).
///
/// Note that Constants are immutable (once created they never change)
/// and are fully shared by structural equivalence. This means that two
/// structurally equivalent constants will always have the same address.
/// Constants are created on demand as needed and never deleted: thus clients
/// don't have to worry about the lifetime of the objects.
/// @brief LLVM Constant Representation
class Constant : public User {
void operator=(const Constant &) = delete;
Constant(const Constant &) = delete;
void anchor() override;
protected:
Constant(Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
: User(ty, vty, Ops, NumOps) {}
public:
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue.
bool isNullValue() const;
/// \brief Returns true if the value is one.
bool isOneValue() const;
/// isAllOnesValue - Return true if this is the value that would be returned by
/// getAllOnesValue.
bool isAllOnesValue() const;
/// isNegativeZeroValue - Return true if the value is what would be returned
/// by getZeroValueForNegation.
bool isNegativeZeroValue() const;
/// Return true if the value is negative zero or null value.
bool isZeroValue() const;
/// \brief Return true if the value is not the smallest signed value.
bool isNotMinSignedValue() const;
/// \brief Return true if the value is the smallest signed value.
bool isMinSignedValue() const;
/// canTrap - Return true if evaluation of this constant could trap. This is
/// true for things like constant expressions that could divide by zero.
bool canTrap() const;
/// isThreadDependent - Return true if the value can vary between threads.
bool isThreadDependent() const;
/// Return true if the value is dependent on a dllimport variable.
bool isDLLImportDependent() const;
/// isConstantUsed - Return true if the constant has users other than constant
/// exprs and other dangling things.
bool isConstantUsed() const;
enum PossibleRelocationsTy {
NoRelocation = 0,
LocalRelocation = 1,
GlobalRelocations = 2
};
/// getRelocationInfo - This method classifies the entry according to
/// whether or not it may generate a relocation entry. This must be
/// conservative, so if it might codegen to a relocatable entry, it should say
/// so. The return values are:
///
/// NoRelocation: This constant pool entry is guaranteed to never have a
/// relocation applied to it (because it holds a simple constant like
/// '4').
/// LocalRelocation: This entry has relocations, but the entries are
/// guaranteed to be resolvable by the static linker, so the dynamic
/// linker will never see them.
/// GlobalRelocations: This entry may have arbitrary relocations.
///
/// FIXME: This really should not be in VMCore.
PossibleRelocationsTy getRelocationInfo() const;
/// getAggregateElement - For aggregates (struct/array/vector) return the
/// constant that corresponds to the specified element if possible, or null if
/// not. This can return null if the element index is a ConstantExpr, or if
/// 'this' is a constant expr.
Constant *getAggregateElement(unsigned Elt) const;
Constant *getAggregateElement(Constant *Elt) const;
/// getSplatValue - If this is a splat vector constant, meaning that all of
/// the elements have the same value, return that value. Otherwise return 0.
Constant *getSplatValue() const;
/// If C is a constant integer then return its value, otherwise C must be a
/// vector of constant integers, all equal, and the common value is returned.
const APInt &getUniqueInteger() const;
/// Called if some element of this constant is no longer valid.
/// At this point only other constants may be on the use_list for this
/// constant. Any constants on our Use list must also be destroy'd. The
/// implementation must be sure to remove the constant from the list of
/// available cached constants. Implementations should implement
/// destroyConstantImpl to remove constants from any pools/maps they are
/// contained it.
void destroyConstant();
//// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Value *V) {
return V->getValueID() >= ConstantFirstVal &&
V->getValueID() <= ConstantLastVal;
}
/// This method is a special form of User::replaceUsesOfWith
/// (which does not work on constants) that does work
/// on constants. Basically this method goes through the trouble of building
/// a new constant that is equivalent to the current one, with all uses of
/// From replaced with uses of To. After this construction is completed, all
/// of the users of 'this' are replaced to use the new constant, and then
/// 'this' is deleted. In general, you should not call this method, instead,
/// use Value::replaceAllUsesWith, which automatically dispatches to this
/// method as needed.
///
void handleOperandChange(Value *, Value *, Use *);
static Constant *getNullValue(Type* Ty);
/// @returns the value for an integer or vector of integer constant of the
/// given type that has all its bits set to true.
/// @brief Get the all ones value
static Constant *getAllOnesValue(Type* Ty);
/// getIntegerValue - Return the value for an integer or pointer constant,
/// or a vector thereof, with the given scalar value.
static Constant *getIntegerValue(Type* Ty, const APInt &V);
/// removeDeadConstantUsers - If there are any dead constant users dangling
/// off of this constant, remove them. This method is useful for clients
/// that want to check to see if a global is unused, but don't want to deal
/// with potentially dead constants hanging off of the globals.
void removeDeadConstantUsers() const;
Constant *stripPointerCasts() {
return cast<Constant>(Value::stripPointerCasts());
}
const Constant *stripPointerCasts() const {
return const_cast<Constant*>(this)->stripPointerCasts();
}
};
} // End llvm namespace
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/Instruction.def | //===-- llvm/Instruction.def - File that describes Instructions -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains descriptions of the various LLVM instructions. This is
// used as a central place for enumerating the different instructions and
// should eventually be the place to put comments about the instructions.
//
//===----------------------------------------------------------------------===//
// Provide definitions of macros so that users of this file do not have to
// define everything to use it...
//
#ifndef FIRST_TERM_INST
#define FIRST_TERM_INST(num)
#endif
#ifndef HANDLE_TERM_INST
#ifndef HANDLE_INST
#define HANDLE_TERM_INST(num, opcode, Class)
#else
#define HANDLE_TERM_INST(num, opcode, Class) HANDLE_INST(num, opcode, Class)
#endif
#endif
#ifndef LAST_TERM_INST
#define LAST_TERM_INST(num)
#endif
#ifndef FIRST_BINARY_INST
#define FIRST_BINARY_INST(num)
#endif
#ifndef HANDLE_BINARY_INST
#ifndef HANDLE_INST
#define HANDLE_BINARY_INST(num, opcode, instclass)
#else
#define HANDLE_BINARY_INST(num, opcode, Class) HANDLE_INST(num, opcode, Class)
#endif
#endif
#ifndef LAST_BINARY_INST
#define LAST_BINARY_INST(num)
#endif
#ifndef FIRST_MEMORY_INST
#define FIRST_MEMORY_INST(num)
#endif
#ifndef HANDLE_MEMORY_INST
#ifndef HANDLE_INST
#define HANDLE_MEMORY_INST(num, opcode, Class)
#else
#define HANDLE_MEMORY_INST(num, opcode, Class) HANDLE_INST(num, opcode, Class)
#endif
#endif
#ifndef LAST_MEMORY_INST
#define LAST_MEMORY_INST(num)
#endif
#ifndef FIRST_CAST_INST
#define FIRST_CAST_INST(num)
#endif
#ifndef HANDLE_CAST_INST
#ifndef HANDLE_INST
#define HANDLE_CAST_INST(num, opcode, Class)
#else
#define HANDLE_CAST_INST(num, opcode, Class) HANDLE_INST(num, opcode, Class)
#endif
#endif
#ifndef LAST_CAST_INST
#define LAST_CAST_INST(num)
#endif
#ifndef FIRST_OTHER_INST
#define FIRST_OTHER_INST(num)
#endif
#ifndef HANDLE_OTHER_INST
#ifndef HANDLE_INST
#define HANDLE_OTHER_INST(num, opcode, Class)
#else
#define HANDLE_OTHER_INST(num, opcode, Class) HANDLE_INST(num, opcode, Class)
#endif
#endif
#ifndef LAST_OTHER_INST
#define LAST_OTHER_INST(num)
#endif
// Terminator Instructions - These instructions are used to terminate a basic
// block of the program. Every basic block must end with one of these
// instructions for it to be a well formed basic block.
//
FIRST_TERM_INST ( 1)
HANDLE_TERM_INST ( 1, Ret , ReturnInst)
HANDLE_TERM_INST ( 2, Br , BranchInst)
HANDLE_TERM_INST ( 3, Switch , SwitchInst)
HANDLE_TERM_INST ( 4, IndirectBr , IndirectBrInst)
HANDLE_TERM_INST ( 5, Invoke , InvokeInst)
HANDLE_TERM_INST ( 6, Resume , ResumeInst)
HANDLE_TERM_INST ( 7, Unreachable, UnreachableInst)
LAST_TERM_INST ( 7)
// Standard binary operators...
FIRST_BINARY_INST( 8)
HANDLE_BINARY_INST( 8, Add , BinaryOperator)
HANDLE_BINARY_INST( 9, FAdd , BinaryOperator)
HANDLE_BINARY_INST(10, Sub , BinaryOperator)
HANDLE_BINARY_INST(11, FSub , BinaryOperator)
HANDLE_BINARY_INST(12, Mul , BinaryOperator)
HANDLE_BINARY_INST(13, FMul , BinaryOperator)
HANDLE_BINARY_INST(14, UDiv , BinaryOperator)
HANDLE_BINARY_INST(15, SDiv , BinaryOperator)
HANDLE_BINARY_INST(16, FDiv , BinaryOperator)
HANDLE_BINARY_INST(17, URem , BinaryOperator)
HANDLE_BINARY_INST(18, SRem , BinaryOperator)
HANDLE_BINARY_INST(19, FRem , BinaryOperator)
// Logical operators (integer operands)
HANDLE_BINARY_INST(20, Shl , BinaryOperator) // Shift left (logical)
HANDLE_BINARY_INST(21, LShr , BinaryOperator) // Shift right (logical)
HANDLE_BINARY_INST(22, AShr , BinaryOperator) // Shift right (arithmetic)
HANDLE_BINARY_INST(23, And , BinaryOperator)
HANDLE_BINARY_INST(24, Or , BinaryOperator)
HANDLE_BINARY_INST(25, Xor , BinaryOperator)
LAST_BINARY_INST(25)
// Memory operators...
FIRST_MEMORY_INST(26)
HANDLE_MEMORY_INST(26, Alloca, AllocaInst) // Stack management
HANDLE_MEMORY_INST(27, Load , LoadInst ) // Memory manipulation instrs
HANDLE_MEMORY_INST(28, Store , StoreInst )
HANDLE_MEMORY_INST(29, GetElementPtr, GetElementPtrInst)
HANDLE_MEMORY_INST(30, Fence , FenceInst )
HANDLE_MEMORY_INST(31, AtomicCmpXchg , AtomicCmpXchgInst )
HANDLE_MEMORY_INST(32, AtomicRMW , AtomicRMWInst )
LAST_MEMORY_INST(32)
// Cast operators ...
// NOTE: The order matters here because CastInst::isEliminableCastPair
// NOTE: (see Instructions.cpp) encodes a table based on this ordering.
FIRST_CAST_INST(33)
HANDLE_CAST_INST(33, Trunc , TruncInst ) // Truncate integers
HANDLE_CAST_INST(34, ZExt , ZExtInst ) // Zero extend integers
HANDLE_CAST_INST(35, SExt , SExtInst ) // Sign extend integers
HANDLE_CAST_INST(36, FPToUI , FPToUIInst ) // floating point -> UInt
HANDLE_CAST_INST(37, FPToSI , FPToSIInst ) // floating point -> SInt
HANDLE_CAST_INST(38, UIToFP , UIToFPInst ) // UInt -> floating point
HANDLE_CAST_INST(39, SIToFP , SIToFPInst ) // SInt -> floating point
HANDLE_CAST_INST(40, FPTrunc , FPTruncInst ) // Truncate floating point
HANDLE_CAST_INST(41, FPExt , FPExtInst ) // Extend floating point
HANDLE_CAST_INST(42, PtrToInt, PtrToIntInst) // Pointer -> Integer
HANDLE_CAST_INST(43, IntToPtr, IntToPtrInst) // Integer -> Pointer
HANDLE_CAST_INST(44, BitCast , BitCastInst ) // Type cast
HANDLE_CAST_INST(45, AddrSpaceCast, AddrSpaceCastInst) // addrspace cast
LAST_CAST_INST(45)
// Other operators...
FIRST_OTHER_INST(46)
HANDLE_OTHER_INST(46, ICmp , ICmpInst ) // Integer comparison instruction
HANDLE_OTHER_INST(47, FCmp , FCmpInst ) // Floating point comparison instr.
HANDLE_OTHER_INST(48, PHI , PHINode ) // PHI node instruction
HANDLE_OTHER_INST(49, Call , CallInst ) // Call a function
HANDLE_OTHER_INST(50, Select , SelectInst ) // select instruction
HANDLE_OTHER_INST(51, UserOp1, Instruction) // May be used internally in a pass
HANDLE_OTHER_INST(52, UserOp2, Instruction) // Internal to passes only
HANDLE_OTHER_INST(53, VAArg , VAArgInst ) // vaarg instruction
HANDLE_OTHER_INST(54, ExtractElement, ExtractElementInst)// extract from vector
HANDLE_OTHER_INST(55, InsertElement, InsertElementInst) // insert into vector
HANDLE_OTHER_INST(56, ShuffleVector, ShuffleVectorInst) // shuffle two vectors.
HANDLE_OTHER_INST(57, ExtractValue, ExtractValueInst)// extract from aggregate
HANDLE_OTHER_INST(58, InsertValue, InsertValueInst) // insert into aggregate
HANDLE_OTHER_INST(59, LandingPad, LandingPadInst) // Landing pad instruction.
LAST_OTHER_INST(59)
#undef FIRST_TERM_INST
#undef HANDLE_TERM_INST
#undef LAST_TERM_INST
#undef FIRST_BINARY_INST
#undef HANDLE_BINARY_INST
#undef LAST_BINARY_INST
#undef FIRST_MEMORY_INST
#undef HANDLE_MEMORY_INST
#undef LAST_MEMORY_INST
#undef FIRST_CAST_INST
#undef HANDLE_CAST_INST
#undef LAST_CAST_INST
#undef FIRST_OTHER_INST
#undef HANDLE_OTHER_INST
#undef LAST_OTHER_INST
#ifdef HANDLE_INST
#undef HANDLE_INST
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/LegacyPassManager.h | //===- LegacyPassManager.h - Legacy Container for Passes --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the legacy PassManager class. This class is used to hold,
// maintain, and optimize execution of Passes. The PassManager class ensures
// that analysis results are available before a pass runs, and that Pass's are
// destroyed when the PassManager is destroyed.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_LEGACYPASSMANAGER_H
#define LLVM_IR_LEGACYPASSMANAGER_H
#include "llvm/Pass.h"
#include "llvm/Support/CBindingWrapping.h"
#include <set> // HLSL change
namespace llvm {
class Pass;
class Module;
namespace legacy {
class PassManagerImpl;
class FunctionPassManagerImpl;
/// PassManagerBase - An abstract interface to allow code to add passes to
/// a pass manager without having to hard-code what kind of pass manager
/// it is.
class PassManagerBase {
public:
bool HLSLPrintBeforeAll = false; // HLSL Change
std::set<std::string> HLSLPrintBefore; // HLSL Change
bool HLSLPrintAfterAll = false; // HLSL Change
std::set<std::string> HLSLPrintAfter; // HLSL Change
virtual ~PassManagerBase();
/// Add a pass to the queue of passes to run. This passes ownership of
/// the Pass to the PassManager. When the PassManager is destroyed, the pass
/// will be destroyed as well, so there is no need to delete the pass. This
/// may even destroy the pass right away if it is found to be redundant. This
/// implies that all passes MUST be allocated with 'new'.
virtual void add(Pass *P) = 0;
raw_ostream *TrackPassOS = nullptr; // HLSL Change - add this field
};
/// PassManager manages ModulePassManagers
class PassManager : public PassManagerBase {
public:
PassManager();
~PassManager() override;
void add(Pass *P) override;
/// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the module, and if so, return true.
bool run(Module &M);
private:
/// PassManagerImpl_New is the actual class. PassManager is just the
/// wraper to publish simple pass manager interface
PassManagerImpl *PM;
};
/// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
class FunctionPassManager : public PassManagerBase {
public:
/// FunctionPassManager ctor - This initializes the pass manager. It needs,
/// but does not take ownership of, the specified Module.
explicit FunctionPassManager(Module *M);
~FunctionPassManager() override;
void add(Pass *P) override;
/// run - Execute all of the passes scheduled for execution. Keep
/// track of whether any of the passes modifies the function, and if
/// so, return true.
///
bool run(Function &F);
/// doInitialization - Run all of the initializers for the function passes.
///
bool doInitialization();
/// doFinalization - Run all of the finalizers for the function passes.
///
bool doFinalization();
private:
FunctionPassManagerImpl *FPM;
Module *M;
};
} // End legacy namespace
// Create wrappers for C Binding types (see CBindingWrapping.h).
DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef)
} // End llvm namespace
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/Constants.h | //===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
/// @file
/// This file contains the declarations for the subclasses of Constant,
/// which represent the different flavors of constant values that live in LLVM.
/// Note that Constants are immutable (once created they never change) and are
/// fully shared by structural equivalence. This means that two structurally
/// equivalent constants will always have the same address. Constants are
/// created on demand as needed and never deleted: thus clients don't have to
/// worry about the lifetime of the objects.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_CONSTANTS_H
#define LLVM_IR_CONSTANTS_H
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/OperandTraits.h"
namespace llvm {
class ArrayType;
class IntegerType;
class StructType;
class PointerType;
class VectorType;
class SequentialType;
struct ConstantExprKeyType;
template <class ConstantClass> struct ConstantAggrKeyType;
//===----------------------------------------------------------------------===//
/// This is the shared class of boolean and integer constants. This class
/// represents both boolean and integral constants.
/// @brief Class for constant integers.
class ConstantInt : public Constant {
void anchor() override;
void *operator new(size_t, unsigned) = delete;
ConstantInt(const ConstantInt &) = delete;
ConstantInt(IntegerType *Ty, const APInt& V);
APInt Val;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public:
static ConstantInt *getTrue(LLVMContext &Context);
static ConstantInt *getFalse(LLVMContext &Context);
static Constant *getTrue(Type *Ty);
static Constant *getFalse(Type *Ty);
/// 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, 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
/// to fit the type, unless isSigned is true, in which case the value will
/// be interpreted as a 64-bit signed integer and sign-extended to fit
/// the type.
/// @brief Get a ConstantInt for a specific value.
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.
/// @brief Get a ConstantInt for a specific signed value.
static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
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(LLVMContext &Context, 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);
/// 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);
/// Return the constant as an APInt value reference. This allows clients to
/// obtain a copy of the value, with all its precision in tact.
/// @brief Return the constant's value.
inline const APInt &getValue() const {
return Val;
}
/// getBitWidth - Return the bitwidth of this constant.
unsigned getBitWidth() const { return Val.getBitWidth(); }
/// Return the constant as a 64-bit unsigned integer value after it
/// has been zero extended as appropriate for the type of this constant. Note
/// that this method can assert if the value does not fit in 64 bits.
/// @brief Return the zero extended value.
inline uint64_t getZExtValue() const {
return Val.getZExtValue();
}
/// Return the constant as a 64-bit integer value after it has been sign
/// extended as appropriate for the type of this constant. Note that
/// this method can assert if the value does not fit in 64 bits.
/// @brief Return the sign extended value.
inline int64_t getSExtValue() const {
return Val.getSExtValue();
}
/// A helper method that can be used to determine if the constant contained
/// within is equal to a constant. This only works for very small values,
/// because this is all that can be represented with all types.
/// @brief Determine if this constant's value is same as an unsigned char.
bool equalsInt(uint64_t V) const {
return Val == V;
}
/// getType - Specialize the getType() method to always return an IntegerType,
/// which reduces the amount of casting needed in parts of the compiler.
///
inline IntegerType *getType() const {
return cast<IntegerType>(Value::getType());
}
/// 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
/// assert when V is larger than Ty can represent. Note that there are two
/// versions of this method, one for unsigned and one for signed integers.
/// Although ConstantInt canonicalizes everything to an unsigned integer,
/// the signed version avoids callers having to convert a signed quantity
/// to the appropriate unsigned type before calling the method.
/// @returns true if V is a valid value for type Ty
/// @brief 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);
bool isNegative() const { return Val.isNegative(); }
/// This is just a convenience method to make client code smaller for a
/// common code. It also correctly performs the comparison without the
/// potential for an assertion from getZExtValue().
bool isZero() const {
return Val == 0;
}
/// This is just a convenience method to make client code smaller for a
/// common case. It also correctly performs the comparison without the
/// potential for an assertion from getZExtValue().
/// @brief Determine if the value is one.
bool isOne() const {
return Val == 1;
}
/// This function will return true iff every bit in this constant is set
/// to true.
/// @returns true iff this constant's bits are all set to true.
/// @brief Determine if the value is all ones.
bool isMinusOne() const {
return Val.isAllOnesValue();
}
/// This function will return true iff this constant represents the largest
/// value that may be represented by the constant's type.
/// @returns true iff this is the largest value that may be represented
/// by this type.
/// @brief Determine if the value is maximal.
bool isMaxValue(bool isSigned) const {
if (isSigned)
return Val.isMaxSignedValue();
else
return Val.isMaxValue();
}
/// This function will return true iff this constant represents the smallest
/// value that may be represented by this constant's type.
/// @returns true if this is the smallest value that may be represented by
/// this type.
/// @brief Determine if the value is minimal.
bool isMinValue(bool isSigned) const {
if (isSigned)
return Val.isMinSignedValue();
else
return Val.isMinValue();
}
/// This function will return true iff this constant represents a value with
/// active bits bigger than 64 bits or a value greater than the given uint64_t
/// value.
/// @returns true iff this constant is greater or equal to the given number.
/// @brief Determine if the value is greater or equal to the given number.
bool uge(uint64_t Num) const {
return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
}
/// getLimitedValue - If the value is smaller than the specified limit,
/// return it, otherwise return the limit value. This causes the value
/// to saturate to the limit.
/// @returns the min of the value of the constant and the specified value
/// @brief Get the constant's value with a saturation limit
uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
return Val.getLimitedValue(Limit);
}
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
static bool classof(const Value *V) {
return V->getValueID() == ConstantIntVal;
}
};
//===----------------------------------------------------------------------===//
/// ConstantFP - Floating Point Values [float, double]
///
class ConstantFP : public Constant {
APFloat Val;
void anchor() override;
void *operator new(size_t, unsigned) = delete;
ConstantFP(const ConstantFP &) = delete;
friend class LLVMContextImpl;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
ConstantFP(Type *Ty, const APFloat& V);
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public:
/// Floating point negation must be implemented with f(x) = -0.0 - x. This
/// method returns the negative zero constant for floating point or vector
/// floating point types; for all other types, it returns the null value.
static Constant *getZeroValueForNegation(Type *Ty);
/// get() - This returns a ConstantFP, or a vector containing a splat of a
/// ConstantFP, 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);
static Constant *get(Type* Ty, StringRef Str);
static ConstantFP *get(LLVMContext &Context, const APFloat &V);
static Constant *getNaN(Type *Ty, bool Negative = false, unsigned type = 0);
static Constant *getNegativeZero(Type *Ty);
static Constant *getInfinity(Type *Ty, bool Negative = false);
/// isValueValidForType - return true if Ty is big enough to represent V.
static bool isValueValidForType(Type *Ty, const APFloat &V);
inline const APFloat &getValueAPF() const { return Val; }
/// isZero - Return true if the value is positive or negative zero.
bool isZero() const { return Val.isZero(); }
/// isNegative - Return true if the sign bit is set.
bool isNegative() const { return Val.isNegative(); }
/// isInfinity - Return true if the value is infinity
bool isInfinity() const { return Val.isInfinity(); }
/// isNaN - Return true if the value is a NaN.
bool isNaN() const { return Val.isNaN(); }
/// isExactlyValue - We don't rely on operator== working on double values, as
/// it returns true for things that are clearly not equal, like -0.0 and 0.0.
/// As such, this method can be used to do an exact bit-for-bit comparison of
/// two floating point values. The version with a double operand is retained
/// because it's so convenient to write isExactlyValue(2.0), but please use
/// it only for simple constants.
bool isExactlyValue(const APFloat &V) const;
bool isExactlyValue(double V) const {
bool ignored;
APFloat FV(V);
FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
return isExactlyValue(FV);
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
return V->getValueID() == ConstantFPVal;
}
};
//===----------------------------------------------------------------------===//
/// ConstantAggregateZero - All zero aggregate value
///
class ConstantAggregateZero : public Constant {
void *operator new(size_t, unsigned) = delete;
ConstantAggregateZero(const ConstantAggregateZero &) = delete;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
explicit ConstantAggregateZero(Type *ty)
: Constant(ty, ConstantAggregateZeroVal, nullptr, 0) {}
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public:
static ConstantAggregateZero *get(Type *Ty);
/// getSequentialElement - If this CAZ has array or vector type, return a zero
/// with the right element type.
Constant *getSequentialElement() const;
/// getStructElement - If this CAZ has struct type, return a zero with the
/// right element type for the specified element.
Constant *getStructElement(unsigned Elt) const;
/// getElementValue - Return a zero of the right value for the specified GEP
/// index.
Constant *getElementValue(Constant *C) const;
/// getElementValue - Return a zero of the right value for the specified GEP
/// index.
Constant *getElementValue(unsigned Idx) const;
/// \brief Return the number of elements in the array, vector, or struct.
unsigned getNumElements() const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
///
static bool classof(const Value *V) {
return V->getValueID() == ConstantAggregateZeroVal;
}
};
//===----------------------------------------------------------------------===//
/// ConstantArray - Constant Array Declarations
///
class ConstantArray : public Constant {
friend struct ConstantAggrKeyType<ConstantArray>;
ConstantArray(const ConstantArray &) = delete;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
ConstantArray(ArrayType *T, ArrayRef<Constant *> Val);
public:
// ConstantArray accessors
static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
private:
static Constant *getImpl(ArrayType *T, ArrayRef<Constant *> V);
public:
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
/// getType - Specialize the getType() method to always return an ArrayType,
/// which reduces the amount of casting needed in parts of the compiler.
///
inline ArrayType *getType() const {
return cast<ArrayType>(Value::getType());
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
return V->getValueID() == ConstantArrayVal;
}
};
template <>
struct OperandTraits<ConstantArray> :
public VariadicOperandTraits<ConstantArray> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Constant)
//===----------------------------------------------------------------------===//
// ConstantStruct - Constant Struct Declarations
//
class ConstantStruct : public Constant {
friend struct ConstantAggrKeyType<ConstantStruct>;
ConstantStruct(const ConstantStruct &) = delete;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
ConstantStruct(StructType *T, ArrayRef<Constant *> Val);
public:
// ConstantStruct accessors
static Constant *get(StructType *T, ArrayRef<Constant*> V);
static Constant *get(StructType *T, ...) LLVM_END_WITH_NULL;
/// getAnon - Return an anonymous struct that has the specified
/// elements. If the struct is possibly empty, then you must specify a
/// context.
static Constant *getAnon(ArrayRef<Constant*> V, bool Packed = false) {
return get(getTypeForElements(V, Packed), V);
}
static Constant *getAnon(LLVMContext &Ctx,
ArrayRef<Constant*> V, bool Packed = false) {
return get(getTypeForElements(Ctx, V, Packed), V);
}
/// getTypeForElements - 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,
bool Packed = false);
/// getTypeForElements - This version of the method allows an empty list.
static StructType *getTypeForElements(LLVMContext &Ctx,
ArrayRef<Constant*> V,
bool Packed = false);
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
/// getType() specialization - Reduce amount of casting...
///
inline StructType *getType() const {
return cast<StructType>(Value::getType());
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
return V->getValueID() == ConstantStructVal;
}
};
template <>
struct OperandTraits<ConstantStruct> :
public VariadicOperandTraits<ConstantStruct> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Constant)
//===----------------------------------------------------------------------===//
/// ConstantVector - Constant Vector Declarations
///
class ConstantVector : public Constant {
friend struct ConstantAggrKeyType<ConstantVector>;
ConstantVector(const ConstantVector &) = delete;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
ConstantVector(VectorType *T, ArrayRef<Constant *> Val);
public:
// ConstantVector accessors
static Constant *get(ArrayRef<Constant*> V);
private:
static Constant *getImpl(ArrayRef<Constant *> V);
public:
/// getSplat - Return a ConstantVector with the specified constant in each
/// element.
static Constant *getSplat(unsigned NumElts, Constant *Elt);
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
/// getType - Specialize the getType() method to always return a VectorType,
/// which reduces the amount of casting needed in parts of the compiler.
///
inline VectorType *getType() const {
return cast<VectorType>(Value::getType());
}
/// getSplatValue - If this is a splat constant, meaning that all of the
/// elements have the same value, return that value. Otherwise return NULL.
Constant *getSplatValue() const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
return V->getValueID() == ConstantVectorVal;
}
};
template <>
struct OperandTraits<ConstantVector> :
public VariadicOperandTraits<ConstantVector> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Constant)
//===----------------------------------------------------------------------===//
/// ConstantPointerNull - a constant pointer value that points to null
///
class ConstantPointerNull : public Constant {
void *operator new(size_t, unsigned) = delete;
ConstantPointerNull(const ConstantPointerNull &) = delete;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
explicit ConstantPointerNull(PointerType *T)
: Constant(T,
Value::ConstantPointerNullVal, nullptr, 0) {}
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public:
/// get() - Static factory methods - Return objects of the specified value
static ConstantPointerNull *get(PointerType *T);
/// getType - Specialize the getType() method to always return an PointerType,
/// which reduces the amount of casting needed in parts of the compiler.
///
inline PointerType *getType() const {
return cast<PointerType>(Value::getType());
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
return V->getValueID() == ConstantPointerNullVal;
}
};
//===----------------------------------------------------------------------===//
/// ConstantDataSequential - A vector or array constant whose element type is a
/// simple 1/2/4/8-byte integer or float/double, and whose elements are just
/// simple data values (i.e. ConstantInt/ConstantFP). This Constant node has no
/// operands because it stores all of the elements of the constant as densely
/// packed data, instead of as Value*'s.
///
/// This is the common base class of ConstantDataArray and ConstantDataVector.
///
class ConstantDataSequential : public Constant {
friend class LLVMContextImpl;
/// DataElements - A pointer to the bytes underlying this constant (which is
/// owned by the uniquing StringMap).
const char *DataElements;
/// Next - This forms a link list of ConstantDataSequential nodes that have
/// the same value but different type. For example, 0,0,0,1 could be a 4
/// element array of i8, or a 1-element array of i32. They'll both end up in
/// the same StringMap bucket, linked up.
ConstantDataSequential *Next;
void *operator new(size_t, unsigned) = delete;
ConstantDataSequential(const ConstantDataSequential &) = delete;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
: Constant(ty, VT, nullptr, 0), DataElements(Data), Next(nullptr) {}
~ConstantDataSequential() override { delete Next; }
static Constant *getImpl(StringRef Bytes, Type *Ty);
protected:
// allocate space for exactly zero operands.
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public:
/// isElementTypeCompatible - Return true if a ConstantDataSequential can be
/// formed with a vector or array of the specified element type.
/// ConstantDataArray only works with normal float and int types that are
/// stored densely in memory, not with things like i42 or x86_f80.
static bool isElementTypeCompatible(const Type *Ty);
/// getElementAsInteger - If this is a sequential container of integers (of
/// any size), return the specified element in the low bits of a uint64_t.
uint64_t getElementAsInteger(unsigned i) const;
/// getElementAsAPFloat - If this is a sequential container of floating point
/// type, return the specified element as an APFloat.
APFloat getElementAsAPFloat(unsigned i) const;
/// getElementAsFloat - If this is an sequential container of floats, return
/// the specified element as a float.
float getElementAsFloat(unsigned i) const;
/// getElementAsDouble - If this is an sequential container of doubles, return
/// the specified element as a double.
double getElementAsDouble(unsigned i) const;
/// getElementAsConstant - Return a Constant for a specified index's element.
/// Note that this has to compute a new constant to return, so it isn't as
/// efficient as getElementAsInteger/Float/Double.
Constant *getElementAsConstant(unsigned i) const;
/// getType - Specialize the getType() method to always return a
/// SequentialType, which reduces the amount of casting needed in parts of the
/// compiler.
inline SequentialType *getType() const {
return cast<SequentialType>(Value::getType());
}
/// getElementType - Return the element type of the array/vector.
Type *getElementType() const;
/// getNumElements - Return the number of elements in the array or vector.
unsigned getNumElements() const;
/// getElementByteSize - Return the size (in bytes) of each element in the
/// array/vector. The size of the elements is known to be a multiple of one
/// byte.
uint64_t getElementByteSize() const;
/// isString - This method returns true if this is an array of i8.
bool isString() const;
/// isCString - This method returns true if the array "isString", ends with a
/// nul byte, and does not contains any other nul bytes.
bool isCString() const;
/// getAsString - If this array is isString(), then this method returns the
/// array as a StringRef. Otherwise, it asserts out.
///
StringRef getAsString() const {
assert(isString() && "Not a string");
return getRawDataValues();
}
/// getAsCString - If this array is isCString(), then this method returns the
/// array (without the trailing null byte) as a StringRef. Otherwise, it
/// asserts out.
///
StringRef getAsCString() const {
assert(isCString() && "Isn't a C string");
StringRef Str = getAsString();
return Str.substr(0, Str.size()-1);
}
/// getRawDataValues - Return the raw, underlying, bytes of this data. Note
/// that this is an extremely tricky thing to work with, as it exposes the
/// host endianness of the data elements.
StringRef getRawDataValues() const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
///
static bool classof(const Value *V) {
return V->getValueID() == ConstantDataArrayVal ||
V->getValueID() == ConstantDataVectorVal;
}
private:
const char *getElementPointer(unsigned Elt) const;
};
//===----------------------------------------------------------------------===//
/// ConstantDataArray - An array constant whose element type is a simple
/// 1/2/4/8-byte integer or float/double, and whose elements are just simple
/// data values (i.e. ConstantInt/ConstantFP). This Constant node has no
/// operands because it stores all of the elements of the constant as densely
/// packed data, instead of as Value*'s.
class ConstantDataArray : public ConstantDataSequential {
void *operator new(size_t, unsigned) = delete;
ConstantDataArray(const ConstantDataArray &) = delete;
void anchor() override;
friend class ConstantDataSequential;
explicit ConstantDataArray(Type *ty, const char *Data)
: ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
protected:
// allocate space for exactly zero operands.
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public:
/// get() constructors - Return a constant with array type with an element
/// count and element type matching the ArrayRef passed in. Note that this
/// can return a ConstantAggregateZero object.
static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
/// getFP() constructors - Return a constant with array type with an element
/// count and element type of float with precision matching the number of
/// bits in the ArrayRef passed in. (i.e. half for 16bits, float for 32bits,
/// double for 64bits) Note that this can return a ConstantAggregateZero
/// object.
static Constant *getFP(LLVMContext &Context, ArrayRef<uint16_t> Elts);
static Constant *getFP(LLVMContext &Context, ArrayRef<uint32_t> Elts);
static Constant *getFP(LLVMContext &Context, ArrayRef<uint64_t> Elts);
/// getString - This method constructs a CDS and initializes it with a text
/// string. The default behavior (AddNull==true) causes a null terminator to
/// be placed at the end of the array (increasing the length of the string by
/// one more than the StringRef would normally indicate. Pass AddNull=false
/// to disable this behavior.
static Constant *getString(LLVMContext &Context, StringRef Initializer,
bool AddNull = true);
/// getType - Specialize the getType() method to always return an ArrayType,
/// which reduces the amount of casting needed in parts of the compiler.
///
inline ArrayType *getType() const {
return cast<ArrayType>(Value::getType());
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
///
static bool classof(const Value *V) {
return V->getValueID() == ConstantDataArrayVal;
}
};
//===----------------------------------------------------------------------===//
/// ConstantDataVector - A vector constant whose element type is a simple
/// 1/2/4/8-byte integer or float/double, and whose elements are just simple
/// data values (i.e. ConstantInt/ConstantFP). This Constant node has no
/// operands because it stores all of the elements of the constant as densely
/// packed data, instead of as Value*'s.
class ConstantDataVector : public ConstantDataSequential {
void *operator new(size_t, unsigned) = delete;
ConstantDataVector(const ConstantDataVector &) = delete;
void anchor() override;
friend class ConstantDataSequential;
explicit ConstantDataVector(Type *ty, const char *Data)
: ConstantDataSequential(ty, ConstantDataVectorVal, Data) {}
protected:
// allocate space for exactly zero operands.
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public:
/// get() constructors - Return a constant with vector type with an element
/// count and element type matching the ArrayRef passed in. Note that this
/// can return a ConstantAggregateZero object.
static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
/// getFP() constructors - Return a constant with vector type with an element
/// count and element type of float with the precision matching the number of
/// bits in the ArrayRef passed in. (i.e. half for 16bits, float for 32bits,
/// double for 64bits) Note that this can return a ConstantAggregateZero
/// object.
static Constant *getFP(LLVMContext &Context, ArrayRef<uint16_t> Elts);
static Constant *getFP(LLVMContext &Context, ArrayRef<uint32_t> Elts);
static Constant *getFP(LLVMContext &Context, ArrayRef<uint64_t> Elts);
/// getSplat - Return a ConstantVector with the specified constant in each
/// element. The specified constant has to be a of a compatible type (i8/i16/
/// i32/i64/float/double) and must be a ConstantFP or ConstantInt.
static Constant *getSplat(unsigned NumElts, Constant *Elt);
/// getSplatValue - If this is a splat constant, meaning that all of the
/// elements have the same value, return that value. Otherwise return NULL.
Constant *getSplatValue() const;
/// getType - Specialize the getType() method to always return a VectorType,
/// which reduces the amount of casting needed in parts of the compiler.
///
inline VectorType *getType() const {
return cast<VectorType>(Value::getType());
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
///
static bool classof(const Value *V) {
return V->getValueID() == ConstantDataVectorVal;
}
};
/// BlockAddress - The address of a basic block.
///
class BlockAddress : public Constant {
void *operator new(size_t, unsigned) = delete;
void *operator new(size_t s) { return User::operator new(s, 2); }
BlockAddress(Function *F, BasicBlock *BB);
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
public:
/// get - Return a BlockAddress for the specified function and basic block.
static BlockAddress *get(Function *F, BasicBlock *BB);
/// get - Return a BlockAddress for the specified basic block. The basic
/// block must be embedded into a function.
static BlockAddress *get(BasicBlock *BB);
/// \brief 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);
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Function *getFunction() const { return (Function*)Op<0>().get(); }
BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Value *V) {
return V->getValueID() == BlockAddressVal;
}
};
template <>
struct OperandTraits<BlockAddress> :
public FixedNumOperandTraits<BlockAddress, 2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value)
//===----------------------------------------------------------------------===//
/// ConstantExpr - a constant value that is initialized with an expression using
/// other constant values.
///
/// This class uses the standard Instruction opcodes to define the various
/// constant expressions. The Opcode field for the ConstantExpr class is
/// maintained in the Value::SubclassData field.
class ConstantExpr : public Constant {
friend struct ConstantExprKeyType;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
: Constant(ty, ConstantExprVal, Ops, NumOps) {
// Operation type (an Instruction opcode) is stored as the SubclassData.
setValueSubclassData(Opcode);
}
public:
// Static methods to construct a ConstantExpr of different kinds. Note that
// these methods may return a object that is not an instance of the
// ConstantExpr class, because they will attempt to fold the constant
// expression into something simpler if possible.
/// getAlignOf constant expr - computes the alignment of a type in a target
/// independent way (Note: the return type is an i64).
static Constant *getAlignOf(Type *Ty);
/// getSizeOf constant expr - computes the (alloc) size of a type (in
/// address-units, not bits) in a target independent way (Note: the return
/// type is an i64).
///
static Constant *getSizeOf(Type *Ty);
/// getOffsetOf constant expr - computes the offset of a struct field in a
/// target independent way (Note: the return type is an i64).
///
static Constant *getOffsetOf(StructType *STy, unsigned FieldNo);
/// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
/// which supports any aggregate type, and any Constant index.
///
static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false);
static Constant *getFNeg(Constant *C);
static Constant *getNot(Constant *C);
static Constant *getAdd(Constant *C1, Constant *C2,
bool HasNUW = false, bool HasNSW = false);
static Constant *getFAdd(Constant *C1, Constant *C2);
static Constant *getSub(Constant *C1, Constant *C2,
bool HasNUW = false, bool HasNSW = false);
static Constant *getFSub(Constant *C1, Constant *C2);
static Constant *getMul(Constant *C1, Constant *C2,
bool HasNUW = false, bool HasNSW = false);
static Constant *getFMul(Constant *C1, Constant *C2);
static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getFDiv(Constant *C1, Constant *C2);
static Constant *getURem(Constant *C1, Constant *C2);
static Constant *getSRem(Constant *C1, Constant *C2);
static Constant *getFRem(Constant *C1, Constant *C2);
static Constant *getAnd(Constant *C1, Constant *C2);
static Constant *getOr(Constant *C1, Constant *C2);
static Constant *getXor(Constant *C1, Constant *C2);
static Constant *getShl(Constant *C1, Constant *C2,
bool HasNUW = false, bool HasNSW = false);
static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
static Constant *getSExt(Constant *C, Type *Ty, bool OnlyIfReduced = false);
static Constant *getZExt(Constant *C, Type *Ty, bool OnlyIfReduced = false);
static Constant *getFPTrunc(Constant *C, Type *Ty,
bool OnlyIfReduced = false);
static Constant *getFPExtend(Constant *C, Type *Ty,
bool OnlyIfReduced = false);
static Constant *getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
static Constant *getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
static Constant *getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
static Constant *getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
static Constant *getPtrToInt(Constant *C, Type *Ty,
bool OnlyIfReduced = false);
static Constant *getIntToPtr(Constant *C, Type *Ty,
bool OnlyIfReduced = false);
static Constant *getBitCast(Constant *C, Type *Ty,
bool OnlyIfReduced = false);
static Constant *getAddrSpaceCast(Constant *C, Type *Ty,
bool OnlyIfReduced = false);
static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
static Constant *getNSWAdd(Constant *C1, Constant *C2) {
return getAdd(C1, C2, false, true);
}
static Constant *getNUWAdd(Constant *C1, Constant *C2) {
return getAdd(C1, C2, true, false);
}
static Constant *getNSWSub(Constant *C1, Constant *C2) {
return getSub(C1, C2, false, true);
}
static Constant *getNUWSub(Constant *C1, Constant *C2) {
return getSub(C1, C2, true, false);
}
static Constant *getNSWMul(Constant *C1, Constant *C2) {
return getMul(C1, C2, false, true);
}
static Constant *getNUWMul(Constant *C1, Constant *C2) {
return getMul(C1, C2, true, false);
}
static Constant *getNSWShl(Constant *C1, Constant *C2) {
return getShl(C1, C2, false, true);
}
static Constant *getNUWShl(Constant *C1, Constant *C2) {
return getShl(C1, C2, true, false);
}
static Constant *getExactSDiv(Constant *C1, Constant *C2) {
return getSDiv(C1, C2, true);
}
static Constant *getExactUDiv(Constant *C1, Constant *C2) {
return getUDiv(C1, C2, true);
}
static Constant *getExactAShr(Constant *C1, Constant *C2) {
return getAShr(C1, C2, true);
}
static Constant *getExactLShr(Constant *C1, Constant *C2) {
return getLShr(C1, C2, true);
}
/// getBinOpIdentity - Return the identity for the given binary operation,
/// i.e. a constant C such that X op C = X and C op X = X for every X. It
/// returns null if the operator doesn't have an identity.
static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty);
/// getBinOpAbsorber - Return the absorbing element for the given binary
/// operation, i.e. a constant C such that X op C = C and C op X = C for
/// every X. For example, this returns zero for integer multiplication.
/// It returns null if the operator doesn't have an absorbing element.
static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty);
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
/// \brief Convenience function for getting a Cast operation.
///
/// \param ops The opcode for the conversion
/// \param C The constant to be converted
/// \param Ty The type to which the constant is converted
/// \param OnlyIfReduced see \a getWithOperands() docs.
static Constant *getCast(unsigned ops, Constant *C, Type *Ty,
bool OnlyIfReduced = false);
// @brief Create a ZExt or BitCast cast constant expression
static Constant *getZExtOrBitCast(
Constant *C, ///< The constant to zext or bitcast
Type *Ty ///< The type to zext or bitcast C to
);
// @brief Create a SExt or BitCast cast constant expression
static Constant *getSExtOrBitCast(
Constant *C, ///< The constant to sext or bitcast
Type *Ty ///< The type to sext or bitcast C to
);
// @brief Create a Trunc or BitCast cast constant expression
static Constant *getTruncOrBitCast(
Constant *C, ///< The constant to trunc or bitcast
Type *Ty ///< The type to trunc or bitcast C to
);
/// @brief Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant
/// expression.
static Constant *getPointerCast(
Constant *C, ///< The pointer value to be casted (operand 0)
Type *Ty ///< The type to which cast should be made
);
/// @brief Create a BitCast or AddrSpaceCast for a pointer type depending on
/// the address space.
static Constant *getPointerBitCastOrAddrSpaceCast(
Constant *C, ///< The constant to addrspacecast or bitcast
Type *Ty ///< The type to bitcast or addrspacecast C to
);
/// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
static Constant *getIntegerCast(
Constant *C, ///< The integer constant to be casted
Type *Ty, ///< The integer type to cast to
bool isSigned ///< Whether C should be treated as signed or not
);
/// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
static Constant *getFPCast(
Constant *C, ///< The integer constant to be casted
Type *Ty ///< The integer type to cast to
);
/// @brief Return true if this is a convert constant expression
bool isCast() const;
/// @brief Return true if this is a compare constant expression
bool isCompare() const;
/// @brief Return true if this is an insertvalue or extractvalue expression,
/// and the getIndices() method may be used.
bool hasIndices() const;
/// @brief Return true if this is a getelementptr expression and all
/// the index operands are compile-time known integers within the
/// corresponding notional static array extents. Note that this is
/// not equivalant to, a subset of, or a superset of the "inbounds"
/// property.
bool isGEPWithNoNotionalOverIndexing() const;
/// Select constant expr
///
/// \param OnlyIfReducedTy see \a getWithOperands() docs.
static Constant *getSelect(Constant *C, Constant *V1, Constant *V2,
Type *OnlyIfReducedTy = nullptr);
/// get - Return a binary or shift operator constant expression,
/// folding if possible.
///
/// \param OnlyIfReducedTy see \a getWithOperands() docs.
static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
unsigned Flags = 0, Type *OnlyIfReducedTy = nullptr);
/// \brief Return an ICmp or FCmp comparison operator constant expression.
///
/// \param OnlyIfReduced see \a getWithOperands() docs.
static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2,
bool OnlyIfReduced = false);
/// get* - Return some common constants without having to
/// specify the full Instruction::OPCODE identifier.
///
static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS,
bool OnlyIfReduced = false);
static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS,
bool OnlyIfReduced = false);
/// Getelementptr form. Value* is only accepted for convenience;
/// all elements must be Constants.
///
/// \param OnlyIfReducedTy see \a getWithOperands() docs.
static Constant *getGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Constant *> IdxList,
bool InBounds = false,
Type *OnlyIfReducedTy = nullptr) {
return getGetElementPtr(
Ty, C, makeArrayRef((Value * const *)IdxList.data(), IdxList.size()),
InBounds, OnlyIfReducedTy);
}
static Constant *getGetElementPtr(Type *Ty, Constant *C, Constant *Idx,
bool InBounds = false,
Type *OnlyIfReducedTy = nullptr) {
// This form of the function only exists to avoid ambiguous overload
// warnings about whether to convert Idx to ArrayRef<Constant *> or
// ArrayRef<Value *>.
return getGetElementPtr(Ty, C, cast<Value>(Idx), InBounds, OnlyIfReducedTy);
}
static Constant *getGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Value *> IdxList,
bool InBounds = false,
Type *OnlyIfReducedTy = nullptr);
/// Create an "inbounds" getelementptr. See the documentation for the
/// "inbounds" flag in LangRef.html for details.
static Constant *getInBoundsGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Constant *> IdxList) {
return getGetElementPtr(Ty, C, IdxList, true);
}
static Constant *getInBoundsGetElementPtr(Type *Ty, Constant *C,
Constant *Idx) {
// This form of the function only exists to avoid ambiguous overload
// warnings about whether to convert Idx to ArrayRef<Constant *> or
// ArrayRef<Value *>.
return getGetElementPtr(Ty, C, Idx, true);
}
static Constant *getInBoundsGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Value *> IdxList) {
return getGetElementPtr(Ty, C, IdxList, true);
}
static Constant *getExtractElement(Constant *Vec, Constant *Idx,
Type *OnlyIfReducedTy = nullptr);
static Constant *getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx,
Type *OnlyIfReducedTy = nullptr);
static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask,
Type *OnlyIfReducedTy = nullptr);
static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs,
Type *OnlyIfReducedTy = nullptr);
static Constant *getInsertValue(Constant *Agg, Constant *Val,
ArrayRef<unsigned> Idxs,
Type *OnlyIfReducedTy = nullptr);
/// getOpcode - Return the opcode at the root of this constant expression
unsigned getOpcode() const { return getSubclassDataFromValue(); }
/// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
/// not an ICMP or FCMP constant expression.
unsigned getPredicate() const;
/// getIndices - Assert that this is an insertvalue or exactvalue
/// expression and return the list of indices.
ArrayRef<unsigned> getIndices() const;
/// getOpcodeName - Return a string representation for an opcode.
const char *getOpcodeName() const;
/// getWithOperandReplaced - Return a constant expression identical to this
/// one, but with the specified operand set to the specified value.
Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
/// getWithOperands - This returns the current constant expression with the
/// operands replaced with the specified values. The specified array must
/// have the same number of operands as our current one.
Constant *getWithOperands(ArrayRef<Constant*> Ops) const {
return getWithOperands(Ops, getType());
}
/// \brief Get the current expression with the operands replaced.
///
/// Return the current constant expression with the operands replaced with \c
/// Ops and the type with \c Ty. The new operands must have the same number
/// as the current ones.
///
/// If \c OnlyIfReduced is \c true, nullptr will be returned unless something
/// gets constant-folded, the type changes, or the expression is otherwise
/// canonicalized. This parameter should almost always be \c false.
Constant *getWithOperands(ArrayRef<Constant *> Ops, Type *Ty,
bool OnlyIfReduced = false) const;
/// getAsInstruction - Returns an Instruction which implements the same
/// operation as this ConstantExpr. The instruction is not linked to any basic
/// block.
///
/// A better approach to this could be to have a constructor for Instruction
/// which would take a ConstantExpr parameter, but that would have spread
/// implementation details of ConstantExpr outside of Constants.cpp, which
/// would make it harder to remove ConstantExprs altogether.
Instruction *getAsInstruction();
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Value *V) {
return V->getValueID() == ConstantExprVal;
}
private:
// Shadow Value::setValueSubclassData with a private forwarding method so that
// subclasses cannot accidentally use it.
void setValueSubclassData(unsigned short D) {
Value::setValueSubclassData(D);
}
};
template <>
struct OperandTraits<ConstantExpr> :
public VariadicOperandTraits<ConstantExpr, 1> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
// //
///////////////////////////////////////////////////////////////////////////////
/// UndefValue - 'undef' values are things that do not have specified contents.
/// These are used for a variety of purposes, including global variable
/// initializers and operands to instructions. 'undef' values can occur with
/// any first-class type.
///
/// Undef values aren't exactly constants; if they have multiple uses, they
/// can appear to have different bit patterns at each use. See
/// LangRef.html#undefvalues for details.
///
class UndefValue : public Constant {
void *operator new(size_t, unsigned) = delete;
UndefValue(const UndefValue &) = delete;
friend class Constant;
void destroyConstantImpl();
Value *handleOperandChangeImpl(Value *From, Value *To, Use *U);
protected:
explicit UndefValue(Type *T) : Constant(T, UndefValueVal, nullptr, 0) {}
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public:
/// get() - Static factory methods - Return an 'undef' object of the specified
/// type.
///
static UndefValue *get(Type *T);
/// getSequentialElement - If this Undef has array or vector type, return a
/// undef with the right element type.
UndefValue *getSequentialElement() const;
/// getStructElement - If this undef has struct type, return a undef with the
/// right element type for the specified element.
UndefValue *getStructElement(unsigned Elt) const;
/// getElementValue - Return an undef of the right value for the specified GEP
/// index.
UndefValue *getElementValue(Constant *C) const;
/// getElementValue - Return an undef of the right value for the specified GEP
/// index.
UndefValue *getElementValue(unsigned Idx) const;
/// \brief Return the number of elements in the array, vector, or struct.
unsigned getNumElements() const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
return V->getValueID() == UndefValueVal;
}
};
} // End llvm namespace
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/TypeFinder.h | //===-- llvm/IR/TypeFinder.h - Class to find used struct types --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the declaration of the TypeFinder class.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_TYPEFINDER_H
#define LLVM_IR_TYPEFINDER_H
#include "llvm/ADT/DenseSet.h"
#include <vector>
namespace llvm {
class MDNode;
class Module;
class StructType;
class Type;
class Value;
/// TypeFinder - Walk over a module, identifying all of the types that are
/// used by the module.
class TypeFinder {
// To avoid walking constant expressions multiple times and other IR
// objects, we keep several helper maps.
DenseSet<const Value*> VisitedConstants;
DenseSet<const MDNode *> VisitedMetadata;
DenseSet<Type*> VisitedTypes;
std::vector<StructType*> StructTypes;
bool OnlyNamed;
public:
TypeFinder() : OnlyNamed(false) {}
void run(const Module &M, bool onlyNamed);
void clear();
typedef std::vector<StructType*>::iterator iterator;
typedef std::vector<StructType*>::const_iterator const_iterator;
iterator begin() { return StructTypes.begin(); }
iterator end() { return StructTypes.end(); }
const_iterator begin() const { return StructTypes.begin(); }
const_iterator end() const { return StructTypes.end(); }
bool empty() const { return StructTypes.empty(); }
size_t size() const { return StructTypes.size(); }
iterator erase(iterator I, iterator E) { return StructTypes.erase(I, E); }
StructType *&operator[](unsigned Idx) { return StructTypes[Idx]; }
private:
/// incorporateType - This method adds the type to the list of used
/// structures if it's not in there already.
void incorporateType(Type *Ty);
/// incorporateValue - This method is used to walk operand lists finding types
/// hiding in constant expressions and other operands that won't be walked in
/// other ways. GlobalValues, basic blocks, instructions, and inst operands
/// are all explicitly enumerated.
void incorporateValue(const Value *V);
/// incorporateMDNode - This method is used to walk the operands of an MDNode
/// to find types hiding within.
void incorporateMDNode(const MDNode *V);
};
} // end llvm namespace
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/DebugInfoMetadata.h | //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Declarations for metadata specific to debug info.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_DEBUGINFOMETADATA_H
#define LLVM_IR_DEBUGINFOMETADATA_H
#include "llvm/IR/Metadata.h"
#include "llvm/Support/Dwarf.h"
// Helper macros for defining get() overrides.
#define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__
#define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS
#define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \
static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \
} \
static CLASS *getIfExists(LLVMContext &Context, \
DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \
/* ShouldCreate */ false); \
} \
static CLASS *getDistinct(LLVMContext &Context, \
DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \
} \
static Temp##CLASS getTemporary(LLVMContext &Context, \
DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \
return Temp##CLASS( \
getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \
}
namespace llvm {
/// \brief Pointer union between a subclass of DINode and MDString.
///
/// \a DICompositeType can be referenced via an \a MDString unique identifier.
/// This class allows some type safety in the face of that, requiring either a
/// node of a particular type or an \a MDString.
template <class T> class TypedDINodeRef {
const Metadata *MD = nullptr;
public:
TypedDINodeRef() = default;
TypedDINodeRef(std::nullptr_t) {}
/// \brief Construct from a raw pointer.
explicit TypedDINodeRef(const Metadata *MD) : MD(MD) {
assert((!MD || isa<MDString>(MD) || isa<T>(MD)) && "Expected valid ref");
}
template <class U>
TypedDINodeRef(
const TypedDINodeRef<U> &X,
typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
nullptr)
: MD(X) {}
operator Metadata *() const { return const_cast<Metadata *>(MD); }
bool operator==(const TypedDINodeRef<T> &X) const { return MD == X.MD; };
bool operator!=(const TypedDINodeRef<T> &X) const { return MD != X.MD; };
/// \brief Create a reference.
///
/// Get a reference to \c N, using an \a MDString reference if available.
static TypedDINodeRef get(const T *N);
template <class MapTy> T *resolve(const MapTy &Map) const {
if (!MD)
return nullptr;
if (auto *Typed = dyn_cast<T>(MD))
return const_cast<T *>(Typed);
auto *S = cast<MDString>(MD);
auto I = Map.find(S);
assert(I != Map.end() && "Missing identifier in type map");
return cast<T>(I->second);
}
};
typedef TypedDINodeRef<DINode> DINodeRef;
typedef TypedDINodeRef<DIScope> DIScopeRef;
typedef TypedDINodeRef<DIType> DITypeRef;
class DITypeRefArray {
const MDTuple *N = nullptr;
public:
DITypeRefArray(const MDTuple *N) : N(N) {}
explicit operator bool() const { return get(); }
explicit operator MDTuple *() const { return get(); }
MDTuple *get() const { return const_cast<MDTuple *>(N); }
MDTuple *operator->() const { return get(); }
MDTuple &operator*() const { return *get(); }
// FIXME: Fix callers and remove condition on N.
unsigned size() const { return N ? N->getNumOperands() : 0u; }
DITypeRef operator[](unsigned I) const { return DITypeRef(N->getOperand(I)); }
class iterator {
MDNode::op_iterator I = nullptr;
public:
using iterator_category = std::input_iterator_tag;
using value_type = DITypeRef;
using difference_type = std::ptrdiff_t;
using pointer = void;
using reference = DITypeRef;
iterator() = default;
explicit iterator(MDNode::op_iterator I) : I(I) {}
DITypeRef operator*() const { return DITypeRef(*I); }
iterator &operator++() {
++I;
return *this;
}
iterator operator++(int) {
iterator Temp(*this);
++I;
return Temp;
}
bool operator==(const iterator &X) const { return I == X.I; }
bool operator!=(const iterator &X) const { return I != X.I; }
};
// FIXME: Fix callers and remove condition on N.
iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
};
/// \brief Tagged DWARF-like metadata node.
///
/// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
/// defined in llvm/Support/Dwarf.h). Called \a DINode because it's
/// potentially used for non-DWARF output.
class DINode : public MDNode {
friend class LLVMContextImpl;
friend class MDNode;
protected:
DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None)
: MDNode(C, ID, Storage, Ops1, Ops2) {
assert(Tag < 1u << 16);
SubclassData16 = Tag;
}
~DINode() = default;
template <class Ty> Ty *getOperandAs(unsigned I) const {
return cast_or_null<Ty>(getOperand(I));
}
StringRef getStringOperand(unsigned I) const {
if (auto *S = getOperandAs<MDString>(I))
return S->getString();
return StringRef();
}
static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
if (S.empty())
return nullptr;
return MDString::get(Context, S);
}
public:
unsigned getTag() const { return SubclassData16; }
/// \brief Debug info flags.
///
/// The three accessibility flags are mutually exclusive and rolled together
/// in the first two bits.
enum DIFlags {
#define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID,
#include "llvm/IR/DebugInfoFlags.def"
FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
};
static unsigned getFlag(StringRef Flag);
static const char *getFlagString(unsigned Flag);
/// \brief Split up a flags bitfield.
///
/// Split \c Flags into \c SplitFlags, a vector of its components. Returns
/// any remaining (unrecognized) bits.
static unsigned splitFlags(unsigned Flags,
SmallVectorImpl<unsigned> &SplitFlags);
DINodeRef getRef() const { return DINodeRef::get(this); }
static bool classof(const Metadata *MD) {
switch (MD->getMetadataID()) {
default:
return false;
case GenericDINodeKind:
case DISubrangeKind:
case DIEnumeratorKind:
case DIBasicTypeKind:
case DIDerivedTypeKind:
case DICompositeTypeKind:
case DISubroutineTypeKind:
case DIFileKind:
case DICompileUnitKind:
case DISubprogramKind:
case DILexicalBlockKind:
case DILexicalBlockFileKind:
case DINamespaceKind:
case DITemplateTypeParameterKind:
case DITemplateValueParameterKind:
case DIGlobalVariableKind:
case DILocalVariableKind:
case DIObjCPropertyKind:
case DIImportedEntityKind:
case DIModuleKind:
return true;
}
}
};
template <class T> struct simplify_type<const TypedDINodeRef<T>> {
typedef Metadata *SimpleType;
static SimpleType getSimplifiedValue(const TypedDINodeRef<T> &MD) {
return MD;
}
};
template <class T>
struct simplify_type<TypedDINodeRef<T>>
: simplify_type<const TypedDINodeRef<T>> {};
/// \brief Generic tagged DWARF-like metadata node.
///
/// An un-specialized DWARF-like metadata node. The first operand is a
/// (possibly empty) null-separated \a MDString header that contains arbitrary
/// fields. The remaining operands are \a dwarf_operands(), and are pointers
/// to other metadata.
class GenericDINode : public DINode {
friend class LLVMContextImpl;
friend class MDNode;
GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
unsigned Tag, ArrayRef<Metadata *> Ops1,
ArrayRef<Metadata *> Ops2)
: DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
setHash(Hash);
}
~GenericDINode() { dropAllReferences(); }
void setHash(unsigned Hash) { SubclassData32 = Hash; }
void recalculateHash();
static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
StringRef Header, ArrayRef<Metadata *> DwarfOps,
StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
DwarfOps, Storage, ShouldCreate);
}
static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
MDString *Header, ArrayRef<Metadata *> DwarfOps,
StorageType Storage, bool ShouldCreate = true);
TempGenericDINode cloneImpl() const {
return getTemporary(
getContext(), getTag(), getHeader(),
SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
}
public:
unsigned getHash() const { return SubclassData32; }
DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, StringRef Header,
ArrayRef<Metadata *> DwarfOps),
(Tag, Header, DwarfOps))
DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, MDString *Header,
ArrayRef<Metadata *> DwarfOps),
(Tag, Header, DwarfOps))
/// \brief Return a (temporary) clone of this.
TempGenericDINode clone() const { return cloneImpl(); }
unsigned getTag() const { return SubclassData16; }
StringRef getHeader() const { return getStringOperand(0); }
op_iterator dwarf_op_begin() const { return op_begin() + 1; }
op_iterator dwarf_op_end() const { return op_end(); }
op_range dwarf_operands() const {
return op_range(dwarf_op_begin(), dwarf_op_end());
}
unsigned getNumDwarfOperands() const { return getNumOperands() - 1; }
const MDOperand &getDwarfOperand(unsigned I) const {
return getOperand(I + 1);
}
void replaceDwarfOperandWith(unsigned I, Metadata *New) {
replaceOperandWith(I + 1, New);
}
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == GenericDINodeKind;
}
};
/// \brief Array subrange.
///
/// TODO: Merge into node for DW_TAG_array_type, which should have a custom
/// type.
class DISubrange : public DINode {
friend class LLVMContextImpl;
friend class MDNode;
int64_t Count;
int64_t LowerBound;
DISubrange(LLVMContext &C, StorageType Storage, int64_t Count,
int64_t LowerBound)
: DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, None),
Count(Count), LowerBound(LowerBound) {}
~DISubrange() = default;
static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
int64_t LowerBound, StorageType Storage,
bool ShouldCreate = true);
TempDISubrange cloneImpl() const {
return getTemporary(getContext(), getCount(), getLowerBound());
}
public:
DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
(Count, LowerBound))
TempDISubrange clone() const { return cloneImpl(); }
int64_t getLowerBound() const { return LowerBound; }
int64_t getCount() const { return Count; }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DISubrangeKind;
}
};
/// \brief Enumeration value.
///
/// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
/// longer creates a type cycle.
class DIEnumerator : public DINode {
friend class LLVMContextImpl;
friend class MDNode;
int64_t Value;
DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
ArrayRef<Metadata *> Ops)
: DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
Value(Value) {}
~DIEnumerator() = default;
static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
StringRef Name, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
ShouldCreate);
}
static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
MDString *Name, StorageType Storage,
bool ShouldCreate = true);
TempDIEnumerator cloneImpl() const {
return getTemporary(getContext(), getValue(), getName());
}
public:
DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, StringRef Name),
(Value, Name))
DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, MDString *Name),
(Value, Name))
TempDIEnumerator clone() const { return cloneImpl(); }
int64_t getValue() const { return Value; }
StringRef getName() const { return getStringOperand(0); }
MDString *getRawName() const { return getOperandAs<MDString>(0); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIEnumeratorKind;
}
};
/// \brief Base class for scope-like contexts.
///
/// Base class for lexical scopes and types (which are also declaration
/// contexts).
///
/// TODO: Separate the concepts of declaration contexts and lexical scopes.
class DIScope : public DINode {
protected:
DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
ArrayRef<Metadata *> Ops)
: DINode(C, ID, Storage, Tag, Ops) {}
~DIScope() = default;
public:
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
inline StringRef getFilename() const;
inline StringRef getDirectory() const;
StringRef getName() const;
DIScopeRef getScope() const;
/// \brief Return the raw underlying file.
///
/// An \a DIFile is an \a DIScope, but it doesn't point at a separate file
/// (it\em is the file). If \c this is an \a DIFile, we need to return \c
/// this. Otherwise, return the first operand, which is where all other
/// subclasses store their file pointer.
Metadata *getRawFile() const {
return isa<DIFile>(this) ? const_cast<DIScope *>(this)
: static_cast<Metadata *>(getOperand(0));
}
DIScopeRef getRef() const { return DIScopeRef::get(this); }
static bool classof(const Metadata *MD) {
switch (MD->getMetadataID()) {
default:
return false;
case DIBasicTypeKind:
case DIDerivedTypeKind:
case DICompositeTypeKind:
case DISubroutineTypeKind:
case DIFileKind:
case DICompileUnitKind:
case DISubprogramKind:
case DILexicalBlockKind:
case DILexicalBlockFileKind:
case DINamespaceKind:
case DIModuleKind:
return true;
}
}
};
/// \brief File.
///
/// TODO: Merge with directory/file node (including users).
/// TODO: Canonicalize paths on creation.
class DIFile : public DIScope {
friend class LLVMContextImpl;
friend class MDNode;
DIFile(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Ops)
: DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
~DIFile() = default;
static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
StringRef Directory, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, getCanonicalMDString(Context, Filename),
getCanonicalMDString(Context, Directory), Storage,
ShouldCreate);
}
static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
MDString *Directory, StorageType Storage,
bool ShouldCreate = true);
TempDIFile cloneImpl() const {
return getTemporary(getContext(), getFilename(), getDirectory());
}
public:
DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory),
(Filename, Directory))
DEFINE_MDNODE_GET(DIFile, (MDString * Filename, MDString *Directory),
(Filename, Directory))
TempDIFile clone() const { return cloneImpl(); }
StringRef getFilename() const { return getStringOperand(0); }
StringRef getDirectory() const { return getStringOperand(1); }
MDString *getRawFilename() const { return getOperandAs<MDString>(0); }
MDString *getRawDirectory() const { return getOperandAs<MDString>(1); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIFileKind;
}
};
StringRef DIScope::getFilename() const {
if (auto *F = getFile())
return F->getFilename();
return "";
}
StringRef DIScope::getDirectory() const {
if (auto *F = getFile())
return F->getDirectory();
return "";
}
/// \brief Base class for types.
///
/// TODO: Remove the hardcoded name and context, since many types don't use
/// them.
/// TODO: Split up flags.
class DIType : public DIScope {
unsigned Line;
unsigned Flags;
uint64_t SizeInBits;
uint64_t AlignInBits;
uint64_t OffsetInBits;
protected:
DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
: DIScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
SizeInBits(SizeInBits), AlignInBits(AlignInBits),
OffsetInBits(OffsetInBits) {}
~DIType() = default;
public:
TempDIType clone() const {
return TempDIType(cast<DIType>(MDNode::clone().release()));
}
unsigned getLine() const { return Line; }
uint64_t getSizeInBits() const { return SizeInBits; }
uint64_t getAlignInBits() const { return AlignInBits; }
uint64_t getOffsetInBits() const { return OffsetInBits; }
unsigned getFlags() const { return Flags; }
DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
StringRef getName() const { return getStringOperand(2); }
Metadata *getRawScope() const { return getOperand(1); }
void setScope(Metadata *scope) { setOperand(1, scope); } // HLSL Change
MDString *getRawName() const { return getOperandAs<MDString>(2); }
void setFlags(unsigned NewFlags) {
assert(!isUniqued() && "Cannot set flags on uniqued nodes");
Flags = NewFlags;
}
bool isPrivate() const {
return (getFlags() & FlagAccessibility) == FlagPrivate;
}
bool isProtected() const {
return (getFlags() & FlagAccessibility) == FlagProtected;
}
bool isPublic() const {
return (getFlags() & FlagAccessibility) == FlagPublic;
}
bool isForwardDecl() const { return getFlags() & FlagFwdDecl; }
bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; }
bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; }
bool isVirtual() const { return getFlags() & FlagVirtual; }
bool isArtificial() const { return getFlags() & FlagArtificial; }
bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
bool isObjcClassComplete() const {
return getFlags() & FlagObjcClassComplete;
}
bool isVector() const { return getFlags() & FlagVector; }
bool isStaticMember() const { return getFlags() & FlagStaticMember; }
bool isLValueReference() const { return getFlags() & FlagLValueReference; }
bool isRValueReference() const { return getFlags() & FlagRValueReference; }
DITypeRef getRef() const { return DITypeRef::get(this); }
static bool classof(const Metadata *MD) {
switch (MD->getMetadataID()) {
default:
return false;
case DIBasicTypeKind:
case DIDerivedTypeKind:
case DICompositeTypeKind:
case DISubroutineTypeKind:
return true;
}
}
};
/// \brief Basic type, like 'int' or 'float'.
///
/// TODO: Split out DW_TAG_unspecified_type.
/// TODO: Drop unused accessors.
class DIBasicType : public DIType {
friend class LLVMContextImpl;
friend class MDNode;
unsigned Encoding;
DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
ArrayRef<Metadata *> Ops)
: DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
0, Ops),
Encoding(Encoding) {}
~DIBasicType() = default;
static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
StringRef Name, uint64_t SizeInBits,
uint64_t AlignInBits, unsigned Encoding,
StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
}
static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
MDString *Name, uint64_t SizeInBits,
uint64_t AlignInBits, unsigned Encoding,
StorageType Storage, bool ShouldCreate = true);
TempDIBasicType cloneImpl() const {
return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
getAlignInBits(), getEncoding());
}
public:
DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
(Tag, Name, 0, 0, 0))
DEFINE_MDNODE_GET(DIBasicType,
(unsigned Tag, StringRef Name, uint64_t SizeInBits,
uint64_t AlignInBits, unsigned Encoding),
(Tag, Name, SizeInBits, AlignInBits, Encoding))
DEFINE_MDNODE_GET(DIBasicType,
(unsigned Tag, MDString *Name, uint64_t SizeInBits,
uint64_t AlignInBits, unsigned Encoding),
(Tag, Name, SizeInBits, AlignInBits, Encoding))
TempDIBasicType clone() const { return cloneImpl(); }
unsigned getEncoding() const { return Encoding; }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIBasicTypeKind;
}
};
/// \brief Base class for DIDerivedType and DICompositeType.
///
/// TODO: Delete; they're not really related.
class DIDerivedTypeBase : public DIType {
protected:
DIDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
unsigned Tag, unsigned Line, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
ArrayRef<Metadata *> Ops)
: DIType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
Flags, Ops) {}
~DIDerivedTypeBase() = default;
public:
DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
Metadata *getRawBaseType() const { return getOperand(3); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIDerivedTypeKind ||
MD->getMetadataID() == DICompositeTypeKind ||
MD->getMetadataID() == DISubroutineTypeKind;
}
};
/// \brief Derived types.
///
/// This includes qualified types, pointers, references, friends, typedefs, and
/// class members.
///
/// TODO: Split out members (inheritance, fields, methods, etc.).
class DIDerivedType : public DIDerivedTypeBase {
friend class LLVMContextImpl;
friend class MDNode;
DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags, ArrayRef<Metadata *> Ops)
: DIDerivedTypeBase(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits,
AlignInBits, OffsetInBits, Flags, Ops) {}
~DIDerivedType() = default;
static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
StringRef Name, DIFile *File, unsigned Line,
DIScopeRef Scope, DITypeRef BaseType,
uint64_t SizeInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags,
Metadata *ExtraData, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
Flags, ExtraData, Storage, ShouldCreate);
}
static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
MDString *Name, Metadata *File, unsigned Line,
Metadata *Scope, Metadata *BaseType,
uint64_t SizeInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags,
Metadata *ExtraData, StorageType Storage,
bool ShouldCreate = true);
TempDIDerivedType cloneImpl() const {
return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
getScope(), getBaseType(), getSizeInBits(),
getAlignInBits(), getOffsetInBits(), getFlags(),
getExtraData());
}
public:
DEFINE_MDNODE_GET(DIDerivedType,
(unsigned Tag, MDString *Name, Metadata *File,
unsigned Line, Metadata *Scope, Metadata *BaseType,
uint64_t SizeInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags,
Metadata *ExtraData = nullptr),
(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
AlignInBits, OffsetInBits, Flags, ExtraData))
DEFINE_MDNODE_GET(DIDerivedType,
(unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t OffsetInBits,
unsigned Flags, Metadata *ExtraData = nullptr),
(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
AlignInBits, OffsetInBits, Flags, ExtraData))
TempDIDerivedType clone() const { return cloneImpl(); }
/// \brief Get extra data associated with this derived type.
///
/// Class type for pointer-to-members, objective-c property node for ivars,
/// or global constant wrapper for static members.
///
/// TODO: Separate out types that need this extra operand: pointer-to-member
/// types and member fields (static members and ivars).
Metadata *getExtraData() const { return getRawExtraData(); }
Metadata *getRawExtraData() const { return getOperand(4); }
/// \brief Get casted version of extra data.
/// @{
DITypeRef getClassType() const {
assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
return DITypeRef(getExtraData());
}
DIObjCProperty *getObjCProperty() const {
return dyn_cast_or_null<DIObjCProperty>(getExtraData());
}
Constant *getConstant() const {
assert(getTag() == dwarf::DW_TAG_member && isStaticMember());
if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
return C->getValue();
return nullptr;
}
/// @}
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIDerivedTypeKind;
}
};
/// \brief Base class for DICompositeType and DISubroutineType.
///
/// TODO: Delete; they're not really related.
class DICompositeTypeBase : public DIDerivedTypeBase {
unsigned RuntimeLang;
protected:
DICompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
unsigned Tag, unsigned Line, unsigned RuntimeLang,
uint64_t SizeInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags,
ArrayRef<Metadata *> Ops)
: DIDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
OffsetInBits, Flags, Ops),
RuntimeLang(RuntimeLang) {}
~DICompositeTypeBase() = default;
public:
/// \brief Get the elements of the composite type.
///
/// \note Calling this is only valid for \a DICompositeType. This assertion
/// can be removed once \a DISubroutineType has been separated from
/// "composite types".
DINodeArray getElements() const {
assert(!isa<DISubroutineType>(this) && "no elements for DISubroutineType");
return cast_or_null<MDTuple>(getRawElements());
}
DITypeRef getVTableHolder() const { return DITypeRef(getRawVTableHolder()); }
DITemplateParameterArray getTemplateParams() const {
return cast_or_null<MDTuple>(getRawTemplateParams());
}
StringRef getIdentifier() const { return getStringOperand(7); }
unsigned getRuntimeLang() const { return RuntimeLang; }
Metadata *getRawElements() const { return getOperand(4); }
Metadata *getRawVTableHolder() const { return getOperand(5); }
Metadata *getRawTemplateParams() const { return getOperand(6); }
MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
/// \brief Replace operands.
///
/// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
/// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
/// of its movement if necessary.
/// @{
void replaceElements(DINodeArray Elements) {
#ifndef NDEBUG
for (DINode *Op : getElements())
assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
"Lost a member during member list replacement");
#endif
replaceOperandWith(4, Elements.get());
}
void replaceVTableHolder(DITypeRef VTableHolder) {
replaceOperandWith(5, VTableHolder);
}
void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
replaceOperandWith(6, TemplateParams.get());
}
/// @}
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DICompositeTypeKind ||
MD->getMetadataID() == DISubroutineTypeKind;
}
};
/// \brief Composite types.
///
/// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
/// TODO: Create a custom, unrelated node for DW_TAG_array_type.
class DICompositeType : public DICompositeTypeBase {
friend class LLVMContextImpl;
friend class MDNode;
DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
ArrayRef<Metadata *> Ops)
: DICompositeTypeBase(C, DICompositeTypeKind, Storage, Tag, Line,
RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
Flags, Ops) {}
~DICompositeType() = default;
static DICompositeType *
getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
unsigned Line, DIScopeRef Scope, DITypeRef BaseType,
uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
uint64_t Flags, DINodeArray Elements, unsigned RuntimeLang,
DITypeRef VTableHolder, DITemplateParameterArray TemplateParams,
StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
return getImpl(
Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
RuntimeLang, VTableHolder, TemplateParams.get(),
getCanonicalMDString(Context, Identifier), Storage, ShouldCreate);
}
static DICompositeType *
getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
unsigned Line, Metadata *Scope, Metadata *BaseType,
uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
unsigned Flags, Metadata *Elements, unsigned RuntimeLang,
Metadata *VTableHolder, Metadata *TemplateParams,
MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
TempDICompositeType cloneImpl() const {
return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
getScope(), getBaseType(), getSizeInBits(),
getAlignInBits(), getOffsetInBits(), getFlags(),
getElements(), getRuntimeLang(), getVTableHolder(),
getTemplateParams(), getIdentifier());
}
public:
DEFINE_MDNODE_GET(DICompositeType,
(unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t OffsetInBits,
unsigned Flags, DINodeArray Elements, unsigned RuntimeLang,
DITypeRef VTableHolder,
DITemplateParameterArray TemplateParams = nullptr,
StringRef Identifier = ""),
(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
VTableHolder, TemplateParams, Identifier))
DEFINE_MDNODE_GET(DICompositeType,
(unsigned Tag, MDString *Name, Metadata *File,
unsigned Line, Metadata *Scope, Metadata *BaseType,
uint64_t SizeInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags, Metadata *Elements,
unsigned RuntimeLang, Metadata *VTableHolder,
Metadata *TemplateParams = nullptr,
MDString *Identifier = nullptr),
(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
VTableHolder, TemplateParams, Identifier))
TempDICompositeType clone() const { return cloneImpl(); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DICompositeTypeKind;
}
};
template <class T> TypedDINodeRef<T> TypedDINodeRef<T>::get(const T *N) {
if (N)
if (auto *Composite = dyn_cast<DICompositeType>(N))
if (auto *S = Composite->getRawIdentifier())
return TypedDINodeRef<T>(S);
return TypedDINodeRef<T>(N);
}
/// \brief Type array for a subprogram.
///
/// TODO: Detach from CompositeType, and fold the array of types in directly
/// as operands.
class DISubroutineType : public DICompositeTypeBase {
friend class LLVMContextImpl;
friend class MDNode;
DISubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
ArrayRef<Metadata *> Ops)
: DICompositeTypeBase(C, DISubroutineTypeKind, Storage,
dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
Ops) {}
~DISubroutineType() = default;
static DISubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
DITypeRefArray TypeArray,
StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Flags, TypeArray.get(), Storage, ShouldCreate);
}
static DISubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
Metadata *TypeArray, StorageType Storage,
bool ShouldCreate = true);
TempDISubroutineType cloneImpl() const {
return getTemporary(getContext(), getFlags(), getTypeArray());
}
public:
DEFINE_MDNODE_GET(DISubroutineType,
(unsigned Flags, DITypeRefArray TypeArray),
(Flags, TypeArray))
DEFINE_MDNODE_GET(DISubroutineType, (unsigned Flags, Metadata *TypeArray),
(Flags, TypeArray))
TempDISubroutineType clone() const { return cloneImpl(); }
DITypeRefArray getTypeArray() const {
return cast_or_null<MDTuple>(getRawTypeArray());
}
Metadata *getRawTypeArray() const { return getRawElements(); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DISubroutineTypeKind;
}
};
/// \brief Compile unit.
class DICompileUnit : public DIScope {
friend class LLVMContextImpl;
friend class MDNode;
unsigned SourceLanguage;
bool IsOptimized;
unsigned RuntimeVersion;
unsigned EmissionKind;
uint64_t DWOId;
DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
bool IsOptimized, unsigned RuntimeVersion,
unsigned EmissionKind, uint64_t DWOId, ArrayRef<Metadata *> Ops)
: DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
DWOId(DWOId) {}
~DICompileUnit() = default;
static DICompileUnit *
getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
StringRef Producer, bool IsOptimized, StringRef Flags,
unsigned RuntimeVersion, StringRef SplitDebugFilename,
unsigned EmissionKind, DICompositeTypeArray EnumTypes,
DITypeArray RetainedTypes, DISubprogramArray Subprograms,
DIGlobalVariableArray GlobalVariables,
DIImportedEntityArray ImportedEntities, uint64_t DWOId,
StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, SourceLanguage, File,
getCanonicalMDString(Context, Producer), IsOptimized,
getCanonicalMDString(Context, Flags), RuntimeVersion,
getCanonicalMDString(Context, SplitDebugFilename),
EmissionKind, EnumTypes.get(), RetainedTypes.get(),
Subprograms.get(), GlobalVariables.get(),
ImportedEntities.get(), DWOId, Storage, ShouldCreate);
}
static DICompileUnit *
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
MDString *Producer, bool IsOptimized, MDString *Flags,
unsigned RuntimeVersion, MDString *SplitDebugFilename,
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
Metadata *Subprograms, Metadata *GlobalVariables,
Metadata *ImportedEntities, uint64_t DWOId, StorageType Storage,
bool ShouldCreate = true);
TempDICompileUnit cloneImpl() const {
return getTemporary(
getContext(), getSourceLanguage(), getFile(), getProducer(),
isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
getEmissionKind(), getEnumTypes(), getRetainedTypes(), getSubprograms(),
getGlobalVariables(), getImportedEntities(), DWOId);
}
public:
DEFINE_MDNODE_GET(DICompileUnit,
(unsigned SourceLanguage, DIFile *File, StringRef Producer,
bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
StringRef SplitDebugFilename, unsigned EmissionKind,
DICompositeTypeArray EnumTypes, DITypeArray RetainedTypes,
DISubprogramArray Subprograms,
DIGlobalVariableArray GlobalVariables,
DIImportedEntityArray ImportedEntities, uint64_t DWOId),
(SourceLanguage, File, Producer, IsOptimized, Flags,
RuntimeVersion, SplitDebugFilename, EmissionKind,
EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
ImportedEntities, DWOId))
DEFINE_MDNODE_GET(
DICompileUnit,
(unsigned SourceLanguage, Metadata *File, MDString *Producer,
bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
Metadata *RetainedTypes, Metadata *Subprograms,
Metadata *GlobalVariables, Metadata *ImportedEntities, uint64_t DWOId),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes, Subprograms,
GlobalVariables, ImportedEntities, DWOId))
TempDICompileUnit clone() const { return cloneImpl(); }
unsigned getSourceLanguage() const { return SourceLanguage; }
bool isOptimized() const { return IsOptimized; }
unsigned getRuntimeVersion() const { return RuntimeVersion; }
unsigned getEmissionKind() const { return EmissionKind; }
StringRef getProducer() const { return getStringOperand(1); }
StringRef getFlags() const { return getStringOperand(2); }
StringRef getSplitDebugFilename() const { return getStringOperand(3); }
DICompositeTypeArray getEnumTypes() const {
return cast_or_null<MDTuple>(getRawEnumTypes());
}
DITypeArray getRetainedTypes() const {
return cast_or_null<MDTuple>(getRawRetainedTypes());
}
DISubprogramArray getSubprograms() const {
return cast_or_null<MDTuple>(getRawSubprograms());
}
DIGlobalVariableArray getGlobalVariables() const {
return cast_or_null<MDTuple>(getRawGlobalVariables());
}
DIImportedEntityArray getImportedEntities() const {
return cast_or_null<MDTuple>(getRawImportedEntities());
}
unsigned getDWOId() const { return DWOId; }
MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
MDString *getRawSplitDebugFilename() const {
return getOperandAs<MDString>(3);
}
Metadata *getRawEnumTypes() const { return getOperand(4); }
Metadata *getRawRetainedTypes() const { return getOperand(5); }
Metadata *getRawSubprograms() const { return getOperand(6); }
Metadata *getRawGlobalVariables() const { return getOperand(7); }
Metadata *getRawImportedEntities() const { return getOperand(8); }
/// \brief Replace arrays.
///
/// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
/// deleted on a uniquing collision. In practice, uniquing collisions on \a
/// DICompileUnit should be fairly rare.
/// @{
void replaceEnumTypes(DICompositeTypeArray N) {
replaceOperandWith(4, N.get());
}
void replaceRetainedTypes(DITypeArray N) {
replaceOperandWith(5, N.get());
}
void replaceSubprograms(DISubprogramArray N) {
replaceOperandWith(6, N.get());
}
void replaceGlobalVariables(DIGlobalVariableArray N) {
replaceOperandWith(7, N.get());
}
void replaceImportedEntities(DIImportedEntityArray N) {
replaceOperandWith(8, N.get());
}
/// @}
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DICompileUnitKind;
}
};
/// \brief A scope for locals.
///
/// A legal scope for lexical blocks, local variables, and debug info
/// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
/// DILexicalBlockFile.
class DILocalScope : public DIScope {
protected:
DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
ArrayRef<Metadata *> Ops)
: DIScope(C, ID, Storage, Tag, Ops) {}
~DILocalScope() = default;
public:
/// \brief Get the subprogram for this scope.
///
/// Return this if it's an \a DISubprogram; otherwise, look up the scope
/// chain.
DISubprogram *getSubprogram() const;
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DISubprogramKind ||
MD->getMetadataID() == DILexicalBlockKind ||
MD->getMetadataID() == DILexicalBlockFileKind;
}
};
/// \brief Debug location.
///
/// A debug location in source code, used for debug info and otherwise.
class DILocation : public MDNode {
friend class LLVMContextImpl;
friend class MDNode;
DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Column, ArrayRef<Metadata *> MDs);
~DILocation() { dropAllReferences(); }
static DILocation *getImpl(LLVMContext &Context, unsigned Line,
unsigned Column, Metadata *Scope,
Metadata *InlinedAt, StorageType Storage,
bool ShouldCreate = true);
static DILocation *getImpl(LLVMContext &Context, unsigned Line,
unsigned Column, DILocalScope *Scope,
DILocation *InlinedAt, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
}
TempDILocation cloneImpl() const {
return getTemporary(getContext(), getLine(), getColumn(), getScope(),
getInlinedAt());
}
// Disallow replacing operands.
void replaceOperandWith(unsigned I, Metadata *New) = delete;
public:
DEFINE_MDNODE_GET(DILocation,
(unsigned Line, unsigned Column, Metadata *Scope,
Metadata *InlinedAt = nullptr),
(Line, Column, Scope, InlinedAt))
DEFINE_MDNODE_GET(DILocation,
(unsigned Line, unsigned Column, DILocalScope *Scope,
DILocation *InlinedAt = nullptr),
(Line, Column, Scope, InlinedAt))
/// \brief Return a (temporary) clone of this.
TempDILocation clone() const { return cloneImpl(); }
unsigned getLine() const { return SubclassData32; }
unsigned getColumn() const { return SubclassData16; }
DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
DILocation *getInlinedAt() const {
return cast_or_null<DILocation>(getRawInlinedAt());
}
DIFile *getFile() const { return getScope()->getFile(); }
StringRef getFilename() const { return getScope()->getFilename(); }
StringRef getDirectory() const { return getScope()->getDirectory(); }
/// \brief Get the scope where this is inlined.
///
/// Walk through \a getInlinedAt() and return \a getScope() from the deepest
/// location.
DILocalScope *getInlinedAtScope() const {
if (auto *IA = getInlinedAt())
return IA->getInlinedAtScope();
return getScope();
}
/// \brief Check whether this can be discriminated from another location.
///
/// Check \c this can be discriminated from \c RHS in a linetable entry.
/// Scope and inlined-at chains are not recorded in the linetable, so they
/// cannot be used to distinguish basic blocks.
///
/// The current implementation is weaker than it should be, since it just
/// checks filename and line.
///
/// FIXME: Add a check for getDiscriminator().
/// FIXME: Add a check for getColumn().
/// FIXME: Change the getFilename() check to getFile() (or add one for
/// getDirectory()).
bool canDiscriminate(const DILocation &RHS) const {
return getFilename() != RHS.getFilename() || getLine() != RHS.getLine();
}
/// \brief Get the DWARF discriminator.
///
/// DWARF discriminators distinguish identical file locations between
/// instructions that are on different basic blocks.
inline unsigned getDiscriminator() const;
/// \brief Compute new discriminator in the given context.
///
/// This modifies the \a LLVMContext that \c this is in to increment the next
/// discriminator for \c this's line/filename combination.
///
/// FIXME: Delete this. See comments in implementation and at the only call
/// site in \a AddDiscriminators::runOnFunction().
unsigned computeNewDiscriminator() const;
Metadata *getRawScope() const { return getOperand(0); }
Metadata *getRawInlinedAt() const {
if (getNumOperands() == 2)
return getOperand(1);
return nullptr;
}
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DILocationKind;
}
};
/// \brief Subprogram description.
///
/// TODO: Remove DisplayName. It's always equal to Name.
/// TODO: Split up flags.
class DISubprogram : public DILocalScope {
friend class LLVMContextImpl;
friend class MDNode;
unsigned Line;
unsigned ScopeLine;
unsigned Virtuality;
unsigned VirtualIndex;
unsigned Flags;
bool IsLocalToUnit;
bool IsDefinition;
bool IsOptimized;
DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
bool IsOptimized, ArrayRef<Metadata *> Ops)
: DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram,
Ops),
Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
~DISubprogram() = default;
static DISubprogram *
getImpl(LLVMContext &Context, DIScopeRef Scope, StringRef Name,
StringRef LinkageName, DIFile *File, unsigned Line,
DISubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
unsigned ScopeLine, DITypeRef ContainingType, unsigned Virtuality,
unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
Constant *Function, DITemplateParameterArray TemplateParams,
DISubprogram *Declaration, DILocalVariableArray Variables,
StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
getCanonicalMDString(Context, LinkageName), File, Line, Type,
IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
Virtuality, VirtualIndex, Flags, IsOptimized,
Function ? ConstantAsMetadata::get(Function) : nullptr,
TemplateParams.get(), Declaration, Variables.get(), Storage,
ShouldCreate);
}
static DISubprogram *
getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
unsigned Flags, bool IsOptimized, Metadata *Function,
Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
StorageType Storage, bool ShouldCreate = true);
TempDISubprogram cloneImpl() const {
return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
getFile(), getLine(), getType(), isLocalToUnit(),
isDefinition(), getScopeLine(), getContainingType(),
getVirtuality(), getVirtualIndex(), getFlags(),
isOptimized(), getFunctionConstant(),
getTemplateParams(), getDeclaration(), getVariables());
}
public:
DEFINE_MDNODE_GET(DISubprogram,
(DIScopeRef Scope, StringRef Name, StringRef LinkageName,
DIFile *File, unsigned Line, DISubroutineType *Type,
bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
DITypeRef ContainingType, unsigned Virtuality,
unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
Constant *Function = nullptr,
DITemplateParameterArray TemplateParams = nullptr,
DISubprogram *Declaration = nullptr,
DILocalVariableArray Variables = nullptr),
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
IsDefinition, ScopeLine, ContainingType, Virtuality,
VirtualIndex, Flags, IsOptimized, Function, TemplateParams,
Declaration, Variables))
DEFINE_MDNODE_GET(
DISubprogram,
(Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File,
unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
Function, TemplateParams, Declaration, Variables))
TempDISubprogram clone() const { return cloneImpl(); }
public:
unsigned getLine() const { return Line; }
unsigned getVirtuality() const { return Virtuality; }
unsigned getVirtualIndex() const { return VirtualIndex; }
unsigned getScopeLine() const { return ScopeLine; }
unsigned getFlags() const { return Flags; }
bool isLocalToUnit() const { return IsLocalToUnit; }
bool isDefinition() const { return IsDefinition; }
bool isOptimized() const { return IsOptimized; }
unsigned isArtificial() const { return getFlags() & FlagArtificial; }
bool isPrivate() const {
return (getFlags() & FlagAccessibility) == FlagPrivate;
}
bool isProtected() const {
return (getFlags() & FlagAccessibility) == FlagProtected;
}
bool isPublic() const {
return (getFlags() & FlagAccessibility) == FlagPublic;
}
bool isExplicit() const { return getFlags() & FlagExplicit; }
bool isPrototyped() const { return getFlags() & FlagPrototyped; }
/// \brief Check if this is reference-qualified.
///
/// Return true if this subprogram is a C++11 reference-qualified non-static
/// member function (void foo() &).
unsigned isLValueReference() const {
return getFlags() & FlagLValueReference;
}
/// \brief Check if this is rvalue-reference-qualified.
///
/// Return true if this subprogram is a C++11 rvalue-reference-qualified
/// non-static member function (void foo() &&).
unsigned isRValueReference() const {
return getFlags() & FlagRValueReference;
}
DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
StringRef getName() const { return getStringOperand(2); }
StringRef getDisplayName() const { return getStringOperand(3); }
StringRef getLinkageName() const { return getStringOperand(4); }
MDString *getRawName() const { return getOperandAs<MDString>(2); }
MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
DISubroutineType *getType() const {
return cast_or_null<DISubroutineType>(getRawType());
}
DITypeRef getContainingType() const {
return DITypeRef(getRawContainingType());
}
Constant *getFunctionConstant() const {
if (auto *C = cast_or_null<ConstantAsMetadata>(getRawFunction()))
return C->getValue();
return nullptr;
}
DITemplateParameterArray getTemplateParams() const {
return cast_or_null<MDTuple>(getRawTemplateParams());
}
DISubprogram *getDeclaration() const {
return cast_or_null<DISubprogram>(getRawDeclaration());
}
DILocalVariableArray getVariables() const {
return cast_or_null<MDTuple>(getRawVariables());
}
Metadata *getRawScope() const { return getOperand(1); }
Metadata *getRawType() const { return getOperand(5); }
Metadata *getRawContainingType() const { return getOperand(6); }
Metadata *getRawFunction() const { return getOperand(7); }
Metadata *getRawTemplateParams() const { return getOperand(8); }
Metadata *getRawDeclaration() const { return getOperand(9); }
Metadata *getRawVariables() const { return getOperand(10); }
/// \brief Get a pointer to the function this subprogram describes.
///
/// This dyn_casts \a getFunctionConstant() to \a Function.
///
/// FIXME: Should this be looking through bitcasts?
Function *getFunction() const;
/// \brief Replace the function.
///
/// If \a isUniqued() and not \a isResolved(), this could node will be
/// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
/// that's a problem.
/// @{
void replaceFunction(Function *F);
void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
/// @}
/// \brief Check if this subprogram decribes the given function.
///
/// FIXME: Should this be looking through bitcasts?
bool describes(const Function *F) const;
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DISubprogramKind;
}
};
class DILexicalBlockBase : public DILocalScope {
protected:
DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
ArrayRef<Metadata *> Ops)
: DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
~DILexicalBlockBase() = default;
public:
DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); }
Metadata *getRawScope() const { return getOperand(1); }
/// \brief Forwarding accessors to LexicalBlock.
///
/// TODO: Remove these and update code to use \a DILexicalBlock directly.
/// @{
inline unsigned getLine() const;
inline unsigned getColumn() const;
/// @}
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DILexicalBlockKind ||
MD->getMetadataID() == DILexicalBlockFileKind;
}
};
class DILexicalBlock : public DILexicalBlockBase {
friend class LLVMContextImpl;
friend class MDNode;
unsigned Line;
unsigned Column;
DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Column, ArrayRef<Metadata *> Ops)
: DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
Column(Column) {}
~DILexicalBlock() = default;
static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope,
DIFile *File, unsigned Line, unsigned Column,
StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, static_cast<Metadata *>(Scope),
static_cast<Metadata *>(File), Line, Column, Storage,
ShouldCreate);
}
static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope,
Metadata *File, unsigned Line, unsigned Column,
StorageType Storage, bool ShouldCreate = true);
TempDILexicalBlock cloneImpl() const {
return getTemporary(getContext(), getScope(), getFile(), getLine(),
getColumn());
}
public:
DEFINE_MDNODE_GET(DILexicalBlock, (DILocalScope * Scope, DIFile *File,
unsigned Line, unsigned Column),
(Scope, File, Line, Column))
DEFINE_MDNODE_GET(DILexicalBlock, (Metadata * Scope, Metadata *File,
unsigned Line, unsigned Column),
(Scope, File, Line, Column))
TempDILexicalBlock clone() const { return cloneImpl(); }
unsigned getLine() const { return Line; }
unsigned getColumn() const { return Column; }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DILexicalBlockKind;
}
};
unsigned DILexicalBlockBase::getLine() const {
if (auto *N = dyn_cast<DILexicalBlock>(this))
return N->getLine();
return 0;
}
unsigned DILexicalBlockBase::getColumn() const {
if (auto *N = dyn_cast<DILexicalBlock>(this))
return N->getColumn();
return 0;
}
class DILexicalBlockFile : public DILexicalBlockBase {
friend class LLVMContextImpl;
friend class MDNode;
unsigned Discriminator;
DILexicalBlockFile(LLVMContext &C, StorageType Storage,
unsigned Discriminator, ArrayRef<Metadata *> Ops)
: DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops),
Discriminator(Discriminator) {}
~DILexicalBlockFile() = default;
static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
DIFile *File, unsigned Discriminator,
StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, static_cast<Metadata *>(Scope),
static_cast<Metadata *>(File), Discriminator, Storage,
ShouldCreate);
}
static DILexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope,
Metadata *File, unsigned Discriminator,
StorageType Storage,
bool ShouldCreate = true);
TempDILexicalBlockFile cloneImpl() const {
return getTemporary(getContext(), getScope(), getFile(),
getDiscriminator());
}
public:
DEFINE_MDNODE_GET(DILexicalBlockFile, (DILocalScope * Scope, DIFile *File,
unsigned Discriminator),
(Scope, File, Discriminator))
DEFINE_MDNODE_GET(DILexicalBlockFile,
(Metadata * Scope, Metadata *File, unsigned Discriminator),
(Scope, File, Discriminator))
TempDILexicalBlockFile clone() const { return cloneImpl(); }
// TODO: Remove these once they're gone from DILexicalBlockBase.
unsigned getLine() const = delete;
unsigned getColumn() const = delete;
unsigned getDiscriminator() const { return Discriminator; }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DILexicalBlockFileKind;
}
};
unsigned DILocation::getDiscriminator() const {
if (auto *F = dyn_cast<DILexicalBlockFile>(getScope()))
return F->getDiscriminator();
return 0;
}
class DINamespace : public DIScope {
friend class LLVMContextImpl;
friend class MDNode;
unsigned Line;
DINamespace(LLVMContext &Context, StorageType Storage, unsigned Line,
ArrayRef<Metadata *> Ops)
: DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace,
Ops),
Line(Line) {}
~DINamespace() = default;
static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope,
DIFile *File, StringRef Name, unsigned Line,
StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
Line, Storage, ShouldCreate);
}
static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope,
Metadata *File, MDString *Name, unsigned Line,
StorageType Storage, bool ShouldCreate = true);
TempDINamespace cloneImpl() const {
return getTemporary(getContext(), getScope(), getFile(), getName(),
getLine());
}
public:
DEFINE_MDNODE_GET(DINamespace, (DIScope * Scope, DIFile *File, StringRef Name,
unsigned Line),
(Scope, File, Name, Line))
DEFINE_MDNODE_GET(DINamespace, (Metadata * Scope, Metadata *File,
MDString *Name, unsigned Line),
(Scope, File, Name, Line))
TempDINamespace clone() const { return cloneImpl(); }
unsigned getLine() const { return Line; }
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
StringRef getName() const { return getStringOperand(2); }
Metadata *getRawScope() const { return getOperand(1); }
MDString *getRawName() const { return getOperandAs<MDString>(2); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DINamespaceKind;
}
};
/// \brief A (clang) module that has been imported by the compile unit.
///
class DIModule : public DIScope {
friend class LLVMContextImpl;
friend class MDNode;
DIModule(LLVMContext &Context, StorageType Storage, ArrayRef<Metadata *> Ops)
: DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
~DIModule() {}
static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
StringRef Name, StringRef ConfigurationMacros,
StringRef IncludePath, StringRef ISysRoot,
StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
getCanonicalMDString(Context, ConfigurationMacros),
getCanonicalMDString(Context, IncludePath),
getCanonicalMDString(Context, ISysRoot),
Storage, ShouldCreate);
}
static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, MDString *ConfigurationMacros,
MDString *IncludePath, MDString *ISysRoot,
StorageType Storage, bool ShouldCreate = true);
TempDIModule cloneImpl() const {
return getTemporary(getContext(), getScope(), getName(),
getConfigurationMacros(), getIncludePath(),
getISysRoot());
}
public:
DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name,
StringRef ConfigurationMacros, StringRef IncludePath,
StringRef ISysRoot),
(Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
DEFINE_MDNODE_GET(DIModule,
(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
MDString *IncludePath, MDString *ISysRoot),
(Scope, Name, ConfigurationMacros, IncludePath, ISysRoot))
TempDIModule clone() const { return cloneImpl(); }
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
StringRef getName() const { return getStringOperand(1); }
StringRef getConfigurationMacros() const { return getStringOperand(2); }
StringRef getIncludePath() const { return getStringOperand(3); }
StringRef getISysRoot() const { return getStringOperand(4); }
Metadata *getRawScope() const { return getOperand(0); }
MDString *getRawName() const { return getOperandAs<MDString>(1); }
MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
MDString *getRawISysRoot() const { return getOperandAs<MDString>(4); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIModuleKind;
}
};
/// \brief Base class for template parameters.
class DITemplateParameter : public DINode {
protected:
DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
unsigned Tag, ArrayRef<Metadata *> Ops)
: DINode(Context, ID, Storage, Tag, Ops) {}
~DITemplateParameter() = default;
public:
StringRef getName() const { return getStringOperand(0); }
DITypeRef getType() const { return DITypeRef(getRawType()); }
MDString *getRawName() const { return getOperandAs<MDString>(0); }
Metadata *getRawType() const { return getOperand(1); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DITemplateTypeParameterKind ||
MD->getMetadataID() == DITemplateValueParameterKind;
}
};
class DITemplateTypeParameter : public DITemplateParameter {
friend class LLVMContextImpl;
friend class MDNode;
DITemplateTypeParameter(LLVMContext &Context, StorageType Storage,
ArrayRef<Metadata *> Ops)
: DITemplateParameter(Context, DITemplateTypeParameterKind, Storage,
dwarf::DW_TAG_template_type_parameter, Ops) {}
~DITemplateTypeParameter() = default;
static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name,
DITypeRef Type, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage,
ShouldCreate);
}
static DITemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name,
Metadata *Type, StorageType Storage,
bool ShouldCreate = true);
TempDITemplateTypeParameter cloneImpl() const {
return getTemporary(getContext(), getName(), getType());
}
public:
DEFINE_MDNODE_GET(DITemplateTypeParameter, (StringRef Name, DITypeRef Type),
(Name, Type))
DEFINE_MDNODE_GET(DITemplateTypeParameter, (MDString * Name, Metadata *Type),
(Name, Type))
TempDITemplateTypeParameter clone() const { return cloneImpl(); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DITemplateTypeParameterKind;
}
};
class DITemplateValueParameter : public DITemplateParameter {
friend class LLVMContextImpl;
friend class MDNode;
DITemplateValueParameter(LLVMContext &Context, StorageType Storage,
unsigned Tag, ArrayRef<Metadata *> Ops)
: DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag,
Ops) {}
~DITemplateValueParameter() = default;
static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
StringRef Name, DITypeRef Type,
Metadata *Value, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type,
Value, Storage, ShouldCreate);
}
static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag,
MDString *Name, Metadata *Type,
Metadata *Value, StorageType Storage,
bool ShouldCreate = true);
TempDITemplateValueParameter cloneImpl() const {
return getTemporary(getContext(), getTag(), getName(), getType(),
getValue());
}
public:
DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, StringRef Name,
DITypeRef Type, Metadata *Value),
(Tag, Name, Type, Value))
DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, MDString *Name,
Metadata *Type, Metadata *Value),
(Tag, Name, Type, Value))
TempDITemplateValueParameter clone() const { return cloneImpl(); }
Metadata *getValue() const { return getOperand(2); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DITemplateValueParameterKind;
}
};
/// \brief Base class for variables.
///
/// TODO: Hardcode to DW_TAG_variable.
class DIVariable : public DINode {
unsigned Line;
protected:
DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
unsigned Line, ArrayRef<Metadata *> Ops)
: DINode(C, ID, Storage, Tag, Ops), Line(Line) {}
~DIVariable() = default;
public:
unsigned getLine() const { return Line; }
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
StringRef getName() const { return getStringOperand(1); }
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
DITypeRef getType() const { return DITypeRef(getRawType()); }
StringRef getFilename() const {
if (auto *F = getFile())
return F->getFilename();
return "";
}
StringRef getDirectory() const {
if (auto *F = getFile())
return F->getDirectory();
return "";
}
void setScope(DIScope *scope) { setOperand(0, scope); } // HLSL Change
Metadata *getRawScope() const { return getOperand(0); }
MDString *getRawName() const { return getOperandAs<MDString>(1); }
Metadata *getRawFile() const { return getOperand(2); }
Metadata *getRawType() const { return getOperand(3); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DILocalVariableKind ||
MD->getMetadataID() == DIGlobalVariableKind;
}
};
/// \brief Global variables.
///
/// TODO: Remove DisplayName. It's always equal to Name.
class DIGlobalVariable : public DIVariable {
friend class LLVMContextImpl;
friend class MDNode;
bool IsLocalToUnit;
bool IsDefinition;
DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
bool IsLocalToUnit, bool IsDefinition,
ArrayRef<Metadata *> Ops)
: DIVariable(C, DIGlobalVariableKind, Storage, dwarf::DW_TAG_variable,
Line, Ops),
IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
~DIGlobalVariable() = default;
static DIGlobalVariable *
getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type,
bool IsLocalToUnit, bool IsDefinition, Constant *Variable,
DIDerivedType *StaticDataMemberDeclaration, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
getCanonicalMDString(Context, LinkageName), File, Line, Type,
IsLocalToUnit, IsDefinition,
Variable ? ConstantAsMetadata::get(Variable) : nullptr,
StaticDataMemberDeclaration, Storage, ShouldCreate);
}
static DIGlobalVariable *
getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
Metadata *StaticDataMemberDeclaration, StorageType Storage,
bool ShouldCreate = true);
TempDIGlobalVariable cloneImpl() const {
return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
getFile(), getLine(), getType(), isLocalToUnit(),
isDefinition(), getVariable(),
getStaticDataMemberDeclaration());
}
public:
DEFINE_MDNODE_GET(DIGlobalVariable,
(DIScope * Scope, StringRef Name, StringRef LinkageName,
DIFile *File, unsigned Line, DITypeRef Type,
bool IsLocalToUnit, bool IsDefinition, Constant *Variable,
DIDerivedType *StaticDataMemberDeclaration),
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
IsDefinition, Variable, StaticDataMemberDeclaration))
DEFINE_MDNODE_GET(DIGlobalVariable,
(Metadata * Scope, MDString *Name, MDString *LinkageName,
Metadata *File, unsigned Line, Metadata *Type,
bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
Metadata *StaticDataMemberDeclaration),
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
IsDefinition, Variable, StaticDataMemberDeclaration))
TempDIGlobalVariable clone() const { return cloneImpl(); }
bool isLocalToUnit() const { return IsLocalToUnit; }
bool isDefinition() const { return IsDefinition; }
StringRef getDisplayName() const { return getStringOperand(4); }
StringRef getLinkageName() const { return getStringOperand(5); }
Constant *getVariable() const {
if (auto *C = cast_or_null<ConstantAsMetadata>(getRawVariable()))
return dyn_cast<Constant>(C->getValue());
return nullptr;
}
DIDerivedType *getStaticDataMemberDeclaration() const {
return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration());
}
MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); }
Metadata *getRawVariable() const { return getOperand(6); }
Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(7); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIGlobalVariableKind;
}
};
/// \brief Local variable.
///
/// TODO: Split between arguments and otherwise.
/// TODO: Use \c DW_TAG_variable instead of fake tags.
/// TODO: Split up flags.
class DILocalVariable : public DIVariable {
friend class LLVMContextImpl;
friend class MDNode;
unsigned Arg;
unsigned Flags;
DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Tag,
unsigned Line, unsigned Arg, unsigned Flags,
ArrayRef<Metadata *> Ops)
: DIVariable(C, DILocalVariableKind, Storage, Tag, Line, Ops), Arg(Arg),
Flags(Flags) {}
~DILocalVariable() = default;
static DILocalVariable *getImpl(LLVMContext &Context, unsigned Tag,
DIScope *Scope, StringRef Name, DIFile *File,
unsigned Line, DITypeRef Type, unsigned Arg,
unsigned Flags, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Tag, Scope, getCanonicalMDString(Context, Name),
File, Line, Type, Arg, Flags, Storage, ShouldCreate);
}
static DILocalVariable *
getImpl(LLVMContext &Context, unsigned Tag, Metadata *Scope, MDString *Name,
Metadata *File, unsigned Line, Metadata *Type, unsigned Arg,
unsigned Flags, StorageType Storage, bool ShouldCreate = true);
TempDILocalVariable cloneImpl() const {
return getTemporary(getContext(), getTag(), getScope(), getName(),
getFile(), getLine(), getType(), getArg(), getFlags());
}
public:
DEFINE_MDNODE_GET(DILocalVariable,
(unsigned Tag, DILocalScope *Scope, StringRef Name,
DIFile *File, unsigned Line, DITypeRef Type, unsigned Arg,
unsigned Flags),
(Tag, Scope, Name, File, Line, Type, Arg, Flags))
DEFINE_MDNODE_GET(DILocalVariable,
(unsigned Tag, Metadata *Scope, MDString *Name,
Metadata *File, unsigned Line, Metadata *Type,
unsigned Arg, unsigned Flags),
(Tag, Scope, Name, File, Line, Type, Arg, Flags))
TempDILocalVariable clone() const { return cloneImpl(); }
/// \brief Get the local scope for this variable.
///
/// Variables must be defined in a local scope.
DILocalScope *getScope() const {
return cast<DILocalScope>(DIVariable::getScope());
}
unsigned getArg() const { return Arg; }
unsigned getFlags() const { return Flags; }
bool isArtificial() const { return getFlags() & FlagArtificial; }
bool isObjectPointer() const { return getFlags() & FlagObjectPointer; }
/// \brief Check that a location is valid for this variable.
///
/// Check that \c DL exists, is in the same subprogram, and has the same
/// inlined-at location as \c this. (Otherwise, it's not a valid attachemnt
/// to a \a DbgInfoIntrinsic.)
bool isValidLocationForIntrinsic(const DILocation *DL) const {
return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram();
}
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DILocalVariableKind;
}
};
/// \brief DWARF expression.
///
/// This is (almost) a DWARF expression that modifies the location of a
/// variable or (or the location of a single piece of a variable).
///
/// FIXME: Instead of DW_OP_plus taking an argument, this should use DW_OP_const
/// and have DW_OP_plus consume the topmost elements on the stack.
///
/// TODO: Co-allocate the expression elements.
/// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary
/// storage types.
class DIExpression : public MDNode {
friend class LLVMContextImpl;
friend class MDNode;
std::vector<uint64_t> Elements;
DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
: MDNode(C, DIExpressionKind, Storage, None),
Elements(Elements.begin(), Elements.end()) {}
~DIExpression() = default;
static DIExpression *getImpl(LLVMContext &Context,
ArrayRef<uint64_t> Elements, StorageType Storage,
bool ShouldCreate = true);
TempDIExpression cloneImpl() const {
return getTemporary(getContext(), getElements());
}
public:
DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements))
TempDIExpression clone() const { return cloneImpl(); }
ArrayRef<uint64_t> getElements() const { return Elements; }
unsigned getNumElements() const { return Elements.size(); }
uint64_t getElement(unsigned I) const {
assert(I < Elements.size() && "Index out of range");
return Elements[I];
}
/// \brief Return whether this is a piece of an aggregate variable.
bool isBitPiece() const;
/// \brief Return the offset of this piece in bits.
uint64_t getBitPieceOffset() const;
/// \brief Return the size of this piece in bits.
uint64_t getBitPieceSize() const;
typedef ArrayRef<uint64_t>::iterator element_iterator;
element_iterator elements_begin() const { return getElements().begin(); }
element_iterator elements_end() const { return getElements().end(); }
/// \brief A lightweight wrapper around an expression operand.
///
/// TODO: Store arguments directly and change \a DIExpression to store a
/// range of these.
class ExprOperand {
const uint64_t *Op;
public:
explicit ExprOperand(const uint64_t *Op) : Op(Op) {}
const uint64_t *get() const { return Op; }
/// \brief Get the operand code.
uint64_t getOp() const { return *Op; }
/// \brief Get an argument to the operand.
///
/// Never returns the operand itself.
uint64_t getArg(unsigned I) const { return Op[I + 1]; }
unsigned getNumArgs() const { return getSize() - 1; }
/// \brief Return the size of the operand.
///
/// Return the number of elements in the operand (1 + args).
unsigned getSize() const;
};
/// \brief An iterator for expression operands.
class expr_op_iterator {
ExprOperand Op;
public:
using iterator_category = std::input_iterator_tag;
using value_type = ExprOperand;
using difference_type = std::ptrdiff_t;
using pointer = value_type *;
using reference = value_type &;
explicit expr_op_iterator(element_iterator I) : Op(I) {}
element_iterator getBase() const { return Op.get(); }
const ExprOperand &operator*() const { return Op; }
const ExprOperand *operator->() const { return &Op; }
expr_op_iterator &operator++() {
increment();
return *this;
}
expr_op_iterator operator++(int) {
expr_op_iterator T(*this);
increment();
return T;
}
/// \brief Get the next iterator.
///
/// \a std::next() doesn't work because this is technically an
/// input_iterator, but it's a perfectly valid operation. This is an
/// accessor to provide the same functionality.
expr_op_iterator getNext() const { return ++expr_op_iterator(*this); }
bool operator==(const expr_op_iterator &X) const {
return getBase() == X.getBase();
}
bool operator!=(const expr_op_iterator &X) const {
return getBase() != X.getBase();
}
private:
void increment() { Op = ExprOperand(getBase() + Op.getSize()); }
};
/// \brief Visit the elements via ExprOperand wrappers.
///
/// These range iterators visit elements through \a ExprOperand wrappers.
/// This is not guaranteed to be a valid range unless \a isValid() gives \c
/// true.
///
/// \pre \a isValid() gives \c true.
/// @{
expr_op_iterator expr_op_begin() const {
return expr_op_iterator(elements_begin());
}
expr_op_iterator expr_op_end() const {
return expr_op_iterator(elements_end());
}
/// @}
bool isValid() const;
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIExpressionKind;
}
};
class DIObjCProperty : public DINode {
friend class LLVMContextImpl;
friend class MDNode;
unsigned Line;
unsigned Attributes;
DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Attributes, ArrayRef<Metadata *> Ops)
: DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property,
Ops),
Line(Line), Attributes(Attributes) {}
~DIObjCProperty() = default;
static DIObjCProperty *
getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
StringRef GetterName, StringRef SetterName, unsigned Attributes,
DITypeRef Type, StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
getCanonicalMDString(Context, GetterName),
getCanonicalMDString(Context, SetterName), Attributes, Type,
Storage, ShouldCreate);
}
static DIObjCProperty *getImpl(LLVMContext &Context, MDString *Name,
Metadata *File, unsigned Line,
MDString *GetterName, MDString *SetterName,
unsigned Attributes, Metadata *Type,
StorageType Storage, bool ShouldCreate = true);
TempDIObjCProperty cloneImpl() const {
return getTemporary(getContext(), getName(), getFile(), getLine(),
getGetterName(), getSetterName(), getAttributes(),
getType());
}
public:
DEFINE_MDNODE_GET(DIObjCProperty,
(StringRef Name, DIFile *File, unsigned Line,
StringRef GetterName, StringRef SetterName,
unsigned Attributes, DITypeRef Type),
(Name, File, Line, GetterName, SetterName, Attributes,
Type))
DEFINE_MDNODE_GET(DIObjCProperty,
(MDString * Name, Metadata *File, unsigned Line,
MDString *GetterName, MDString *SetterName,
unsigned Attributes, Metadata *Type),
(Name, File, Line, GetterName, SetterName, Attributes,
Type))
TempDIObjCProperty clone() const { return cloneImpl(); }
unsigned getLine() const { return Line; }
unsigned getAttributes() const { return Attributes; }
StringRef getName() const { return getStringOperand(0); }
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
StringRef getGetterName() const { return getStringOperand(2); }
StringRef getSetterName() const { return getStringOperand(3); }
DITypeRef getType() const { return DITypeRef(getRawType()); }
StringRef getFilename() const {
if (auto *F = getFile())
return F->getFilename();
return "";
}
StringRef getDirectory() const {
if (auto *F = getFile())
return F->getDirectory();
return "";
}
MDString *getRawName() const { return getOperandAs<MDString>(0); }
Metadata *getRawFile() const { return getOperand(1); }
MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
Metadata *getRawType() const { return getOperand(4); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIObjCPropertyKind;
}
};
/// \brief An imported module (C++ using directive or similar).
class DIImportedEntity : public DINode {
friend class LLVMContextImpl;
friend class MDNode;
unsigned Line;
DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
unsigned Line, ArrayRef<Metadata *> Ops)
: DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
~DIImportedEntity() = default;
static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
DIScope *Scope, DINodeRef Entity,
unsigned Line, StringRef Name,
StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Tag, Scope, Entity, Line,
getCanonicalMDString(Context, Name), Storage, ShouldCreate);
}
static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
Metadata *Scope, Metadata *Entity,
unsigned Line, MDString *Name,
StorageType Storage,
bool ShouldCreate = true);
TempDIImportedEntity cloneImpl() const {
return getTemporary(getContext(), getTag(), getScope(), getEntity(),
getLine(), getName());
}
public:
DEFINE_MDNODE_GET(DIImportedEntity,
(unsigned Tag, DIScope *Scope, DINodeRef Entity,
unsigned Line, StringRef Name = ""),
(Tag, Scope, Entity, Line, Name))
DEFINE_MDNODE_GET(DIImportedEntity,
(unsigned Tag, Metadata *Scope, Metadata *Entity,
unsigned Line, MDString *Name),
(Tag, Scope, Entity, Line, Name))
TempDIImportedEntity clone() const { return cloneImpl(); }
unsigned getLine() const { return Line; }
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
DINodeRef getEntity() const { return DINodeRef(getRawEntity()); }
StringRef getName() const { return getStringOperand(2); }
Metadata *getRawScope() const { return getOperand(0); }
Metadata *getRawEntity() const { return getOperand(1); }
MDString *getRawName() const { return getOperandAs<MDString>(2); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIImportedEntityKind;
}
};
} // end namespace llvm
#undef DEFINE_MDNODE_GET_UNPACK_IMPL
#undef DEFINE_MDNODE_GET_UNPACK
#undef DEFINE_MDNODE_GET
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/InstrTypes.h | //===-- llvm/InstrTypes.h - Important Instruction subclasses ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines various meta classes of instructions that exist in the VM
// representation. Specific concrete subclasses of these may be found in the
// i*.h files...
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_INSTRTYPES_H
#define LLVM_IR_INSTRTYPES_H
#include "llvm/ADT/Twine.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/OperandTraits.h"
namespace llvm {
class LLVMContext;
//===----------------------------------------------------------------------===//
// TerminatorInst Class
//===----------------------------------------------------------------------===//
/// Subclasses of this class are all able to terminate a basic
/// block. Thus, these are all the flow control type of operations.
///
class TerminatorInst : public Instruction {
protected:
TerminatorInst(Type *Ty, Instruction::TermOps iType,
Use *Ops, unsigned NumOps,
Instruction *InsertBefore = nullptr)
: Instruction(Ty, iType, Ops, NumOps, InsertBefore) {}
TerminatorInst(Type *Ty, Instruction::TermOps iType,
Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
: Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
// Out of line virtual method, so the vtable, etc has a home.
~TerminatorInst() override;
/// Virtual methods - Terminators should overload these and provide inline
/// overrides of non-V methods.
virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
virtual unsigned getNumSuccessorsV() const = 0;
virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
public:
/// Return the number of successors that this terminator has.
unsigned getNumSuccessors() const {
return getNumSuccessorsV();
}
/// Return the specified successor.
BasicBlock *getSuccessor(unsigned idx) const {
return getSuccessorV(idx);
}
/// Update the specified successor to point at the provided block.
void setSuccessor(unsigned idx, BasicBlock *B) {
setSuccessorV(idx, B);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
return I->isTerminator();
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
//===----------------------------------------------------------------------===//
// UnaryInstruction Class
//===----------------------------------------------------------------------===//
class UnaryInstruction : public Instruction {
void *operator new(size_t, unsigned) = delete;
protected:
UnaryInstruction(Type *Ty, unsigned iType, Value *V,
Instruction *IB = nullptr)
: Instruction(Ty, iType, &Op<0>(), 1, IB) {
Op<0>() = V;
}
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
: Instruction(Ty, iType, &Op<0>(), 1, IAE) {
Op<0>() = V;
}
public:
// allocate space for exactly one operand
void *operator new(size_t s) {
return User::operator new(s, 1);
}
// Out of line virtual method, so the vtable, etc has a home.
~UnaryInstruction() override;
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Alloca ||
I->getOpcode() == Instruction::Load ||
I->getOpcode() == Instruction::VAArg ||
I->getOpcode() == Instruction::ExtractValue ||
(I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
template <>
struct OperandTraits<UnaryInstruction> :
public FixedNumOperandTraits<UnaryInstruction, 1> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
//===----------------------------------------------------------------------===//
// BinaryOperator Class
//===----------------------------------------------------------------------===//
class BinaryOperator : public Instruction {
void *operator new(size_t, unsigned) = delete;
protected:
void init(BinaryOps iType);
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
const Twine &Name, Instruction *InsertBefore);
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
const Twine &Name, BasicBlock *InsertAtEnd);
// Note: Instruction needs to be a friend here to call cloneImpl.
friend class Instruction;
BinaryOperator *cloneImpl() const;
public:
// allocate space for exactly two operands
void *operator new(size_t s) {
return User::operator new(s, 2);
}
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
/// Construct a binary instruction, given the opcode and the two
/// operands. Optionally (if InstBefore is specified) insert the instruction
/// into a BasicBlock right before the specified instruction. The specified
/// Instruction is allowed to be a dereferenced end iterator.
///
static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
const Twine &Name = Twine(),
Instruction *InsertBefore = nullptr);
/// Construct a binary instruction, given the opcode and the two
/// operands. Also automatically insert this instruction to the end of the
/// BasicBlock specified.
///
static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
const Twine &Name, BasicBlock *InsertAtEnd);
/// These methods just forward to Create, and are useful when you
/// statically know what type of instruction you're going to create. These
/// helpers just save some typing.
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name = "") {\
return Create(Instruction::OPC, V1, V2, Name);\
}
#include "llvm/IR/Instruction.def"
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name, BasicBlock *BB) {\
return Create(Instruction::OPC, V1, V2, Name, BB);\
}
#include "llvm/IR/Instruction.def"
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name, Instruction *I) {\
return Create(Instruction::OPC, V1, V2, Name, I);\
}
#include "llvm/IR/Instruction.def"
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name = "") {
BinaryOperator *BO = Create(Opc, V1, V2, Name);
BO->setHasNoSignedWrap(true);
return BO;
}
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock *BB) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
BO->setHasNoSignedWrap(true);
return BO;
}
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
BO->setHasNoSignedWrap(true);
return BO;
}
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name = "") {
BinaryOperator *BO = Create(Opc, V1, V2, Name);
BO->setHasNoUnsignedWrap(true);
return BO;
}
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock *BB) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
BO->setHasNoUnsignedWrap(true);
return BO;
}
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
BO->setHasNoUnsignedWrap(true);
return BO;
}
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name = "") {
BinaryOperator *BO = Create(Opc, V1, V2, Name);
BO->setIsExact(true);
return BO;
}
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock *BB) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
BO->setIsExact(true);
return BO;
}
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
BO->setIsExact(true);
return BO;
}
#define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
static BinaryOperator *Create ## NUWNSWEXACT ## OPC \
(Value *V1, Value *V2, const Twine &Name = "") { \
return Create ## NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \
} \
static BinaryOperator *Create ## NUWNSWEXACT ## OPC \
(Value *V1, Value *V2, const Twine &Name, BasicBlock *BB) { \
return Create ## NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB); \
} \
static BinaryOperator *Create ## NUWNSWEXACT ## OPC \
(Value *V1, Value *V2, const Twine &Name, Instruction *I) { \
return Create ## NUWNSWEXACT(Instruction::OPC, V1, V2, Name, I); \
}
DEFINE_HELPERS(Add, NSW) // CreateNSWAdd
DEFINE_HELPERS(Add, NUW) // CreateNUWAdd
DEFINE_HELPERS(Sub, NSW) // CreateNSWSub
DEFINE_HELPERS(Sub, NUW) // CreateNUWSub
DEFINE_HELPERS(Mul, NSW) // CreateNSWMul
DEFINE_HELPERS(Mul, NUW) // CreateNUWMul
DEFINE_HELPERS(Shl, NSW) // CreateNSWShl
DEFINE_HELPERS(Shl, NUW) // CreateNUWShl
DEFINE_HELPERS(SDiv, Exact) // CreateExactSDiv
DEFINE_HELPERS(UDiv, Exact) // CreateExactUDiv
DEFINE_HELPERS(AShr, Exact) // CreateExactAShr
DEFINE_HELPERS(LShr, Exact) // CreateExactLShr
#undef DEFINE_HELPERS
/// Helper functions to construct and inspect unary operations (NEG and NOT)
/// via binary operators SUB and XOR:
///
/// Create the NEG and NOT instructions out of SUB and XOR instructions.
///
static BinaryOperator *CreateNeg(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = nullptr);
static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = nullptr);
static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = nullptr);
static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = nullptr);
static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = nullptr);
static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
/// Check if the given Value is a NEG, FNeg, or NOT instruction.
///
static bool isNeg(const Value *V);
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false);
static bool isNot(const Value *V);
/// Helper functions to extract the unary argument of a NEG, FNEG or NOT
/// operation implemented via Sub, FSub, or Xor.
///
static const Value *getNegArgument(const Value *BinOp);
static Value *getNegArgument( Value *BinOp);
static const Value *getFNegArgument(const Value *BinOp);
static Value *getFNegArgument( Value *BinOp);
static const Value *getNotArgument(const Value *BinOp);
static Value *getNotArgument( Value *BinOp);
BinaryOps getOpcode() const {
return static_cast<BinaryOps>(Instruction::getOpcode());
}
/// Exchange the two operands to this instruction.
/// This instruction is safe to use on any binary instruction and
/// does not modify the semantics of the instruction. If the instruction
/// cannot be reversed (ie, it's a Div), then return true.
///
bool swapOperands();
/// Set or clear the nsw flag on this instruction, which must be an operator
/// which supports this flag. See LangRef.html for the meaning of this flag.
void setHasNoUnsignedWrap(bool b = true);
/// Set or clear the nsw flag on this instruction, which must be an operator
/// which supports this flag. See LangRef.html for the meaning of this flag.
void setHasNoSignedWrap(bool b = true);
/// Set or clear the exact flag on this instruction, which must be an operator
/// which supports this flag. See LangRef.html for the meaning of this flag.
void setIsExact(bool b = true);
/// Determine whether the no unsigned wrap flag is set.
bool hasNoUnsignedWrap() const;
/// Determine whether the no signed wrap flag is set.
bool hasNoSignedWrap() const;
/// Determine whether the exact flag is set.
bool isExact() const;
/// Convenience method to copy supported wrapping, exact, and fast-math flags
/// from V to this instruction.
void copyIRFlags(const Value *V);
/// Logical 'and' of any supported wrapping, exact, and fast-math flags of
/// V and this instruction.
void andIRFlags(const Value *V);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
return I->isBinaryOp();
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
template <>
struct OperandTraits<BinaryOperator> :
public FixedNumOperandTraits<BinaryOperator, 2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryOperator, Value)
//===----------------------------------------------------------------------===//
// CastInst Class
//===----------------------------------------------------------------------===//
/// This is the base class for all instructions that perform data
/// casts. It is simply provided so that instruction category testing
/// can be performed with code like:
///
/// if (isa<CastInst>(Instr)) { ... }
/// @brief Base class of casting instructions.
class CastInst : public UnaryInstruction {
void anchor() override;
protected:
/// @brief Constructor with insert-before-instruction semantics for subclasses
CastInst(Type *Ty, unsigned iType, Value *S,
const Twine &NameStr = "", Instruction *InsertBefore = nullptr)
: UnaryInstruction(Ty, iType, S, InsertBefore) {
setName(NameStr);
}
/// @brief Constructor with insert-at-end-of-block semantics for subclasses
CastInst(Type *Ty, unsigned iType, Value *S,
const Twine &NameStr, BasicBlock *InsertAtEnd)
: UnaryInstruction(Ty, iType, S, InsertAtEnd) {
setName(NameStr);
}
public:
/// Provides a way to construct any of the CastInst subclasses using an
/// opcode instead of the subclass's constructor. The opcode must be in the
/// CastOps category (Instruction::isCast(opcode) returns true). This
/// constructor has insert-before-instruction semantics to automatically
/// insert the new CastInst before InsertBefore (if it is non-null).
/// @brief Construct any of the CastInst subclasses
static CastInst *Create(
Instruction::CastOps, ///< The opcode of the cast instruction
Value *S, ///< The value to be casted (operand 0)
Type *Ty, ///< The type to which cast should be made
const Twine &Name = "", ///< Name for the instruction
Instruction *InsertBefore = nullptr ///< Place to insert the instruction
);
/// Provides a way to construct any of the CastInst subclasses using an
/// opcode instead of the subclass's constructor. The opcode must be in the
/// CastOps category. This constructor has insert-at-end-of-block semantics
/// to automatically insert the new CastInst at the end of InsertAtEnd (if
/// its non-null).
/// @brief Construct any of the CastInst subclasses
static CastInst *Create(
Instruction::CastOps, ///< The opcode for the cast instruction
Value *S, ///< The value to be casted (operand 0)
Type *Ty, ///< The type to which operand is casted
const Twine &Name, ///< The name for the instruction
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
/// @brief Create a ZExt or BitCast cast instruction
static CastInst *CreateZExtOrBitCast(
Value *S, ///< The value to be casted (operand 0)
Type *Ty, ///< The type to which cast should be made
const Twine &Name = "", ///< Name for the instruction
Instruction *InsertBefore = nullptr ///< Place to insert the instruction
);
/// @brief Create a ZExt or BitCast cast instruction
static CastInst *CreateZExtOrBitCast(
Value *S, ///< The value to be casted (operand 0)
Type *Ty, ///< The type to which operand is casted
const Twine &Name, ///< The name for the instruction
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
/// @brief Create a SExt or BitCast cast instruction
static CastInst *CreateSExtOrBitCast(
Value *S, ///< The value to be casted (operand 0)
Type *Ty, ///< The type to which cast should be made
const Twine &Name = "", ///< Name for the instruction
Instruction *InsertBefore = nullptr ///< Place to insert the instruction
);
/// @brief Create a SExt or BitCast cast instruction
static CastInst *CreateSExtOrBitCast(
Value *S, ///< The value to be casted (operand 0)
Type *Ty, ///< The type to which operand is casted
const Twine &Name, ///< The name for the instruction
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
/// @brief Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
static CastInst *CreatePointerCast(
Value *S, ///< The pointer value to be casted (operand 0)
Type *Ty, ///< The type to which operand is casted
const Twine &Name, ///< The name for the instruction
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
/// @brief Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
static CastInst *CreatePointerCast(
Value *S, ///< The pointer value to be casted (operand 0)
Type *Ty, ///< The type to which cast should be made
const Twine &Name = "", ///< Name for the instruction
Instruction *InsertBefore = nullptr ///< Place to insert the instruction
);
/// @brief Create a BitCast or an AddrSpaceCast cast instruction.
static CastInst *CreatePointerBitCastOrAddrSpaceCast(
Value *S, ///< The pointer value to be casted (operand 0)
Type *Ty, ///< The type to which operand is casted
const Twine &Name, ///< The name for the instruction
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
/// @brief Create a BitCast or an AddrSpaceCast cast instruction.
static CastInst *CreatePointerBitCastOrAddrSpaceCast(
Value *S, ///< The pointer value to be casted (operand 0)
Type *Ty, ///< The type to which cast should be made
const Twine &Name = "", ///< Name for the instruction
Instruction *InsertBefore = 0 ///< Place to insert the instruction
);
/// @brief Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
///
/// If the value is a pointer type and the destination an integer type,
/// creates a PtrToInt cast. If the value is an integer type and the
/// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
/// a bitcast.
static CastInst *CreateBitOrPointerCast(
Value *S, ///< The pointer value to be casted (operand 0)
Type *Ty, ///< The type to which cast should be made
const Twine &Name = "", ///< Name for the instruction
Instruction *InsertBefore = 0 ///< Place to insert the instruction
);
/// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
static CastInst *CreateIntegerCast(
Value *S, ///< The pointer value to be casted (operand 0)
Type *Ty, ///< The type to which cast should be made
bool isSigned, ///< Whether to regard S as signed or not
const Twine &Name = "", ///< Name for the instruction
Instruction *InsertBefore = nullptr ///< Place to insert the instruction
);
/// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
static CastInst *CreateIntegerCast(
Value *S, ///< The integer value to be casted (operand 0)
Type *Ty, ///< The integer type to which operand is casted
bool isSigned, ///< Whether to regard S as signed or not
const Twine &Name, ///< The name for the instruction
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
/// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
static CastInst *CreateFPCast(
Value *S, ///< The floating point value to be casted
Type *Ty, ///< The floating point type to cast to
const Twine &Name = "", ///< Name for the instruction
Instruction *InsertBefore = nullptr ///< Place to insert the instruction
);
/// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
static CastInst *CreateFPCast(
Value *S, ///< The floating point value to be casted
Type *Ty, ///< The floating point type to cast to
const Twine &Name, ///< The name for the instruction
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
/// @brief Create a Trunc or BitCast cast instruction
static CastInst *CreateTruncOrBitCast(
Value *S, ///< The value to be casted (operand 0)
Type *Ty, ///< The type to which cast should be made
const Twine &Name = "", ///< Name for the instruction
Instruction *InsertBefore = nullptr ///< Place to insert the instruction
);
/// @brief Create a Trunc or BitCast cast instruction
static CastInst *CreateTruncOrBitCast(
Value *S, ///< The value to be casted (operand 0)
Type *Ty, ///< The type to which operand is casted
const Twine &Name, ///< The name for the instruction
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
/// @brief Check whether it is valid to call getCastOpcode for these types.
static bool isCastable(
Type *SrcTy, ///< The Type from which the value should be cast.
Type *DestTy ///< The Type to which the value should be cast.
);
/// @brief Check whether a bitcast between these types is valid
static bool isBitCastable(
Type *SrcTy, ///< The Type from which the value should be cast.
Type *DestTy ///< The Type to which the value should be cast.
);
/// @brief Check whether a bitcast, inttoptr, or ptrtoint cast between these
/// types is valid and a no-op.
///
/// This ensures that any pointer<->integer cast has enough bits in the
/// integer and any other cast is a bitcast.
static bool isBitOrNoopPointerCastable(
Type *SrcTy, ///< The Type from which the value should be cast.
Type *DestTy, ///< The Type to which the value should be cast.
const DataLayout &DL);
/// Returns the opcode necessary to cast Val into Ty using usual casting
/// rules.
/// @brief Infer the opcode for cast operand and type
static Instruction::CastOps getCastOpcode(
const Value *Val, ///< The value to cast
bool SrcIsSigned, ///< Whether to treat the source as signed
Type *Ty, ///< The Type to which the value should be casted
bool DstIsSigned ///< Whether to treate the dest. as signed
);
/// There are several places where we need to know if a cast instruction
/// only deals with integer source and destination types. To simplify that
/// logic, this method is provided.
/// @returns true iff the cast has only integral typed operand and dest type.
/// @brief Determine if this is an integer-only cast.
bool isIntegerCast() const;
/// A lossless cast is one that does not alter the basic value. It implies
/// a no-op cast but is more stringent, preventing things like int->float,
/// long->double, or int->ptr.
/// @returns true iff the cast is lossless.
/// @brief Determine if this is a lossless cast.
bool isLosslessCast() const;
/// A no-op cast is one that can be effected without changing any bits.
/// It implies that the source and destination types are the same size. The
/// IntPtrTy argument is used to make accurate determinations for casts
/// involving Integer and Pointer types. They are no-op casts if the integer
/// is the same size as the pointer. However, pointer size varies with
/// platform. Generally, the result of DataLayout::getIntPtrType() should be
/// passed in. If that's not available, use Type::Int64Ty, which will make
/// the isNoopCast call conservative.
/// @brief Determine if the described cast is a no-op cast.
static bool isNoopCast(
Instruction::CastOps Opcode, ///< Opcode of cast
Type *SrcTy, ///< SrcTy of cast
Type *DstTy, ///< DstTy of cast
Type *IntPtrTy ///< Integer type corresponding to Ptr types
);
/// @brief Determine if this cast is a no-op cast.
bool isNoopCast(
Type *IntPtrTy ///< Integer type corresponding to pointer
) const;
/// @brief Determine if this cast is a no-op cast.
///
/// \param DL is the DataLayout to get the Int Ptr type from.
bool isNoopCast(const DataLayout &DL) const;
/// Determine how a pair of casts can be eliminated, if they can be at all.
/// This is a helper function for both CastInst and ConstantExpr.
/// @returns 0 if the CastInst pair can't be eliminated, otherwise
/// returns Instruction::CastOps value for a cast that can replace
/// the pair, casting SrcTy to DstTy.
/// @brief Determine if a cast pair is eliminable
static unsigned isEliminableCastPair(
Instruction::CastOps firstOpcode, ///< Opcode of first cast
Instruction::CastOps secondOpcode, ///< Opcode of second cast
Type *SrcTy, ///< SrcTy of 1st cast
Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
Type *DstTy, ///< DstTy of 2nd cast
Type *SrcIntPtrTy, ///< Integer type corresponding to Ptr SrcTy, or null
Type *MidIntPtrTy, ///< Integer type corresponding to Ptr MidTy, or null
Type *DstIntPtrTy ///< Integer type corresponding to Ptr DstTy, or null
);
/// @brief Return the opcode of this CastInst
Instruction::CastOps getOpcode() const {
return Instruction::CastOps(Instruction::getOpcode());
}
/// @brief Return the source type, as a convenience
Type* getSrcTy() const { return getOperand(0)->getType(); }
/// @brief Return the destination type, as a convenience
Type* getDestTy() const { return getType(); }
/// This method can be used to determine if a cast from S to DstTy using
/// Opcode op is valid or not.
/// @returns true iff the proposed cast is valid.
/// @brief Determine if a cast is valid without creating one.
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy);
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
return I->isCast();
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
//===----------------------------------------------------------------------===//
// CmpInst Class
// //
///////////////////////////////////////////////////////////////////////////////
/// This class is the base class for the comparison instructions.
/// @brief Abstract base class of comparison instructions.
class CmpInst : public Instruction {
void *operator new(size_t, unsigned) = delete;
CmpInst() = delete;
protected:
CmpInst(Type *ty, Instruction::OtherOps op, unsigned short pred,
Value *LHS, Value *RHS, const Twine &Name = "",
Instruction *InsertBefore = nullptr);
CmpInst(Type *ty, Instruction::OtherOps op, unsigned short pred,
Value *LHS, Value *RHS, const Twine &Name,
BasicBlock *InsertAtEnd);
void anchor() override; // Out of line virtual method.
public:
/// This enumeration lists the possible predicates for CmpInst subclasses.
/// Values in the range 0-31 are reserved for FCmpInst, while values in the
/// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
/// predicate values are not overlapping between the classes.
enum Predicate {
// Opcode U L G E Intuitive operation
FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
FCMP_UGT = 10, ///< 1 0 1 0 True if unordered or greater than
FCMP_UGE = 11, ///< 1 0 1 1 True if unordered, greater than, or equal
FCMP_ULT = 12, ///< 1 1 0 0 True if unordered or less than
FCMP_ULE = 13, ///< 1 1 0 1 True if unordered, less than, or equal
FCMP_UNE = 14, ///< 1 1 1 0 True if unordered or not equal
FCMP_TRUE = 15, ///< 1 1 1 1 Always true (always folded)
FIRST_FCMP_PREDICATE = FCMP_FALSE,
LAST_FCMP_PREDICATE = FCMP_TRUE,
BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
ICMP_EQ = 32, ///< equal
ICMP_NE = 33, ///< not equal
ICMP_UGT = 34, ///< unsigned greater than
ICMP_UGE = 35, ///< unsigned greater or equal
ICMP_ULT = 36, ///< unsigned less than
ICMP_ULE = 37, ///< unsigned less or equal
ICMP_SGT = 38, ///< signed greater than
ICMP_SGE = 39, ///< signed greater or equal
ICMP_SLT = 40, ///< signed less than
ICMP_SLE = 41, ///< signed less or equal
FIRST_ICMP_PREDICATE = ICMP_EQ,
LAST_ICMP_PREDICATE = ICMP_SLE,
BAD_ICMP_PREDICATE = ICMP_SLE + 1
};
// allocate space for exactly two operands
void *operator new(size_t s) {
return User::operator new(s, 2);
}
/// Construct a compare instruction, given the opcode, the predicate and
/// the two operands. Optionally (if InstBefore is specified) insert the
/// instruction into a BasicBlock right before the specified instruction.
/// The specified Instruction is allowed to be a dereferenced end iterator.
/// @brief Create a CmpInst
static CmpInst *Create(OtherOps Op,
unsigned short predicate, Value *S1,
Value *S2, const Twine &Name = "",
Instruction *InsertBefore = nullptr);
/// Construct a compare instruction, given the opcode, the predicate and the
/// two operands. Also automatically insert this instruction to the end of
/// the BasicBlock specified.
/// @brief Create a CmpInst
static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
Value *S2, const Twine &Name, BasicBlock *InsertAtEnd);
/// @brief Get the opcode casted to the right type
OtherOps getOpcode() const {
return static_cast<OtherOps>(Instruction::getOpcode());
}
/// @brief Return the predicate for this instruction.
Predicate getPredicate() const {
return Predicate(getSubclassDataFromInstruction());
}
/// @brief Set the predicate for this instruction to the specified value.
void setPredicate(Predicate P) { setInstructionSubclassData(P); }
static bool isFPPredicate(Predicate P) {
return P >= FIRST_FCMP_PREDICATE && P <= LAST_FCMP_PREDICATE;
}
static bool isIntPredicate(Predicate P) {
return P >= FIRST_ICMP_PREDICATE && P <= LAST_ICMP_PREDICATE;
}
bool isFPPredicate() const { return isFPPredicate(getPredicate()); }
bool isIntPredicate() const { return isIntPredicate(getPredicate()); }
/// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
/// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
/// @returns the inverse predicate for the instruction's current predicate.
/// @brief Return the inverse of the instruction's predicate.
Predicate getInversePredicate() const {
return getInversePredicate(getPredicate());
}
/// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
/// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
/// @returns the inverse predicate for predicate provided in \p pred.
/// @brief Return the inverse of a given predicate
static Predicate getInversePredicate(Predicate pred);
/// For example, EQ->EQ, SLE->SGE, ULT->UGT,
/// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
/// @returns the predicate that would be the result of exchanging the two
/// operands of the CmpInst instruction without changing the result
/// produced.
/// @brief Return the predicate as if the operands were swapped
Predicate getSwappedPredicate() const {
return getSwappedPredicate(getPredicate());
}
/// This is a static version that you can use without an instruction
/// available.
/// @brief Return the predicate as if the operands were swapped.
static Predicate getSwappedPredicate(Predicate pred);
/// @brief Provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
/// This is just a convenience that dispatches to the subclasses.
/// @brief Swap the operands and adjust predicate accordingly to retain
/// the same comparison.
void swapOperands();
/// This is just a convenience that dispatches to the subclasses.
/// @brief Determine if this CmpInst is commutative.
bool isCommutative() const;
/// This is just a convenience that dispatches to the subclasses.
/// @brief Determine if this is an equals/not equals predicate.
bool isEquality() const;
/// @returns true if the comparison is signed, false otherwise.
/// @brief Determine if this instruction is using a signed comparison.
bool isSigned() const {
return isSigned(getPredicate());
}
/// @returns true if the comparison is unsigned, false otherwise.
/// @brief Determine if this instruction is using an unsigned comparison.
bool isUnsigned() const {
return isUnsigned(getPredicate());
}
/// This is just a convenience.
/// @brief Determine if this is true when both operands are the same.
bool isTrueWhenEqual() const {
return isTrueWhenEqual(getPredicate());
}
/// This is just a convenience.
/// @brief Determine if this is false when both operands are the same.
bool isFalseWhenEqual() const {
return isFalseWhenEqual(getPredicate());
}
/// @returns true if the predicate is unsigned, false otherwise.
/// @brief Determine if the predicate is an unsigned operation.
static bool isUnsigned(unsigned short predicate);
/// @returns true if the predicate is signed, false otherwise.
/// @brief Determine if the predicate is an signed operation.
static bool isSigned(unsigned short predicate);
/// @brief Determine if the predicate is an ordered operation.
static bool isOrdered(unsigned short predicate);
/// @brief Determine if the predicate is an unordered operation.
static bool isUnordered(unsigned short predicate);
/// Determine if the predicate is true when comparing a value with itself.
static bool isTrueWhenEqual(unsigned short predicate);
/// Determine if the predicate is false when comparing a value with itself.
static bool isFalseWhenEqual(unsigned short predicate);
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::ICmp ||
I->getOpcode() == Instruction::FCmp;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
/// @brief Create a result type for fcmp/icmp
static Type* makeCmpResultType(Type* opnd_type) {
if (VectorType* vt = dyn_cast<VectorType>(opnd_type)) {
return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
vt->getNumElements());
}
return Type::getInt1Ty(opnd_type->getContext());
}
private:
// Shadow Value::setValueSubclassData with a private forwarding method so that
// subclasses cannot accidentally use it.
void setValueSubclassData(unsigned short D) {
Value::setValueSubclassData(D);
}
};
// FIXME: these are redundant if CmpInst < BinaryOperator
template <>
struct OperandTraits<CmpInst> : public FixedNumOperandTraits<CmpInst, 2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CmpInst, Value)
} // End llvm namespace
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/InstVisitor.h | //===- InstVisitor.h - Instruction visitor templates ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_INSTVISITOR_H
#define LLVM_IR_INSTVISITOR_H
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/ErrorHandling.h"
namespace llvm {
// We operate on opaque instruction classes, so forward declare all instruction
// types now...
//
#define HANDLE_INST(NUM, OPCODE, CLASS) class CLASS;
#include "llvm/IR/Instruction.def"
#define DELEGATE(CLASS_TO_VISIT) \
return static_cast<SubClass*>(this)-> \
visit##CLASS_TO_VISIT(static_cast<CLASS_TO_VISIT&>(I))
/// @brief Base class for instruction visitors
///
/// Instruction visitors are used when you want to perform different actions
/// for different kinds of instructions without having to use lots of casts
/// and a big switch statement (in your code, that is).
///
/// To define your own visitor, inherit from this class, specifying your
/// new type for the 'SubClass' template parameter, and "override" visitXXX
/// functions in your class. I say "override" because this class is defined
/// in terms of statically resolved overloading, not virtual functions.
///
/// For example, here is a visitor that counts the number of malloc
/// instructions processed:
///
/// /// Declare the class. Note that we derive from InstVisitor instantiated
/// /// with _our new subclasses_ type.
/// ///
/// struct CountAllocaVisitor : public InstVisitor<CountAllocaVisitor> {
/// unsigned Count;
/// CountAllocaVisitor() : Count(0) {}
///
/// void visitAllocaInst(AllocaInst &AI) { ++Count; }
/// };
///
/// And this class would be used like this:
/// CountAllocaVisitor CAV;
/// CAV.visit(function);
/// NumAllocas = CAV.Count;
///
/// The defined has 'visit' methods for Instruction, and also for BasicBlock,
/// Function, and Module, which recursively process all contained instructions.
///
/// Note that if you don't implement visitXXX for some instruction type,
/// the visitXXX method for instruction superclass will be invoked. So
/// if instructions are added in the future, they will be automatically
/// supported, if you handle one of their superclasses.
///
/// The optional second template argument specifies the type that instruction
/// visitation functions should return. If you specify this, you *MUST* provide
/// an implementation of visitInstruction though!.
///
/// Note that this class is specifically designed as a template to avoid
/// virtual function call overhead. Defining and using an InstVisitor is just
/// as efficient as having your own switch statement over the instruction
/// opcode.
template<typename SubClass, typename RetTy=void>
class InstVisitor {
//===--------------------------------------------------------------------===//
// Interface code - This is the public interface of the InstVisitor that you
// use to visit instructions...
//
public:
// Generic visit method - Allow visitation to all instructions in a range
template<class Iterator>
void visit(Iterator Start, Iterator End) {
while (Start != End)
static_cast<SubClass*>(this)->visit(*Start++);
}
// Define visitors for functions and basic blocks...
//
void visit(Module &M) {
static_cast<SubClass*>(this)->visitModule(M);
visit(M.begin(), M.end());
}
void visit(Function &F) {
static_cast<SubClass*>(this)->visitFunction(F);
visit(F.begin(), F.end());
}
void visit(BasicBlock &BB) {
static_cast<SubClass*>(this)->visitBasicBlock(BB);
visit(BB.begin(), BB.end());
}
// Forwarding functions so that the user can visit with pointers AND refs.
void visit(Module *M) { visit(*M); }
void visit(Function *F) { visit(*F); }
void visit(BasicBlock *BB) { visit(*BB); }
RetTy visit(Instruction *I) { return visit(*I); }
// visit - Finally, code to visit an instruction...
//
RetTy visit(Instruction &I) {
switch (I.getOpcode()) {
default: llvm_unreachable("Unknown instruction type encountered!");
// Build the switch statement using the Instruction.def file...
#define HANDLE_INST(NUM, OPCODE, CLASS) \
case Instruction::OPCODE: return \
static_cast<SubClass*>(this)-> \
visit##OPCODE(static_cast<CLASS&>(I));
#include "llvm/IR/Instruction.def"
}
}
//===--------------------------------------------------------------------===//
// Visitation functions... these functions provide default fallbacks in case
// the user does not specify what to do for a particular instruction type.
// The default behavior is to generalize the instruction type to its subtype
// and try visiting the subtype. All of this should be inlined perfectly,
// because there are no virtual functions to get in the way.
//
// When visiting a module, function or basic block directly, these methods get
// called to indicate when transitioning into a new unit.
//
void visitModule (Module &M) {}
void visitFunction (Function &F) {}
void visitBasicBlock(BasicBlock &BB) {}
// Define instruction specific visitor functions that can be overridden to
// handle SPECIFIC instructions. These functions automatically define
// visitMul to proxy to visitBinaryOperator for instance in case the user does
// not need this generality.
//
// These functions can also implement fan-out, when a single opcode and
// instruction have multiple more specific Instruction subclasses. The Call
// instruction currently supports this. We implement that by redirecting that
// instruction to a special delegation helper.
#define HANDLE_INST(NUM, OPCODE, CLASS) \
RetTy visit##OPCODE(CLASS &I) { \
if (NUM == Instruction::Call) \
return delegateCallInst(I); \
else \
DELEGATE(CLASS); \
}
#include "llvm/IR/Instruction.def"
// Specific Instruction type classes... note that all of the casts are
// necessary because we use the instruction classes as opaque types...
//
RetTy visitReturnInst(ReturnInst &I) { DELEGATE(TerminatorInst);}
RetTy visitBranchInst(BranchInst &I) { DELEGATE(TerminatorInst);}
RetTy visitSwitchInst(SwitchInst &I) { DELEGATE(TerminatorInst);}
RetTy visitIndirectBrInst(IndirectBrInst &I) { DELEGATE(TerminatorInst);}
RetTy visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);}
RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);}
RetTy visitAllocaInst(AllocaInst &I) { DELEGATE(UnaryInstruction);}
RetTy visitLoadInst(LoadInst &I) { DELEGATE(UnaryInstruction);}
RetTy visitStoreInst(StoreInst &I) { DELEGATE(Instruction);}
RetTy visitAtomicCmpXchgInst(AtomicCmpXchgInst &I) { DELEGATE(Instruction);}
RetTy visitAtomicRMWInst(AtomicRMWInst &I) { DELEGATE(Instruction);}
RetTy visitFenceInst(FenceInst &I) { DELEGATE(Instruction);}
RetTy visitGetElementPtrInst(GetElementPtrInst &I){ DELEGATE(Instruction);}
RetTy visitPHINode(PHINode &I) { DELEGATE(Instruction);}
RetTy visitTruncInst(TruncInst &I) { DELEGATE(CastInst);}
RetTy visitZExtInst(ZExtInst &I) { DELEGATE(CastInst);}
RetTy visitSExtInst(SExtInst &I) { DELEGATE(CastInst);}
RetTy visitFPTruncInst(FPTruncInst &I) { DELEGATE(CastInst);}
RetTy visitFPExtInst(FPExtInst &I) { DELEGATE(CastInst);}
RetTy visitFPToUIInst(FPToUIInst &I) { DELEGATE(CastInst);}
RetTy visitFPToSIInst(FPToSIInst &I) { DELEGATE(CastInst);}
RetTy visitUIToFPInst(UIToFPInst &I) { DELEGATE(CastInst);}
RetTy visitSIToFPInst(SIToFPInst &I) { DELEGATE(CastInst);}
RetTy visitPtrToIntInst(PtrToIntInst &I) { DELEGATE(CastInst);}
RetTy visitIntToPtrInst(IntToPtrInst &I) { DELEGATE(CastInst);}
RetTy visitBitCastInst(BitCastInst &I) { DELEGATE(CastInst);}
RetTy visitAddrSpaceCastInst(AddrSpaceCastInst &I) { DELEGATE(CastInst);}
RetTy visitSelectInst(SelectInst &I) { DELEGATE(Instruction);}
RetTy visitVAArgInst(VAArgInst &I) { DELEGATE(UnaryInstruction);}
RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);}
RetTy visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction);}
RetTy visitShuffleVectorInst(ShuffleVectorInst &I) { DELEGATE(Instruction);}
RetTy visitExtractValueInst(ExtractValueInst &I){ DELEGATE(UnaryInstruction);}
RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
// Handle the special instrinsic instruction classes.
RetTy visitDbgDeclareInst(DbgDeclareInst &I) { DELEGATE(DbgInfoIntrinsic);}
RetTy visitDbgValueInst(DbgValueInst &I) { DELEGATE(DbgInfoIntrinsic);}
RetTy visitDbgInfoIntrinsic(DbgInfoIntrinsic &I) { DELEGATE(IntrinsicInst); }
RetTy visitMemSetInst(MemSetInst &I) { DELEGATE(MemIntrinsic); }
RetTy visitMemCpyInst(MemCpyInst &I) { DELEGATE(MemTransferInst); }
RetTy visitMemMoveInst(MemMoveInst &I) { DELEGATE(MemTransferInst); }
RetTy visitMemTransferInst(MemTransferInst &I) { DELEGATE(MemIntrinsic); }
RetTy visitMemIntrinsic(MemIntrinsic &I) { DELEGATE(IntrinsicInst); }
RetTy visitVAStartInst(VAStartInst &I) { DELEGATE(IntrinsicInst); }
RetTy visitVAEndInst(VAEndInst &I) { DELEGATE(IntrinsicInst); }
RetTy visitVACopyInst(VACopyInst &I) { DELEGATE(IntrinsicInst); }
RetTy visitIntrinsicInst(IntrinsicInst &I) { DELEGATE(CallInst); }
// Call and Invoke are slightly different as they delegate first through
// a generic CallSite visitor.
RetTy visitCallInst(CallInst &I) {
return static_cast<SubClass*>(this)->visitCallSite(&I);
}
RetTy visitInvokeInst(InvokeInst &I) {
return static_cast<SubClass*>(this)->visitCallSite(&I);
}
// Next level propagators: If the user does not overload a specific
// instruction type, they can overload one of these to get the whole class
// of instructions...
//
RetTy visitCastInst(CastInst &I) { DELEGATE(UnaryInstruction);}
RetTy visitBinaryOperator(BinaryOperator &I) { DELEGATE(Instruction);}
RetTy visitCmpInst(CmpInst &I) { DELEGATE(Instruction);}
RetTy visitTerminatorInst(TerminatorInst &I) { DELEGATE(Instruction);}
RetTy visitUnaryInstruction(UnaryInstruction &I){ DELEGATE(Instruction);}
// Provide a special visitor for a 'callsite' that visits both calls and
// invokes. When unimplemented, properly delegates to either the terminator or
// regular instruction visitor.
RetTy visitCallSite(CallSite CS) {
assert(CS);
Instruction &I = *CS.getInstruction();
if (CS.isCall())
DELEGATE(Instruction);
assert(CS.isInvoke());
DELEGATE(TerminatorInst);
}
// If the user wants a 'default' case, they can choose to override this
// function. If this function is not overloaded in the user's subclass, then
// this instruction just gets ignored.
//
// Note that you MUST override this function if your return type is not void.
//
void visitInstruction(Instruction &I) {} // Ignore unhandled instructions
private:
// Special helper function to delegate to CallInst subclass visitors.
RetTy delegateCallInst(CallInst &I) {
if (const Function *F = I.getCalledFunction()) {
switch (F->getIntrinsicID()) {
default: DELEGATE(IntrinsicInst);
case Intrinsic::dbg_declare: DELEGATE(DbgDeclareInst);
case Intrinsic::dbg_value: DELEGATE(DbgValueInst);
case Intrinsic::memcpy: DELEGATE(MemCpyInst);
case Intrinsic::memmove: DELEGATE(MemMoveInst);
case Intrinsic::memset: DELEGATE(MemSetInst);
case Intrinsic::vastart: DELEGATE(VAStartInst);
case Intrinsic::vaend: DELEGATE(VAEndInst);
case Intrinsic::vacopy: DELEGATE(VACopyInst);
case Intrinsic::not_intrinsic: break;
}
}
DELEGATE(CallInst);
}
// An overload that will never actually be called, it is used only from dead
// code in the dispatching from opcodes to instruction subclasses.
RetTy delegateCallInst(Instruction &I) {
llvm_unreachable("delegateCallInst called for non-CallInst");
}
};
#undef DELEGATE
} // End llvm namespace
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/Verifier.h | //===- Verifier.h - LLVM IR Verifier ----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the function verifier interface, that can be used for some
// sanity checking of input to the system, and for checking that transformations
// haven't done something bad.
//
// Note that this does not provide full 'java style' security and verifications,
// instead it just tries to ensure that code is well formed.
//
// To see what specifically is checked, look at the top of Verifier.cpp
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_VERIFIER_H
#define LLVM_IR_VERIFIER_H
#include "llvm/ADT/StringRef.h"
#include <string>
namespace llvm {
class Function;
class FunctionPass;
class ModulePass;
class Module;
class PreservedAnalyses;
class raw_ostream;
/// \brief Check a function for errors, useful for use when debugging a
/// pass.
///
/// If there are no errors, the function returns false. If an error is found,
/// a message describing the error is written to OS (if non-null) and true is
/// returned.
bool verifyFunction(const Function &F, raw_ostream *OS = nullptr);
/// \brief Check a module for errors.
///
/// If there are no errors, the function returns false. If an error is found,
/// a message describing the error is written to OS (if non-null) and true is
/// returned.
bool verifyModule(const Module &M, raw_ostream *OS = nullptr);
/// \brief Create a verifier pass.
///
/// Check a module or function for validity. This is essentially a pass wrapped
/// around the above verifyFunction and verifyModule routines and
/// functionality. When the pass detects a verification error it is always
/// printed to stderr, and by default they are fatal. You can override that by
/// passing \c false to \p FatalErrors.
///
/// Note that this creates a pass suitable for the legacy pass manager. It has
/// nothing to do with \c VerifierPass.
FunctionPass *createVerifierPass(bool FatalErrors = true);
class VerifierPass {
bool FatalErrors;
public:
explicit VerifierPass(bool FatalErrors = true) : FatalErrors(FatalErrors) {}
PreservedAnalyses run(Module &M);
PreservedAnalyses run(Function &F);
static StringRef name() { return "VerifierPass"; }
};
} // End llvm namespace
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/IR/InlineAsm.h | //===-- llvm/InlineAsm.h - Class to represent inline asm strings-*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class represents the inline asm strings, which are Value*'s that are
// used as the callee operand of call instructions. InlineAsm's are uniqued
// like constants, and created via InlineAsm::get(...).
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_INLINEASM_H
#define LLVM_IR_INLINEASM_H
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Value.h"
#include <vector>
namespace llvm {
class PointerType;
class FunctionType;
class Module;
struct InlineAsmKeyType;
template <class ConstantClass> class ConstantUniqueMap;
class InlineAsm : public Value {
public:
enum AsmDialect {
AD_ATT,
AD_Intel
};
private:
friend struct InlineAsmKeyType;
friend class ConstantUniqueMap<InlineAsm>;
InlineAsm(const InlineAsm &) = delete;
void operator=(const InlineAsm&) = delete;
std::string AsmString, Constraints;
bool HasSideEffects;
bool IsAlignStack;
AsmDialect Dialect;
InlineAsm(PointerType *Ty, const std::string &AsmString,
const std::string &Constraints, bool hasSideEffects,
bool isAlignStack, AsmDialect asmDialect);
~InlineAsm() override;
/// When the ConstantUniqueMap merges two types and makes two InlineAsms
/// identical, it destroys one of them with this method.
void destroyConstant();
public:
/// InlineAsm::get - Return the specified uniqued inline asm string.
///
static InlineAsm *get(FunctionType *Ty, StringRef AsmString,
StringRef Constraints, bool hasSideEffects,
bool isAlignStack = false,
AsmDialect asmDialect = AD_ATT);
bool hasSideEffects() const { return HasSideEffects; }
bool isAlignStack() const { return IsAlignStack; }
AsmDialect getDialect() const { return Dialect; }
/// getType - InlineAsm's are always pointers.
///
PointerType *getType() const {
return reinterpret_cast<PointerType*>(Value::getType());
}
/// getFunctionType - InlineAsm's are always pointers to functions.
///
FunctionType *getFunctionType() const;
const std::string &getAsmString() const { return AsmString; }
const std::string &getConstraintString() const { return Constraints; }
/// Verify - This static method can be used by the parser to check to see if
/// the specified constraint string is legal for the type. This returns true
/// if legal, false if not.
///
static bool Verify(FunctionType *Ty, StringRef Constraints);
// Constraint String Parsing
enum ConstraintPrefix {
isInput, // 'x'
isOutput, // '=x'
isClobber // '~x'
};
typedef std::vector<std::string> ConstraintCodeVector;
struct SubConstraintInfo {
/// MatchingInput - If this is not -1, this is an output constraint where an
/// input constraint is required to match it (e.g. "0"). The value is the
/// constraint number that matches this one (for example, if this is
/// constraint #0 and constraint #4 has the value "0", this will be 4).
signed char MatchingInput;
/// Code - The constraint code, either the register name (in braces) or the
/// constraint letter/number.
ConstraintCodeVector Codes;
/// Default constructor.
SubConstraintInfo() : MatchingInput(-1) {}
};
typedef std::vector<SubConstraintInfo> SubConstraintInfoVector;
struct ConstraintInfo;
typedef std::vector<ConstraintInfo> ConstraintInfoVector;
struct ConstraintInfo {
/// Type - The basic type of the constraint: input/output/clobber
///
ConstraintPrefix Type;
/// isEarlyClobber - "&": output operand writes result before inputs are all
/// read. This is only ever set for an output operand.
bool isEarlyClobber;
/// MatchingInput - If this is not -1, this is an output constraint where an
/// input constraint is required to match it (e.g. "0"). The value is the
/// constraint number that matches this one (for example, if this is
/// constraint #0 and constraint #4 has the value "0", this will be 4).
signed char MatchingInput;
/// hasMatchingInput - Return true if this is an output constraint that has
/// a matching input constraint.
bool hasMatchingInput() const { return MatchingInput != -1; }
/// isCommutative - This is set to true for a constraint that is commutative
/// with the next operand.
bool isCommutative;
/// isIndirect - True if this operand is an indirect operand. This means
/// that the address of the source or destination is present in the call
/// instruction, instead of it being returned or passed in explicitly. This
/// is represented with a '*' in the asm string.
bool isIndirect;
/// Code - The constraint code, either the register name (in braces) or the
/// constraint letter/number.
ConstraintCodeVector Codes;
/// isMultipleAlternative - '|': has multiple-alternative constraints.
bool isMultipleAlternative;
/// multipleAlternatives - If there are multiple alternative constraints,
/// this array will contain them. Otherwise it will be empty.
SubConstraintInfoVector multipleAlternatives;
/// The currently selected alternative constraint index.
unsigned currentAlternativeIndex;
///Default constructor.
ConstraintInfo();
/// Parse - Analyze the specified string (e.g. "=*&{eax}") and fill in the
/// fields in this structure. If the constraint string is not understood,
/// return true, otherwise return false.
bool Parse(StringRef Str, ConstraintInfoVector &ConstraintsSoFar);
/// selectAlternative - Point this constraint to the alternative constraint
/// indicated by the index.
void selectAlternative(unsigned index);
};
/// ParseConstraints - Split up the constraint string into the specific
/// constraints and their prefixes. If this returns an empty vector, and if
/// the constraint string itself isn't empty, there was an error parsing.
static ConstraintInfoVector ParseConstraints(StringRef ConstraintString);
/// ParseConstraints - Parse the constraints of this inlineasm object,
/// returning them the same way that ParseConstraints(str) does.
ConstraintInfoVector ParseConstraints() const {
return ParseConstraints(Constraints);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Value *V) {
return V->getValueID() == Value::InlineAsmVal;
}
// These are helper methods for dealing with flags in the INLINEASM SDNode
// in the backend.
//
// The encoding of the flag word is currently:
// Bits 2-0 - A Kind_* value indicating the kind of the operand.
// Bits 15-3 - The number of SDNode operands associated with this inline
// assembly operand.
// If bit 31 is set:
// Bit 30-16 - The operand number that this operand must match.
// When bits 2-0 are Kind_Mem, the Constraint_* value must be
// obtained from the flags for this operand number.
// Else if bits 2-0 are Kind_Mem:
// Bit 30-16 - A Constraint_* value indicating the original constraint
// code.
// Else:
// Bit 30-16 - The register class ID to use for the operand.
enum : uint32_t {
// Fixed operands on an INLINEASM SDNode.
Op_InputChain = 0,
Op_AsmString = 1,
Op_MDNode = 2,
Op_ExtraInfo = 3, // HasSideEffects, IsAlignStack, AsmDialect.
Op_FirstOperand = 4,
// Fixed operands on an INLINEASM MachineInstr.
MIOp_AsmString = 0,
MIOp_ExtraInfo = 1, // HasSideEffects, IsAlignStack, AsmDialect.
MIOp_FirstOperand = 2,
// Interpretation of the MIOp_ExtraInfo bit field.
Extra_HasSideEffects = 1,
Extra_IsAlignStack = 2,
Extra_AsmDialect = 4,
Extra_MayLoad = 8,
Extra_MayStore = 16,
// Inline asm operands map to multiple SDNode / MachineInstr operands.
// The first operand is an immediate describing the asm operand, the low
// bits is the kind:
Kind_RegUse = 1, // Input register, "r".
Kind_RegDef = 2, // Output register, "=r".
Kind_RegDefEarlyClobber = 3, // Early-clobber output register, "=&r".
Kind_Clobber = 4, // Clobbered register, "~r".
Kind_Imm = 5, // Immediate.
Kind_Mem = 6, // Memory operand, "m".
// Memory constraint codes.
// These could be tablegenerated but there's little need to do that since
// there's plenty of space in the encoding to support the union of all
// constraint codes for all targets.
Constraint_Unknown = 0,
Constraint_es,
Constraint_i,
Constraint_m,
Constraint_o,
Constraint_v,
Constraint_Q,
Constraint_R,
Constraint_S,
Constraint_T,
Constraint_Um,
Constraint_Un,
Constraint_Uq,
Constraint_Us,
Constraint_Ut,
Constraint_Uv,
Constraint_Uy,
Constraint_X,
Constraint_Z,
Constraint_ZC,
Constraint_Zy,
Constraints_Max = Constraint_Zy,
Constraints_ShiftAmount = 16,
Flag_MatchingOperand = 0x80000000
};
static unsigned getFlagWord(unsigned Kind, unsigned NumOps) {
assert(((NumOps << 3) & ~0xffff) == 0 && "Too many inline asm operands!");
assert(Kind >= Kind_RegUse && Kind <= Kind_Mem && "Invalid Kind");
return Kind | (NumOps << 3);
}
/// getFlagWordForMatchingOp - Augment an existing flag word returned by
/// getFlagWord with information indicating that this input operand is tied
/// to a previous output operand.
static unsigned getFlagWordForMatchingOp(unsigned InputFlag,
unsigned MatchedOperandNo) {
assert(MatchedOperandNo <= 0x7fff && "Too big matched operand");
assert((InputFlag & ~0xffff) == 0 && "High bits already contain data");
return InputFlag | Flag_MatchingOperand | (MatchedOperandNo << 16);
}
/// getFlagWordForRegClass - Augment an existing flag word returned by
/// getFlagWord with the required register class for the following register
/// operands.
/// A tied use operand cannot have a register class, use the register class
/// from the def operand instead.
static unsigned getFlagWordForRegClass(unsigned InputFlag, unsigned RC) {
// Store RC + 1, reserve the value 0 to mean 'no register class'.
++RC;
assert(RC <= 0x7fff && "Too large register class ID");
assert((InputFlag & ~0xffff) == 0 && "High bits already contain data");
return InputFlag | (RC << 16);
}
/// Augment an existing flag word returned by getFlagWord with the constraint
/// code for a memory constraint.
static unsigned getFlagWordForMem(unsigned InputFlag, unsigned Constraint) {
assert(Constraint <= 0x7fff && "Too large a memory constraint ID");
assert(Constraint <= Constraints_Max && "Unknown constraint ID");
assert((InputFlag & ~0xffff) == 0 && "High bits already contain data");
return InputFlag | (Constraint << Constraints_ShiftAmount);
}
static unsigned convertMemFlagWordToMatchingFlagWord(unsigned InputFlag) {
assert(isMemKind(InputFlag));
return InputFlag & ~(0x7fff << Constraints_ShiftAmount);
}
static unsigned getKind(unsigned Flags) {
return Flags & 7;
}
static bool isRegDefKind(unsigned Flag){ return getKind(Flag) == Kind_RegDef;}
static bool isImmKind(unsigned Flag) { return getKind(Flag) == Kind_Imm; }
static bool isMemKind(unsigned Flag) { return getKind(Flag) == Kind_Mem; }
static bool isRegDefEarlyClobberKind(unsigned Flag) {
return getKind(Flag) == Kind_RegDefEarlyClobber;
}
static bool isClobberKind(unsigned Flag) {
return getKind(Flag) == Kind_Clobber;
}
static unsigned getMemoryConstraintID(unsigned Flag) {
assert(isMemKind(Flag));
return (Flag >> Constraints_ShiftAmount) & 0x7fff;
}
/// getNumOperandRegisters - Extract the number of registers field from the
/// inline asm operand flag.
static unsigned getNumOperandRegisters(unsigned Flag) {
return (Flag & 0xffff) >> 3;
}
/// isUseOperandTiedToDef - Return true if the flag of the inline asm
/// operand indicates it is an use operand that's matched to a def operand.
static bool isUseOperandTiedToDef(unsigned Flag, unsigned &Idx) {
if ((Flag & Flag_MatchingOperand) == 0)
return false;
Idx = (Flag & ~Flag_MatchingOperand) >> 16;
return true;
}
/// hasRegClassConstraint - Returns true if the flag contains a register
/// class constraint. Sets RC to the register class ID.
static bool hasRegClassConstraint(unsigned Flag, unsigned &RC) {
if (Flag & Flag_MatchingOperand)
return false;
unsigned High = Flag >> 16;
// getFlagWordForRegClass() uses 0 to mean no register class, and otherwise
// stores RC + 1.
if (!High)
return false;
RC = High - 1;
return true;
}
};
} // End llvm namespace
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DIContext.h | //===-- DIContext.h ---------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines DIContext, an abstract data structure that holds
// debug information data.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_DICONTEXT_H
#define LLVM_DEBUGINFO_DICONTEXT_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/RelocVisitor.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DataTypes.h"
#include <string>
namespace llvm {
class raw_ostream;
/// DILineInfo - a format-neutral container for source line information.
struct DILineInfo {
std::string FileName;
std::string FunctionName;
uint32_t Line;
uint32_t Column;
DILineInfo()
: FileName("<invalid>"), FunctionName("<invalid>"), Line(0), Column(0) {}
bool operator==(const DILineInfo &RHS) const {
return Line == RHS.Line && Column == RHS.Column &&
FileName == RHS.FileName && FunctionName == RHS.FunctionName;
}
bool operator!=(const DILineInfo &RHS) const {
return !(*this == RHS);
}
};
typedef SmallVector<std::pair<uint64_t, DILineInfo>, 16> DILineInfoTable;
/// DIInliningInfo - a format-neutral container for inlined code description.
class DIInliningInfo {
SmallVector<DILineInfo, 4> Frames;
public:
DIInliningInfo() {}
DILineInfo getFrame(unsigned Index) const {
assert(Index < Frames.size());
return Frames[Index];
}
uint32_t getNumberOfFrames() const {
return Frames.size();
}
void addFrame(const DILineInfo &Frame) {
Frames.push_back(Frame);
}
};
/// A DINameKind is passed to name search methods to specify a
/// preference regarding the type of name resolution the caller wants.
enum class DINameKind { None, ShortName, LinkageName };
/// DILineInfoSpecifier - controls which fields of DILineInfo container
/// should be filled with data.
struct DILineInfoSpecifier {
enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
typedef DINameKind FunctionNameKind;
FileLineInfoKind FLIKind;
FunctionNameKind FNKind;
DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default,
FunctionNameKind FNKind = FunctionNameKind::None)
: FLIKind(FLIKind), FNKind(FNKind) {}
};
/// Selects which debug sections get dumped.
enum DIDumpType {
DIDT_Null,
DIDT_All,
DIDT_Abbrev,
DIDT_AbbrevDwo,
DIDT_Aranges,
DIDT_Frames,
DIDT_Info,
DIDT_InfoDwo,
DIDT_Types,
DIDT_TypesDwo,
DIDT_Line,
DIDT_LineDwo,
DIDT_Loc,
DIDT_LocDwo,
DIDT_Ranges,
DIDT_Pubnames,
DIDT_Pubtypes,
DIDT_GnuPubnames,
DIDT_GnuPubtypes,
DIDT_Str,
DIDT_StrDwo,
DIDT_StrOffsetsDwo,
DIDT_AppleNames,
DIDT_AppleTypes,
DIDT_AppleNamespaces,
DIDT_AppleObjC
};
class DIContext {
public:
enum DIContextKind {
CK_DWARF,
CK_PDB
};
DIContextKind getKind() const { return Kind; }
DIContext(DIContextKind K) : Kind(K) {}
virtual ~DIContext() {}
virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
virtual DILineInfo getLineInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
private:
const DIContextKind Kind;
};
/// An inferface for inquiring the load address of a loaded object file
/// to be used by the DIContext implementations when applying relocations
/// on the fly.
class LoadedObjectInfo {
public:
virtual ~LoadedObjectInfo() = default;
/// Obtain the Load Address of a section by Name.
///
/// Calculate the address of the section identified by the passed in Name.
/// The section need not be present in the local address space. The addresses
/// need to be consistent with the addresses used to query the DIContext and
/// the output of this function should be deterministic, i.e. repeated calls with
/// the same Name should give the same address.
virtual uint64_t getSectionLoadAddress(StringRef Name) const = 0;
/// If conveniently available, return the content of the given Section.
///
/// When the section is available in the local address space, in relocated (loaded)
/// form, e.g. because it was relocated by a JIT for execution, this function
/// should provide the contents of said section in `Data`. If the loaded section
/// is not available, or the cost of retrieving it would be prohibitive, this
/// function should return false. In that case, relocations will be read from the
/// local (unrelocated) object file and applied on the fly. Note that this method
/// is used purely for optimzation purposes in the common case of JITting in the
/// local address space, so returning false should always be correct.
virtual bool getLoadedSectionContents(StringRef Name, StringRef &Data) const {
return false;
}
/// Obtain a copy of this LoadedObjectInfo.
///
/// The caller is responsible for deallocation once the copy is no longer required.
virtual std::unique_ptr<LoadedObjectInfo> clone() const = 0;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h | //===-- DWARFDebugLoc.h -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGLOC_H
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGLOC_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/Support/DataExtractor.h"
namespace llvm {
class raw_ostream;
class DWARFDebugLoc {
/// A single location within a location list.
struct Entry {
/// The beginning address of the instruction range.
uint64_t Begin;
/// The ending address of the instruction range.
uint64_t End;
/// The location of the variable within the specified range.
SmallVector<unsigned char, 4> Loc;
};
/// A list of locations that contain one variable.
struct LocationList {
/// The beginning offset where this location list is stored in the debug_loc
/// section.
unsigned Offset;
/// All the locations in which the variable is stored.
SmallVector<Entry, 2> Entries;
};
typedef SmallVector<LocationList, 4> LocationLists;
/// A list of all the variables in the debug_loc section, each one describing
/// the locations in which the variable is stored.
LocationLists Locations;
/// A map used to resolve binary relocations.
const RelocAddrMap &RelocMap;
public:
DWARFDebugLoc(const RelocAddrMap &LocRelocMap) : RelocMap(LocRelocMap) {}
/// Print the location lists found within the debug_loc section.
void dump(raw_ostream &OS) const;
/// Parse the debug_loc section accessible via the 'data' parameter using the
/// specified address size to interpret the address ranges.
void parse(DataExtractor data, unsigned AddressSize);
};
class DWARFDebugLocDWO {
struct Entry {
uint64_t Start;
uint32_t Length;
SmallVector<unsigned char, 4> Loc;
};
struct LocationList {
unsigned Offset;
SmallVector<Entry, 2> Entries;
};
typedef SmallVector<LocationList, 4> LocationLists;
LocationLists Locations;
public:
void parse(DataExtractor data);
void dump(raw_ostream &OS) const;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h | //===-- DWARFRelocMap.h -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFRELOCMAP_H
#define LLVM_LIB_DEBUGINFO_DWARFRELOCMAP_H
#include "llvm/ADT/DenseMap.h"
namespace llvm {
typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap;
} // namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFFormValue.h | //===-- DWARFFormValue.h ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H
#define LLVM_DEBUGINFO_DWARFFORMVALUE_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/DataExtractor.h"
namespace llvm {
class DWARFUnit;
class raw_ostream;
class DWARFFormValue {
public:
enum FormClass {
FC_Unknown,
FC_Address,
FC_Block,
FC_Constant,
FC_String,
FC_Flag,
FC_Reference,
FC_Indirect,
FC_SectionOffset,
FC_Exprloc
};
private:
struct ValueType {
ValueType() : data(nullptr) {
uval = 0;
}
union {
uint64_t uval;
int64_t sval;
const char* cstr;
};
const uint8_t* data;
};
uint16_t Form; // Form for this value.
ValueType Value; // Contains all data for the form.
public:
DWARFFormValue(uint16_t Form = 0) : Form(Form) {}
uint16_t getForm() const { return Form; }
bool isFormClass(FormClass FC) const;
void dump(raw_ostream &OS, const DWARFUnit *U) const;
/// \brief extracts a value in data at offset *offset_ptr.
///
/// The passed DWARFUnit is allowed to be nullptr, in which
/// case no relocation processing will be performed and some
/// kind of forms that depend on Unit information are disallowed.
/// \returns whether the extraction succeeded.
bool extractValue(DataExtractor data, uint32_t *offset_ptr,
const DWARFUnit *u);
bool isInlinedCStr() const {
return Value.data != nullptr && Value.data == (const uint8_t*)Value.cstr;
}
/// getAsFoo functions below return the extracted value as Foo if only
/// DWARFFormValue has form class is suitable for representing Foo.
Optional<uint64_t> getAsReference(const DWARFUnit *U) const;
Optional<uint64_t> getAsUnsignedConstant() const;
Optional<int64_t> getAsSignedConstant() const;
Optional<const char *> getAsCString(const DWARFUnit *U) const;
Optional<uint64_t> getAsAddress(const DWARFUnit *U) const;
Optional<uint64_t> getAsSectionOffset() const;
Optional<ArrayRef<uint8_t>> getAsBlock() const;
bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
const DWARFUnit *u) const;
static bool skipValue(uint16_t form, DataExtractor debug_info_data,
uint32_t *offset_ptr, const DWARFUnit *u);
static ArrayRef<uint8_t> getFixedFormSizes(uint8_t AddrSize,
uint16_t Version);
private:
void dumpString(raw_ostream &OS, const DWARFUnit *U) const;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFUnit.h | //===-- DWARFUnit.h ---------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFUNIT_H
#define LLVM_LIB_DEBUGINFO_DWARFUNIT_H
#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
#include <vector>
namespace llvm {
namespace object {
class ObjectFile;
}
class DWARFContext;
class DWARFDebugAbbrev;
class DWARFUnit;
class StringRef;
class raw_ostream;
/// Base class for all DWARFUnitSection classes. This provides the
/// functionality common to all unit types.
class DWARFUnitSectionBase {
public:
/// Returns the Unit that contains the given section offset in the
/// same section this Unit originated from.
virtual DWARFUnit *getUnitForOffset(uint32_t Offset) const = 0;
void parse(DWARFContext &C, const DWARFSection &Section);
void parseDWO(DWARFContext &C, const DWARFSection &DWOSection);
protected:
virtual void parseImpl(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
StringRef SOS, StringRef AOS, bool isLittleEndian) = 0;
~DWARFUnitSectionBase() = default;
};
/// Concrete instance of DWARFUnitSection, specialized for one Unit type.
template<typename UnitType>
class DWARFUnitSection final : public SmallVector<std::unique_ptr<UnitType>, 1>,
public DWARFUnitSectionBase {
struct UnitOffsetComparator {
bool operator()(uint32_t LHS,
const std::unique_ptr<UnitType> &RHS) const {
return LHS < RHS->getNextUnitOffset();
}
};
bool Parsed;
public:
DWARFUnitSection() : Parsed(false) {}
DWARFUnitSection(DWARFUnitSection &&DUS) :
SmallVector<std::unique_ptr<UnitType>, 1>(std::move(DUS)), Parsed(DUS.Parsed) {}
typedef llvm::SmallVectorImpl<std::unique_ptr<UnitType>> UnitVector;
typedef typename UnitVector::iterator iterator;
typedef llvm::iterator_range<typename UnitVector::iterator> iterator_range;
UnitType *getUnitForOffset(uint32_t Offset) const override {
auto *CU = std::upper_bound(this->begin(), this->end(), Offset,
UnitOffsetComparator());
if (CU != this->end())
return CU->get();
return nullptr;
}
private:
void parseImpl(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
StringRef SOS, StringRef AOS, bool LE) override {
if (Parsed)
return;
DataExtractor Data(Section.Data, LE, 0);
uint32_t Offset = 0;
while (Data.isValidOffset(Offset)) {
auto U = llvm::make_unique<UnitType>(Context, Section, DA, RS, SS, SOS,
AOS, LE, *this);
if (!U->extract(Data, &Offset))
break;
this->push_back(std::move(U));
Offset = this->back()->getNextUnitOffset();
}
Parsed = true;
}
};
class DWARFUnit {
DWARFContext &Context;
// Section containing this DWARFUnit.
const DWARFSection &InfoSection;
const DWARFDebugAbbrev *Abbrev;
StringRef RangeSection;
uint32_t RangeSectionBase;
StringRef StringSection;
StringRef StringOffsetSection;
StringRef AddrOffsetSection;
uint32_t AddrOffsetSectionBase;
bool isLittleEndian;
const DWARFUnitSectionBase &UnitSection;
uint32_t Offset;
uint32_t Length;
uint16_t Version;
const DWARFAbbreviationDeclarationSet *Abbrevs;
uint8_t AddrSize;
uint64_t BaseAddr;
// The compile unit debug information entry items.
std::vector<DWARFDebugInfoEntryMinimal> DieArray;
class DWOHolder {
object::OwningBinary<object::ObjectFile> DWOFile;
std::unique_ptr<DWARFContext> DWOContext;
DWARFUnit *DWOU;
public:
DWOHolder(StringRef DWOPath);
DWARFUnit *getUnit() const { return DWOU; }
};
std::unique_ptr<DWOHolder> DWO;
protected:
virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr);
/// Size in bytes of the unit header.
virtual uint32_t getHeaderSize() const { return 11; }
public:
DWARFUnit(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
StringRef SOS, StringRef AOS, bool LE,
const DWARFUnitSectionBase &UnitSection);
virtual ~DWARFUnit();
DWARFContext& getContext() const { return Context; }
StringRef getStringSection() const { return StringSection; }
StringRef getStringOffsetSection() const { return StringOffsetSection; }
void setAddrOffsetSection(StringRef AOS, uint32_t Base) {
AddrOffsetSection = AOS;
AddrOffsetSectionBase = Base;
}
void setRangesSection(StringRef RS, uint32_t Base) {
RangeSection = RS;
RangeSectionBase = Base;
}
bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
// FIXME: Result should be uint64_t in DWARF64.
bool getStringOffsetSectionItem(uint32_t Index, uint32_t &Result) const;
DataExtractor getDebugInfoExtractor() const {
return DataExtractor(InfoSection.Data, isLittleEndian, AddrSize);
}
DataExtractor getStringExtractor() const {
return DataExtractor(StringSection, false, 0);
}
const RelocAddrMap *getRelocMap() const { return &InfoSection.Relocs; }
bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
/// extractRangeList - extracts the range list referenced by this compile
/// unit from .debug_ranges section. Returns true on success.
/// Requires that compile unit is already extracted.
bool extractRangeList(uint32_t RangeListOffset,
DWARFDebugRangeList &RangeList) const;
void clear();
uint32_t getOffset() const { return Offset; }
uint32_t getNextUnitOffset() const { return Offset + Length + 4; }
uint32_t getLength() const { return Length; }
uint16_t getVersion() const { return Version; }
const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
return Abbrevs;
}
uint8_t getAddressByteSize() const { return AddrSize; }
uint64_t getBaseAddress() const { return BaseAddr; }
void setBaseAddress(uint64_t base_addr) {
BaseAddr = base_addr;
}
const DWARFDebugInfoEntryMinimal *getUnitDIE(bool ExtractUnitDIEOnly = true) {
extractDIEsIfNeeded(ExtractUnitDIEOnly);
return DieArray.empty() ? nullptr : &DieArray[0];
}
const char *getCompilationDir();
uint64_t getDWOId();
void collectAddressRanges(DWARFAddressRangesVector &CURanges);
/// getInlinedChainForAddress - fetches inlined chain for a given address.
/// Returns empty chain if there is no subprogram containing address. The
/// chain is valid as long as parsed compile unit DIEs are not cleared.
DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address);
/// getUnitSection - Return the DWARFUnitSection containing this unit.
const DWARFUnitSectionBase &getUnitSection() const { return UnitSection; }
/// \brief Returns the number of DIEs in the unit. Parses the unit
/// if necessary.
unsigned getNumDIEs() {
extractDIEsIfNeeded(false);
return DieArray.size();
}
/// \brief Return the index of a DIE inside the unit's DIE vector.
///
/// It is illegal to call this method with a DIE that hasn't be
/// created by this unit. In other word, it's illegal to call this
/// method on a DIE that isn't accessible by following
/// children/sibling links starting from this unit's getUnitDIE().
uint32_t getDIEIndex(const DWARFDebugInfoEntryMinimal *DIE) {
assert(!DieArray.empty() && DIE >= &DieArray[0] &&
DIE < &DieArray[0] + DieArray.size());
return DIE - &DieArray[0];
}
/// \brief Return the DIE object at the given index.
const DWARFDebugInfoEntryMinimal *getDIEAtIndex(unsigned Index) const {
assert(Index < DieArray.size());
return &DieArray[Index];
}
/// \brief Return the DIE object for a given offset inside the
/// unit's DIE vector.
///
/// The unit needs to have his DIEs extracted for this method to work.
const DWARFDebugInfoEntryMinimal *getDIEForOffset(uint32_t Offset) const {
assert(!DieArray.empty());
auto it = std::lower_bound(
DieArray.begin(), DieArray.end(), Offset,
[=](const DWARFDebugInfoEntryMinimal &LHS, uint32_t Offset) {
return LHS.getOffset() < Offset;
});
return it == DieArray.end() ? nullptr : &*it;
}
private:
/// Size in bytes of the .debug_info data associated with this compile unit.
size_t getDebugInfoSize() const { return Length + 4 - getHeaderSize(); }
/// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
/// hasn't already been done. Returns the number of DIEs parsed at this call.
size_t extractDIEsIfNeeded(bool CUDieOnly);
/// extractDIEsToVector - Appends all parsed DIEs to a vector.
void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const;
/// setDIERelations - We read in all of the DIE entries into our flat list
/// of DIE entries and now we need to go back through all of them and set the
/// parent, sibling and child pointers for quick DIE navigation.
void setDIERelations();
/// clearDIEs - Clear parsed DIEs to keep memory usage low.
void clearDIEs(bool KeepCUDie);
/// parseDWO - Parses .dwo file for current compile unit. Returns true if
/// it was actually constructed.
bool parseDWO();
/// getSubprogramForAddress - Returns subprogram DIE with address range
/// encompassing the provided address. The pointer is alive as long as parsed
/// compile unit DIEs are not cleared.
const DWARFDebugInfoEntryMinimal *getSubprogramForAddress(uint64_t Address);
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h | //===--- DWARFAcceleratorTable.h --------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFACCELERATORTABLE_H
#define LLVM_LIB_DEBUGINFO_DWARFACCELERATORTABLE_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include <cstdint>
namespace llvm {
class DWARFAcceleratorTable {
struct Header {
uint32_t Magic;
uint16_t Version;
uint16_t HashFunction;
uint32_t NumBuckets;
uint32_t NumHashes;
uint32_t HeaderDataLength;
};
struct HeaderData {
typedef uint16_t AtomType;
typedef uint16_t Form;
uint32_t DIEOffsetBase;
SmallVector<std::pair<AtomType, Form>, 3> Atoms;
};
struct Header Hdr;
struct HeaderData HdrData;
DataExtractor AccelSection;
DataExtractor StringSection;
const RelocAddrMap& Relocs;
public:
DWARFAcceleratorTable(DataExtractor AccelSection, DataExtractor StringSection,
const RelocAddrMap &Relocs)
: AccelSection(AccelSection), StringSection(StringSection), Relocs(Relocs) {}
bool extract();
void dump(raw_ostream &OS) const;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFTypeUnit.h | //===-- DWARFTypeUnit.h -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFTYPEUNIT_H
#define LLVM_LIB_DEBUGINFO_DWARFTYPEUNIT_H
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
namespace llvm {
class DWARFTypeUnit : public DWARFUnit {
private:
uint64_t TypeHash;
uint32_t TypeOffset;
public:
DWARFTypeUnit(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
StringRef SOS, StringRef AOS, bool LE,
const DWARFUnitSectionBase &UnitSection)
: DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LE, UnitSection) {}
uint32_t getHeaderSize() const override {
return DWARFUnit::getHeaderSize() + 12;
}
void dump(raw_ostream &OS);
protected:
bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) override;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h | //===-- DWARFDebugArangeSet.h -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGESET_H
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGESET_H
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/DataExtractor.h"
#include <vector>
namespace llvm {
class raw_ostream;
class DWARFDebugArangeSet {
public:
struct Header {
// The total length of the entries for that set, not including the length
// field itself.
uint32_t Length;
// The offset from the beginning of the .debug_info section of the
// compilation unit entry referenced by the table.
uint32_t CuOffset;
// The DWARF version number.
uint16_t Version;
// The size in bytes of an address on the target architecture. For segmented
// addressing, this is the size of the offset portion of the address.
uint8_t AddrSize;
// The size in bytes of a segment descriptor on the target architecture.
// If the target system uses a flat address space, this value is 0.
uint8_t SegSize;
};
struct Descriptor {
uint64_t Address;
uint64_t Length;
uint64_t getEndAddress() const { return Address + Length; }
};
private:
typedef std::vector<Descriptor> DescriptorColl;
typedef iterator_range<DescriptorColl::const_iterator> desc_iterator_range;
uint32_t Offset;
Header HeaderData;
DescriptorColl ArangeDescriptors;
public:
DWARFDebugArangeSet() { clear(); }
void clear();
bool extract(DataExtractor data, uint32_t *offset_ptr);
void dump(raw_ostream &OS) const;
uint32_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; }
desc_iterator_range descriptors() const {
return desc_iterator_range(ArangeDescriptors.begin(),
ArangeDescriptors.end());
}
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h | //===-- DWARFDebugFrame.h - Parsing of .debug_frame -------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGFRAME_H
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGFRAME_H
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>
#include <vector>
namespace llvm {
class FrameEntry;
/// \brief A parsed .debug_frame section
///
class DWARFDebugFrame {
public:
DWARFDebugFrame();
~DWARFDebugFrame();
/// \brief Dump the section data into the given stream.
void dump(raw_ostream &OS) const;
/// \brief Parse the section from raw data.
/// data is assumed to be pointing to the beginning of the section.
void parse(DataExtractor Data);
private:
std::vector<std::unique_ptr<FrameEntry>> Entries;
};
} // namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFCompileUnit.h | //===-- DWARFCompileUnit.h --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFCOMPILEUNIT_H
#define LLVM_LIB_DEBUGINFO_DWARFCOMPILEUNIT_H
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
namespace llvm {
class DWARFCompileUnit : public DWARFUnit {
public:
DWARFCompileUnit(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
StringRef SOS, StringRef AOS, bool LE,
const DWARFUnitSectionBase &UnitSection)
: DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LE, UnitSection) {}
void dump(raw_ostream &OS);
// VTable anchor.
~DWARFCompileUnit() override;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h | //===-- DWARFDebugAbbrev.h --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGABBREV_H
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGABBREV_H
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
#include <list>
#include <map>
#include <vector>
namespace llvm {
class DWARFAbbreviationDeclarationSet {
uint32_t Offset;
/// Code of the first abbreviation, if all abbreviations in the set have
/// consecutive codes. UINT32_MAX otherwise.
uint32_t FirstAbbrCode;
std::vector<DWARFAbbreviationDeclaration> Decls;
public:
DWARFAbbreviationDeclarationSet();
uint32_t getOffset() const { return Offset; }
void dump(raw_ostream &OS) const;
bool extract(DataExtractor Data, uint32_t *OffsetPtr);
const DWARFAbbreviationDeclaration *
getAbbreviationDeclaration(uint32_t AbbrCode) const;
private:
void clear();
};
class DWARFDebugAbbrev {
typedef std::map<uint64_t, DWARFAbbreviationDeclarationSet>
DWARFAbbreviationDeclarationSetMap;
DWARFAbbreviationDeclarationSetMap AbbrDeclSets;
mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos;
public:
DWARFDebugAbbrev();
const DWARFAbbreviationDeclarationSet *
getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
void dump(raw_ostream &OS) const;
void extract(DataExtractor Data);
private:
void clear();
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFContext.h | //===-- DWARFContext.h ------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===/
#ifndef LLVM_LIB_DEBUGINFO_DWARFCONTEXT_H
#define LLVM_LIB_DEBUGINFO_DWARFCONTEXT_H
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
#include <vector>
namespace llvm {
// In place of applying the relocations to the data we've read from disk we use
// a separate mapping table to the side and checking that at locations in the
// dwarf where we expect relocated values. This adds a bit of complexity to the
// dwarf parsing/extraction at the benefit of not allocating memory for the
// entire size of the debug info sections.
typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap;
/// DWARFContext
/// This data structure is the top level entity that deals with dwarf debug
/// information parsing. The actual data is supplied through pure virtual
/// methods that a concrete implementation provides.
class DWARFContext : public DIContext {
DWARFUnitSection<DWARFCompileUnit> CUs;
std::vector<DWARFUnitSection<DWARFTypeUnit>> TUs;
std::unique_ptr<DWARFDebugAbbrev> Abbrev;
std::unique_ptr<DWARFDebugLoc> Loc;
std::unique_ptr<DWARFDebugAranges> Aranges;
std::unique_ptr<DWARFDebugLine> Line;
std::unique_ptr<DWARFDebugFrame> DebugFrame;
DWARFUnitSection<DWARFCompileUnit> DWOCUs;
std::vector<DWARFUnitSection<DWARFTypeUnit>> DWOTUs;
std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
std::unique_ptr<DWARFDebugLocDWO> LocDWO;
DWARFContext(DWARFContext &) = delete;
DWARFContext &operator=(DWARFContext &) = delete;
/// Read compile units from the debug_info section (if necessary)
/// and store them in CUs.
void parseCompileUnits();
/// Read type units from the debug_types sections (if necessary)
/// and store them in TUs.
void parseTypeUnits();
/// Read compile units from the debug_info.dwo section (if necessary)
/// and store them in DWOCUs.
void parseDWOCompileUnits();
/// Read type units from the debug_types.dwo section (if necessary)
/// and store them in DWOTUs.
void parseDWOTypeUnits();
public:
DWARFContext() : DIContext(CK_DWARF) {}
static bool classof(const DIContext *DICtx) {
return DICtx->getKind() == CK_DWARF;
}
void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) override;
typedef DWARFUnitSection<DWARFCompileUnit>::iterator_range cu_iterator_range;
typedef DWARFUnitSection<DWARFTypeUnit>::iterator_range tu_iterator_range;
typedef iterator_range<std::vector<DWARFUnitSection<DWARFTypeUnit>>::iterator> tu_section_iterator_range;
/// Get compile units in this context.
cu_iterator_range compile_units() {
parseCompileUnits();
return cu_iterator_range(CUs.begin(), CUs.end());
}
/// Get type units in this context.
tu_section_iterator_range type_unit_sections() {
parseTypeUnits();
return tu_section_iterator_range(TUs.begin(), TUs.end());
}
/// Get compile units in the DWO context.
cu_iterator_range dwo_compile_units() {
parseDWOCompileUnits();
return cu_iterator_range(DWOCUs.begin(), DWOCUs.end());
}
/// Get type units in the DWO context.
tu_section_iterator_range dwo_type_unit_sections() {
parseDWOTypeUnits();
return tu_section_iterator_range(DWOTUs.begin(), DWOTUs.end());
}
/// Get the number of compile units in this context.
unsigned getNumCompileUnits() {
parseCompileUnits();
return CUs.size();
}
/// Get the number of compile units in this context.
unsigned getNumTypeUnits() {
parseTypeUnits();
return TUs.size();
}
/// Get the number of compile units in the DWO context.
unsigned getNumDWOCompileUnits() {
parseDWOCompileUnits();
return DWOCUs.size();
}
/// Get the number of compile units in the DWO context.
unsigned getNumDWOTypeUnits() {
parseDWOTypeUnits();
return DWOTUs.size();
}
/// Get the compile unit at the specified index for this compile unit.
DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
parseCompileUnits();
return CUs[index].get();
}
/// Get the compile unit at the specified index for the DWO compile units.
DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
parseDWOCompileUnits();
return DWOCUs[index].get();
}
/// Get a pointer to the parsed DebugAbbrev object.
const DWARFDebugAbbrev *getDebugAbbrev();
/// Get a pointer to the parsed DebugLoc object.
const DWARFDebugLoc *getDebugLoc();
/// Get a pointer to the parsed dwo abbreviations object.
const DWARFDebugAbbrev *getDebugAbbrevDWO();
/// Get a pointer to the parsed DebugLoc object.
const DWARFDebugLocDWO *getDebugLocDWO();
/// Get a pointer to the parsed DebugAranges object.
const DWARFDebugAranges *getDebugAranges();
/// Get a pointer to the parsed frame information object.
const DWARFDebugFrame *getDebugFrame();
/// Get a pointer to a parsed line table corresponding to a compile unit.
const DWARFDebugLine::LineTable *getLineTableForUnit(DWARFUnit *cu);
DILineInfo getLineInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
DIInliningInfo getInliningInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
virtual bool isLittleEndian() const = 0;
virtual uint8_t getAddressSize() const = 0;
virtual const DWARFSection &getInfoSection() = 0;
typedef MapVector<object::SectionRef, DWARFSection,
std::map<object::SectionRef, unsigned>> TypeSectionMap;
virtual const TypeSectionMap &getTypesSections() = 0;
virtual StringRef getAbbrevSection() = 0;
virtual const DWARFSection &getLocSection() = 0;
virtual StringRef getARangeSection() = 0;
virtual StringRef getDebugFrameSection() = 0;
virtual const DWARFSection &getLineSection() = 0;
virtual StringRef getStringSection() = 0;
virtual StringRef getRangeSection() = 0;
virtual StringRef getPubNamesSection() = 0;
virtual StringRef getPubTypesSection() = 0;
virtual StringRef getGnuPubNamesSection() = 0;
virtual StringRef getGnuPubTypesSection() = 0;
// Sections for DWARF5 split dwarf proposal.
virtual const DWARFSection &getInfoDWOSection() = 0;
virtual const TypeSectionMap &getTypesDWOSections() = 0;
virtual StringRef getAbbrevDWOSection() = 0;
virtual const DWARFSection &getLineDWOSection() = 0;
virtual const DWARFSection &getLocDWOSection() = 0;
virtual StringRef getStringDWOSection() = 0;
virtual StringRef getStringOffsetDWOSection() = 0;
virtual StringRef getRangeDWOSection() = 0;
virtual StringRef getAddrSection() = 0;
virtual const DWARFSection& getAppleNamesSection() = 0;
virtual const DWARFSection& getAppleTypesSection() = 0;
virtual const DWARFSection& getAppleNamespacesSection() = 0;
virtual const DWARFSection& getAppleObjCSection() = 0;
static bool isSupportedVersion(unsigned version) {
return version == 2 || version == 3 || version == 4;
}
private:
/// Return the compile unit that includes an offset (relative to .debug_info).
DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
/// Return the compile unit which contains instruction with provided
/// address.
DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
};
/// DWARFContextInMemory is the simplest possible implementation of a
/// DWARFContext. It assumes all content is available in memory and stores
/// pointers to it.
class DWARFContextInMemory : public DWARFContext {
virtual void anchor();
bool IsLittleEndian;
uint8_t AddressSize;
DWARFSection InfoSection;
TypeSectionMap TypesSections;
StringRef AbbrevSection;
DWARFSection LocSection;
StringRef ARangeSection;
StringRef DebugFrameSection;
DWARFSection LineSection;
StringRef StringSection;
StringRef RangeSection;
StringRef PubNamesSection;
StringRef PubTypesSection;
StringRef GnuPubNamesSection;
StringRef GnuPubTypesSection;
// Sections for DWARF5 split dwarf proposal.
DWARFSection InfoDWOSection;
TypeSectionMap TypesDWOSections;
StringRef AbbrevDWOSection;
DWARFSection LineDWOSection;
DWARFSection LocDWOSection;
StringRef StringDWOSection;
StringRef StringOffsetDWOSection;
StringRef RangeDWOSection;
StringRef AddrSection;
DWARFSection AppleNamesSection;
DWARFSection AppleTypesSection;
DWARFSection AppleNamespacesSection;
DWARFSection AppleObjCSection;
SmallVector<SmallString<32>, 4> UncompressedSections;
public:
DWARFContextInMemory(const object::ObjectFile &Obj,
const LoadedObjectInfo *L = nullptr);
bool isLittleEndian() const override { return IsLittleEndian; }
uint8_t getAddressSize() const override { return AddressSize; }
const DWARFSection &getInfoSection() override { return InfoSection; }
const TypeSectionMap &getTypesSections() override { return TypesSections; }
StringRef getAbbrevSection() override { return AbbrevSection; }
const DWARFSection &getLocSection() override { return LocSection; }
StringRef getARangeSection() override { return ARangeSection; }
StringRef getDebugFrameSection() override { return DebugFrameSection; }
const DWARFSection &getLineSection() override { return LineSection; }
StringRef getStringSection() override { return StringSection; }
StringRef getRangeSection() override { return RangeSection; }
StringRef getPubNamesSection() override { return PubNamesSection; }
StringRef getPubTypesSection() override { return PubTypesSection; }
StringRef getGnuPubNamesSection() override { return GnuPubNamesSection; }
StringRef getGnuPubTypesSection() override { return GnuPubTypesSection; }
const DWARFSection& getAppleNamesSection() override { return AppleNamesSection; }
const DWARFSection& getAppleTypesSection() override { return AppleTypesSection; }
const DWARFSection& getAppleNamespacesSection() override { return AppleNamespacesSection; }
const DWARFSection& getAppleObjCSection() override { return AppleObjCSection; }
// Sections for DWARF5 split dwarf proposal.
const DWARFSection &getInfoDWOSection() override { return InfoDWOSection; }
const TypeSectionMap &getTypesDWOSections() override {
return TypesDWOSections;
}
StringRef getAbbrevDWOSection() override { return AbbrevDWOSection; }
const DWARFSection &getLineDWOSection() override { return LineDWOSection; }
const DWARFSection &getLocDWOSection() override { return LocDWOSection; }
StringRef getStringDWOSection() override { return StringDWOSection; }
StringRef getStringOffsetDWOSection() override {
return StringOffsetDWOSection;
}
StringRef getRangeDWOSection() override { return RangeDWOSection; }
StringRef getAddrSection() override {
return AddrSection;
}
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h | //===-- DWARFDebugLine.h ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/Support/DataExtractor.h"
#include <map>
#include <string>
#include <vector>
namespace llvm {
class raw_ostream;
class DWARFDebugLine {
public:
DWARFDebugLine(const RelocAddrMap* LineInfoRelocMap) : RelocMap(LineInfoRelocMap) {}
struct FileNameEntry {
FileNameEntry() : Name(nullptr), DirIdx(0), ModTime(0), Length(0) {}
const char *Name;
uint64_t DirIdx;
uint64_t ModTime;
uint64_t Length;
};
struct Prologue {
Prologue();
// The size in bytes of the statement information for this compilation unit
// (not including the total_length field itself).
uint64_t TotalLength;
// Version identifier for the statement information format.
uint16_t Version;
// The number of bytes following the prologue_length field to the beginning
// of the first byte of the statement program itself.
uint64_t PrologueLength;
// The size in bytes of the smallest target machine instruction. Statement
// program opcodes that alter the address register first multiply their
// operands by this value.
uint8_t MinInstLength;
// The maximum number of individual operations that may be encoded in an
// instruction.
uint8_t MaxOpsPerInst;
// The initial value of theis_stmtregister.
uint8_t DefaultIsStmt;
// This parameter affects the meaning of the special opcodes. See below.
int8_t LineBase;
// This parameter affects the meaning of the special opcodes. See below.
uint8_t LineRange;
// The number assigned to the first special opcode.
uint8_t OpcodeBase;
std::vector<uint8_t> StandardOpcodeLengths;
std::vector<const char*> IncludeDirectories;
std::vector<FileNameEntry> FileNames;
bool IsDWARF64;
uint32_t sizeofTotalLength() const {
return IsDWARF64 ? 12 : 4;
}
uint32_t sizeofPrologueLength() const {
return IsDWARF64 ? 8 : 4;
}
// Length of the prologue in bytes.
uint32_t getLength() const {
return PrologueLength + sizeofTotalLength() + sizeof(Version) +
sizeofPrologueLength();
}
// Length of the line table data in bytes (not including the prologue).
uint32_t getStatementTableLength() const {
return TotalLength + sizeofTotalLength() - getLength();
}
int32_t getMaxLineIncrementForSpecialOpcode() const {
return LineBase + (int8_t)LineRange - 1;
}
void clear();
void dump(raw_ostream &OS) const;
bool parse(DataExtractor debug_line_data, uint32_t *offset_ptr);
};
// Standard .debug_line state machine structure.
struct Row {
explicit Row(bool default_is_stmt = false);
/// Called after a row is appended to the matrix.
void postAppend();
void reset(bool default_is_stmt);
void dump(raw_ostream &OS) const;
static bool orderByAddress(const Row& LHS, const Row& RHS) {
return LHS.Address < RHS.Address;
}
// The program-counter value corresponding to a machine instruction
// generated by the compiler.
uint64_t Address;
// An unsigned integer indicating a source line number. Lines are numbered
// beginning at 1. The compiler may emit the value 0 in cases where an
// instruction cannot be attributed to any source line.
uint32_t Line;
// An unsigned integer indicating a column number within a source line.
// Columns are numbered beginning at 1. The value 0 is reserved to indicate
// that a statement begins at the 'left edge' of the line.
uint16_t Column;
// An unsigned integer indicating the identity of the source file
// corresponding to a machine instruction.
uint16_t File;
// An unsigned integer whose value encodes the applicable instruction set
// architecture for the current instruction.
uint8_t Isa;
// An unsigned integer representing the DWARF path discriminator value
// for this location.
uint32_t Discriminator;
// A boolean indicating that the current instruction is the beginning of a
// statement.
uint8_t IsStmt:1,
// A boolean indicating that the current instruction is the
// beginning of a basic block.
BasicBlock:1,
// A boolean indicating that the current address is that of the
// first byte after the end of a sequence of target machine
// instructions.
EndSequence:1,
// A boolean indicating that the current address is one (of possibly
// many) where execution should be suspended for an entry breakpoint
// of a function.
PrologueEnd:1,
// A boolean indicating that the current address is one (of possibly
// many) where execution should be suspended for an exit breakpoint
// of a function.
EpilogueBegin:1;
};
// Represents a series of contiguous machine instructions. Line table for each
// compilation unit may consist of multiple sequences, which are not
// guaranteed to be in the order of ascending instruction address.
struct Sequence {
// Sequence describes instructions at address range [LowPC, HighPC)
// and is described by line table rows [FirstRowIndex, LastRowIndex).
uint64_t LowPC;
uint64_t HighPC;
unsigned FirstRowIndex;
unsigned LastRowIndex;
bool Empty;
Sequence();
void reset();
static bool orderByLowPC(const Sequence& LHS, const Sequence& RHS) {
return LHS.LowPC < RHS.LowPC;
}
bool isValid() const {
return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex);
}
bool containsPC(uint64_t pc) const {
return (LowPC <= pc && pc < HighPC);
}
};
struct LineTable {
LineTable();
// Represents an invalid row
const uint32_t UnknownRowIndex = UINT32_MAX;
void appendRow(const DWARFDebugLine::Row &R) {
Rows.push_back(R);
}
void appendSequence(const DWARFDebugLine::Sequence &S) {
Sequences.push_back(S);
}
// Returns the index of the row with file/line info for a given address,
// or UnknownRowIndex if there is no such row.
uint32_t lookupAddress(uint64_t address) const;
bool lookupAddressRange(uint64_t address, uint64_t size,
std::vector<uint32_t> &result) const;
// Extracts filename by its index in filename table in prologue.
// Returns true on success.
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind,
std::string &Result) const;
// Fills the Result argument with the file and line information
// corresponding to Address. Returns true on success.
bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind,
DILineInfo &Result) const;
void dump(raw_ostream &OS) const;
void clear();
/// Parse prologue and all rows.
bool parse(DataExtractor debug_line_data, const RelocAddrMap *RMap,
uint32_t *offset_ptr);
struct Prologue Prologue;
typedef std::vector<Row> RowVector;
typedef RowVector::const_iterator RowIter;
typedef std::vector<Sequence> SequenceVector;
typedef SequenceVector::const_iterator SequenceIter;
RowVector Rows;
SequenceVector Sequences;
private:
uint32_t findRowInSeq(const DWARFDebugLine::Sequence &seq,
uint64_t address) const;
};
const LineTable *getLineTable(uint32_t offset) const;
const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
uint32_t offset);
private:
struct ParsingState {
ParsingState(struct LineTable *LT);
void resetRowAndSequence();
void appendRowToMatrix(uint32_t offset);
// Line table we're currently parsing.
struct LineTable *LineTable;
// The row number that starts at zero for the prologue, and increases for
// each row added to the matrix.
unsigned RowNumber;
struct Row Row;
struct Sequence Sequence;
};
typedef std::map<uint32_t, LineTable> LineTableMapTy;
typedef LineTableMapTy::iterator LineTableIter;
typedef LineTableMapTy::const_iterator LineTableConstIter;
const RelocAddrMap *RelocMap;
LineTableMapTy LineTableMap;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h | //===-- DWARFDebugAranges.h -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H
#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/DataExtractor.h"
#include <vector>
namespace llvm {
class DWARFContext;
class DWARFDebugAranges {
public:
void generate(DWARFContext *CTX);
uint32_t findAddress(uint64_t Address) const;
private:
void clear();
void extract(DataExtractor DebugArangesData);
// Call appendRange multiple times and then call construct.
void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC);
void construct();
struct Range {
explicit Range(uint64_t LowPC = -1ULL, uint64_t HighPC = -1ULL,
uint32_t CUOffset = -1U)
: LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
void setHighPC(uint64_t HighPC) {
if (HighPC == -1ULL || HighPC <= LowPC)
Length = 0;
else
Length = HighPC - LowPC;
}
uint64_t HighPC() const {
if (Length)
return LowPC + Length;
return -1ULL;
}
bool containsAddress(uint64_t Address) const {
return LowPC <= Address && Address < HighPC();
}
bool operator<(const Range &other) const {
return LowPC < other.LowPC;
}
uint64_t LowPC; // Start of address range.
uint32_t Length; // End of address range (not including this address).
uint32_t CUOffset; // Offset of the compile unit or die.
};
struct RangeEndpoint {
uint64_t Address;
uint32_t CUOffset;
bool IsRangeStart;
RangeEndpoint(uint64_t Address, uint32_t CUOffset, bool IsRangeStart)
: Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {}
bool operator<(const RangeEndpoint &Other) const {
return Address < Other.Address;
}
};
typedef std::vector<Range> RangeColl;
typedef RangeColl::const_iterator RangeCollIterator;
std::vector<RangeEndpoint> Endpoints;
RangeColl Aranges;
DenseSet<uint32_t> ParsedCUOffsets;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h | //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
#include "llvm/Support/DataTypes.h"
namespace llvm {
class DWARFDebugAranges;
class DWARFCompileUnit;
class DWARFUnit;
class DWARFContext;
class DWARFFormValue;
struct DWARFDebugInfoEntryInlinedChain;
/// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
class DWARFDebugInfoEntryMinimal {
/// Offset within the .debug_info of the start of this entry.
uint32_t Offset;
/// How many to add to "this" to get the sibling.
uint32_t SiblingIdx;
const DWARFAbbreviationDeclaration *AbbrevDecl;
public:
DWARFDebugInfoEntryMinimal()
: Offset(0), SiblingIdx(0), AbbrevDecl(nullptr) {}
void dump(raw_ostream &OS, DWARFUnit *u, unsigned recurseDepth,
unsigned indent = 0) const;
void dumpAttribute(raw_ostream &OS, DWARFUnit *u, uint32_t *offset_ptr,
uint16_t attr, uint16_t form, unsigned indent = 0) const;
/// Extracts a debug info entry, which is a child of a given unit,
/// starting at a given offset. If DIE can't be extracted, returns false and
/// doesn't change OffsetPtr.
bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
bool isNULL() const { return AbbrevDecl == nullptr; }
/// Returns true if DIE represents a subprogram (not inlined).
bool isSubprogramDIE() const;
/// Returns true if DIE represents a subprogram or an inlined
/// subroutine.
bool isSubroutineDIE() const;
uint32_t getOffset() const { return Offset; }
bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
// We know we are kept in a vector of contiguous entries, so we know
// our sibling will be some index after "this".
const DWARFDebugInfoEntryMinimal *getSibling() const {
return SiblingIdx > 0 ? this + SiblingIdx : nullptr;
}
// We know we are kept in a vector of contiguous entries, so we know
// we don't need to store our child pointer, if we have a child it will
// be the next entry in the list...
const DWARFDebugInfoEntryMinimal *getFirstChild() const {
return hasChildren() ? this + 1 : nullptr;
}
void setSibling(const DWARFDebugInfoEntryMinimal *Sibling) {
if (Sibling) {
// We know we are kept in a vector of contiguous entries, so we know
// our sibling will be some index after "this".
SiblingIdx = Sibling - this;
} else
SiblingIdx = 0;
}
const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
return AbbrevDecl;
}
bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
DWARFFormValue &FormValue) const;
const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
const char *FailValue) const;
uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
uint64_t FailValue) const;
uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
const uint16_t Attr,
uint64_t FailValue) const;
uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
uint64_t FailValue) const;
uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
const uint16_t Attr,
uint64_t FailValue) const;
uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const;
/// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
/// Returns true if both attributes are present.
bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
uint64_t &HighPC) const;
DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const;
void collectChildrenAddressRanges(const DWARFUnit *U,
DWARFAddressRangesVector &Ranges) const;
bool addressRangeContainsAddress(const DWARFUnit *U,
const uint64_t Address) const;
/// If a DIE represents a subprogram (or inlined subroutine),
/// returns its mangled name (or short name, if mangled is missing).
/// This name may be fetched from specification or abstract origin
/// for this subprogram. Returns null if no name is found.
const char *getSubroutineName(const DWARFUnit *U, DINameKind Kind) const;
/// Return the DIE name resolving DW_AT_sepcification or
/// DW_AT_abstract_origin references if necessary.
/// Returns null if no name is found.
const char *getName(const DWARFUnit *U, DINameKind Kind) const;
/// Retrieves values of DW_AT_call_file, DW_AT_call_line and
/// DW_AT_call_column from DIE (or zeroes if they are missing).
void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile,
uint32_t &CallLine, uint32_t &CallColumn) const;
/// Get inlined chain for a given address, rooted at the current DIE.
/// Returns empty chain if address is not contained in address range
/// of current DIE.
DWARFDebugInfoEntryInlinedChain
getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
};
/// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
/// DIEs, (possibly ending with subprogram DIE), all of which are contained
/// in some concrete inlined instance tree. Address range for each DIE
/// (except the last DIE) in this chain is contained in address
/// range for next DIE in the chain.
struct DWARFDebugInfoEntryInlinedChain {
DWARFDebugInfoEntryInlinedChain() : U(nullptr) {}
SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs;
const DWARFUnit *U;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFSection.h | //===-- DWARFSection.h ------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFSECTION_H
#define LLVM_LIB_DEBUGINFO_DWARFSECTION_H
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/ADT/StringRef.h"
namespace llvm {
struct DWARFSection {
StringRef Data;
RelocAddrMap Relocs;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h | //===-- DWARFAbbreviationDeclaration.h --------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
#define LLVM_LIB_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/DataExtractor.h"
namespace llvm {
class raw_ostream;
class DWARFAbbreviationDeclaration {
public:
struct AttributeSpec {
AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {}
uint16_t Attr;
uint16_t Form;
};
typedef SmallVector<AttributeSpec, 8> AttributeSpecVector;
DWARFAbbreviationDeclaration();
uint32_t getCode() const { return Code; }
uint32_t getTag() const { return Tag; }
bool hasChildren() const { return HasChildren; }
typedef iterator_range<AttributeSpecVector::const_iterator>
attr_iterator_range;
attr_iterator_range attributes() const {
return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end());
}
uint16_t getFormByIndex(uint32_t idx) const {
return idx < AttributeSpecs.size() ? AttributeSpecs[idx].Form : 0;
}
uint32_t findAttributeIndex(uint16_t attr) const;
bool extract(DataExtractor Data, uint32_t* OffsetPtr);
void dump(raw_ostream &OS) const;
private:
void clear();
uint32_t Code;
uint32_t Tag;
bool HasChildren;
AttributeSpecVector AttributeSpecs;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h | //===-- DWARFDebugRangeList.h -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGRANGELIST_H
#define LLVM_LIB_DEBUGINFO_DWARFDEBUGRANGELIST_H
#include "llvm/Support/DataExtractor.h"
#include <vector>
namespace llvm {
class raw_ostream;
/// DWARFAddressRangesVector - represents a set of absolute address ranges.
typedef std::vector<std::pair<uint64_t, uint64_t>> DWARFAddressRangesVector;
class DWARFDebugRangeList {
public:
struct RangeListEntry {
// A beginning address offset. This address offset has the size of an
// address and is relative to the applicable base address of the
// compilation unit referencing this range list. It marks the beginning
// of an address range.
uint64_t StartAddress;
// An ending address offset. This address offset again has the size of
// an address and is relative to the applicable base address of the
// compilation unit referencing this range list. It marks the first
// address past the end of the address range. The ending address must
// be greater than or equal to the beginning address.
uint64_t EndAddress;
// The end of any given range list is marked by an end of list entry,
// which consists of a 0 for the beginning address offset
// and a 0 for the ending address offset.
bool isEndOfListEntry() const {
return (StartAddress == 0) && (EndAddress == 0);
}
// A base address selection entry consists of:
// 1. The value of the largest representable address offset
// (for example, 0xffffffff when the size of an address is 32 bits).
// 2. An address, which defines the appropriate base address for
// use in interpreting the beginning and ending address offsets of
// subsequent entries of the location list.
bool isBaseAddressSelectionEntry(uint8_t AddressSize) const {
assert(AddressSize == 4 || AddressSize == 8);
if (AddressSize == 4)
return StartAddress == -1U;
else
return StartAddress == -1ULL;
}
};
private:
// Offset in .debug_ranges section.
uint32_t Offset;
uint8_t AddressSize;
std::vector<RangeListEntry> Entries;
public:
DWARFDebugRangeList() { clear(); }
void clear();
void dump(raw_ostream &OS) const;
bool extract(DataExtractor data, uint32_t *offset_ptr);
const std::vector<RangeListEntry> &getEntries() { return Entries; }
/// getAbsoluteRanges - Returns absolute address ranges defined by this range
/// list. Has to be passed base address of the compile unit referencing this
/// range list.
DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const;
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/IPDBEnumChildren.h | //===- IPDBEnumChildren.h - base interface for child enumerator -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_IPDBENUMCHILDREN_H
#define LLVM_DEBUGINFO_PDB_IPDBENUMCHILDREN_H
#include "PDBTypes.h"
#include <memory>
namespace llvm {
template <typename ChildType> class IPDBEnumChildren {
public:
typedef std::unique_ptr<ChildType> ChildTypePtr;
typedef IPDBEnumChildren<ChildType> MyType;
virtual ~IPDBEnumChildren() {}
virtual uint32_t getChildCount() const = 0;
virtual ChildTypePtr getChildAtIndex(uint32_t Index) const = 0;
virtual ChildTypePtr getNext() = 0;
virtual void reset() = 0;
virtual MyType *clone() const = 0;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h | //===- PDBSymbolTypeFriend.h - friend type info -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEFRIEND_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEFRIEND_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeFriend : public PDBSymbol {
public:
PDBSymbolTypeFriend(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Friend)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getTypeId)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEFRIEND_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolAnnotation.h | //===- PDBSymbolAnnotation.h - Accessors for querying PDB annotations ---*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLANNOTATION_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLANNOTATION_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
#include <string>
namespace llvm {
class raw_ostream;
class PDBSymbolAnnotation : public PDBSymbol {
public:
PDBSymbolAnnotation(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Annotation)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
FORWARD_SYMBOL_METHOD(getDataKind)
FORWARD_SYMBOL_METHOD(getRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getSymIndexId)
// FORWARD_SYMBOL_METHOD(getValue)
FORWARD_SYMBOL_METHOD(getVirtualAddress)
};
}
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLANNOTATION_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolExe.h | //===- PDBSymbolExe.h - Accessors for querying executables in a PDB ----*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLEXE_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLEXE_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
#include <string>
namespace llvm {
class raw_ostream;
class PDBSymbolExe : public PDBSymbol {
public:
PDBSymbolExe(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> ExeSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Exe)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAge)
FORWARD_SYMBOL_METHOD(getGuid)
FORWARD_SYMBOL_METHOD(hasCTypes)
FORWARD_SYMBOL_METHOD(hasPrivateSymbols)
FORWARD_SYMBOL_METHOD(getMachineType)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(getSignature)
FORWARD_SYMBOL_METHOD(getSymbolsFileName)
FORWARD_SYMBOL_METHOD(getSymIndexId)
private:
void dumpChildren(raw_ostream &OS, StringRef Label, PDB_SymType ChildType,
int Indent) const;
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLEXE_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h | //===- PDBSymbolUsingNamespace.h - using namespace info ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLUSINGNAMESPACE_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLUSINGNAMESPACE_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolUsingNamespace : public PDBSymbol {
public:
PDBSymbolUsingNamespace(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UsingNamespace)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(getSymIndexId)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLUSINGNAMESPACE_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBContext.h | //===-- PDBContext.h --------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===/
#ifndef LLVM_DEBUGINFO_PDB_PDBCONTEXT_H
#define LLVM_DEBUGINFO_PDB_PDBCONTEXT_H
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
namespace llvm {
namespace object {
class COFFObjectFile;
}
/// PDBContext
/// This data structure is the top level entity that deals with PDB debug
/// information parsing. This data structure exists only when there is a
/// need for a transparent interface to different debug information formats
/// (e.g. PDB and DWARF). More control and power over the debug information
/// access can be had by using the PDB interfaces directly.
class PDBContext : public DIContext {
PDBContext(PDBContext &) = delete;
PDBContext &operator=(PDBContext &) = delete;
public:
PDBContext(const object::COFFObjectFile &Object,
std::unique_ptr<IPDBSession> PDBSession,
bool RelativeAddress);
static bool classof(const DIContext *DICtx) {
return DICtx->getKind() == CK_PDB;
}
void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) override;
DILineInfo getLineInfoForAddress(
uint64_t Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
DILineInfoTable getLineInfoForAddressRange(
uint64_t Address, uint64_t Size,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
DIInliningInfo getInliningInfoForAddress(
uint64_t Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
private:
std::string getFunctionName(uint64_t Address, DINameKind NameKind) const;
std::unique_ptr<IPDBSession> Session;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h | //===- PDBSymbolFuncDebugEnd.h - function end bounds info -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLFUNCDEBUGEND_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLFUNCDEBUGEND_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolFuncDebugEnd : public PDBSymbol {
public:
PDBSymbolFuncDebugEnd(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> FuncDebugEndSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugEnd)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
FORWARD_SYMBOL_METHOD(hasCustomCallingConvention)
FORWARD_SYMBOL_METHOD(hasFarReturn)
FORWARD_SYMBOL_METHOD(hasInterruptReturn)
FORWARD_SYMBOL_METHOD(isStatic)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getLocationType)
FORWARD_SYMBOL_METHOD(hasNoInlineAttribute)
FORWARD_SYMBOL_METHOD(hasNoReturnAttribute)
FORWARD_SYMBOL_METHOD(isUnreached)
FORWARD_SYMBOL_METHOD(getOffset)
FORWARD_SYMBOL_METHOD(hasOptimizedCodeDebugInfo)
FORWARD_SYMBOL_METHOD(getRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getVirtualAddress)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLFUNCDEBUGEND_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolBlock.h | //===- PDBSymbolBlock.h - Accessors for querying PDB blocks -------------*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLBLOCK_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLBLOCK_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
#include <string>
namespace llvm {
class raw_ostream;
class PDBSymbolBlock : public PDBSymbol {
public:
PDBSymbolBlock(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Block)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getLocationType)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(getRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getVirtualAddress)
};
}
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLBLOCK_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h | //===- PDBSymbolTypeTypedef.h - typedef type info ---------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPETYPEDEF_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPETYPEDEF_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeTypedef : public PDBSymbol {
public:
PDBSymbolTypeTypedef(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Typedef)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getBuiltinType)
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(hasConstructor)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(hasAssignmentOperator)
FORWARD_SYMBOL_METHOD(hasCastOperator)
FORWARD_SYMBOL_METHOD(hasNestedTypes)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(isNested)
FORWARD_SYMBOL_METHOD(hasOverloadedOperator)
FORWARD_SYMBOL_METHOD(isPacked)
FORWARD_SYMBOL_METHOD(isReference)
FORWARD_SYMBOL_METHOD(isScoped)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(getUdtKind)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(getVirtualTableShapeId)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPETYPEDEF_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBTypes.h | //===- PDBTypes.h - Defines enums for various fields contained in PDB ---*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
#define LLVM_DEBUGINFO_PDB_PDBTYPES_H
#include "llvm/Config/llvm-config.h"
#include <functional>
#include <stdint.h>
namespace llvm {
class PDBSymDumper;
class PDBSymbol;
class IPDBDataStream;
template <class T> class IPDBEnumChildren;
class IPDBLineNumber;
class IPDBRawSymbol;
class IPDBSession;
class IPDBSourceFile;
typedef IPDBEnumChildren<PDBSymbol> IPDBEnumSymbols;
typedef IPDBEnumChildren<IPDBSourceFile> IPDBEnumSourceFiles;
typedef IPDBEnumChildren<IPDBDataStream> IPDBEnumDataStreams;
typedef IPDBEnumChildren<IPDBLineNumber> IPDBEnumLineNumbers;
class PDBSymbolExe;
class PDBSymbolCompiland;
class PDBSymbolCompilandDetails;
class PDBSymbolCompilandEnv;
class PDBSymbolFunc;
class PDBSymbolBlock;
class PDBSymbolData;
class PDBSymbolAnnotation;
class PDBSymbolLabel;
class PDBSymbolPublicSymbol;
class PDBSymbolTypeUDT;
class PDBSymbolTypeEnum;
class PDBSymbolTypeFunctionSig;
class PDBSymbolTypePointer;
class PDBSymbolTypeArray;
class PDBSymbolTypeBuiltin;
class PDBSymbolTypeTypedef;
class PDBSymbolTypeBaseClass;
class PDBSymbolTypeFriend;
class PDBSymbolTypeFunctionArg;
class PDBSymbolFuncDebugStart;
class PDBSymbolFuncDebugEnd;
class PDBSymbolUsingNamespace;
class PDBSymbolTypeVTableShape;
class PDBSymbolTypeVTable;
class PDBSymbolCustom;
class PDBSymbolThunk;
class PDBSymbolTypeCustom;
class PDBSymbolTypeManaged;
class PDBSymbolTypeDimension;
class PDBSymbolUnknown;
/// Specifies which PDB reader implementation is to be used. Only a value
/// of PDB_ReaderType::DIA is supported.
enum class PDB_ReaderType {
DIA = 0,
};
/// Defines a 128-bit unique identifier. This maps to a GUID on Windows, but
/// is abstracted here for the purposes of non-Windows platforms that don't have
/// the GUID structure defined.
struct PDB_UniqueId {
uint64_t HighPart;
uint64_t LowPart;
};
/// An enumeration indicating the type of data contained in this table.
enum class PDB_TableType {
Symbols,
SourceFiles,
LineNumbers,
SectionContribs,
Segments,
InjectedSources,
FrameData
};
/// Defines flags used for enumerating child symbols. This corresponds to the
/// NameSearchOptions enumeration which is documented here:
/// https://msdn.microsoft.com/en-us/library/yat28ads.aspx
enum PDB_NameSearchFlags {
NS_Default = 0x0,
NS_CaseSensitive = 0x1,
NS_CaseInsensitive = 0x2,
NS_FileNameExtMatch = 0x4,
NS_Regex = 0x8,
NS_UndecoratedName = 0x10
};
/// Specifies the hash algorithm that a source file from a PDB was hashed with.
/// This corresponds to the CV_SourceChksum_t enumeration and are documented
/// here: https://msdn.microsoft.com/en-us/library/e96az21x.aspx
enum class PDB_Checksum { None = 0, MD5 = 1, SHA1 = 2 };
/// These values correspond to the CV_CPU_TYPE_e enumeration, and are documented
/// here: https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
enum class PDB_Cpu {
Intel8080 = 0x0,
Intel8086 = 0x1,
Intel80286 = 0x2,
Intel80386 = 0x3,
Intel80486 = 0x4,
Pentium = 0x5,
PentiumPro = 0x6,
Pentium3 = 0x7,
MIPS = 0x10,
MIPS16 = 0x11,
MIPS32 = 0x12,
MIPS64 = 0x13,
MIPSI = 0x14,
MIPSII = 0x15,
MIPSIII = 0x16,
MIPSIV = 0x17,
MIPSV = 0x18,
M68000 = 0x20,
M68010 = 0x21,
M68020 = 0x22,
M68030 = 0x23,
M68040 = 0x24,
Alpha = 0x30,
Alpha21164 = 0x31,
Alpha21164A = 0x32,
Alpha21264 = 0x33,
Alpha21364 = 0x34,
PPC601 = 0x40,
PPC603 = 0x41,
PPC604 = 0x42,
PPC620 = 0x43,
PPCFP = 0x44,
PPCBE = 0x45,
SH3 = 0x50,
SH3E = 0x51,
SH3DSP = 0x52,
SH4 = 0x53,
SHMedia = 0x54,
ARM3 = 0x60,
ARM4 = 0x61,
ARM4T = 0x62,
ARM5 = 0x63,
ARM5T = 0x64,
ARM6 = 0x65,
ARM_XMAC = 0x66,
ARM_WMMX = 0x67,
ARM7 = 0x68,
Omni = 0x70,
Ia64 = 0x80,
Ia64_2 = 0x81,
CEE = 0x90,
AM33 = 0xa0,
M32R = 0xb0,
TriCore = 0xc0,
X64 = 0xd0,
EBC = 0xe0,
Thumb = 0xf0,
ARMNT = 0xf4,
D3D11_Shader = 0x100,
};
enum class PDB_Machine {
Invalid = 0xffff,
Unknown = 0x0,
Am33 = 0x13,
Amd64 = 0x8664,
Arm = 0x1C0,
ArmNT = 0x1C4,
Ebc = 0xEBC,
x86 = 0x14C,
Ia64 = 0x200,
M32R = 0x9041,
Mips16 = 0x266,
MipsFpu = 0x366,
MipsFpu16 = 0x466,
PowerPC = 0x1F0,
PowerPCFP = 0x1F1,
R4000 = 0x166,
SH3 = 0x1A2,
SH3DSP = 0x1A3,
SH4 = 0x1A6,
SH5 = 0x1A8,
Thumb = 0x1C2,
WceMipsV2 = 0x169
};
/// These values correspond to the CV_call_e enumeration, and are documented
/// at the following locations:
/// https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
/// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680207(v=vs.85).aspx
///
enum class PDB_CallingConv {
NearCdecl = 0x00,
FarCdecl = 0x01,
NearPascal = 0x02,
FarPascal = 0x03,
NearFastcall = 0x04,
FarFastcall = 0x05,
Skipped = 0x06,
NearStdcall = 0x07,
FarStdcall = 0x08,
NearSyscall = 0x09,
FarSyscall = 0x0a,
Thiscall = 0x0b,
MipsCall = 0x0c,
Generic = 0x0d,
Alphacall = 0x0e,
Ppccall = 0x0f,
SuperHCall = 0x10,
Armcall = 0x11,
AM33call = 0x12,
Tricall = 0x13,
Sh5call = 0x14,
M32R = 0x15,
Clrcall = 0x16,
Inline = 0x17,
NearVectorcall = 0x18,
Reserved = 0x19,
};
/// These values correspond to the CV_CFL_LANG enumeration, and are documented
/// here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx
enum class PDB_Lang {
C = 0x00,
Cpp = 0x01,
Fortran = 0x02,
Masm = 0x03,
Pascal = 0x04,
Basic = 0x05,
Cobol = 0x06,
Link = 0x07,
Cvtres = 0x08,
Cvtpgd = 0x09,
CSharp = 0x0a,
VB = 0x0b,
ILAsm = 0x0c,
Java = 0x0d,
JScript = 0x0e,
MSIL = 0x0f,
HLSL = 0x10
};
/// These values correspond to the DataKind enumeration, and are documented
/// here: https://msdn.microsoft.com/en-us/library/b2x2t313.aspx
enum class PDB_DataKind {
Unknown,
Local,
StaticLocal,
Param,
ObjectPtr,
FileStatic,
Global,
Member,
StaticMember,
Constant
};
/// These values correspond to the SymTagEnum enumeration, and are documented
/// here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx
enum class PDB_SymType {
None,
Exe,
Compiland,
CompilandDetails,
CompilandEnv,
Function,
Block,
Data,
Annotation,
Label,
PublicSymbol,
UDT,
Enum,
FunctionSig,
PointerType,
ArrayType,
BuiltinType,
Typedef,
BaseClass,
Friend,
FunctionArg,
FuncDebugStart,
FuncDebugEnd,
UsingNamespace,
VTableShape,
VTable,
Custom,
Thunk,
CustomType,
ManagedType,
Dimension,
Max
};
/// These values correspond to the LocationType enumeration, and are documented
/// here: https://msdn.microsoft.com/en-us/library/f57kaez3.aspx
enum class PDB_LocType {
Null,
Static,
TLS,
RegRel,
ThisRel,
Enregistered,
BitField,
Slot,
IlRel,
MetaData,
Constant,
Max
};
/// These values correspond to the THUNK_ORDINAL enumeration, and are documented
/// here: https://msdn.microsoft.com/en-us/library/dh0k8hft.aspx
enum class PDB_ThunkOrdinal {
Standard,
ThisAdjustor,
Vcall,
Pcode,
UnknownLoad,
TrampIncremental,
BranchIsland
};
/// These values correspond to the UdtKind enumeration, and are documented
/// here: https://msdn.microsoft.com/en-us/library/wcstk66t.aspx
enum class PDB_UdtType { Struct, Class, Union, Interface };
// HLSL Change Starts - undef FPO if defined
#ifdef FPO
#undef FPO
#endif
// HLSL Change Ends
/// These values correspond to the StackFrameTypeEnum enumeration, and are
/// documented here: https://msdn.microsoft.com/en-us/library/bc5207xw.aspx.
enum class PDB_StackFrameType { FPO, KernelTrap, KernelTSS, EBP, FrameData };
/// These values correspond to the StackFrameTypeEnum enumeration, and are
/// documented here: https://msdn.microsoft.com/en-us/library/bc5207xw.aspx.
enum class PDB_MemoryType { Code, Data, Stack, HeapCode };
/// These values correspond to the Basictype enumeration, and are documented
/// here: https://msdn.microsoft.com/en-us/library/4szdtzc3.aspx
enum class PDB_BuiltinType {
None = 0,
Void = 1,
Char = 2,
WCharT = 3,
Int = 6,
UInt = 7,
Float = 8,
BCD = 9,
Bool = 10,
Long = 13,
ULong = 14,
Currency = 25,
Date = 26,
Variant = 27,
Complex = 28,
Bitfield = 29,
BSTR = 30,
HResult = 31
};
enum class PDB_RegisterId {
Unknown = 0,
VFrame = 30006,
AL = 1,
CL = 2,
DL = 3,
BL = 4,
AH = 5,
CH = 6,
DH = 7,
BH = 8,
AX = 9,
CX = 10,
DX = 11,
BX = 12,
SP = 13,
BP = 14,
SI = 15,
DI = 16,
EAX = 17,
ECX = 18,
EDX = 19,
EBX = 20,
ESP = 21,
EBP = 22,
ESI = 23,
EDI = 24,
ES = 25,
CS = 26,
SS = 27,
DS = 28,
FS = 29,
GS = 30,
IP = 31,
RAX = 328,
RBX = 329,
RCX = 330,
RDX = 331,
RSI = 332,
RDI = 333,
RBP = 334,
RSP = 335,
R8 = 336,
R9 = 337,
R10 = 338,
R11 = 339,
R12 = 340,
R13 = 341,
R14 = 342,
R15 = 343,
};
enum class PDB_MemberAccess { Private = 1, Protected = 2, Public = 3 };
enum class PDB_ErrorCode {
Success,
NoPdbImpl,
InvalidPath,
InvalidFileFormat,
InvalidParameter,
AlreadyLoaded,
UnknownError,
NoMemory,
DebugInfoMismatch
};
struct VersionInfo {
uint32_t Major;
uint32_t Minor;
uint32_t Build;
uint32_t QFE;
};
enum PDB_VariantType {
Empty,
Unknown,
Int8,
Int16,
Int32,
Int64,
Single,
Double,
UInt8,
UInt16,
UInt32,
UInt64,
Bool,
};
struct Variant {
Variant()
: Type(PDB_VariantType::Empty) {
}
PDB_VariantType Type;
union {
bool Bool;
int8_t Int8;
int16_t Int16;
int32_t Int32;
int64_t Int64;
float Single;
double Double;
uint8_t UInt8;
uint16_t UInt16;
uint32_t UInt32;
uint64_t UInt64;
};
#define VARIANT_EQUAL_CASE(Enum) \
case PDB_VariantType::Enum: \
return Enum == Other.Enum;
bool operator==(const Variant &Other) const {
if (Type != Other.Type)
return false;
switch (Type) {
VARIANT_EQUAL_CASE(Bool)
VARIANT_EQUAL_CASE(Int8)
VARIANT_EQUAL_CASE(Int16)
VARIANT_EQUAL_CASE(Int32)
VARIANT_EQUAL_CASE(Int64)
VARIANT_EQUAL_CASE(Single)
VARIANT_EQUAL_CASE(Double)
VARIANT_EQUAL_CASE(UInt8)
VARIANT_EQUAL_CASE(UInt16)
VARIANT_EQUAL_CASE(UInt32)
VARIANT_EQUAL_CASE(UInt64)
default:
return true;
}
}
#undef VARIANT_EQUAL_CASE
bool operator!=(const Variant &Other) const { return !(*this == Other); }
};
} // namespace llvm
namespace std {
template <> struct hash<llvm::PDB_SymType> {
typedef llvm::PDB_SymType argument_type;
typedef std::size_t result_type;
result_type operator()(const argument_type &Arg) const {
return std::hash<int>()(static_cast<int>(Arg));
}
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolLabel.h | //===- PDBSymbolLabel.h - label info ----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLLABEL_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLLABEL_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolLabel : public PDBSymbol {
public:
PDBSymbolLabel(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> LabelSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Label)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
FORWARD_SYMBOL_METHOD(hasCustomCallingConvention)
FORWARD_SYMBOL_METHOD(hasFarReturn)
FORWARD_SYMBOL_METHOD(hasInterruptReturn)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getLocationType)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(hasNoInlineAttribute)
FORWARD_SYMBOL_METHOD(hasNoReturnAttribute)
FORWARD_SYMBOL_METHOD(isUnreached)
FORWARD_SYMBOL_METHOD(getOffset)
FORWARD_SYMBOL_METHOD(hasOptimizedCodeDebugInfo)
FORWARD_SYMBOL_METHOD(getRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getVirtualAddress)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLLABEL_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h | //===- PDBSymbolTypeDimension.h - array dimension type info -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEDIMENSION_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEDIMENSION_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeDimension : public PDBSymbol {
public:
PDBSymbolTypeDimension(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Dimension)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getLowerBoundId)
FORWARD_SYMBOL_METHOD(getUpperBoundId)
FORWARD_SYMBOL_METHOD(getSymIndexId)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEDIMENSION_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h | //===- PDBSymbolTypeVTable.h - VTable type info -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEVTABLE_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEVTABLE_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeVTable : public PDBSymbol {
public:
PDBSymbolTypeVTable(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> VtblSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTable)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEVTABLE_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/IPDBSourceFile.h | //===- IPDBSourceFile.h - base interface for a PDB source file --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_IPDBSOURCEFILE_H
#define LLVM_DEBUGINFO_PDB_IPDBSOURCEFILE_H
#include "PDBTypes.h"
#include <memory>
#include <string>
namespace llvm {
class raw_ostream;
/// IPDBSourceFile defines an interface used to represent source files whose
/// information are stored in the PDB.
class IPDBSourceFile {
public:
virtual ~IPDBSourceFile();
void dump(raw_ostream &OS, int Indent) const;
virtual std::string getFileName() const = 0;
virtual uint32_t getUniqueId() const = 0;
virtual std::string getChecksum() const = 0;
virtual PDB_Checksum getChecksumType() const = 0;
virtual std::unique_ptr<IPDBEnumSymbols> getCompilands() const = 0;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolThunk.h | //===- PDBSymbolThunk.h - Support for querying PDB thunks ---------------*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTHUNK_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTHUNK_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
#include <string>
namespace llvm {
class raw_ostream;
class PDBSymbolThunk : public PDBSymbol {
public:
PDBSymbolThunk(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> ThunkSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Thunk)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAccess)
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(isIntroVirtualFunction)
FORWARD_SYMBOL_METHOD(isStatic)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(isPureVirtual)
FORWARD_SYMBOL_METHOD(getRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getTargetOffset)
FORWARD_SYMBOL_METHOD(getTargetRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getTargetVirtualAddress)
FORWARD_SYMBOL_METHOD(getTargetSection)
FORWARD_SYMBOL_METHOD(getThunkOrdinal)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(isVirtual)
FORWARD_SYMBOL_METHOD(getVirtualAddress)
FORWARD_SYMBOL_METHOD(getVirtualBaseOffset)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTHUNK_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/IPDBDataStream.h | //===- IPDBDataStream.h - base interface for child enumerator -*- C++ ---*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_IPDBDATASTREAM_H
#define LLVM_DEBUGINFO_PDB_IPDBDATASTREAM_H
#include "PDBTypes.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
namespace llvm {
/// IPDBDataStream defines an interface used to represent a stream consisting
/// of a name and a series of records whose formats depend on the particular
/// stream type.
class IPDBDataStream {
public:
typedef llvm::SmallVector<uint8_t, 32> RecordType;
virtual ~IPDBDataStream();
virtual uint32_t getRecordCount() const = 0;
virtual std::string getName() const = 0;
virtual llvm::Optional<RecordType> getItemAtIndex(uint32_t Index) const = 0;
virtual bool getNext(RecordType &Record) = 0;
virtual void reset() = 0;
virtual IPDBDataStream *clone() const = 0;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h | //===- PDBSymbolUnknown.h - unknown symbol type -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLUNKNOWN_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLUNKNOWN_H
#include "PDBSymbol.h"
namespace llvm {
class raw_ostream;
class PDBSymbolUnknown : public PDBSymbol {
public:
PDBSymbolUnknown(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> UnknownSymbol);
void dump(PDBSymDumper &Dumper) const override;
static bool classof(const PDBSymbol *S) {
return (S->getSymTag() == PDB_SymType::None ||
S->getSymTag() >= PDB_SymType::Max);
}
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLUNKNOWN_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/IPDBSession.h | //===- IPDBSession.h - base interface for a PDB symbol context --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_IPDBSESSION_H
#define LLVM_DEBUGINFO_PDB_IPDBSESSION_H
#include "PDBTypes.h"
#include "llvm/Support/Casting.h"
#include <memory>
namespace llvm {
class PDBSymbolCompiland;
class PDBSymbolExe;
/// IPDBSession defines an interface used to provide a context for querying
/// debug information from a debug data source (for example, a PDB).
class IPDBSession {
public:
virtual ~IPDBSession();
virtual uint64_t getLoadAddress() const = 0;
virtual void setLoadAddress(uint64_t Address) = 0;
virtual std::unique_ptr<PDBSymbolExe> getGlobalScope() const = 0;
virtual std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const = 0;
template <typename T>
std::unique_ptr<T> getConcreteSymbolById(uint32_t SymbolId) const {
auto Symbol(getSymbolById(SymbolId));
if (!Symbol)
return nullptr;
T *ConcreteSymbol = dyn_cast<T>(Symbol.get());
if (!ConcreteSymbol)
return nullptr;
Symbol.release();
return std::unique_ptr<T>(ConcreteSymbol);
}
virtual std::unique_ptr<PDBSymbol>
findSymbolByAddress(uint64_t Address, PDB_SymType Type) const = 0;
virtual std::unique_ptr<IPDBEnumLineNumbers>
findLineNumbersByAddress(uint64_t Address, uint32_t Length) const = 0;
virtual std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const = 0;
virtual std::unique_ptr<IPDBEnumSourceFiles>
getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const = 0;
virtual std::unique_ptr<IPDBSourceFile>
getSourceFileById(uint32_t FileId) const = 0;
virtual std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const = 0;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypePointer.h | //===- PDBSymbolTypePointer.h - pointer type info ---------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEPOINTER_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEPOINTER_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypePointer : public PDBSymbol {
public:
PDBSymbolTypePointer(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PointerType)
std::unique_ptr<PDBSymbol> getPointeeType() const;
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(isReference)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEPOINTER_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolData.h | //===- PDBSymbolData.h - PDB data (e.g. variable) accessors -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLDATA_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLDATA_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolData : public PDBSymbol {
public:
PDBSymbolData(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> DataSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Data)
std::unique_ptr<PDBSymbol> getType() const;
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAccess)
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
FORWARD_SYMBOL_METHOD(getAddressTaken)
FORWARD_SYMBOL_METHOD(getBitPosition)
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(isCompilerGenerated)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(getDataKind)
FORWARD_SYMBOL_METHOD(isAggregated)
FORWARD_SYMBOL_METHOD(isSplitted)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getLocationType)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(getOffset)
FORWARD_SYMBOL_METHOD(getRegisterId)
FORWARD_SYMBOL_METHOD(getRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getSlot)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getToken)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(getValue)
FORWARD_SYMBOL_METHOD(getVirtualAddress)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLDATA_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h | //===- PDBSymbolCompilandDetails.h - PDB compiland details ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLCOMPILANDDETAILS_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLCOMPILANDDETAILS_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolCompilandDetails : public PDBSymbol {
public:
PDBSymbolCompilandDetails(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandDetails)
void dump(PDBSymDumper &Dumper) const override;
void getFrontEndVersion(VersionInfo &Version) const {
RawSymbol->getFrontEndVersion(Version);
}
void getBackEndVersion(VersionInfo &Version) const {
RawSymbol->getBackEndVersion(Version);
}
FORWARD_SYMBOL_METHOD(getCompilerName)
FORWARD_SYMBOL_METHOD(isEditAndContinueEnabled)
FORWARD_SYMBOL_METHOD(hasDebugInfo)
FORWARD_SYMBOL_METHOD(hasManagedCode)
FORWARD_SYMBOL_METHOD(hasSecurityChecks)
FORWARD_SYMBOL_METHOD(isCVTCIL)
FORWARD_SYMBOL_METHOD(isDataAligned)
FORWARD_SYMBOL_METHOD(isHotpatchable)
FORWARD_SYMBOL_METHOD(isLTCG)
FORWARD_SYMBOL_METHOD(isMSILNetmodule)
FORWARD_SYMBOL_METHOD(getLanguage)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getPlatform)
FORWARD_SYMBOL_METHOD(getSymIndexId)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBFUNCTION_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbol.h | //===- PDBSymbol.h - base class for user-facing symbol types -----*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_IPDBSYMBOL_H
#define LLVM_DEBUGINFO_PDB_IPDBSYMBOL_H
#include "ConcreteSymbolEnumerator.h"
#include "IPDBRawSymbol.h"
#include "PDBExtras.h"
#include "PDBTypes.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include <unordered_map>
#define FORWARD_SYMBOL_METHOD(MethodName) \
auto MethodName() const->decltype(RawSymbol->MethodName()) { \
return RawSymbol->MethodName(); \
}
namespace llvm {
class IPDBRawSymbol;
class raw_ostream;
#define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue) \
static const PDB_SymType Tag = TagValue; \
static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
/// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
/// types (e.g. functions, executables, vtables, etc). All concrete symbol
/// types inherit from PDBSymbol and expose the exact set of methods that are
/// valid for that particular symbol type, as described in the Microsoft
/// reference "Lexical and Class Hierarchy of Symbol Types":
/// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
class PDBSymbol {
protected:
PDBSymbol(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
public:
static std::unique_ptr<PDBSymbol>
create(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
virtual ~PDBSymbol();
/// Dumps the contents of a symbol a raw_ostream. By default this will just
/// call dump() on the underlying RawSymbol, which allows us to discover
/// unknown properties, but individual implementations of PDBSymbol may
/// override the behavior to only dump known fields.
virtual void dump(PDBSymDumper &Dumper) const = 0;
void defaultDump(raw_ostream &OS, int Indent) const;
PDB_SymType getSymTag() const;
template <typename T> std::unique_ptr<T> findOneChild() const {
auto Enumerator(findAllChildren<T>());
return Enumerator->getNext();
}
template <typename T>
std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
auto BaseIter = RawSymbol->findChildren(T::Tag);
return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
}
std::unique_ptr<IPDBEnumSymbols> findAllChildren(PDB_SymType Type) const;
std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type, StringRef Name,
PDB_NameSearchFlags Flags) const;
std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
StringRef Name,
PDB_NameSearchFlags Flags,
uint32_t RVA) const;
std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
const IPDBSession &getSession() const { return Session; }
std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
protected:
const IPDBSession &Session;
const std::unique_ptr<IPDBRawSymbol> RawSymbol;
};
} // namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDB.h | //===- PDB.h - base header file for creating a PDB reader -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDB_H
#define LLVM_DEBUGINFO_PDB_PDB_H
#include "PDBTypes.h"
#include <memory>
namespace llvm {
class StringRef;
PDB_ErrorCode loadDataForPDB(PDB_ReaderType Type, StringRef Path,
std::unique_ptr<IPDBSession> &Session);
PDB_ErrorCode loadDataForEXE(PDB_ReaderType Type, StringRef Path,
std::unique_ptr<IPDBSession> &Session);
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h | //===- ConcreteSymbolEnumerator.h -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_CONCRETESYMBOLENUMERATOR_H
#define LLVM_DEBUGINFO_PDB_CONCRETESYMBOLENUMERATOR_H
#include "IPDBEnumChildren.h"
#include "llvm/Support/Casting.h"
#include <memory>
namespace llvm {
template <typename ChildType>
class ConcreteSymbolEnumerator : public IPDBEnumChildren<ChildType> {
public:
ConcreteSymbolEnumerator(std::unique_ptr<IPDBEnumSymbols> SymbolEnumerator)
: Enumerator(std::move(SymbolEnumerator)) {}
~ConcreteSymbolEnumerator() override {}
uint32_t getChildCount() const override {
return Enumerator->getChildCount();
}
std::unique_ptr<ChildType> getChildAtIndex(uint32_t Index) const override {
std::unique_ptr<PDBSymbol> Child = Enumerator->getChildAtIndex(Index);
return make_concrete_child(std::move(Child));
}
std::unique_ptr<ChildType> getNext() override {
std::unique_ptr<PDBSymbol> Child = Enumerator->getNext();
return make_concrete_child(std::move(Child));
}
void reset() override { Enumerator->reset(); }
ConcreteSymbolEnumerator<ChildType> *clone() const override {
std::unique_ptr<IPDBEnumSymbols> WrappedClone(Enumerator->clone());
return new ConcreteSymbolEnumerator<ChildType>(std::move(WrappedClone));
}
private:
std::unique_ptr<ChildType>
make_concrete_child(std::unique_ptr<PDBSymbol> Child) const {
ChildType *ConcreteChild = dyn_cast_or_null<ChildType>(Child.release());
return std::unique_ptr<ChildType>(ConcreteChild);
}
std::unique_ptr<IPDBEnumSymbols> Enumerator;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBExtras.h | //===- PDBExtras.h - helper functions and classes for PDBs -------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBEXTRAS_H
#define LLVM_DEBUGINFO_PDB_PDBEXTRAS_H
#include "PDBTypes.h"
#include "llvm/Support/raw_ostream.h"
#include <unordered_map>
namespace llvm {
typedef std::unordered_map<PDB_SymType, int> TagStats;
raw_ostream &operator<<(raw_ostream &OS, const PDB_VariantType &Value);
raw_ostream &operator<<(raw_ostream &OS, const PDB_CallingConv &Conv);
raw_ostream &operator<<(raw_ostream &OS, const PDB_DataKind &Data);
raw_ostream &operator<<(raw_ostream &OS, const PDB_RegisterId &Reg);
raw_ostream &operator<<(raw_ostream &OS, const PDB_LocType &Loc);
raw_ostream &operator<<(raw_ostream &OS, const PDB_ThunkOrdinal &Thunk);
raw_ostream &operator<<(raw_ostream &OS, const PDB_Checksum &Checksum);
raw_ostream &operator<<(raw_ostream &OS, const PDB_Lang &Lang);
raw_ostream &operator<<(raw_ostream &OS, const PDB_SymType &Tag);
raw_ostream &operator<<(raw_ostream &OS, const PDB_MemberAccess &Access);
raw_ostream &operator<<(raw_ostream &OS, const PDB_UdtType &Type);
raw_ostream &operator<<(raw_ostream &OS, const PDB_UniqueId &Id);
raw_ostream &operator<<(raw_ostream &OS, const Variant &Value);
raw_ostream &operator<<(raw_ostream &OS, const VersionInfo &Version);
raw_ostream &operator<<(raw_ostream &OS, const TagStats &Stats);
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h | //===- PDBSymbolTypeManaged.h - managed type info ---------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEMANAGED_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEMANAGED_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeManaged : public PDBSymbol {
public:
PDBSymbolTypeManaged(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ManagedType)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(getSymIndexId)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEMANAGED_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h | //===- PDBSymbolTypeCustom.h - custom compiler type information -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPECUSTOM_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPECUSTOM_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeCustom : public PDBSymbol {
public:
PDBSymbolTypeCustom(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CustomType)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getOemId)
FORWARD_SYMBOL_METHOD(getOemSymbolId)
FORWARD_SYMBOL_METHOD(getSymIndexId)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPECUSTOM_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h | //===- PDBSymbolTypeFunctionArg.h - function arg type info ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEFUNCTIONARG_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEFUNCTIONARG_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeFunctionArg : public PDBSymbol {
public:
PDBSymbolTypeFunctionArg(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionArg)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getTypeId)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEFUNCTIONARG_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h | //===- PDBSymbolTypeVTableShape.h - VTable shape info -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEVTABLESHAPE_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEVTABLESHAPE_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeVTableShape : public PDBSymbol {
public:
PDBSymbolTypeVTableShape(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> VtblShapeSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTableShape)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(getCount)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEVTABLESHAPE_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h | //===- PDBSymbolTypeUDT.h - UDT type info -----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEUDT_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEUDT_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeUDT : public PDBSymbol {
public:
PDBSymbolTypeUDT(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> UDTSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UDT)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(getUnmodifiedTypeId)
FORWARD_SYMBOL_METHOD(hasConstructor)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(hasAssignmentOperator)
FORWARD_SYMBOL_METHOD(hasCastOperator)
FORWARD_SYMBOL_METHOD(hasNestedTypes)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(isNested)
FORWARD_SYMBOL_METHOD(hasOverloadedOperator)
FORWARD_SYMBOL_METHOD(isPacked)
FORWARD_SYMBOL_METHOD(isScoped)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getUdtKind)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(getVirtualTableShapeId)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEUDT_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h | //===- PDBSymbolFuncDebugStart.h - function start bounds info ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLFUNCDEBUGSTART_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLFUNCDEBUGSTART_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolFuncDebugStart : public PDBSymbol {
public:
PDBSymbolFuncDebugStart(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> FuncDebugStartSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugStart)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
FORWARD_SYMBOL_METHOD(hasCustomCallingConvention)
FORWARD_SYMBOL_METHOD(hasFarReturn)
FORWARD_SYMBOL_METHOD(hasInterruptReturn)
FORWARD_SYMBOL_METHOD(isStatic)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getLocationType)
FORWARD_SYMBOL_METHOD(hasNoInlineAttribute)
FORWARD_SYMBOL_METHOD(hasNoReturnAttribute)
FORWARD_SYMBOL_METHOD(isUnreached)
FORWARD_SYMBOL_METHOD(getOffset)
FORWARD_SYMBOL_METHOD(hasOptimizedCodeDebugInfo)
FORWARD_SYMBOL_METHOD(getRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getVirtualAddress)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLFUNCDEBUGSTART_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h | //===- PDBSymbolCompiland.h - Accessors for querying PDB compilands -----*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLCOMPILAND_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLCOMPILAND_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
#include <string>
namespace llvm {
class raw_ostream;
class PDBSymbolCompiland : public PDBSymbol {
public:
PDBSymbolCompiland(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> CompilandSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Compiland)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(isEditAndContinueEnabled)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getLibraryName)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(getSourceFileName)
FORWARD_SYMBOL_METHOD(getSymIndexId)
};
}
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLCOMPILAND_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/IPDBRawSymbol.h | //===- IPDBRawSymbol.h - base interface for PDB symbol types ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_IPDBRAWSYMBOL_H
#define LLVM_DEBUGINFO_PDB_IPDBRAWSYMBOL_H
#include "PDBTypes.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <memory>
namespace llvm {
class raw_ostream;
/// IPDBRawSymbol defines an interface used to represent an arbitrary symbol.
/// It exposes a monolithic interface consisting of accessors for the union of
/// all properties that are valid for any symbol type. This interface is then
/// wrapped by a concrete class which exposes only those set of methods valid
/// for this particular symbol type. See PDBSymbol.h for more details.
class IPDBRawSymbol {
public:
virtual ~IPDBRawSymbol();
virtual void dump(raw_ostream &OS, int Indent) const = 0;
virtual std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type) const = 0;
virtual std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type, StringRef Name,
PDB_NameSearchFlags Flags) const = 0;
virtual std::unique_ptr<IPDBEnumSymbols>
findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
uint32_t RVA) const = 0;
virtual std::unique_ptr<IPDBEnumSymbols>
findInlineFramesByRVA(uint32_t RVA) const = 0;
virtual void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const = 0;
virtual void getBackEndVersion(VersionInfo &Version) const = 0;
virtual PDB_MemberAccess getAccess() const = 0;
virtual uint32_t getAddressOffset() const = 0;
virtual uint32_t getAddressSection() const = 0;
virtual uint32_t getAge() const = 0;
virtual uint32_t getArrayIndexTypeId() const = 0;
virtual uint32_t getBaseDataOffset() const = 0;
virtual uint32_t getBaseDataSlot() const = 0;
virtual uint32_t getBaseSymbolId() const = 0;
virtual PDB_BuiltinType getBuiltinType() const = 0;
virtual uint32_t getBitPosition() const = 0;
virtual PDB_CallingConv getCallingConvention() const = 0;
virtual uint32_t getClassParentId() const = 0;
virtual std::string getCompilerName() const = 0;
virtual uint32_t getCount() const = 0;
virtual uint32_t getCountLiveRanges() const = 0;
virtual void getFrontEndVersion(VersionInfo &Version) const = 0;
virtual PDB_Lang getLanguage() const = 0;
virtual uint32_t getLexicalParentId() const = 0;
virtual std::string getLibraryName() const = 0;
virtual uint32_t getLiveRangeStartAddressOffset() const = 0;
virtual uint32_t getLiveRangeStartAddressSection() const = 0;
virtual uint32_t getLiveRangeStartRelativeVirtualAddress() const = 0;
virtual PDB_RegisterId getLocalBasePointerRegisterId() const = 0;
virtual uint32_t getLowerBoundId() const = 0;
virtual uint32_t getMemorySpaceKind() const = 0;
virtual std::string getName() const = 0;
virtual uint32_t getNumberOfAcceleratorPointerTags() const = 0;
virtual uint32_t getNumberOfColumns() const = 0;
virtual uint32_t getNumberOfModifiers() const = 0;
virtual uint32_t getNumberOfRegisterIndices() const = 0;
virtual uint32_t getNumberOfRows() const = 0;
virtual std::string getObjectFileName() const = 0;
virtual uint32_t getOemId() const = 0;
virtual uint32_t getOemSymbolId() const = 0;
virtual uint32_t getOffsetInUdt() const = 0;
virtual PDB_Cpu getPlatform() const = 0;
virtual uint32_t getRank() const = 0;
virtual PDB_RegisterId getRegisterId() const = 0;
virtual uint32_t getRegisterType() const = 0;
virtual uint32_t getRelativeVirtualAddress() const = 0;
virtual uint32_t getSamplerSlot() const = 0;
virtual uint32_t getSignature() const = 0;
virtual uint32_t getSizeInUdt() const = 0;
virtual uint32_t getSlot() const = 0;
virtual std::string getSourceFileName() const = 0;
virtual uint32_t getStride() const = 0;
virtual uint32_t getSubTypeId() const = 0;
virtual std::string getSymbolsFileName() const = 0;
virtual uint32_t getSymIndexId() const = 0;
virtual uint32_t getTargetOffset() const = 0;
virtual uint32_t getTargetRelativeVirtualAddress() const = 0;
virtual uint64_t getTargetVirtualAddress() const = 0;
virtual uint32_t getTargetSection() const = 0;
virtual uint32_t getTextureSlot() const = 0;
virtual uint32_t getTimeStamp() const = 0;
virtual uint32_t getToken() const = 0;
virtual uint32_t getTypeId() const = 0;
virtual uint32_t getUavSlot() const = 0;
virtual std::string getUndecoratedName() const = 0;
virtual uint32_t getUnmodifiedTypeId() const = 0;
virtual uint32_t getUpperBoundId() const = 0;
virtual Variant getValue() const = 0;
virtual uint32_t getVirtualBaseDispIndex() const = 0;
virtual uint32_t getVirtualBaseOffset() const = 0;
virtual uint32_t getVirtualTableShapeId() const = 0;
virtual PDB_DataKind getDataKind() const = 0;
virtual PDB_SymType getSymTag() const = 0;
virtual PDB_UniqueId getGuid() const = 0;
virtual int32_t getOffset() const = 0;
virtual int32_t getThisAdjust() const = 0;
virtual int32_t getVirtualBasePointerOffset() const = 0;
virtual PDB_LocType getLocationType() const = 0;
virtual PDB_Machine getMachineType() const = 0;
virtual PDB_ThunkOrdinal getThunkOrdinal() const = 0;
virtual uint64_t getLength() const = 0;
virtual uint64_t getLiveRangeLength() const = 0;
virtual uint64_t getVirtualAddress() const = 0;
virtual PDB_UdtType getUdtKind() const = 0;
virtual bool hasConstructor() const = 0;
virtual bool hasCustomCallingConvention() const = 0;
virtual bool hasFarReturn() const = 0;
virtual bool isCode() const = 0;
virtual bool isCompilerGenerated() const = 0;
virtual bool isConstType() const = 0;
virtual bool isEditAndContinueEnabled() const = 0;
virtual bool isFunction() const = 0;
virtual bool getAddressTaken() const = 0;
virtual bool getNoStackOrdering() const = 0;
virtual bool hasAlloca() const = 0;
virtual bool hasAssignmentOperator() const = 0;
virtual bool hasCTypes() const = 0;
virtual bool hasCastOperator() const = 0;
virtual bool hasDebugInfo() const = 0;
virtual bool hasEH() const = 0;
virtual bool hasEHa() const = 0;
virtual bool hasFramePointer() const = 0;
virtual bool hasInlAsm() const = 0;
virtual bool hasInlineAttribute() const = 0;
virtual bool hasInterruptReturn() const = 0;
virtual bool hasLongJump() const = 0;
virtual bool hasManagedCode() const = 0;
virtual bool hasNestedTypes() const = 0;
virtual bool hasNoInlineAttribute() const = 0;
virtual bool hasNoReturnAttribute() const = 0;
virtual bool hasOptimizedCodeDebugInfo() const = 0;
virtual bool hasOverloadedOperator() const = 0;
virtual bool hasSEH() const = 0;
virtual bool hasSecurityChecks() const = 0;
virtual bool hasSetJump() const = 0;
virtual bool hasStrictGSCheck() const = 0;
virtual bool isAcceleratorGroupSharedLocal() const = 0;
virtual bool isAcceleratorPointerTagLiveRange() const = 0;
virtual bool isAcceleratorStubFunction() const = 0;
virtual bool isAggregated() const = 0;
virtual bool isIntroVirtualFunction() const = 0;
virtual bool isCVTCIL() const = 0;
virtual bool isConstructorVirtualBase() const = 0;
virtual bool isCxxReturnUdt() const = 0;
virtual bool isDataAligned() const = 0;
virtual bool isHLSLData() const = 0;
virtual bool isHotpatchable() const = 0;
virtual bool isIndirectVirtualBaseClass() const = 0;
virtual bool isInterfaceUdt() const = 0;
virtual bool isIntrinsic() const = 0;
virtual bool isLTCG() const = 0;
virtual bool isLocationControlFlowDependent() const = 0;
virtual bool isMSILNetmodule() const = 0;
virtual bool isMatrixRowMajor() const = 0;
virtual bool isManagedCode() const = 0;
virtual bool isMSILCode() const = 0;
virtual bool isMultipleInheritance() const = 0;
virtual bool isNaked() const = 0;
virtual bool isNested() const = 0;
virtual bool isOptimizedAway() const = 0;
virtual bool isPacked() const = 0;
virtual bool isPointerBasedOnSymbolValue() const = 0;
virtual bool isPointerToDataMember() const = 0;
virtual bool isPointerToMemberFunction() const = 0;
virtual bool isPureVirtual() const = 0;
virtual bool isRValueReference() const = 0;
virtual bool isRefUdt() const = 0;
virtual bool isReference() const = 0;
virtual bool isRestrictedType() const = 0;
virtual bool isReturnValue() const = 0;
virtual bool isSafeBuffers() const = 0;
virtual bool isScoped() const = 0;
virtual bool isSdl() const = 0;
virtual bool isSingleInheritance() const = 0;
virtual bool isSplitted() const = 0;
virtual bool isStatic() const = 0;
virtual bool hasPrivateSymbols() const = 0;
virtual bool isUnalignedType() const = 0;
virtual bool isUnreached() const = 0;
virtual bool isValueUdt() const = 0;
virtual bool isVirtual() const = 0;
virtual bool isVirtualBaseClass() const = 0;
virtual bool isVirtualInheritance() const = 0;
virtual bool isVolatileType() const = 0;
virtual bool wasInlined() const = 0;
virtual std::string getUnused() const = 0;
};
} // namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h | //===- PDBSymbolPublicSymbol.h - public symbol info -------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLPUBLICSYMBOL_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLPUBLICSYMBOL_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolPublicSymbol : public PDBSymbol {
public:
PDBSymbolPublicSymbol(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> PublicSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PublicSymbol)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
FORWARD_SYMBOL_METHOD(isCode)
FORWARD_SYMBOL_METHOD(isFunction)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getLocationType)
FORWARD_SYMBOL_METHOD(isManagedCode)
FORWARD_SYMBOL_METHOD(isMSILCode)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getVirtualAddress)
FORWARD_SYMBOL_METHOD(getUndecoratedName)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLPUBLICSYMBOL_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h | //===- PDBSymbolTypeBuiltin.h - builtin type information --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEBUILTIN_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEBUILTIN_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeBuiltin : public PDBSymbol {
public:
PDBSymbolTypeBuiltin(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BuiltinType)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getBuiltinType)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEBUILTIN_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolCustom.h | //===- PDBSymbolCustom.h - compiler-specific types --------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLCUSTOM_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLCUSTOM_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
#include "llvm/ADT/SmallVector.h"
namespace llvm {
class raw_ostream;
/// PDBSymbolCustom represents symbols that are compiler-specific and do not
/// fit anywhere else in the lexical hierarchy.
/// https://msdn.microsoft.com/en-us/library/d88sf09h.aspx
class PDBSymbolCustom : public PDBSymbol {
public:
PDBSymbolCustom(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> CustomSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Custom)
void dump(PDBSymDumper &Dumper) const override;
void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes);
FORWARD_SYMBOL_METHOD(getSymIndexId)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLCUSTOM_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymDumper.h | //===- PDBSymDumper.h - base interface for PDB symbol dumper *- C++ -----*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMDUMPER_H
#define LLVM_DEBUGINFO_PDB_PDBSYMDUMPER_H
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymDumper {
public:
PDBSymDumper(bool ShouldRequireImpl);
virtual ~PDBSymDumper();
virtual void dump(const PDBSymbolAnnotation &Symbol);
virtual void dump(const PDBSymbolBlock &Symbol);
virtual void dump(const PDBSymbolCompiland &Symbol);
virtual void dump(const PDBSymbolCompilandDetails &Symbol);
virtual void dump(const PDBSymbolCompilandEnv &Symbol);
virtual void dump(const PDBSymbolCustom &Symbol);
virtual void dump(const PDBSymbolData &Symbol);
virtual void dump(const PDBSymbolExe &Symbol);
virtual void dump(const PDBSymbolFunc &Symbol);
virtual void dump(const PDBSymbolFuncDebugEnd &Symbol);
virtual void dump(const PDBSymbolFuncDebugStart &Symbol);
virtual void dump(const PDBSymbolLabel &Symbol);
virtual void dump(const PDBSymbolPublicSymbol &Symbol);
virtual void dump(const PDBSymbolThunk &Symbol);
virtual void dump(const PDBSymbolTypeArray &Symbol);
virtual void dump(const PDBSymbolTypeBaseClass &Symbol);
virtual void dump(const PDBSymbolTypeBuiltin &Symbol);
virtual void dump(const PDBSymbolTypeCustom &Symbol);
virtual void dump(const PDBSymbolTypeDimension &Symbol);
virtual void dump(const PDBSymbolTypeEnum &Symbol);
virtual void dump(const PDBSymbolTypeFriend &Symbol);
virtual void dump(const PDBSymbolTypeFunctionArg &Symbol);
virtual void dump(const PDBSymbolTypeFunctionSig &Symbol);
virtual void dump(const PDBSymbolTypeManaged &Symbol);
virtual void dump(const PDBSymbolTypePointer &Symbol);
virtual void dump(const PDBSymbolTypeTypedef &Symbol);
virtual void dump(const PDBSymbolTypeUDT &Symbol);
virtual void dump(const PDBSymbolTypeVTable &Symbol);
virtual void dump(const PDBSymbolTypeVTableShape &Symbol);
virtual void dump(const PDBSymbolUnknown &Symbol);
virtual void dump(const PDBSymbolUsingNamespace &Symbol);
private:
bool RequireImpl;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h | //===- PDBSymbolTypeEnum.h - enum type info ---------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEENUM_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEENUM_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeEnum : public PDBSymbol {
public:
PDBSymbolTypeEnum(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> EnumTypeSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Enum)
void dump(PDBSymDumper &Dumper) const override;
std::unique_ptr<PDBSymbolTypeUDT> getClassParent() const;
std::unique_ptr<PDBSymbolTypeBuiltin> getUnderlyingType() const;
FORWARD_SYMBOL_METHOD(getBuiltinType)
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(getUnmodifiedTypeId)
FORWARD_SYMBOL_METHOD(hasConstructor)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(hasAssignmentOperator)
FORWARD_SYMBOL_METHOD(hasCastOperator)
FORWARD_SYMBOL_METHOD(hasNestedTypes)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(isNested)
FORWARD_SYMBOL_METHOD(hasOverloadedOperator)
FORWARD_SYMBOL_METHOD(isPacked)
FORWARD_SYMBOL_METHOD(isScoped)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEENUM_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/IPDBLineNumber.h | //===- IPDBLineNumber.h - base interface for PDB line no. info ---*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_IPDBLINENUMBER_H
#define LLVM_DEBUGINFO_PDB_IPDBLINENUMBER_H
#include "PDBTypes.h"
namespace llvm {
class IPDBLineNumber {
public:
virtual ~IPDBLineNumber();
virtual uint32_t getLineNumber() const = 0;
virtual uint32_t getLineNumberEnd() const = 0;
virtual uint32_t getColumnNumber() const = 0;
virtual uint32_t getColumnNumberEnd() const = 0;
virtual uint32_t getAddressSection() const = 0;
virtual uint32_t getAddressOffset() const = 0;
virtual uint32_t getRelativeVirtualAddress() const = 0;
virtual uint64_t getVirtualAddress() const = 0;
virtual uint32_t getLength() const = 0;
virtual uint32_t getSourceFileId() const = 0;
virtual uint32_t getCompilandId() const = 0;
virtual bool isStatement() const = 0;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h | //===- PDBSymbolTypeBaseClass.h - base class type information ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEBASECLASS_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEBASECLASS_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeBaseClass : public PDBSymbol {
public:
PDBSymbolTypeBaseClass(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BaseClass)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getAccess)
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(hasConstructor)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(hasAssignmentOperator)
FORWARD_SYMBOL_METHOD(hasCastOperator)
FORWARD_SYMBOL_METHOD(hasNestedTypes)
FORWARD_SYMBOL_METHOD(isIndirectVirtualBaseClass)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(isNested)
FORWARD_SYMBOL_METHOD(getOffset)
FORWARD_SYMBOL_METHOD(hasOverloadedOperator)
FORWARD_SYMBOL_METHOD(isPacked)
FORWARD_SYMBOL_METHOD(isScoped)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(getUdtKind)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(isVirtualBaseClass)
FORWARD_SYMBOL_METHOD(getVirtualBaseDispIndex)
FORWARD_SYMBOL_METHOD(getVirtualBasePointerOffset)
// FORWARD_SYMBOL_METHOD(getVirtualBaseTableType)
FORWARD_SYMBOL_METHOD(getVirtualTableShapeId)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEBASECLASS_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeArray.h | //===- PDBSymbolTypeArray.h - array type information ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEARRAY_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEARRAY_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeArray : public PDBSymbol {
public:
PDBSymbolTypeArray(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> ArrayTypeSymbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ArrayType)
std::unique_ptr<PDBSymbol> getElementType() const;
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getArrayIndexTypeId)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(getCount)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getRank)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEARRAY_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h | //===- PDBSymbolCompilandEnv.h - compiland environment variables *- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLCOMPILANDENV_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLCOMPILANDENV_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolCompilandEnv : public PDBSymbol {
public:
PDBSymbolCompilandEnv(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandEnv)
void dump(PDBSymDumper &Dumper) const override;
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(getSymIndexId)
std::string getValue() const;
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLCOMPILANDENV_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h | //===- PDBSymbolTypeFunctionSig.h - function signature type info *- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEFUNCTIONSIG_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEFUNCTIONSIG_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolTypeFunctionSig : public PDBSymbol {
public:
PDBSymbolTypeFunctionSig(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> Symbol);
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionSig)
std::unique_ptr<PDBSymbol> getReturnType() const;
std::unique_ptr<IPDBEnumSymbols> getArguments() const;
std::unique_ptr<PDBSymbol> getClassParent() const;
void dump(PDBSymDumper &Dumper) const override;
void dumpArgList(raw_ostream &OS) const;
FORWARD_SYMBOL_METHOD(getCallingConvention)
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(getUnmodifiedTypeId)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(getCount)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
// FORWARD_SYMBOL_METHOD(getObjectPointerType)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getThisAdjust)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLTYPEFUNCTIONSIG_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/PDBSymbolFunc.h | //===- PDBSymbolFunc.h - class representing a function instance -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_PDBSYMBOLFUNC_H
#define LLVM_DEBUGINFO_PDB_PDBSYMBOLFUNC_H
#include "PDBSymbol.h"
#include "PDBTypes.h"
namespace llvm {
class raw_ostream;
class PDBSymbolFunc : public PDBSymbol {
public:
PDBSymbolFunc(const IPDBSession &PDBSession,
std::unique_ptr<IPDBRawSymbol> FuncSymbol);
void dump(PDBSymDumper &Dumper) const override;
std::unique_ptr<PDBSymbolTypeFunctionSig> getSignature() const;
std::unique_ptr<PDBSymbolTypeUDT> getClassParent() const;
std::unique_ptr<IPDBEnumChildren<PDBSymbolData>> getArguments() const;
DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Function)
FORWARD_SYMBOL_METHOD(getAccess)
FORWARD_SYMBOL_METHOD(getAddressOffset)
FORWARD_SYMBOL_METHOD(getAddressSection)
FORWARD_SYMBOL_METHOD(getClassParentId)
FORWARD_SYMBOL_METHOD(isCompilerGenerated)
FORWARD_SYMBOL_METHOD(isConstType)
FORWARD_SYMBOL_METHOD(hasCustomCallingConvention)
FORWARD_SYMBOL_METHOD(hasFarReturn)
FORWARD_SYMBOL_METHOD(hasAlloca)
FORWARD_SYMBOL_METHOD(hasEH)
FORWARD_SYMBOL_METHOD(hasEHa)
FORWARD_SYMBOL_METHOD(hasInlAsm)
FORWARD_SYMBOL_METHOD(hasLongJump)
FORWARD_SYMBOL_METHOD(hasSEH)
FORWARD_SYMBOL_METHOD(hasSecurityChecks)
FORWARD_SYMBOL_METHOD(hasSetJump)
FORWARD_SYMBOL_METHOD(hasInterruptReturn)
FORWARD_SYMBOL_METHOD(isIntroVirtualFunction)
FORWARD_SYMBOL_METHOD(hasInlineAttribute)
FORWARD_SYMBOL_METHOD(isNaked)
FORWARD_SYMBOL_METHOD(isStatic)
FORWARD_SYMBOL_METHOD(getLength)
FORWARD_SYMBOL_METHOD(getLexicalParentId)
FORWARD_SYMBOL_METHOD(getLocalBasePointerRegisterId)
FORWARD_SYMBOL_METHOD(getLocationType)
FORWARD_SYMBOL_METHOD(getName)
FORWARD_SYMBOL_METHOD(hasFramePointer)
FORWARD_SYMBOL_METHOD(hasNoInlineAttribute)
FORWARD_SYMBOL_METHOD(hasNoReturnAttribute)
FORWARD_SYMBOL_METHOD(isUnreached)
FORWARD_SYMBOL_METHOD(getNoStackOrdering)
FORWARD_SYMBOL_METHOD(hasOptimizedCodeDebugInfo)
FORWARD_SYMBOL_METHOD(isPureVirtual)
FORWARD_SYMBOL_METHOD(getRelativeVirtualAddress)
FORWARD_SYMBOL_METHOD(getSymIndexId)
FORWARD_SYMBOL_METHOD(getToken)
FORWARD_SYMBOL_METHOD(getTypeId)
FORWARD_SYMBOL_METHOD(isUnalignedType)
FORWARD_SYMBOL_METHOD(getUndecoratedName)
FORWARD_SYMBOL_METHOD(isVirtual)
FORWARD_SYMBOL_METHOD(getVirtualAddress)
FORWARD_SYMBOL_METHOD(getVirtualBaseOffset)
FORWARD_SYMBOL_METHOD(isVolatileType)
};
} // namespace llvm
#endif // LLVM_DEBUGINFO_PDB_PDBSYMBOLFUNC_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIASupport.h | //===- DIASupport.h - Common header includes for DIA ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Common defines and header includes for all LLVMDebugInfoPDBDIA. The
// definitions here configure the necessary #defines and include system headers
// in the proper order for using DIA.
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIASUPPORT_H
#define LLVM_DEBUGINFO_PDB_DIA_DIASUPPORT_H
// Require at least Vista
#define NTDDI_VERSION NTDDI_VISTA
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#define WINVER _WIN32_WINNT_VISTA
#ifndef NOMINMAX
#define NOMINMAX
#endif
// atlbase.h has to come before windows.h
#include <atlbase.h>
#include <windows.h>
// DIA headers must come after windows headers.
#include <cvconst.h>
#include <dia2.h>
#endif // LLVM_DEBUGINFO_PDB_DIA_DIASUPPORT_H
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIALineNumber.h | //===- DIALineNumber.h - DIA implementation of IPDBLineNumber ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIALINENUMBER_H
#define LLVM_DEBUGINFO_PDB_DIA_DIALINENUMBER_H
#include "DIASupport.h"
#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
namespace llvm {
class DIALineNumber : public IPDBLineNumber {
public:
explicit DIALineNumber(CComPtr<IDiaLineNumber> DiaLineNumber);
uint32_t getLineNumber() const override;
uint32_t getLineNumberEnd() const override;
uint32_t getColumnNumber() const override;
uint32_t getColumnNumberEnd() const override;
uint32_t getAddressSection() const override;
uint32_t getAddressOffset() const override;
uint32_t getRelativeVirtualAddress() const override;
uint64_t getVirtualAddress() const override;
uint32_t getLength() const override;
uint32_t getSourceFileId() const override;
uint32_t getCompilandId() const override;
bool isStatement() const override;
private:
CComPtr<IDiaLineNumber> LineNumber;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIAEnumLineNumbers.h | //==- DIAEnumLineNumbers.h - DIA Line Number Enumerator impl -----*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIAENUMLINENUMBERS_H
#define LLVM_DEBUGINFO_PDB_DIA_DIAENUMLINENUMBERS_H
#include "DIASupport.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
namespace llvm {
class IPDBLineNumber;
class DIAEnumLineNumbers : public IPDBEnumChildren<IPDBLineNumber> {
public:
explicit DIAEnumLineNumbers(CComPtr<IDiaEnumLineNumbers> DiaEnumerator);
uint32_t getChildCount() const override;
ChildTypePtr getChildAtIndex(uint32_t Index) const override;
ChildTypePtr getNext() override;
void reset() override;
DIAEnumLineNumbers *clone() const override;
private:
CComPtr<IDiaEnumLineNumbers> Enumerator;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIADataStream.h | //===- DIADataStream.h - DIA implementation of IPDBDataStream ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIADATASTREAM_H
#define LLVM_DEBUGINFO_PDB_DIA_DIADATASTREAM_H
#include "DIASupport.h"
#include "llvm/DebugInfo/PDB/IPDBDataStream.h"
namespace llvm {
class DIADataStream : public IPDBDataStream {
public:
explicit DIADataStream(CComPtr<IDiaEnumDebugStreamData> DiaStreamData);
uint32_t getRecordCount() const override;
std::string getName() const override;
llvm::Optional<RecordType> getItemAtIndex(uint32_t Index) const override;
bool getNext(RecordType &Record) override;
void reset() override;
DIADataStream *clone() const override;
private:
CComPtr<IDiaEnumDebugStreamData> StreamData;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h | //==- DIAEnumSymbols.h - DIA Symbol Enumerator impl --------------*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIAENUMSYMBOLS_H
#define LLVM_DEBUGINFO_PDB_DIA_DIAENUMSYMBOLS_H
#include "DIASupport.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
namespace llvm {
class DIASession;
class DIAEnumSymbols : public IPDBEnumChildren<PDBSymbol> {
public:
explicit DIAEnumSymbols(const DIASession &Session,
CComPtr<IDiaEnumSymbols> DiaEnumerator);
uint32_t getChildCount() const override;
std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override;
std::unique_ptr<PDBSymbol> getNext() override;
void reset() override;
DIAEnumSymbols *clone() const override;
private:
const DIASession &Session;
CComPtr<IDiaEnumSymbols> Enumerator;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIAEnumSourceFiles.h | //==- DIAEnumSourceFiles.h - DIA Source File Enumerator impl -----*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIAENUMSOURCEFILES_H
#define LLVM_DEBUGINFO_PDB_DIA_DIAENUMSOURCEFILES_H
#include "DIASupport.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
namespace llvm {
class DIASession;
class DIAEnumSourceFiles : public IPDBEnumChildren<IPDBSourceFile> {
public:
explicit DIAEnumSourceFiles(const DIASession &PDBSession,
CComPtr<IDiaEnumSourceFiles> DiaEnumerator);
uint32_t getChildCount() const override;
ChildTypePtr getChildAtIndex(uint32_t Index) const override;
ChildTypePtr getNext() override;
void reset() override;
DIAEnumSourceFiles *clone() const override;
private:
const DIASession &Session;
CComPtr<IDiaEnumSourceFiles> Enumerator;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIASourceFile.h | //===- DIASourceFile.h - DIA implementation of IPDBSourceFile ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIASOURCEFILE_H
#define LLVM_DEBUGINFO_PDB_DIA_DIASOURCEFILE_H
#include "DIASupport.h"
#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
namespace llvm {
class DIASession;
class DIASourceFile : public IPDBSourceFile {
public:
explicit DIASourceFile(const DIASession &Session,
CComPtr<IDiaSourceFile> DiaSourceFile);
std::string getFileName() const override;
uint32_t getUniqueId() const override;
std::string getChecksum() const override;
PDB_Checksum getChecksumType() const override;
std::unique_ptr<IPDBEnumSymbols> getCompilands() const override;
private:
const DIASession &Session;
CComPtr<IDiaSourceFile> SourceFile;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIAEnumDebugStreams.h | //==- DIAEnumDebugStreams.h - DIA Debug Stream Enumerator impl ---*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIAENUMDEBUGSTREAMS_H
#define LLVM_DEBUGINFO_PDB_DIA_DIAENUMDEBUGSTREAMS_H
#include "DIASupport.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
namespace llvm {
class IPDBDataStream;
class DIAEnumDebugStreams : public IPDBEnumChildren<IPDBDataStream> {
public:
explicit DIAEnumDebugStreams(CComPtr<IDiaEnumDebugStreams> DiaEnumerator);
uint32_t getChildCount() const override;
ChildTypePtr getChildAtIndex(uint32_t Index) const override;
ChildTypePtr getNext() override;
void reset() override;
DIAEnumDebugStreams *clone() const override;
private:
CComPtr<IDiaEnumDebugStreams> Enumerator;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIASession.h | //===- DIASession.h - DIA implementation of IPDBSession ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIASESSION_H
#define LLVM_DEBUGINFO_PDB_DIA_DIASESSION_H
#include "DIASupport.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
namespace llvm {
class DIASession : public IPDBSession {
public:
explicit DIASession(CComPtr<IDiaSession> DiaSession);
static PDB_ErrorCode createFromPdb(StringRef Path,
std::unique_ptr<IPDBSession> &Session);
static PDB_ErrorCode createFromExe(StringRef Path,
std::unique_ptr<IPDBSession> &Session);
uint64_t getLoadAddress() const override;
void setLoadAddress(uint64_t Address) override;
std::unique_ptr<PDBSymbolExe> getGlobalScope() const override;
std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override;
std::unique_ptr<PDBSymbol>
findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override;
std::unique_ptr<IPDBEnumLineNumbers>
findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override;
std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override;
std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
const PDBSymbolCompiland &Compiland) const override;
std::unique_ptr<IPDBSourceFile>
getSourceFileById(uint32_t FileId) const override;
std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override;
private:
CComPtr<IDiaSession> Session;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB | repos/DirectXShaderCompiler/include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h | //===- DIARawSymbol.h - DIA implementation of IPDBRawSymbol ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIARAWSYMBOL_H
#define LLVM_DEBUGINFO_PDB_DIA_DIARAWSYMBOL_H
#include "DIASupport.h"
#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
namespace llvm {
class DIASession;
class DIARawSymbol : public IPDBRawSymbol {
public:
DIARawSymbol(const DIASession &PDBSession, CComPtr<IDiaSymbol> DiaSymbol);
void dump(raw_ostream &OS, int Indent) const override;
CComPtr<IDiaSymbol> getDiaSymbol() const { return Symbol; }
std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type) const override;
std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type, StringRef Name,
PDB_NameSearchFlags Flags) const override;
std::unique_ptr<IPDBEnumSymbols>
findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
uint32_t RVA) const override;
std::unique_ptr<IPDBEnumSymbols>
findInlineFramesByRVA(uint32_t RVA) const override;
void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const override;
void getFrontEndVersion(VersionInfo &Version) const override;
void getBackEndVersion(VersionInfo &Version) const override;
PDB_MemberAccess getAccess() const override;
uint32_t getAddressOffset() const override;
uint32_t getAddressSection() const override;
uint32_t getAge() const override;
uint32_t getArrayIndexTypeId() const override;
uint32_t getBaseDataOffset() const override;
uint32_t getBaseDataSlot() const override;
uint32_t getBaseSymbolId() const override;
PDB_BuiltinType getBuiltinType() const override;
uint32_t getBitPosition() const override;
PDB_CallingConv getCallingConvention() const override;
uint32_t getClassParentId() const override;
std::string getCompilerName() const override;
uint32_t getCount() const override;
uint32_t getCountLiveRanges() const override;
PDB_Lang getLanguage() const override;
uint32_t getLexicalParentId() const override;
std::string getLibraryName() const override;
uint32_t getLiveRangeStartAddressOffset() const override;
uint32_t getLiveRangeStartAddressSection() const override;
uint32_t getLiveRangeStartRelativeVirtualAddress() const override;
PDB_RegisterId getLocalBasePointerRegisterId() const override;
uint32_t getLowerBoundId() const override;
uint32_t getMemorySpaceKind() const override;
std::string getName() const override;
uint32_t getNumberOfAcceleratorPointerTags() const override;
uint32_t getNumberOfColumns() const override;
uint32_t getNumberOfModifiers() const override;
uint32_t getNumberOfRegisterIndices() const override;
uint32_t getNumberOfRows() const override;
std::string getObjectFileName() const override;
uint32_t getOemId() const override;
uint32_t getOemSymbolId() const override;
uint32_t getOffsetInUdt() const override;
PDB_Cpu getPlatform() const override;
uint32_t getRank() const override;
PDB_RegisterId getRegisterId() const override;
uint32_t getRegisterType() const override;
uint32_t getRelativeVirtualAddress() const override;
uint32_t getSamplerSlot() const override;
uint32_t getSignature() const override;
uint32_t getSizeInUdt() const override;
uint32_t getSlot() const override;
std::string getSourceFileName() const override;
uint32_t getStride() const override;
uint32_t getSubTypeId() const override;
std::string getSymbolsFileName() const override;
uint32_t getSymIndexId() const override;
uint32_t getTargetOffset() const override;
uint32_t getTargetRelativeVirtualAddress() const override;
uint64_t getTargetVirtualAddress() const override;
uint32_t getTargetSection() const override;
uint32_t getTextureSlot() const override;
uint32_t getTimeStamp() const override;
uint32_t getToken() const override;
uint32_t getTypeId() const override;
uint32_t getUavSlot() const override;
std::string getUndecoratedName() const override;
uint32_t getUnmodifiedTypeId() const override;
uint32_t getUpperBoundId() const override;
Variant getValue() const override;
uint32_t getVirtualBaseDispIndex() const override;
uint32_t getVirtualBaseOffset() const override;
uint32_t getVirtualTableShapeId() const override;
PDB_DataKind getDataKind() const override;
PDB_SymType getSymTag() const override;
PDB_UniqueId getGuid() const override;
int32_t getOffset() const override;
int32_t getThisAdjust() const override;
int32_t getVirtualBasePointerOffset() const override;
PDB_LocType getLocationType() const override;
PDB_Machine getMachineType() const override;
PDB_ThunkOrdinal getThunkOrdinal() const override;
uint64_t getLength() const override;
uint64_t getLiveRangeLength() const override;
uint64_t getVirtualAddress() const override;
PDB_UdtType getUdtKind() const override;
bool hasConstructor() const override;
bool hasCustomCallingConvention() const override;
bool hasFarReturn() const override;
bool isCode() const override;
bool isCompilerGenerated() const override;
bool isConstType() const override;
bool isEditAndContinueEnabled() const override;
bool isFunction() const override;
bool getAddressTaken() const override;
bool getNoStackOrdering() const override;
bool hasAlloca() const override;
bool hasAssignmentOperator() const override;
bool hasCTypes() const override;
bool hasCastOperator() const override;
bool hasDebugInfo() const override;
bool hasEH() const override;
bool hasEHa() const override;
bool hasInlAsm() const override;
bool hasInlineAttribute() const override;
bool hasInterruptReturn() const override;
bool hasFramePointer() const override;
bool hasLongJump() const override;
bool hasManagedCode() const override;
bool hasNestedTypes() const override;
bool hasNoInlineAttribute() const override;
bool hasNoReturnAttribute() const override;
bool hasOptimizedCodeDebugInfo() const override;
bool hasOverloadedOperator() const override;
bool hasSEH() const override;
bool hasSecurityChecks() const override;
bool hasSetJump() const override;
bool hasStrictGSCheck() const override;
bool isAcceleratorGroupSharedLocal() const override;
bool isAcceleratorPointerTagLiveRange() const override;
bool isAcceleratorStubFunction() const override;
bool isAggregated() const override;
bool isIntroVirtualFunction() const override;
bool isCVTCIL() const override;
bool isConstructorVirtualBase() const override;
bool isCxxReturnUdt() const override;
bool isDataAligned() const override;
bool isHLSLData() const override;
bool isHotpatchable() const override;
bool isIndirectVirtualBaseClass() const override;
bool isInterfaceUdt() const override;
bool isIntrinsic() const override;
bool isLTCG() const override;
bool isLocationControlFlowDependent() const override;
bool isMSILNetmodule() const override;
bool isMatrixRowMajor() const override;
bool isManagedCode() const override;
bool isMSILCode() const override;
bool isMultipleInheritance() const override;
bool isNaked() const override;
bool isNested() const override;
bool isOptimizedAway() const override;
bool isPacked() const override;
bool isPointerBasedOnSymbolValue() const override;
bool isPointerToDataMember() const override;
bool isPointerToMemberFunction() const override;
bool isPureVirtual() const override;
bool isRValueReference() const override;
bool isRefUdt() const override;
bool isReference() const override;
bool isRestrictedType() const override;
bool isReturnValue() const override;
bool isSafeBuffers() const override;
bool isScoped() const override;
bool isSdl() const override;
bool isSingleInheritance() const override;
bool isSplitted() const override;
bool isStatic() const override;
bool hasPrivateSymbols() const override;
bool isUnalignedType() const override;
bool isUnreached() const override;
bool isValueUdt() const override;
bool isVirtual() const override;
bool isVirtualBaseClass() const override;
bool isVirtualInheritance() const override;
bool isVolatileType() const override;
bool wasInlined() const override;
std::string getUnused() const override;
private:
const DIASession &Session;
CComPtr<IDiaSymbol> Symbol;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/llvm_assert/assert.h | ///////////////////////////////////////////////////////////////////////////////
// //
// assert.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Defines custom assert macro for clang/llvm. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#undef assert
#undef wassert
// This assert will raise a structured exception (RaiseException), using
// STATUS_LLVM_ASSERT. llvm_unreachable and report_fatal_error will also
// raise structured exceptions. Each indicate a condition from which the
// application should not continue, but can be useful for catching and logging
// during automated testing.
#define STATUS_LLVM_ASSERT 0xE0000001
#define STATUS_LLVM_UNREACHABLE 0xE0000002
#define STATUS_LLVM_FATAL 0xE0000003
#ifdef NDEBUG
#define assert(_Expression) ((void)0)
#else /* NDEBUG */
#ifdef __cplusplus
extern "C" {
#endif
void llvm_assert(const char *Message, const char *File, unsigned Line,
const char *Function);
#ifdef __cplusplus
}
#endif
// If LLVM_ASSERTIONS_NO_STRINGS is defined, pass empty strings to llvm_assert
// to reduce binary size.
#ifdef LLVM_ASSERTIONS_NO_STRINGS
#define assert(Expression) \
((void)((!!(Expression)) || (llvm_assert("", "", 0, ""), 0)))
#else
#define assert(Expression) \
((void)((!!(Expression)) || \
(llvm_assert(#Expression, __FILE__, __LINE__, __FUNCTION__), 0)))
#endif
#endif /* NDEBUG */
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/ExecutionEngine.h | //===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the abstract interface that implements execution support
// for LLVM.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
#define LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
#include "RuntimeDyld.h"
#include "llvm-c/ExecutionEngine.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/IR/ValueMap.h"
#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/Object/Binary.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include <map>
#include <string>
#include <vector>
#include <functional>
namespace llvm {
struct GenericValue;
class Constant;
class DataLayout;
class ExecutionEngine;
class Function;
class GlobalVariable;
class GlobalValue;
class JITEventListener;
class MachineCodeInfo;
class MCJITMemoryManager;
class MutexGuard;
class ObjectCache;
class RTDyldMemoryManager;
class Triple;
class Type;
namespace object {
class Archive;
class ObjectFile;
}
/// \brief Helper class for helping synchronize access to the global address map
/// table. Access to this class should be serialized under a mutex.
class ExecutionEngineState {
public:
typedef StringMap<uint64_t> GlobalAddressMapTy;
private:
/// GlobalAddressMap - A mapping between LLVM global symbol names values and
/// their actualized version...
GlobalAddressMapTy GlobalAddressMap;
/// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap,
/// used to convert raw addresses into the LLVM global value that is emitted
/// at the address. This map is not computed unless getGlobalValueAtAddress
/// is called at some point.
std::map<uint64_t, std::string> GlobalAddressReverseMap;
public:
GlobalAddressMapTy &getGlobalAddressMap() {
return GlobalAddressMap;
}
std::map<uint64_t, std::string> &getGlobalAddressReverseMap() {
return GlobalAddressReverseMap;
}
/// \brief Erase an entry from the mapping table.
///
/// \returns The address that \p ToUnmap was happed to.
uint64_t RemoveMapping(StringRef Name);
};
using FunctionCreator = std::function<void *(const std::string &)>;
/// \brief Abstract interface for implementation execution of LLVM modules,
/// designed to support both interpreter and just-in-time (JIT) compiler
/// implementations.
class ExecutionEngine {
/// The state object holding the global address mapping, which must be
/// accessed synchronously.
//
// FIXME: There is no particular need the entire map needs to be
// synchronized. Wouldn't a reader-writer design be better here?
ExecutionEngineState EEState;
/// The target data for the platform for which execution is being performed.
const DataLayout *DL;
/// Whether lazy JIT compilation is enabled.
bool CompilingLazily;
/// Whether JIT compilation of external global variables is allowed.
bool GVCompilationDisabled;
/// Whether the JIT should perform lookups of external symbols (e.g.,
/// using dlsym).
bool SymbolSearchingDisabled;
/// Whether the JIT should verify IR modules during compilation.
bool VerifyModules;
friend class EngineBuilder; // To allow access to JITCtor and InterpCtor.
protected:
/// The list of Modules that we are JIT'ing from. We use a SmallVector to
/// optimize for the case where there is only one module.
SmallVector<std::unique_ptr<Module>, 1> Modules;
void setDataLayout(const DataLayout *Val) { DL = Val; }
/// getMemoryforGV - Allocate memory for a global variable.
virtual char *getMemoryForGV(const GlobalVariable *GV);
static ExecutionEngine *(*MCJITCtor)(
std::unique_ptr<Module> M,
std::string *ErrorStr,
std::shared_ptr<MCJITMemoryManager> MM,
std::shared_ptr<RuntimeDyld::SymbolResolver> SR,
std::unique_ptr<TargetMachine> TM);
static ExecutionEngine *(*OrcMCJITReplacementCtor)(
std::string *ErrorStr,
std::shared_ptr<MCJITMemoryManager> MM,
std::shared_ptr<RuntimeDyld::SymbolResolver> SR,
std::unique_ptr<TargetMachine> TM);
static ExecutionEngine *(*InterpCtor)(std::unique_ptr<Module> M,
std::string *ErrorStr);
/// LazyFunctionCreator - If an unknown function is needed, this function
/// pointer is invoked to create it. If this returns null, the JIT will
/// abort.
FunctionCreator LazyFunctionCreator;
/// getMangledName - Get mangled name.
std::string getMangledName(const GlobalValue *GV);
public:
/// lock - This lock protects the ExecutionEngine and MCJIT classes. It must
/// be held while changing the internal state of any of those classes.
sys::Mutex lock;
//===--------------------------------------------------------------------===//
// ExecutionEngine Startup
//===--------------------------------------------------------------------===//
virtual ~ExecutionEngine();
/// Add a Module to the list of modules that we can JIT from.
virtual void addModule(std::unique_ptr<Module> M) {
Modules.push_back(std::move(M));
}
/// addObjectFile - Add an ObjectFile to the execution engine.
///
/// This method is only supported by MCJIT. MCJIT will immediately load the
/// object into memory and adds its symbols to the list used to resolve
/// external symbols while preparing other objects for execution.
///
/// Objects added using this function will not be made executable until
/// needed by another object.
///
/// MCJIT will take ownership of the ObjectFile.
virtual void addObjectFile(std::unique_ptr<object::ObjectFile> O);
virtual void addObjectFile(object::OwningBinary<object::ObjectFile> O);
/// addArchive - Add an Archive to the execution engine.
///
/// This method is only supported by MCJIT. MCJIT will use the archive to
/// resolve external symbols in objects it is loading. If a symbol is found
/// in the Archive the contained object file will be extracted (in memory)
/// and loaded for possible execution.
virtual void addArchive(object::OwningBinary<object::Archive> A);
//===--------------------------------------------------------------------===//
const DataLayout *getDataLayout() const { return DL; }
/// removeModule - Remove a Module from the list of modules. Returns true if
/// M is found.
virtual bool removeModule(Module *M);
/// FindFunctionNamed - Search all of the active modules to find the function that
/// defines FnName. This is very slow operation and shouldn't be used for
/// general code.
virtual Function *FindFunctionNamed(const char *FnName);
/// FindGlobalVariableNamed - Search all of the active modules to find the global variable
/// that defines Name. This is very slow operation and shouldn't be used for
/// general code.
virtual GlobalVariable *FindGlobalVariableNamed(const char *Name, bool AllowInternal = false);
/// runFunction - Execute the specified function with the specified arguments,
/// and return the result.
virtual GenericValue runFunction(Function *F,
ArrayRef<GenericValue> ArgValues) = 0;
/// getPointerToNamedFunction - This method returns the address of the
/// specified function by using the dlsym function call. As such it is only
/// useful for resolving library symbols, not code generated symbols.
///
/// If AbortOnFailure is false and no function with the given name is
/// found, this function silently returns a null pointer. Otherwise,
/// it prints a message to stderr and aborts.
///
/// This function is deprecated for the MCJIT execution engine.
virtual void *getPointerToNamedFunction(StringRef Name,
bool AbortOnFailure = true) = 0;
/// mapSectionAddress - map a section to its target address space value.
/// Map the address of a JIT section as returned from the memory manager
/// to the address in the target process as the running code will see it.
/// This is the address which will be used for relocation resolution.
virtual void mapSectionAddress(const void *LocalAddress,
uint64_t TargetAddress) {
llvm_unreachable("Re-mapping of section addresses not supported with this "
"EE!");
}
/// generateCodeForModule - Run code generation for the specified module and
/// load it into memory.
///
/// When this function has completed, all code and data for the specified
/// module, and any module on which this module depends, will be generated
/// and loaded into memory, but relocations will not yet have been applied
/// and all memory will be readable and writable but not executable.
///
/// This function is primarily useful when generating code for an external
/// target, allowing the client an opportunity to remap section addresses
/// before relocations are applied. Clients that intend to execute code
/// locally can use the getFunctionAddress call, which will generate code
/// and apply final preparations all in one step.
///
/// This method has no effect for the interpeter.
virtual void generateCodeForModule(Module *M) {}
/// finalizeObject - ensure the module is fully processed and is usable.
///
/// It is the user-level function for completing the process of making the
/// object usable for execution. It should be called after sections within an
/// object have been relocated using mapSectionAddress. When this method is
/// called the MCJIT execution engine will reapply relocations for a loaded
/// object. This method has no effect for the interpeter.
virtual void finalizeObject() {}
/// runStaticConstructorsDestructors - This method is used to execute all of
/// the static constructors or destructors for a program.
///
/// \param isDtors - Run the destructors instead of constructors.
virtual void runStaticConstructorsDestructors(bool isDtors);
/// This method is used to execute all of the static constructors or
/// destructors for a particular module.
///
/// \param isDtors - Run the destructors instead of constructors.
void runStaticConstructorsDestructors(Module &mod, bool isDtors);
/// runFunctionAsMain - This is a helper function which wraps runFunction to
/// handle the common task of starting up main with the specified argc, argv,
/// and envp parameters.
int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv,
const char * const * envp);
/// addGlobalMapping - Tell the execution engine that the specified global is
/// at the specified location. This is used internally as functions are JIT'd
/// and as global variables are laid out in memory. It can and should also be
/// used by clients of the EE that want to have an LLVM global overlay
/// existing data in memory. Mappings are automatically removed when their
/// GlobalValue is destroyed.
void addGlobalMapping(const GlobalValue *GV, void *Addr);
void addGlobalMapping(StringRef Name, uint64_t Addr);
/// clearAllGlobalMappings - Clear all global mappings and start over again,
/// for use in dynamic compilation scenarios to move globals.
void clearAllGlobalMappings();
/// clearGlobalMappingsFromModule - Clear all global mappings that came from a
/// particular module, because it has been removed from the JIT.
void clearGlobalMappingsFromModule(Module *M);
/// updateGlobalMapping - Replace an existing mapping for GV with a new
/// address. This updates both maps as required. If "Addr" is null, the
/// entry for the global is removed from the mappings. This returns the old
/// value of the pointer, or null if it was not in the map.
uint64_t updateGlobalMapping(const GlobalValue *GV, void *Addr);
uint64_t updateGlobalMapping(StringRef Name, uint64_t Addr);
/// getAddressToGlobalIfAvailable - This returns the address of the specified
/// global symbol.
uint64_t getAddressToGlobalIfAvailable(StringRef S);
/// getPointerToGlobalIfAvailable - This returns the address of the specified
/// global value if it is has already been codegen'd, otherwise it returns
/// null.
void *getPointerToGlobalIfAvailable(StringRef S);
void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
/// getPointerToGlobal - This returns the address of the specified global
/// value. This may involve code generation if it's a function.
///
/// This function is deprecated for the MCJIT execution engine. Use
/// getGlobalValueAddress instead.
void *getPointerToGlobal(const GlobalValue *GV);
/// getPointerToFunction - The different EE's represent function bodies in
/// different ways. They should each implement this to say what a function
/// pointer should look like. When F is destroyed, the ExecutionEngine will
/// remove its global mapping and free any machine code. Be sure no threads
/// are running inside F when that happens.
///
/// This function is deprecated for the MCJIT execution engine. Use
/// getFunctionAddress instead.
virtual void *getPointerToFunction(Function *F) = 0;
/// getPointerToFunctionOrStub - If the specified function has been
/// code-gen'd, return a pointer to the function. If not, compile it, or use
/// a stub to implement lazy compilation if available. See
/// getPointerToFunction for the requirements on destroying F.
///
/// This function is deprecated for the MCJIT execution engine. Use
/// getFunctionAddress instead.
virtual void *getPointerToFunctionOrStub(Function *F) {
// Default implementation, just codegen the function.
return getPointerToFunction(F);
}
/// getGlobalValueAddress - Return the address of the specified global
/// value. This may involve code generation.
///
/// This function should not be called with the interpreter engine.
virtual uint64_t getGlobalValueAddress(const std::string &Name) {
// Default implementation for the interpreter. MCJIT will override this.
// JIT and interpreter clients should use getPointerToGlobal instead.
return 0;
}
/// getFunctionAddress - Return the address of the specified function.
/// This may involve code generation.
virtual uint64_t getFunctionAddress(const std::string &Name) {
// Default implementation for the interpreter. MCJIT will override this.
// Interpreter clients should use getPointerToFunction instead.
return 0;
}
/// getGlobalValueAtAddress - Return the LLVM global value object that starts
/// at the specified address.
///
const GlobalValue *getGlobalValueAtAddress(void *Addr);
/// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
/// Ptr is the address of the memory at which to store Val, cast to
/// GenericValue *. It is not a pointer to a GenericValue containing the
/// address at which to store Val.
void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
Type *Ty);
void InitializeMemory(const Constant *Init, void *Addr);
/// getOrEmitGlobalVariable - Return the address of the specified global
/// variable, possibly emitting it to memory if needed. This is used by the
/// Emitter.
///
/// This function is deprecated for the MCJIT execution engine. Use
/// getGlobalValueAddress instead.
virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
return getPointerToGlobal((const GlobalValue *)GV);
}
/// Registers a listener to be called back on various events within
/// the JIT. See JITEventListener.h for more details. Does not
/// take ownership of the argument. The argument may be NULL, in
/// which case these functions do nothing.
virtual void RegisterJITEventListener(JITEventListener *) {}
virtual void UnregisterJITEventListener(JITEventListener *) {}
/// Sets the pre-compiled object cache. The ownership of the ObjectCache is
/// not changed. Supported by MCJIT but not the interpreter.
virtual void setObjectCache(ObjectCache *) {
llvm_unreachable("No support for an object cache");
}
/// setProcessAllSections (MCJIT Only): By default, only sections that are
/// "required for execution" are passed to the RTDyldMemoryManager, and other
/// sections are discarded. Passing 'true' to this method will cause
/// RuntimeDyld to pass all sections to its RTDyldMemoryManager regardless
/// of whether they are "required to execute" in the usual sense.
///
/// Rationale: Some MCJIT clients want to be able to inspect metadata
/// sections (e.g. Dwarf, Stack-maps) to enable functionality or analyze
/// performance. Passing these sections to the memory manager allows the
/// client to make policy about the relevant sections, rather than having
/// MCJIT do it.
virtual void setProcessAllSections(bool ProcessAllSections) {
llvm_unreachable("No support for ProcessAllSections option");
}
/// Return the target machine (if available).
virtual TargetMachine *getTargetMachine() { return nullptr; }
/// DisableLazyCompilation - When lazy compilation is off (the default), the
/// JIT will eagerly compile every function reachable from the argument to
/// getPointerToFunction. If lazy compilation is turned on, the JIT will only
/// compile the one function and emit stubs to compile the rest when they're
/// first called. If lazy compilation is turned off again while some lazy
/// stubs are still around, and one of those stubs is called, the program will
/// abort.
///
/// In order to safely compile lazily in a threaded program, the user must
/// ensure that 1) only one thread at a time can call any particular lazy
/// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock
/// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a
/// lazy stub. See http://llvm.org/PR5184 for details.
void DisableLazyCompilation(bool Disabled = true) {
CompilingLazily = !Disabled;
}
bool isCompilingLazily() const {
return CompilingLazily;
}
/// DisableGVCompilation - If called, the JIT will abort if it's asked to
/// allocate space and populate a GlobalVariable that is not internal to
/// the module.
void DisableGVCompilation(bool Disabled = true) {
GVCompilationDisabled = Disabled;
}
bool isGVCompilationDisabled() const {
return GVCompilationDisabled;
}
/// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
/// symbols with dlsym. A client can still use InstallLazyFunctionCreator to
/// resolve symbols in a custom way.
void DisableSymbolSearching(bool Disabled = true) {
SymbolSearchingDisabled = Disabled;
}
bool isSymbolSearchingDisabled() const {
return SymbolSearchingDisabled;
}
/// Enable/Disable IR module verification.
///
/// Note: Module verification is enabled by default in Debug builds, and
/// disabled by default in Release. Use this method to override the default.
void setVerifyModules(bool Verify) {
VerifyModules = Verify;
}
bool getVerifyModules() const {
return VerifyModules;
}
/// InstallLazyFunctionCreator - If an unknown function is needed, the
/// specified function pointer is invoked to create it. If it returns null,
/// the JIT will abort.
void InstallLazyFunctionCreator(FunctionCreator C) {
LazyFunctionCreator = C;
}
protected:
ExecutionEngine() {}
explicit ExecutionEngine(std::unique_ptr<Module> M);
void emitGlobals();
void EmitGlobalVariable(const GlobalVariable *GV);
GenericValue getConstantValue(const Constant *C);
void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
Type *Ty);
};
namespace EngineKind {
// These are actually bitmasks that get or-ed together.
enum Kind {
JIT = 0x1,
Interpreter = 0x2
};
const static Kind Either = (Kind)(JIT | Interpreter);
}
/// Builder class for ExecutionEngines. Use this by stack-allocating a builder,
/// chaining the various set* methods, and terminating it with a .create()
/// call.
class EngineBuilder {
private:
std::unique_ptr<Module> M;
EngineKind::Kind WhichEngine;
std::string *ErrorStr;
CodeGenOpt::Level OptLevel;
std::shared_ptr<MCJITMemoryManager> MemMgr;
std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver;
TargetOptions Options;
Reloc::Model RelocModel;
CodeModel::Model CMModel;
std::string MArch;
std::string MCPU;
SmallVector<std::string, 4> MAttrs;
bool VerifyModules;
bool UseOrcMCJITReplacement;
public:
/// Default constructor for EngineBuilder.
EngineBuilder();
/// Constructor for EngineBuilder.
EngineBuilder(std::unique_ptr<Module> M);
// Out-of-line since we don't have the def'n of RTDyldMemoryManager here.
~EngineBuilder();
/// setEngineKind - Controls whether the user wants the interpreter, the JIT,
/// or whichever engine works. This option defaults to EngineKind::Either.
EngineBuilder &setEngineKind(EngineKind::Kind w) {
WhichEngine = w;
return *this;
}
/// setMCJITMemoryManager - Sets the MCJIT memory manager to use. This allows
/// clients to customize their memory allocation policies for the MCJIT. This
/// is only appropriate for the MCJIT; setting this and configuring the builder
/// to create anything other than MCJIT will cause a runtime error. If create()
/// is called and is successful, the created engine takes ownership of the
/// memory manager. This option defaults to NULL.
EngineBuilder &setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
/// setErrorStr - Set the error string to write to on error. This option
/// defaults to NULL.
EngineBuilder &setErrorStr(std::string *e) {
ErrorStr = e;
return *this;
}
/// setOptLevel - Set the optimization level for the JIT. This option
/// defaults to CodeGenOpt::Default.
EngineBuilder &setOptLevel(CodeGenOpt::Level l) {
OptLevel = l;
return *this;
}
/// setTargetOptions - Set the target options that the ExecutionEngine
/// target is using. Defaults to TargetOptions().
EngineBuilder &setTargetOptions(const TargetOptions &Opts) {
Options = Opts;
return *this;
}
/// setRelocationModel - Set the relocation model that the ExecutionEngine
/// target is using. Defaults to target specific default "Reloc::Default".
EngineBuilder &setRelocationModel(Reloc::Model RM) {
RelocModel = RM;
return *this;
}
/// setCodeModel - Set the CodeModel that the ExecutionEngine target
/// data is using. Defaults to target specific default
/// "CodeModel::JITDefault".
EngineBuilder &setCodeModel(CodeModel::Model M) {
CMModel = M;
return *this;
}
/// setMArch - Override the architecture set by the Module's triple.
EngineBuilder &setMArch(StringRef march) {
MArch.assign(march.begin(), march.end());
return *this;
}
/// setMCPU - Target a specific cpu type.
EngineBuilder &setMCPU(StringRef mcpu) {
MCPU.assign(mcpu.begin(), mcpu.end());
return *this;
}
/// setVerifyModules - Set whether the JIT implementation should verify
/// IR modules during compilation.
EngineBuilder &setVerifyModules(bool Verify) {
VerifyModules = Verify;
return *this;
}
/// setMAttrs - Set cpu-specific attributes.
template<typename StringSequence>
EngineBuilder &setMAttrs(const StringSequence &mattrs) {
MAttrs.clear();
MAttrs.append(mattrs.begin(), mattrs.end());
return *this;
}
// \brief Use OrcMCJITReplacement instead of MCJIT. Off by default.
void setUseOrcMCJITReplacement(bool UseOrcMCJITReplacement) {
this->UseOrcMCJITReplacement = UseOrcMCJITReplacement;
}
TargetMachine *selectTarget();
/// selectTarget - Pick a target either via -march or by guessing the native
/// arch. Add any CPU features specified via -mcpu or -mattr.
TargetMachine *selectTarget(const Triple &TargetTriple,
StringRef MArch,
StringRef MCPU,
const SmallVectorImpl<std::string>& MAttrs);
ExecutionEngine *create() {
return create(selectTarget());
}
ExecutionEngine *create(TargetMachine *TM);
};
// Create wrappers for C Binding types (see CBindingWrapping.h).
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
} // End llvm namespace
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/SectionMemoryManager.h | //===- SectionMemoryManager.h - Memory manager for MCJIT/RtDyld -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the declaration of a section-based memory manager used by
// the MCJIT execution engine and RuntimeDyld.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_SECTIONMEMORYMANAGER_H
#define LLVM_EXECUTIONENGINE_SECTIONMEMORYMANAGER_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Memory.h"
namespace llvm {
/// This is a simple memory manager which implements the methods called by
/// the RuntimeDyld class to allocate memory for section-based loading of
/// objects, usually those generated by the MCJIT execution engine.
///
/// This memory manager allocates all section memory as read-write. The
/// RuntimeDyld will copy JITed section memory into these allocated blocks
/// and perform any necessary linking and relocations.
///
/// Any client using this memory manager MUST ensure that section-specific
/// page permissions have been applied before attempting to execute functions
/// in the JITed object. Permissions can be applied either by calling
/// MCJIT::finalizeObject or by calling SectionMemoryManager::finalizeMemory
/// directly. Clients of MCJIT should call MCJIT::finalizeObject.
class SectionMemoryManager : public RTDyldMemoryManager {
SectionMemoryManager(const SectionMemoryManager&) = delete;
void operator=(const SectionMemoryManager&) = delete;
public:
SectionMemoryManager() { }
~SectionMemoryManager() override;
/// \brief Allocates a memory block of (at least) the given size suitable for
/// executable code.
///
/// The value of \p Alignment must be a power of two. If \p Alignment is zero
/// a default alignment of 16 will be used.
uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName) override;
/// \brief Allocates a memory block of (at least) the given size suitable for
/// executable code.
///
/// The value of \p Alignment must be a power of two. If \p Alignment is zero
/// a default alignment of 16 will be used.
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID, StringRef SectionName,
bool isReadOnly) override;
/// \brief Update section-specific memory permissions and other attributes.
///
/// This method is called when object loading is complete and section page
/// permissions can be applied. It is up to the memory manager implementation
/// to decide whether or not to act on this method. The memory manager will
/// typically allocate all sections as read-write and then apply specific
/// permissions when this method is called. Code sections cannot be executed
/// until this function has been called. In addition, any cache coherency
/// operations needed to reliably use the memory are also performed.
///
/// \returns true if an error occurred, false otherwise.
bool finalizeMemory(std::string *ErrMsg = nullptr) override;
/// \brief Invalidate instruction cache for code sections.
///
/// Some platforms with separate data cache and instruction cache require
/// explicit cache flush, otherwise JIT code manipulations (like resolved
/// relocations) will get to the data cache but not to the instruction cache.
///
/// This method is called from finalizeMemory.
virtual void invalidateInstructionCache();
private:
struct MemoryGroup {
SmallVector<sys::MemoryBlock, 16> AllocatedMem;
SmallVector<sys::MemoryBlock, 16> FreeMem;
sys::MemoryBlock Near;
};
uint8_t *allocateSection(MemoryGroup &MemGroup, uintptr_t Size,
unsigned Alignment);
std::error_code applyMemoryGroupPermissions(MemoryGroup &MemGroup,
unsigned Permissions);
MemoryGroup CodeMem;
MemoryGroup RWDataMem;
MemoryGroup RODataMem;
};
}
#endif // LLVM_EXECUTION_ENGINE_SECTION_MEMORY_MANAGER_H
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/RTDyldMemoryManager.h | //===-- RTDyldMemoryManager.cpp - Memory manager for MC-JIT -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Interface of the runtime dynamic memory manager base class.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H
#define LLVM_EXECUTIONENGINE_RTDYLDMEMORYMANAGER_H
#include "RuntimeDyld.h"
#include "llvm-c/ExecutionEngine.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/Memory.h"
namespace llvm {
class ExecutionEngine;
namespace object {
class ObjectFile;
}
class MCJITMemoryManager : public RuntimeDyld::MemoryManager {
public:
/// This method is called after an object has been loaded into memory but
/// before relocations are applied to the loaded sections. The object load
/// may have been initiated by MCJIT to resolve an external symbol for another
/// object that is being finalized. In that case, the object about which
/// the memory manager is being notified will be finalized immediately after
/// the memory manager returns from this call.
///
/// Memory managers which are preparing code for execution in an external
/// address space can use this call to remap the section addresses for the
/// newly loaded object.
virtual void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
};
// RuntimeDyld clients often want to handle the memory management of
// what gets placed where. For JIT clients, this is the subset of
// JITMemoryManager required for dynamic loading of binaries.
//
// FIXME: As the RuntimeDyld fills out, additional routines will be needed
// for the varying types of objects to be allocated.
class RTDyldMemoryManager : public MCJITMemoryManager,
public RuntimeDyld::SymbolResolver {
RTDyldMemoryManager(const RTDyldMemoryManager&) = delete;
void operator=(const RTDyldMemoryManager&) = delete;
public:
RTDyldMemoryManager() {}
~RTDyldMemoryManager() override;
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override;
void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override;
/// This method returns the address of the specified function or variable in
/// the current process.
static uint64_t getSymbolAddressInProcess(const std::string &Name);
/// Legacy symbol lookup - DEPRECATED! Please override findSymbol instead.
///
/// This method returns the address of the specified function or variable.
/// It is used to resolve symbols during module linking.
virtual uint64_t getSymbolAddress(const std::string &Name) {
return getSymbolAddressInProcess(Name);
}
/// This method returns a RuntimeDyld::SymbolInfo for the specified function
/// or variable. It is used to resolve symbols during module linking.
///
/// By default this falls back on the legacy lookup method:
/// 'getSymbolAddress'. The address returned by getSymbolAddress is treated as
/// a strong, exported symbol, consistent with historical treatment by
/// RuntimeDyld.
///
/// Clients writing custom RTDyldMemoryManagers are encouraged to override
/// this method and return a SymbolInfo with the flags set correctly. This is
/// necessary for RuntimeDyld to correctly handle weak and non-exported symbols.
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override {
return RuntimeDyld::SymbolInfo(getSymbolAddress(Name),
JITSymbolFlags::Exported);
}
/// Legacy symbol lookup -- DEPRECATED! Please override
/// findSymbolInLogicalDylib instead.
///
/// Default to treating all modules as separate.
virtual uint64_t getSymbolAddressInLogicalDylib(const std::string &Name) {
return 0;
}
/// Default to treating all modules as separate.
///
/// By default this falls back on the legacy lookup method:
/// 'getSymbolAddressInLogicalDylib'. The address returned by
/// getSymbolAddressInLogicalDylib is treated as a strong, exported symbol,
/// consistent with historical treatment by RuntimeDyld.
///
/// Clients writing custom RTDyldMemoryManagers are encouraged to override
/// this method and return a SymbolInfo with the flags set correctly. This is
/// necessary for RuntimeDyld to correctly handle weak and non-exported symbols.
RuntimeDyld::SymbolInfo
findSymbolInLogicalDylib(const std::string &Name) override {
return RuntimeDyld::SymbolInfo(getSymbolAddressInLogicalDylib(Name),
JITSymbolFlags::Exported);
}
/// This method returns the address of the specified function. As such it is
/// only useful for resolving library symbols, not code generated symbols.
///
/// If \p AbortOnFailure is false and no function with the given name is
/// found, this function returns a null pointer. Otherwise, it prints a
/// message to stderr and aborts.
///
/// This function is deprecated for memory managers to be used with
/// MCJIT or RuntimeDyld. Use getSymbolAddress instead.
virtual void *getPointerToNamedFunction(const std::string &Name,
bool AbortOnFailure = true);
};
// Create wrappers for C Binding types (see CBindingWrapping.h).
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(
RTDyldMemoryManager, LLVMMCJITMemoryManagerRef)
} // namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/RuntimeDyld.h | //===-- RuntimeDyld.h - Run-time dynamic linker for MC-JIT ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Interface for the runtime dynamic linker facilities of the MC-JIT.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
#define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
#include "JITSymbolFlags.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Memory.h"
#include "llvm/DebugInfo/DIContext.h"
#include <memory>
namespace llvm {
namespace object {
class ObjectFile;
template <typename T> class OwningBinary;
}
class RuntimeDyldImpl;
class RuntimeDyldCheckerImpl;
class RuntimeDyld {
friend class RuntimeDyldCheckerImpl;
RuntimeDyld(const RuntimeDyld &) = delete;
void operator=(const RuntimeDyld &) = delete;
protected:
// Change the address associated with a section when resolving relocations.
// Any relocations already associated with the symbol will be re-resolved.
void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
public:
/// \brief Information about a named symbol.
class SymbolInfo : public JITSymbolBase {
public:
SymbolInfo(std::nullptr_t) : JITSymbolBase(JITSymbolFlags::None), Address(0) {}
SymbolInfo(uint64_t Address, JITSymbolFlags Flags)
: JITSymbolBase(Flags), Address(Address) {}
explicit operator bool() const { return Address != 0; }
uint64_t getAddress() const { return Address; }
private:
uint64_t Address;
};
/// \brief Information about the loaded object.
class LoadedObjectInfo : public llvm::LoadedObjectInfo {
friend class RuntimeDyldImpl;
public:
LoadedObjectInfo(RuntimeDyldImpl &RTDyld, unsigned BeginIdx,
unsigned EndIdx)
: RTDyld(RTDyld), BeginIdx(BeginIdx), EndIdx(EndIdx) { }
virtual object::OwningBinary<object::ObjectFile>
getObjectForDebug(const object::ObjectFile &Obj) const = 0;
uint64_t getSectionLoadAddress(StringRef Name) const;
protected:
virtual void anchor();
RuntimeDyldImpl &RTDyld;
unsigned BeginIdx, EndIdx;
};
template <typename Derived> struct LoadedObjectInfoHelper : LoadedObjectInfo {
LoadedObjectInfoHelper(RuntimeDyldImpl &RTDyld, unsigned BeginIdx,
unsigned EndIdx)
: LoadedObjectInfo(RTDyld, BeginIdx, EndIdx) {}
std::unique_ptr<llvm::LoadedObjectInfo> clone() const override {
return llvm::make_unique<Derived>(static_cast<const Derived &>(*this));
}
};
/// \brief Memory Management.
class MemoryManager {
public:
virtual ~MemoryManager() {};
/// Allocate a memory block of (at least) the given size suitable for
/// executable code. The SectionID is a unique identifier assigned by the
/// RuntimeDyld instance, and optionally recorded by the memory manager to
/// access a loaded section.
virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName) = 0;
/// Allocate a memory block of (at least) the given size suitable for data.
/// The SectionID is a unique identifier assigned by the JIT engine, and
/// optionally recorded by the memory manager to access a loaded section.
virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName,
bool IsReadOnly) = 0;
/// Inform the memory manager about the total amount of memory required to
/// allocate all sections to be loaded:
/// \p CodeSize - the total size of all code sections
/// \p DataSizeRO - the total size of all read-only data sections
/// \p DataSizeRW - the total size of all read-write data sections
///
/// Note that by default the callback is disabled. To enable it
/// redefine the method needsToReserveAllocationSpace to return true.
virtual void reserveAllocationSpace(uintptr_t CodeSize,
uintptr_t DataSizeRO,
uintptr_t DataSizeRW) {}
/// Override to return true to enable the reserveAllocationSpace callback.
virtual bool needsToReserveAllocationSpace() { return false; }
/// Register the EH frames with the runtime so that c++ exceptions work.
///
/// \p Addr parameter provides the local address of the EH frame section
/// data, while \p LoadAddr provides the address of the data in the target
/// address space. If the section has not been remapped (which will usually
/// be the case for local execution) these two values will be the same.
virtual void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
size_t Size) = 0;
virtual void deregisterEHFrames(uint8_t *addr, uint64_t LoadAddr,
size_t Size) = 0;
/// This method is called when object loading is complete and section page
/// permissions can be applied. It is up to the memory manager implementation
/// to decide whether or not to act on this method. The memory manager will
/// typically allocate all sections as read-write and then apply specific
/// permissions when this method is called. Code sections cannot be executed
/// until this function has been called. In addition, any cache coherency
/// operations needed to reliably use the memory are also performed.
///
/// Returns true if an error occurred, false otherwise.
virtual bool finalizeMemory(std::string *ErrMsg = nullptr) = 0;
private:
virtual void anchor();
};
/// \brief Symbol resolution.
class SymbolResolver {
public:
virtual ~SymbolResolver() {};
/// This method returns the address of the specified function or variable.
/// It is used to resolve symbols during module linking.
///
/// If the returned symbol's address is equal to ~0ULL then RuntimeDyld will
/// skip all relocations for that symbol, and the client will be responsible
/// for handling them manually.
virtual SymbolInfo findSymbol(const std::string &Name) = 0;
/// This method returns the address of the specified symbol if it exists
/// within the logical dynamic library represented by this
/// RTDyldMemoryManager. Unlike getSymbolAddress, queries through this
/// interface should return addresses for hidden symbols.
///
/// This is of particular importance for the Orc JIT APIs, which support lazy
/// compilation by breaking up modules: Each of those broken out modules
/// must be able to resolve hidden symbols provided by the others. Clients
/// writing memory managers for MCJIT can usually ignore this method.
///
/// This method will be queried by RuntimeDyld when checking for previous
/// definitions of common symbols. It will *not* be queried by default when
/// resolving external symbols (this minimises the link-time overhead for
/// MCJIT clients who don't care about Orc features). If you are writing a
/// RTDyldMemoryManager for Orc and want "external" symbol resolution to
/// search the logical dylib, you should override your getSymbolAddress
/// method call this method directly.
virtual SymbolInfo findSymbolInLogicalDylib(const std::string &Name) = 0;
private:
virtual void anchor();
};
/// \brief Construct a RuntimeDyld instance.
RuntimeDyld(MemoryManager &MemMgr, SymbolResolver &Resolver);
~RuntimeDyld();
/// Add the referenced object file to the list of objects to be loaded and
/// relocated.
std::unique_ptr<LoadedObjectInfo> loadObject(const object::ObjectFile &O);
/// Get the address of our local copy of the symbol. This may or may not
/// be the address used for relocation (clients can copy the data around
/// and resolve relocatons based on where they put it).
void *getSymbolLocalAddress(StringRef Name) const;
/// Get the target address and flags for the named symbol.
/// This address is the one used for relocation.
SymbolInfo getSymbol(StringRef Name) const;
/// Resolve the relocations for all symbols we currently know about.
void resolveRelocations();
/// Map a section to its target address space value.
/// Map the address of a JIT section as returned from the memory manager
/// to the address in the target process as the running code will see it.
/// This is the address which will be used for relocation resolution.
void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
/// Register any EH frame sections that have been loaded but not previously
/// registered with the memory manager. Note, RuntimeDyld is responsible
/// for identifying the EH frame and calling the memory manager with the
/// EH frame section data. However, the memory manager itself will handle
/// the actual target-specific EH frame registration.
void registerEHFrames();
void deregisterEHFrames();
bool hasError();
StringRef getErrorString();
/// By default, only sections that are "required for execution" are passed to
/// the RTDyldMemoryManager, and other sections are discarded. Passing 'true'
/// to this method will cause RuntimeDyld to pass all sections to its
/// memory manager regardless of whether they are "required to execute" in the
/// usual sense. This is useful for inspecting metadata sections that may not
/// contain relocations, E.g. Debug info, stackmaps.
///
/// Must be called before the first object file is loaded.
void setProcessAllSections(bool ProcessAllSections) {
assert(!Dyld && "setProcessAllSections must be called before loadObject.");
this->ProcessAllSections = ProcessAllSections;
}
private:
// RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
// interface.
std::unique_ptr<RuntimeDyldImpl> Dyld;
MemoryManager &MemMgr;
SymbolResolver &Resolver;
bool ProcessAllSections;
RuntimeDyldCheckerImpl *Checker;
};
} // end namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/MCJIT.h | //===-- MCJIT.h - MC-Based Just-In-Time Execution Engine --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file forces the MCJIT to link in on certain operating systems.
// (Windows).
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_MCJIT_H
#define LLVM_EXECUTIONENGINE_MCJIT_H
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include <cstdlib>
extern "C" void LLVMLinkInMCJIT();
namespace {
struct ForceMCJITLinking {
ForceMCJITLinking() {
// We must reference MCJIT in such a way that compilers will not
// delete it all as dead code, even with whole program optimization,
// yet is effectively a NO-OP. As the compiler isn't smart enough
// to know that getenv() never returns -1, this will do the job.
if (std::getenv("bar") != (char*) -1)
return;
LLVMLinkInMCJIT();
}
} ForceMCJITLinking;
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/ObjectMemoryBuffer.h | //===- ObjectMemoryBuffer.h - SmallVector-backed MemoryBuffrer -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file declares a wrapper class to hold the memory into which an
// object will be generated.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_OBJECTMEMORYBUFFER_H
#define LLVM_EXECUTIONENGINE_OBJECTMEMORYBUFFER_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
/// \brief SmallVector-backed MemoryBuffer instance.
///
/// This class enables efficient construction of MemoryBuffers from SmallVector
/// instances. This is useful for MCJIT and Orc, where object files are streamed
/// into SmallVectors, then inspected using ObjectFile (which takes a
/// MemoryBuffer).
class ObjectMemoryBuffer : public MemoryBuffer {
public:
/// \brief Construct an ObjectMemoryBuffer from the given SmallVector r-value.
///
/// FIXME: It'd be nice for this to be a non-templated constructor taking a
/// SmallVectorImpl here instead of a templated one taking a SmallVector<N>,
/// but SmallVector's move-construction/assignment currently only take
/// SmallVectors. If/when that is fixed we can simplify this constructor and
/// the following one.
ObjectMemoryBuffer(SmallVectorImpl<char> &&SV)
: SV(std::move(SV)), BufferName("<in-memory object>") {
init(this->SV.begin(), this->SV.end(), false);
}
/// \brief Construct a named ObjectMemoryBuffer from the given SmallVector
/// r-value and StringRef.
ObjectMemoryBuffer(SmallVectorImpl<char> &&SV, StringRef Name)
: SV(std::move(SV)), BufferName(Name) {
init(this->SV.begin(), this->SV.end(), false);
}
const char* getBufferIdentifier() const override { return BufferName.c_str(); }
BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; }
private:
SmallVector<char, 0> SV;
std::string BufferName;
};
} // namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/Interpreter.h | //===-- Interpreter.h - Abstract Execution Engine Interface -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file forces the interpreter to link in on certain operating systems.
// (Windows).
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_INTERPRETER_H
#define LLVM_EXECUTIONENGINE_INTERPRETER_H
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include <cstdlib>
extern "C" void LLVMLinkInInterpreter();
namespace {
struct ForceInterpreterLinking {
ForceInterpreterLinking() {
// We must reference the interpreter in such a way that compilers will not
// delete it all as dead code, even with whole program optimization,
// yet is effectively a NO-OP. As the compiler isn't smart enough
// to know that getenv() never returns -1, this will do the job.
if (std::getenv("bar") != (char*) -1)
return;
LLVMLinkInInterpreter();
}
} ForceInterpreterLinking;
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/JITSymbolFlags.h | //===------ JITSymbolFlags.h - Flags for symbols in the JIT -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Symbol flags for symbols in the JIT (e.g. weak, exported).
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_JITSYMBOLFLAGS_H
#define LLVM_EXECUTIONENGINE_JITSYMBOLFLAGS_H
#include "llvm/IR/GlobalValue.h"
namespace llvm {
/// @brief Flags for symbols in the JIT.
enum class JITSymbolFlags : char {
None = 0,
Weak = 1U << 0,
Exported = 1U << 1
};
inline JITSymbolFlags operator|(JITSymbolFlags LHS, JITSymbolFlags RHS) {
typedef std::underlying_type<JITSymbolFlags>::type UT;
return static_cast<JITSymbolFlags>(
static_cast<UT>(LHS) | static_cast<UT>(RHS));
}
inline JITSymbolFlags& operator |=(JITSymbolFlags &LHS, JITSymbolFlags RHS) {
LHS = LHS | RHS;
return LHS;
}
inline JITSymbolFlags operator&(JITSymbolFlags LHS, JITSymbolFlags RHS) {
typedef std::underlying_type<JITSymbolFlags>::type UT;
return static_cast<JITSymbolFlags>(
static_cast<UT>(LHS) & static_cast<UT>(RHS));
}
inline JITSymbolFlags& operator &=(JITSymbolFlags &LHS, JITSymbolFlags RHS) {
LHS = LHS & RHS;
return LHS;
}
/// @brief Base class for symbols in the JIT.
class JITSymbolBase {
public:
JITSymbolBase(JITSymbolFlags Flags) : Flags(Flags) {}
JITSymbolFlags getFlags() const { return Flags; }
bool isWeak() const {
return (Flags & JITSymbolFlags::Weak) == JITSymbolFlags::Weak;
}
bool isExported() const {
return (Flags & JITSymbolFlags::Exported) == JITSymbolFlags::Exported;
}
static JITSymbolFlags flagsFromGlobalValue(const GlobalValue &GV) {
JITSymbolFlags Flags = JITSymbolFlags::None;
if (GV.hasWeakLinkage())
Flags |= JITSymbolFlags::Weak;
if (!GV.hasLocalLinkage() && !GV.hasHiddenVisibility())
Flags |= JITSymbolFlags::Exported;
return Flags;
}
private:
JITSymbolFlags Flags;
};
} // end namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/RuntimeDyldChecker.h | //===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- C++ -*-=//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
#define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
#include "llvm/ADT/StringRef.h"
namespace llvm {
class MCDisassembler;
class MemoryBuffer;
class MCInstPrinter;
class RuntimeDyld;
class RuntimeDyldCheckerImpl;
class raw_ostream;
/// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has
/// correctly applied relocations.
///
/// The RuntimeDyldChecker class evaluates expressions against an attached
/// RuntimeDyld instance to verify that relocations have been applied
/// correctly.
///
/// The expression language supports basic pointer arithmetic and bit-masking,
/// and has limited disassembler integration for accessing instruction
/// operands and the next PC (program counter) address for each instruction.
///
/// The language syntax is:
///
/// check = expr '=' expr
///
/// expr = binary_expr
/// | sliceable_expr
///
/// sliceable_expr = '*{' number '}' load_addr_expr [slice]
/// | '(' expr ')' [slice]
/// | ident_expr [slice]
/// | number [slice]
///
/// slice = '[' high-bit-index ':' low-bit-index ']'
///
/// load_addr_expr = symbol
/// | '(' symbol '+' number ')'
/// | '(' symbol '-' number ')'
///
/// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
/// | 'next_pc' '(' symbol ')'
/// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')'
/// | symbol
///
/// binary_expr = expr '+' expr
/// | expr '-' expr
/// | expr '&' expr
/// | expr '|' expr
/// | expr '<<' expr
/// | expr '>>' expr
///
class RuntimeDyldChecker {
public:
RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
MCInstPrinter *InstPrinter, raw_ostream &ErrStream);
~RuntimeDyldChecker();
// \brief Get the associated RTDyld instance.
RuntimeDyld& getRTDyld();
// \brief Get the associated RTDyld instance.
const RuntimeDyld& getRTDyld() const;
/// \brief Check a single expression against the attached RuntimeDyld
/// instance.
bool check(StringRef CheckExpr) const;
/// \brief Scan the given memory buffer for lines beginning with the string
/// in RulePrefix. The remainder of the line is passed to the check
/// method to be evaluated as an expression.
bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
/// \brief Returns the address of the requested section (or an error message
/// in the second element of the pair if the address cannot be found).
///
/// if 'LocalAddress' is true, this returns the address of the section
/// within the linker's memory. If 'LocalAddress' is false it returns the
/// address within the target process (i.e. the load address).
std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
StringRef SectionName,
bool LocalAddress);
private:
std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
};
} // end namespace llvm
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/OrcMCJITReplacement.h | //===---- OrcMCJITReplacement.h - Orc-based MCJIT replacement ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file forces OrcMCJITReplacement to link in on certain operating systems.
// (Windows).
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_ORCMCJITREPLACEMENT_H
#define LLVM_EXECUTIONENGINE_ORCMCJITREPLACEMENT_H
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include <cstdlib>
extern "C" void LLVMLinkInOrcMCJITReplacement();
namespace {
struct ForceOrcMCJITReplacementLinking {
ForceOrcMCJITReplacementLinking() {
// We must reference OrcMCJITReplacement in such a way that compilers will
// not delete it all as dead code, even with whole program optimization,
// yet is effectively a NO-OP. As the compiler isn't smart enough to know
// that getenv() never returns -1, this will do the job.
if (std::getenv("bar") != (char*) -1)
return;
LLVMLinkInOrcMCJITReplacement();
}
} ForceOrcMCJITReplacementLinking;
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/OProfileWrapper.h | //===-- OProfileWrapper.h - OProfile JIT API Wrapper ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// This file defines a OProfileWrapper object that detects if the oprofile
// daemon is running, and provides wrappers for opagent functions used to
// communicate with the oprofile JIT interface. The dynamic library libopagent
// does not need to be linked directly as this object lazily loads the library
// when the first op_ function is called.
//
// See http://oprofile.sourceforge.net/doc/devel/jit-interface.html for the
// definition of the interface.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_OPROFILEWRAPPER_H
#define LLVM_EXECUTIONENGINE_OPROFILEWRAPPER_H
#include "llvm/Support/DataTypes.h"
#include <opagent.h>
namespace llvm {
class OProfileWrapper {
typedef op_agent_t (*op_open_agent_ptr_t)();
typedef int (*op_close_agent_ptr_t)(op_agent_t);
typedef int (*op_write_native_code_ptr_t)(op_agent_t,
const char*,
uint64_t,
void const*,
const unsigned int);
typedef int (*op_write_debug_line_info_ptr_t)(op_agent_t,
void const*,
size_t,
struct debug_line_info const*);
typedef int (*op_unload_native_code_ptr_t)(op_agent_t, uint64_t);
// Also used for op_minor_version function which has the same signature
typedef int (*op_major_version_ptr_t)();
// This is not a part of the opagent API, but is useful nonetheless
typedef bool (*IsOProfileRunningPtrT)();
op_agent_t Agent;
op_open_agent_ptr_t OpenAgentFunc;
op_close_agent_ptr_t CloseAgentFunc;
op_write_native_code_ptr_t WriteNativeCodeFunc;
op_write_debug_line_info_ptr_t WriteDebugLineInfoFunc;
op_unload_native_code_ptr_t UnloadNativeCodeFunc;
op_major_version_ptr_t MajorVersionFunc;
op_major_version_ptr_t MinorVersionFunc;
IsOProfileRunningPtrT IsOProfileRunningFunc;
bool Initialized;
public:
OProfileWrapper();
// For testing with a mock opagent implementation, skips the dynamic load and
// the function resolution.
OProfileWrapper(op_open_agent_ptr_t OpenAgentImpl,
op_close_agent_ptr_t CloseAgentImpl,
op_write_native_code_ptr_t WriteNativeCodeImpl,
op_write_debug_line_info_ptr_t WriteDebugLineInfoImpl,
op_unload_native_code_ptr_t UnloadNativeCodeImpl,
op_major_version_ptr_t MajorVersionImpl,
op_major_version_ptr_t MinorVersionImpl,
IsOProfileRunningPtrT MockIsOProfileRunningImpl = 0)
: OpenAgentFunc(OpenAgentImpl),
CloseAgentFunc(CloseAgentImpl),
WriteNativeCodeFunc(WriteNativeCodeImpl),
WriteDebugLineInfoFunc(WriteDebugLineInfoImpl),
UnloadNativeCodeFunc(UnloadNativeCodeImpl),
MajorVersionFunc(MajorVersionImpl),
MinorVersionFunc(MinorVersionImpl),
IsOProfileRunningFunc(MockIsOProfileRunningImpl),
Initialized(true)
{
}
// Calls op_open_agent in the oprofile JIT library and saves the returned
// op_agent_t handle internally so it can be used when calling all the other
// op_* functions. Callers of this class do not need to keep track of
// op_agent_t objects.
bool op_open_agent();
int op_close_agent();
int op_write_native_code(const char* name,
uint64_t addr,
void const* code,
const unsigned int size);
int op_write_debug_line_info(void const* code,
size_t num_entries,
struct debug_line_info const* info);
int op_unload_native_code(uint64_t addr);
int op_major_version();
int op_minor_version();
// Returns true if the oprofiled process is running, the opagent library is
// loaded and a connection to the agent has been established, and false
// otherwise.
bool isAgentAvailable();
private:
// Loads the libopagent library and initializes this wrapper if the oprofile
// daemon is running
bool initialize();
// Searches /proc for the oprofile daemon and returns true if the process if
// found, or false otherwise.
bool checkForOProfileProcEntry();
bool isOProfileRunning();
};
} // namespace llvm
#endif // LLVM_EXECUTIONENGINE_OPROFILEWRAPPER_H
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/ObjectCache.h | //===-- ObjectCache.h - Class definition for the ObjectCache -----C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_OBJECTCACHE_H
#define LLVM_EXECUTIONENGINE_OBJECTCACHE_H
#include "llvm/Support/MemoryBuffer.h"
namespace llvm {
class Module;
/// This is the base ObjectCache type which can be provided to an
/// ExecutionEngine for the purpose of avoiding compilation for Modules that
/// have already been compiled and an object file is available.
class ObjectCache {
virtual void anchor();
public:
ObjectCache() { }
virtual ~ObjectCache() { }
/// notifyObjectCompiled - Provides a pointer to compiled code for Module M.
virtual void notifyObjectCompiled(const Module *M, MemoryBufferRef Obj) = 0;
/// Returns a pointer to a newly allocated MemoryBuffer that contains the
/// object which corresponds with Module M, or 0 if an object is not
/// available.
virtual std::unique_ptr<MemoryBuffer> getObject(const Module* M) = 0;
};
}
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/JITEventListener.h | //===- JITEventListener.h - Exposes events from JIT compilation -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the JITEventListener interface, which lets users get
// callbacks when significant events happen during the JIT compilation process.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
#define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
#include "RuntimeDyld.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/Support/DataTypes.h"
#include <vector>
namespace llvm {
class Function;
class MachineFunction;
class OProfileWrapper;
class IntelJITEventsWrapper;
namespace object {
class ObjectFile;
}
/// JITEvent_EmittedFunctionDetails - Helper struct for containing information
/// about a generated machine code function.
struct JITEvent_EmittedFunctionDetails {
struct LineStart {
/// The address at which the current line changes.
uintptr_t Address;
/// The new location information. These can be translated to DebugLocTuples
/// using MF->getDebugLocTuple().
DebugLoc Loc;
};
/// The machine function the struct contains information for.
const MachineFunction *MF;
/// The list of line boundary information, sorted by address.
std::vector<LineStart> LineStarts;
};
/// JITEventListener - Abstract interface for use by the JIT to notify clients
/// about significant events during compilation. For example, to notify
/// profilers and debuggers that need to know where functions have been emitted.
///
/// The default implementation of each method does nothing.
class JITEventListener {
public:
typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails;
public:
JITEventListener() {}
virtual ~JITEventListener() {}
/// NotifyObjectEmitted - Called after an object has been successfully
/// emitted to memory. NotifyFunctionEmitted will not be called for
/// individual functions in the object.
///
/// ELF-specific information
/// The ObjectImage contains the generated object image
/// with section headers updated to reflect the address at which sections
/// were loaded and with relocations performed in-place on debug sections.
virtual void NotifyObjectEmitted(const object::ObjectFile &Obj,
const RuntimeDyld::LoadedObjectInfo &L) {}
/// NotifyFreeingObject - Called just before the memory associated with
/// a previously emitted object is released.
virtual void NotifyFreeingObject(const object::ObjectFile &Obj) {}
// Get a pointe to the GDB debugger registration listener.
static JITEventListener *createGDBRegistrationListener();
#if LLVM_USE_INTEL_JITEVENTS
// Construct an IntelJITEventListener
static JITEventListener *createIntelJITEventListener();
// Construct an IntelJITEventListener with a test Intel JIT API implementation
static JITEventListener *createIntelJITEventListener(
IntelJITEventsWrapper* AlternativeImpl);
#else
static JITEventListener *createIntelJITEventListener() { return nullptr; }
static JITEventListener *createIntelJITEventListener(
IntelJITEventsWrapper* AlternativeImpl) {
return nullptr;
}
#endif // USE_INTEL_JITEVENTS
#if LLVM_USE_OPROFILE
// Construct an OProfileJITEventListener
static JITEventListener *createOProfileJITEventListener();
// Construct an OProfileJITEventListener with a test opagent implementation
static JITEventListener *createOProfileJITEventListener(
OProfileWrapper* AlternativeImpl);
#else
static JITEventListener *createOProfileJITEventListener() { return nullptr; }
static JITEventListener *createOProfileJITEventListener(
OProfileWrapper* AlternativeImpl) {
return nullptr;
}
#endif // USE_OPROFILE
private:
virtual void anchor();
};
} // end namespace llvm.
#endif // defined LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
|
0 | repos/DirectXShaderCompiler/include/llvm | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/GenericValue.h | //===-- GenericValue.h - Represent any type of LLVM value -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// The GenericValue class is used to represent an LLVM value of arbitrary type.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_GENERICVALUE_H
#define LLVM_EXECUTIONENGINE_GENERICVALUE_H
#include "llvm/ADT/APInt.h"
#include "llvm/Support/DataTypes.h"
namespace llvm {
typedef void* PointerTy;
class APInt;
struct GenericValue {
struct IntPair {
unsigned int first;
unsigned int second;
};
union {
double DoubleVal;
float FloatVal;
PointerTy PointerVal;
struct IntPair UIntPairVal;
unsigned char Untyped[8];
};
APInt IntVal; // also used for long doubles.
// For aggregate data types.
std::vector<GenericValue> AggregateVal;
// to make code faster, set GenericValue to zero could be omitted, but it is
// potentially can cause problems, since GenericValue to store garbage
// instead of zero.
GenericValue() : IntVal(1,0) {UIntPairVal.first = 0; UIntPairVal.second = 0;}
explicit GenericValue(void *V) : PointerVal(V), IntVal(1,0) { }
};
inline GenericValue PTOGV(void *P) { return GenericValue(P); }
inline void* GVTOP(const GenericValue &GV) { return GV.PointerVal; }
} // End llvm namespace.
#endif
|
0 | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/Orc/OrcTargetSupport.h | //===-- OrcTargetSupport.h - Code to support specific targets --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Target specific code for Orc, e.g. callback assembly.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_ORC_ORCTARGETSUPPORT_H
#define LLVM_EXECUTIONENGINE_ORC_ORCTARGETSUPPORT_H
#include "IndirectionUtils.h"
namespace llvm {
namespace orc {
class OrcX86_64 {
public:
static const char *ResolverBlockName;
/// @brief Insert module-level inline callback asm into module M for the
/// symbols managed by JITResolveCallbackHandler J.
static void insertResolverBlock(Module &M,
JITCompileCallbackManagerBase &JCBM);
/// @brief Get a label name from the given index.
typedef std::function<std::string(unsigned)> LabelNameFtor;
/// @brief Insert the requested number of trampolines into the given module.
/// @param M Module to insert the call block into.
/// @param NumCalls Number of calls to create in the call block.
/// @param StartIndex Optional argument specifying the index suffix to start
/// with.
/// @return A functor that provides the symbol name for each entry in the call
/// block.
///
static LabelNameFtor insertCompileCallbackTrampolines(
Module &M,
TargetAddress TrampolineAddr,
unsigned NumCalls,
unsigned StartIndex = 0);
};
} // End namespace orc.
} // End namespace llvm.
#endif // LLVM_EXECUTIONENGINE_ORC_ORCTARGETSUPPORT_H
|
0 | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine | repos/DirectXShaderCompiler/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h | //===- LazyEmittingLayer.h - Lazily emit IR to lower JIT layers -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Contains the definition for a lazy-emitting layer for the JIT.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_ORC_LAZYEMITTINGLAYER_H
#define LLVM_EXECUTIONENGINE_ORC_LAZYEMITTINGLAYER_H
#include "JITSymbol.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include <list>
namespace llvm {
namespace orc {
/// @brief Lazy-emitting IR layer.
///
/// This layer accepts sets of LLVM IR Modules (via addModuleSet), but does
/// not immediately emit them the layer below. Instead, emissing to the base
/// layer is deferred until the first time the client requests the address
/// (via JITSymbol::getAddress) for a symbol contained in this layer.
template <typename BaseLayerT> class LazyEmittingLayer {
public:
typedef typename BaseLayerT::ModuleSetHandleT BaseLayerHandleT;
private:
class EmissionDeferredSet {
public:
EmissionDeferredSet() : EmitState(NotEmitted) {}
virtual ~EmissionDeferredSet() {}
JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) {
switch (EmitState) {
case NotEmitted:
if (auto GV = searchGVs(Name, ExportedSymbolsOnly)) {
// Create a std::string version of Name to capture here - the argument
// (a StringRef) may go away before the lambda is executed.
// FIXME: Use capture-init when we move to C++14.
std::string PName = Name;
JITSymbolFlags Flags = JITSymbolBase::flagsFromGlobalValue(*GV);
auto GetAddress =
[this, ExportedSymbolsOnly, PName, &B]() -> TargetAddress {
if (this->EmitState == Emitting)
return 0;
else if (this->EmitState == NotEmitted) {
this->EmitState = Emitting;
Handle = this->emitToBaseLayer(B);
this->EmitState = Emitted;
}
auto Sym = B.findSymbolIn(Handle, PName, ExportedSymbolsOnly);
return Sym.getAddress();
};
return JITSymbol(std::move(GetAddress), Flags);
} else
return nullptr;
case Emitting:
// Calling "emit" can trigger external symbol lookup (e.g. to check for
// pre-existing definitions of common-symbol), but it will never find in
// this module that it would not have found already, so return null from
// here.
return nullptr;
case Emitted:
return B.findSymbolIn(Handle, Name, ExportedSymbolsOnly);
}
llvm_unreachable("Invalid emit-state.");
}
void removeModulesFromBaseLayer(BaseLayerT &BaseLayer) {
if (EmitState != NotEmitted)
BaseLayer.removeModuleSet(Handle);
}
void emitAndFinalize(BaseLayerT &BaseLayer) {
assert(EmitState != Emitting &&
"Cannot emitAndFinalize while already emitting");
if (EmitState == NotEmitted) {
EmitState = Emitting;
Handle = emitToBaseLayer(BaseLayer);
EmitState = Emitted;
}
BaseLayer.emitAndFinalize(Handle);
}
template <typename ModuleSetT, typename MemoryManagerPtrT,
typename SymbolResolverPtrT>
static std::unique_ptr<EmissionDeferredSet>
create(BaseLayerT &B, ModuleSetT Ms, MemoryManagerPtrT MemMgr,
SymbolResolverPtrT Resolver);
protected:
virtual const GlobalValue* searchGVs(StringRef Name,
bool ExportedSymbolsOnly) const = 0;
virtual BaseLayerHandleT emitToBaseLayer(BaseLayerT &BaseLayer) = 0;
private:
enum { NotEmitted, Emitting, Emitted } EmitState;
BaseLayerHandleT Handle;
};
template <typename ModuleSetT, typename MemoryManagerPtrT,
typename SymbolResolverPtrT>
class EmissionDeferredSetImpl : public EmissionDeferredSet {
public:
EmissionDeferredSetImpl(ModuleSetT Ms,
MemoryManagerPtrT MemMgr,
SymbolResolverPtrT Resolver)
: Ms(std::move(Ms)), MemMgr(std::move(MemMgr)),
Resolver(std::move(Resolver)) {}
protected:
const GlobalValue* searchGVs(StringRef Name,
bool ExportedSymbolsOnly) const override {
// FIXME: We could clean all this up if we had a way to reliably demangle
// names: We could just demangle name and search, rather than
// mangling everything else.
// If we have already built the mangled name set then just search it.
if (MangledSymbols) {
auto VI = MangledSymbols->find(Name);
if (VI == MangledSymbols->end())
return nullptr;
auto GV = VI->second;
if (!ExportedSymbolsOnly || GV->hasDefaultVisibility())
return GV;
return nullptr;
}
// If we haven't built the mangled name set yet, try to build it. As an
// optimization this will leave MangledNames set to nullptr if we find
// Name in the process of building the set.
return buildMangledSymbols(Name, ExportedSymbolsOnly);
}
BaseLayerHandleT emitToBaseLayer(BaseLayerT &BaseLayer) override {
// We don't need the mangled names set any more: Once we've emitted this
// to the base layer we'll just look for symbols there.
MangledSymbols.reset();
return BaseLayer.addModuleSet(std::move(Ms), std::move(MemMgr),
std::move(Resolver));
}
private:
// If the mangled name of the given GlobalValue matches the given search
// name (and its visibility conforms to the ExportedSymbolsOnly flag) then
// return the symbol. Otherwise, add the mangled name to the Names map and
// return nullptr.
const GlobalValue* addGlobalValue(StringMap<const GlobalValue*> &Names,
const GlobalValue &GV,
const Mangler &Mang, StringRef SearchName,
bool ExportedSymbolsOnly) const {
// Modules don't "provide" decls or common symbols.
if (GV.isDeclaration() || GV.hasCommonLinkage())
return nullptr;
// Mangle the GV name.
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
Mang.getNameWithPrefix(MangledNameStream, &GV, false);
}
// Check whether this is the name we were searching for, and if it is then
// bail out early.
if (MangledName == SearchName)
if (!ExportedSymbolsOnly || GV.hasDefaultVisibility())
return &GV;
// Otherwise add this to the map for later.
Names[MangledName] = &GV;
return nullptr;
}
// Build the MangledSymbols map. Bails out early (with MangledSymbols left set
// to nullptr) if the given SearchName is found while building the map.
const GlobalValue* buildMangledSymbols(StringRef SearchName,
bool ExportedSymbolsOnly) const {
assert(!MangledSymbols && "Mangled symbols map already exists?");
auto Symbols = llvm::make_unique<StringMap<const GlobalValue*>>();
for (const auto &M : Ms) {
Mangler Mang;
for (const auto &V : M->globals())
if (auto GV = addGlobalValue(*Symbols, V, Mang, SearchName,
ExportedSymbolsOnly))
return GV;
for (const auto &F : *M)
if (auto GV = addGlobalValue(*Symbols, F, Mang, SearchName,
ExportedSymbolsOnly))
return GV;
}
MangledSymbols = std::move(Symbols);
return nullptr;
}
ModuleSetT Ms;
MemoryManagerPtrT MemMgr;
SymbolResolverPtrT Resolver;
mutable std::unique_ptr<StringMap<const GlobalValue*>> MangledSymbols;
};
typedef std::list<std::unique_ptr<EmissionDeferredSet>> ModuleSetListT;
BaseLayerT &BaseLayer;
ModuleSetListT ModuleSetList;
public:
/// @brief Handle to a set of loaded modules.
typedef typename ModuleSetListT::iterator ModuleSetHandleT;
/// @brief Construct a lazy emitting layer.
LazyEmittingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
/// @brief Add the given set of modules to the lazy emitting layer.
template <typename ModuleSetT, typename MemoryManagerPtrT,
typename SymbolResolverPtrT>
ModuleSetHandleT addModuleSet(ModuleSetT Ms,
MemoryManagerPtrT MemMgr,
SymbolResolverPtrT Resolver) {
return ModuleSetList.insert(
ModuleSetList.end(),
EmissionDeferredSet::create(BaseLayer, std::move(Ms), std::move(MemMgr),
std::move(Resolver)));
}
/// @brief Remove the module set represented by the given handle.
///
/// This method will free the memory associated with the given module set,
/// both in this layer, and the base layer.
void removeModuleSet(ModuleSetHandleT H) {
(*H)->removeModulesFromBaseLayer(BaseLayer);
ModuleSetList.erase(H);
}
/// @brief Search for the given named symbol.
/// @param Name The name of the symbol to search for.
/// @param ExportedSymbolsOnly If true, search only for exported symbols.
/// @return A handle for the given named symbol, if it exists.
JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
// Look for the symbol among existing definitions.
if (auto Symbol = BaseLayer.findSymbol(Name, ExportedSymbolsOnly))
return Symbol;
// If not found then search the deferred sets. If any of these contain a
// definition of 'Name' then they will return a JITSymbol that will emit
// the corresponding module when the symbol address is requested.
for (auto &DeferredSet : ModuleSetList)
if (auto Symbol = DeferredSet->find(Name, ExportedSymbolsOnly, BaseLayer))
return Symbol;
// If no definition found anywhere return a null symbol.
return nullptr;
}
/// @brief Get the address of the given symbol in the context of the set of
/// compiled modules represented by the handle H.
JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
bool ExportedSymbolsOnly) {
return (*H)->find(Name, ExportedSymbolsOnly, BaseLayer);
}
/// @brief Immediately emit and finalize the moduleOB set represented by the
/// given handle.
/// @param H Handle for module set to emit/finalize.
void emitAndFinalize(ModuleSetHandleT H) {
(*H)->emitAndFinalize(BaseLayer);
}
};
template <typename BaseLayerT>
template <typename ModuleSetT, typename MemoryManagerPtrT,
typename SymbolResolverPtrT>
std::unique_ptr<typename LazyEmittingLayer<BaseLayerT>::EmissionDeferredSet>
LazyEmittingLayer<BaseLayerT>::EmissionDeferredSet::create(
BaseLayerT &B, ModuleSetT Ms, MemoryManagerPtrT MemMgr,
SymbolResolverPtrT Resolver) {
typedef EmissionDeferredSetImpl<ModuleSetT, MemoryManagerPtrT, SymbolResolverPtrT>
EDS;
return llvm::make_unique<EDS>(std::move(Ms), std::move(MemMgr),
std::move(Resolver));
}
} // End namespace orc.
} // End namespace llvm.
#endif // LLVM_EXECUTIONENGINE_ORC_LAZYEMITTINGLAYER_H
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.