X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FCollectorMetadata.cpp;h=80085cd29de1e039f4755427c1cd588c0940206f;hb=249ded3fa8884f91fded869fb6e251b8aebb0376;hp=f86ee04c9510b6e1c47b7d61af0e22805effd0e3;hpb=fc3282221f90c626d80292327213e2badc3de86b;p=oota-llvm.git diff --git a/lib/CodeGen/CollectorMetadata.cpp b/lib/CodeGen/CollectorMetadata.cpp index f86ee04c951..80085cd29de 100644 --- a/lib/CodeGen/CollectorMetadata.cpp +++ b/lib/CodeGen/CollectorMetadata.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Gordon Henriksen and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -13,8 +13,11 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/CollectorMetadata.h" +#include "llvm/CodeGen/Collector.h" +#include "llvm/CodeGen/Collectors.h" #include "llvm/CodeGen/MachineFrameInfo.h" -#include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/Pass.h" +#include "llvm/CodeGen/Passes.h" #include "llvm/Function.h" #include "llvm/Support/Compiler.h" @@ -22,20 +25,20 @@ using namespace llvm; namespace { - class VISIBILITY_HIDDEN Printer : public MachineFunctionPass { + class VISIBILITY_HIDDEN Printer : public FunctionPass { static char ID; std::ostream &OS; public: - Printer(std::ostream &OS = *cerr); + explicit Printer(std::ostream &OS = *cerr); const char *getPassName() const; void getAnalysisUsage(AnalysisUsage &AU) const; - bool runOnMachineFunction(MachineFunction &MF); + bool runOnFunction(Function &F); }; - class VISIBILITY_HIDDEN Deleter : public MachineFunctionPass { + class VISIBILITY_HIDDEN Deleter : public FunctionPass { static char ID; public: @@ -44,7 +47,7 @@ namespace { const char *getPassName() const; void getAnalysisUsage(AnalysisUsage &AU) const; - bool runOnMachineFunction(MachineFunction &MF); + bool runOnFunction(Function &F); bool doFinalization(Module &M); }; @@ -55,8 +58,8 @@ namespace { // ----------------------------------------------------------------------------- -CollectorMetadata::CollectorMetadata(const Function &F) - : F(F), FrameSize(~0LL) {} +CollectorMetadata::CollectorMetadata(const Function &F, Collector &C) + : F(F), C(C), FrameSize(~0LL) {} CollectorMetadata::~CollectorMetadata() {} @@ -71,46 +74,71 @@ CollectorModuleMetadata::~CollectorModuleMetadata() { clear(); } -CollectorMetadata& CollectorModuleMetadata::insert(const Function *F) { - assert(Map.find(F) == Map.end() && "Function GC metadata already exists!"); - CollectorMetadata *FMD = new CollectorMetadata(*F); - Functions.push_back(FMD); - Map[F] = FMD; - return *FMD; +Collector *CollectorModuleMetadata:: +getOrCreateCollector(const Module *M, const std::string &Name) { + const char *Start = Name.c_str(); + + collector_map_type::iterator NMI = NameMap.find(Start, Start + Name.size()); + if (NMI != NameMap.end()) + return NMI->getValue(); + + for (CollectorRegistry::iterator I = CollectorRegistry::begin(), + E = CollectorRegistry::end(); I != E; ++I) { + if (strcmp(Start, I->getName()) == 0) { + Collector *C = I->instantiate(); + C->M = M; + C->Name = Name; + NameMap.GetOrCreateValue(Start, Start + Name.size()).setValue(C); + Collectors.push_back(C); + return C; + } + } + + cerr << "unsupported collector: " << Name << "\n"; + abort(); } -CollectorMetadata* CollectorModuleMetadata::get(const Function *F) const { - map_type::iterator I = Map.find(F); - if (I == Map.end()) - return 0; - return I->second; +CollectorMetadata &CollectorModuleMetadata::get(const Function &F) { + assert(F.hasCollector()); + function_map_type::iterator I = Map.find(&F); + if (I != Map.end()) + return *I->second; + + Collector *C = getOrCreateCollector(F.getParent(), F.getCollector()); + CollectorMetadata *MD = C->insertFunctionMetadata(F); + Map[&F] = MD; + return *MD; } void CollectorModuleMetadata::clear() { + Map.clear(); + + // TODO: StringMap should provide a clear method. + while (!NameMap.empty()) + NameMap.erase(NameMap.begin()); + for (iterator I = begin(), E = end(); I != E; ++I) delete *I; - - Functions.clear(); - Map.clear(); + Collectors.clear(); } // ----------------------------------------------------------------------------- char Printer::ID = 0; -Pass *llvm::createCollectorMetadataPrinter(std::ostream &OS) { +FunctionPass *llvm::createCollectorMetadataPrinter(std::ostream &OS) { return new Printer(OS); } Printer::Printer(std::ostream &OS) - : MachineFunctionPass(intptr_t(&ID)), OS(OS) {} + : FunctionPass(intptr_t(&ID)), OS(OS) {} const char *Printer::getPassName() const { return "Print Garbage Collector Information"; } void Printer::getAnalysisUsage(AnalysisUsage &AU) const { - MachineFunctionPass::getAnalysisUsage(AU); + FunctionPass::getAnalysisUsage(AU); AU.setPreservesAll(); AU.addRequired(); } @@ -125,9 +153,9 @@ static const char *DescKind(GC::PointKind Kind) { } } -bool Printer::runOnMachineFunction(MachineFunction &MF) { - if (CollectorMetadata *FD = - getAnalysis().get(MF.getFunction())) { +bool Printer::runOnFunction(Function &F) { + if (F.hasCollector()) { + CollectorMetadata *FD = &getAnalysis().get(F); OS << "GC roots for " << FD->getFunction().getNameStart() << ":\n"; for (CollectorMetadata::roots_iterator RI = FD->roots_begin(), @@ -160,11 +188,11 @@ bool Printer::runOnMachineFunction(MachineFunction &MF) { char Deleter::ID = 0; -Pass *llvm::createCollectorMetadataDeleter() { +FunctionPass *llvm::createCollectorMetadataDeleter() { return new Deleter(); } -Deleter::Deleter() : MachineFunctionPass(intptr_t(&ID)) {} +Deleter::Deleter() : FunctionPass(intptr_t(&ID)) {} const char *Deleter::getPassName() const { return "Delete Garbage Collector Information"; @@ -175,11 +203,13 @@ void Deleter::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); } -bool Deleter::runOnMachineFunction(MachineFunction &MF) { +bool Deleter::runOnFunction(Function &MF) { return false; } bool Deleter::doFinalization(Module &M) { - getAnalysis().clear(); + CollectorModuleMetadata *CMM = getAnalysisToUpdate(); + assert(CMM && "Deleter didn't require CollectorModuleMetadata?!"); + CMM->clear(); return false; }