Recognize strings for Hexagon-specific variant kinds
[oota-llvm.git] / lib / IR / DebugInfoMetadata.cpp
index ed6206264b0966a4025165fa0c0f6f3f493cfa11..58e0abdd577c077ee10b39b713b7b49fd0643c9f 100644 (file)
@@ -19,9 +19,9 @@
 
 using namespace llvm;
 
-MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
+DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
                        unsigned Column, ArrayRef<Metadata *> MDs)
-    : MDNode(C, MDLocationKind, Storage, MDs) {
+    : MDNode(C, DILocationKind, Storage, MDs) {
   assert((MDs.size() == 1 || MDs.size() == 2) &&
          "Expected a scope and optional inlined-at");
 
@@ -38,7 +38,7 @@ static void adjustColumn(unsigned &Column) {
     Column = 0;
 }
 
-MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
+DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
                                 unsigned Column, Metadata *Scope,
                                 Metadata *InlinedAt, StorageType Storage,
                                 bool ShouldCreate) {
@@ -48,8 +48,8 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
   assert(Scope && "Expected scope");
   if (Storage == Uniqued) {
     if (auto *N =
-            getUniqued(Context.pImpl->MDLocations,
-                       MDLocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
+            getUniqued(Context.pImpl->DILocations,
+                       DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
       return N;
     if (!ShouldCreate)
       return nullptr;
@@ -62,18 +62,35 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
   if (InlinedAt)
     Ops.push_back(InlinedAt);
   return storeImpl(new (Ops.size())
-                       MDLocation(Context, Storage, Line, Column, Ops),
-                   Storage, Context.pImpl->MDLocations);
+                       DILocation(Context, Storage, Line, Column, Ops),
+                   Storage, Context.pImpl->DILocations);
 }
 
-unsigned DebugNode::getFlag(StringRef Flag) {
+unsigned DILocation::computeNewDiscriminator() const {
+  // FIXME: This seems completely wrong.
+  //
+  //  1. If two modules are generated in the same context, then the second
+  //     Module will get different discriminators than it would have if it were
+  //     generated in its own context.
+  //  2. If this function is called after round-tripping to bitcode instead of
+  //     before, it will give a different (and potentially incorrect!) return.
+  //
+  // The discriminator should instead be calculated from local information
+  // where it's actually needed.  This logic should be moved to
+  // AddDiscriminators::runOnFunction(), where it doesn't pollute the
+  // LLVMContext.
+  std::pair<const char *, unsigned> Key(getFilename().data(), getLine());
+  return ++getContext().pImpl->DiscriminatorTable[Key];
+}
+
+unsigned DINode::getFlag(StringRef Flag) {
   return StringSwitch<unsigned>(Flag)
 #define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
 #include "llvm/IR/DebugInfoFlags.def"
       .Default(0);
 }
 
-const char *DebugNode::getFlagString(unsigned Flag) {
+const char *DINode::getFlagString(unsigned Flag) {
   switch (Flag) {
   default:
     return "";
@@ -84,8 +101,8 @@ const char *DebugNode::getFlagString(unsigned Flag) {
   }
 }
 
-unsigned DebugNode::splitFlags(unsigned Flags,
-                               SmallVectorImpl<unsigned> &SplitFlags) {
+unsigned DINode::splitFlags(unsigned Flags,
+                            SmallVectorImpl<unsigned> &SplitFlags) {
   // Accessibility flags need to be specially handled, since they're packed
   // together.
   if (unsigned A = Flags & FlagAccessibility) {
@@ -108,33 +125,38 @@ unsigned DebugNode::splitFlags(unsigned Flags,
   return Flags;
 }
 
-MDScopeRef MDScope::getScope() const {
-  if (auto *T = dyn_cast<MDType>(this))
+DIScopeRef DIScope::getScope() const {
+  if (auto *T = dyn_cast<DIType>(this))
     return T->getScope();
 
-  if (auto *SP = dyn_cast<MDSubprogram>(this))
+  if (auto *SP = dyn_cast<DISubprogram>(this))
     return SP->getScope();
 
-  if (auto *LB = dyn_cast<MDLexicalBlockBase>(this))
-    return MDScopeRef(LB->getScope());
+  if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
+    return DIScopeRef(LB->getScope());
 
-  if (auto *NS = dyn_cast<MDNamespace>(this))
-    return MDScopeRef(NS->getScope());
+  if (auto *NS = dyn_cast<DINamespace>(this))
+    return DIScopeRef(NS->getScope());
 
-  assert((isa<MDFile>(this) || isa<MDCompileUnit>(this)) &&
+  if (auto *M = dyn_cast<DIModule>(this))
+    return DIScopeRef(M->getScope());
+
+  assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
          "Unhandled type of scope.");
   return nullptr;
 }
 
-StringRef MDScope::getName() const {
-  if (auto *T = dyn_cast<MDType>(this))
+StringRef DIScope::getName() const {
+  if (auto *T = dyn_cast<DIType>(this))
     return T->getName();
-  if (auto *SP = dyn_cast<MDSubprogram>(this))
+  if (auto *SP = dyn_cast<DISubprogram>(this))
     return SP->getName();
-  if (auto *NS = dyn_cast<MDNamespace>(this))
+  if (auto *NS = dyn_cast<DINamespace>(this))
     return NS->getName();
-  assert((isa<MDLexicalBlockBase>(this) || isa<MDFile>(this) ||
-          isa<MDCompileUnit>(this)) &&
+  if (auto *M = dyn_cast<DIModule>(this))
+    return M->getName();
+  assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
+          isa<DICompileUnit>(this)) &&
          "Unhandled type of scope.");
   return "";
 }
@@ -151,15 +173,14 @@ static bool isCanonical(const MDString *S) {
 }
 #endif
 
-GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
-                                            MDString *Header,
-                                            ArrayRef<Metadata *> DwarfOps,
-                                            StorageType Storage,
-                                            bool ShouldCreate) {
+GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
+                                      MDString *Header,
+                                      ArrayRef<Metadata *> DwarfOps,
+                                      StorageType Storage, bool ShouldCreate) {
   unsigned Hash = 0;
   if (Storage == Uniqued) {
-    GenericDebugNodeInfo::KeyTy Key(Tag, getString(Header), DwarfOps);
-    if (auto *N = getUniqued(Context.pImpl->GenericDebugNodes, Key))
+    GenericDINodeInfo::KeyTy Key(Tag, getString(Header), DwarfOps);
+    if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
       return N;
     if (!ShouldCreate)
       return nullptr;
@@ -171,13 +192,13 @@ GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
   // Use a nullptr for empty headers.
   assert(isCanonical(Header) && "Expected canonical MDString");
   Metadata *PreOps[] = {Header};
-  return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode(
+  return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
                        Context, Storage, Hash, Tag, PreOps, DwarfOps),
-                   Storage, Context.pImpl->GenericDebugNodes);
+                   Storage, Context.pImpl->GenericDINodes);
 }
 
-void GenericDebugNode::recalculateHash() {
-  setHash(GenericDebugNodeInfo::KeyTy::calculateHash(this));
+void GenericDINode::recalculateHash() {
+  setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
 }
 
 #define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
@@ -207,49 +228,49 @@ void GenericDebugNode::recalculateHash() {
                        CLASS(Context, Storage, OPS),                           \
                    Storage, Context.pImpl->CLASS##s)
 
-MDSubrange *MDSubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
+DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
                                 StorageType Storage, bool ShouldCreate) {
-  DEFINE_GETIMPL_LOOKUP(MDSubrange, (Count, Lo));
-  DEFINE_GETIMPL_STORE_NO_OPS(MDSubrange, (Count, Lo));
+  DEFINE_GETIMPL_LOOKUP(DISubrange, (Count, Lo));
+  DEFINE_GETIMPL_STORE_NO_OPS(DISubrange, (Count, Lo));
 }
 
-MDEnumerator *MDEnumerator::getImpl(LLVMContext &Context, int64_t Value,
+DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
                                     MDString *Name, StorageType Storage,
                                     bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDEnumerator, (Value, getString(Name)));
+  DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, getString(Name)));
   Metadata *Ops[] = {Name};
-  DEFINE_GETIMPL_STORE(MDEnumerator, (Value), Ops);
+  DEFINE_GETIMPL_STORE(DIEnumerator, (Value), Ops);
 }
 
-MDBasicType *MDBasicType::getImpl(LLVMContext &Context, unsigned Tag,
+DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
                                   MDString *Name, uint64_t SizeInBits,
                                   uint64_t AlignInBits, unsigned Encoding,
                                   StorageType Storage, bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
   DEFINE_GETIMPL_LOOKUP(
-      MDBasicType, (Tag, getString(Name), SizeInBits, AlignInBits, Encoding));
+      DIBasicType, (Tag, getString(Name), SizeInBits, AlignInBits, Encoding));
   Metadata *Ops[] = {nullptr, nullptr, Name};
-  DEFINE_GETIMPL_STORE(MDBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
+  DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
                        Ops);
 }
 
-MDDerivedType *MDDerivedType::getImpl(
+DIDerivedType *DIDerivedType::getImpl(
     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
     Metadata *ExtraData, StorageType Storage, bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDDerivedType, (Tag, getString(Name), File, Line, Scope,
+  DEFINE_GETIMPL_LOOKUP(DIDerivedType, (Tag, getString(Name), File, Line, Scope,
                                         BaseType, SizeInBits, AlignInBits,
                                         OffsetInBits, Flags, ExtraData));
   Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
   DEFINE_GETIMPL_STORE(
-      MDDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags),
+      DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags),
       Ops);
 }
 
-MDCompositeType *MDCompositeType::getImpl(
+DICompositeType *DICompositeType::getImpl(
     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
@@ -257,100 +278,92 @@ MDCompositeType *MDCompositeType::getImpl(
     Metadata *TemplateParams, MDString *Identifier, StorageType Storage,
     bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDCompositeType,
+  DEFINE_GETIMPL_LOOKUP(DICompositeType,
                         (Tag, getString(Name), File, Line, Scope, BaseType,
                          SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
                          RuntimeLang, VTableHolder, TemplateParams,
                          getString(Identifier)));
   Metadata *Ops[] = {File,     Scope,        Name,           BaseType,
                      Elements, VTableHolder, TemplateParams, Identifier};
-  DEFINE_GETIMPL_STORE(MDCompositeType, (Tag, Line, RuntimeLang, SizeInBits,
+  DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
                                          AlignInBits, OffsetInBits, Flags),
                        Ops);
 }
 
-MDSubroutineType *MDSubroutineType::getImpl(LLVMContext &Context,
+DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context,
                                             unsigned Flags, Metadata *TypeArray,
                                             StorageType Storage,
                                             bool ShouldCreate) {
-  DEFINE_GETIMPL_LOOKUP(MDSubroutineType, (Flags, TypeArray));
-  Metadata *Ops[] = {nullptr,   nullptr, nullptr, nullptr,
-                     TypeArray, nullptr, nullptr, nullptr};
-  DEFINE_GETIMPL_STORE(MDSubroutineType, (Flags), Ops);
+  DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, TypeArray));
+  Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
+  DEFINE_GETIMPL_STORE(DISubroutineType, (Flags), Ops);
 }
 
-MDFile *MDFile::getImpl(LLVMContext &Context, MDString *Filename,
+DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
                         MDString *Directory, StorageType Storage,
                         bool ShouldCreate) {
   assert(isCanonical(Filename) && "Expected canonical MDString");
   assert(isCanonical(Directory) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDFile, (getString(Filename), getString(Directory)));
+  DEFINE_GETIMPL_LOOKUP(DIFile, (getString(Filename), getString(Directory)));
   Metadata *Ops[] = {Filename, Directory};
-  DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(MDFile, Ops);
+  DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIFile, Ops);
 }
 
-MDCompileUnit *MDCompileUnit::getImpl(
+DICompileUnit *DICompileUnit::getImpl(
     LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
     MDString *Producer, bool IsOptimized, MDString *Flags,
     unsigned RuntimeVersion, MDString *SplitDebugFilename,
     unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
     Metadata *Subprograms, Metadata *GlobalVariables,
-    Metadata *ImportedEntities, StorageType Storage, bool ShouldCreate) {
+    Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
+    StorageType Storage, bool ShouldCreate) {
+  assert(Storage != Uniqued && "Cannot unique DICompileUnit");
   assert(isCanonical(Producer) && "Expected canonical MDString");
   assert(isCanonical(Flags) && "Expected canonical MDString");
   assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(
-      MDCompileUnit,
-      (SourceLanguage, File, getString(Producer), IsOptimized, getString(Flags),
-       RuntimeVersion, getString(SplitDebugFilename), EmissionKind, EnumTypes,
-       RetainedTypes, Subprograms, GlobalVariables, ImportedEntities));
+
   Metadata *Ops[] = {File, Producer, Flags, SplitDebugFilename, EnumTypes,
                      RetainedTypes, Subprograms, GlobalVariables,
-                     ImportedEntities};
-  DEFINE_GETIMPL_STORE(
-      MDCompileUnit,
-      (SourceLanguage, IsOptimized, RuntimeVersion, EmissionKind), Ops);
+                     ImportedEntities, Macros};
+  return storeImpl(new (ArrayRef<Metadata *>(Ops).size()) DICompileUnit(
+                       Context, Storage, SourceLanguage, IsOptimized,
+                       RuntimeVersion, EmissionKind, DWOId, Ops),
+                   Storage);
 }
 
-MDSubprogram *MDLocalScope::getSubprogram() const {
-  if (auto *Block = dyn_cast<MDLexicalBlockBase>(this))
+DISubprogram *DILocalScope::getSubprogram() const {
+  if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
     return Block->getScope()->getSubprogram();
-  return const_cast<MDSubprogram *>(cast<MDSubprogram>(this));
+  return const_cast<DISubprogram *>(cast<DISubprogram>(this));
 }
 
-MDSubprogram *MDSubprogram::getImpl(
+DISubprogram *DISubprogram::getImpl(
     LLVMContext &Context, Metadata *Scope, MDString *Name,
     MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
     bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
     Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
-    unsigned Flags, bool IsOptimized, Metadata *Function,
-    Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
-    StorageType Storage, bool ShouldCreate) {
+    unsigned Flags, bool IsOptimized, Metadata *TemplateParams,
+    Metadata *Declaration, Metadata *Variables, StorageType Storage,
+    bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
   assert(isCanonical(LinkageName) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDSubprogram,
+  DEFINE_GETIMPL_LOOKUP(DISubprogram,
                         (Scope, getString(Name), getString(LinkageName), File,
                          Line, Type, IsLocalToUnit, IsDefinition, ScopeLine,
                          ContainingType, Virtuality, VirtualIndex, Flags,
-                         IsOptimized, Function, TemplateParams, Declaration,
-                         Variables));
-  Metadata *Ops[] = {File,           Scope,       Name,           Name,
-                     LinkageName,    Type,        ContainingType, Function,
-                     TemplateParams, Declaration, Variables};
-  DEFINE_GETIMPL_STORE(MDSubprogram,
+                         IsOptimized, TemplateParams, Declaration, Variables));
+  Metadata *Ops[] = {File,        Scope,    Name,           Name,
+                     LinkageName, Type,     ContainingType, TemplateParams,
+                     Declaration, Variables};
+  DEFINE_GETIMPL_STORE(DISubprogram,
                        (Line, ScopeLine, Virtuality, VirtualIndex, Flags,
                         IsLocalToUnit, IsDefinition, IsOptimized),
                        Ops);
 }
 
-Function *MDSubprogram::getFunction() const {
-  // FIXME: Should this be looking through bitcasts?
-  return dyn_cast_or_null<Function>(getFunctionConstant());
-}
-
-bool MDSubprogram::describes(const Function *F) const {
+bool DISubprogram::describes(const Function *F) const {
   assert(F && "Invalid function");
-  if (F == getFunction())
+  if (F->getSubprogram() == this)
     return true;
   StringRef Name = getLinkageName();
   if (Name.empty())
@@ -358,64 +371,74 @@ bool MDSubprogram::describes(const Function *F) const {
   return F->getName() == Name;
 }
 
-void MDSubprogram::replaceFunction(Function *F) {
-  replaceFunction(F ? ConstantAsMetadata::get(F)
-                    : static_cast<ConstantAsMetadata *>(nullptr));
-}
-
-MDLexicalBlock *MDLexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
+DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
                                         Metadata *File, unsigned Line,
                                         unsigned Column, StorageType Storage,
                                         bool ShouldCreate) {
+  // Fixup column.
+  adjustColumn(Column);
+
   assert(Scope && "Expected scope");
-  DEFINE_GETIMPL_LOOKUP(MDLexicalBlock, (Scope, File, Line, Column));
+  DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
   Metadata *Ops[] = {File, Scope};
-  DEFINE_GETIMPL_STORE(MDLexicalBlock, (Line, Column), Ops);
+  DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
 }
 
-MDLexicalBlockFile *MDLexicalBlockFile::getImpl(LLVMContext &Context,
+DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
                                                 Metadata *Scope, Metadata *File,
                                                 unsigned Discriminator,
                                                 StorageType Storage,
                                                 bool ShouldCreate) {
   assert(Scope && "Expected scope");
-  DEFINE_GETIMPL_LOOKUP(MDLexicalBlockFile, (Scope, File, Discriminator));
+  DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
   Metadata *Ops[] = {File, Scope};
-  DEFINE_GETIMPL_STORE(MDLexicalBlockFile, (Discriminator), Ops);
+  DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
 }
 
-MDNamespace *MDNamespace::getImpl(LLVMContext &Context, Metadata *Scope,
+DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
                                   Metadata *File, MDString *Name, unsigned Line,
                                   StorageType Storage, bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDNamespace, (Scope, File, getString(Name), Line));
+  DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, getString(Name), Line));
   Metadata *Ops[] = {File, Scope, Name};
-  DEFINE_GETIMPL_STORE(MDNamespace, (Line), Ops);
+  DEFINE_GETIMPL_STORE(DINamespace, (Line), Ops);
 }
 
-MDTemplateTypeParameter *MDTemplateTypeParameter::getImpl(LLVMContext &Context,
+DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
+                            MDString *Name, MDString *ConfigurationMacros,
+                            MDString *IncludePath, MDString *ISysRoot,
+                            StorageType Storage, bool ShouldCreate) {
+  assert(isCanonical(Name) && "Expected canonical MDString");
+  DEFINE_GETIMPL_LOOKUP(DIModule,
+    (Scope, getString(Name), getString(ConfigurationMacros),
+     getString(IncludePath), getString(ISysRoot)));
+  Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
+  DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
+}
+
+DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
                                                           MDString *Name,
                                                           Metadata *Type,
                                                           StorageType Storage,
                                                           bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDTemplateTypeParameter, (getString(Name), Type));
+  DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (getString(Name), Type));
   Metadata *Ops[] = {Name, Type};
-  DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(MDTemplateTypeParameter, Ops);
+  DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
 }
 
-MDTemplateValueParameter *MDTemplateValueParameter::getImpl(
+DITemplateValueParameter *DITemplateValueParameter::getImpl(
     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
     Metadata *Value, StorageType Storage, bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDTemplateValueParameter,
+  DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter,
                         (Tag, getString(Name), Type, Value));
   Metadata *Ops[] = {Name, Type, Value};
-  DEFINE_GETIMPL_STORE(MDTemplateValueParameter, (Tag), Ops);
+  DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
 }
 
-MDGlobalVariable *
-MDGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
+DIGlobalVariable *
+DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
                           MDString *LinkageName, Metadata *File, unsigned Line,
                           Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
                           Metadata *Variable,
@@ -423,53 +446,53 @@ MDGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
                           StorageType Storage, bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
   assert(isCanonical(LinkageName) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDGlobalVariable,
+  DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
                         (Scope, getString(Name), getString(LinkageName), File,
                          Line, Type, IsLocalToUnit, IsDefinition, Variable,
                          StaticDataMemberDeclaration));
   Metadata *Ops[] = {Scope, Name,        File,     Type,
                      Name,  LinkageName, Variable, StaticDataMemberDeclaration};
-  DEFINE_GETIMPL_STORE(MDGlobalVariable, (Line, IsLocalToUnit, IsDefinition),
+  DEFINE_GETIMPL_STORE(DIGlobalVariable, (Line, IsLocalToUnit, IsDefinition),
                        Ops);
 }
 
-MDLocalVariable *MDLocalVariable::getImpl(
-    LLVMContext &Context, unsigned Tag, Metadata *Scope, MDString *Name,
-    Metadata *File, unsigned Line, Metadata *Type, unsigned Arg, unsigned Flags,
-    Metadata *InlinedAt, StorageType Storage, bool ShouldCreate) {
-  // Truncate Arg to 8 bits.
-  //
-  // FIXME: This is gross (and should be changed to an assert or removed), but
-  // it matches historical behaviour for now.
-  Arg &= (1u << 8) - 1;
+DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
+                                          MDString *Name, Metadata *File,
+                                          unsigned Line, Metadata *Type,
+                                          unsigned Arg, unsigned Flags,
+                                          StorageType Storage,
+                                          bool ShouldCreate) {
+  // 64K ought to be enough for any frontend.
+  assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
 
   assert(Scope && "Expected scope");
   assert(isCanonical(Name) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDLocalVariable, (Tag, Scope, getString(Name), File,
-                                          Line, Type, Arg, Flags, InlinedAt));
-  Metadata *Ops[] = {Scope, Name, File, Type, InlinedAt};
-  DEFINE_GETIMPL_STORE(MDLocalVariable, (Tag, Line, Arg, Flags), Ops);
+  DEFINE_GETIMPL_LOOKUP(DILocalVariable,
+                        (Scope, getString(Name), File, Line, Type, Arg, Flags));
+  Metadata *Ops[] = {Scope, Name, File, Type};
+  DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags), Ops);
 }
 
-MDExpression *MDExpression::getImpl(LLVMContext &Context,
+DIExpression *DIExpression::getImpl(LLVMContext &Context,
                                     ArrayRef<uint64_t> Elements,
                                     StorageType Storage, bool ShouldCreate) {
-  DEFINE_GETIMPL_LOOKUP(MDExpression, (Elements));
-  DEFINE_GETIMPL_STORE_NO_OPS(MDExpression, (Elements));
+  DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
+  DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
 }
 
-unsigned MDExpression::ExprOperand::getSize() const {
+unsigned DIExpression::ExprOperand::getSize() const {
   switch (getOp()) {
   case dwarf::DW_OP_bit_piece:
     return 3;
   case dwarf::DW_OP_plus:
+  case dwarf::DW_OP_minus:
     return 2;
   default:
     return 1;
   }
 }
 
-bool MDExpression::isValid() const {
+bool DIExpression::isValid() const {
   for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
     // Check that there's space for the operand.
     if (I->get() + I->getSize() > E->get())
@@ -483,6 +506,7 @@ bool MDExpression::isValid() const {
       // Piece expressions must be at the end.
       return I->get() + I->getSize() == E->get();
     case dwarf::DW_OP_plus:
+    case dwarf::DW_OP_minus:
     case dwarf::DW_OP_deref:
       break;
     }
@@ -490,7 +514,7 @@ bool MDExpression::isValid() const {
   return true;
 }
 
-bool MDExpression::isBitPiece() const {
+bool DIExpression::isBitPiece() const {
   assert(isValid() && "Expected valid expression");
   if (unsigned N = getNumElements())
     if (N >= 3)
@@ -498,38 +522,59 @@ bool MDExpression::isBitPiece() const {
   return false;
 }
 
-uint64_t MDExpression::getBitPieceOffset() const {
+uint64_t DIExpression::getBitPieceOffset() const {
   assert(isBitPiece() && "Expected bit piece");
   return getElement(getNumElements() - 2);
 }
 
-uint64_t MDExpression::getBitPieceSize() const {
+uint64_t DIExpression::getBitPieceSize() const {
   assert(isBitPiece() && "Expected bit piece");
   return getElement(getNumElements() - 1);
 }
 
-MDObjCProperty *MDObjCProperty::getImpl(
+DIObjCProperty *DIObjCProperty::getImpl(
     LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
     MDString *GetterName, MDString *SetterName, unsigned Attributes,
     Metadata *Type, StorageType Storage, bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
   assert(isCanonical(GetterName) && "Expected canonical MDString");
   assert(isCanonical(SetterName) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDObjCProperty,
+  DEFINE_GETIMPL_LOOKUP(DIObjCProperty,
                         (getString(Name), File, Line, getString(GetterName),
                          getString(SetterName), Attributes, Type));
   Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
-  DEFINE_GETIMPL_STORE(MDObjCProperty, (Line, Attributes), Ops);
+  DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
 }
 
-MDImportedEntity *MDImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
+DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
                                             Metadata *Scope, Metadata *Entity,
                                             unsigned Line, MDString *Name,
                                             StorageType Storage,
                                             bool ShouldCreate) {
   assert(isCanonical(Name) && "Expected canonical MDString");
-  DEFINE_GETIMPL_LOOKUP(MDImportedEntity,
+  DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
                         (Tag, Scope, Entity, Line, getString(Name)));
   Metadata *Ops[] = {Scope, Entity, Name};
-  DEFINE_GETIMPL_STORE(MDImportedEntity, (Tag, Line), Ops);
+  DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
 }
+
+DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
+                          unsigned Line, MDString *Name, MDString *Value,
+                          StorageType Storage, bool ShouldCreate) {
+  assert(isCanonical(Name) && "Expected canonical MDString");
+  DEFINE_GETIMPL_LOOKUP(DIMacro,
+                        (MIType, Line, getString(Name), getString(Value)));
+  Metadata *Ops[] = { Name, Value };
+  DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
+}
+
+DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
+                                  unsigned Line, Metadata *File,
+                                  Metadata *Elements, StorageType Storage,
+                                  bool ShouldCreate) {
+  DEFINE_GETIMPL_LOOKUP(DIMacroFile,
+                        (MIType, Line, File, Elements));
+  Metadata *Ops[] = { File, Elements };
+  DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
+}
+