blob: abeba62707c1d87221143cdaf90812a242b788a8 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- llvm/CodeGen/DwarfStringPoolEntry.h - String pool entry --*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
10#define LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
11
Andrew Scullcdfcccc2018-10-05 20:58:37 +010012#include "llvm/ADT/PointerIntPair.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010013#include "llvm/ADT/StringMap.h"
14
15namespace llvm {
16
17class MCSymbol;
18
19/// Data for a string pool entry.
20struct DwarfStringPoolEntry {
Andrew Scullcdfcccc2018-10-05 20:58:37 +010021 static constexpr unsigned NotIndexed = -1;
22
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010023 MCSymbol *Symbol;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020024 uint64_t Offset;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010025 unsigned Index;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010026
27 bool isIndexed() const { return Index != NotIndexed; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010028};
29
30/// String pool entry reference.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010031class DwarfStringPoolEntryRef {
32 PointerIntPair<const StringMapEntry<DwarfStringPoolEntry> *, 1, bool>
33 MapEntryAndIndexed;
34
35 const StringMapEntry<DwarfStringPoolEntry> *getMapEntry() const {
36 return MapEntryAndIndexed.getPointer();
37 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010038
39public:
40 DwarfStringPoolEntryRef() = default;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010041 DwarfStringPoolEntryRef(const StringMapEntry<DwarfStringPoolEntry> &Entry,
42 bool Indexed)
43 : MapEntryAndIndexed(&Entry, Indexed) {}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010044
Andrew Scullcdfcccc2018-10-05 20:58:37 +010045 explicit operator bool() const { return getMapEntry(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010046 MCSymbol *getSymbol() const {
Andrew Scullcdfcccc2018-10-05 20:58:37 +010047 assert(getMapEntry()->second.Symbol && "No symbol available!");
48 return getMapEntry()->second.Symbol;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010049 }
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020050 uint64_t getOffset() const { return getMapEntry()->second.Offset; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010051 bool isIndexed() const { return MapEntryAndIndexed.getInt(); }
52 unsigned getIndex() const {
53 assert(isIndexed());
54 assert(getMapEntry()->getValue().isIndexed());
55 return getMapEntry()->second.Index;
56 }
57 StringRef getString() const { return getMapEntry()->first(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010058 /// Return the entire string pool entry for convenience.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010059 DwarfStringPoolEntry getEntry() const { return getMapEntry()->getValue(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010060
Andrew Scullcdfcccc2018-10-05 20:58:37 +010061 bool operator==(const DwarfStringPoolEntryRef &X) const {
62 return getMapEntry() == X.getMapEntry();
63 }
64 bool operator!=(const DwarfStringPoolEntryRef &X) const {
65 return getMapEntry() != X.getMapEntry();
66 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010067};
68
69} // end namespace llvm
70
71#endif