diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-02-02 18:53:21 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-02-02 18:53:21 +0000 |
commit | d9901ff5867073cab6c1b2f8ed0702c28dcbbcc1 (patch) | |
tree | d07beb52f89e46427f097cb2bae935dc7d18d639 /llvm/lib/IR/DebugInfoMetadata.cpp | |
parent | 241a9e8db20cd750d34073c549d65f0d07463dbd (diff) | |
download | bcm5719-llvm-d9901ff5867073cab6c1b2f8ed0702c28dcbbcc1.tar.gz bcm5719-llvm-d9901ff5867073cab6c1b2f8ed0702c28dcbbcc1.zip |
IR: Split out DebugInfoMetadata.h, NFC
Move debug-info-centred `Metadata` subclasses into their own
header/source file. A couple of private template functions are needed
from both `Metadata.cpp` and `DebugInfoMetadata.cpp`, so I've moved them
to `lib/IR/MetadataImpl.h`.
llvm-svn: 227835
Diffstat (limited to 'llvm/lib/IR/DebugInfoMetadata.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfoMetadata.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp new file mode 100644 index 00000000000..9daf7857ba6 --- /dev/null +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -0,0 +1,101 @@ +//===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the debug info Metadata classes. +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/DebugInfoMetadata.h" +#include "LLVMContextImpl.h" +#include "MetadataImpl.h" + +using namespace llvm; + +MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line, + unsigned Column, ArrayRef<Metadata *> MDs) + : MDNode(C, MDLocationKind, Storage, MDs) { + assert((MDs.size() == 1 || MDs.size() == 2) && + "Expected a scope and optional inlined-at"); + + // Set line and column. + assert(Line < (1u << 24) && "Expected 24-bit line"); + assert(Column < (1u << 16) && "Expected 16-bit column"); + + SubclassData32 = Line; + SubclassData16 = Column; +} + +static void adjustLine(unsigned &Line) { + // Set to unknown on overflow. Still use 24 bits for now. + if (Line >= (1u << 24)) + Line = 0; +} + +static void adjustColumn(unsigned &Column) { + // Set to unknown on overflow. We only have 16 bits to play with here. + if (Column >= (1u << 16)) + Column = 0; +} + +MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line, + unsigned Column, Metadata *Scope, + Metadata *InlinedAt, StorageType Storage, + bool ShouldCreate) { + // Fixup line/column. + adjustLine(Line); + adjustColumn(Column); + + if (Storage == Uniqued) { + if (auto *N = + getUniqued(Context.pImpl->MDLocations, + MDLocationInfo::KeyTy(Line, Column, Scope, InlinedAt))) + return N; + if (!ShouldCreate) + return nullptr; + } else { + assert(ShouldCreate && "Expected non-uniqued nodes to always be created"); + } + + SmallVector<Metadata *, 2> Ops; + Ops.push_back(Scope); + if (InlinedAt) + Ops.push_back(InlinedAt); + return storeImpl(new (Ops.size()) + MDLocation(Context, Storage, Line, Column, Ops), + Storage, Context.pImpl->MDLocations); +} + +GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag, + StringRef Header, + ArrayRef<Metadata *> DwarfOps, + StorageType Storage, + bool ShouldCreate) { + unsigned Hash = 0; + if (Storage == Uniqued) { + GenericDebugNodeInfo::KeyTy Key(Tag, Header, DwarfOps); + if (auto *N = getUniqued(Context.pImpl->GenericDebugNodes, Key)) + return N; + if (!ShouldCreate) + return nullptr; + Hash = Key.getHash(); + } else { + assert(ShouldCreate && "Expected non-uniqued nodes to always be created"); + } + + // Use a nullptr for empty headers. + Metadata *PreOps[] = {Header.empty() ? nullptr + : MDString::get(Context, Header)}; + return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode( + Context, Storage, Hash, Tag, PreOps, DwarfOps), + Storage, Context.pImpl->GenericDebugNodes); +} + +void GenericDebugNode::recalculateHash() { + setHash(GenericDebugNodeInfo::KeyTy::calculateHash(this)); +} |