X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FUtils%2FValueMapper.cpp;h=7a5fcff1117fdc21d75ecb51bce54a917b1730ad;hb=30b434476796cd4a85c02914687d22f2e5ec95ca;hp=e6ab2974283f9893536dd467046795468752632b;hpb=51cbcbf435d1aaa1a5269d62b5d0b31b57316b4a;p=oota-llvm.git diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index e6ab2974283..7a5fcff1117 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -1,4 +1,11 @@ //===- ValueMapper.cpp - Interface shared by lib/Transforms/Utils ---------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by the LLVM research group and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// // // This file defines the MapValue function, which is shared by various parts of // the lib/Transforms/Utils library. @@ -8,14 +15,22 @@ #include "ValueMapper.h" #include "llvm/Constants.h" #include "llvm/Instruction.h" +#include + +using namespace llvm; -Value *MapValue(const Value *V, std::map &VM) { +Value *llvm::MapValue(const Value *V, std::map &VM) { Value *&VMSlot = VM[V]; if (VMSlot) return VMSlot; // Does it exist in the map yet? - if (Constant *C = (Constant*)dyn_cast(V)) { + // Global values do not need to be seeded into the ValueMap if they are using + // the identity mapping. + if (isa(V)) + return VMSlot = const_cast(V); + + if (Constant *C = const_cast(dyn_cast(V))) { if (isa(C) || isa(C) || - isa(C)) + isa(C) || isa(C)) return VMSlot = C; // Primitive constants map directly else if (ConstantPointerRef *CPR = dyn_cast(C)) { GlobalValue *MV = cast(MapValue((Value*)CPR->getValue(),VM)); @@ -33,7 +48,7 @@ Value *MapValue(const Value *V, std::map &VM) { for (unsigned j = 0; j != i; ++j) Values.push_back(cast(Vals[j])); Values.push_back(cast(MV)); - for (; i != e; ++i) + for (++i; i != e; ++i) Values.push_back(cast(MapValue(Vals[i], VM))); return VMSlot = ConstantArray::get(CA->getType(), Values); } @@ -53,7 +68,7 @@ Value *MapValue(const Value *V, std::map &VM) { for (unsigned j = 0; j != i; ++j) Values.push_back(cast(Vals[j])); Values.push_back(cast(MV)); - for (; i != e; ++i) + for (++i; i != e; ++i) Values.push_back(cast(MapValue(Vals[i], VM))); return VMSlot = ConstantStruct::get(CS->getType(), Values); } @@ -81,8 +96,27 @@ Value *MapValue(const Value *V, std::map &VM) { assert(0 && "Unknown type of constant!"); } } - + + V->dump(); assert(0 && "Unknown value type: why didn't it get resolved?!"); return 0; } +/// RemapInstruction - Convert the instruction operands from referencing the +/// current values into those specified by ValueMap. +/// +void llvm::RemapInstruction(Instruction *I, + std::map &ValueMap) { + for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) { + const Value *Op = I->getOperand(op); + Value *V = MapValue(Op, ValueMap); +#ifndef NDEBUG + if (!V) { + std::cerr << "Val = \n" << *Op << "Addr = " << (void*)Op; + std::cerr << "\nInst = " << *I; + } +#endif + assert(V && "Referenced value not in value map!"); + I->setOperand(op, V); + } +}