From 4ee8ef2a5d5a28cf5255b986d57dc658fa060479 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 8 Oct 2003 22:52:54 +0000 Subject: This patch substantially simplifies and cleans up handling of basic blocks in the bytecode parser. Before we tried to shoehorn basic blocks into the "getValue" code path with other types of values. For a variety of reasons this was a bad idea, so this patch separates it out into its own data structure. This simplifies the code, makes it fit in 80 columns, and is also much faster. In a testcase provided by Bill, which has lots of PHI nodes, this patch speeds up bytecode parsing from taking 6.9s to taking 2.32s. More speedups to follow later. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8977 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bytecode/Reader/InstructionReader.cpp | 37 ++++++++++++++----------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'lib/Bytecode/Reader/InstructionReader.cpp') diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp index d8a6af0179..2f2e7960d6 100644 --- a/lib/Bytecode/Reader/InstructionReader.cpp +++ b/lib/Bytecode/Reader/InstructionReader.cpp @@ -161,12 +161,11 @@ bool BytecodeParser::ParseInstruction(const unsigned char *&Buf, delete PN; return true; case 2: PN->addIncoming(getValue(Raw->Ty, Raw->Arg1), - cast(getValue(Type::LabelTyID, - Raw->Arg2))); + getBasicBlock(Raw->Arg2)); break; default: - PN->addIncoming(getValue(Raw->Ty, Raw->Arg1), - cast(getValue(Type::LabelTyID, Raw->Arg2))); + PN->addIncoming(getValue(Raw->Ty, Raw->Arg1), + getBasicBlock(Raw->Arg2)); if (Raw->VarArgs->size() & 1) { std::cerr << "PHI Node with ODD number of arguments!\n"; delete PN; @@ -174,8 +173,7 @@ bool BytecodeParser::ParseInstruction(const unsigned char *&Buf, } else { std::vector &args = *Raw->VarArgs; for (unsigned i = 0; i < args.size(); i+=2) - PN->addIncoming(getValue(Raw->Ty, args[i]), - cast(getValue(Type::LabelTyID, args[i+1]))); + PN->addIncoming(getValue(Raw->Ty, args[i]), getBasicBlock(args[i+1])); } delete Raw->VarArgs; break; @@ -200,20 +198,18 @@ bool BytecodeParser::ParseInstruction(const unsigned char *&Buf, case Instruction::Br: if (Raw->NumOperands == 1) { - Res = new BranchInst(cast(getValue(Type::LabelTyID,Raw->Arg1))); + Res = new BranchInst(getBasicBlock(Raw->Arg1)); return false; } else if (Raw->NumOperands == 3) { - Res = new BranchInst(cast(getValue(Type::LabelTyID, Raw->Arg1)), - cast(getValue(Type::LabelTyID, Raw->Arg2)), - getValue(Type::BoolTyID , Raw->Arg3)); + Res = new BranchInst(getBasicBlock(Raw->Arg1), getBasicBlock(Raw->Arg2), + getValue(Type::BoolTyID , Raw->Arg3)); return false; } break; case Instruction::Switch: { SwitchInst *I = - new SwitchInst(getValue(Raw->Ty, Raw->Arg1), - cast(getValue(Type::LabelTyID, Raw->Arg2))); + new SwitchInst(getValue(Raw->Ty, Raw->Arg1), getBasicBlock(Raw->Arg2)); Res = I; if (Raw->NumOperands < 3) return false; // No destinations? Weird. @@ -226,7 +222,7 @@ bool BytecodeParser::ParseInstruction(const unsigned char *&Buf, std::vector &args = *Raw->VarArgs; for (unsigned i = 0; i < args.size(); i += 2) I->addCase(cast(getValue(Raw->Ty, args[i])), - cast(getValue(Type::LabelTyID, args[i+1]))); + getBasicBlock(args[i+1])); delete Raw->VarArgs; return false; @@ -311,11 +307,11 @@ bool BytecodeParser::ParseInstruction(const unsigned char *&Buf, if (!FTy->isVarArg()) { if (Raw->NumOperands < 3) return true; - Normal = cast(getValue(Type::LabelTyID, Raw->Arg2)); + Normal = getBasicBlock(Raw->Arg2); if (Raw->NumOperands == 3) - Except = cast(getValue(Type::LabelTyID, Raw->Arg3)); + Except = getBasicBlock(Raw->Arg3); else { - Except = cast(getValue(Type::LabelTyID, args[0])); + Except = getBasicBlock(args[0]); FunctionType::ParamTypes::const_iterator It = PL.begin(); for (unsigned i = 1; i < args.size(); i++) { @@ -327,10 +323,11 @@ bool BytecodeParser::ParseInstruction(const unsigned char *&Buf, } } else { if (args.size() < 4) return true; - if (getType(args[0]) != Type::LabelTy || - getType(args[2]) != Type::LabelTy) return true; - Normal = cast(getValue(Type::LabelTyID, args[1])); - Except = cast(getValue(Type::LabelTyID, args[3])); + if (args[0] != Type::LabelTyID || args[2] != Type::LabelTyID) + return true; + + Normal = getBasicBlock(args[1]); + Except = getBasicBlock(args[3]); if ((args.size() & 1) != 0) return true; // Must be pairs of type/value -- cgit v1.2.3-18-g5258