Rename some GC classes so that their roll will hopefully be clearer.

In particular, Collector was confusing to implementors. Several
thought that this compile-time class was the place to implement
their runtime GC heap. Of course, it doesn't even exist at runtime.
Specifically, the renames are:

  Collector               -> GCStrategy
  CollectorMetadata       -> GCFunctionInfo
  CollectorModuleMetadata -> GCModuleInfo
  CollectorRegistry       -> GCRegistry
  Function::getCollector  -> getGC (setGC, hasGC, clearGC)

Several accessors and nested types have also been renamed to be
consistent. These changes should be obvious.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54899 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Gordon Henriksen
2008-08-17 18:44:35 +00:00
parent 94fb5f2a70
commit 5eca075b74
38 changed files with 524 additions and 678 deletions

View File

@@ -16,9 +16,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
#include "llvm/Module.h"
#include "llvm/CodeGen/GCStrategy.h"
#include "llvm/CodeGen/GCMetadata.h"
#include "llvm/CodeGen/GCs.h"
#include "llvm/CodeGen/GCMetadataPrinter.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
@@ -110,18 +108,17 @@ void AsmPrinter::SwitchToDataSection(const char *NewSection,
void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
MachineFunctionPass::getAnalysisUsage(AU);
AU.addRequired<CollectorModuleMetadata>();
AU.addRequired<GCModuleInfo>();
}
bool AsmPrinter::doInitialization(Module &M) {
Mang = new Mangler(M, TAI->getGlobalPrefix());
CollectorModuleMetadata *CMM = getAnalysisToUpdate<CollectorModuleMetadata>();
assert(CMM && "AsmPrinter didn't require CollectorModuleMetadata?");
for (CollectorModuleMetadata::iterator I = CMM->begin(),
E = CMM->end(); I != E; ++I)
if (GCMetadataPrinter *GCP = GetOrCreateGCPrinter(*I))
GCP->beginAssembly(O, *this, *TAI);
GCModuleInfo *MI = getAnalysisToUpdate<GCModuleInfo>();
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
MP->beginAssembly(O, *this, *TAI);
if (!M.getModuleInlineAsm().empty())
O << TAI->getCommentString() << " Start of file scope inline assembly\n"
@@ -192,12 +189,11 @@ bool AsmPrinter::doFinalization(Module &M) {
}
}
CollectorModuleMetadata *CMM = getAnalysisToUpdate<CollectorModuleMetadata>();
assert(CMM && "AsmPrinter didn't require CollectorModuleMetadata?");
for (CollectorModuleMetadata::iterator I = CMM->end(),
E = CMM->begin(); I != E; )
if (GCMetadataPrinter *GCP = GetOrCreateGCPrinter(*--I))
GCP->finishAssembly(O, *this, *TAI);
GCModuleInfo *MI = getAnalysisToUpdate<GCModuleInfo>();
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I))
MP->finishAssembly(O, *this, *TAI);
// If we don't have any trampolines, then we don't require stack memory
// to be executable. Some targets have a directive to declare this.
@@ -1466,26 +1462,26 @@ void AsmPrinter::printVisibility(const std::string& Name,
}
}
GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(Collector *C) {
if (!C->usesMetadata())
GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
if (!S->usesMetadata())
return 0;
gcp_iterator GCPI = GCMetadataPrinters.find(C);
gcp_iterator GCPI = GCMetadataPrinters.find(S);
if (GCPI != GCMetadataPrinters.end())
return GCPI->second;
const char *Name = C->getName().c_str();
const char *Name = S->getName().c_str();
for (GCMetadataPrinterRegistry::iterator
I = GCMetadataPrinterRegistry::begin(),
E = GCMetadataPrinterRegistry::end(); I != E; ++I)
if (strcmp(Name, I->getName()) == 0) {
GCMetadataPrinter *GCP = I->instantiate();
GCP->Coll = C;
GCMetadataPrinters.insert(std::make_pair(C, GCP));
return GCP;
GCMetadataPrinter *GMP = I->instantiate();
GMP->S = S;
GCMetadataPrinters.insert(std::make_pair(S, GMP));
return GMP;
}
cerr << "no GCMetadataPrinter registered for collector: " << Name << "\n";
cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";
abort();
}

View File

@@ -1,4 +1,4 @@
//===-- OcamlCollector.cpp - Ocaml frametable emitter ---------------------===//
//===-- OcamlGCPrinter.cpp - Ocaml frametable emitter ---------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,13 +7,13 @@
//
//===----------------------------------------------------------------------===//
//
// This file implements lowering for the llvm.gc* intrinsics compatible with
// Objective Caml 3.10.0, which uses a liveness-accurate static stack map.
// This file implements printing the assembly code for an Ocaml frametable.
//
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/GCs.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/GCMetadataPrinter.h"
#include "llvm/CodeGen/GCStrategy.h"
#include "llvm/Module.h"
#include "llvm/Target/TargetAsmInfo.h"
@@ -38,9 +38,7 @@ namespace {
static GCMetadataPrinterRegistry::Add<OcamlGCMetadataPrinter>
Y("ocaml", "ocaml 3.10-compatible collector");
GCMetadataPrinter *llvm::createOcamlMetadataPrinter() {
return new OcamlGCMetadataPrinter();
}
void llvm::linkOcamlGCPrinter() { }
static void EmitCamlGlobal(const Module &M, std::ostream &OS, AsmPrinter &AP,
const TargetAsmInfo &TAI, const char *Id) {
@@ -85,7 +83,7 @@ void OcamlGCMetadataPrinter::beginAssembly(std::ostream &OS, AsmPrinter &AP,
///
/// Note that this precludes programs from stack frames larger than 64K
/// (FrameSize and LiveOffsets would overflow). FrameTablePrinter will abort if
/// either condition is detected in a function which uses the collector.
/// either condition is detected in a function which uses the GC.
///
void OcamlGCMetadataPrinter::finishAssembly(std::ostream &OS, AsmPrinter &AP,
const TargetAsmInfo &TAI) {
@@ -111,33 +109,32 @@ void OcamlGCMetadataPrinter::finishAssembly(std::ostream &OS, AsmPrinter &AP,
AP.SwitchToDataSection(TAI.getDataSection());
EmitCamlGlobal(getModule(), OS, AP, TAI, "frametable");
for (iterator FI = begin(), FE = end(); FI != FE; ++FI) {
CollectorMetadata &MD = **FI;
for (iterator I = begin(), IE = end(); I != IE; ++I) {
GCFunctionInfo &FI = **I;
uint64_t FrameSize = FI.getFrameSize();
if (FrameSize >= 1<<16) {
cerr << "Function '" << FI.getFunction().getNameStart()
<< "' is too large for the ocaml GC! "
<< "Frame size " << FrameSize << " >= 65536.\n";
cerr << "(" << uintptr_t(&FI) << ")\n";
abort(); // Very rude!
}
OS << "\t" << TAI.getCommentString() << " live roots for "
<< MD.getFunction().getNameStart() << "\n";
<< FI.getFunction().getNameStart() << "\n";
for (CollectorMetadata::iterator PI = MD.begin(),
PE = MD.end(); PI != PE; ++PI) {
uint64_t FrameSize = MD.getFrameSize();
if (FrameSize >= 1<<16) {
cerr << "Function '" << MD.getFunction().getNameStart()
<< "' is too large for the ocaml collector! "
<< "Frame size " << FrameSize << " >= 65536.\n";
abort(); // Very rude!
}
size_t LiveCount = MD.live_size(PI);
for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) {
size_t LiveCount = FI.live_size(J);
if (LiveCount >= 1<<16) {
cerr << "Function '" << MD.getFunction().getNameStart()
<< "' is too large for the ocaml collector! "
cerr << "Function '" << FI.getFunction().getNameStart()
<< "' is too large for the ocaml GC! "
<< "Live root count " << LiveCount << " >= 65536.\n";
abort(); // Very rude!
}
OS << AddressDirective
<< TAI.getPrivateGlobalPrefix() << "label" << PI->Num;
<< TAI.getPrivateGlobalPrefix() << "label" << J->Num;
AP.EOL("call return address");
AP.EmitInt16(FrameSize);
@@ -146,14 +143,13 @@ void OcamlGCMetadataPrinter::finishAssembly(std::ostream &OS, AsmPrinter &AP,
AP.EmitInt16(LiveCount);
AP.EOL("live root count");
for (CollectorMetadata::live_iterator LI = MD.live_begin(PI),
LE = MD.live_end(PI);
LI != LE; ++LI) {
assert(LI->StackOffset < 1<<16 &&
for (GCFunctionInfo::live_iterator K = FI.live_begin(J),
KE = FI.live_end(J); K != KE; ++K) {
assert(K->StackOffset < 1<<16 &&
"GC root stack offset is outside of fixed stack frame and out "
"of range for Ocaml collector!");
"of range for ocaml GC!");
OS << "\t.word\t" << LI->StackOffset;
OS << "\t.word\t" << K->StackOffset;
AP.EOL("stack offset");
}