rename getMDKind -> getMDKindID, make it autoinsert if an MD Kind
authorChris Lattner <sabre@nondot.org>
Mon, 28 Dec 2009 20:45:51 +0000 (20:45 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 28 Dec 2009 20:45:51 +0000 (20:45 +0000)
doesn't exist already, eliminate registerMDKind.  Tidy up a bunch
of random stuff.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92225 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 10433df7d93973618739c4546e87d6972c54d305..a6e2d812e3ade68dbbb031a97910b4957a90d3a4 100644 (file)
@@ -197,32 +197,25 @@ public:
 };
 
 //===----------------------------------------------------------------------===//
-/// 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 @@ public:
   
   /// 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.
index 543ea856ad954b4613dd38675e243a69b933bee0..9e6ef57e0ce305f1678dce4f9944180f8b9dd2ae 100644 (file)
@@ -137,9 +137,7 @@ public:
   /// 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 @@ public:
   /// 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);
   }
 
index c8cb60f0c111a036a8c23e56d6202754d3c5c970..3732818de36c0f0c81485f71496ab4d2e00f5f8b 100644 (file)
@@ -1119,7 +1119,7 @@ Instruction *DIFactory::InsertDbgValueIntrinsic(Value *V, Value *Offset,
 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 @@ void DebugInfoFinder::processModule(Module &M) {
            ++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");
index 48b6e87e04d0c6734ddac794f524f7641080bef0..a84336d60778d6da8d405756d1cefe7370a1e7e8 100644 (file)
@@ -1123,11 +1123,8 @@ bool LLParser::ParseOptionalCustomMetadata() {
   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;
 }
 
index 9916388dad100060067148d4a06dc183080b892d..0bda03e337f11bd69930bf127c022e26c75a049c 100644 (file)
@@ -840,17 +840,10 @@ bool BitcodeReader::ParseMetadata() {
       (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;
     }
     }
index 9e182efbbbf20818c4619b7202ffdd89ed5cc1d9..24a5b0d6481ba104df5bc366710010f8fbaa01fd 100644 (file)
@@ -351,9 +351,9 @@ bool FastISel::SelectCall(User *I) {
     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;
   }
index 8fe7c4554501de761365e88c603132e20ffac195..266cb64b7155663c603b43ca3a73739140dac320 100644 (file)
@@ -4383,9 +4383,9 @@ SelectionDAGBuilder::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     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;
   }
index 667be906751be87aeaafdbdd4dee5c690c157fcd..7efd480dccf44280f782938d59025be40fdae0b2 100644 (file)
@@ -362,27 +362,25 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
 
 /// 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 @@ void SelectionDAGISel::SelectBasicBlock(BasicBlock *LLVMBB,
                                         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 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn,
                                 );
 
   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 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn,
             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)) {
index 0b5e00706c9b67a018ca5a54c0da0979ffc57f6b..b213b014eb2902b154e5c74cf6d106f71415ba30 100644 (file)
@@ -221,9 +221,7 @@ static bool StripDebugInfo(Module &M) {
     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;
index 162d7b3502cbdc4f624b7c31a10c751e5df458c2..2f94ee16cb4e577486b9da2c27ad109ca9a697c1 100644 (file)
@@ -422,7 +422,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
     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()) 
index 31e737f4150009420e50d2392d5c9c979e07649b..a516d7bf93dd6bc223f231beaffda9f93a6d7e60 100644 (file)
@@ -261,13 +261,7 @@ private:
   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 @@ public:
 };
 }
 
-/// 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 @@ bool MetadataContext::isValidName(StringRef MDName) {
   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.