diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2009-05-30 05:06:04 +0000 | 
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2009-05-30 05:06:04 +0000 | 
| commit | adbc2846667507bdb0b06707b04539aacf4bc6f5 (patch) | |
| tree | e3dcbbaf39e5a96c0c13e7f93bc176521ef4e6d0 /llvm/lib/Transforms | |
| parent | ef334fdfa2a461491301d23ad5f17942ec845d92 (diff) | |
| download | bcm5719-llvm-adbc2846667507bdb0b06707b04539aacf4bc6f5.tar.gz bcm5719-llvm-adbc2846667507bdb0b06707b04539aacf4bc6f5.zip | |
Give embedded metadata its own type instead of relying on EmptyStructTy.
llvm-svn: 72610
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Utils/ValueMapper.cpp | 25 | 
1 files changed, 24 insertions, 1 deletions
| diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index 841e661b374..20b676d0fb8 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/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!");      } | 

