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