[llvm-commits] [llvm] r92225 - in /llvm/trunk: include/llvm/Metadata.h include/llvm/Support/IRBuilder.h lib/Analysis/DebugInfo.cpp lib/AsmParser/LLParser.cpp lib/Bitcode/Reader/BitcodeReader.cpp lib/CodeGen/SelectionDAG/FastISel.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp lib/Transforms/IPO/StripSymbols.cpp lib/Transforms/Utils/CloneFunction.cpp lib/VMCore/Metadata.cpp

Chris Lattner sabre at nondot.org
Mon Dec 28 12:45:52 PST 2009


Author: lattner
Date: Mon Dec 28 14:45:51 2009
New Revision: 92225

URL: http://llvm.org/viewvc/llvm-project?rev=92225&view=rev
Log:
rename getMDKind -> getMDKindID, make it autoinsert if an MD Kind
doesn't exist already, eliminate registerMDKind.  Tidy up a bunch
of random stuff.

Modified:
    llvm/trunk/include/llvm/Metadata.h
    llvm/trunk/include/llvm/Support/IRBuilder.h
    llvm/trunk/lib/Analysis/DebugInfo.cpp
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
    llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
    llvm/trunk/lib/VMCore/Metadata.cpp

Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Mon Dec 28 14:45:51 2009
@@ -197,32 +197,25 @@
 };
 
 //===----------------------------------------------------------------------===//
-/// MetadataContext -
-/// MetadataContext handles uniquing and assignment of IDs for custom metadata
-/// types. Custom metadata handler names do not contain spaces. And the name
-/// must start with an alphabet. The regular expression used to check name
-/// is [a-zA-Z$._][a-zA-Z$._0-9]*
+/// MetadataContext - MetadataContext handles uniquing and assignment of IDs for
+/// custom metadata types.
+///
 class MetadataContext {
-  // DO NOT IMPLEMENT
-  MetadataContext(MetadataContext&);
-  void operator=(MetadataContext&);
+  MetadataContext(MetadataContext&); // DO NOT IMPLEMENT
+  void operator=(MetadataContext&);  // DO NOT IMPLEMENT
 
   MetadataContextImpl *const pImpl;
 public:
   MetadataContext();
   ~MetadataContext();
 
-  /// registerMDKind - Register a new metadata kind and return its ID.
-  /// A metadata kind can be registered only once. 
-  unsigned registerMDKind(StringRef Name);
-
-  /// getMDKind - Return metadata kind. If the requested metadata kind
-  /// is not registered then return 0.
-  unsigned getMDKind(StringRef Name) const;
+  /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
+  unsigned getMDKindID(StringRef Name) const;
 
   /// isValidName - Return true if Name is a valid custom metadata handler name.
   static bool isValidName(StringRef Name);
 
+#if 1
   /// getMD - Get the metadata of given kind attached to an Instruction.
   /// If the metadata is not found then return 0.
   MDNode *getMD(unsigned Kind, const Instruction *Inst);
@@ -239,6 +232,7 @@
   
   /// removeAllMetadata - Remove all metadata attached with an instruction.
   void removeAllMetadata(Instruction *Inst);
+#endif
 
   /// copyMD - If metadata is attached with Instruction In1 then attach
   /// the same metadata to In2.

Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Mon Dec 28 14:45:51 2009
@@ -137,9 +137,7 @@
   /// information.
   void SetCurrentDebugLocation(MDNode *L) {
     if (MDKind == 0) 
-      MDKind = Context.getMetadata().getMDKind("dbg");
-    if (MDKind == 0)
-      MDKind = Context.getMetadata().registerMDKind("dbg");
+      MDKind = Context.getMetadata().getMDKindID("dbg");
     CurDbgLocation = L;
   }
 
@@ -154,9 +152,7 @@
   /// SetDebugLocation -  Set location information for the given instruction.
   void SetDebugLocation(Instruction *I, MDNode *Loc) {
     if (MDKind == 0) 
-      MDKind = Context.getMetadata().getMDKind("dbg");
-    if (MDKind == 0)
-      MDKind = Context.getMetadata().registerMDKind("dbg");
+      MDKind = Context.getMetadata().getMDKindID("dbg");
     Context.getMetadata().addMD(MDKind, Loc, I);
   }
 

Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Mon Dec 28 14:45:51 2009
@@ -1119,7 +1119,7 @@
 void DebugInfoFinder::processModule(Module &M) {
 
   MetadataContext &TheMetadata = M.getContext().getMetadata();
-  unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
+  unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
 
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
     for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
@@ -1127,9 +1127,8 @@
            ++BI) {
         if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
           processDeclare(DDI);
-        else if (MDDbgKind) 
-          if (MDNode *L = TheMetadata.getMD(MDDbgKind, BI)) 
-            processLocation(DILocation(L));
+        else if (MDNode *L = TheMetadata.getMD(MDDbgKind, BI)) 
+          processLocation(DILocation(L));
       }
 
   NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv");

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Dec 28 14:45:51 2009
@@ -1123,11 +1123,8 @@
   if (ParseMDNode(Node)) return true;
 
   MetadataContext &TheMetadata = M->getContext().getMetadata();
-  unsigned MDK = TheMetadata.getMDKind(Name.c_str());
-  if (!MDK)
-    MDK = TheMetadata.registerMDKind(Name.c_str());
+  unsigned MDK = TheMetadata.getMDKindID(Name.c_str());
   MDsOnInst.push_back(std::make_pair(MDK, cast<MDNode>(Node)));
-
   return false;
 }
 

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Dec 28 14:45:51 2009
@@ -840,17 +840,10 @@
       (void) Kind;
       for (unsigned i = 1; i != RecordLength; ++i)
         Name[i-1] = Record[i];
-      MetadataContext &TheMetadata = Context.getMetadata();
-      unsigned ExistingKind = TheMetadata.getMDKind(Name.str());
-      if (ExistingKind == 0) {
-        unsigned NewKind = TheMetadata.registerMDKind(Name.str());
-        (void) NewKind;
-        assert (Kind == NewKind 
-                && "Unable to handle custom metadata mismatch!");
-      } else {
-        assert (ExistingKind == Kind 
-                && "Unable to handle custom metadata mismatch!");
-      }
+      
+      unsigned NewKind = Context.getMetadata().getMDKindID(Name.str());
+      assert(Kind == NewKind &&
+             "FIXME: Unable to handle custom metadata mismatch!");(void)NewKind;
       break;
     }
     }

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp Mon Dec 28 14:45:51 2009
@@ -351,9 +351,9 @@
     if (MMI) {
       MetadataContext &TheMetadata = 
         DI->getParent()->getContext().getMetadata();
-      unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
-      MDNode *Dbg = TheMetadata.getMD(MDDbgKind, DI);
-      MMI->setVariableDbgInfo(DI->getVariable(), FI, Dbg);
+      unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
+      if (MDNode *Dbg = TheMetadata.getMD(MDDbgKind, DI))
+        MMI->setVariableDbgInfo(DI->getVariable(), FI, Dbg);
     }
     return true;
   }

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Mon Dec 28 14:45:51 2009
@@ -4383,9 +4383,9 @@
     if (MMI) {
       MetadataContext &TheMetadata = 
         DI.getParent()->getContext().getMetadata();
-      unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
-      MDNode *Dbg = TheMetadata.getMD(MDDbgKind, &DI);
-      MMI->setVariableDbgInfo(Variable, FI, Dbg);
+      unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
+      if (MDNode *Dbg = TheMetadata.getMD(MDDbgKind, &DI))
+        MMI->setVariableDbgInfo(Variable, FI, Dbg);
     }
     return 0;
   }

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Mon Dec 28 14:45:51 2009
@@ -362,27 +362,25 @@
 
 /// SetDebugLoc - Update MF's and SDB's DebugLocs if debug information is
 /// attached with this instruction.
-static void SetDebugLoc(unsigned MDDbgKind,
-                        MetadataContext &TheMetadata,
-                        Instruction *I,
-                        SelectionDAGBuilder *SDB,
-                        FastISel *FastIS,
-                        MachineFunction *MF) {
-  if (!isa<DbgInfoIntrinsic>(I)) 
-    if (MDNode *Dbg = TheMetadata.getMD(MDDbgKind, I)) {
-      DILocation DILoc(Dbg);
-      DebugLoc Loc = ExtractDebugLocation(DILoc, MF->getDebugLocInfo());
-
-      SDB->setCurDebugLoc(Loc);
-
-      if (FastIS)
-        FastIS->setCurDebugLoc(Loc);
-
-      // If the function doesn't have a default debug location yet, set
-      // it. This is kind of a hack.
-      if (MF->getDefaultDebugLoc().isUnknown())
-        MF->setDefaultDebugLoc(Loc);
-    }
+static void SetDebugLoc(unsigned MDDbgKind, MetadataContext &TheMetadata,
+                        Instruction *I, SelectionDAGBuilder *SDB,
+                        FastISel *FastIS, MachineFunction *MF) {
+  if (isa<DbgInfoIntrinsic>(I)) return;
+  
+  if (MDNode *Dbg = TheMetadata.getMD(MDDbgKind, I)) {
+    DILocation DILoc(Dbg);
+    DebugLoc Loc = ExtractDebugLocation(DILoc, MF->getDebugLocInfo());
+
+    SDB->setCurDebugLoc(Loc);
+
+    if (FastIS)
+      FastIS->setCurDebugLoc(Loc);
+
+    // If the function doesn't have a default debug location yet, set
+    // it. This is kind of a hack.
+    if (MF->getDefaultDebugLoc().isUnknown())
+      MF->setDefaultDebugLoc(Loc);
+  }
 }
 
 /// ResetDebugLoc - Set MF's and SDB's DebugLocs to Unknown.
@@ -398,14 +396,13 @@
                                         BasicBlock::iterator End,
                                         bool &HadTailCall) {
   SDB->setCurrentBasicBlock(BB);
-  MetadataContext &TheMetadata = LLVMBB->getParent()->getContext().getMetadata();
-  unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
+  MetadataContext &TheMetadata =LLVMBB->getParent()->getContext().getMetadata();
+  unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
 
   // Lower all of the non-terminator instructions. If a call is emitted
   // as a tail call, cease emitting nodes for this block.
   for (BasicBlock::iterator I = Begin; I != End && !SDB->HasTailCall; ++I) {
-    if (MDDbgKind)
-      SetDebugLoc(MDDbgKind, TheMetadata, I, SDB, 0, MF);
+    SetDebugLoc(MDDbgKind, TheMetadata, I, SDB, 0, MF);
 
     if (!isa<TerminatorInst>(I)) {
       SDB->visit(*I);
@@ -681,7 +678,7 @@
                                 );
 
   MetadataContext &TheMetadata = Fn.getContext().getMetadata();
-  unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
+  unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
 
   // Iterate over all basic blocks in the function.
   for (Function::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
@@ -779,8 +776,7 @@
             break;
           }
 
-        if (MDDbgKind)
-          SetDebugLoc(MDDbgKind, TheMetadata, BI, SDB, FastIS, &MF);
+        SetDebugLoc(MDDbgKind, TheMetadata, BI, SDB, FastIS, &MF);
 
         // First try normal tablegen-generated "fast" selection.
         if (FastIS->SelectInstruction(BI)) {

Modified: llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp Mon Dec 28 14:45:51 2009
@@ -221,9 +221,7 @@
     NMD->eraseFromParent();
   }
   MetadataContext &TheMetadata = M.getContext().getMetadata();
-  unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
-  if (!MDDbgKind)
-    return Changed;
+  unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
 
   for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI) 
     for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE;

Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Mon Dec 28 14:45:51 2009
@@ -422,7 +422,7 @@
     BasicBlock::iterator I = NewBB->begin();
 
     LLVMContext &Context = OldFunc->getContext();
-    unsigned DbgKind = Context.getMetadata().getMDKind("dbg");
+    unsigned DbgKind = Context.getMetadata().getMDKindID("dbg");
     MDNode *TheCallMD = NULL;
     SmallVector<Value *, 4> MDVs;
     if (TheCall && TheCall->hasMetadata()) 

Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=92225&r1=92224&r2=92225&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Mon Dec 28 14:45:51 2009
@@ -261,13 +261,7 @@
   StringMap<unsigned> MDHandlerNames;
 
 public:
-  /// registerMDKind - Register a new metadata kind and return its ID.
-  /// A metadata kind can be registered only once. 
-  unsigned registerMDKind(StringRef Name);
-
-  /// getMDKind - Return metadata kind. If the requested metadata kind
-  /// is not registered then return 0.
-  unsigned getMDKind(StringRef Name) const;
+  unsigned getMDKindID(StringRef Name);
 
   /// getMD - Get the metadata of given kind attached to an Instruction.
   /// If the metadata is not found then return 0.
@@ -308,22 +302,14 @@
 };
 }
 
-/// registerMDKind - Register a new metadata kind and return its ID.
-/// A metadata kind can be registered only once. 
-unsigned MetadataContextImpl::registerMDKind(StringRef Name) {
-  unsigned Count = MDHandlerNames.size();
-  assert(MDHandlerNames.count(Name) == 0 && "Already registered MDKind!");
-  return MDHandlerNames[Name] = Count + 1;
-}
-
-/// getMDKind - Return metadata kind. If the requested metadata kind
-/// is not registered then return 0.
-unsigned MetadataContextImpl::getMDKind(StringRef Name) const {
-  StringMap<unsigned>::const_iterator I = MDHandlerNames.find(Name);
-  if (I == MDHandlerNames.end())
-    return 0;
+/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
+unsigned MetadataContextImpl::getMDKindID(StringRef Name) {
+  unsigned &Entry = MDHandlerNames[Name];
 
-  return I->getValue();
+  // If this is new, assign it its ID.
+  if (Entry == 0) Entry = MDHandlerNames.size();
+  
+  return Entry;
 }
 
 /// addMD - Attach the metadata of given kind to an Instruction.
@@ -472,17 +458,9 @@
   return true;
 }
 
-/// registerMDKind - Register a new metadata kind and return its ID.
-/// A metadata kind can be registered only once. 
-unsigned MetadataContext::registerMDKind(StringRef Name) {
-  assert(isValidName(Name) && "Invalid custome metadata name!");
-  return pImpl->registerMDKind(Name);
-}
-
-/// getMDKind - Return metadata kind. If the requested metadata kind
-/// is not registered then return 0.
-unsigned MetadataContext::getMDKind(StringRef Name) const {
-  return pImpl->getMDKind(Name);
+/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
+unsigned MetadataContext::getMDKindID(StringRef Name) const {
+  return pImpl->getMDKindID(Name);
 }
 
 /// getMD - Get the metadata of given kind attached to an Instruction.





More information about the llvm-commits mailing list