LLVM 24.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/Module.h"
20#include "llvm/IR/Value.h"
22
23using namespace llvm;
24
26 return reinterpret_cast<TargetLibraryInfoImpl*>(P);
27}
28
31 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
32}
33
39
41 return wrap(&unwrap(M)->getDataLayout());
42}
43
47
49 return wrap(new DataLayout(StringRep));
50}
51
53 delete unwrap(TD);
54}
55
60
62 std::string StringRep = unwrap(TD)->getStringRepresentation();
63 return strdup(StringRep.c_str());
64}
65
69
71 return unwrap(TD)->getPointerSize(0);
72}
73
74unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS) {
75 return unwrap(TD)->getPointerSize(AS);
76}
77
81
83 return wrap(
84 unwrap(TD)->getIntPtrType(*unwrap(getGlobalContextForCAPI()), AS));
85}
86
90
92 return wrap(unwrap(TD)->getIntPtrType(*unwrap(C), AS));
93}
94
96 return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
97}
98
100 return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
101}
102
104 return unwrap(TD)->getTypeAllocSize(unwrap(Ty));
105}
106
108 return unwrap(TD)->getABITypeAlign(unwrap(Ty)).value();
109}
110
112 return unwrap(TD)->getABITypeAlign(unwrap(Ty)).value();
113}
114
116 return unwrap(TD)->getPrefTypeAlign(unwrap(Ty)).value();
117}
118
120 LLVMValueRef GlobalVar) {
121 return unwrap(TD)
122 ->getPreferredAlign(unwrap<GlobalVariable>(GlobalVar))
123 .value();
124}
125
127 unsigned long long Offset) {
128 StructType *STy = unwrap<StructType>(StructTy);
129 return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
130}
131
132unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
133 unsigned Element) {
134 StructType *STy = unwrap<StructType>(StructTy);
135 return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
136}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
Module.h This file contains the declarations for the Module class.
#define P(N)
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD)
Definition Target.cpp:78
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS)
Definition Target.cpp:82
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition Registry.h:116
Class to represent struct types.
Implementation of the target library information.
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
LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M)
Obtain the data layout for a module.
Definition Target.cpp:40
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep)
Creates target data from a target layout string.
Definition Target.cpp:48
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the preferred alignment of a type in bytes for a target.
Definition Target.cpp:115
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the call frame alignment of a type in bytes for a target.
Definition Target.cpp:111
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:132
void LLVMDisposeTargetData(LLVMTargetDataRef TD)
Deallocates a TargetData.
Definition Target.cpp:52
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI, LLVMPassManagerRef PM)
Adds target library information to a pass manager.
Definition Target.cpp:56
LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD)
Returns the byte order of a target, either LLVMBigEndian or LLVMLittleEndian.
Definition Target.cpp:66
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD, LLVMValueRef GlobalVar)
Computes the preferred alignment of a global variable in bytes for a target.
Definition Target.cpp:119
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the storage size of a type in bytes for a target.
Definition Target.cpp:99
LLVMByteOrdering
Definition Target.h:37
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI size of a type in bytes for a target.
Definition Target.cpp:103
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the pointer size in bytes for a target for a specified address space.
Definition Target.cpp:74
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI alignment of a type in bytes for a target.
Definition Target.cpp:107
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:126
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition Target.cpp:87
char * LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD)
Converts target data to a target layout string.
Definition Target.cpp:61
unsigned LLVMPointerSize(LLVMTargetDataRef TD)
Returns the pointer size in bytes for a target.
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:91
struct LLVMOpaqueTargetLibraryInfotData * LLVMTargetLibraryInfoRef
Definition Target.h:40
void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL)
Set the data layout for a module.
Definition Target.cpp:44
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the size of a type in bits for a target.
Definition Target.cpp:95
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition Target.h:39
@ LLVMBigEndian
Definition Target.h:37
@ LLVMLittleEndian
Definition Target.h:37
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
LLVM_ABI LLVMContextRef getGlobalContextForCAPI()
Get the deprecated global context for use by the C API.
Definition Core.cpp:100
LLVM_ABI void initializeRuntimeLibraryInfoWrapperPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition Attributes.h:397
LLVM_ABI void initializeTarget(PassRegistry &)
Initialize all passes linked into the CodeGen library.
Definition Target.cpp:34
LLVM_ABI void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
LLVMAttributeRef wrap(Attribute Attr)
Definition Attributes.h:392