aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGordon Henriksen <gordonhenriksen@mac.com>2007-12-11 00:30:17 +0000
committerGordon Henriksen <gordonhenriksen@mac.com>2007-12-11 00:30:17 +0000
commitad93c4f936d220570535711262e0fff8857f798a (patch)
tree285ad723e6fbc86a2e38e2dcdabb27288d6fe8f6 /include
parent519452282b1fc4d48c112f4b945700629ac34585 (diff)
downloadexternal_llvm-ad93c4f936d220570535711262e0fff8857f798a.zip
external_llvm-ad93c4f936d220570535711262e0fff8857f798a.tar.gz
external_llvm-ad93c4f936d220570535711262e0fff8857f798a.tar.bz2
CollectorMetadata and Collector are rejiggered to get along with
per-function collector model. Collector is now the factory for CollectorMetadata, so the latter may be subclassed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44827 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/CodeGen/Collector.h88
-rw-r--r--include/llvm/CodeGen/CollectorMetadata.h61
-rw-r--r--include/llvm/CodeGen/Collectors.h3
-rw-r--r--include/llvm/CodeGen/Passes.h18
4 files changed, 95 insertions, 75 deletions
diff --git a/include/llvm/CodeGen/Collector.h b/include/llvm/CodeGen/Collector.h
index 664e13c..dbe84ca 100644
--- a/include/llvm/CodeGen/Collector.h
+++ b/include/llvm/CodeGen/Collector.h
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
//
-// GCInfo records sufficient information about a machine function to enable
+// Collector records sufficient information about a machine function to enable
// accurate garbage collectors. Specifically:
//
// - Safe points
@@ -25,8 +25,8 @@
// This generic information should used by ABI-specific passes to emit support
// tables for the runtime garbage collector.
//
-// GCSafePointPass identifies the GC safe points in the machine code. (Roots are
-// identified in SelectionDAGISel.)
+// MachineCodeAnalysis identifies the GC safe points in the machine code. (Roots
+// are identified in SelectionDAGISel.)
//
//===----------------------------------------------------------------------===//
@@ -35,19 +35,25 @@
#include "llvm/CodeGen/CollectorMetadata.h"
#include <iosfwd>
+#include <string>
namespace llvm {
- class AsmPrinter;
- class FunctionPassManager;
- class PassManager;
- class TargetAsmInfo;
-
-
/// Collector describes a garbage collector's code generation requirements,
/// and provides overridable hooks for those needs which cannot be abstractly
/// described.
class Collector {
+ public:
+ typedef std::vector<CollectorMetadata*> list_type;
+ typedef list_type::iterator iterator;
+
+ private:
+ friend class CollectorModuleMetadata;
+ const Module *M;
+ std::string Name;
+
+ list_type Functions;
+
protected:
unsigned NeededSafePoints; //< Bitmask of required safe points.
bool CustomReadBarriers; //< Default is to insert loads.
@@ -55,16 +61,20 @@ namespace llvm {
bool CustomRoots; //< Default is to pass through to backend.
bool InitRoots; //< If set, roots are nulled during lowering.
- /// If any of the actions are set to Custom, this is expected to be
- /// overriden to create a transform to lower those actions to LLVM IR.
- virtual Pass *createCustomLoweringPass() const;
-
public:
Collector();
virtual ~Collector();
+ /// getName - The name of the collector, for debugging.
+ ///
+ const std::string &getName() const { return Name; }
+
+ /// getModule - The module upon which the collector is operating.
+ ///
+ const Module &getModule() const { return *M; }
+
/// True if this collector requires safe points of any kind. By default,
/// none are recorded.
bool needsSafePoints() const { return NeededSafePoints != 0; }
@@ -94,40 +104,30 @@ namespace llvm {
bool initializeRoots() const { return InitRoots; }
- /// Adds LLVM IR transforms to handle collection intrinsics. By default,
- /// read- and write barriers are replaced with direct memory accesses, and
- /// roots are passed on to the code generator.
- void addLoweringPasses(FunctionPassManager &PM) const;
-
- /// Same as addLoweringPasses(FunctionPassManager &), except uses a
- /// PassManager for compatibility with unusual backends (such as MSIL or
- /// CBackend).
- void addLoweringPasses(PassManager &PM) const;
-
- /// Adds target-independent MachineFunction pass to mark safe points. This
- /// is added very late during code generation, just prior to output, and
- /// importantly after all CFG transformations (like branch folding).
- void addGenericMachineCodePass(FunctionPassManager &PM,
- const TargetMachine &TM, bool Fast) const;
-
/// beginAssembly/finishAssembly - Emit module metadata as assembly code.
- virtual void beginAssembly(Module &M, std::ostream &OS, AsmPrinter &AP,
- const TargetAsmInfo &TAI) const;
- virtual void finishAssembly(Module &M, CollectorModuleMetadata &CMM,
- std::ostream &OS, AsmPrinter &AP,
- const TargetAsmInfo &TAI) const;
-
- private:
- bool NeedsDefaultLoweringPass() const;
- bool NeedsCustomLoweringPass() const;
-
+ virtual void beginAssembly(std::ostream &OS, AsmPrinter &AP,
+ const TargetAsmInfo &TAI);
+ virtual void finishAssembly(std::ostream &OS, AsmPrinter &AP,
+ const TargetAsmInfo &TAI);
+
+ /// begin/end - Iterators for function metadata.
+ ///
+ iterator begin() { return Functions.begin(); }
+ iterator end() { return Functions.end(); }
+
+ /// insertFunctionMetadata - Creates metadata for a function.
+ ///
+ CollectorMetadata *insertFunctionMetadata(const Function &F);
+
+ /// initializeCustomLowering/performCustomLowering - If any of the actions
+ /// are set to custom, performCustomLowering must be overriden to create a
+ /// transform to lower those actions to LLVM IR. initializeCustomLowering
+ /// is optional to override. These are the only Collector methods through
+ /// which the LLVM IR can be modified.
+ virtual bool initializeCustomLowering(Module &F);
+ virtual bool performCustomLowering(Function &F);
};
-
- /// If set, the code generator should generate garbage collection as specified
- /// by the collector properties.
- extern const Collector *TheCollector; // FIXME: Find a better home!
-
}
#endif
diff --git a/include/llvm/CodeGen/CollectorMetadata.h b/include/llvm/CodeGen/CollectorMetadata.h
index 9924bd9..0f958a8 100644
--- a/include/llvm/CodeGen/CollectorMetadata.h
+++ b/include/llvm/CodeGen/CollectorMetadata.h
@@ -9,7 +9,7 @@
//
// This file declares the CollectorMetadata and CollectorModuleMetadata classes,
// which are used as a communication channel from the target code generator
-// to the target garbage collector. This interface allows code generators and
+// to the target garbage collectors. This interface allows code generators and
// garbage collectors to be developed independently.
//
// The CollectorMetadata class records the data necessary to build a type
@@ -37,19 +37,14 @@
#include "llvm/Pass.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringMap.h"
namespace llvm {
+ class AsmPrinter;
+ class Collector;
class Constant;
-
-
- /// Creates a pass to print collector metadata.
- ///
- Pass *createCollectorMetadataPrinter(std::ostream &OS);
-
- /// Creates a pass to destroy collector metadata.
- ///
- Pass *createCollectorMetadataDeleter();
+ class TargetAsmInfo;
namespace GC {
@@ -77,7 +72,7 @@ namespace llvm {
struct GCRoot {
int Num; //< Usually a frame index.
int StackOffset; //< Offset from the stack pointer.
- Constant *Metadata; //< From the call to llvm.gcroot.
+ Constant *Metadata; //< Metadata straight from the call to llvm.gcroot.
GCRoot(int N, Constant *MD) : Num(N), StackOffset(-1), Metadata(MD) {}
};
@@ -93,6 +88,7 @@ namespace llvm {
private:
const Function &F;
+ Collector &C;
uint64_t FrameSize;
std::vector<GCRoot> Roots;
std::vector<GCPoint> SafePoints;
@@ -107,14 +103,18 @@ namespace llvm {
// The bit vector is the more compact representation where >3.2% of roots
// are live per safe point (1.5% on 64-bit hosts).
- friend class CollectorModuleMetadata;
- CollectorMetadata(const Function &F);
-
public:
+ CollectorMetadata(const Function &F, Collector &C);
~CollectorMetadata();
+ /// getFunction - Return the function to which this metadata applies.
+ ///
const Function &getFunction() const { return F; }
+ /// getCollector - Return the collector for the function.
+ ///
+ Collector &getCollector() { return C; }
+
/// addStackRoot - Registers a root that lives on the stack. Num is the
/// stack object ID for the alloca (if the code generator is using
/// MachineFrameInfo).
@@ -157,37 +157,36 @@ namespace llvm {
/// CollectorModuleMetadata - Garbage collection metadata for a whole module.
///
class CollectorModuleMetadata : public ImmutablePass {
- typedef std::vector<CollectorMetadata*> list_type;
- typedef DenseMap<const Function*,CollectorMetadata*> map_type;
+ typedef StringMap<Collector*> collector_map_type;
+ typedef std::vector<Collector*> list_type;
+ typedef DenseMap<const Function*,CollectorMetadata*> function_map_type;
- Module *Mod;
- list_type Functions;
- map_type Map;
+ collector_map_type NameMap;
+ list_type Collectors;
+ function_map_type Map;
+
+ Collector *getOrCreateCollector(const Module *M, const std::string &Name);
public:
- typedef list_type::iterator iterator;
+ typedef list_type::const_iterator iterator;
static char ID;
CollectorModuleMetadata();
~CollectorModuleMetadata();
- /// clear - Used to delete module metadata. Collector invokes this as
- /// necessary.
+ /// clear - Used to delete module metadata. The metadata deleter pass calls
+ /// this.
void clear();
- /// begin/end - Iterators for function metadata.
- ///
- iterator begin() { return Functions.begin(); }
- iterator end() { return Functions.end(); }
-
- /// insert - Creates metadata for a function.
+ /// begin/end - Iterators for collectors.
///
- CollectorMetadata& insert(const Function *F);
+ iterator begin() const { return Collectors.begin(); }
+ iterator end() const { return Collectors.end(); }
- /// get - Looks up existing function metadata.
+ /// get - Look up function metadata.
///
- CollectorMetadata* get(const Function *F) const;
+ CollectorMetadata &get(const Function &F);
};
}
diff --git a/include/llvm/CodeGen/Collectors.h b/include/llvm/CodeGen/Collectors.h
index 18c1546..de8e2e6 100644
--- a/include/llvm/CodeGen/Collectors.h
+++ b/include/llvm/CodeGen/Collectors.h
@@ -25,6 +25,9 @@ namespace llvm {
///
typedef Registry<Collector> CollectorRegistry;
+ /// FIXME: Collector instances are not useful on their own. These no longer
+ /// serve any purpose except to link in the plugins.
+
/// Creates an ocaml-compatible garbage collector.
Collector *createOcamlCollector();
diff --git a/include/llvm/CodeGen/Passes.h b/include/llvm/CodeGen/Passes.h
index f0aa508..2286dc6 100644
--- a/include/llvm/CodeGen/Passes.h
+++ b/include/llvm/CodeGen/Passes.h
@@ -135,6 +135,24 @@ namespace llvm {
/// for the Sparc.
FunctionPass *getRegisterAllocator(TargetMachine &T);
+ /// IntrinsicLowering Pass - Performs target-independent LLVM IR
+ /// transformations for highly portable collectors.
+ FunctionPass *createGCLoweringPass();
+
+ /// MachineCodeAnalysis Pass - Target-independent pass to mark safe points in
+ /// machine code. Must be added very late during code generation, just prior
+ /// to output, and importantly after all CFG transformations (such as branch
+ /// folding).
+ FunctionPass *createGCMachineCodeAnalysisPass();
+
+ /// Deleter Pass - Releases collector metadata.
+ ///
+ FunctionPass *createCollectorMetadataDeleter();
+
+ /// Creates a pass to print collector metadata.
+ ///
+ FunctionPass *createCollectorMetadataPrinter(std::ostream &OS);
+
/// createMachineLICMPass - This pass performs LICM on machine instructions.
///
FunctionPass *createMachineLICMPass();