aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/AsmPrinter/AsmPrinter.cpp46
-rw-r--r--lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp58
-rw-r--r--lib/CodeGen/GCMetadata.cpp104
-rw-r--r--lib/CodeGen/GCMetadataPrinter.cpp18
-rw-r--r--lib/CodeGen/GCStrategy.cpp107
-rw-r--r--lib/CodeGen/GCs.cpp28
-rw-r--r--lib/CodeGen/LLVMTargetMachine.cpp8
-rw-r--r--lib/CodeGen/OcamlGC.cpp27
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp35
-rw-r--r--lib/CodeGen/ShadowStackGC.cpp49
10 files changed, 226 insertions, 254 deletions
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index de31840d70..380b3bc214 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -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();
}
diff --git a/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp b/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
index efa7f67276..42f1a0fe92 100644
--- a/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
@@ -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");
}
diff --git a/lib/CodeGen/GCMetadata.cpp b/lib/CodeGen/GCMetadata.cpp
index 0b5c6f0662..efb89e128e 100644
--- a/lib/CodeGen/GCMetadata.cpp
+++ b/lib/CodeGen/GCMetadata.cpp
@@ -1,4 +1,4 @@
-//===-- CollectorMetadata.cpp - Garbage collector metadata ----------------===//
+//===-- GCMetadata.cpp - Garbage collector metadata -----------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,14 +7,12 @@
//
//===----------------------------------------------------------------------===//
//
-// This file implements the CollectorMetadata and CollectorModuleMetadata
-// classes.
+// This file implements the GCFunctionInfo class and GCModuleInfo pass.
//
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/GCMetadata.h"
#include "llvm/CodeGen/GCStrategy.h"
-#include "llvm/CodeGen/GCs.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/Pass.h"
#include "llvm/CodeGen/Passes.h"
@@ -53,79 +51,80 @@ namespace {
}
-static RegisterPass<CollectorModuleMetadata>
+static RegisterPass<GCModuleInfo>
X("collector-metadata", "Create Garbage Collector Module Metadata");
// -----------------------------------------------------------------------------
-CollectorMetadata::CollectorMetadata(const Function &F, Collector &C)
- : F(F), C(C), FrameSize(~0LL) {}
+GCFunctionInfo::GCFunctionInfo(const Function &F, GCStrategy &S)
+ : F(F), S(S), FrameSize(~0LL) {}
-CollectorMetadata::~CollectorMetadata() {}
+GCFunctionInfo::~GCFunctionInfo() {}
// -----------------------------------------------------------------------------
-char CollectorModuleMetadata::ID = 0;
+char GCModuleInfo::ID = 0;
-CollectorModuleMetadata::CollectorModuleMetadata()
+GCModuleInfo::GCModuleInfo()
: ImmutablePass((intptr_t)&ID) {}
-CollectorModuleMetadata::~CollectorModuleMetadata() {
+GCModuleInfo::~GCModuleInfo() {
clear();
}
-Collector *CollectorModuleMetadata::
-getOrCreateCollector(const Module *M, const std::string &Name) {
+GCStrategy *GCModuleInfo::getOrCreateStrategy(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())
+ strategy_map_type::iterator NMI =
+ StrategyMap.find(Start, Start + Name.size());
+ if (NMI != StrategyMap.end())
return NMI->getValue();
- for (CollectorRegistry::iterator I = CollectorRegistry::begin(),
- E = CollectorRegistry::end(); I != E; ++I) {
+ for (GCRegistry::iterator I = GCRegistry::begin(),
+ E = GCRegistry::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;
+ GCStrategy *S = I->instantiate();
+ S->M = M;
+ S->Name = Name;
+ StrategyMap.GetOrCreateValue(Start, Start + Name.size()).setValue(S);
+ StrategyList.push_back(S);
+ return S;
}
}
- cerr << "unsupported collector: " << Name << "\n";
+ cerr << "unsupported GC: " << Name << "\n";
abort();
}
-CollectorMetadata &CollectorModuleMetadata::get(const Function &F) {
+GCFunctionInfo &GCModuleInfo::getFunctionInfo(const Function &F) {
assert(!F.isDeclaration() && "Can only get GCFunctionInfo for a definition!");
- assert(F.hasCollector());
+ assert(F.hasGC());
- function_map_type::iterator I = Map.find(&F);
- if (I != Map.end())
+ finfo_map_type::iterator I = FInfoMap.find(&F);
+ if (I != FInfoMap.end())
return *I->second;
-
- Collector *C = getOrCreateCollector(F.getParent(), F.getCollector());
- CollectorMetadata *MD = C->insertFunctionMetadata(F);
- Map[&F] = MD;
- return *MD;
+
+ GCStrategy *S = getOrCreateStrategy(F.getParent(), F.getGC());
+ GCFunctionInfo *GFI = S->insertFunctionInfo(F);
+ FInfoMap[&F] = GFI;
+ return *GFI;
}
-void CollectorModuleMetadata::clear() {
- Map.clear();
- NameMap.clear();
+void GCModuleInfo::clear() {
+ FInfoMap.clear();
+ StrategyMap.clear();
for (iterator I = begin(), E = end(); I != E; ++I)
delete *I;
- Collectors.clear();
+ StrategyList.clear();
}
// -----------------------------------------------------------------------------
char Printer::ID = 0;
-FunctionPass *llvm::createCollectorMetadataPrinter(std::ostream &OS) {
+FunctionPass *llvm::createGCInfoPrinter(std::ostream &OS) {
return new Printer(OS);
}
@@ -139,7 +138,7 @@ const char *Printer::getPassName() const {
void Printer::getAnalysisUsage(AnalysisUsage &AU) const {
FunctionPass::getAnalysisUsage(AU);
AU.setPreservesAll();
- AU.addRequired<CollectorModuleMetadata>();
+ AU.addRequired<GCModuleInfo>();
}
static const char *DescKind(GC::PointKind Kind) {
@@ -153,23 +152,22 @@ static const char *DescKind(GC::PointKind Kind) {
}
bool Printer::runOnFunction(Function &F) {
- if (F.hasCollector()) {
- CollectorMetadata *FD = &getAnalysis<CollectorModuleMetadata>().get(F);
+ if (!F.hasGC()) {
+ GCFunctionInfo *FD = &getAnalysis<GCModuleInfo>().getFunctionInfo(F);
OS << "GC roots for " << FD->getFunction().getNameStart() << ":\n";
- for (CollectorMetadata::roots_iterator RI = FD->roots_begin(),
- RE = FD->roots_end();
- RI != RE; ++RI)
+ for (GCFunctionInfo::roots_iterator RI = FD->roots_begin(),
+ RE = FD->roots_end(); RI != RE; ++RI)
OS << "\t" << RI->Num << "\t" << RI->StackOffset << "[sp]\n";
OS << "GC safe points for " << FD->getFunction().getNameStart() << ":\n";
- for (CollectorMetadata::iterator PI = FD->begin(),
- PE = FD->end(); PI != PE; ++PI) {
+ for (GCFunctionInfo::iterator PI = FD->begin(),
+ PE = FD->end(); PI != PE; ++PI) {
OS << "\tlabel " << PI->Num << ": " << DescKind(PI->Kind) << ", live = {";
- for (CollectorMetadata::live_iterator RI = FD->live_begin(PI),
- RE = FD->live_end(PI);;) {
+ for (GCFunctionInfo::live_iterator RI = FD->live_begin(PI),
+ RE = FD->live_end(PI);;) {
OS << " " << RI->Num;
if (++RI == RE)
break;
@@ -187,7 +185,7 @@ bool Printer::runOnFunction(Function &F) {
char Deleter::ID = 0;
-FunctionPass *llvm::createCollectorMetadataDeleter() {
+FunctionPass *llvm::createGCInfoDeleter() {
return new Deleter();
}
@@ -199,7 +197,7 @@ const char *Deleter::getPassName() const {
void Deleter::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
- AU.addRequired<CollectorModuleMetadata>();
+ AU.addRequired<GCModuleInfo>();
}
bool Deleter::runOnFunction(Function &MF) {
@@ -207,8 +205,8 @@ bool Deleter::runOnFunction(Function &MF) {
}
bool Deleter::doFinalization(Module &M) {
- CollectorModuleMetadata *CMM = getAnalysisToUpdate<CollectorModuleMetadata>();
- assert(CMM && "Deleter didn't require CollectorModuleMetadata?!");
- CMM->clear();
+ GCModuleInfo *GMI = getAnalysisToUpdate<GCModuleInfo>();
+ assert(GMI && "Deleter didn't require GCModuleInfo?!");
+ GMI->clear();
return false;
}
diff --git a/lib/CodeGen/GCMetadataPrinter.cpp b/lib/CodeGen/GCMetadataPrinter.cpp
index b16d873520..07ec0bd035 100644
--- a/lib/CodeGen/GCMetadataPrinter.cpp
+++ b/lib/CodeGen/GCMetadataPrinter.cpp
@@ -1,4 +1,4 @@
-//===-- Collector.cpp - Garbage collection infrastructure -----------------===//
+//===-- GCMetadataPrinter.cpp - Garbage collection infrastructure ---------===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,15 +7,25 @@
//
//===----------------------------------------------------------------------===//
//
-// This file implements target- and collector-independent garbage collection
-// infrastructure.
+// This file implements the abstract base class GCMetadataPrinter.
//
//===----------------------------------------------------------------------===//
-#include "llvm/CodeGen/GCStrategy.h"
+#include "llvm/CodeGen/GCMetadataPrinter.h"
using namespace llvm;
+// -----------------------------------------------------------------------------
+
+template<> GCMetadataPrinterRegistry::node *GCMetadataPrinterRegistry::Head = 0;
+template<> GCMetadataPrinterRegistry::node *GCMetadataPrinterRegistry::Tail = 0;
+template<> GCMetadataPrinterRegistry::listener *
+GCMetadataPrinterRegistry::ListenerHead = 0;
+template<> GCMetadataPrinterRegistry::listener *
+GCMetadataPrinterRegistry::ListenerTail = 0;
+
+// -----------------------------------------------------------------------------
+
GCMetadataPrinter::GCMetadataPrinter() { }
GCMetadataPrinter::~GCMetadataPrinter() { }
diff --git a/lib/CodeGen/GCStrategy.cpp b/lib/CodeGen/GCStrategy.cpp
index f5cb9ab631..2666775996 100644
--- a/lib/CodeGen/GCStrategy.cpp
+++ b/lib/CodeGen/GCStrategy.cpp
@@ -1,4 +1,4 @@
-//===-- Collector.cpp - Garbage collection infrastructure -----------------===//
+//===-- GCStrategy.cpp - Garbage collection infrastructure -----------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,6 +10,9 @@
// This file implements target- and collector-independent garbage collection
// infrastructure.
//
+// MachineCodeAnalysis identifies the GC safe points in the machine code. Roots
+// are identified in SelectionDAGISel.
+//
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/GCStrategy.h"
@@ -31,13 +34,13 @@ namespace {
/// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or
/// llvm.gcwrite intrinsics, replacing them with simple loads and stores as
- /// directed by the Collector. It also performs automatic root initialization
+ /// directed by the GCStrategy. It also performs automatic root initialization
/// and custom intrinsic lowering.
class VISIBILITY_HIDDEN LowerIntrinsics : public FunctionPass {
- static bool NeedsDefaultLoweringPass(const Collector &C);
- static bool NeedsCustomLoweringPass(const Collector &C);
+ static bool NeedsDefaultLoweringPass(const GCStrategy &C);
+ static bool NeedsCustomLoweringPass(const GCStrategy &C);
static bool CouldBecomeSafePoint(Instruction *I);
- bool PerformDefaultLowering(Function &F, Collector &Coll);
+ bool PerformDefaultLowering(Function &F, GCStrategy &Coll);
static bool InsertRootInitializers(Function &F,
AllocaInst **Roots, unsigned Count);
@@ -56,10 +59,10 @@ namespace {
/// MachineCodeAnalysis - This is a target-independent pass over the machine
/// function representation to identify safe points for the garbage collector
/// in the machine code. It inserts labels at safe points and populates a
- /// CollectorMetadata record for each function.
+ /// GCMetadata record for each function.
class VISIBILITY_HIDDEN MachineCodeAnalysis : public MachineFunctionPass {
const TargetMachine *TM;
- CollectorMetadata *MD;
+ GCFunctionInfo *FI;
MachineModuleInfo *MMI;
const TargetInstrInfo *TII;
MachineFrameInfo *MFI;
@@ -85,7 +88,14 @@ namespace {
// -----------------------------------------------------------------------------
-Collector::Collector() :
+template<> GCRegistry::node *GCRegistry::Head = 0;
+template<> GCRegistry::node *GCRegistry::Tail = 0;
+template<> GCRegistry::listener *GCRegistry::ListenerHead = 0;
+template<> GCRegistry::listener *GCRegistry::ListenerTail = 0;
+
+// -----------------------------------------------------------------------------
+
+GCStrategy::GCStrategy() :
NeededSafePoints(0),
CustomReadBarriers(false),
CustomWriteBarriers(false),
@@ -94,26 +104,26 @@ Collector::Collector() :
UsesMetadata(false)
{}
-Collector::~Collector() {
+GCStrategy::~GCStrategy() {
for (iterator I = begin(), E = end(); I != E; ++I)
delete *I;
Functions.clear();
}
-bool Collector::initializeCustomLowering(Module &M) { return false; }
+bool GCStrategy::initializeCustomLowering(Module &M) { return false; }
-bool Collector::performCustomLowering(Function &F) {
+bool GCStrategy::performCustomLowering(Function &F) {
cerr << "gc " << getName() << " must override performCustomLowering.\n";
abort();
return 0;
}
-
-CollectorMetadata *Collector::insertFunctionMetadata(const Function &F) {
- CollectorMetadata *CM = new CollectorMetadata(F, *this);
- Functions.push_back(CM);
- return CM;
-}
+
+GCFunctionInfo *GCStrategy::insertFunctionInfo(const Function &F) {
+ GCFunctionInfo *FI = new GCFunctionInfo(F, *this);
+ Functions.push_back(FI);
+ return FI;
+}
// -----------------------------------------------------------------------------
@@ -132,7 +142,7 @@ const char *LowerIntrinsics::getPassName() const {
void LowerIntrinsics::getAnalysisUsage(AnalysisUsage &AU) const {
FunctionPass::getAnalysisUsage(AU);
- AU.addRequired<CollectorModuleMetadata>();
+ AU.addRequired<GCModuleInfo>();
}
/// doInitialization - If this module uses the GC intrinsics, find them now.
@@ -141,15 +151,14 @@ bool LowerIntrinsics::doInitialization(Module &M) {
// work against the entire module. But this cannot be done at
// runFunction time (initializeCustomLowering likely needs to change
// the module).
- CollectorModuleMetadata *CMM = getAnalysisToUpdate<CollectorModuleMetadata>();
- assert(CMM && "LowerIntrinsics didn't require CollectorModuleMetadata!?");
+ GCModuleInfo *MI = getAnalysisToUpdate<GCModuleInfo>();
+ assert(MI && "LowerIntrinsics didn't require GCModuleInfo!?");
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
- if (!I->isDeclaration() && I->hasCollector())
- CMM->get(*I); // Instantiate the Collector.
+ if (!I->isDeclaration() && I->hasGC())
+ MI->getFunctionInfo(*I); // Instantiate the GC strategy.
bool MadeChange = false;
- for (CollectorModuleMetadata::iterator I = CMM->begin(),
- E = CMM->end(); I != E; ++I)
+ for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
if (NeedsCustomLoweringPass(**I))
if ((*I)->initializeCustomLowering(M))
MadeChange = true;
@@ -185,7 +194,7 @@ bool LowerIntrinsics::InsertRootInitializers(Function &F, AllocaInst **Roots,
return MadeChange;
}
-bool LowerIntrinsics::NeedsDefaultLoweringPass(const Collector &C) {
+bool LowerIntrinsics::NeedsDefaultLoweringPass(const GCStrategy &C) {
// Default lowering is necessary only if read or write barriers have a default
// action. The default for roots is no action.
return !C.customWriteBarrier()
@@ -193,7 +202,7 @@ bool LowerIntrinsics::NeedsDefaultLoweringPass(const Collector &C) {
|| C.initializeRoots();
}
-bool LowerIntrinsics::NeedsCustomLoweringPass(const Collector &C) {
+bool LowerIntrinsics::NeedsCustomLoweringPass(const GCStrategy &C) {
// Custom lowering is only necessary if enabled for some action.
return C.customWriteBarrier()
|| C.customReadBarrier()
@@ -232,26 +241,27 @@ bool LowerIntrinsics::CouldBecomeSafePoint(Instruction *I) {
/// Leave gcroot intrinsics; the code generator needs to see those.
bool LowerIntrinsics::runOnFunction(Function &F) {
// Quick exit for functions that do not use GC.
- if (!F.hasCollector()) return false;
+ if (!F.hasGC())
+ return false;
- CollectorMetadata &MD = getAnalysis<CollectorModuleMetadata>().get(F);
- Collector &Coll = MD.getCollector();
+ GCFunctionInfo &FI = getAnalysis<GCModuleInfo>().getFunctionInfo(F);
+ GCStrategy &S = FI.getStrategy();
bool MadeChange = false;
- if (NeedsDefaultLoweringPass(Coll))
- MadeChange |= PerformDefaultLowering(F, Coll);
+ if (NeedsDefaultLoweringPass(S))
+ MadeChange |= PerformDefaultLowering(F, S);
- if (NeedsCustomLoweringPass(Coll))
- MadeChange |= Coll.performCustomLowering(F);
+ if (NeedsCustomLoweringPass(S))
+ MadeChange |= S.performCustomLowering(F);
return MadeChange;
}
-bool LowerIntrinsics::PerformDefaultLowering(Function &F, Collector &Coll) {
- bool LowerWr = !Coll.customWriteBarrier();
- bool LowerRd = !Coll.customReadBarrier();
- bool InitRoots = Coll.initializeRoots();
+bool LowerIntrinsics::PerformDefaultLowering(Function &F, GCStrategy &S) {
+ bool LowerWr = !S.customWriteBarrier();
+ bool LowerRd = !S.customReadBarrier();
+ bool InitRoots = S.initializeRoots();
SmallVector<AllocaInst*,32> Roots;
@@ -320,7 +330,7 @@ void MachineCodeAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
MachineFunctionPass::getAnalysisUsage(AU);
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
- AU.addRequired<CollectorModuleMetadata>();
+ AU.addRequired<GCModuleInfo>();
}
unsigned MachineCodeAnalysis::InsertLabel(MachineBasicBlock &MBB,
@@ -336,11 +346,11 @@ void MachineCodeAnalysis::VisitCallPoint(MachineBasicBlock::iterator CI) {
MachineBasicBlock::iterator RAI = CI;
++RAI;
- if (MD->getCollector().needsSafePoint(GC::PreCall))
- MD->addSafePoint(GC::PreCall, InsertLabel(*CI->getParent(), CI));
+ if (FI->getStrategy().needsSafePoint(GC::PreCall))
+ FI->addSafePoint(GC::PreCall, InsertLabel(*CI->getParent(), CI));
- if (MD->getCollector().needsSafePoint(GC::PostCall))
- MD->addSafePoint(GC::PostCall, InsertLabel(*CI->getParent(), RAI));
+ if (FI->getStrategy().needsSafePoint(GC::PostCall))
+ FI->addSafePoint(GC::PostCall, InsertLabel(*CI->getParent(), RAI));
}
void MachineCodeAnalysis::FindSafePoints(MachineFunction &MF) {
@@ -357,18 +367,19 @@ void MachineCodeAnalysis::FindStackOffsets(MachineFunction &MF) {
uint64_t OffsetAdjustment = MFI->getOffsetAdjustment();
uint64_t OffsetOfLocalArea = TM->getFrameInfo()->getOffsetOfLocalArea();
- for (CollectorMetadata::roots_iterator RI = MD->roots_begin(),
- RE = MD->roots_end(); RI != RE; ++RI)
+ for (GCFunctionInfo::roots_iterator RI = FI->roots_begin(),
+ RE = FI->roots_end(); RI != RE; ++RI)
RI->StackOffset = MFI->getObjectOffset(RI->Num) + StackSize
- OffsetOfLocalArea + OffsetAdjustment;
}
bool MachineCodeAnalysis::runOnMachineFunction(MachineFunction &MF) {
// Quick exit for functions that do not use GC.
- if (!MF.getFunction()->hasCollector()) return false;
+ if (!MF.getFunction()->hasGC())
+ return false;
- MD = &getAnalysis<CollectorModuleMetadata>().get(*MF.getFunction());
- if (!MD->getCollector().needsSafePoints())
+ FI = &getAnalysis<GCModuleInfo>().getFunctionInfo(*MF.getFunction());
+ if (!FI->getStrategy().needsSafePoints())
return false;
TM = &MF.getTarget();
@@ -377,7 +388,7 @@ bool MachineCodeAnalysis::runOnMachineFunction(MachineFunction &MF) {
MFI = MF.getFrameInfo();
// Find the size of the stack frame.
- MD->setFrameSize(MFI->getStackSize());
+ FI->setFrameSize(MFI->getStackSize());
// Find all safe points.
FindSafePoints(MF);
diff --git a/lib/CodeGen/GCs.cpp b/lib/CodeGen/GCs.cpp
deleted file mode 100644
index 124725358e..0000000000
--- a/lib/CodeGen/GCs.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-//===-- Collectors.cpp - Garbage collector registry -----------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the static data members of the CollectorRegistry class.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CodeGen/GCs.h"
-
-using namespace llvm;
-
-template<> CollectorRegistry::node *CollectorRegistry::Head = 0;
-template<> CollectorRegistry::node *CollectorRegistry::Tail = 0;
-template<> CollectorRegistry::listener *CollectorRegistry::ListenerHead = 0;
-template<> CollectorRegistry::listener *CollectorRegistry::ListenerTail = 0;
-
-template<> GCMetadataPrinterRegistry::node *GCMetadataPrinterRegistry::Head = 0;
-template<> GCMetadataPrinterRegistry::node *GCMetadataPrinterRegistry::Tail = 0;
-template<> GCMetadataPrinterRegistry::listener *
-GCMetadataPrinterRegistry::ListenerHead = 0;
-template<> GCMetadataPrinterRegistry::listener *
-GCMetadataPrinterRegistry::ListenerTail = 0;
diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp
index d420ffb7d9..938e1ae9cc 100644
--- a/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/lib/CodeGen/LLVMTargetMachine.cpp
@@ -133,7 +133,7 @@ LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
PM.add(createMachineFunctionPrinterPass(cerr));
if (PrintGCInfo)
- PM.add(createCollectorMetadataPrinter(*cerr));
+ PM.add(createGCInfoPrinter(*cerr));
// Fold redundant debug labels.
PM.add(createDebugLabelFoldingPass());
@@ -173,7 +173,7 @@ bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
if (MCE)
addSimpleCodeEmitter(PM, Fast, PrintEmittedAsm, *MCE);
- PM.add(createCollectorMetadataDeleter());
+ PM.add(createGCInfoDeleter());
// Delete machine code for this function
PM.add(createMachineCodeDeleter());
@@ -274,14 +274,14 @@ bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
PM.add(createMachineFunctionPrinterPass(cerr));
if (PrintGCInfo)
- PM.add(createCollectorMetadataPrinter(*cerr));
+ PM.add(createGCInfoPrinter(*cerr));
if (addPreEmitPass(PM, Fast) && PrintMachineCode)
PM.add(createMachineFunctionPrinterPass(cerr));
addCodeEmitter(PM, Fast, PrintEmittedAsm, MCE);
- PM.add(createCollectorMetadataDeleter());
+ PM.add(createGCInfoDeleter());
// Delete machine code for this function
PM.add(createMachineCodeDeleter());
diff --git a/lib/CodeGen/OcamlGC.cpp b/lib/CodeGen/OcamlGC.cpp
index 88499cbd66..0b90444406 100644
--- a/lib/CodeGen/OcamlGC.cpp
+++ b/lib/CodeGen/OcamlGC.cpp
@@ -1,4 +1,4 @@
-//===-- OcamlCollector.cpp - Ocaml frametable emitter ---------------------===//
+//===-- OcamlGC.cpp - Ocaml frametable GC strategy ------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -9,38 +9,29 @@
//
// This file implements lowering for the llvm.gc* intrinsics compatible with
// Objective Caml 3.10.0, which uses a liveness-accurate static stack map.
+//
+// The frametable emitter is in OcamlGCPrinter.cpp.
//
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/GCs.h"
-#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/GCStrategy.h"
-#include "llvm/Module.h"
-#include "llvm/Target/TargetAsmInfo.h"
-#include "llvm/Target/TargetData.h"
-#include "llvm/Target/TargetMachine.h"
using namespace llvm;
namespace {
-
- class VISIBILITY_HIDDEN OcamlCollector : public Collector {
+ class VISIBILITY_HIDDEN OcamlGC : public GCStrategy {
public:
- OcamlCollector();
+ OcamlGC();
};
-
}
-static CollectorRegistry::Add<OcamlCollector>
-X("ocaml", "ocaml 3.10-compatible collector");
-
-// -----------------------------------------------------------------------------
+static GCRegistry::Add<OcamlGC>
+X("ocaml", "ocaml 3.10-compatible GC");
-Collector *llvm::createOcamlCollector() {
- return new OcamlCollector();
-}
+void llvm::linkOcamlGC() { }
-OcamlCollector::OcamlCollector() {
+OcamlGC::OcamlGC() {
NeededSafePoints = 1 << GC::PostCall;
UsesMetadata = true;
}
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 012e7d0992..f4e31f727e 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -27,6 +27,7 @@
#include "llvm/IntrinsicInst.h"
#include "llvm/ParameterAttributes.h"
#include "llvm/CodeGen/GCStrategy.h"
+#include "llvm/CodeGen/GCMetadata.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
@@ -601,15 +602,15 @