From 63cf59ed3fc65486fb0108edfae0a7b76137a724 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 7 Feb 2007 05:08:39 +0000 Subject: [PATCH] Eliminate std::vectors from the bcanalyzer interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33978 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bytecode/Reader/Analyzer.cpp | 28 ++++++++++---------- lib/Bytecode/Reader/Reader.cpp | 45 ++++++++++++++++++++------------ lib/Bytecode/Reader/Reader.h | 4 +-- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/lib/Bytecode/Reader/Analyzer.cpp b/lib/Bytecode/Reader/Analyzer.cpp index 71cb4b25795..94224e36ab8 100644 --- a/lib/Bytecode/Reader/Analyzer.cpp +++ b/lib/Bytecode/Reader/Analyzer.cpp @@ -359,13 +359,13 @@ public: } virtual bool handleInstruction( unsigned Opcode, const Type* iType, - std::vector& 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 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& 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& 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& 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"; diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index ff6d8f04ca8..17d68248f43 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -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 &Oprnds, +void BytecodeReader::ParseInstruction(SmallVector &Oprnds, BasicBlock* BB) { BufPtr SaveAt = At; @@ -859,7 +859,8 @@ void BytecodeReader::ParseInstruction(std::vector &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 Args; + SmallVector 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 BBMap; + SmallVector 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; } diff --git a/lib/Bytecode/Reader/Reader.h b/lib/Bytecode/Reader/Reader.h index b881f9d0a56..5fec59e3788 100644 --- a/lib/Bytecode/Reader/Reader.h +++ b/lib/Bytecode/Reader/Reader.h @@ -22,8 +22,8 @@ #include "llvm/Function.h" #include "llvm/ModuleProvider.h" #include "llvm/Bytecode/Analyzer.h" +#include "llvm/ADT/SmallVector.h" #include -#include #include namespace llvm { @@ -228,7 +228,7 @@ protected: /// @brief Parse a single instruction. void ParseInstruction( - std::vector& Args, ///< The arguments to be filled in + SmallVector & Args, ///< The arguments to be filled in BasicBlock* BB ///< The BB the instruction goes in );