From: Chris Lattner Date: Sun, 1 Nov 2009 02:46:39 +0000 (+0000) Subject: implement linker support for BlockAddress. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2a749d36475bda8964e996725ea101aec3ee15cf;p=oota-llvm.git implement linker support for BlockAddress. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85700 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index e64c200cf63..8ece835bfe7 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -349,8 +349,7 @@ static void PrintMap(const std::map &M) { // RemapOperand - Use ValueMap to convert constants from one module to another. static Value *RemapOperand(const Value *In, - std::map &ValueMap, - LLVMContext &Context) { + std::map &ValueMap) { std::map::const_iterator I = ValueMap.find(In); if (I != ValueMap.end()) return I->second; @@ -365,31 +364,29 @@ static Value *RemapOperand(const Value *In, if (const ConstantArray *CPA = dyn_cast(CPV)) { std::vector Operands(CPA->getNumOperands()); for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i) - Operands[i] =cast(RemapOperand(CPA->getOperand(i), ValueMap, - Context)); - Result = - ConstantArray::get(cast(CPA->getType()), Operands); + Operands[i] =cast(RemapOperand(CPA->getOperand(i), ValueMap)); + Result = ConstantArray::get(cast(CPA->getType()), Operands); } else if (const ConstantStruct *CPS = dyn_cast(CPV)) { std::vector Operands(CPS->getNumOperands()); for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i) - Operands[i] =cast(RemapOperand(CPS->getOperand(i), ValueMap, - Context)); - Result = - ConstantStruct::get(cast(CPS->getType()), Operands); + Operands[i] =cast(RemapOperand(CPS->getOperand(i), ValueMap)); + Result = ConstantStruct::get(cast(CPS->getType()), Operands); } else if (isa(CPV) || isa(CPV)) { Result = const_cast(CPV); } else if (const ConstantVector *CP = dyn_cast(CPV)) { std::vector Operands(CP->getNumOperands()); for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i) - Operands[i] = cast(RemapOperand(CP->getOperand(i), ValueMap, - Context)); + Operands[i] = cast(RemapOperand(CP->getOperand(i), ValueMap)); Result = ConstantVector::get(Operands); } else if (const ConstantExpr *CE = dyn_cast(CPV)) { std::vector Ops; for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) - Ops.push_back(cast(RemapOperand(CE->getOperand(i),ValueMap, - Context))); + Ops.push_back(cast(RemapOperand(CE->getOperand(i),ValueMap))); Result = CE->getWithOperands(Ops); + } else if (const BlockAddress *CE = dyn_cast(CPV)) { + Result = BlockAddress::get( + cast(RemapOperand(CE->getFunction(), ValueMap)), + CE->getBasicBlock()); } else { assert(!isa(CPV) && "Unmapped global?"); llvm_unreachable("Unknown type of derived type constant value!"); @@ -896,8 +893,7 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src, if (SGV->hasInitializer()) { // Only process initialized GV's // Figure out what the initializer looks like in the dest module... Constant *SInit = - cast(RemapOperand(SGV->getInitializer(), ValueMap, - Dest->getContext())); + cast(RemapOperand(SGV->getInitializer(), ValueMap)); // Grab destination global variable or alias. GlobalValue *DGV = cast(ValueMap[SGV]->stripPointerCasts()); @@ -1084,7 +1080,7 @@ static bool LinkFunctionBody(Function *Dest, Function *Src, for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end(); OI != OE; ++OI) if (!isa(*OI) && !isa(*OI)) - *OI = RemapOperand(*OI, ValueMap, Dest->getContext()); + *OI = RemapOperand(*OI, ValueMap); // There is no need to map the arguments anymore. for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end();