From 0294932a43109d91d650332ff178e49803c66e6c Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 15 Feb 2012 22:34:20 +0000 Subject: [PATCH] Add a module flags accessor method which returns the flags in a vector. llvm-svn: 150623 --- llvm/include/llvm/Module.h | 11 +++++++++++ llvm/lib/VMCore/Module.cpp | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/llvm/include/llvm/Module.h b/llvm/include/llvm/Module.h index 046798845bec..e068f93deb39 100644 --- a/llvm/include/llvm/Module.h +++ b/llvm/include/llvm/Module.h @@ -179,6 +179,14 @@ public: /// values. enum ModAttrBehavior { Error = 1, Warning = 2, Require = 3, Override = 4 }; + struct ModuleFlagEntry { + unsigned Behavior; + MDString *Key; + Value *Val; + ModuleFlagEntry(unsigned B, MDString *K, Value *V) + : Behavior(B), Key(K), Val(V) {} + }; + /// @} /// @name Member Variables /// @{ @@ -401,6 +409,9 @@ public: /// @name Module Flags Accessors /// @{ + /// getModuleFlagsMetadata - Returns the module flags in the provided vector. + void getModuleFlagsMetadata(SmallVectorImpl &Flags) const; + /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that /// represents module-level flags. This method returns null if there are no /// module-level flags. diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp index 09468184cc15..9de5db5a2b25 100644 --- a/llvm/lib/VMCore/Module.cpp +++ b/llvm/lib/VMCore/Module.cpp @@ -328,6 +328,21 @@ void Module::eraseNamedMetadata(NamedMDNode *NMD) { NamedMDList.erase(NMD); } +/// getModuleFlagsMetadata - Returns the module flags in the provided vector. +void Module:: +getModuleFlagsMetadata(SmallVectorImpl &Flags) const { + const NamedMDNode *ModFlags = getModuleFlagsMetadata(); + if (!ModFlags) return; + + for (unsigned i = 0, e = ModFlags->getNumOperands(); i != e; ++i) { + MDNode *Flag = ModFlags->getOperand(i); + ConstantInt *Behavior = cast(Flag->getOperand(0)); + MDString *Key = cast(Flag->getOperand(1)); + Value *Val = Flag->getOperand(2); + Flags.push_back(ModuleFlagEntry(Behavior->getZExtValue(), Key, Val)); + } +} + /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that /// represents module-level flags. This method returns null if there are no /// module-level flags.