[llvm] r186470 - Add getModuleFlag(StringRef Key) to query a module flag given Key.
Manman Ren
mren at apple.com
Tue Jul 16 16:21:17 PDT 2013
Author: mren
Date: Tue Jul 16 18:21:16 2013
New Revision: 186470
URL: http://llvm.org/viewvc/llvm-project?rev=186470&view=rev
Log:
Add getModuleFlag(StringRef Key) to query a module flag given Key.
No functionality change.
Modified:
llvm/trunk/include/llvm/IR/Module.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/trunk/lib/IR/Module.cpp
Modified: llvm/trunk/include/llvm/IR/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Module.h?rev=186470&r1=186469&r2=186470&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Module.h (original)
+++ llvm/trunk/include/llvm/IR/Module.h Tue Jul 16 18:21:16 2013
@@ -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.
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=186470&r1=186469&r2=186470&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Jul 16 18:21:16 2013
@@ -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)
Modified: llvm/trunk/lib/IR/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Module.cpp?rev=186470&r1=186469&r2=186470&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Module.cpp (original)
+++ llvm/trunk/lib/IR/Module.cpp Tue Jul 16 18:21:16 2013
@@ -325,6 +325,19 @@ getModuleFlagsMetadata(SmallVectorImpl<M
}
}
+/// 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.
More information about the llvm-commits
mailing list