1 //===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the debug info Metadata classes.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/IR/DebugInfoMetadata.h"
15 #include "LLVMContextImpl.h"
16 #include "MetadataImpl.h"
20 MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
21 unsigned Column, ArrayRef<Metadata *> MDs)
22 : MDNode(C, MDLocationKind, Storage, MDs) {
23 assert((MDs.size() == 1 || MDs.size() == 2) &&
24 "Expected a scope and optional inlined-at");
26 // Set line and column.
27 assert(Line < (1u << 24) && "Expected 24-bit line");
28 assert(Column < (1u << 16) && "Expected 16-bit column");
30 SubclassData32 = Line;
31 SubclassData16 = Column;
34 static void adjustLine(unsigned &Line) {
35 // Set to unknown on overflow. Still use 24 bits for now.
36 if (Line >= (1u << 24))
40 static void adjustColumn(unsigned &Column) {
41 // Set to unknown on overflow. We only have 16 bits to play with here.
42 if (Column >= (1u << 16))
46 MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
47 unsigned Column, Metadata *Scope,
48 Metadata *InlinedAt, StorageType Storage,
54 if (Storage == Uniqued) {
56 getUniqued(Context.pImpl->MDLocations,
57 MDLocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
62 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
65 SmallVector<Metadata *, 2> Ops;
68 Ops.push_back(InlinedAt);
69 return storeImpl(new (Ops.size())
70 MDLocation(Context, Storage, Line, Column, Ops),
71 Storage, Context.pImpl->MDLocations);
74 GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
76 ArrayRef<Metadata *> DwarfOps,
80 if (Storage == Uniqued) {
81 GenericDebugNodeInfo::KeyTy Key(Tag, Header, DwarfOps);
82 if (auto *N = getUniqued(Context.pImpl->GenericDebugNodes, Key))
88 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
91 // Use a nullptr for empty headers.
92 Metadata *PreOps[] = {Header.empty() ? nullptr
93 : MDString::get(Context, Header)};
94 return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode(
95 Context, Storage, Hash, Tag, PreOps, DwarfOps),
96 Storage, Context.pImpl->GenericDebugNodes);
99 void GenericDebugNode::recalculateHash() {
100 setHash(GenericDebugNodeInfo::KeyTy::calculateHash(this));