Add getModuleFlag(StringRef Key) to query a module flag given Key.
authorManman Ren <mren@apple.com>
Tue, 16 Jul 2013 23:21:16 +0000 (23:21 +0000)
committerManman Ren <mren@apple.com>
Tue, 16 Jul 2013 23:21:16 +0000 (23:21 +0000)
No functionality change.

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

include/llvm/IR/Module.h
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/IR/Module.cpp

index d414405818261089c1f566a67e410e0604ed4bc1..2514be4faa333d86cb41928c434bc023b8a88185 100644 (file)
@@ -405,6 +405,10 @@ public:
   /// getModuleFlagsMetadata - Returns the module flags in the provided vector.
   void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const;
 
+  /// Return the corresponding value if Key appears in module flags, otherwise
+  /// return null.
+  Value *getModuleFlag(StringRef Key) const;
+
   /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
   /// represents module-level flags. This method returns null if there are no
   /// module-level flags.
index a35cfa2ec90e96ed79033e83bb0ab96829d1ab6f..254ecd256d759af83de5b7f1d6076672b7402765 100644 (file)
@@ -164,17 +164,10 @@ DIType DbgVariable::getType() const {
 
 /// Return Dwarf Version by checking module flags.
 static unsigned getDwarfVersionFromModule(const Module *M) {
-  SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
-  M->getModuleFlagsMetadata(ModuleFlags);
-  for (unsigned I = 0, E = ModuleFlags.size(); I < E; ++I) {
-    const Module::ModuleFlagEntry &MFE = ModuleFlags[I];
-    StringRef Key = MFE.Key->getString();
-    Value *Val = MFE.Val;
-
-    if (Key == "Dwarf Version")
-      return cast<ConstantInt>(Val)->getZExtValue();
-  }
-  return dwarf::DWARF_VERSION;
+  Value *Val = M->getModuleFlag("Dwarf Version");
+  if (!Val)
+    return dwarf::DWARF_VERSION;
+  return cast<ConstantInt>(Val)->getZExtValue();
 }
 
 DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
index 3f505aa3e095f4e7eec69553511ec52ada82316c..3d3dc737a1b5c50d427693227fe68d7845b62244 100644 (file)
@@ -325,6 +325,19 @@ getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
   }
 }
 
+/// Return the corresponding value if Key appears in module flags, otherwise
+/// return null.
+Value *Module::getModuleFlag(StringRef Key) const {
+  SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
+  getModuleFlagsMetadata(ModuleFlags);
+  for (unsigned I = 0, E = ModuleFlags.size(); I < E; ++I) {
+    const ModuleFlagEntry &MFE = ModuleFlags[I];
+    if (Key == MFE.Key->getString())
+      return MFE.Val;
+  }
+  return 0;
+}
+
 /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
 /// represents module-level flags. This method returns null if there are no
 /// module-level flags.