diff options
author | Chris Lattner <sabre@nondot.org> | 2006-07-14 22:21:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-07-14 22:21:31 +0000 |
commit | 27d672136a57519095a3ef20161697749cffb57c (patch) | |
tree | 71f1e15a65b625bc7344c58b79f1f24efb169927 /lib/Linker/LinkModules.cpp | |
parent | b88a7fbdf6365a6d7a4ad334b8411462ae851924 (diff) |
eliminate some ugly code, using ConstantExpr::getWithOperands instead.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29149 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker/LinkModules.cpp')
-rw-r--r-- | lib/Linker/LinkModules.cpp | 55 |
1 files changed, 4 insertions, 51 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 600b21d398..3c87177df3 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -295,57 +295,10 @@ static Value *RemapOperand(const Value *In, Operands[i] = cast<Constant>(RemapOperand(CP->getOperand(i), ValueMap)); Result = ConstantPacked::get(Operands); } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CPV)) { - if (CE->getOpcode() == Instruction::GetElementPtr) { - Value *Ptr = RemapOperand(CE->getOperand(0), ValueMap); - std::vector<Constant*> Indices; - Indices.reserve(CE->getNumOperands()-1); - for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) - Indices.push_back(cast<Constant>(RemapOperand(CE->getOperand(i), - ValueMap))); - - Result = ConstantExpr::getGetElementPtr(cast<Constant>(Ptr), Indices); - } else if (CE->getOpcode() == Instruction::ExtractElement) { - Value *Ptr = RemapOperand(CE->getOperand(0), ValueMap); - Value *Idx = RemapOperand(CE->getOperand(1), ValueMap); - Result = ConstantExpr::getExtractElement(cast<Constant>(Ptr), - cast<Constant>(Idx)); - } else if (CE->getOpcode() == Instruction::InsertElement) { - Value *Ptr = RemapOperand(CE->getOperand(0), ValueMap); - Value *Elt = RemapOperand(CE->getOperand(1), ValueMap); - Value *Idx = RemapOperand(CE->getOperand(2), ValueMap); - Result = ConstantExpr::getInsertElement(cast<Constant>(Ptr), - cast<Constant>(Elt), - cast<Constant>(Idx)); - } else if (CE->getOpcode() == Instruction::ShuffleVector) { - Value *V1 = RemapOperand(CE->getOperand(0), ValueMap); - Value *V2 = RemapOperand(CE->getOperand(1), ValueMap); - Result = ConstantExpr::getShuffleVector(cast<Constant>(V1), - cast<Constant>(V2), - cast<Constant>(CE->getOperand(2))); - } else if (CE->getNumOperands() == 1) { - // Cast instruction - assert(CE->getOpcode() == Instruction::Cast); - Value *V = RemapOperand(CE->getOperand(0), ValueMap); - Result = ConstantExpr::getCast(cast<Constant>(V), CE->getType()); - } else if (CE->getNumOperands() == 3) { - // Select instruction - assert(CE->getOpcode() == Instruction::Select); - Value *V1 = RemapOperand(CE->getOperand(0), ValueMap); - Value *V2 = RemapOperand(CE->getOperand(1), ValueMap); - Value *V3 = RemapOperand(CE->getOperand(2), ValueMap); - Result = ConstantExpr::getSelect(cast<Constant>(V1), cast<Constant>(V2), - cast<Constant>(V3)); - } else if (CE->getNumOperands() == 2) { - // Binary operator... - Value *V1 = RemapOperand(CE->getOperand(0), ValueMap); - Value *V2 = RemapOperand(CE->getOperand(1), ValueMap); - - Result = ConstantExpr::get(CE->getOpcode(), cast<Constant>(V1), - cast<Constant>(V2)); - } else { - assert(0 && "Unknown constant expr type!"); - } - + std::vector<Constant*> Ops; + for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) + Ops.push_back(cast<Constant>(RemapOperand(CE->getOperand(i),ValueMap))); + Result = CE->getWithOperands(Ops); } else { assert(0 && "Unknown type of derived type constant value!"); } |