comparison lib/Target/Hexagon/HexagonTargetObjectFile.cpp @ 147:c2174574ed3a

LLVM 10
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 16:55:33 +0900
parents 803732b1fca8
children 63bd29f05246
comparison
equal deleted inserted replaced
134:3a76565eade5 147:c2174574ed3a
1 //===-- HexagonTargetObjectFile.cpp ---------------------------------------===// 1 //===-- HexagonTargetObjectFile.cpp ---------------------------------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // 4 // See https://llvm.org/LICENSE.txt for license information.
5 // This file is distributed under the University of Illinois Open Source 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // License. See LICENSE.TXT for details.
7 // 6 //
8 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
9 // 8 //
10 // This file contains the declarations of the HexagonTargetAsmInfo properties. 9 // This file contains the declarations of the HexagonTargetAsmInfo properties.
11 // 10 //
72 #define TRACE(X) \ 71 #define TRACE(X) \
73 do { \ 72 do { \
74 if (TraceGVPlacement) { \ 73 if (TraceGVPlacement) { \
75 TRACE_TO(errs(), X); \ 74 TRACE_TO(errs(), X); \
76 } else { \ 75 } else { \
77 DEBUG(TRACE_TO(dbgs(), X)); \ 76 LLVM_DEBUG(TRACE_TO(dbgs(), X)); \
78 } \ 77 } \
79 } while (false) 78 } while (false)
80 #endif 79 #endif
81 80
82 // Returns true if the section name is such that the symbol will be put 81 // Returns true if the section name is such that the symbol will be put
197 196
198 /// Return true if this global value should be placed into small data/bss 197 /// Return true if this global value should be placed into small data/bss
199 /// section. 198 /// section.
200 bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO, 199 bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO,
201 const TargetMachine &TM) const { 200 const TargetMachine &TM) const {
201 bool HaveSData = isSmallDataEnabled(TM);
202 if (!HaveSData)
203 LLVM_DEBUG(dbgs() << "Small-data allocation is disabled, but symbols "
204 "may have explicit section assignments...\n");
202 // Only global variables, not functions. 205 // Only global variables, not functions.
203 DEBUG(dbgs() << "Checking if value is in small-data, -G" 206 LLVM_DEBUG(dbgs() << "Checking if value is in small-data, -G"
204 << SmallDataThreshold << ": \"" << GO->getName() << "\": "); 207 << SmallDataThreshold << ": \"" << GO->getName() << "\": ");
205 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO); 208 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO);
206 if (!GVar) { 209 if (!GVar) {
207 DEBUG(dbgs() << "no, not a global variable\n"); 210 LLVM_DEBUG(dbgs() << "no, not a global variable\n");
208 return false; 211 return false;
209 } 212 }
210 213
211 // Globals with external linkage that have an original section set must be 214 // Globals with external linkage that have an original section set must be
212 // emitted to that section, regardless of whether we would put them into 215 // emitted to that section, regardless of whether we would put them into
213 // small data or not. This is how we can support mixing -G0/-G8 in LTO. 216 // small data or not. This is how we can support mixing -G0/-G8 in LTO.
214 if (GVar->hasSection()) { 217 if (GVar->hasSection()) {
215 bool IsSmall = isSmallDataSection(GVar->getSection()); 218 bool IsSmall = isSmallDataSection(GVar->getSection());
216 DEBUG(dbgs() << (IsSmall ? "yes" : "no") << ", has section: " 219 LLVM_DEBUG(dbgs() << (IsSmall ? "yes" : "no")
217 << GVar->getSection() << '\n'); 220 << ", has section: " << GVar->getSection() << '\n');
218 return IsSmall; 221 return IsSmall;
219 } 222 }
220 223
224 // If sdata is disabled, stop the checks here.
225 if (!HaveSData) {
226 LLVM_DEBUG(dbgs() << "no, small-data allocation is disabled\n");
227 return false;
228 }
229
221 if (GVar->isConstant()) { 230 if (GVar->isConstant()) {
222 DEBUG(dbgs() << "no, is a constant\n"); 231 LLVM_DEBUG(dbgs() << "no, is a constant\n");
223 return false; 232 return false;
224 } 233 }
225 234
226 bool IsLocal = GVar->hasLocalLinkage(); 235 bool IsLocal = GVar->hasLocalLinkage();
227 if (!StaticsInSData && IsLocal) { 236 if (!StaticsInSData && IsLocal) {
228 DEBUG(dbgs() << "no, is static\n"); 237 LLVM_DEBUG(dbgs() << "no, is static\n");
229 return false; 238 return false;
230 } 239 }
231 240
232 Type *GType = GVar->getType(); 241 Type *GType = GVar->getValueType();
233 if (PointerType *PT = dyn_cast<PointerType>(GType))
234 GType = PT->getElementType();
235
236 if (isa<ArrayType>(GType)) { 242 if (isa<ArrayType>(GType)) {
237 DEBUG(dbgs() << "no, is an array\n"); 243 LLVM_DEBUG(dbgs() << "no, is an array\n");
238 return false; 244 return false;
239 } 245 }
240 246
241 // If the type is a struct with no body provided, treat is conservatively. 247 // If the type is a struct with no body provided, treat is conservatively.
242 // There cannot be actual definitions of object of such a type in this CU 248 // There cannot be actual definitions of object of such a type in this CU
243 // (only references), so assuming that they are not in sdata is safe. If 249 // (only references), so assuming that they are not in sdata is safe. If
244 // these objects end up in the sdata, the references will still be valid. 250 // these objects end up in the sdata, the references will still be valid.
245 if (StructType *ST = dyn_cast<StructType>(GType)) { 251 if (StructType *ST = dyn_cast<StructType>(GType)) {
246 if (ST->isOpaque()) { 252 if (ST->isOpaque()) {
247 DEBUG(dbgs() << "no, has opaque type\n"); 253 LLVM_DEBUG(dbgs() << "no, has opaque type\n");
248 return false; 254 return false;
249 } 255 }
250 } 256 }
251 257
252 unsigned Size = GVar->getParent()->getDataLayout().getTypeAllocSize(GType); 258 unsigned Size = GVar->getParent()->getDataLayout().getTypeAllocSize(GType);
253 if (Size == 0) { 259 if (Size == 0) {
254 DEBUG(dbgs() << "no, has size 0\n"); 260 LLVM_DEBUG(dbgs() << "no, has size 0\n");
255 return false; 261 return false;
256 } 262 }
257 if (Size > SmallDataThreshold) { 263 if (Size > SmallDataThreshold) {
258 DEBUG(dbgs() << "no, size exceeds sdata threshold: " << Size << '\n'); 264 LLVM_DEBUG(dbgs() << "no, size exceeds sdata threshold: " << Size << '\n');
259 return false; 265 return false;
260 } 266 }
261 267
262 DEBUG(dbgs() << "yes\n"); 268 LLVM_DEBUG(dbgs() << "yes\n");
263 return true; 269 return true;
264 } 270 }
265 271
266 bool HexagonTargetObjectFile::isSmallDataEnabled() const { 272 bool HexagonTargetObjectFile::isSmallDataEnabled(const TargetMachine &TM)
267 return SmallDataThreshold > 0; 273 const {
274 return SmallDataThreshold > 0 && !TM.isPositionIndependent();
268 } 275 }
269 276
270 unsigned HexagonTargetObjectFile::getSmallDataSize() const { 277 unsigned HexagonTargetObjectFile::getSmallDataSize() const {
271 return SmallDataThreshold; 278 return SmallDataThreshold;
272 } 279 }
329 return 0; 336 return 0;
330 } 337 }
331 338
332 MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal( 339 MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
333 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { 340 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
334 const Type *GTy = GO->getType()->getElementType(); 341 const Type *GTy = GO->getValueType();
335 unsigned Size = getSmallestAddressableSize(GTy, GO, TM); 342 unsigned Size = getSmallestAddressableSize(GTy, GO, TM);
336 343
337 // If we have -ffunction-section or -fdata-section then we should emit the 344 // If we have -ffunction-section or -fdata-section then we should emit the
338 // global value to a unique section specifically for it... even for sdata. 345 // global value to a unique section specifically for it... even for sdata.
339 bool EmitUniquedSection = TM.getDataSections(); 346 bool EmitUniquedSection = TM.getDataSections();