Eliminate std::vectors from the bcanalyzer interface.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33978 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2007-02-07 05:08:39 +00:00
parent 4d544cd646
commit 63cf59ed3f
3 changed files with 45 additions and 32 deletions

View File

@ -359,13 +359,13 @@ public:
}
virtual bool handleInstruction( unsigned Opcode, const Type* iType,
std::vector<unsigned>& Operands,
unsigned *Operands, unsigned NumOps,
Instruction *Inst,
unsigned Size){
if (os) {
*os << " INST: OpCode="
<< Instruction::getOpcodeName(Opcode);
for ( unsigned i = 0; i < Operands.size(); ++i )
for (unsigned i = 0; i != NumOps; ++i)
*os << " Op(" << Operands[i] << ")";
*os << *Inst;
}
@ -374,15 +374,15 @@ public:
bca.numValues++;
bca.instructionSize += Size;
if (Size > 4 ) bca.longInstructions++;
bca.numOperands += Operands.size();
for (unsigned i = 0; i < Operands.size(); ++i )
bca.numOperands += NumOps;
for (unsigned i = 0; i != NumOps; ++i)
if (Operands[i] > bca.maxValueSlot)
bca.maxValueSlot = Operands[i];
if ( currFunc ) {
currFunc->numInstructions++;
currFunc->instructionSize += Size;
if (Size > 4 ) currFunc->longInstructions++;
if ( Opcode == Instruction::PHI ) currFunc->numPhis++;
if (Opcode == Instruction::PHI) currFunc->numPhis++;
}
return Instruction::isTerminator(Opcode);
}
@ -397,11 +397,11 @@ public:
*os << " BLOCK: GlobalConstants {\n";
}
virtual void handleConstantExpression( unsigned Opcode,
std::vector<Constant*> ArgVec, Constant* C ) {
virtual void handleConstantExpression(unsigned Opcode,
Constant**ArgVec, unsigned NumArgs, Constant* C) {
if (os) {
*os << " EXPR: " << Instruction::getOpcodeName(Opcode) << "\n";
for ( unsigned i = 0; i < ArgVec.size(); ++i ) {
for ( unsigned i = 0; i != NumArgs; ++i ) {
*os << " Arg#" << i << " "; ArgVec[i]->print(*os);
*os << "\n";
}
@ -424,14 +424,14 @@ public:
}
virtual void handleConstantArray( const ArrayType* AT,
std::vector<Constant*>& Elements,
Constant**Elements, unsigned NumElts,
unsigned TypeSlot,
Constant* ArrayVal ) {
if (os) {
*os << " ARRAY: ";
WriteTypeSymbolic(*os,AT,M);
*os << " TypeSlot=" << TypeSlot << "\n";
for ( unsigned i = 0; i < Elements.size(); ++i ) {
for (unsigned i = 0; i != NumElts; ++i) {
*os << " #" << i;
Elements[i]->print(*os);
*os << "\n";
@ -447,14 +447,14 @@ public:
virtual void handleConstantStruct(
const StructType* ST,
std::vector<Constant*>& Elements,
Constant**Elements, unsigned NumElts,
Constant* StructVal)
{
if (os) {
*os << " STRUC: ";
WriteTypeSymbolic(*os,ST,M);
*os << "\n";
for ( unsigned i = 0; i < Elements.size(); ++i ) {
for ( unsigned i = 0; i != NumElts; ++i) {
*os << " #" << i << " "; Elements[i]->print(*os);
*os << "\n";
}
@ -468,7 +468,7 @@ public:
virtual void handleConstantPacked(
const PackedType* PT,
std::vector<Constant*>& Elements,
Constant**Elements, unsigned NumElts,
unsigned TypeSlot,
Constant* PackedVal)
{
@ -476,7 +476,7 @@ public:
*os << " PACKD: ";
WriteTypeSymbolic(*os,PT,M);
*os << " TypeSlot=" << TypeSlot << "\n";
for ( unsigned i = 0; i < Elements.size(); ++i ) {
for ( unsigned i = 0; i != NumElts; ++i ) {
*os << " #" << i;
Elements[i]->print(*os);
*os << "\n";

View File

@ -366,7 +366,7 @@ void BytecodeReader::insertArguments(Function* F) {
/// This method parses a single instruction. The instruction is
/// inserted at the end of the \p BB provided. The arguments of
/// the instruction are provided in the \p Oprnds vector.
void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
void BytecodeReader::ParseInstruction(SmallVector<unsigned, 8> &Oprnds,
BasicBlock* BB) {
BufPtr SaveAt = At;
@ -859,7 +859,8 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
// We have enough info to inform the handler now.
if (Handler)
Handler->handleInstruction(Opcode, InstTy, Oprnds, Result, At-SaveAt);
Handler->handleInstruction(Opcode, InstTy, &Oprnds[0], Oprnds.size(),
Result, At-SaveAt);
insertValue(Result, TypeSlot, FunctionValues);
}
@ -890,7 +891,7 @@ BasicBlock *BytecodeReader::getBasicBlock(unsigned ID) {
/// @returns the number of basic blocks encountered.
unsigned BytecodeReader::ParseInstructionList(Function* F) {
unsigned BlockNo = 0;
std::vector<unsigned> Args;
SmallVector<unsigned, 8> Args;
while (moreInBlock()) {
if (Handler) Handler->handleBasicBlockBegin(BlockNo);
@ -941,7 +942,7 @@ void BytecodeReader::ParseValueSymbolTable(Function *CurrentFunction,
if (Handler) Handler->handleValueSymbolTableBegin(CurrentFunction,VST);
// Allow efficient basic block lookup by number.
std::vector<BasicBlock*> BBMap;
SmallVector<BasicBlock*, 32> BBMap;
if (CurrentFunction)
for (Function::iterator I = CurrentFunction->begin(),
E = CurrentFunction->end(); I != E; ++I)
@ -1166,26 +1167,30 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
Constant *Result = ConstantExpr::getCast(Opcode, ArgVec[0],
getType(TypeID));
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
if (Handler) Handler->handleConstantExpression(Opcode, &ArgVec[0],
ArgVec.size(), Result);
return Result;
} else if (Opcode == Instruction::GetElementPtr) { // GetElementPtr
Constant *Result = ConstantExpr::getGetElementPtr(ArgVec[0], &ArgVec[1],
ArgVec.size()-1);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
if (Handler) Handler->handleConstantExpression(Opcode, &ArgVec[0],
ArgVec.size(), Result);
return Result;
} else if (Opcode == Instruction::Select) {
if (ArgVec.size() != 3)
error("Select instruction must have three arguments.");
Constant* Result = ConstantExpr::getSelect(ArgVec[0], ArgVec[1],
ArgVec[2]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
if (Handler) Handler->handleConstantExpression(Opcode, &ArgVec[0],
ArgVec.size(), Result);
return Result;
} else if (Opcode == Instruction::ExtractElement) {
if (ArgVec.size() != 2 ||
!ExtractElementInst::isValidOperands(ArgVec[0], ArgVec[1]))
error("Invalid extractelement constand expr arguments");
Constant* Result = ConstantExpr::getExtractElement(ArgVec[0], ArgVec[1]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
if (Handler) Handler->handleConstantExpression(Opcode, &ArgVec[0],
ArgVec.size(), Result);
return Result;
} else if (Opcode == Instruction::InsertElement) {
if (ArgVec.size() != 3 ||
@ -1194,7 +1199,8 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
Constant *Result =
ConstantExpr::getInsertElement(ArgVec[0], ArgVec[1], ArgVec[2]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
if (Handler) Handler->handleConstantExpression(Opcode, &ArgVec[0],
ArgVec.size(), Result);
return Result;
} else if (Opcode == Instruction::ShuffleVector) {
if (ArgVec.size() != 3 ||
@ -1202,25 +1208,29 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
error("Invalid shufflevector constant expr arguments.");
Constant *Result =
ConstantExpr::getShuffleVector(ArgVec[0], ArgVec[1], ArgVec[2]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
if (Handler) Handler->handleConstantExpression(Opcode, &ArgVec[0],
ArgVec.size(), Result);
return Result;
} else if (Opcode == Instruction::ICmp) {
if (ArgVec.size() != 2)
error("Invalid ICmp constant expr arguments.");
unsigned predicate = read_vbr_uint();
Constant *Result = ConstantExpr::getICmp(predicate, ArgVec[0], ArgVec[1]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
if (Handler) Handler->handleConstantExpression(Opcode, &ArgVec[0],
ArgVec.size(), Result);
return Result;
} else if (Opcode == Instruction::FCmp) {
if (ArgVec.size() != 2)
error("Invalid FCmp constant expr arguments.");
unsigned predicate = read_vbr_uint();
Constant *Result = ConstantExpr::getFCmp(predicate, ArgVec[0], ArgVec[1]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
if (Handler) Handler->handleConstantExpression(Opcode, &ArgVec[0],
ArgVec.size(), Result);
return Result;
} else { // All other 2-operand expressions
Constant* Result = ConstantExpr::get(Opcode, ArgVec[0], ArgVec[1]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
if (Handler) Handler->handleConstantExpression(Opcode, &ArgVec[0],
ArgVec.size(), Result);
return Result;
}
}
@ -1273,7 +1283,8 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
Elements.push_back(getConstantValue(TypeSlot,
read_vbr_uint()));
Result = ConstantArray::get(AT, Elements);
if (Handler) Handler->handleConstantArray(AT, Elements, TypeSlot, Result);
if (Handler) Handler->handleConstantArray(AT, &Elements[0], Elements.size(),
TypeSlot, Result);
break;
}
@ -1287,7 +1298,8 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
read_vbr_uint()));
Result = ConstantStruct::get(ST, Elements);
if (Handler) Handler->handleConstantStruct(ST, Elements, Result);
if (Handler) Handler->handleConstantStruct(ST, &Elements[0],Elements.size(),
Result);
break;
}
@ -1301,7 +1313,8 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
Elements.push_back(getConstantValue(TypeSlot,
read_vbr_uint()));
Result = ConstantPacked::get(PT, Elements);
if (Handler) Handler->handleConstantPacked(PT, Elements, TypeSlot, Result);
if (Handler) Handler->handleConstantPacked(PT, &Elements[0],Elements.size(),
TypeSlot, Result);
break;
}

View File

@ -22,8 +22,8 @@
#include "llvm/Function.h"
#include "llvm/ModuleProvider.h"
#include "llvm/Bytecode/Analyzer.h"
#include "llvm/ADT/SmallVector.h"
#include <utility>
#include <map>
#include <setjmp.h>
namespace llvm {
@ -228,7 +228,7 @@ protected:
/// @brief Parse a single instruction.
void ParseInstruction(
std::vector<unsigned>& Args, ///< The arguments to be filled in
SmallVector <unsigned, 8>& Args, ///< The arguments to be filled in
BasicBlock* BB ///< The BB the instruction goes in
);