diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 29dcf5a3c9c..aec7425b0b4 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -431,8 +431,8 @@ protected: public: // Static methods to construct a ConstantExpr of different kinds. - // Unary constant expr - Use with unary operators and casts - static ConstantExpr *get(unsigned Opcode, Constant *C, const Type *Ty); + // Cast constant expr + static ConstantExpr *getCast(Constant *C, const Type *Ty); // Binary constant expr - Use with binary operators... static ConstantExpr *get(unsigned Opcode, Constant *C1, Constant *C2); diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 6b858650b74..923e48d36bb 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -962,7 +962,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr // FIXME: ConstExpr::get never return null! Do checking here in the parser. ConstExpr: Types CAST ConstVal { - $$ = ConstantExpr::get(Instruction::Cast, $3, $1->get()); + $$ = ConstantExpr::getCast($3, $1->get()); delete $1; } | Types GETELEMENTPTR '(' ConstVal IndexList ')' { diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index 921b875644d..37e201f2807 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -217,7 +217,8 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf, // Construct a ConstantExpr of the appropriate kind if (isExprNumArgs == 1) { // All one-operand expressions - V = ConstantExpr::get(Opcode, ArgVec[0], Ty); + assert(Opcode == Instruction::Cast); + V = ConstantExpr::getCast(ArgVec[0], Ty); } else if (Opcode == Instruction::GetElementPtr) { // GetElementPtr std::vector IdxList(ArgVec.begin()+1, ArgVec.end()); V = ConstantExpr::getGetElementPtr(ArgVec[0], IdxList); diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp index 0916b2b876a..0de8f39c579 100644 --- a/lib/Bytecode/Reader/InstructionReader.cpp +++ b/lib/Bytecode/Reader/InstructionReader.cpp @@ -122,13 +122,8 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, if (ParseRawInst(Buf, EndBuf, Raw)) return failure(true); - if (Raw.Opcode >= Instruction::FirstUnaryOp && - Raw.Opcode < Instruction::NumUnaryOps && Raw.NumOperands == 1) { - Res = UnaryOperator::create((Instruction::UnaryOps)Raw.Opcode, - getValue(Raw.Ty,Raw.Arg1)); - return false; - } else if (Raw.Opcode >= Instruction::FirstBinaryOp && - Raw.Opcode < Instruction::NumBinaryOps && Raw.NumOperands == 2) { + if (Raw.Opcode >= Instruction::FirstBinaryOp && + Raw.Opcode < Instruction::NumBinaryOps && Raw.NumOperands == 2) { Res = BinaryOperator::create((Instruction::BinaryOps)Raw.Opcode, getValue(Raw.Ty, Raw.Arg1), getValue(Raw.Ty, Raw.Arg2)); diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 48e40d0b3d9..21e25b444a1 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -119,10 +119,10 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Result = ConstantPointerRef::get(cast(V)); } else if (const ConstantExpr *CE = dyn_cast(CPV)) { if (CE->getNumOperands() == 1) { - // Cast instruction, unary operator + // Cast instruction + assert(CE->getOpcode() == Instruction::Cast); Value *V = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); - Result = ConstantExpr::get(CE->getOpcode(), cast(V), - CE->getType()); + Result = ConstantExpr::getCast(cast(V), CE->getType()); } else if (CE->getNumOperands() == 2) { // Binary operator... Value *V1 = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp index 48e40d0b3d9..21e25b444a1 100644 --- a/lib/Transforms/Utils/Linker.cpp +++ b/lib/Transforms/Utils/Linker.cpp @@ -119,10 +119,10 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Result = ConstantPointerRef::get(cast(V)); } else if (const ConstantExpr *CE = dyn_cast(CPV)) { if (CE->getNumOperands() == 1) { - // Cast instruction, unary operator + // Cast instruction + assert(CE->getOpcode() == Instruction::Cast); Value *V = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); - Result = ConstantExpr::get(CE->getOpcode(), cast(V), - CE->getType()); + Result = ConstantExpr::getCast(cast(V), CE->getType()); } else if (CE->getNumOperands() == 2) { // Binary operator... Value *V1 = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 2aef498b367..ff803dcf61c 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -466,26 +466,16 @@ ConstantPointerRef *ConstantPointerRef::get(GlobalValue *GV) { typedef pair > ExprMapKeyType; static ValueMap ExprConstants; -ConstantExpr *ConstantExpr::get(unsigned Opcode, Constant *C, const Type *Ty) { +ConstantExpr *ConstantExpr::getCast(Constant *C, const Type *Ty) { // Look up the constant in the table first to ensure uniqueness vector argVec(1, C); - const ExprMapKeyType &Key = make_pair(Opcode, argVec); + const ExprMapKeyType &Key = make_pair(Instruction::Cast, argVec); ConstantExpr *Result = ExprConstants.get(Ty, Key); if (Result) return Result; // Its not in the table so create a new one and put it in the table. - // Check the operands for consistency first - assert(Opcode == Instruction::Cast || - (Opcode >= Instruction::FirstUnaryOp && - Opcode < Instruction::NumUnaryOps) && - "Invalid opcode in unary ConstantExpr!"); - - // type of operand will not match result for Cast operation - assert((Opcode == Instruction::Cast || Ty == C->getType()) && - "Type of operand in unary constant expression should match result"); - - Result = new ConstantExpr(Opcode, C, Ty); + Result = new ConstantExpr(Instruction::Cast, C, Ty); ExprConstants.add(Ty, Key, Result); return Result; } diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp index 48e40d0b3d9..21e25b444a1 100644 --- a/lib/VMCore/Linker.cpp +++ b/lib/VMCore/Linker.cpp @@ -119,10 +119,10 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Result = ConstantPointerRef::get(cast(V)); } else if (const ConstantExpr *CE = dyn_cast(CPV)) { if (CE->getNumOperands() == 1) { - // Cast instruction, unary operator + // Cast instruction + assert(CE->getOpcode() == Instruction::Cast); Value *V = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); - Result = ConstantExpr::get(CE->getOpcode(), cast(V), - CE->getType()); + Result = ConstantExpr::getCast(cast(V), CE->getType()); } else if (CE->getNumOperands() == 2) { // Binary operator... Value *V1 = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap);