| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef LLVM_CODEGEN_DIE_H |
| 14 |
#define LLVM_CODEGEN_DIE_H |
| 15 |
|
| 16 |
#include "llvm/ADT/FoldingSet.h" |
| 17 |
#include "llvm/ADT/PointerIntPair.h" |
| 18 |
#include "llvm/ADT/PointerUnion.h" |
| 19 |
#include "llvm/ADT/SmallVector.h" |
| 20 |
#include "llvm/ADT/StringRef.h" |
| 21 |
#include "llvm/ADT/iterator.h" |
| 22 |
#include "llvm/ADT/iterator_range.h" |
| 23 |
#include "llvm/BinaryFormat/Dwarf.h" |
| 24 |
#include "llvm/CodeGen/DwarfStringPoolEntry.h" |
| 25 |
#include "llvm/Support/AlignOf.h" |
| 26 |
#include "llvm/Support/Allocator.h" |
| 27 |
#include <cassert> |
| 28 |
#include <cstddef> |
| 29 |
#include <cstdint> |
| 30 |
#include <iterator> |
| 31 |
#include <new> |
| 32 |
#include <type_traits> |
| 33 |
#include <utility> |
| 34 |
#include <vector> |
| 35 |
|
| 36 |
namespace llvm { |
| 37 |
|
| 38 |
class AsmPrinter; |
| 39 |
class DIE; |
| 40 |
class DIEUnit; |
| 41 |
class DwarfCompileUnit; |
| 42 |
class MCExpr; |
| 43 |
class MCSection; |
| 44 |
class MCSymbol; |
| 45 |
class raw_ostream; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
class DIEAbbrevData { |
| 50 |
|
| 51 |
dwarf::Attribute Attribute; |
| 52 |
|
| 53 |
|
| 54 |
dwarf::Form Form; |
| 55 |
|
| 56 |
|
| 57 |
int64_t Value = 0; |
| 58 |
|
| 59 |
public: |
| 60 |
DIEAbbrevData(dwarf::Attribute A, dwarf::Form F) |
| 61 |
: Attribute(A), Form(F) {} |
| 62 |
DIEAbbrevData(dwarf::Attribute A, int64_t V) |
| 63 |
: Attribute(A), Form(dwarf::DW_FORM_implicit_const), Value(V) {} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
dwarf::Attribute getAttribute() const { return Attribute; } |
| 68 |
dwarf::Form getForm() const { return Form; } |
| 69 |
int64_t getValue() const { return Value; } |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
void Profile(FoldingSetNodeID &ID) const; |
| 74 |
}; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
class DIEAbbrev : public FoldingSetNode { |
| 80 |
|
| 81 |
unsigned Number = 0; |
| 82 |
|
| 83 |
|
| 84 |
dwarf::Tag Tag; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
bool Children; |
| 91 |
|
| 92 |
|
| 93 |
SmallVector<DIEAbbrevData, 12> Data; |
| 94 |
|
| 95 |
public: |
| 96 |
DIEAbbrev(dwarf::Tag T, bool C) : Tag(T), Children(C) {} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
dwarf::Tag getTag() const { return Tag; } |
| 101 |
unsigned getNumber() const { return Number; } |
| 102 |
bool hasChildren() const { return Children; } |
| 103 |
const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; } |
| 104 |
void setChildrenFlag(bool hasChild) { Children = hasChild; } |
| 105 |
void setNumber(unsigned N) { Number = N; } |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) { |
| 110 |
Data.push_back(DIEAbbrevData(Attribute, Form)); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value) { |
| 115 |
Data.push_back(DIEAbbrevData(Attribute, Value)); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
void Profile(FoldingSetNodeID &ID) const; |
| 120 |
|
| 121 |
|
| 122 |
void Emit(const AsmPrinter *AP) const; |
| 123 |
|
| 124 |
void print(raw_ostream &O) const; |
| 125 |
void dump() const; |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
class DIEAbbrevSet { |
| 136 |
|
| 137 |
|
| 138 |
BumpPtrAllocator &Alloc; |
| 139 |
|
| 140 |
FoldingSet<DIEAbbrev> AbbreviationsSet; |
| 141 |
|
| 142 |
std::vector<DIEAbbrev *> Abbreviations; |
| 143 |
|
| 144 |
public: |
| 145 |
DIEAbbrevSet(BumpPtrAllocator &A) : Alloc(A) {} |
| 146 |
~DIEAbbrevSet(); |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
DIEAbbrev &uniqueAbbreviation(DIE &Die); |
| 155 |
|
| 156 |
|
| 157 |
void Emit(const AsmPrinter *AP, MCSection *Section) const; |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
class DIEInteger { |
| 164 |
uint64_t Integer; |
| 165 |
|
| 166 |
public: |
| 167 |
explicit DIEInteger(uint64_t I) : Integer(I) {} |
| 168 |
|
| 169 |
|
| 170 |
static dwarf::Form BestForm(bool IsSigned, uint64_t Int) { |
| 171 |
if (IsSigned) { |
| 172 |
const int64_t SignedInt = Int; |
| 173 |
if ((char)Int == SignedInt) |
| 174 |
return dwarf::DW_FORM_data1; |
| 175 |
if ((short)Int == SignedInt) |
| 176 |
return dwarf::DW_FORM_data2; |
| 177 |
if ((int)Int == SignedInt) |
| 178 |
return dwarf::DW_FORM_data4; |
| 179 |
} else { |
| 180 |
if ((unsigned char)Int == Int) |
| 181 |
return dwarf::DW_FORM_data1; |
| 182 |
if ((unsigned short)Int == Int) |
| 183 |
return dwarf::DW_FORM_data2; |
| 184 |
if ((unsigned int)Int == Int) |
| 185 |
return dwarf::DW_FORM_data4; |
| 186 |
} |
| 187 |
return dwarf::DW_FORM_data8; |
| 188 |
} |
| 189 |
|
| 190 |
uint64_t getValue() const { return Integer; } |
| 191 |
void setValue(uint64_t Val) { Integer = Val; } |
| 192 |
|
| 193 |
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const; |
| 194 |
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const; |
| 195 |
|
| 196 |
void print(raw_ostream &O) const; |
| 197 |
}; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
class DIEExpr { |
| 202 |
const MCExpr *Expr; |
| 203 |
|
| 204 |
public: |
| 205 |
explicit DIEExpr(const MCExpr *E) : Expr(E) {} |
| 206 |
|
| 207 |
|
| 208 |
const MCExpr *getValue() const { return Expr; } |
| 209 |
|
| 210 |
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; |
| 211 |
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const; |
| 212 |
|
| 213 |
void print(raw_ostream &O) const; |
| 214 |
}; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
class DIELabel { |
| 219 |
const MCSymbol *Label; |
| 220 |
|
| 221 |
public: |
| 222 |
explicit DIELabel(const MCSymbol *L) : Label(L) {} |
| 223 |
|
| 224 |
|
| 225 |
const MCSymbol *getValue() const { return Label; } |
| 226 |
|
| 227 |
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; |
| 228 |
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const; |
| 229 |
|
| 230 |
void print(raw_ostream &O) const; |
| 231 |
}; |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
class DIEBaseTypeRef { |
| 236 |
const DwarfCompileUnit *CU; |
| 237 |
const uint64_t Index; |
| 238 |
static constexpr unsigned ULEB128PadSize = 4; |
| 239 |
|
| 240 |
public: |
| 241 |
explicit DIEBaseTypeRef(const DwarfCompileUnit *TheCU, uint64_t Idx) |
| 242 |
: CU(TheCU), Index(Idx) {} |
| 243 |
|
| 244 |
|
| 245 |
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; |
| 246 |
|
| 247 |
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const; |
| 248 |
|
| 249 |
void print(raw_ostream &O) const; |
| 250 |
uint64_t getIndex() const { return Index; } |
| 251 |
}; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
class DIEDelta { |
| 257 |
const MCSymbol *LabelHi; |
| 258 |
const MCSymbol *LabelLo; |
| 259 |
|
| 260 |
public: |
| 261 |
DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo) : LabelHi(Hi), LabelLo(Lo) {} |
| 262 |
|
| 263 |
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; |
| 264 |
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const; |
| 265 |
|
| 266 |
void print(raw_ostream &O) const; |
| 267 |
}; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
class DIEString { |
| 274 |
DwarfStringPoolEntryRef S; |
| 275 |
|
| 276 |
public: |
| 277 |
DIEString(DwarfStringPoolEntryRef S) : S(S) {} |
| 278 |
|
| 279 |
|
| 280 |
StringRef getString() const { return S.getString(); } |
| 281 |
|
| 282 |
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; |
| 283 |
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const; |
| 284 |
|
| 285 |
void print(raw_ostream &O) const; |
| 286 |
}; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
class DIEInlineString { |
| 293 |
StringRef S; |
| 294 |
|
| 295 |
public: |
| 296 |
template <typename Allocator> |
| 297 |
explicit DIEInlineString(StringRef Str, Allocator &A) : S(Str.copy(A)) {} |
| 298 |
|
| 299 |
~DIEInlineString() = default; |
| 300 |
|
| 301 |
|
| 302 |
StringRef getString() const { return S; } |
| 303 |
|
| 304 |
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; |
| 305 |
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const; |
| 306 |
|
| 307 |
void print(raw_ostream &O) const; |
| 308 |
}; |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
class DIEEntry { |
| 315 |
DIE *Entry; |
| 316 |
|
| 317 |
public: |
| 318 |
DIEEntry() = delete; |
| 319 |
explicit DIEEntry(DIE &E) : Entry(&E) {} |
| 320 |
|
| 321 |
DIE &getEntry() const { return *Entry; } |
| 322 |
|
| 323 |
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; |
| 324 |
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const; |
| 325 |
|
| 326 |
void print(raw_ostream &O) const; |
| 327 |
}; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
class DIELocList { |
| 333 |
|
| 334 |
size_t Index; |
| 335 |
|
| 336 |
public: |
| 337 |
DIELocList(size_t I) : Index(I) {} |
| 338 |
|
| 339 |
|
| 340 |
size_t getValue() const { return Index; } |
| 341 |
|
| 342 |
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; |
| 343 |
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const; |
| 344 |
|
| 345 |
void print(raw_ostream &O) const; |
| 346 |
}; |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
class DIEAddrOffset { |
| 351 |
DIEInteger Addr; |
| 352 |
DIEDelta Offset; |
| 353 |
|
| 354 |
public: |
| 355 |
explicit DIEAddrOffset(uint64_t Idx, const MCSymbol *Hi, const MCSymbol *Lo) |
| 356 |
: Addr(Idx), Offset(Hi, Lo) {} |
| 357 |
|
| 358 |
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; |
| 359 |
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const; |
| 360 |
|
| 361 |
void print(raw_ostream &O) const; |
| 362 |
}; |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
class DIEBlock; |
| 368 |
class DIELoc; |
| 369 |
class DIEValue { |
| 370 |
public: |
| 371 |
enum Type { |
| 372 |
isNone, |
| 373 |
#define HANDLE_DIEVALUE(T) is##T, |
| 374 |
#include "llvm/CodeGen/DIEValue.def" |
| 375 |
}; |
| 376 |
|
| 377 |
private: |
| 378 |
|
| 379 |
Type Ty = isNone; |
| 380 |
dwarf::Attribute Attribute = (dwarf::Attribute)0; |
| 381 |
dwarf::Form Form = (dwarf::Form)0; |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
using ValTy = |
| 388 |
AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel, |
| 389 |
DIEDelta *, DIEEntry, DIEBlock *, DIELoc *, |
| 390 |
DIELocList, DIEBaseTypeRef *, DIEAddrOffset *>; |
| 391 |
|
| 392 |
static_assert(sizeof(ValTy) <= sizeof(uint64_t) || |
| 393 |
sizeof(ValTy) <= sizeof(void *), |
| 394 |
"Expected all large types to be stored via pointer"); |
| 395 |
|
| 396 |
|
| 397 |
ValTy Val; |
| 398 |
|
| 399 |
template <class T> void construct(T V) { |
| 400 |
static_assert(std::is_standard_layout<T>::value || |
| 401 |
std::is_pointer<T>::value, |
| 402 |
"Expected standard layout or pointer"); |
| 403 |
new (reinterpret_cast<void *>(&Val)) T(V); |
| 404 |
} |
| 405 |
|
| 406 |
template <class T> T *get() { return reinterpret_cast<T *>(&Val); } |
| 407 |
template <class T> const T *get() const { |
| 408 |
return reinterpret_cast<const T *>(&Val); |
| 409 |
} |
| 410 |
template <class T> void destruct() { get<T>()->~T(); } |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
void destroyVal() { |
| 418 |
switch (Ty) { |
| 419 |
case isNone: |
| 420 |
return; |
| 421 |
#define HANDLE_DIEVALUE_SMALL(T) \ |
| 422 |
case is##T: \ |
| 423 |
destruct<DIE##T>(); \ |
| 424 |
return; |
| 425 |
#define HANDLE_DIEVALUE_LARGE(T) \ |
| 426 |
case is##T: \ |
| 427 |
destruct<const DIE##T *>(); \ |
| 428 |
return; |
| 429 |
#include "llvm/CodeGen/DIEValue.def" |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
void copyVal(const DIEValue &X) { |
| 439 |
switch (Ty) { |
| 440 |
case isNone: |
| 441 |
return; |
| 442 |
#define HANDLE_DIEVALUE_SMALL(T) \ |
| 443 |
case is##T: \ |
| 444 |
construct<DIE##T>(*X.get<DIE##T>()); \ |
| 445 |
return; |
| 446 |
#define HANDLE_DIEVALUE_LARGE(T) \ |
| 447 |
case is##T: \ |
| 448 |
construct<const DIE##T *>(*X.get<const DIE##T *>()); \ |
| 449 |
return; |
| 450 |
#include "llvm/CodeGen/DIEValue.def" |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
public: |
| 455 |
DIEValue() = default; |
| 456 |
|
| 457 |
DIEValue(const DIEValue &X) : Ty(X.Ty), Attribute(X.Attribute), Form(X.Form) { |
| 458 |
copyVal(X); |
| 459 |
} |
| 460 |
|
| 461 |
DIEValue &operator=(const DIEValue &X) { |
| 462 |
destroyVal(); |
| 463 |
Ty = X.Ty; |
| 464 |
Attribute = X.Attribute; |
| 465 |
Form = X.Form; |
| 466 |
copyVal(X); |
| 467 |
return *this; |
| 468 |
} |
| 469 |
|
| 470 |
~DIEValue() { destroyVal(); } |
| 471 |
|
| 472 |
#define HANDLE_DIEVALUE_SMALL(T) \ |
| 473 |
DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T &V) \ |
| 474 |
: Ty(is##T), Attribute(Attribute), Form(Form) { \ |
| 475 |
construct<DIE##T>(V); \ |
| 476 |
} |
| 477 |
#define HANDLE_DIEVALUE_LARGE(T) \ |
| 478 |
DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T *V) \ |
| 479 |
: Ty(is##T), Attribute(Attribute), Form(Form) { \ |
| 480 |
assert(V && "Expected valid value"); \ |
| 481 |
construct<const DIE##T *>(V); \ |
| 482 |
} |
| 483 |
#include "llvm/CodeGen/DIEValue.def" |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
Type getType() const { return Ty; } |
| 488 |
dwarf::Attribute getAttribute() const { return Attribute; } |
| 489 |
dwarf::Form getForm() const { return Form; } |
| 490 |
explicit operator bool() const { return Ty; } |
| 491 |
|
| 492 |
|
| 493 |
#define HANDLE_DIEVALUE_SMALL(T) \ |
| 494 |
const DIE##T &getDIE##T() const { \ |
| 495 |
assert(getType() == is##T && "Expected " #T); \ |
| 496 |
return *get<DIE##T>(); \ |
| 497 |
} |
| 498 |
#define HANDLE_DIEVALUE_LARGE(T) \ |
| 499 |
const DIE##T &getDIE##T() const { \ |
| 500 |
assert(getType() == is##T && "Expected " #T); \ |
| 501 |
return **get<const DIE##T *>(); \ |
| 502 |
} |
| 503 |
#include "llvm/CodeGen/DIEValue.def" |
| 504 |
|
| 505 |
|
| 506 |
void emitValue(const AsmPrinter *AP) const; |
| 507 |
|
| 508 |
|
| 509 |
unsigned sizeOf(const dwarf::FormParams &FormParams) const; |
| 510 |
|
| 511 |
void print(raw_ostream &O) const; |
| 512 |
void dump() const; |
| 513 |
}; |
| 514 |
|
| 515 |
struct IntrusiveBackListNode { |
| 516 |
PointerIntPair<IntrusiveBackListNode *, 1> Next; |
| 517 |
|
| 518 |
IntrusiveBackListNode() : Next(this, true) {} |
| 519 |
|
| 520 |
IntrusiveBackListNode *getNext() const { |
| 521 |
return Next.getInt() ? nullptr : Next.getPointer(); |
| 522 |
} |
| 523 |
}; |
| 524 |
|
| 525 |
struct IntrusiveBackListBase { |
| 526 |
using Node = IntrusiveBackListNode; |
| 527 |
|
| 528 |
Node *Last = nullptr; |
| 529 |
|
| 530 |
bool empty() const { return !Last; } |
| 531 |
|
| 532 |
void push_back(Node &N) { |
| 533 |
assert(N.Next.getPointer() == &N && "Expected unlinked node"); |
| 534 |
assert(N.Next.getInt() == true && "Expected unlinked node"); |
| 535 |
|
| 536 |
if (Last) { |
| 537 |
N.Next = Last->Next; |
| 538 |
Last->Next.setPointerAndInt(&N, false); |
| 539 |
} |
| 540 |
Last = &N; |
| 541 |
} |
| 542 |
|
| 543 |
void push_front(Node &N) { |
| 544 |
assert(N.Next.getPointer() == &N && "Expected unlinked node"); |
| 545 |
assert(N.Next.getInt() == true && "Expected unlinked node"); |
| 546 |
|
| 547 |
if (Last) { |
| 548 |
N.Next.setPointerAndInt(Last->Next.getPointer(), false); |
| 549 |
Last->Next.setPointerAndInt(&N, true); |
| 550 |
} else { |
| 551 |
Last = &N; |
| 552 |
} |
| 553 |
} |
| 554 |
}; |
| 555 |
|
| 556 |
template <class T> class IntrusiveBackList : IntrusiveBackListBase { |
| 557 |
public: |
| 558 |
using IntrusiveBackListBase::empty; |
| 559 |
|
| 560 |
void push_back(T &N) { IntrusiveBackListBase::push_back(N); } |
| 561 |
void push_front(T &N) { IntrusiveBackListBase::push_front(N); } |
| 562 |
T &back() { return *static_cast<T *>(Last); } |
| 563 |
const T &back() const { return *static_cast<T *>(Last); } |
| 564 |
T &front() { |
| 565 |
return *static_cast<T *>(Last ? Last->Next.getPointer() : nullptr); |
| 566 |
} |
| 567 |
const T &front() const { |
| 568 |
return *static_cast<T *>(Last ? Last->Next.getPointer() : nullptr); |
| 569 |
} |
| 570 |
|
| 571 |
void takeNodes(IntrusiveBackList<T> &Other) { |
| 572 |
if (Other.empty()) |
| 573 |
return; |
| 574 |
|
| 575 |
T *FirstNode = static_cast<T *>(Other.Last->Next.getPointer()); |
| 576 |
T *IterNode = FirstNode; |
| 577 |
do { |
| 578 |
|
| 579 |
T *TmpNode = IterNode; |
| 580 |
IterNode = static_cast<T *>(IterNode->Next.getPointer()); |
| 581 |
|
| 582 |
|
| 583 |
TmpNode->Next.setPointerAndInt(TmpNode, true); |
| 584 |
push_back(*TmpNode); |
| 585 |
} while (IterNode != FirstNode); |
| 586 |
|
| 587 |
Other.Last = nullptr; |
| 588 |
} |
| 589 |
|
| 590 |
class const_iterator; |
| 591 |
class iterator |
| 592 |
: public iterator_facade_base<iterator, std::forward_iterator_tag, T> { |
| 593 |
friend class const_iterator; |
| 594 |
|
| 595 |
Node *N = nullptr; |
| 596 |
|
| 597 |
public: |
| 598 |
iterator() = default; |
| 599 |
explicit iterator(T *N) : N(N) {} |
| 600 |
|
| 601 |
iterator &operator++() { |
| 602 |
N = N->getNext(); |
| 603 |
return *this; |
| 604 |
} |
| 605 |
|
| 606 |
explicit operator bool() const { return N; } |
| 607 |
T &operator*() const { return *static_cast<T *>(N); } |
| 608 |
|
| 609 |
bool operator==(const iterator &X) const { return N == X.N; } |
| 610 |
}; |
| 611 |
|
| 612 |
class const_iterator |
| 613 |
: public iterator_facade_base<const_iterator, std::forward_iterator_tag, |
| 614 |
const T> { |
| 615 |
const Node *N = nullptr; |
| 616 |
|
| 617 |
public: |
| 618 |
const_iterator() = default; |
| 619 |
|
| 620 |
const_iterator(typename IntrusiveBackList<T>::iterator X) : N(X.N) {} |
| 621 |
explicit const_iterator(const T *N) : N(N) {} |
| 622 |
|
| 623 |
const_iterator &operator++() { |
| 624 |
N = N->getNext(); |
| 625 |
return *this; |
| 626 |
} |
| 627 |
|
| 628 |
explicit operator bool() const { return N; } |
| 629 |
const T &operator*() const { return *static_cast<const T *>(N); } |
| 630 |
|
| 631 |
bool operator==(const const_iterator &X) const { return N == X.N; } |
| 632 |
}; |
| 633 |
|
| 634 |
iterator begin() { |
| 635 |
return Last ? iterator(static_cast<T *>(Last->Next.getPointer())) : end(); |
| 636 |
} |
| 637 |
const_iterator begin() const { |
| 638 |
return const_cast<IntrusiveBackList *>(this)->begin(); |
| 639 |
} |
| 640 |
iterator end() { return iterator(); } |
| 641 |
const_iterator end() const { return const_iterator(); } |
| 642 |
|
| 643 |
static iterator toIterator(T &N) { return iterator(&N); } |
| 644 |
static const_iterator toIterator(const T &N) { return const_iterator(&N); } |
| 645 |
}; |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
class DIEValueList { |
| 663 |
struct Node : IntrusiveBackListNode { |
| 664 |
DIEValue V; |
| 665 |
|
| 666 |
explicit Node(DIEValue V) : V(V) {} |
| 667 |
}; |
| 668 |
|
| 669 |
using ListTy = IntrusiveBackList<Node>; |
| 670 |
|
| 671 |
ListTy List; |
| 672 |
|
| 673 |
public: |
| 674 |
class const_value_iterator; |
| 675 |
class value_iterator |
| 676 |
: public iterator_adaptor_base<value_iterator, ListTy::iterator, |
| 677 |
std::forward_iterator_tag, DIEValue> { |
| 678 |
friend class const_value_iterator; |
| 679 |
|
| 680 |
using iterator_adaptor = |
| 681 |
iterator_adaptor_base<value_iterator, ListTy::iterator, |
| 682 |
std::forward_iterator_tag, DIEValue>; |
| 683 |
|
| 684 |
public: |
| 685 |
value_iterator() = default; |
| 686 |
explicit value_iterator(ListTy::iterator X) : iterator_adaptor(X) {} |
| 687 |
|
| 688 |
explicit operator bool() const { return bool(wrapped()); } |
| 689 |
DIEValue &operator*() const { return wrapped()->V; } |
| 690 |
}; |
| 691 |
|
| 692 |
class const_value_iterator : public iterator_adaptor_base< |
| 693 |
const_value_iterator, ListTy::const_iterator, |
| 694 |
std::forward_iterator_tag, const DIEValue> { |
| 695 |
using iterator_adaptor = |
| 696 |
iterator_adaptor_base<const_value_iterator, ListTy::const_iterator, |
| 697 |
std::forward_iterator_tag, const DIEValue>; |
| 698 |
|
| 699 |
public: |
| 700 |
const_value_iterator() = default; |
| 701 |
const_value_iterator(DIEValueList::value_iterator X) |
| 702 |
: iterator_adaptor(X.wrapped()) {} |
| 703 |
explicit const_value_iterator(ListTy::const_iterator X) |
| 704 |
: iterator_adaptor(X) {} |
| 705 |
|
| 706 |
explicit operator bool() const { return bool(wrapped()); } |
| 707 |
const DIEValue &operator*() const { return wrapped()->V; } |
| 708 |
}; |
| 709 |
|
| 710 |
using value_range = iterator_range<value_iterator>; |
| 711 |
using const_value_range = iterator_range<const_value_iterator>; |
| 712 |
|
| 713 |
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V) { |
| 714 |
List.push_back(*new (Alloc) Node(V)); |
| 715 |
return value_iterator(ListTy::toIterator(List.back())); |
| 716 |
} |
| 717 |
template <class T> |
| 718 |
value_iterator addValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute, |
| 719 |
dwarf::Form Form, T &&Value) { |
| 720 |
return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value))); |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
void takeValues(DIEValueList &Other) { List.takeNodes(Other.List); } |
| 726 |
|
| 727 |
value_range values() { |
| 728 |
return make_range(value_iterator(List.begin()), value_iterator(List.end())); |
| 729 |
} |
| 730 |
const_value_range values() const { |
| 731 |
return make_range(const_value_iterator(List.begin()), |
| 732 |
const_value_iterator(List.end())); |
| 733 |
} |
| 734 |
}; |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
class DIE : IntrusiveBackListNode, public DIEValueList { |
| 740 |
friend class IntrusiveBackList<DIE>; |
| 741 |
friend class DIEUnit; |
| 742 |
|
| 743 |
|
| 744 |
unsigned Offset = 0; |
| 745 |
|
| 746 |
unsigned Size = 0; |
| 747 |
unsigned AbbrevNumber = ~0u; |
| 748 |
|
| 749 |
dwarf::Tag Tag = (dwarf::Tag)0; |
| 750 |
|
| 751 |
|
| 752 |
bool ForceChildren = false; |
| 753 |
|
| 754 |
IntrusiveBackList<DIE> Children; |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
PointerUnion<DIE *, DIEUnit *> Owner; |
| 759 |
|
| 760 |
explicit DIE(dwarf::Tag Tag) : Tag(Tag) {} |
| 761 |
|
| 762 |
public: |
| 763 |
DIE() = delete; |
| 764 |
DIE(const DIE &RHS) = delete; |
| 765 |
DIE(DIE &&RHS) = delete; |
| 766 |
DIE &operator=(const DIE &RHS) = delete; |
| 767 |
DIE &operator=(const DIE &&RHS) = delete; |
| 768 |
|
| 769 |
static DIE *get(BumpPtrAllocator &Alloc, dwarf::Tag Tag) { |
| 770 |
return new (Alloc) DIE(Tag); |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
unsigned getAbbrevNumber() const { return AbbrevNumber; } |
| 775 |
dwarf::Tag getTag() const { return Tag; } |
| 776 |
|
| 777 |
unsigned getOffset() const { |
| 778 |
|
| 779 |
assert(Offset && "Offset being queried before it's been computed."); |
| 780 |
return Offset; |
| 781 |
} |
| 782 |
unsigned getSize() const { |
| 783 |
|
| 784 |
assert(Size && "Size being queried before it's been ocmputed."); |
| 785 |
return Size; |
| 786 |
} |
| 787 |
bool hasChildren() const { return ForceChildren || !Children.empty(); } |
| 788 |
void setForceChildren(bool B) { ForceChildren = B; } |
| 789 |
|
| 790 |
using child_iterator = IntrusiveBackList<DIE>::iterator; |
| 791 |
using const_child_iterator = IntrusiveBackList<DIE>::const_iterator; |
| 792 |
using child_range = iterator_range<child_iterator>; |
| 793 |
using const_child_range = iterator_range<const_child_iterator>; |
| 794 |
|
| 795 |
child_range children() { |
| 796 |
return make_range(Children.begin(), Children.end()); |
| 797 |
} |
| 798 |
const_child_range children() const { |
| 799 |
return make_range(Children.begin(), Children.end()); |
| 800 |
} |
| 801 |
|
| 802 |
DIE *getParent() const; |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
DIEAbbrev generateAbbrev() const; |
| 809 |
|
| 810 |
|
| 811 |
void setAbbrevNumber(unsigned I) { AbbrevNumber = I; } |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
uint64_t getDebugSectionOffset() const; |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
unsigned computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams, |
| 834 |
DIEAbbrevSet &AbbrevSet, unsigned CUOffset); |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
const DIE *getUnitDie() const; |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
DIEUnit *getUnit() const; |
| 849 |
|
| 850 |
void setOffset(unsigned O) { Offset = O; } |
| 851 |
void setSize(unsigned S) { Size = S; } |
| 852 |
|
| 853 |
|
| 854 |
DIE &addChild(DIE *Child) { |
| 855 |
assert(!Child->getParent() && "Child should be orphaned"); |
| 856 |
Child->Owner = this; |
| 857 |
Children.push_back(*Child); |
| 858 |
return Children.back(); |
| 859 |
} |
| 860 |
|
| 861 |
DIE &addChildFront(DIE *Child) { |
| 862 |
assert(!Child->getParent() && "Child should be orphaned"); |
| 863 |
Child->Owner = this; |
| 864 |
Children.push_front(*Child); |
| 865 |
return Children.front(); |
| 866 |
} |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
DIEValue findAttribute(dwarf::Attribute Attribute) const; |
| 873 |
|
| 874 |
void print(raw_ostream &O, unsigned IndentCount = 0) const; |
| 875 |
void dump() const; |
| 876 |
}; |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
class DIEUnit { |
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
DIE Die; |
| 887 |
|
| 888 |
|
| 889 |
MCSection *Section = nullptr; |
| 890 |
uint64_t Offset = 0; |
| 891 |
protected: |
| 892 |
virtual ~DIEUnit() = default; |
| 893 |
|
| 894 |
public: |
| 895 |
explicit DIEUnit(dwarf::Tag UnitTag); |
| 896 |
DIEUnit(const DIEUnit &RHS) = delete; |
| 897 |
DIEUnit(DIEUnit &&RHS) = delete; |
| 898 |
void operator=(const DIEUnit &RHS) = delete; |
| 899 |
void operator=(const DIEUnit &&RHS) = delete; |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
void setSection(MCSection *Section) { |
| 905 |
assert(!this->Section); |
| 906 |
this->Section = Section; |
| 907 |
} |
| 908 |
|
| 909 |
virtual const MCSymbol *getCrossSectionRelativeBaseAddress() const { |
| 910 |
return nullptr; |
| 911 |
} |
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
MCSection *getSection() const { return Section; } |
| 917 |
void setDebugSectionOffset(uint64_t O) { Offset = O; } |
| 918 |
uint64_t getDebugSectionOffset() const { return Offset; } |
| 919 |
DIE &getUnitDie() { return Die; } |
| 920 |
const DIE &getUnitDie() const { return Die; } |
| 921 |
}; |
| 922 |
|
| 923 |
struct BasicDIEUnit final : DIEUnit { |
| 924 |
explicit BasicDIEUnit(dwarf::Tag UnitTag) : DIEUnit(UnitTag) {} |
| 925 |
}; |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
class DIELoc : public DIEValueList { |
| 931 |
mutable unsigned Size = 0; |
| 932 |
|
| 933 |
public: |
| 934 |
DIELoc() = default; |
| 935 |
|
| 936 |
|
| 937 |
unsigned computeSize(const dwarf::FormParams &FormParams) const; |
| 938 |
|
| 939 |
|
| 940 |
void setSize(unsigned size) { Size = size; } |
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
dwarf::Form BestForm(unsigned DwarfVersion) const { |
| 945 |
if (DwarfVersion > 3) |
| 946 |
return dwarf::DW_FORM_exprloc; |
| 947 |
|
| 948 |
if ((unsigned char)Size == Size) |
| 949 |
return dwarf::DW_FORM_block1; |
| 950 |
if ((unsigned short)Size == Size) |
| 951 |
return dwarf::DW_FORM_block2; |
| 952 |
if ((unsigned int)Size == Size) |
| 953 |
return dwarf::DW_FORM_block4; |
| 954 |
return dwarf::DW_FORM_block; |
| 955 |
} |
| 956 |
|
| 957 |
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const; |
| 958 |
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const; |
| 959 |
|
| 960 |
void print(raw_ostream &O) const; |
| 961 |
}; |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
class DIEBlock : public DIEValueList { |
| 967 |
mutable unsigned Size = 0; |
| 968 |
|
| 969 |
public: |
| 970 |
DIEBlock() = default; |
| 971 |
|
| 972 |
|
| 973 |
unsigned computeSize(const dwarf::FormParams &FormParams) const; |
| 974 |
|
| 975 |
|
| 976 |
void setSize(unsigned size) { Size = size; } |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
dwarf::Form BestForm() const { |
| 981 |
if ((unsigned char)Size == Size) |
| 982 |
return dwarf::DW_FORM_block1; |
| 983 |
if ((unsigned short)Size == Size) |
| 984 |
return dwarf::DW_FORM_block2; |
| 985 |
if ((unsigned int)Size == Size) |
| 986 |
return dwarf::DW_FORM_block4; |
| 987 |
return dwarf::DW_FORM_block; |
| 988 |
} |
| 989 |
|
| 990 |
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const; |
| 991 |
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const; |
| 992 |
|
| 993 |
void print(raw_ostream &O) const; |
| 994 |
}; |
| 995 |
|
| 996 |
} |
| 997 |
|
| 998 |
#endif |