/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/Target.cpp
Line | Count | Source (jump to first uncovered line) |
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" |
16 | | #include "llvm/Analysis/TargetLibraryInfo.h" |
17 | | #include "llvm/IR/DataLayout.h" |
18 | | #include "llvm/IR/LLVMContext.h" |
19 | | #include "llvm/IR/LegacyPassManager.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 | | |
29 | 0 | inline TargetLibraryInfoImpl *unwrap(LLVMTargetLibraryInfoRef P) { |
30 | 0 | return reinterpret_cast<TargetLibraryInfoImpl*>(P); |
31 | 0 | } |
32 | | |
33 | 0 | inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfoImpl *P) { |
34 | 0 | TargetLibraryInfoImpl *X = const_cast<TargetLibraryInfoImpl*>(P); |
35 | 0 | return reinterpret_cast<LLVMTargetLibraryInfoRef>(X); |
36 | 0 | } |
37 | | |
38 | 11.0k | void llvm::initializeTarget(PassRegistry &Registry) { |
39 | 11.0k | initializeTargetLibraryInfoWrapperPassPass(Registry); |
40 | 11.0k | initializeTargetTransformInfoWrapperPassPass(Registry); |
41 | 11.0k | } |
42 | | |
43 | 0 | void LLVMInitializeTarget(LLVMPassRegistryRef R) { |
44 | 0 | initializeTarget(*unwrap(R)); |
45 | 0 | } |
46 | | |
47 | 5 | LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M) { |
48 | 5 | return wrap(&unwrap(M)->getDataLayout()); |
49 | 5 | } |
50 | | |
51 | 5 | void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL) { |
52 | 5 | unwrap(M)->setDataLayout(*unwrap(DL)); |
53 | 5 | } |
54 | | |
55 | 0 | LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) { |
56 | 0 | return wrap(new DataLayout(StringRep)); |
57 | 0 | } |
58 | | |
59 | 0 | void LLVMDisposeTargetData(LLVMTargetDataRef TD) { |
60 | 0 | delete unwrap(TD); |
61 | 0 | } |
62 | | |
63 | | void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI, |
64 | 0 | LLVMPassManagerRef PM) { |
65 | 0 | unwrap(PM)->add(new TargetLibraryInfoWrapperPass(*unwrap(TLI))); |
66 | 0 | } |
67 | | |
68 | 0 | char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD) { |
69 | 0 | std::string StringRep = unwrap(TD)->getStringRepresentation(); |
70 | 0 | return strdup(StringRep.c_str()); |
71 | 0 | } |
72 | | |
73 | 0 | LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD) { |
74 | 0 | return unwrap(TD)->isLittleEndian() ? LLVMLittleEndian : LLVMBigEndian; |
75 | 0 | } |
76 | | |
77 | 0 | unsigned LLVMPointerSize(LLVMTargetDataRef TD) { |
78 | 0 | return unwrap(TD)->getPointerSize(0); |
79 | 0 | } |
80 | | |
81 | 0 | unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS) { |
82 | 0 | return unwrap(TD)->getPointerSize(AS); |
83 | 0 | } |
84 | | |
85 | 0 | LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) { |
86 | 0 | return wrap(unwrap(TD)->getIntPtrType(*unwrap(LLVMGetGlobalContext()))); |
87 | 0 | } |
88 | | |
89 | 0 | LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS) { |
90 | 0 | return wrap(unwrap(TD)->getIntPtrType(*unwrap(LLVMGetGlobalContext()), AS)); |
91 | 0 | } |
92 | | |
93 | 0 | LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD) { |
94 | 0 | return wrap(unwrap(TD)->getIntPtrType(*unwrap(C))); |
95 | 0 | } |
96 | | |
97 | 0 | LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD, unsigned AS) { |
98 | 0 | return wrap(unwrap(TD)->getIntPtrType(*unwrap(C), AS)); |
99 | 0 | } |
100 | | |
101 | 0 | unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty) { |
102 | 0 | return unwrap(TD)->getTypeSizeInBits(unwrap(Ty)); |
103 | 0 | } |
104 | | |
105 | 0 | unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { |
106 | 0 | return unwrap(TD)->getTypeStoreSize(unwrap(Ty)); |
107 | 0 | } |
108 | | |
109 | 0 | unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { |
110 | 0 | return unwrap(TD)->getTypeAllocSize(unwrap(Ty)); |
111 | 0 | } |
112 | | |
113 | 0 | unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { |
114 | 0 | return unwrap(TD)->getABITypeAlignment(unwrap(Ty)); |
115 | 0 | } |
116 | | |
117 | 0 | unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { |
118 | 0 | return unwrap(TD)->getABITypeAlignment(unwrap(Ty)); |
119 | 0 | } |
120 | | |
121 | 0 | unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) { |
122 | 0 | return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty)); |
123 | 0 | } |
124 | | |
125 | | unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD, |
126 | 0 | LLVMValueRef GlobalVar) { |
127 | 0 | return unwrap(TD)->getPreferredAlignment(unwrap<GlobalVariable>(GlobalVar)); |
128 | 0 | } |
129 | | |
130 | | unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy, |
131 | 0 | unsigned long long Offset) { |
132 | 0 | StructType *STy = unwrap<StructType>(StructTy); |
133 | 0 | return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset); |
134 | 0 | } |
135 | | |
136 | | unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy, |
137 | 0 | unsigned Element) { |
138 | 0 | StructType *STy = unwrap<StructType>(StructTy); |
139 | 0 | return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element); |
140 | 0 | } |