LLVM  14.0.0git
Target.cpp
Go to the documentation of this file.
1 //===-- Target.cpp --------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the common infrastructure (including C bindings) for
10 // libLLVMTarget.a, which implements target information.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm-c/Target.h"
15 #include "llvm-c/Initialization.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/IR/Value.h"
21 #include "llvm/InitializePasses.h"
22 #include <cstring>
23 
24 using namespace llvm;
25 
26 // Avoid including "llvm-c/Core.h" for compile time, fwd-declare this instead.
27 extern "C" LLVMContextRef LLVMGetGlobalContext(void);
28 
30  return reinterpret_cast<TargetLibraryInfoImpl*>(P);
31 }
32 
35  return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
36 }
37 
41 }
42 
45 }
46 
48  return wrap(&unwrap(M)->getDataLayout());
49 }
50 
52  unwrap(M)->setDataLayout(*unwrap(DL));
53 }
54 
55 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
56  return wrap(new DataLayout(StringRep));
57 }
58 
60  delete unwrap(TD);
61 }
62 
64  LLVMPassManagerRef PM) {
65  unwrap(PM)->add(new TargetLibraryInfoWrapperPass(*unwrap(TLI)));
66 }
67 
69  std::string StringRep = unwrap(TD)->getStringRepresentation();
70  return strdup(StringRep.c_str());
71 }
72 
74  return unwrap(TD)->isLittleEndian() ? LLVMLittleEndian : LLVMBigEndian;
75 }
76 
78  return unwrap(TD)->getPointerSize(0);
79 }
80 
81 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS) {
82  return unwrap(TD)->getPointerSize(AS);
83 }
84 
86  return wrap(unwrap(TD)->getIntPtrType(*unwrap(LLVMGetGlobalContext())));
87 }
88 
90  return wrap(unwrap(TD)->getIntPtrType(*unwrap(LLVMGetGlobalContext()), AS));
91 }
92 
94  return wrap(unwrap(TD)->getIntPtrType(*unwrap(C)));
95 }
96 
98  return wrap(unwrap(TD)->getIntPtrType(*unwrap(C), AS));
99 }
100 
102  return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
103 }
104 
106  return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
107 }
108 
109 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
110  return unwrap(TD)->getTypeAllocSize(unwrap(Ty));
111 }
112 
114  return unwrap(TD)->getABITypeAlign(unwrap(Ty)).value();
115 }
116 
118  return unwrap(TD)->getABITypeAlign(unwrap(Ty)).value();
119 }
120 
122  return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty));
123 }
124 
127  return unwrap(TD)
128  ->getPreferredAlign(unwrap<GlobalVariable>(GlobalVar))
129  .value();
130 }
131 
133  unsigned long long Offset) {
134  StructType *STy = unwrap<StructType>(StructTy);
135  return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
136 }
137 
138 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
139  unsigned Element) {
140  StructType *STy = unwrap<StructType>(StructTy);
141  return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
142 }
LLVMCreateTargetData
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep)
Creates target data from a target layout string.
Definition: Target.cpp:55
LLVMIntPtrType
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:85
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
LLVMContextRef
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:53
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
LLVMGetGlobalContext
LLVMContextRef LLVMGetGlobalContext(void)
Obtain the global context instance.
Definition: Core.cpp:81
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
LLVMElementAtOffset
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:132
LLVMPassRegistryRef
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:130
LLVMCallFrameAlignmentOfType
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the call frame alignment of a type in bytes for a target.
Definition: Target.cpp:117
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
LLVMIntPtrTypeInContext
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:93
llvm::initializeTargetTransformInfoWrapperPassPass
void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
LLVMByteOrder
LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD)
Returns the byte order of a target, either LLVMBigEndian or LLVMLittleEndian.
Definition: Target.cpp:73
LLVMSizeOfTypeInBits
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the size of a type in bytes for a target.
Definition: Target.cpp:101
llvm::TargetLibraryInfoImpl
Implementation of the target library information.
Definition: TargetLibraryInfo.h:48
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
LegacyPassManager.h
llvm::initializeTargetLibraryInfoWrapperPassPass
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
LLVMPreferredAlignmentOfGlobal
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD, LLVMValueRef GlobalVar)
Computes the preferred alignment of a global variable in bytes for a target.
Definition: Target.cpp:125
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:198
LLVMTargetDataRef
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: DataLayout.h:40
LLVMLittleEndian
@ LLVMLittleEndian
Definition: Target.h:35
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
TargetLibraryInfo.h
LLVMByteOrdering
LLVMByteOrdering
Definition: Target.h:35
LLVMPreferredAlignmentOfType
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the preferred alignment of a type in bytes for a target.
Definition: Target.cpp:121
llvm::PassRegistry
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
llvm::unwrap
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:256
LLVMTypeRef
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: Types.h:68
LLVMPointerSize
unsigned LLVMPointerSize(LLVMTargetDataRef TD)
Returns the pointer size in bytes for a target.
Definition: Target.cpp:77
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
LLVMABISizeOfType
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI size of a type in bytes for a target.
Definition: Target.cpp:109
LLVMPointerSizeForAS
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the pointer size in bytes for a target for a specified address space.
Definition: Target.cpp:81
Target.h
LLVMSetModuleDataLayout
void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL)
Set the data layout for a module.
Definition: Target.cpp:51
LLVMGetModuleDataLayout
LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M)
Obtain the data layout for a module.
Definition: Target.cpp:47
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:463
LLVMAddTargetLibraryInfo
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI, LLVMPassManagerRef PM)
Adds target library information to a pass manager.
Definition: Target.cpp:63
LLVMABIAlignmentOfType
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI alignment of a type in bytes for a target.
Definition: Target.cpp:113
LLVMDisposeTargetData
void LLVMDisposeTargetData(LLVMTargetDataRef TD)
Deallocates a TargetData.
Definition: Target.cpp:59
LLVMIntPtrTypeForAS
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:89
LLVMTargetLibraryInfoRef
struct LLVMOpaqueTargetLibraryInfotData * LLVMTargetLibraryInfoRef
Definition: Target.h:38
LLVMPassManagerRef
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:127
llvm::wrap
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:251
DataLayout.h
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:213
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
LLVMOffsetOfElement
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:138
LLVMInitializeTarget
void LLVMInitializeTarget(LLVMPassRegistryRef R)
Definition: Target.cpp:43
LLVMIntPtrTypeForASInContext
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:97
LLVMStoreSizeOfType
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the storage size of a type in bytes for a target.
Definition: Target.cpp:105
LLVMBigEndian
@ LLVMBigEndian
Definition: Target.h:35
llvm::Registry
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
llvm::initializeTarget
void initializeTarget(PassRegistry &)
Initialize all passes linked into the CodeGen library.
Definition: Target.cpp:38
llvm::lltok::GlobalVar
@ GlobalVar
Definition: LLToken.h:471
LLVMValueRef
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
LLVMContext.h
LLVMCopyStringRepOfTargetData
char * LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD)
Converts target data to a target layout string.
Definition: Target.cpp:68
Value.h
InitializePasses.h
LLVMModuleRef
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
Initialization.h