summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-02-11 11:38:06 +0000
committerBill Wendling <isanbard@gmail.com>2012-02-11 11:38:06 +0000
commit66f02413efe426de35b298dd7aaa23f0a550707d (patch)
tree7f9fef071add611e46bacfe032224b12292ca4cf /llvm/lib/VMCore
parent981c6cf7b318132ea2ab123e5423b35d0d7a2e2f (diff)
downloadbcm5719-llvm-66f02413efe426de35b298dd7aaa23f0a550707d.tar.gz
bcm5719-llvm-66f02413efe426de35b298dd7aaa23f0a550707d.zip
[WIP] Initial code for module flags.
Module flags are key-value pairs associated with the module. They include a 'behavior' value, indicating how module flags react when mergine two files. Normally, it's just the union of the two module flags. But if two module flags have the same key, then the resulting flags are dictated by the behaviors. Allowable behaviors are: Error Emits an error if two values disagree. Warning Emits a warning if two values disagree. Require Emits an error when the specified value is not present or doesn't have the specified value. It is an error for two (or more) llvm.module.flags with the same ID to have the Require behavior but different values. There may be multiple Require flags per ID. Override Uses the specified value if the two values disagree. It is an error for two (or more) llvm.module.flags with the same ID to have the Override behavior but different values. llvm-svn: 150300
Diffstat (limited to 'llvm/lib/VMCore')
-rw-r--r--llvm/lib/VMCore/Module.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp
index c29029bf6c0..09468184cc1 100644
--- a/llvm/lib/VMCore/Module.cpp
+++ b/llvm/lib/VMCore/Module.cpp
@@ -321,11 +321,51 @@ NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) {
return NMD;
}
+/// eraseNamedMetadata - Remove the given NamedMDNode from this module and
+/// delete it.
void Module::eraseNamedMetadata(NamedMDNode *NMD) {
static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab)->erase(NMD->getName());
NamedMDList.erase(NMD);
}
+/// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
+/// represents module-level flags. This method returns null if there are no
+/// module-level flags.
+NamedMDNode *Module::getModuleFlagsMetadata() const {
+ return getNamedMetadata("llvm.module.flags");
+}
+
+/// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module that
+/// represents module-level flags. If module-level flags aren't found, it
+/// creates the named metadata that contains them.
+NamedMDNode *Module::getOrInsertModuleFlagsMetadata() {
+ return getOrInsertNamedMetadata("llvm.module.flags");
+}
+
+/// addModuleFlag - Add a module-level flag to the module-level flags
+/// metadata. It will create the module-level flags named metadata if it doesn't
+/// already exist.
+void Module::addModuleFlag(ModAttrBehavior Behavior, StringRef Key,
+ Value *Val) {
+ Type *Int32Ty = Type::getInt32Ty(Context);
+ Value *Ops[3] = {
+ ConstantInt::get(Int32Ty, Behavior), MDString::get(Context, Key), Val
+ };
+ getOrInsertModuleFlagsMetadata()->addOperand(MDNode::get(Context, Ops));
+}
+void Module::addModuleFlag(ModAttrBehavior Behavior, StringRef Key,
+ uint32_t Val) {
+ Type *Int32Ty = Type::getInt32Ty(Context);
+ addModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
+}
+void Module::addModuleFlag(MDNode *Node) {
+ assert(Node->getNumOperands() == 3 &&
+ "Invalid number of operands for module flag!");
+ assert(isa<ConstantInt>(Node->getOperand(0)) &&
+ isa<MDString>(Node->getOperand(1)) &&
+ "Invalid operand types for module flag!");
+ getOrInsertModuleFlagsMetadata()->addOperand(Node);
+}
//===----------------------------------------------------------------------===//
// Methods to control the materialization of GlobalValues in the Module.
OpenPOWER on IntegriCloud