mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
Miscellaneous cleanups:
* Convert post to pre-increment for for loops * Use generic programming more * Use new Value::cast* instructions * Use new Module, Method, & BasicBlock forwarding methods * Use new facilities in STLExtras.h * Use new Instruction::isPHINode() method llvm-svn: 96
This commit is contained in:
parent
0a37aa1884
commit
d616582a7a
@ -48,12 +48,15 @@ public:
|
||||
typedef PredIterator<_Ptr,_USE_iterator> _Self;
|
||||
|
||||
typedef bidirectional_iterator_tag iterator_category;
|
||||
typedef _Ptr &reference;
|
||||
typedef unsigned difference_type;
|
||||
typedef _Ptr value_type;
|
||||
typedef _Ptr pointer;
|
||||
|
||||
inline void advancePastConstPool() {
|
||||
// Loop to ignore constant pool references
|
||||
while (It != BB->use_end() &&
|
||||
(((*It)->getValueType() != Value::InstructionVal) ||
|
||||
((!(*It)->isInstruction()) ||
|
||||
!(((Instruction*)(*It))->isTerminator())))
|
||||
++It;
|
||||
}
|
||||
@ -67,8 +70,7 @@ public:
|
||||
inline bool operator!=(const _Self& x) const { return !operator==(x); }
|
||||
|
||||
inline pointer operator*() const {
|
||||
assert ((*It)->getValueType() == Value::InstructionVal);
|
||||
return ((Instruction *)(*It))->getParent();
|
||||
return (*It)->castInstructionAsserting()->getParent();
|
||||
}
|
||||
inline pointer *operator->() const { return &(operator*()); }
|
||||
|
||||
@ -113,6 +115,9 @@ public:
|
||||
typedef SuccIterator<_Term, _BB> _Self;
|
||||
// TODO: This can be random access iterator, need operator+ and stuff tho
|
||||
typedef bidirectional_iterator_tag iterator_category;
|
||||
typedef _BB &reference;
|
||||
typedef unsigned difference_type;
|
||||
typedef _BB value_type;
|
||||
typedef _BB pointer;
|
||||
|
||||
inline SuccIterator(_Term T) : Term(T), idx(0) {} // begin iterator
|
||||
@ -242,11 +247,11 @@ public:
|
||||
};
|
||||
|
||||
inline df_iterator df_begin(Method *M, bool Reverse = false) {
|
||||
return df_iterator(M->getBasicBlocks().front(), Reverse);
|
||||
return df_iterator(M->front(), Reverse);
|
||||
}
|
||||
|
||||
inline df_const_iterator df_begin(const Method *M, bool Reverse = false) {
|
||||
return df_const_iterator(M->getBasicBlocks().front(), Reverse);
|
||||
return df_const_iterator(M->front(), Reverse);
|
||||
}
|
||||
inline df_iterator df_end(Method*) {
|
||||
return df_iterator();
|
||||
@ -334,10 +339,10 @@ public:
|
||||
};
|
||||
|
||||
inline po_iterator po_begin( Method *M) {
|
||||
return po_iterator(M->getBasicBlocks().front());
|
||||
return po_iterator(M->front());
|
||||
}
|
||||
inline po_const_iterator po_begin(const Method *M) {
|
||||
return po_const_iterator(M->getBasicBlocks().front());
|
||||
return po_const_iterator(M->front());
|
||||
}
|
||||
inline po_iterator po_end ( Method *M) {
|
||||
return po_iterator();
|
||||
@ -371,7 +376,7 @@ class ReversePostOrderTraversal {
|
||||
}
|
||||
public:
|
||||
inline ReversePostOrderTraversal(Method *M) {
|
||||
Initialize(M->getBasicBlocks().front());
|
||||
Initialize(M->front());
|
||||
}
|
||||
inline ReversePostOrderTraversal(BasicBlock *BB) {
|
||||
Initialize(BB);
|
||||
|
@ -6,6 +6,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Analysis/IntervalIterator.h"
|
||||
#include "llvm/Tools/STLExtras.h"
|
||||
|
||||
using namespace cfg;
|
||||
|
||||
@ -49,22 +50,24 @@ void IntervalPartition::updatePredecessors(cfg::Interval *Int) {
|
||||
// specified method...
|
||||
//
|
||||
IntervalPartition::IntervalPartition(Method *M) {
|
||||
assert(M->getBasicBlocks().front() && "Cannot operate on prototypes!");
|
||||
assert(M->front() && "Cannot operate on prototypes!");
|
||||
|
||||
// Pass false to intervals_begin because we take ownership of it's memory
|
||||
method_interval_iterator I = intervals_begin(M, false);
|
||||
method_interval_iterator End = intervals_end(M);
|
||||
assert(I != End && "No intervals in method!?!?!");
|
||||
assert(I != intervals_end(M) && "No intervals in method!?!?!");
|
||||
|
||||
addIntervalToPartition(RootInterval = *I);
|
||||
|
||||
for (++I; I != End; ++I)
|
||||
addIntervalToPartition(*I);
|
||||
++I; // After the first one...
|
||||
|
||||
// Add the rest of the intervals to the partition...
|
||||
for_each(I, intervals_end(M),
|
||||
bind_obj(this, &IntervalPartition::addIntervalToPartition));
|
||||
|
||||
// Now that we know all of the successor information, propogate this to the
|
||||
// predecessors for each block...
|
||||
for(iterator It = begin(), E = end(); It != E; ++It)
|
||||
updatePredecessors(*It);
|
||||
for_each(begin(), end(),
|
||||
bind_obj(this, &IntervalPartition::updatePredecessors));
|
||||
}
|
||||
|
||||
|
||||
@ -78,16 +81,18 @@ IntervalPartition::IntervalPartition(IntervalPartition &IP, bool) {
|
||||
|
||||
// Pass false to intervals_begin because we take ownership of it's memory
|
||||
interval_part_interval_iterator I = intervals_begin(IP, false);
|
||||
interval_part_interval_iterator End = intervals_end(IP);
|
||||
assert(I != End && "No intervals in interval partition!?!?!");
|
||||
assert(I != intervals_end(IP) && "No intervals in interval partition!?!?!");
|
||||
|
||||
addIntervalToPartition(RootInterval = *I);
|
||||
|
||||
for (++I; I != End; ++I)
|
||||
addIntervalToPartition(*I);
|
||||
++I; // After the first one...
|
||||
|
||||
// Add the rest of the intervals to the partition...
|
||||
for_each(I, intervals_end(IP),
|
||||
bind_obj(this, &IntervalPartition::addIntervalToPartition));
|
||||
|
||||
// Now that we know all of the successor information, propogate this to the
|
||||
// predecessors for each block...
|
||||
for(iterator I = begin(), E = end(); I != E; ++I)
|
||||
updatePredecessors(*I);
|
||||
for_each(begin(), end(),
|
||||
bind_obj(this, &IntervalPartition::updatePredecessors));
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "llvm/BasicBlock.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/ConstPoolVals.h"
|
||||
#include "llvm/Tools/STLExtras.h"
|
||||
#include <map>
|
||||
|
||||
// processModule - Driver function to call all of my subclasses virtual methods.
|
||||
@ -87,7 +88,7 @@ bool ModuleAnalyzer::processConstPool(const ConstantPool &CP, bool isMethod) {
|
||||
if (processConstPoolPlane(CP, Plane, isMethod)) return true;
|
||||
|
||||
for (ConstantPool::PlaneType::const_iterator CI = Plane.begin();
|
||||
CI != Plane.end(); CI++) {
|
||||
CI != Plane.end(); ++CI) {
|
||||
if ((*CI)->getType() == Type::TypeTy)
|
||||
if (handleType(TypeSet, ((const ConstPoolType*)(*CI))->getValue()))
|
||||
return true;
|
||||
@ -98,11 +99,9 @@ bool ModuleAnalyzer::processConstPool(const ConstantPool &CP, bool isMethod) {
|
||||
}
|
||||
|
||||
if (!isMethod) {
|
||||
assert(CP.getParent()->getValueType() == Value::ModuleVal);
|
||||
const Module *M = (const Module*)CP.getParent();
|
||||
const Module *M = CP.getParent()->castModuleAsserting();
|
||||
// Process the method types after the constant pool...
|
||||
for (Module::MethodListType::const_iterator I = M->getMethodList().begin();
|
||||
I != M->getMethodList().end(); I++) {
|
||||
for (Module::const_iterator I = M->begin(); I != M->end(); ++I) {
|
||||
if (handleType(TypeSet, (*I)->getType())) return true;
|
||||
if (visitMethod(*I)) return true;
|
||||
}
|
||||
@ -111,34 +110,28 @@ bool ModuleAnalyzer::processConstPool(const ConstantPool &CP, bool isMethod) {
|
||||
}
|
||||
|
||||
bool ModuleAnalyzer::processMethods(const Module *M) {
|
||||
for (Module::MethodListType::const_iterator I = M->getMethodList().begin();
|
||||
I != M->getMethodList().end(); I++)
|
||||
if (processMethod(*I)) return true;
|
||||
|
||||
return false;
|
||||
return apply_until(M->begin(), M->end(),
|
||||
bind_obj(this, &ModuleAnalyzer::processMethod));
|
||||
}
|
||||
|
||||
bool ModuleAnalyzer::processMethod(const Method *M) {
|
||||
// Loop over the arguments, processing them...
|
||||
const Method::ArgumentListType &ArgList = M->getArgumentList();
|
||||
for (Method::ArgumentListType::const_iterator AI = ArgList.begin();
|
||||
AI != ArgList.end(); AI++)
|
||||
if (processMethodArgument(*AI)) return true;
|
||||
if (apply_until(M->getArgumentList().begin(), M->getArgumentList().end(),
|
||||
bind_obj(this, &ModuleAnalyzer::processMethodArgument)))
|
||||
return true;
|
||||
|
||||
// Loop over the constant pool, adding the constants to the table...
|
||||
processConstPool(M->getConstantPool(), true);
|
||||
|
||||
// Loop over all the basic blocks, in order...
|
||||
Method::BasicBlocksType::const_iterator BBI = M->getBasicBlocks().begin();
|
||||
for (; BBI != M->getBasicBlocks().end(); BBI++)
|
||||
if (processBasicBlock(*BBI)) return true;
|
||||
return false;
|
||||
return apply_until(M->begin(), M->end(),
|
||||
bind_obj(this, &ModuleAnalyzer::processBasicBlock));
|
||||
}
|
||||
|
||||
bool ModuleAnalyzer::processBasicBlock(const BasicBlock *BB) {
|
||||
// Process all of the instructions in the basic block
|
||||
BasicBlock::InstListType::const_iterator Inst = BB->getInstList().begin();
|
||||
for (; Inst != BB->getInstList().end(); Inst++) {
|
||||
BasicBlock::const_iterator Inst = BB->begin();
|
||||
for (; Inst != BB->end(); Inst++) {
|
||||
if (preProcessInstruction(*Inst) || processInstruction(*Inst)) return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1569,7 +1569,7 @@ case 74:
|
||||
{
|
||||
MethodType::ParamTypes ParamTypeList;
|
||||
if (yyvsp[-1].MethodArgList)
|
||||
for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); I++)
|
||||
for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); ++I)
|
||||
ParamTypeList.push_back((*I)->getType());
|
||||
|
||||
const MethodType *MT = MethodType::getMethodType(yyvsp[-4].TypeVal, ParamTypeList);
|
||||
@ -1585,7 +1585,7 @@ case 74:
|
||||
if (yyvsp[-1].MethodArgList) { // Is null if empty...
|
||||
Method::ArgumentListType &ArgList = M->getArgumentList();
|
||||
|
||||
for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); I++) {
|
||||
for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); ++I) {
|
||||
InsertValue(*I);
|
||||
ArgList.push_back(*I);
|
||||
}
|
||||
@ -1658,9 +1658,9 @@ case 85:
|
||||
{
|
||||
Value *D = getVal(Type::TypeTy, yyvsp[0].ValIDVal, true);
|
||||
if (D == 0) ThrowException("Invalid user defined type: " + yyvsp[0].ValIDVal.getName());
|
||||
assert (D->getValueType() == Value::ConstantVal &&
|
||||
"Internal error! User defined type not in const pool!");
|
||||
ConstPoolType *CPT = (ConstPoolType*)D;
|
||||
|
||||
// User defined type not in const pool!
|
||||
ConstPoolType *CPT = (ConstPoolType*)D->castConstantAsserting();
|
||||
yyval.TypeVal = CPT->getValue();
|
||||
;
|
||||
break;}
|
||||
@ -1805,7 +1805,7 @@ case 105:
|
||||
|
||||
list<pair<ConstPoolVal*, BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(),
|
||||
end = yyvsp[-1].JumpTable->end();
|
||||
for (; I != end; I++)
|
||||
for (; I != end; ++I)
|
||||
S->dest_push_back(I->first, I->second);
|
||||
;
|
||||
break;}
|
||||
@ -1916,7 +1916,7 @@ case 118:
|
||||
const MethodType *Ty = (const MethodType*)yyvsp[-4].TypeVal;
|
||||
|
||||
Value *V = getVal(Ty, yyvsp[-3].ValIDVal);
|
||||
if (V->getValueType() != Value::MethodVal || V->getType() != Ty)
|
||||
if (!V->isMethod() || V->getType() != Ty)
|
||||
ThrowException("Cannot call: " + yyvsp[-3].ValIDVal.getName() + "!");
|
||||
|
||||
// Create or access a new type that corresponds to the function call...
|
||||
|
@ -643,7 +643,7 @@ ArgList : ArgListH {
|
||||
MethodHeaderH : TypesV STRINGCONSTANT '(' ArgList ')' {
|
||||
MethodType::ParamTypes ParamTypeList;
|
||||
if ($4)
|
||||
for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); I++)
|
||||
for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); ++I)
|
||||
ParamTypeList.push_back((*I)->getType());
|
||||
|
||||
const MethodType *MT = MethodType::getMethodType($1, ParamTypeList);
|
||||
@ -659,7 +659,7 @@ MethodHeaderH : TypesV STRINGCONSTANT '(' ArgList ')' {
|
||||
if ($4) { // Is null if empty...
|
||||
Method::ArgumentListType &ArgList = M->getArgumentList();
|
||||
|
||||
for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); I++) {
|
||||
for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); ++I) {
|
||||
InsertValue(*I);
|
||||
ArgList.push_back(*I);
|
||||
}
|
||||
@ -713,9 +713,9 @@ ValueRef : INTVAL { // Is it an integer reference...?
|
||||
Types : ValueRef {
|
||||
Value *D = getVal(Type::TypeTy, $1, true);
|
||||
if (D == 0) ThrowException("Invalid user defined type: " + $1.getName());
|
||||
assert (D->getValueType() == Value::ConstantVal &&
|
||||
"Internal error! User defined type not in const pool!");
|
||||
ConstPoolType *CPT = (ConstPoolType*)D;
|
||||
|
||||
// User defined type not in const pool!
|
||||
ConstPoolType *CPT = (ConstPoolType*)D->castConstantAsserting();
|
||||
$$ = CPT->getValue();
|
||||
}
|
||||
| TypesV '(' TypeList ')' { // Method derived type?
|
||||
@ -811,7 +811,7 @@ BBTerminatorInst : RET Types ValueRef { // Return with a result...
|
||||
|
||||
list<pair<ConstPoolVal*, BasicBlock*> >::iterator I = $8->begin(),
|
||||
end = $8->end();
|
||||
for (; I != end; I++)
|
||||
for (; I != end; ++I)
|
||||
S->dest_push_back(I->first, I->second);
|
||||
}
|
||||
|
||||
@ -894,7 +894,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef {
|
||||
const MethodType *Ty = (const MethodType*)$2;
|
||||
|
||||
Value *V = getVal(Ty, $3);
|
||||
if (V->getValueType() != Value::MethodVal || V->getType() != Ty)
|
||||
if (!V->isMethod() || V->getType() != Ty)
|
||||
ThrowException("Cannot call: " + $3.getName() + "!");
|
||||
|
||||
// Create or access a new type that corresponds to the function call...
|
||||
|
@ -156,7 +156,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
|
||||
unsigned Slot;
|
||||
if (read_vbr(Buf, EndBuf, Slot)) return true;
|
||||
Value *V = getValue(AT->getElementType(), Slot, false);
|
||||
if (!V || V->getValueType() != Value::ConstantVal)
|
||||
if (!V || !V->isConstant())
|
||||
return true;
|
||||
Elements.push_back((ConstPoolVal*)V);
|
||||
}
|
||||
@ -173,7 +173,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
|
||||
unsigned Slot;
|
||||
if (read_vbr(Buf, EndBuf, Slot)) return true;
|
||||
Value *V = getValue(ET[i], Slot, false);
|
||||
if (!V || V->getValueType() != Value::ConstantVal)
|
||||
if (!V || !V->isConstant())
|
||||
return true;
|
||||
Elements.push_back((ConstPoolVal*)V);
|
||||
}
|
||||
|
@ -46,11 +46,8 @@ const Type *BytecodeParser::getType(unsigned ID) {
|
||||
const Value *D = getValue(Type::TypeTy, ID, false);
|
||||
if (D == 0) return 0;
|
||||
|
||||
assert(D->getType() == Type::TypeTy &&
|
||||
D->getValueType() == Value::ConstantVal);
|
||||
|
||||
|
||||
return ((const ConstPoolType*)D)->getValue();;
|
||||
assert(D->getType() == Type::TypeTy);
|
||||
return ((const ConstPoolType*)D->castConstantAsserting())->getValue();
|
||||
}
|
||||
|
||||
bool BytecodeParser::insertValue(Value *Def, vector<ValueList> &ValueTab) {
|
||||
@ -63,7 +60,7 @@ bool BytecodeParser::insertValue(Value *Def, vector<ValueList> &ValueTab) {
|
||||
//cerr << "insertValue Values[" << type << "][" << ValueTab[type].size()
|
||||
// << "] = " << Def << endl;
|
||||
|
||||
if (type == Type::TypeTyID && Def->getValueType() == Value::ConstantVal) {
|
||||
if (type == Type::TypeTyID && Def->isConstant()) {
|
||||
const Type *Ty = ((const ConstPoolType*)Def)->getValue();
|
||||
unsigned ValueOffset = FirstDerivedTyID;
|
||||
|
||||
@ -123,7 +120,7 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) {
|
||||
|
||||
bool BytecodeParser::postResolveValues(ValueTable &ValTab) {
|
||||
bool Error = false;
|
||||
for (unsigned ty = 0; ty < ValTab.size(); ty++) {
|
||||
for (unsigned ty = 0; ty < ValTab.size(); ++ty) {
|
||||
ValueList &DL = ValTab[ty];
|
||||
unsigned Size;
|
||||
while ((Size = DL.size())) {
|
||||
@ -180,7 +177,7 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf) {
|
||||
const Type *Ty = getType(Typ);
|
||||
if (Ty == 0) return true;
|
||||
|
||||
for (unsigned i = 0; i < NumEntries; i++) {
|
||||
for (unsigned i = 0; i < NumEntries; ++i) {
|
||||
// Symtab entry: [def slot #][name]
|
||||
unsigned slot;
|
||||
if (read_vbr(Buf, EndBuf, slot)) return true;
|
||||
@ -211,7 +208,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
|
||||
|
||||
const MethodType::ParamTypes &Params = MTy->getParamTypes();
|
||||
for (MethodType::ParamTypes::const_iterator It = Params.begin();
|
||||
It != Params.end(); It++) {
|
||||
It != Params.end(); ++It) {
|
||||
MethodArgument *MA = new MethodArgument(*It);
|
||||
if (insertValue(MA, Values)) { delete M; return true; }
|
||||
M->getArgumentList().push_back(MA);
|
||||
@ -267,7 +264,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
|
||||
|
||||
Value *MethPHolder = getValue(MTy, MethSlot, false);
|
||||
assert(MethPHolder && "Something is broken no placeholder found!");
|
||||
assert(MethPHolder->getValueType() == Value::MethodVal && "Not a method?");
|
||||
assert(MethPHolder->isMethod() && "Not a method?");
|
||||
|
||||
unsigned type; // Type slot
|
||||
assert(!getTypeSlot(MTy, type) && "How can meth type not exist?");
|
||||
|
@ -67,7 +67,7 @@ bool BytecodeWriter::processConstPool(const ConstantPool &CP, bool isMethod) {
|
||||
|
||||
unsigned NumConstants = 0;
|
||||
for (unsigned vn = ValNo; vn < Plane.size(); vn++)
|
||||
if (Plane[vn]->getValueType() == Value::ConstantVal)
|
||||
if (Plane[vn]->isConstant())
|
||||
NumConstants++;
|
||||
|
||||
if (NumConstants == 0) continue; // Skip empty type planes...
|
||||
@ -85,21 +85,19 @@ bool BytecodeWriter::processConstPool(const ConstantPool &CP, bool isMethod) {
|
||||
|
||||
for (; ValNo < Plane.size(); ValNo++) {
|
||||
const Value *V = Plane[ValNo];
|
||||
if (V->getValueType() == Value::ConstantVal) {
|
||||
if (const ConstPoolVal *CPV = V->castConstant()) {
|
||||
//cerr << "Serializing value: <" << V->getType() << ">: "
|
||||
// << ((const ConstPoolVal*)V)->getStrValue() << ":"
|
||||
// << Out.size() << "\n";
|
||||
outputConstant((const ConstPoolVal*)V);
|
||||
outputConstant(CPV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete CPool; // End bytecode block section!
|
||||
|
||||
if (!isMethod) { // The ModuleInfoBlock follows directly after the c-pool
|
||||
assert(CP.getParent()->getValueType() == Value::ModuleVal);
|
||||
outputModuleInfoBlock((const Module*)CP.getParent());
|
||||
}
|
||||
if (!isMethod) // The ModuleInfoBlock follows directly after the c-pool
|
||||
outputModuleInfoBlock(CP.getParent()->castModuleAsserting());
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -108,13 +106,11 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
|
||||
BytecodeBlock ModuleInfoBlock(BytecodeFormat::ModuleGlobalInfo, Out);
|
||||
|
||||
// Output the types of the methods in this class
|
||||
Module::MethodListType::const_iterator I = M->getMethodList().begin();
|
||||
while (I != M->getMethodList().end()) {
|
||||
for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) {
|
||||
int Slot = Table.getValSlot((*I)->getType());
|
||||
assert(Slot != -1 && "Module const pool is broken!");
|
||||
assert(Slot >= Type::FirstDerivedTyID && "Derived type not in range!");
|
||||
output_vbr((unsigned)Slot, Out);
|
||||
I++;
|
||||
}
|
||||
output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out);
|
||||
align32(Out);
|
||||
@ -144,7 +140,7 @@ bool BytecodeWriter::processBasicBlock(const BasicBlock *BB) {
|
||||
void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
|
||||
BytecodeBlock MethodBlock(BytecodeFormat::SymbolTable, Out);
|
||||
|
||||
for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); TI++) {
|
||||
for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); ++TI) {
|
||||
SymbolTable::type_const_iterator I = MST.type_begin(TI->first);
|
||||
SymbolTable::type_const_iterator End = MST.type_end(TI->first);
|
||||
int Slot;
|
||||
@ -158,7 +154,7 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
|
||||
assert(Slot != -1 && "Type in symtab, but not in table!");
|
||||
output_vbr((unsigned)Slot, Out);
|
||||
|
||||
for (; I != End; I++) {
|
||||
for (; I != End; ++I) {
|
||||
// Symtab entry: [def slot #][name]
|
||||
Slot = Table.getValSlot(I->second);
|
||||
assert (Slot != -1 && "Value in symtab but not in method!!");
|
||||
|
@ -36,9 +36,9 @@
|
||||
static inline void RemapInstruction(Instruction *I,
|
||||
map<const Value *, Value*> &ValueMap) {
|
||||
|
||||
for (unsigned op = 0; const Value *Op = I->getOperand(op); op++) {
|
||||
for (unsigned op = 0; const Value *Op = I->getOperand(op); ++op) {
|
||||
Value *V = ValueMap[Op];
|
||||
if (!V && Op->getValueType() == Value::MethodVal)
|
||||
if (!V && Op->isMethod())
|
||||
continue; // Methods don't get relocated
|
||||
|
||||
if (!V) {
|
||||
@ -60,7 +60,7 @@ static inline void RemapInstruction(Instruction *I,
|
||||
// exists in the instruction stream. Similiarly this will inline a recursive
|
||||
// method by one level.
|
||||
//
|
||||
bool InlineMethod(BasicBlock::InstListType::iterator CIIt) {
|
||||
bool InlineMethod(BasicBlock::iterator CIIt) {
|
||||
assert((*CIIt)->getInstType() == Instruction::Call &&
|
||||
"InlineMethod only works on CallInst nodes!");
|
||||
assert((*CIIt)->getParent() && "Instruction not embedded in basic block!");
|
||||
@ -124,9 +124,8 @@ bool InlineMethod(BasicBlock::InstListType::iterator CIIt) {
|
||||
// Loop over all of the basic blocks in the method, inlining them as
|
||||
// appropriate. Keep track of the first basic block of the method...
|
||||
//
|
||||
for (Method::BasicBlocksType::const_iterator BI =
|
||||
CalledMeth->getBasicBlocks().begin();
|
||||
BI != CalledMeth->getBasicBlocks().end(); BI++) {
|
||||
for (Method::const_iterator BI = CalledMeth->begin();
|
||||
BI != CalledMeth->end(); ++BI) {
|
||||
const BasicBlock *BB = *BI;
|
||||
assert(BB->getTerminator() && "BasicBlock doesn't have terminator!?!?");
|
||||
|
||||
@ -143,8 +142,8 @@ bool InlineMethod(BasicBlock::InstListType::iterator CIIt) {
|
||||
|
||||
// Loop over all instructions copying them over...
|
||||
Instruction *NewInst;
|
||||
for (BasicBlock::InstListType::const_iterator II = BB->getInstList().begin();
|
||||
II != (BB->getInstList().end()-1); II++) {
|
||||
for (BasicBlock::const_iterator II = BB->begin();
|
||||
II != (BB->end()-1); ++II) {
|
||||
IBB->getInstList().push_back((NewInst = (*II)->clone()));
|
||||
ValueMap[*II] = NewInst; // Add instruction map to value.
|
||||
}
|
||||
@ -193,16 +192,14 @@ bool InlineMethod(BasicBlock::InstListType::iterator CIIt) {
|
||||
// Loop over all of the instructions in the method, fixing up operand
|
||||
// references as we go. This uses ValueMap to do all the hard work.
|
||||
//
|
||||
for (Method::BasicBlocksType::const_iterator BI =
|
||||
CalledMeth->getBasicBlocks().begin();
|
||||
BI != CalledMeth->getBasicBlocks().end(); BI++) {
|
||||
for (Method::const_iterator BI = CalledMeth->begin();
|
||||
BI != CalledMeth->end(); ++BI) {
|
||||
const BasicBlock *BB = *BI;
|
||||
BasicBlock *NBB = (BasicBlock*)ValueMap[BB];
|
||||
|
||||
// Loop over all instructions, fixing each one as we find it...
|
||||
//
|
||||
for (BasicBlock::InstListType::iterator II = NBB->getInstList().begin();
|
||||
II != NBB->getInstList().end(); II++)
|
||||
for (BasicBlock::iterator II = NBB->begin(); II != NBB->end(); II++)
|
||||
RemapInstruction(*II, ValueMap);
|
||||
}
|
||||
|
||||
@ -214,7 +211,7 @@ bool InlineMethod(BasicBlock::InstListType::iterator CIIt) {
|
||||
TerminatorInst *Br = OrigBB->getTerminator();
|
||||
assert(Br && Br->getInstType() == Instruction::Br &&
|
||||
"splitBasicBlock broken!");
|
||||
Br->setOperand(0, ValueMap[CalledMeth->getBasicBlocks().front()]);
|
||||
Br->setOperand(0, ValueMap[CalledMeth->front()]);
|
||||
|
||||
// Since we are now done with the CallInst, we can finally delete it.
|
||||
delete CI;
|
||||
@ -225,10 +222,9 @@ bool InlineMethod(CallInst *CI) {
|
||||
assert(CI->getParent() && "CallInst not embeded in BasicBlock!");
|
||||
BasicBlock *PBB = CI->getParent();
|
||||
|
||||
BasicBlock::InstListType::iterator CallIt = find(PBB->getInstList().begin(),
|
||||
PBB->getInstList().end(),
|
||||
CI);
|
||||
assert(CallIt != PBB->getInstList().end() &&
|
||||
BasicBlock::iterator CallIt = find(PBB->begin(), PBB->end(), CI);
|
||||
|
||||
assert(CallIt != PBB->end() &&
|
||||
"CallInst has parent that doesn't contain CallInst?!?");
|
||||
return InlineMethod(CallIt);
|
||||
}
|
||||
@ -241,10 +237,10 @@ static inline bool ShouldInlineMethod(const CallInst *CI, const Method *M) {
|
||||
if (CI->getParent()->getParent() == M) return false;
|
||||
|
||||
// Don't inline something too big. This is a really crappy heuristic
|
||||
if (M->getBasicBlocks().size() > 3) return false;
|
||||
if (M->size() > 3) return false;
|
||||
|
||||
// Don't inline into something too big. This is a **really** crappy heuristic
|
||||
if (CI->getParent()->getParent()->getBasicBlocks().size() > 10) return false;
|
||||
if (CI->getParent()->getParent()->size() > 10) return false;
|
||||
|
||||
// Go ahead and try just about anything else.
|
||||
return true;
|
||||
@ -252,8 +248,7 @@ static inline bool ShouldInlineMethod(const CallInst *CI, const Method *M) {
|
||||
|
||||
|
||||
static inline bool DoMethodInlining(BasicBlock *BB) {
|
||||
for (BasicBlock::InstListType::iterator I = BB->getInstList().begin();
|
||||
I != BB->getInstList().end(); I++) {
|
||||
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
|
||||
if ((*I)->getInstType() == Instruction::Call) {
|
||||
// Check to see if we should inline this method
|
||||
CallInst *CI = (CallInst*)*I;
|
||||
@ -266,15 +261,14 @@ static inline bool DoMethodInlining(BasicBlock *BB) {
|
||||
}
|
||||
|
||||
bool DoMethodInlining(Method *M) {
|
||||
Method::BasicBlocksType &BBs = M->getBasicBlocks();
|
||||
bool Changed = false;
|
||||
|
||||
// Loop through now and inline instructions a basic block at a time...
|
||||
for (Method::BasicBlocksType::iterator I = BBs.begin(); I != BBs.end(); )
|
||||
for (Method::iterator I = M->begin(); I != M->end(); )
|
||||
if (DoMethodInlining(*I)) {
|
||||
Changed = true;
|
||||
// Iterator is now invalidated by new basic blocks inserted
|
||||
I = BBs.begin();
|
||||
I = M->begin();
|
||||
} else {
|
||||
++I;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ static bool RemoveUnusedDefs(ValueHolder<ValueSubclass, ItemParentType> &Vals,
|
||||
delete Vals.remove(DI);
|
||||
Changed = true;
|
||||
} else {
|
||||
DI++;
|
||||
++DI;
|
||||
}
|
||||
}
|
||||
return Changed;
|
||||
@ -79,8 +79,8 @@ static bool RemoveSingularPHIs(BasicBlock *BB) {
|
||||
if (PI == pred_end(BB) || ++PI != pred_end(BB))
|
||||
return false; // More than one predecessor...
|
||||
|
||||
Instruction *I = BB->getInstList().front();
|
||||
if (I->getInstType() != Instruction::PHINode) return false; // No PHI nodes
|
||||
Instruction *I = BB->front();
|
||||
if (!I->isPHINode()) return false; // No PHI nodes
|
||||
|
||||
//cerr << "Killing PHIs from " << BB;
|
||||
//cerr << "Pred #0 = " << *pred_begin(BB);
|
||||
@ -93,10 +93,10 @@ static bool RemoveSingularPHIs(BasicBlock *BB) {
|
||||
Value *V = PN->getOperand(0);
|
||||
|
||||
PN->replaceAllUsesWith(V); // Replace PHI node with its single value.
|
||||
delete BB->getInstList().remove(BB->getInstList().begin());
|
||||
delete BB->getInstList().remove(BB->begin());
|
||||
|
||||
I = BB->getInstList().front();
|
||||
} while (I->getInstType() == Instruction::PHINode);
|
||||
I = BB->front();
|
||||
} while (I->isPHINode());
|
||||
|
||||
return true; // Yes, we nuked at least one phi node
|
||||
}
|
||||
@ -154,8 +154,8 @@ static void RemovePredecessorFromBlock(BasicBlock *BB, BasicBlock *Pred) {
|
||||
|
||||
// Okay, now we know that we need to remove predecessor #pred_idx from all
|
||||
// PHI nodes. Iterate over each PHI node fixing them up
|
||||
BasicBlock::InstListType::iterator II(BB->getInstList().begin());
|
||||
for (; (*II)->getInstType() == Instruction::PHINode; ++II) {
|
||||
BasicBlock::iterator II(BB->begin());
|
||||
for (; (*II)->isPHINode(); ++II) {
|
||||
PHINode *PN = (PHINode*)*II;
|
||||
PN->removeIncomingValue(BB);
|
||||
|
||||
@ -177,25 +177,36 @@ static void RemovePredecessorFromBlock(BasicBlock *BB, BasicBlock *Pred) {
|
||||
// Assumption: BB is the single predecessor of Succ.
|
||||
//
|
||||
static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
|
||||
assert(BB && Succ && *pred_begin(Succ) == BB && "BB is only pred of Succ" &&
|
||||
++pred_begin(Succ) == pred_end(Succ));
|
||||
assert(Succ->front()->isPHINode() && "Only works on PHId BBs!");
|
||||
|
||||
// If there is more than one predecessor, and there are PHI nodes in
|
||||
// the successor, then we need to add incoming edges for the PHI nodes
|
||||
pred_iterator PI(pred_begin(BB));
|
||||
for (; PI != pred_end(BB); ++PI) {
|
||||
// TODO:
|
||||
}
|
||||
//
|
||||
const vector<BasicBlock*> BBPreds(pred_begin(BB), pred_end(BB));
|
||||
|
||||
BasicBlock::iterator I = Succ->begin();
|
||||
do { // Loop over all of the PHI nodes in the successor BB
|
||||
PHINode *PN = (PHINode*)*I;
|
||||
Value *OldVal = PN->removeIncomingValue(BB);
|
||||
assert(OldVal && "No entry in PHI for Pred BB!");
|
||||
|
||||
for (vector<BasicBlock*>::const_iterator PredI = BBPreds.begin(),
|
||||
End = BBPreds.end(); PredI != End; ++PredI) {
|
||||
// Add an incoming value for each of the new incoming values...
|
||||
PN->addIncoming(OldVal, *PredI);
|
||||
}
|
||||
|
||||
++I;
|
||||
} while ((*I)->isPHINode());
|
||||
}
|
||||
|
||||
static bool DoDCEPass(Method *M) {
|
||||
Method::BasicBlocksType &BBs = M->getBasicBlocks();
|
||||
Method::BasicBlocksType::iterator BBIt, BBEnd = BBs.end();
|
||||
if (BBs.begin() == BBEnd) return false; // Nothing to do
|
||||
Method::iterator BBIt, BBEnd = M->end();
|
||||
if (M->begin() == BBEnd) return false; // Nothing to do
|
||||
bool Changed = false;
|
||||
|
||||
// Loop through now and remove instructions that have no uses...
|
||||
for (BBIt = BBs.begin(); BBIt != BBEnd; BBIt++) {
|
||||
for (BBIt = M->begin(); BBIt != BBEnd; ++BBIt) {
|
||||
Changed |= RemoveUnusedDefs((*BBIt)->getInstList(), BasicBlockDCE());
|
||||
Changed |= RemoveSingularPHIs(*BBIt);
|
||||
}
|
||||
@ -203,11 +214,11 @@ static bool DoDCEPass(Method *M) {
|
||||
// Loop over all of the basic blocks (except the first one) and remove them
|
||||
// if they are unneeded...
|
||||
//
|
||||
for (BBIt = BBs.begin(), ++BBIt; BBIt != BBs.end(); ++BBIt) {
|
||||
for (BBIt = M->begin(), ++BBIt; BBIt != M->end(); ++BBIt) {
|
||||
BasicBlock *BB = *BBIt;
|
||||
assert(BB->getTerminator() && "Degenerate basic block encountered!");
|
||||
|
||||
#if 0
|
||||
#if 0 // This is know to basically work?
|
||||
// Remove basic blocks that have no predecessors... which are unreachable.
|
||||
if (pred_begin(BB) == pred_end(BB) &&
|
||||
!BB->hasConstantPoolReferences() && 0) {
|
||||
@ -215,43 +226,46 @@ static bool DoDCEPass(Method *M) {
|
||||
|
||||
// Loop through all of our successors and make sure they know that one
|
||||
// of their predecessors is going away.
|
||||
for (succ_iterator SI = succ_begin(BB), EI = succ_end(BB); SI != EI; ++SI)
|
||||
RemovePredecessorFromBlock(*SI, BB);
|
||||
for_each(succ_begin(BB), succ_end(BB),
|
||||
bind_2nd(RemovePredecessorFromBlock, BB));
|
||||
|
||||
while (!BB->getInstList().empty()) {
|
||||
Instruction *I = BB->getInstList().front();
|
||||
while (!BB->empty()) {
|
||||
Instruction *I = BB->front();
|
||||
// If this instruction is used, replace uses with an arbitrary
|
||||
// constant value. Because control flow can't get here, we don't care
|
||||
// what we replace the value with.
|
||||
if (!I->use_empty()) ReplaceUsesWithConstant(I);
|
||||
|
||||
// Remove the instruction from the basic block
|
||||
delete BB->getInstList().remove(BB->getInstList().begin());
|
||||
delete BB->getInstList().remove(BB->begin());
|
||||
}
|
||||
delete BBs.remove(BBIt);
|
||||
delete M->getBasicBlocks().remove(BBIt);
|
||||
--BBIt; // remove puts use on the next block, we want the previous one
|
||||
Changed = true;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 // This has problems
|
||||
// Check to see if this block has no instructions and only a single
|
||||
// successor. If so, replace block references with successor.
|
||||
succ_iterator SI(succ_begin(BB));
|
||||
if (SI != succ_end(BB) && ++SI == succ_end(BB)) { // One succ?
|
||||
Instruction *I = BB->getInstList().front();
|
||||
Instruction *I = BB->front();
|
||||
if (I->isTerminator()) { // Terminator is the only instruction!
|
||||
BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor
|
||||
cerr << "Killing Trivial BB: \n" << BB;
|
||||
|
||||
if (Succ->getInstList().front()->getInstType() == Instruction::PHINode){
|
||||
// Add entries to the PHI nodes so that the PHI nodes have the right
|
||||
// number of entries...
|
||||
if (Succ->front()->isPHINode()) {
|
||||
// If our successor has PHI nodes, then we need to update them to
|
||||
// include entries for BB's predecessors, not for BB itself.
|
||||
//
|
||||
PropogatePredecessorsForPHIs(BB, Succ);
|
||||
}
|
||||
|
||||
BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor
|
||||
BB->replaceAllUsesWith(Succ);
|
||||
cerr << "Killing Trivial BB: \n" << BB;
|
||||
|
||||
BB = BBs.remove(BBIt);
|
||||
BB = M->getBasicBlocks().remove(BBIt);
|
||||
--BBIt; // remove puts use on the next block, we want the previous one
|
||||
|
||||
if (BB->hasName() && !Succ->hasName()) // Transfer name if we can
|
||||
@ -280,21 +294,21 @@ static bool DoDCEPass(Method *M) {
|
||||
//cerr << "Merging: " << BB << "into: " << Pred;
|
||||
|
||||
// Delete the unconditianal branch from the predecessor...
|
||||
BasicBlock::InstListType::iterator DI = Pred->getInstList().end();
|
||||
BasicBlock::iterator DI = Pred->end();
|
||||
assert(Pred->getTerminator() &&
|
||||
"Degenerate basic block encountered!"); // Empty bb???
|
||||
delete Pred->getInstList().remove(--DI); // Destroy uncond branch
|
||||
|
||||
// Move all definitions in the succecessor to the predecessor...
|
||||
while (!BB->getInstList().empty()) {
|
||||
DI = BB->getInstList().begin();
|
||||
while (!BB->empty()) {
|
||||
DI = BB->begin();
|
||||
Instruction *Def = BB->getInstList().remove(DI); // Remove from front
|
||||
Pred->getInstList().push_back(Def); // Add to end...
|
||||
}
|
||||
|
||||
// Remove basic block from the method... and advance iterator to the
|
||||
// next valid block...
|
||||
BB = BBs.remove(BBIt);
|
||||
BB = M->getBasicBlocks().remove(BBIt);
|
||||
--BBIt; // remove puts us on the NEXT bb. We want the prev BB
|
||||
Changed = true;
|
||||
|
||||
|
@ -23,7 +23,7 @@ static bool StripSymbolTable(SymbolTable *SymTab) {
|
||||
if (SymTab == 0) return false; // No symbol table? No problem.
|
||||
bool RemovedSymbol = false;
|
||||
|
||||
for (SymbolTable::iterator I = SymTab->begin(); I != SymTab->end(); I++) {
|
||||
for (SymbolTable::iterator I = SymTab->begin(); I != SymTab->end(); ++I) {
|
||||
map<const string, Value *> &Plane = I->second;
|
||||
|
||||
map<const string, Value *>::iterator B;
|
||||
|
@ -178,7 +178,7 @@ bool AssemblyWriter::processInstruction(const Instruction *I) {
|
||||
writeOperand(I->getOperand(op+1), true);
|
||||
}
|
||||
Out << "\n\t]";
|
||||
} else if (I->getInstType() == Instruction::PHINode) {
|
||||
} else if (I->isPHINode()) {
|
||||
Out << " " << Operand->getType();
|
||||
|
||||
Out << " ["; writeOperand(Operand, false); Out << ",";
|
||||
@ -262,7 +262,7 @@ void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType,
|
||||
} else {
|
||||
int Slot = Table.getValSlot(Operand);
|
||||
|
||||
if (Operand->getValueType() == Value::ConstantVal) {
|
||||
if (Operand->isConstant()) {
|
||||
Out << " " << ((ConstPoolVal*)Operand)->getStrValue();
|
||||
} else {
|
||||
if (Slot >= 0) Out << " %" << Slot;
|
||||
@ -313,12 +313,11 @@ void WriteToAssembly(const ConstPoolVal *CPV, ostream &o) {
|
||||
// A Constant pool value may have a parent that is either a method or a
|
||||
// module. Untangle this now...
|
||||
//
|
||||
if (CPV->getParent() == 0 ||
|
||||
CPV->getParent()->getValueType() == Value::MethodVal) {
|
||||
if (CPV->getParent() == 0 || CPV->getParent()->isMethod()) {
|
||||
SlotTable = new SlotCalculator((Method*)CPV->getParent(), true);
|
||||
} else {
|
||||
assert(CPV->getParent()->getValueType() == Value::ModuleVal);
|
||||
SlotTable = new SlotCalculator((Module*)CPV->getParent(), true);
|
||||
SlotTable =
|
||||
new SlotCalculator(CPV->getParent()->castModuleAsserting(), true);
|
||||
}
|
||||
|
||||
AssemblyWriter W(o, *SlotTable);
|
||||
|
@ -73,7 +73,7 @@ void BasicBlock::dropAllReferences() {
|
||||
//
|
||||
bool BasicBlock::hasConstantPoolReferences() const {
|
||||
for (use_const_iterator I = use_begin(), E = use_end(); I != E; ++I)
|
||||
if ((*I)->getValueType() == ConstantVal)
|
||||
if ((*I)->isConstant())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@ -91,7 +91,7 @@ bool BasicBlock::hasConstantPoolReferences() const {
|
||||
// cause a degenerate basic block to be formed, having a terminator inside of
|
||||
// the basic block).
|
||||
//
|
||||
BasicBlock *BasicBlock::splitBasicBlock(InstListType::iterator I) {
|
||||
BasicBlock *BasicBlock::splitBasicBlock(iterator I) {
|
||||
assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
|
||||
assert(I != InstList.end() &&
|
||||
"Trying to get me to create degenerate basic block!");
|
||||
@ -102,7 +102,7 @@ BasicBlock *BasicBlock::splitBasicBlock(InstListType::iterator I) {
|
||||
// to the new basic block...
|
||||
Instruction *Inst = 0;
|
||||
do {
|
||||
InstListType::iterator EndIt = InstList.end();
|
||||
iterator EndIt = end();
|
||||
Inst = InstList.remove(--EndIt); // Remove from end
|
||||
New->InstList.push_front(Inst); // Add to front
|
||||
} while (Inst != *I); // Loop until we move the specified instruction.
|
||||
|
@ -85,9 +85,8 @@ void ConstantPool::delete_all() {
|
||||
|
||||
void ConstantPool::dropAllReferences() {
|
||||
for (unsigned i = 0; i < Planes.size(); i++)
|
||||
for (PlaneType::iterator I = Planes[i]->begin();
|
||||
I != Planes[i]->end(); I++)
|
||||
(*I)->dropAllReferences();
|
||||
for_each(Planes[i]->begin(), Planes[i]->end(),
|
||||
mem_fun(&ConstPoolVal::dropAllReferences));
|
||||
}
|
||||
|
||||
struct EqualsConstant {
|
||||
@ -280,10 +279,7 @@ ConstPoolStruct::ConstPoolStruct(const ConstPoolStruct &CPS)
|
||||
// getStrValue implementations
|
||||
|
||||
string ConstPoolBool::getStrValue() const {
|
||||
if (Val)
|
||||
return "true";
|
||||
else
|
||||
return "false";
|
||||
return Val ? "true" : "false";
|
||||
}
|
||||
|
||||
string ConstPoolSInt::getStrValue() const {
|
||||
|
@ -29,8 +29,8 @@ Method::~Method() {
|
||||
dropAllReferences(); // After this it is safe to delete instructions.
|
||||
|
||||
// TODO: Should remove from the end, not the beginning of vector!
|
||||
BasicBlocksType::iterator BI = BasicBlocks.begin();
|
||||
while ((BI = BasicBlocks.begin()) != BasicBlocks.end())
|
||||
iterator BI = begin();
|
||||
while ((BI = begin()) != end())
|
||||
delete BasicBlocks.remove(BI);
|
||||
|
||||
// Delete all of the method arguments and unlink from symbol table...
|
||||
@ -70,6 +70,5 @@ const MethodType *Method::getMethodType() const {
|
||||
// delete.
|
||||
//
|
||||
void Method::dropAllReferences() {
|
||||
for_each(BasicBlocks.begin(), BasicBlocks.end(),
|
||||
std::mem_fun(&BasicBlock::dropAllReferences));
|
||||
for_each(begin(), end(), std::mem_fun(&BasicBlock::dropAllReferences));
|
||||
}
|
||||
|
@ -68,8 +68,7 @@ bool PHINode::setOperand(unsigned i, Value *Val) {
|
||||
if (i >= IncomingValues.size()*2) return false;
|
||||
|
||||
if (i & 1) {
|
||||
assert(Val->getValueType() == BasicBlockVal && "Not a BB!");
|
||||
IncomingValues[i/2].second = (BasicBlock*)Val;
|
||||
IncomingValues[i/2].second = Val->castBasicBlockAsserting();
|
||||
} else {
|
||||
IncomingValues[i/2].first = Val;
|
||||
}
|
||||
|
@ -37,6 +37,6 @@ Module::~Module() {
|
||||
//
|
||||
void Module::dropAllReferences() {
|
||||
MethodListType::iterator MI = MethodList.begin();
|
||||
for (; MI != MethodList.end(); MI++)
|
||||
for (; MI != MethodList.end(); ++MI)
|
||||
(*MI)->dropAllReferences();
|
||||
}
|
||||
|
@ -176,12 +176,11 @@ void SlotCalculator::insertVal(const Value *D) {
|
||||
// Insert node into table and NodeMap...
|
||||
NodeMap[D] = Table[Ty].size();
|
||||
|
||||
if (Typ == Type::TypeTy && // If it's a type constant, add the Type also
|
||||
D->getValueType() != Value::TypeVal) {
|
||||
assert(D->getValueType() == Value::ConstantVal &&
|
||||
"All Type instances should be constant types!");
|
||||
|
||||
const ConstPoolType *CPT = (const ConstPoolType*)D;
|
||||
if (Typ == Type::TypeTy && !D->isType()) {
|
||||
// If it's a type constant, add the Type also
|
||||
|
||||
// All Type instances should be constant types!
|
||||
const ConstPoolType *CPT = (const ConstPoolType*)D->castConstantAsserting();
|
||||
int Slot = getValSlot(CPT->getValue());
|
||||
if (Slot == -1) {
|
||||
// Only add if it's not already here!
|
||||
|
@ -15,9 +15,9 @@
|
||||
SymbolTable::~SymbolTable() {
|
||||
#ifndef NDEBUG // Only do this in -g mode...
|
||||
bool Good = true;
|
||||
for (iterator i = begin(); i != end(); i++) {
|
||||
for (iterator i = begin(); i != end(); ++i) {
|
||||
if (i->second.begin() != i->second.end()) {
|
||||
for (type_iterator I = i->second.begin(); I != i->second.end(); I++)
|
||||
for (type_iterator I = i->second.begin(); I != i->second.end(); ++I)
|
||||
cerr << "Value still in symbol table! Type = " << i->first->getName()
|
||||
<< " Name = " << I->first << endl;
|
||||
Good = false;
|
||||
|
@ -157,13 +157,13 @@ PointerType::PointerType(const Type *E)
|
||||
const MethodType *MethodType::getMethodType(const Type *ReturnType,
|
||||
const vector<const Type*> &Params) {
|
||||
static vector<const MethodType*> ExistingMethodTypesCache;
|
||||
for (unsigned i = 0; i < ExistingMethodTypesCache.size(); i++) {
|
||||
for (unsigned i = 0; i < ExistingMethodTypesCache.size(); ++i) {
|
||||
const MethodType *T = ExistingMethodTypesCache[i];
|
||||
if (T->getReturnType() == ReturnType) {
|
||||
const ParamTypes &EParams = T->getParamTypes();
|
||||
ParamTypes::const_iterator I = Params.begin();
|
||||
ParamTypes::const_iterator J = EParams.begin();
|
||||
for (; I != Params.end() && J != EParams.end(); I++, J++)
|
||||
for (; I != Params.end() && J != EParams.end(); ++I, ++J)
|
||||
if (*I != *J) break; // These types aren't equal!
|
||||
|
||||
if (I == Params.end() && J == EParams.end()) {
|
||||
@ -189,7 +189,7 @@ const MethodType *MethodType::getMethodType(const Type *ReturnType,
|
||||
// Calculate the string name for the new type...
|
||||
string Name = ReturnType->getName() + " (";
|
||||
for (ParamTypes::const_iterator I = Params.begin();
|
||||
I != Params.end(); I++) {
|
||||
I != Params.end(); ++I) {
|
||||
if (I != Params.begin())
|
||||
Name += ", ";
|
||||
Name += (*I)->getName();
|
||||
@ -211,7 +211,7 @@ const ArrayType *ArrayType::getArrayType(const Type *ElementType,
|
||||
static vector<const ArrayType*> ExistingTypesCache;
|
||||
|
||||
// Search cache for value...
|
||||
for (unsigned i = 0; i < ExistingTypesCache.size(); i++) {
|
||||
for (unsigned i = 0; i < ExistingTypesCache.size(); ++i) {
|
||||
const ArrayType *T = ExistingTypesCache[i];
|
||||
|
||||
if (T->getElementType() == ElementType &&
|
||||
@ -237,13 +237,13 @@ const ArrayType *ArrayType::getArrayType(const Type *ElementType,
|
||||
const StructType *StructType::getStructType(const ElementTypes &ETypes) {
|
||||
static vector<const StructType*> ExistingStructTypesCache;
|
||||
|
||||
for (unsigned i = 0; i < ExistingStructTypesCache.size(); i++) {
|
||||
for (unsigned i = 0; i < ExistingStructTypesCache.size(); ++i) {
|
||||
const StructType *T = ExistingStructTypesCache[i];
|
||||
|
||||
const ElementTypes &Elements = T->getElementTypes();
|
||||
ElementTypes::const_iterator I = ETypes.begin();
|
||||
ElementTypes::const_iterator J = Elements.begin();
|
||||
for (; I != ETypes.end() && J != Elements.end(); I++, J++)
|
||||
for (; I != ETypes.end() && J != Elements.end(); ++I, ++J)
|
||||
if (*I != *J) break; // These types aren't equal!
|
||||
|
||||
if (I == ETypes.end() && J == Elements.end()) {
|
||||
@ -269,7 +269,7 @@ const StructType *StructType::getStructType(const ElementTypes &ETypes) {
|
||||
// Calculate the string name for the new type...
|
||||
string Name = "{ ";
|
||||
for (ElementTypes::const_iterator I = ETypes.begin();
|
||||
I != ETypes.end(); I++) {
|
||||
I != ETypes.end(); ++I) {
|
||||
if (I != ETypes.begin())
|
||||
Name += ", ";
|
||||
Name += (*I)->getName();
|
||||
@ -290,7 +290,7 @@ const PointerType *PointerType::getPointerType(const Type *ValueType) {
|
||||
static vector<const PointerType*> ExistingTypesCache;
|
||||
|
||||
// Search cache for value...
|
||||
for (unsigned i = 0; i < ExistingTypesCache.size(); i++) {
|
||||
for (unsigned i = 0; i < ExistingTypesCache.size(); ++i) {
|
||||
const PointerType *T = ExistingTypesCache[i];
|
||||
|
||||
if (T->getValueType() == ValueType)
|
||||
|
@ -34,7 +34,7 @@ Value::~Value() {
|
||||
// a <badref>
|
||||
//
|
||||
if (Uses.begin() != Uses.end()) {
|
||||
for (use_const_iterator I = Uses.begin(); I != Uses.end(); I++)
|
||||
for (use_const_iterator I = Uses.begin(); I != Uses.end(); ++I)
|
||||
cerr << "Use still stuck around after Def is destroyed:" << *I << endl;
|
||||
}
|
||||
#endif
|
||||
@ -88,7 +88,7 @@ User::User(const Type *Ty, ValueTy vty, const string &name)
|
||||
void User::replaceUsesOfWith(Value *From, Value *To) {
|
||||
if (From == To) return; // Duh what?
|
||||
|
||||
for (unsigned OpNum = 0; Value *D = getOperand(OpNum); OpNum++) {
|
||||
for (unsigned OpNum = 0; Value *D = getOperand(OpNum); ++OpNum) {
|
||||
if (D == From) { // Okay, this operand is pointing to our fake def.
|
||||
// The side effects of this setOperand call include linking to
|
||||
// "To", adding "this" to the uses list of To, and
|
||||
@ -140,7 +140,7 @@ bool SymTabValue::hasSymbolTable() const {
|
||||
if (!SymTab) return false;
|
||||
|
||||
for (SymbolTable::const_iterator I = SymTab->begin();
|
||||
I != SymTab->end(); I++) {
|
||||
I != SymTab->end(); ++I) {
|
||||
if (I->second.begin() != I->second.end())
|
||||
return true; // Found nonempty type plane!
|
||||
}
|
||||
|
@ -71,10 +71,9 @@ static bool verify(const BasicBlock *BB, vector<string> &ErrorMsgs) {
|
||||
bool verify(const Method *M, vector<string> &ErrorMsgs) {
|
||||
bool Bad = false;
|
||||
|
||||
for (Method::BasicBlocksType::const_iterator BBIt = M->getBasicBlocks().begin();
|
||||
BBIt != M->getBasicBlocks().end(); BBIt++) {
|
||||
for (Method::const_iterator BBIt = M->begin();
|
||||
BBIt != M->end(); ++BBIt)
|
||||
Bad |= verify(*BBIt, ErrorMsgs);
|
||||
}
|
||||
|
||||
return Bad;
|
||||
}
|
||||
@ -84,11 +83,8 @@ bool verify(const Module *C, vector<string> &ErrorMsgs) {
|
||||
assert(Type::FirstDerivedTyID-1 < sizeof(long)*8 &&
|
||||
"Resize ValidTypes table to handle more than 32 primitive types!");
|
||||
|
||||
for (Module::MethodListType::const_iterator MI = C->getMethodList().begin();
|
||||
MI != C->getMethodList().end(); MI++) {
|
||||
const Method *M = *MI;
|
||||
Bad |= verify(M, ErrorMsgs);
|
||||
}
|
||||
for (Module::const_iterator MI = C->begin(); MI != C->end(); ++MI)
|
||||
Bad |= verify(*MI, ErrorMsgs);
|
||||
|
||||
return Bad;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ CallInst::CallInst(Method *m, vector<Value*> ¶ms,
|
||||
|
||||
const MethodType* MT = M->getMethodType();
|
||||
const MethodType::ParamTypes &PL = MT->getParamTypes();
|
||||
assert(params.size() == PL.size());
|
||||
assert(params.size() == PL.size() && "Calling a function with bad signature");
|
||||
#ifndef NDEBUG
|
||||
MethodType::ParamTypes::const_iterator It = PL.begin();
|
||||
#endif
|
||||
@ -38,8 +38,7 @@ void CallInst::dropAllReferences() {
|
||||
bool CallInst::setOperand(unsigned i, Value *Val) {
|
||||
if (i > Params.size()) return false;
|
||||
if (i == 0) {
|
||||
assert(Val->getValueType() == Value::MethodVal);
|
||||
M = (Method*)Val;
|
||||
M = Val->castMethodAsserting();
|
||||
} else {
|
||||
// TODO: assert = method arg type
|
||||
Params[i-1] = Val;
|
||||
|
36
test/sccptest.ll
Normal file
36
test/sccptest.ll
Normal file
@ -0,0 +1,36 @@
|
||||
implementation
|
||||
|
||||
int "test function"(int %i0, int %j0)
|
||||
%i1 = int 1
|
||||
%j1 = int 1
|
||||
%k1 = int 0
|
||||
begin
|
||||
BB1:
|
||||
br label %BB2
|
||||
BB2:
|
||||
%j2 = phi int [%j4, %BB7], [%j1, %BB1]
|
||||
%k2 = phi int [%k4, %BB7], [%k1, %BB1]
|
||||
%kcond = setlt int %k2, 100
|
||||
br bool %kcond, label %BB3, label %BB4
|
||||
|
||||
BB3:
|
||||
%jcond = setlt int %j2, 20
|
||||
br bool %jcond, label %BB5, label %BB6
|
||||
|
||||
BB4:
|
||||
ret int %j2
|
||||
|
||||
BB5:
|
||||
%k3 = add int %k2, 1
|
||||
br label %BB7
|
||||
|
||||
BB6:
|
||||
%k5 = add int %k2, 1
|
||||
br label %BB7
|
||||
|
||||
BB7:
|
||||
%j4 = phi int [%i1, %BB5], [%k2, %BB6]
|
||||
%k4 = phi int [%k3, %BB5], [%k5, %BB6]
|
||||
br label %BB2
|
||||
end
|
||||
|
@ -94,8 +94,7 @@ int main(int argc, char **argv) {
|
||||
// methods... more should definately be printed. It should be valid output
|
||||
// consumable by the assembler.
|
||||
//
|
||||
for (Module::MethodListType::iterator I = C->getMethodList().begin();
|
||||
I != C->getMethodList().end(); I++) {
|
||||
for (Module::iterator I = C->begin(), End = C->end(); I != End; ++I) {
|
||||
Method *M = *I;
|
||||
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
||||
|
||||
|
@ -94,8 +94,7 @@ int main(int argc, char **argv) {
|
||||
// methods... more should definately be printed. It should be valid output
|
||||
// consumable by the assembler.
|
||||
//
|
||||
for (Module::MethodListType::iterator I = C->getMethodList().begin();
|
||||
I != C->getMethodList().end(); I++) {
|
||||
for (Module::iterator I = C->begin(), End = C->end(); I != End; ++I) {
|
||||
Method *M = *I;
|
||||
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
||||
|
||||
|
@ -94,8 +94,7 @@ int main(int argc, char **argv) {
|
||||
// methods... more should definately be printed. It should be valid output
|
||||
// consumable by the assembler.
|
||||
//
|
||||
for (Module::MethodListType::iterator I = C->getMethodList().begin();
|
||||
I != C->getMethodList().end(); I++) {
|
||||
for (Module::iterator I = C->begin(), End = C->end(); I != End; ++I) {
|
||||
Method *M = *I;
|
||||
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user