Use the version of getValue that takes the type plane instead of the type

if possible.  This provides a consistent 8.5% speedup.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8991 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2003-10-09 22:39:30 +00:00
parent 6fcf50338e
commit 35d2ca672b
2 changed files with 18 additions and 17 deletions

View File

@ -112,34 +112,34 @@ Instruction *BytecodeParser::ParseInstruction(const unsigned char *&Buf,
if (RI.Opcode >= Instruction::BinaryOpsBegin && if (RI.Opcode >= Instruction::BinaryOpsBegin &&
RI.Opcode < Instruction::BinaryOpsEnd && Args.size() == 2) RI.Opcode < Instruction::BinaryOpsEnd && Args.size() == 2)
return BinaryOperator::create((Instruction::BinaryOps)RI.Opcode, return BinaryOperator::create((Instruction::BinaryOps)RI.Opcode,
getValue(InstTy, Args[0]), getValue(RI.Type, Args[0]),
getValue(InstTy, Args[1])); getValue(RI.Type, Args[1]));
switch (RI.Opcode) { switch (RI.Opcode) {
case Instruction::VarArg: case Instruction::VarArg:
return new VarArgInst(getValue(InstTy, Args[0]), getType(Args[1])); return new VarArgInst(getValue(RI.Type, Args[0]), getType(Args[1]));
case Instruction::Cast: case Instruction::Cast:
return new CastInst(getValue(InstTy, Args[0]), getType(Args[1])); return new CastInst(getValue(RI.Type, Args[0]), getType(Args[1]));
case Instruction::PHINode: { case Instruction::PHINode: {
if (Args.size() == 0 || (Args.size() & 1)) if (Args.size() == 0 || (Args.size() & 1))
throw std::string("Invalid phi node encountered!\n"); throw std::string("Invalid phi node encountered!\n");
PHINode *PN = new PHINode(InstTy); PHINode *PN = new PHINode(InstTy);
for (unsigned i = 0, e = Args.size(); i != e; i += 2) for (unsigned i = 0, e = Args.size(); i != e; i += 2)
PN->addIncoming(getValue(InstTy, Args[i]), getBasicBlock(Args[i+1])); PN->addIncoming(getValue(RI.Type, Args[i]), getBasicBlock(Args[i+1]));
return PN; return PN;
} }
case Instruction::Shl: case Instruction::Shl:
case Instruction::Shr: case Instruction::Shr:
return new ShiftInst((Instruction::OtherOps)RI.Opcode, return new ShiftInst((Instruction::OtherOps)RI.Opcode,
getValue(InstTy, Args[0]), getValue(RI.Type, Args[0]),
getValue(Type::UByteTyID, Args[1])); getValue(Type::UByteTyID, Args[1]));
case Instruction::Ret: case Instruction::Ret:
if (Args.size() == 0) if (Args.size() == 0)
return new ReturnInst(); return new ReturnInst();
else if (Args.size() == 1) else if (Args.size() == 1)
return new ReturnInst(getValue(InstTy, Args[0])); return new ReturnInst(getValue(RI.Type, Args[0]));
break; break;
case Instruction::Br: case Instruction::Br:
@ -154,10 +154,10 @@ Instruction *BytecodeParser::ParseInstruction(const unsigned char *&Buf,
if (Args.size() & 1) if (Args.size() & 1)
throw std::string("Switch statement with odd number of arguments!"); throw std::string("Switch statement with odd number of arguments!");
SwitchInst *I = new SwitchInst(getValue(InstTy, Args[0]), SwitchInst *I = new SwitchInst(getValue(RI.Type, Args[0]),
getBasicBlock(Args[1])); getBasicBlock(Args[1]));
for (unsigned i = 2, e = Args.size(); i != e; i += 2) for (unsigned i = 2, e = Args.size(); i != e; i += 2)
I->addCase(cast<Constant>(getValue(InstTy, Args[i])), I->addCase(cast<Constant>(getValue(RI.Type, Args[i])),
getBasicBlock(Args[i+1])); getBasicBlock(Args[i+1]));
return I; return I;
} }
@ -166,7 +166,7 @@ Instruction *BytecodeParser::ParseInstruction(const unsigned char *&Buf,
if (Args.size() == 0) if (Args.size() == 0)
throw std::string("Invalid call instruction encountered!"); throw std::string("Invalid call instruction encountered!");
Value *F = getValue(InstTy, Args[0]); Value *F = getValue(RI.Type, Args[0]);
// Check to make sure we have a pointer to function type // Check to make sure we have a pointer to function type
const PointerType *PTy = dyn_cast<PointerType>(F->getType()); const PointerType *PTy = dyn_cast<PointerType>(F->getType());
@ -192,14 +192,14 @@ Instruction *BytecodeParser::ParseInstruction(const unsigned char *&Buf,
throw std::string("Invalid call instruction!"); throw std::string("Invalid call instruction!");
for (unsigned i = 2, e = Args.size(); i != e; i += 2) for (unsigned i = 2, e = Args.size(); i != e; i += 2)
Params.push_back(getValue(getType(Args[i]), Args[i+1])); Params.push_back(getValue(Args[i], Args[i+1]));
} }
return new CallInst(F, Params); return new CallInst(F, Params);
} }
case Instruction::Invoke: { case Instruction::Invoke: {
if (Args.size() < 3) throw std::string("Invalid invoke instruction!"); if (Args.size() < 3) throw std::string("Invalid invoke instruction!");
Value *F = getValue(InstTy, Args[0]); Value *F = getValue(RI.Type, Args[0]);
// Check to make sure we have a pointer to function type // Check to make sure we have a pointer to function type
const PointerType *PTy = dyn_cast<PointerType>(F->getType()); const PointerType *PTy = dyn_cast<PointerType>(F->getType());
@ -261,7 +261,7 @@ Instruction *BytecodeParser::ParseInstruction(const unsigned char *&Buf,
case Instruction::Free: case Instruction::Free:
if (!isa<PointerType>(InstTy)) if (!isa<PointerType>(InstTy))
throw std::string("Invalid free instruction!"); throw std::string("Invalid free instruction!");
return new FreeInst(getValue(InstTy, Args[0])); return new FreeInst(getValue(RI.Type, Args[0]));
case Instruction::GetElementPtr: { case Instruction::GetElementPtr: {
if (Args.size() == 0 || !isa<PointerType>(InstTy)) if (Args.size() == 0 || !isa<PointerType>(InstTy))
@ -277,21 +277,21 @@ Instruction *BytecodeParser::ParseInstruction(const unsigned char *&Buf,
NextTy = GetElementPtrInst::getIndexedType(InstTy, Idx, true); NextTy = GetElementPtrInst::getIndexedType(InstTy, Idx, true);
} }
return new GetElementPtrInst(getValue(InstTy, Args[0]), Idx); return new GetElementPtrInst(getValue(RI.Type, Args[0]), Idx);
} }
case 62: // volatile load case 62: // volatile load
case Instruction::Load: case Instruction::Load:
if (Args.size() != 1 || !isa<PointerType>(InstTy)) if (Args.size() != 1 || !isa<PointerType>(InstTy))
throw std::string("Invalid load instruction!"); throw std::string("Invalid load instruction!");
return new LoadInst(getValue(InstTy, Args[0]), "", RI.Opcode == 62); return new LoadInst(getValue(RI.Type, Args[0]), "", RI.Opcode == 62);
case 63: // volatile store case 63: // volatile store
case Instruction::Store: { case Instruction::Store: {
if (!isa<PointerType>(InstTy) || Args.size() != 2) if (!isa<PointerType>(InstTy) || Args.size() != 2)
throw std::string("Invalid store instruction!"); throw std::string("Invalid store instruction!");
Value *Ptr = getValue(InstTy, Args[1]); Value *Ptr = getValue(RI.Type, Args[1]);
const Type *ValTy = cast<PointerType>(Ptr->getType())->getElementType(); const Type *ValTy = cast<PointerType>(Ptr->getType())->getElementType();
return new StoreInst(getValue(ValTy, Args[0]), Ptr, RI.Opcode == 63); return new StoreInst(getValue(ValTy, Args[0]), Ptr, RI.Opcode == 63);
} }

View File

@ -385,7 +385,8 @@ void BytecodeParser::materializeFunction(Function* F) {
// Resolve forward references // Resolve forward references
while (!ForwardReferences.empty()) { while (!ForwardReferences.empty()) {
std::map<std::pair<unsigned,unsigned>, Value*>::iterator I = ForwardReferences.begin(); std::map<std::pair<unsigned,unsigned>, Value*>::iterator I =
ForwardReferences.begin();
unsigned type = I->first.first; unsigned type = I->first.first;
unsigned Slot = I->first.second; unsigned Slot = I->first.second;
Value *PlaceHolder = I->second; Value *PlaceHolder = I->second;