LLVM API Documentation

llvm::TargetData Class Reference

#include <TargetData.h>

Inheritance diagram for llvm::TargetData:
[legend]
Collaboration diagram for llvm::TargetData:
[legend]

List of all members.

Public Member Functions

 TargetData ()
 TargetData (const std::string &TargetDescription)
 Constructs a TargetData from a specification string. See init().
 TargetData (const Module *M)
 Initialize target data from properties stored in the module.
 TargetData (const TargetData &TD)
 ~TargetData ()
void init (const std::string &TargetDescription)
 Parse a target data layout string and initialize TargetData alignments.
bool isLittleEndian () const
 Target endianness...
bool isBigEndian () const
std::string getStringRepresentation () const
unsigned char getPointerABIAlignment () const
 Target pointer alignment.
unsigned char getPointerPrefAlignment () const
 Return target's alignment for stack-based pointers.
unsigned char getPointerSize () const
 Target pointer size.
unsigned char getPointerSizeInBits () const
 Target pointer size, in bits.
uint64_t getTypeSizeInBits (const Type *Ty) const
uint64_t getTypeStoreSize (const Type *Ty) const
uint64_t getTypeStoreSizeInBits (const Type *Ty) const
uint64_t getTypeAllocSize (const Type *Ty) const
uint64_t getTypeAllocSizeInBits (const Type *Ty) const
unsigned char getABITypeAlignment (const Type *Ty) const
unsigned char getCallFrameTypeAlignment (const Type *Ty) const
unsigned char getPrefTypeAlignment (const Type *Ty) const
unsigned char getPreferredTypeAlignmentShift (const Type *Ty) const
const IntegerType * getIntPtrType (LLVMContext &C) const
uint64_t getIndexedOffset (const Type *Ty, Value *const *Indices, unsigned NumIndices) const
const StructLayout * getStructLayout (const StructType *Ty) const
void InvalidateStructLayoutInfo (const StructType *Ty) const
unsigned getPreferredAlignment (const GlobalVariable *GV) const
unsigned getPreferredAlignmentLog (const GlobalVariable *GV) const

Static Public Member Functions

template<typename UIntTy>
static UIntTy RoundUpAlignment (UIntTy Val, unsigned Alignment)

Static Public Attributes

static char ID = 0


Detailed Description

Definition at line 69 of file TargetData.h.


Constructor & Destructor Documentation

llvm::TargetData::TargetData (  )  [inline]

Default ctor.

Note:
This has to exist, because this is a pass, but it should never be used.

Definition at line 118 of file TargetData.h.

References llvm::llvm_report_error().

llvm::TargetData::TargetData ( const std::string &  TargetDescription  )  [inline, explicit]

Constructs a TargetData from a specification string. See init().

Definition at line 124 of file TargetData.h.

References init().

TargetData::TargetData ( const Module *  M  )  [explicit]

Initialize target data from properties stored in the module.

Definition at line 238 of file TargetData.cpp.

References llvm::Module::getDataLayout(), and init().

llvm::TargetData::TargetData ( const TargetData &  TD  )  [inline]

Definition at line 132 of file TargetData.h.

TargetData::~TargetData (  ) 


Member Function Documentation

void TargetData::init ( const std::string &  TargetDescription  ) 

Parse a target data layout string and initialize TargetData alignments.

A TargetDescription string consists of a sequence of hyphen-delimited specifiers for target endianness, pointer size and alignments, and various primitive type sizes and alignments. A typical string looks something like:

"E-p:32:32:32-i1:8:8-i8:8:8-i32:32:32-i64:32:64-f32:32:32-f64:32:64"

(note: this string is not fully specified and is only an example.) Alignments come in two flavors: ABI and preferred. ABI alignment (abi_align, below) dictates how a type will be aligned within an aggregate and when used as an argument. Preferred alignment (pref_align, below) determines a type's alignment when emitted as a global. Specifier string details:

[E|e]: Endianness. "E" specifies a big-endian target data model, "e" specifies a little-endian target data model.

p:

<size>:<abi_align>:<pref_align>
: Pointer size, ABI and preferred alignment.

<type><size>:<abi_align>:<pref_align>
: Numeric type alignment. Type is one of i|f|v|a, corresponding to integer, floating point, vector, or aggregate. Size indicates the size, e.g., 32 or 64 bits. The default string, fully specified, is:

"E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64" "-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64" "-v64:64:64-v128:128:128"

Note that in the case of aggregates, 0 is the default ABI and preferred alignment. This is a special case, where the aggregate's computed worst-case alignment will be used.

Definition at line 172 of file TargetData.cpp.

References llvm::AGGREGATE_ALIGN, llvm::FLOAT_ALIGN, llvm::getToken(), llvm::INTEGER_ALIGN, llvm::STACK_ALIGN, and llvm::VECTOR_ALIGN.

Referenced by TargetData().

bool llvm::TargetData::isLittleEndian (  )  const [inline]

bool llvm::TargetData::isBigEndian (  )  const [inline]

Definition at line 149 of file TargetData.h.

Referenced by llvm::AsmPrinter::EmitInt64(), and llvm::MachOWriter::InitMem().

std::string TargetData::getStringRepresentation (  )  const

getStringRepresentation - Return the string representation of the TargetData. This representation is in the same format accepted by the string constructor above.

Definition at line 378 of file TargetData.cpp.

References llvm::itostr(), and llvm::utostr().

unsigned char llvm::TargetData::getPointerABIAlignment (  )  const [inline]

Target pointer alignment.

Definition at line 156 of file TargetData.h.

Referenced by llvm::MachineFunction::MachineFunction().

unsigned char llvm::TargetData::getPointerPrefAlignment (  )  const [inline]

Return target's alignment for stack-based pointers.

Definition at line 158 of file TargetData.h.

unsigned char llvm::TargetData::getPointerSize (  )  const [inline]

unsigned char llvm::TargetData::getPointerSizeInBits (  )  const [inline]

uint64_t TargetData::getTypeSizeInBits ( const Type *  Ty  )  const

Size examples:

Type SizeInBits StoreSizeInBits AllocSizeInBits[*] ---- ---------- --------------- --------------- i1 1 8 8 i8 8 8 8 i19 19 24 32 i32 32 32 32 i100 100 104 128 i128 128 128 128 Float 32 32 32 Double 64 64 64 X86_FP80 80 80 96

[*] The alloc size depends on the alignment, and thus on the target. These values are for x86-32 linux. getTypeSizeInBits - Return the number of bits necessary to hold the specified type. For example, returns 36 for i36 and 80 for x86_fp80.

Definition at line 396 of file TargetData.cpp.

References llvm::Type::ArrayTyID, llvm::Type::DoubleTyID, llvm::Type::FloatTyID, llvm::Type::FP128TyID, llvm::SequentialType::getElementType(), llvm::ArrayType::getNumElements(), getPointerSizeInBits(), llvm::StructLayout::getSizeInBits(), getStructLayout(), getTypeAllocSizeInBits(), llvm::Type::getTypeID(), llvm::Type::IntegerTyID, llvm::Type::isSized(), llvm::Type::LabelTyID, llvm_unreachable, llvm::Type::PointerTyID, llvm::Type::PPC_FP128TyID, llvm::Type::StructTyID, llvm::Type::VectorTyID, llvm::Type::VoidTyID, and llvm::Type::X86_FP80TyID.

Referenced by llvm::ComputeMaskedBits(), llvm::ComputeNumSignBits(), FindElementAtOffset(), llvm::SDISelAsmOperandInfo::getCallOperandValEVT(), getPreferredAlignment(), llvm::ScalarEvolution::getTypeSizeInBits(), getTypeStoreSize(), HasPadding(), and SymbolicallyEvaluateGEP().

uint64_t llvm::TargetData::getTypeStoreSize ( const Type *  Ty  )  const [inline]

getTypeStoreSize - Return the maximum number of bytes that may be overwritten by storing the specified type. For example, returns 5 for i36 and 10 for x86_fp80.

Definition at line 188 of file TargetData.h.

References getTypeSizeInBits().

Referenced by ffiInvoke(), getTypeAllocSize(), llvm::AliasAnalysis::getTypeStoreSize(), getTypeStoreSizeInBits(), llvm::InlineFunction(), llvm::ExecutionEngine::LoadValueFromMemory(), and llvm::ExecutionEngine::StoreValueToMemory().

uint64_t llvm::TargetData::getTypeStoreSizeInBits ( const Type *  Ty  )  const [inline]

getTypeStoreSizeInBits - Return the maximum number of bits that may be overwritten by storing the specified type; always a multiple of 8. For example, returns 40 for i36 and 80 for x86_fp80.

Definition at line 195 of file TargetData.h.

References getTypeStoreSize().

uint64_t llvm::TargetData::getTypeAllocSize ( const Type *  Ty  )  const [inline]

getTypeAllocSize - Return the offset in bytes between successive objects of the specified type, including alignment padding. This is the amount that alloca reserves for this type. For example, returns 12 or 16 for x86_fp80, depending on alignment.

Definition at line 203 of file TargetData.h.

References getABITypeAlignment(), getTypeStoreSize(), and RoundUpAlignment().

Referenced by calculateFunctionInfo(), ComputeValueVTs(), llvm::ConstantFoldInstOperands(), llvm::MachOCodeEmitter::emitConstantPool(), llvm::AsmPrinter::EmitConstantPool(), llvm::AsmPrinter::EmitConstantValueOnly(), EmitGEPOffset(), llvm::AsmPrinter::EmitGlobalConstant(), llvm::ExecutionEngine::EmitGlobalVariable(), EvaluateGEPOffsetExpression(), llvm::Interpreter::executeGEPOperation(), FindElementAtOffset(), llvm::ScalarEvolution::getAllocSizeExpr(), GetConstantPoolSizeInBytes(), getIndexedOffset(), llvm::TargetLoweringObjectFile::getKindForGlobal(), llvm::JIT::getMemoryForGV(), llvm::ExecutionEngine::getMemoryForGV(), GetOffsetFromIndex(), getTypeAllocSizeInBits(), llvm::MSILWriter::getTypePostfix(), llvm::ExecutionEngine::InitializeMemory(), llvm::MachOWriter::InitMem(), IsConstantOffsetFromGlobal(), llvm::MipsTargetObjectFile::IsGlobalInSmallSection(), llvm::XCoreTargetLowering::isLegalAddressingMode(), isObjectSmallerThan(), isSafeToEliminateVarargsCast(), llvm::TargetLowering::LowerCallTo(), llvm::MSILWriter::printAllocaInstruction(), llvm::MSILWriter::printDeclarations(), llvm::MSILWriter::printGepInstruction(), llvm::X86ATTAsmPrinter::PrintGlobalVariable(), llvm::MSILWriter::printStaticConstant(), llvm::FunctionLoweringInfo::set(), SRAGlobal(), SymbolicallyEvaluateGEP(), TryToOptimizeStoreOfMallocToGlobal(), and llvm::Interpreter::visitAllocationInst().

uint64_t llvm::TargetData::getTypeAllocSizeInBits ( const Type *  Ty  )  const [inline]

getTypeAllocSizeInBits - Return the offset in bits between successive objects of the specified type, including alignment padding; always a multiple of 8. This is the amount that alloca reserves for this type. For example, returns 96 or 128 for x86_fp80, depending on alignment.

Definition at line 212 of file TargetData.h.

References getTypeAllocSize().

Referenced by llvm::AsmPrinter::EmitConstantValueOnly(), getTypeSizeInBits(), and HasPadding().

unsigned char TargetData::getABITypeAlignment ( const Type *  Ty  )  const

unsigned char TargetData::getCallFrameTypeAlignment ( const Type *  Ty  )  const

getCallFrameTypeAlignment - Return the minimum ABI-required alignment for the specified type when it is part of a call frame.

Definition at line 494 of file TargetData.cpp.

References getABITypeAlignment(), and llvm::STACK_ALIGN.

Referenced by llvm::TargetLowering::getByValTypeAlignment().

unsigned char TargetData::getPrefTypeAlignment ( const Type *  Ty  )  const

getPrefTypeAlignment - Return the preferred stack/global alignment for the specified type. This is always at least as good as the ABI alignment.

Definition at line 502 of file TargetData.cpp.

Referenced by llvm::ComputeMaskedBits(), llvm::SelectionDAG::CreateStackTemporary(), llvm::SelectionDAG::getConstantPool(), getPreferredAlignment(), getPreferredTypeAlignmentShift(), llvm::InlineFunction(), llvm::FunctionLoweringInfo::set(), and llvm::MachOCodeEmitter::startFunction().

unsigned char TargetData::getPreferredTypeAlignmentShift ( const Type *  Ty  )  const

getPreferredTypeAlignmentShift - Return the preferred alignment for the specified type, returned as log2 of the value (a shift amount).

Definition at line 506 of file TargetData.cpp.

References getPrefTypeAlignment(), and llvm::Log2_32().

const IntegerType * TargetData::getIntPtrType ( LLVMContext &  C  )  const

uint64_t TargetData::getIndexedOffset ( const Type *  Ty,
Value *const *  Indices,
unsigned  NumIndices 
) const

getIndexedOffset - return the offset from the beginning of the type for the specified indices. This is used to implement getelementptr.

Definition at line 519 of file TargetData.cpp.

References llvm::gep_type_begin(), llvm::Type::getContext(), llvm::StructLayout::getElementOffset(), llvm::Type::getInt32Ty(), getStructLayout(), llvm::Intrinsic::getType(), and getTypeAllocSize().

Referenced by llvm::AsmPrinter::EmitConstantValueOnly(), llvm::ExecutionEngine::getConstantValue(), llvm::MachOWriter::InitMem(), and SymbolicallyEvaluateGEP().

const StructLayout * TargetData::getStructLayout ( const StructType *  Ty  )  const

void TargetData::InvalidateStructLayoutInfo ( const StructType *  Ty  )  const

InvalidateStructLayoutInfo - TargetData speculatively caches StructLayout objects. If a TargetData object is alive when types are being refined and removed, this method must be called whenever a StructType is removed to avoid a dangling pointer in this cache.

InvalidateStructLayoutInfo - TargetData speculatively caches StructLayout objects. If a TargetData object is alive when types are being refined and removed, this method must be called whenever a StructType is removed to avoid a dangling pointer in this cache.

Definition at line 365 of file TargetData.cpp.

References llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::end(), llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::erase(), and llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::find().

unsigned TargetData::getPreferredAlignment ( const GlobalVariable *  GV  )  const

getPreferredAlignment - Return the preferred alignment of the specified global. This includes an explicitly requested alignment (if the global has one).

getPreferredAlignment - Return the preferred alignment of the specified global. This includes an explicitly requested alignment (if the global has one).

Definition at line 558 of file TargetData.cpp.

References Alignment, llvm::GlobalValue::getAlignment(), llvm::SequentialType::getElementType(), getPrefTypeAlignment(), llvm::GlobalValue::getType(), getTypeSizeInBits(), and llvm::GlobalVariable::hasInitializer().

Referenced by llvm::JIT::getMemoryForGV(), getPreferredAlignmentLog(), llvm::TargetLoweringObjectFileMachO::SelectSectionForGlobal(), and llvm::TargetLoweringObjectFileELF::SelectSectionForGlobal().

unsigned TargetData::getPreferredAlignmentLog ( const GlobalVariable *  GV  )  const

getPreferredAlignmentLog - Return the preferred alignment of the specified global, returned in log form. This includes an explicitly requested alignment (if the global has one).

getPreferredAlignmentLog - Return the preferred alignment of the specified global, returned in log form. This includes an explicitly requested alignment (if the global has one).

Definition at line 578 of file TargetData.cpp.

References getPreferredAlignment(), and llvm::Log2_32().

Referenced by llvm::X86IntelAsmPrinter::PrintGlobalVariable(), and llvm::X86ATTAsmPrinter::PrintGlobalVariable().

template<typename UIntTy>
static UIntTy llvm::TargetData::RoundUpAlignment ( UIntTy  Val,
unsigned  Alignment 
) [inline, static]

RoundUpAlignment - Round the specified value up to the next alignment boundary specified by Alignment. For example, 7 rounded up to an alignment boundary of 4 is 8. 8 rounded up to the alignment boundary of 4 is 8 because it is already aligned.

Definition at line 271 of file TargetData.h.

Referenced by getTypeAllocSize().


Member Data Documentation

char TargetData::ID = 0 [static]

Definition at line 276 of file TargetData.h.


The documentation for this class was generated from the following files: