LLVM  3.7.0
Target.cpp
Go to the documentation of this file.
1 //===-- Target.cpp --------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the common infrastructure (including C bindings) for
11 // libLLVMTarget.a, which implements target information.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm-c/Target.h"
16 #include "llvm-c/Initialization.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/IR/Value.h"
20 #include "llvm/InitializePasses.h"
23 #include <cstring>
24 
25 using namespace llvm;
26 
28  return reinterpret_cast<TargetLibraryInfoImpl*>(P);
29 }
30 
33  return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
34 }
35 
39 }
40 
43 }
44 
45 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
46  return wrap(new DataLayout(StringRep));
47 }
48 
50 }
51 
53  LLVMPassManagerRef PM) {
54  unwrap(PM)->add(new TargetLibraryInfoWrapperPass(*unwrap(TLI)));
55 }
56 
58  std::string StringRep = unwrap(TD)->getStringRepresentation();
59  return strdup(StringRep.c_str());
60 }
61 
64 }
65 
67  return unwrap(TD)->getPointerSize(0);
68 }
69 
70 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS) {
71  return unwrap(TD)->getPointerSize(AS);
72 }
73 
75  return wrap(unwrap(TD)->getIntPtrType(getGlobalContext()));
76 }
77 
79  return wrap(unwrap(TD)->getIntPtrType(getGlobalContext(), AS));
80 }
81 
83  return wrap(unwrap(TD)->getIntPtrType(*unwrap(C)));
84 }
85 
87  return wrap(unwrap(TD)->getIntPtrType(*unwrap(C), AS));
88 }
89 
91  return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
92 }
93 
95  return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
96 }
97 
98 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
99  return unwrap(TD)->getTypeAllocSize(unwrap(Ty));
100 }
101 
103  return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
104 }
105 
107  return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
108 }
109 
111  return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty));
112 }
113 
116  return unwrap(TD)->getPreferredAlignment(unwrap<GlobalVariable>(GlobalVar));
117 }
118 
120  unsigned long long Offset) {
121  StructType *STy = unwrap<StructType>(StructTy);
122  return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
123 }
124 
125 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
126  unsigned Element) {
127  StructType *STy = unwrap<StructType>(StructTy);
128  return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
129 }
130 
132  delete unwrap(TD);
133 }
LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD)
Returns the byte order of a target, either LLVMBigEndian or LLVMLittleEndian.
Definition: Target.cpp:62
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: Core.h:85
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD, LLVMValueRef GlobalVar)
Computes the preferred alignment of a global variable in bytes for a target.
Definition: Target.cpp:114
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:684
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:61
Implementation of the target library information.
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:74
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Definition: DataLayout.cpp:551
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI size of a type in bytes for a target.
Definition: Target.cpp:98
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition: DataLayout.h:225
StructType - Class to represent struct types.
Definition: DerivedTypes.h:191
LLVMByteOrdering
Definition: Target.h:40
void initializeTarget(PassRegistry &)
initializeCodeGen - Initialize all passes linked into the CodeGen library.
Definition: Target.cpp:36
LLVMTargetDataRef wrap(const DataLayout *P)
Definition: DataLayout.h:469
unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy, unsigned Element)
Computes the byte offset of the indexed struct element for a target.
Definition: Target.cpp:125
unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy, unsigned long long Offset)
Computes the structure element that contains the byte offset for a target.
Definition: Target.cpp:119
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:217
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the size of a type in bytes for a target.
Definition: Target.cpp:90
void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the pointer size in bytes for a target for a specified address space.
Definition: Target.cpp:70
LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD, unsigned AS)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:86
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:491
#define P(N)
DataLayout * unwrap(LLVMTargetDataRef P)
Definition: DataLayout.h:465
void LLVMDisposeTargetData(LLVMTargetDataRef TD)
Deallocates a TargetData.
Definition: Target.cpp:131
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Core.h:70
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the preferred alignment of a type in bytes for a target.
Definition: Target.cpp:110
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the storage size of a type in bytes for a target.
Definition: Target.cpp:94
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition: DataLayout.cpp:761
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Core.h:92
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:674
char * LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD)
Converts target data to a target layout string.
Definition: Target.cpp:57
unsigned LLVMPointerSize(LLVMTargetDataRef TD)
Returns the pointer size in bytes for a target.
Definition: Target.cpp:66
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Core.h:119
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:388
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it...
Definition: DataLayout.cpp:74
struct LLVMOpaqueTargetLibraryInfotData * LLVMTargetLibraryInfoRef
Definition: Target.h:43
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep)
Creates target data from a target layout string.
Definition: Target.cpp:45
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the call frame alignment of a type in bytes for a target.
Definition: Target.cpp:106
void LLVMInitializeTarget(LLVMPassRegistryRef R)
Definition: Target.cpp:41
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Core.h:116
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:78
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:371
void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM)
Adds target data information to a pass manager.
Definition: Target.cpp:49
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI, LLVMPassManagerRef PM)
Adds target library information to a pass manager.
Definition: Target.cpp:52
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI alignment of a type in bytes for a target.
Definition: Target.cpp:102
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:82
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:507
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:41
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
Definition: DataLayout.cpp:593
LLVMContext & getGlobalContext()
getGlobalContext - Returns a global context.
Definition: LLVMContext.cpp:30
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: DataLayout.h:32