Made ClassIMPCache a ModulePass (it shouldn't be a FunctionPass because it adds globals).

main
theraven 16 years ago
parent 60f87bc4ad
commit beb8356367

@ -14,31 +14,29 @@ using std::string;
namespace
{
class ClassIMPCachePass : public FunctionPass
class ClassIMPCachePass : public ModulePass
{
GNUstep::IMPCacher *cacher;
Module *M;
const IntegerType *IntTy;
public:
static char ID;
ClassIMPCachePass() : FunctionPass((intptr_t)&ID) {}
~ClassIMPCachePass() { delete cacher; }
ClassIMPCachePass() : ModulePass((intptr_t)&ID) {}
virtual bool doInitialization(Module &Mod) {
M = &Mod;
cacher = new GNUstep::IMPCacher(Mod.getContext(), this);
virtual bool runOnModule(Module &M) {
GNUstep::IMPCacher cacher = GNUstep::IMPCacher(M.getContext(), this);
// FIXME: ILP64
IntTy = Type::getInt32Ty(Mod.getContext());
return false;
}
virtual bool runOnFunction(Function &F) {
IntTy = Type::getInt32Ty(M.getContext());
bool modified = false;
for (Module::iterator F=M.begin(), fend=M.end() ;
F != fend ; ++F) {
if (F->isDeclaration()) { continue; }
SmallVector<CallInst*, 16> Lookups;
BasicBlock *entry = &F.getEntryBlock();
BasicBlock *entry = &F->getEntryBlock();
for (Function::iterator i=F.begin(), end=F.end() ;
for (Function::iterator i=F->begin(), end=F->end() ;
i != end ; ++i) {
for (BasicBlock::iterator b=i->begin(), last=i->end() ;
b != last ; ++b) {
@ -82,13 +80,14 @@ namespace
e=Lookups.end() ; e!=i ; i++) {
const Type *SlotPtrTy = (*i)->getType();
Value *slot = new GlobalVariable(*M, SlotPtrTy, false,
Value *slot = new GlobalVariable(M, SlotPtrTy, false,
GlobalValue::PrivateLinkage, Constant::getNullValue(SlotPtrTy),
"slot");
Value *version = new GlobalVariable(*M, IntTy, false,
Value *version = new GlobalVariable(M, IntTy, false,
GlobalValue::PrivateLinkage, Constant::getNullValue(IntTy),
"version");
cacher->CacheLookup(*i, slot, version);
cacher.CacheLookup(*i, slot, version);
}
}
return modified;
}
@ -99,7 +98,7 @@ namespace
"Cache IMPs for class messages");
}
FunctionPass *createClassIMPCachePass(void)
ModulePass *createClassIMPCachePass(void)
{
return new ClassIMPCachePass();
}

Loading…
Cancel
Save