summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bytecode/Reader/InstructionReader.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-08 22:52:54 +0000
committerChris Lattner <sabre@nondot.org>2003-10-08 22:52:54 +0000
commitabf6412c09a5c05bef936fe0ce2cdda3d572fe73 (patch)
tree4618ea95abe31ca74bb0e9de05500f0e45a76d60 /llvm/lib/Bytecode/Reader/InstructionReader.cpp
parentf29c7b1a3fb93b5a51e8ef27eff5bd75fc0e2251 (diff)
downloadbcm5719-llvm-abf6412c09a5c05bef936fe0ce2cdda3d572fe73.tar.gz
bcm5719-llvm-abf6412c09a5c05bef936fe0ce2cdda3d572fe73.zip
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. llvm-svn: 8977
Diffstat (limited to 'llvm/lib/Bytecode/Reader/InstructionReader.cpp')
-rw-r--r--llvm/lib/Bytecode/Reader/InstructionReader.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/llvm/lib/Bytecode/Reader/InstructionReader.cpp b/llvm/lib/Bytecode/Reader/InstructionReader.cpp
index d8a6af0179c..2f2e7960d60 100644
--- a/llvm/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/llvm/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<BasicBlock>(getValue(Type::LabelTyID,
- Raw->Arg2)));
+ getBasicBlock(Raw->Arg2));
break;
default:
- PN->addIncoming(getValue(Raw->Ty, Raw->Arg1),
- cast<BasicBlock>(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<unsigned> &args = *Raw->VarArgs;
for (unsigned i = 0; i < args.size(); i+=2)
- PN->addIncoming(getValue(Raw->Ty, args[i]),
- cast<BasicBlock>(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<BasicBlock>(getValue(Type::LabelTyID,Raw->Arg1)));
+ Res = new BranchInst(getBasicBlock(Raw->Arg1));
return false;
} else if (Raw->NumOperands == 3) {
- Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTyID, Raw->Arg1)),
- cast<BasicBlock>(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<BasicBlock>(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<unsigned> &args = *Raw->VarArgs;
for (unsigned i = 0; i < args.size(); i += 2)
I->addCase(cast<Constant>(getValue(Raw->Ty, args[i])),
- cast<BasicBlock>(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<BasicBlock>(getValue(Type::LabelTyID, Raw->Arg2));
+ Normal = getBasicBlock(Raw->Arg2);
if (Raw->NumOperands == 3)
- Except = cast<BasicBlock>(getValue(Type::LabelTyID, Raw->Arg3));
+ Except = getBasicBlock(Raw->Arg3);
else {
- Except = cast<BasicBlock>(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<BasicBlock>(getValue(Type::LabelTyID, args[1]));
- Except = cast<BasicBlock>(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
OpenPOWER on IntegriCloud