aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/ValueMapper.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-05-30 05:06:04 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-05-30 05:06:04 +0000
commit7a0370f66ab5739f42ffe822f33494e0de9b182b (patch)
tree45b56951ca455c4f0fffdc0e55733b84608162ef /lib/Transforms/Utils/ValueMapper.cpp
parentc5ca713b8073d9fe95b258d0c01328d020df3357 (diff)
Give embedded metadata its own type instead of relying on EmptyStructTy.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72610 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/ValueMapper.cpp')
-rw-r--r--lib/Transforms/Utils/ValueMapper.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp
index 841e661b37..20b676d0fb 100644
--- a/lib/Transforms/Utils/ValueMapper.cpp
+++ b/lib/Transforms/Utils/ValueMapper.cpp
@@ -16,6 +16,8 @@
#include "llvm/Constants.h"
#include "llvm/GlobalValue.h"
#include "llvm/Instruction.h"
+#include "llvm/MDNode.h"
+#include "llvm/ADT/SmallVector.h"
using namespace llvm;
Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
@@ -33,7 +35,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
if (Constant *C = const_cast<Constant*>(dyn_cast<Constant>(V))) {
if (isa<ConstantInt>(C) || isa<ConstantFP>(C) ||
isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C) ||
- isa<UndefValue>(C))
+ isa<UndefValue>(C) || isa<MDString>(C))
return VMSlot = C; // Primitive constants map directly
else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
for (User::op_iterator b = CA->op_begin(), i = b, e = CA->op_end();
@@ -100,6 +102,27 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
}
return VM[V] = C;
+ } else if (MDNode *N = dyn_cast<MDNode>(C)) {
+ for (MDNode::const_elem_iterator b = N->elem_begin(), i = b,
+ e = N->elem_end(); i != e; ++i) {
+ if (!*i) continue;
+
+ Value *MV = MapValue(*i, VM);
+ if (MV != *i) {
+ // This MDNode must contain a reference to a global, make a new MDNode
+ // and return it.
+ SmallVector<Value*, 8> Values;
+ Values.reserve(N->getNumElements());
+ for (MDNode::const_elem_iterator j = b; j != i; ++j)
+ Values.push_back(*j);
+ Values.push_back(MV);
+ for (++i; i != e; ++i)
+ Values.push_back(MapValue(*i, VM));
+ return VM[V] = MDNode::get(Values.data(), Values.size());
+ }
+ }
+ return VM[V] = C;
+
} else {
assert(0 && "Unknown type of constant!");
}