LLVM  8.0.1
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"
18 #include "llvm/IR/DataLayout.h"
19 #include "llvm/IR/LLVMContext.h"
21 #include "llvm/IR/Value.h"
22 #include "llvm/InitializePasses.h"
23 #include <cstring>
24 
25 using namespace llvm;
26 
27 // Avoid including "llvm-c/Core.h" for compile time, fwd-declare this instead.
28 extern "C" LLVMContextRef LLVMGetGlobalContext(void);
29 
31  return reinterpret_cast<TargetLibraryInfoImpl*>(P);
32 }
33 
36  return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
37 }
38 
42 }
43 
46 }
47 
49  return wrap(&unwrap(M)->getDataLayout());
50 }
51 
53  unwrap(M)->setDataLayout(*unwrap(DL));
54 }
55 
56 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
57  return wrap(new DataLayout(StringRep));
58 }
59 
61  delete unwrap(TD);
62 }
63 
65  LLVMPassManagerRef PM) {
66  unwrap(PM)->add(new TargetLibraryInfoWrapperPass(*unwrap(TLI)));
67 }
68 
70  std::string StringRep = unwrap(TD)->getStringRepresentation();
71  return strdup(StringRep.c_str());
72 }
73 
75  return unwrap(TD)->isLittleEndian() ? LLVMLittleEndian : LLVMBigEndian;
76 }
77 
79  return unwrap(TD)->getPointerSize(0);
80 }
81 
82 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS) {
83  return unwrap(TD)->getPointerSize(AS);
84 }
85 
87  return wrap(unwrap(TD)->getIntPtrType(*unwrap(LLVMGetGlobalContext())));
88 }
89 
91  return wrap(unwrap(TD)->getIntPtrType(*unwrap(LLVMGetGlobalContext()), AS));
92 }
93 
95  return wrap(unwrap(TD)->getIntPtrType(*unwrap(C)));
96 }
97 
99  return wrap(unwrap(TD)->getIntPtrType(*unwrap(C), AS));
100 }
101 
103  return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
104 }
105 
107  return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
108 }
109 
110 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
111  return unwrap(TD)->getTypeAllocSize(unwrap(Ty));
112 }
113 
115  return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
116 }
117 
119  return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
120 }
121 
123  return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty));
124 }
125 
128  return unwrap(TD)->getPreferredAlignment(unwrap<GlobalVariable>(GlobalVar));
129 }
130 
132  unsigned long long Offset) {
133  StructType *STy = unwrap<StructType>(StructTy);
134  return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
135 }
136 
137 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
138  unsigned Element) {
139  StructType *STy = unwrap<StructType>(StructTy);
140  return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
141 }
LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD)
Returns the byte order of a target, either LLVMBigEndian or LLVMLittleEndian.
Definition: Target.cpp:74
uint64_t CallInst * C
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This class represents lattice values for constants.
Definition: AllocatorList.h:24
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:62
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD, LLVMValueRef GlobalVar)
Computes the preferred alignment of a global variable in bytes for a target.
Definition: Target.cpp:126
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:45
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:131
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:86
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: DataLayout.h:39
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:195
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI size of a type in bytes for a target.
Definition: Target.cpp:110
Class to represent struct types.
Definition: DerivedTypes.h:201
LLVMByteOrdering
Definition: Target.h:40
void initializeTarget(PassRegistry &)
Initialize all passes linked into the CodeGen library.
Definition: Target.cpp:39
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: Types.h:69
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:54
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:137
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:131
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the size of a type in bytes for a target.
Definition: Target.cpp:102
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:82
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:98
LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M)
Obtain the data layout for a module.
Definition: Target.cpp:48
#define P(N)
void LLVMDisposeTargetData(LLVMTargetDataRef TD)
Deallocates a TargetData.
Definition: Target.cpp:60
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the preferred alignment of a type in bytes for a target.
Definition: Target.cpp:122
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the storage size of a type in bytes for a target.
Definition: Target.cpp:106
char * LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD)
Converts target data to a target layout string.
Definition: Target.cpp:69
unsigned LLVMPointerSize(LLVMTargetDataRef TD)
Returns the pointer size in bytes for a target.
Definition: Target.cpp:78
void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL)
Set the data layout for a module.
Definition: Target.cpp:52
struct LLVMOpaqueTargetLibraryInfotData * LLVMTargetLibraryInfoRef
Definition: Target.h:43
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep)
Creates target data from a target layout string.
Definition: Target.cpp:56
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:128
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the call frame alignment of a type in bytes for a target.
Definition: Target.cpp:118
void LLVMInitializeTarget(LLVMPassRegistryRef R)
Definition: Target.cpp:44
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:190
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:90
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI, LLVMPassManagerRef PM)
Adds target library information to a pass manager.
Definition: Target.cpp:64
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI alignment of a type in bytes for a target.
Definition: Target.cpp:114
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:94
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:39
LLVMContextRef LLVMGetGlobalContext(void)
Obtain the global context instance.
Definition: Core.cpp:83
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:76