Changes in directory llvm/lib/Bytecode/Reader:
Reader.cpp updated: 1.198.2.7 -> 1.198.2.8 --- Log message: Round 2 of DIV updates. --- Diffs of the changes: (+348 -342) Reader.cpp | 690 ++++++++++++++++++++++++++++++------------------------------- 1 files changed, 348 insertions(+), 342 deletions(-) Index: llvm/lib/Bytecode/Reader/Reader.cpp diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.198.2.7 llvm/lib/Bytecode/Reader/Reader.cpp:1.198.2.8 --- llvm/lib/Bytecode/Reader/Reader.cpp:1.198.2.7 Mon Oct 23 13:13:26 2006 +++ llvm/lib/Bytecode/Reader/Reader.cpp Wed Oct 25 20:58:05 2006 @@ -562,10 +562,17 @@ insertValue(AI, getTypeSlot(AI->getType()), FunctionValues); } -/// Convert previous opcode values into the current value and/or construct -/// the instruction. This function handles all *abnormal* cases for instruction -/// generation based on obsolete opcode values. The normal cases are handled -/// in ParseInstruction below. +// Convert previous opcode values into the current value and/or construct +// the instruction. This function handles all *abnormal* cases for instruction +// generation based on obsolete opcode values. The normal cases are handled +// in ParseInstruction below. Generally this function just produces a new +// Opcode value (first argument). In a few cases (VAArg, VANext) the upgrade +// path requies that the instruction (sequence) be generated differently from +// the normal case in order to preserve the original semantics. In these +// cases the result of the function will be a non-zero Instruction pointer. In +// all other cases, zero will be returned indicating that the *normal* +// instruction generation should be used, but with the new Opcode value. +// Instruction* BytecodeReader::handleObsoleteOpcodes( unsigned &Opcode, ///< The old opcode, possibly updated by this function @@ -575,11 +582,21 @@ BasicBlock* BB ///< The basic block to insert into, if we need to ) { - // Declare the resulting instruction we might build. + // First, short circuit this if no conversion is required. When signless + // instructions were implemented the entire opcode sequence was revised so + // we key on this first which means that the opcode value read is the one + // we should use. + if (!hasSignlessInstructions) + return 0; // The opcode is fine the way it is. + + // Declare the resulting instruction we might build. In general we just + // change the Opcode argument but in a few cases we need to generate the + // Instruction here because the upgrade case is significantly different from + // the normal case. Instruction *Result = 0; // If this is a bytecode format that did not include the unreachable - // instruction, bump up the opcode number to adjust + // instruction, bump up the opcode number to adjust it. if (hasNoUnreachableInst) { if (Opcode >= Instruction::Unreachable && Opcode < 62) { // 62 @@ -587,20 +604,15 @@ } } - // First, short circuit this if no conversion is required. When signless - // instructions were implemented the entire opcode sequence was revised so - // we key on this first which means that the opcode value read is the one - // we should use. - if (!hasSignlessInstructions) - return Result; - // We're dealing with an upgrade situation. For each of the opcode values, // perform the necessary conversion. switch (Opcode) { - default: // Pass Through - // If we don't match any of the cases here then the opcode is fine the - // way it is. That will happen for the opcodes > 53 which are the - // volatile load/store, and call/invoke with calling conventions. + default: // Error + // This switch statement provides cases for all known opcodes prior to + // version 6 bytecode format. We know we're in an upgrade situation so + // if there isn't a match in this switch, then something is horribly + // wrong. + error("Unknown obsolete opcode encountered."); break; case 1: // Ret Opcode = Instruction::Ret; @@ -886,12 +898,12 @@ handleObsoleteOpcodes(Opcode, Oprnds, iType, InstTy, BB); // We have enough info to inform the handler now. - if (Handler) Handler->handleInstruction(Opcode, InstTy, Oprnds, At-SaveAt); + if (Handler) + Handler->handleInstruction(Opcode, InstTy, Oprnds, At-SaveAt); // If the backwards compatibility code didn't produce an instruction then // we do the *normal* thing .. if (!Result) { - // First, handle the easy binary operators case if (Opcode >= Instruction::BinaryOpsBegin && Opcode < Instruction::BinaryOpsEnd && Oprnds.size() == 2) @@ -900,361 +912,355 @@ getValue(iType, Oprnds[1])); // Indicate that we don't think this is a call instruction (yet). - bool isCall = false; - // Process based on the Opcode read switch (Opcode) { - default: // There was an error, this shouldn't happen. - if (Result == 0) - error("Illegal instruction read!"); - break; - case Instruction::VAArg: - if (Oprnds.size() != 2) - error("Invalid VAArg instruction!"); - Result = new VAArgInst(getValue(iType, Oprnds[0]), - getSanitizedType(Oprnds[1])); - break; - case Instruction::ExtractElement: { - if (Oprnds.size() != 2) - error("Invalid extractelement instruction!"); - Value *V1 = getValue(iType, Oprnds[0]); - Value *V2 = getValue(Type::UIntTyID, Oprnds[1]); - - if (!ExtractElementInst::isValidOperands(V1, V2)) - error("Invalid extractelement instruction!"); + default: // There was an error, this shouldn't happen. + if (Result == 0) + error("Illegal instruction read!"); + break; + case Instruction::VAArg: + if (Oprnds.size() != 2) + error("Invalid VAArg instruction!"); + Result = new VAArgInst(getValue(iType, Oprnds[0]), + getSanitizedType(Oprnds[1])); + break; + case Instruction::ExtractElement: { + if (Oprnds.size() != 2) + error("Invalid extractelement instruction!"); + Value *V1 = getValue(iType, Oprnds[0]); + Value *V2 = getValue(Type::UIntTyID, Oprnds[1]); + + if (!ExtractElementInst::isValidOperands(V1, V2)) + error("Invalid extractelement instruction!"); - Result = new ExtractElementInst(V1, V2); - break; - } - case Instruction::InsertElement: { - const PackedType *PackedTy = dyn_cast<PackedType>(InstTy); - if (!PackedTy || Oprnds.size() != 3) - error("Invalid insertelement instruction!"); + Result = new ExtractElementInst(V1, V2); + break; + } + case Instruction::InsertElement: { + const PackedType *PackedTy = dyn_cast<PackedType>(InstTy); + if (!PackedTy || Oprnds.size() != 3) + error("Invalid insertelement instruction!"); + + Value *V1 = getValue(iType, Oprnds[0]); + Value *V2 = getValue(getTypeSlot(PackedTy->getElementType()),Oprnds[1]); + Value *V3 = getValue(Type::UIntTyID, Oprnds[2]); - Value *V1 = getValue(iType, Oprnds[0]); - Value *V2 = getValue(getTypeSlot(PackedTy->getElementType()),Oprnds[1]); - Value *V3 = getValue(Type::UIntTyID, Oprnds[2]); - - if (!InsertElementInst::isValidOperands(V1, V2, V3)) - error("Invalid insertelement instruction!"); - Result = new InsertElementInst(V1, V2, V3); - break; - } - case Instruction::ShuffleVector: { - const PackedType *PackedTy = dyn_cast<PackedType>(InstTy); - if (!PackedTy || Oprnds.size() != 3) - error("Invalid shufflevector instruction!"); - Value *V1 = getValue(iType, Oprnds[0]); - Value *V2 = getValue(iType, Oprnds[1]); - const PackedType *EltTy = - PackedType::get(Type::UIntTy, PackedTy->getNumElements()); - Value *V3 = getValue(getTypeSlot(EltTy), Oprnds[2]); - if (!ShuffleVectorInst::isValidOperands(V1, V2, V3)) - error("Invalid shufflevector instruction!"); - Result = new ShuffleVectorInst(V1, V2, V3); - break; - } - case Instruction::Cast: - if (Oprnds.size() != 2) - error("Invalid Cast instruction!"); - Result = new CastInst(getValue(iType, Oprnds[0]), - getSanitizedType(Oprnds[1])); - break; - case Instruction::Select: - if (Oprnds.size() != 3) - error("Invalid Select instruction!"); - Result = new SelectInst(getValue(Type::BoolTyID, Oprnds[0]), - getValue(iType, Oprnds[1]), - getValue(iType, Oprnds[2])); - break; - case Instruction::PHI: { - if (Oprnds.size() == 0 || (Oprnds.size() & 1)) - error("Invalid phi node encountered!"); - - PHINode *PN = new PHINode(InstTy); - PN->reserveOperandSpace(Oprnds.size()); - for (unsigned i = 0, e = Oprnds.size(); i != e; i += 2) - PN->addIncoming( - getValue(iType, Oprnds[i]), getBasicBlock(Oprnds[i+1])); - Result = PN; - break; - } + if (!InsertElementInst::isValidOperands(V1, V2, V3)) + error("Invalid insertelement instruction!"); + Result = new InsertElementInst(V1, V2, V3); + break; + } + case Instruction::ShuffleVector: { + const PackedType *PackedTy = dyn_cast<PackedType>(InstTy); + if (!PackedTy || Oprnds.size() != 3) + error("Invalid shufflevector instruction!"); + Value *V1 = getValue(iType, Oprnds[0]); + Value *V2 = getValue(iType, Oprnds[1]); + const PackedType *EltTy = + PackedType::get(Type::UIntTy, PackedTy->getNumElements()); + Value *V3 = getValue(getTypeSlot(EltTy), Oprnds[2]); + if (!ShuffleVectorInst::isValidOperands(V1, V2, V3)) + error("Invalid shufflevector instruction!"); + Result = new ShuffleVectorInst(V1, V2, V3); + break; + } + case Instruction::Cast: + if (Oprnds.size() != 2) + error("Invalid Cast instruction!"); + Result = new CastInst(getValue(iType, Oprnds[0]), + getSanitizedType(Oprnds[1])); + break; + case Instruction::Select: + if (Oprnds.size() != 3) + error("Invalid Select instruction!"); + Result = new SelectInst(getValue(Type::BoolTyID, Oprnds[0]), + getValue(iType, Oprnds[1]), + getValue(iType, Oprnds[2])); + break; + case Instruction::PHI: { + if (Oprnds.size() == 0 || (Oprnds.size() & 1)) + error("Invalid phi node encountered!"); + + PHINode *PN = new PHINode(InstTy); + PN->reserveOperandSpace(Oprnds.size()); + for (unsigned i = 0, e = Oprnds.size(); i != e; i += 2) + PN->addIncoming( + getValue(iType, Oprnds[i]), getBasicBlock(Oprnds[i+1])); + Result = PN; + break; + } - case Instruction::Shl: - case Instruction::Shr: - Result = new ShiftInst(Instruction::OtherOps(Opcode), - getValue(iType, Oprnds[0]), - getValue(Type::UByteTyID, Oprnds[1])); - break; - case Instruction::Ret: - if (Oprnds.size() == 0) - Result = new ReturnInst(); - else if (Oprnds.size() == 1) - Result = new ReturnInst(getValue(iType, Oprnds[0])); - else - error("Unrecognized instruction!"); - break; - - case Instruction::Br: - if (Oprnds.size() == 1) - Result = new BranchInst(getBasicBlock(Oprnds[0])); - else if (Oprnds.size() == 3) - Result = new BranchInst(getBasicBlock(Oprnds[0]), - getBasicBlock(Oprnds[1]), getValue(Type::BoolTyID , Oprnds[2])); - else - error("Invalid number of operands for a 'br' instruction!"); - break; - case Instruction::Switch: { - if (Oprnds.size() & 1) - error("Switch statement with odd number of arguments!"); - - SwitchInst *I = new SwitchInst(getValue(iType, Oprnds[0]), - getBasicBlock(Oprnds[1]), - Oprnds.size()/2-1); - for (unsigned i = 2, e = Oprnds.size(); i != e; i += 2) - I->addCase(cast<ConstantInt>(getValue(iType, Oprnds[i])), - getBasicBlock(Oprnds[i+1])); - Result = I; - break; - } + case Instruction::Shl: + case Instruction::Shr: + Result = new ShiftInst(Instruction::OtherOps(Opcode), + getValue(iType, Oprnds[0]), + getValue(Type::UByteTyID, Oprnds[1])); + break; + case Instruction::Ret: + if (Oprnds.size() == 0) + Result = new ReturnInst(); + else if (Oprnds.size() == 1) + Result = new ReturnInst(getValue(iType, Oprnds[0])); + else + error("Unrecognized instruction!"); + break; - case 58: // Call with extra operand for calling conv - case 59: // tail call, Fast CC - case 60: // normal call, Fast CC - case 61: // tail call, C Calling Conv - case Instruction::Call: { // Normal Call, C Calling Convention - if (Oprnds.size() == 0) - error("Invalid call instruction encountered!"); + case Instruction::Br: + if (Oprnds.size() == 1) + Result = new BranchInst(getBasicBlock(Oprnds[0])); + else if (Oprnds.size() == 3) + Result = new BranchInst(getBasicBlock(Oprnds[0]), + getBasicBlock(Oprnds[1]), getValue(Type::BoolTyID , Oprnds[2])); + else + error("Invalid number of operands for a 'br' instruction!"); + break; + case Instruction::Switch: { + if (Oprnds.size() & 1) + error("Switch statement with odd number of arguments!"); + + SwitchInst *I = new SwitchInst(getValue(iType, Oprnds[0]), + getBasicBlock(Oprnds[1]), + Oprnds.size()/2-1); + for (unsigned i = 2, e = Oprnds.size(); i != e; i += 2) + I->addCase(cast<ConstantInt>(getValue(iType, Oprnds[i])), + getBasicBlock(Oprnds[i+1])); + Result = I; + break; + } + case 58: // Call with extra operand for calling conv + case 59: // tail call, Fast CC + case 60: // normal call, Fast CC + case 61: // tail call, C Calling Conv + case Instruction::Call: { // Normal Call, C Calling Convention + if (Oprnds.size() == 0) + error("Invalid call instruction encountered!"); - Value *F = getValue(iType, Oprnds[0]); + Value *F = getValue(iType, Oprnds[0]); - unsigned CallingConv = CallingConv::C; - bool isTailCall = false; + unsigned CallingConv = CallingConv::C; + bool isTailCall = false; - if (Opcode == 61 || Opcode == 59) - isTailCall = true; - - if (Opcode == 58) { - isTailCall = Oprnds.back() & 1; - CallingConv = Oprnds.back() >> 1; - Oprnds.pop_back(); - } else if (Opcode == 59 || Opcode == 60) { - CallingConv = CallingConv::Fast; - } - - // Check to make sure we have a pointer to function type - const PointerType *PTy = dyn_cast<PointerType>(F->getType()); - if (PTy == 0) error("Call to non function pointer value!"); - const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType()); - if (FTy == 0) error("Call to non function pointer value!"); - - std::vector<Value *> Params; - if (!FTy->isVarArg()) { - FunctionType::param_iterator It = FTy->param_begin(); - - for (unsigned i = 1, e = Oprnds.size(); i != e; ++i) { - if (It == FTy->param_end()) - error("Invalid call instruction!"); - Params.push_back(getValue(getTypeSlot(*It++), Oprnds[i])); - } - if (It != FTy->param_end()) - error("Invalid call instruction!"); - } else { - Oprnds.erase(Oprnds.begin(), Oprnds.begin()+1); + if (Opcode == 61 || Opcode == 59) + isTailCall = true; + + if (Opcode == 58) { + isTailCall = Oprnds.back() & 1; + CallingConv = Oprnds.back() >> 1; + Oprnds.pop_back(); + } else if (Opcode == 59 || Opcode == 60) { + CallingConv = CallingConv::Fast; + } + + // Check to make sure we have a pointer to function type + const PointerType *PTy = dyn_cast<PointerType>(F->getType()); + if (PTy == 0) error("Call to non function pointer value!"); + const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType()); + if (FTy == 0) error("Call to non function pointer value!"); + + std::vector<Value *> Params; + if (!FTy->isVarArg()) { + FunctionType::param_iterator It = FTy->param_begin(); - unsigned FirstVariableOperand; - if (Oprnds.size() < FTy->getNumParams()) - error("Call instruction missing operands!"); + for (unsigned i = 1, e = Oprnds.size(); i != e; ++i) { + if (It == FTy->param_end()) + error("Invalid call instruction!"); + Params.push_back(getValue(getTypeSlot(*It++), Oprnds[i])); + } + if (It != FTy->param_end()) + error("Invalid call instruction!"); + } else { + Oprnds.erase(Oprnds.begin(), Oprnds.begin()+1); - // Read all of the fixed arguments - for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) - Params.push_back( - getValue(getTypeSlot(FTy->getParamType(i)),Oprnds[i])); + unsigned FirstVariableOperand; + if (Oprnds.size() < FTy->getNumParams()) + error("Call instruction missing operands!"); - FirstVariableOperand = FTy->getNumParams(); + // Read all of the fixed arguments + for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) + Params.push_back( + getValue(getTypeSlot(FTy->getParamType(i)),Oprnds[i])); - if ((Oprnds.size()-FirstVariableOperand) & 1) - error("Invalid call instruction!"); // Must be pairs of type/value + FirstVariableOperand = FTy->getNumParams(); - for (unsigned i = FirstVariableOperand, e = Oprnds.size(); - i != e; i += 2) - Params.push_back(getValue(Oprnds[i], Oprnds[i+1])); - } + if ((Oprnds.size()-FirstVariableOperand) & 1) + error("Invalid call instruction!"); // Must be pairs of type/value - Result = new CallInst(F, Params); - if (isTailCall) cast<CallInst>(Result)->setTailCall(); - if (CallingConv) cast<CallInst>(Result)->setCallingConv(CallingConv); - break; + for (unsigned i = FirstVariableOperand, e = Oprnds.size(); + i != e; i += 2) + Params.push_back(getValue(Oprnds[i], Oprnds[i+1])); } - case 56: // Invoke with encoded CC - case 57: // Invoke Fast CC - case Instruction::Invoke: { // Invoke C CC - if (Oprnds.size() < 3) - error("Invalid invoke instruction!"); - Value *F = getValue(iType, Oprnds[0]); - // Check to make sure we have a pointer to function type - const PointerType *PTy = dyn_cast<PointerType>(F->getType()); - if (PTy == 0) - error("Invoke to non function pointer value!"); - const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType()); - if (FTy == 0) - error("Invoke to non function pointer value!"); - - std::vector<Value *> Params; - BasicBlock *Normal, *Except; - unsigned CallingConv = CallingConv::C; - - if (Opcode == 57) - CallingConv = CallingConv::Fast; - else if (Opcode == 56) { - CallingConv = Oprnds.back(); - Oprnds.pop_back(); - } + Result = new CallInst(F, Params); + if (isTailCall) cast<CallInst>(Result)->setTailCall(); + if (CallingConv) cast<CallInst>(Result)->setCallingConv(CallingConv); + break; + } + case 56: // Invoke with encoded CC + case 57: // Invoke Fast CC + case Instruction::Invoke: { // Invoke C CC + if (Oprnds.size() < 3) + error("Invalid invoke instruction!"); + Value *F = getValue(iType, Oprnds[0]); + + // Check to make sure we have a pointer to function type + const PointerType *PTy = dyn_cast<PointerType>(F->getType()); + if (PTy == 0) + error("Invoke to non function pointer value!"); + const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType()); + if (FTy == 0) + error("Invoke to non function pointer value!"); + + std::vector<Value *> Params; + BasicBlock *Normal, *Except; + unsigned CallingConv = CallingConv::C; + + if (Opcode == 57) + CallingConv = CallingConv::Fast; + else if (Opcode == 56) { + CallingConv = Oprnds.back(); + Oprnds.pop_back(); + } - if (!FTy->isVarArg()) { - Normal = getBasicBlock(Oprnds[1]); - Except = getBasicBlock(Oprnds[2]); - - FunctionType::param_iterator It = FTy->param_begin(); - for (unsigned i = 3, e = Oprnds.size(); i != e; ++i) { - if (It == FTy->param_end()) - error("Invalid invoke instruction!"); - Params.push_back(getValue(getTypeSlot(*It++), Oprnds[i])); - } - if (It != FTy->param_end()) + if (!FTy->isVarArg()) { + Normal = getBasicBlock(Oprnds[1]); + Except = getBasicBlock(Oprnds[2]); + + FunctionType::param_iterator It = FTy->param_begin(); + for (unsigned i = 3, e = Oprnds.size(); i != e; ++i) { + if (It == FTy->param_end()) error("Invalid invoke instruction!"); - } else { - Oprnds.erase(Oprnds.begin(), Oprnds.begin()+1); - - Normal = getBasicBlock(Oprnds[0]); - Except = getBasicBlock(Oprnds[1]); + Params.push_back(getValue(getTypeSlot(*It++), Oprnds[i])); + } + if (It != FTy->param_end()) + error("Invalid invoke instruction!"); + } else { + Oprnds.erase(Oprnds.begin(), Oprnds.begin()+1); - unsigned FirstVariableArgument = FTy->getNumParams()+2; - for (unsigned i = 2; i != FirstVariableArgument; ++i) - Params.push_back(getValue(getTypeSlot(FTy->getParamType(i-2)), - Oprnds[i])); + Normal = getBasicBlock(Oprnds[0]); + Except = getBasicBlock(Oprnds[1]); - // Must be type/value pairs. If not, error out. - if (Oprnds.size()-FirstVariableArgument & 1) - error("Invalid invoke instruction!"); + unsigned FirstVariableArgument = FTy->getNumParams()+2; + for (unsigned i = 2; i != FirstVariableArgument; ++i) + Params.push_back(getValue(getTypeSlot(FTy->getParamType(i-2)), + Oprnds[i])); - for (unsigned i = FirstVariableArgument; i < Oprnds.size(); i += 2) - Params.push_back(getValue(Oprnds[i], Oprnds[i+1])); - } + // Must be type/value pairs. If not, error out. + if (Oprnds.size()-FirstVariableArgument & 1) + error("Invalid invoke instruction!"); - Result = new InvokeInst(F, Normal, Except, Params); - if (CallingConv) cast<InvokeInst>(Result)->setCallingConv(CallingConv); - break; - } - case Instruction::Malloc: { - unsigned Align = 0; - if (Oprnds.size() == 2) - Align = (1 << Oprnds[1]) >> 1; - else if (Oprnds.size() > 2) - error("Invalid malloc instruction!"); - if (!isa<PointerType>(InstTy)) - error("Invalid malloc instruction!"); - - Result = new MallocInst(cast<PointerType>(InstTy)->getElementType(), - getValue(Type::UIntTyID, Oprnds[0]), Align); - break; + for (unsigned i = FirstVariableArgument; i < Oprnds.size(); i += 2) + Params.push_back(getValue(Oprnds[i], Oprnds[i+1])); } - case Instruction::Alloca: { - unsigned Align = 0; - if (Oprnds.size() == 2) - Align = (1 << Oprnds[1]) >> 1; - else if (Oprnds.size() > 2) - error("Invalid alloca instruction!"); - if (!isa<PointerType>(InstTy)) - error("Invalid alloca instruction!"); - - Result = new AllocaInst(cast<PointerType>(InstTy)->getElementType(), - getValue(Type::UIntTyID, Oprnds[0]), Align); - break; - } - case Instruction::Free: - if (!isa<PointerType>(InstTy)) - error("Invalid free instruction!"); - Result = new FreeInst(getValue(iType, Oprnds[0])); - break; - case Instruction::GetElementPtr: { - if (Oprnds.size() == 0 || !isa<PointerType>(InstTy)) + Result = new InvokeInst(F, Normal, Except, Params); + if (CallingConv) cast<InvokeInst>(Result)->setCallingConv(CallingConv); + break; + } + case Instruction::Malloc: { + unsigned Align = 0; + if (Oprnds.size() == 2) + Align = (1 << Oprnds[1]) >> 1; + else if (Oprnds.size() > 2) + error("Invalid malloc instruction!"); + if (!isa<PointerType>(InstTy)) + error("Invalid malloc instruction!"); + + Result = new MallocInst(cast<PointerType>(InstTy)->getElementType(), + getValue(Type::UIntTyID, Oprnds[0]), Align); + break; + } + case Instruction::Alloca: { + unsigned Align = 0; + if (Oprnds.size() == 2) + Align = (1 << Oprnds[1]) >> 1; + else if (Oprnds.size() > 2) + error("Invalid alloca instruction!"); + if (!isa<PointerType>(InstTy)) + error("Invalid alloca instruction!"); + + Result = new AllocaInst(cast<PointerType>(InstTy)->getElementType(), + getValue(Type::UIntTyID, Oprnds[0]), Align); + break; + } + case Instruction::Free: + if (!isa<PointerType>(InstTy)) + error("Invalid free instruction!"); + Result = new FreeInst(getValue(iType, Oprnds[0])); + break; + case Instruction::GetElementPtr: { + if (Oprnds.size() == 0 || !isa<PointerType>(InstTy)) + error("Invalid getelementptr instruction!"); + + std::vector<Value*> Idx; + + const Type *NextTy = InstTy; + for (unsigned i = 1, e = Oprnds.size(); i != e; ++i) { + const CompositeType *TopTy = dyn_cast_or_null<CompositeType>(NextTy); + if (!TopTy) error("Invalid getelementptr instruction!"); - std::vector<Value*> Idx; - - const Type *NextTy = InstTy; - for (unsigned i = 1, e = Oprnds.size(); i != e; ++i) { - const CompositeType *TopTy = dyn_cast_or_null<CompositeType>(NextTy); - if (!TopTy) - error("Invalid getelementptr instruction!"); - - unsigned ValIdx = Oprnds[i]; - unsigned IdxTy = 0; - if (!hasRestrictedGEPTypes) { - // Struct indices are always uints, sequential type indices can be - // any of the 32 or 64-bit integer types. The actual choice of - // type is encoded in the low two bits of the slot number. - if (isa<StructType>(TopTy)) - IdxTy = Type::UIntTyID; - else { - switch (ValIdx & 3) { - default: - case 0: IdxTy = Type::UIntTyID; break; - case 1: IdxTy = Type::IntTyID; break; - case 2: IdxTy = Type::ULongTyID; break; - case 3: IdxTy = Type::LongTyID; break; - } - ValIdx >>= 2; + unsigned ValIdx = Oprnds[i]; + unsigned IdxTy = 0; + if (!hasRestrictedGEPTypes) { + // Struct indices are always uints, sequential type indices can be + // any of the 32 or 64-bit integer types. The actual choice of + // type is encoded in the low two bits of the slot number. + if (isa<StructType>(TopTy)) + IdxTy = Type::UIntTyID; + else { + switch (ValIdx & 3) { + default: + case 0: IdxTy = Type::UIntTyID; break; + case 1: IdxTy = Type::IntTyID; break; + case 2: IdxTy = Type::ULongTyID; break; + case 3: IdxTy = Type::LongTyID; break; } - } else { - IdxTy = isa<StructType>(TopTy) ? Type::UByteTyID : Type::LongTyID; + ValIdx >>= 2; } + } else { + IdxTy = isa<StructType>(TopTy) ? Type::UByteTyID : Type::LongTyID; + } - Idx.push_back(getValue(IdxTy, ValIdx)); - - // Convert ubyte struct indices into uint struct indices. - if (isa<StructType>(TopTy) && hasRestrictedGEPTypes) - if (ConstantInt *C = dyn_cast<ConstantInt>(Idx.back())) - if (C->getType() == Type::UByteTy) - Idx[Idx.size()-1] = ConstantExpr::getCast(C, Type::UIntTy); + Idx.push_back(getValue(IdxTy, ValIdx)); - NextTy = GetElementPtrInst::getIndexedType(InstTy, Idx, true); - } + // Convert ubyte struct indices into uint struct indices. + if (isa<StructType>(TopTy) && hasRestrictedGEPTypes) + if (ConstantInt *C = dyn_cast<ConstantInt>(Idx.back())) + if (C->getType() == Type::UByteTy) + Idx[Idx.size()-1] = ConstantExpr::getCast(C, Type::UIntTy); - Result = new GetElementPtrInst(getValue(iType, Oprnds[0]), Idx); - break; + NextTy = GetElementPtrInst::getIndexedType(InstTy, Idx, true); } - case 62: // volatile load - case Instruction::Load: - if (Oprnds.size() != 1 || !isa<PointerType>(InstTy)) - error("Invalid load instruction!"); - Result = new LoadInst(getValue(iType, Oprnds[0]), "", Opcode == 62); - break; - - case 63: // volatile store - case Instruction::Store: { - if (!isa<PointerType>(InstTy) || Oprnds.size() != 2) - error("Invalid store instruction!"); - - Value *Ptr = getValue(iType, Oprnds[1]); - const Type *ValTy = cast<PointerType>(Ptr->getType())->getElementType(); - Result = new StoreInst(getValue(getTypeSlot(ValTy), Oprnds[0]), Ptr, - Opcode == 63); - break; - } - case Instruction::Unwind: - if (Oprnds.size() != 0) error("Invalid unwind instruction!"); - Result = new UnwindInst(); - break; - case Instruction::Unreachable: - if (Oprnds.size() != 0) error("Invalid unreachable instruction!"); - Result = new UnreachableInst(); - break; - } // end switch(Opcode) + Result = new GetElementPtrInst(getValue(iType, Oprnds[0]), Idx); + break; + } + case 62: // volatile load + case Instruction::Load: + if (Oprnds.size() != 1 || !isa<PointerType>(InstTy)) + error("Invalid load instruction!"); + Result = new LoadInst(getValue(iType, Oprnds[0]), "", Opcode == 62); + break; + case 63: // volatile store + case Instruction::Store: { + if (!isa<PointerType>(InstTy) || Oprnds.size() != 2) + error("Invalid store instruction!"); + + Value *Ptr = getValue(iType, Oprnds[1]); + const Type *ValTy = cast<PointerType>(Ptr->getType())->getElementType(); + Result = new StoreInst(getValue(getTypeSlot(ValTy), Oprnds[0]), Ptr, + Opcode == 63); + break; + } + case Instruction::Unwind: + if (Oprnds.size() != 0) error("Invalid unwind instruction!"); + Result = new UnwindInst(); + break; + case Instruction::Unreachable: + if (Oprnds.size() != 0) error("Invalid unreachable instruction!"); + Result = new UnreachableInst(); + break; + } // end switch(Opcode) } // end if *normal* BB->getInstList().push_back(Result); @@ -1622,7 +1628,7 @@ } } -// Upgrade obsolte constant expression opcodes (ver. 5 and prior) to the new +// Upgrade obsolete constant expression opcodes (ver. 5 and prior) to the new // values used after ver 6. bytecode format. The operands are provided to the // function so that decisions based on the operand type can be made when // auto-upgrading obsolete opcodes to the new ones. @@ -2652,7 +2658,7 @@ // FALL THROUGH - case 6: // SignlessTypes Implementation (1.10 release) + case 6: // SignlessTypes Implementation (1.9 release) break; default: _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits