|
23 | 23 | #include "llvm/ADT/StringRef.h"
|
24 | 24 | #include "llvm/ADT/Triple.h"
|
25 | 25 | #include "llvm/ADT/iterator_range.h"
|
| 26 | +#include "llvm/MC/MCObjectFileInfo.h" |
26 | 27 | #include "llvm/Support/CodeGen.h"
|
27 | 28 | #include "llvm/Support/ErrorHandling.h"
|
28 | 29 | #include "llvm/Support/FormattedStream.h"
|
@@ -130,6 +131,9 @@ class Target {
|
130 | 131 | using MCAsmInfoCtorFnTy = MCAsmInfo *(*)(const MCRegisterInfo &MRI,
|
131 | 132 | const Triple &TT,
|
132 | 133 | const MCTargetOptions &Options);
|
| 134 | + using MCObjectFileInfoCtorFnTy = MCObjectFileInfo *(*)(MCContext &Ctx, |
| 135 | + bool PIC, |
| 136 | + bool LargeCodeModel); |
133 | 137 | using MCInstrInfoCtorFnTy = MCInstrInfo *(*)();
|
134 | 138 | using MCInstrAnalysisCtorFnTy = MCInstrAnalysis *(*)(const MCInstrInfo *Info);
|
135 | 139 | using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
|
@@ -227,6 +231,9 @@ class Target {
|
227 | 231 | /// registered.
|
228 | 232 | MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
|
229 | 233 |
|
| 234 | + /// Constructor function for this target's MCObjectFileInfo, if registered. |
| 235 | + MCObjectFileInfoCtorFnTy MCObjectFileInfoCtorFn; |
| 236 | + |
230 | 237 | /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
|
231 | 238 | /// if registered.
|
232 | 239 | MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
|
@@ -350,6 +357,19 @@ class Target {
|
350 | 357 | return MCAsmInfoCtorFn(MRI, Triple(TheTriple), Options);
|
351 | 358 | }
|
352 | 359 |
|
| 360 | + /// Create a MCObjectFileInfo implementation for the specified target |
| 361 | + /// triple. |
| 362 | + /// |
| 363 | + MCObjectFileInfo *createMCObjectFileInfo(MCContext &Ctx, bool PIC, |
| 364 | + bool LargeCodeModel = false) const { |
| 365 | + if (!MCObjectFileInfoCtorFn) { |
| 366 | + MCObjectFileInfo *MOFI = new MCObjectFileInfo(); |
| 367 | + MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel); |
| 368 | + return MOFI; |
| 369 | + } |
| 370 | + return MCObjectFileInfoCtorFn(Ctx, PIC, LargeCodeModel); |
| 371 | + } |
| 372 | + |
353 | 373 | /// createMCInstrInfo - Create a MCInstrInfo implementation.
|
354 | 374 | ///
|
355 | 375 | MCInstrInfo *createMCInstrInfo() const {
|
@@ -724,6 +744,19 @@ struct TargetRegistry {
|
724 | 744 | T.MCAsmInfoCtorFn = Fn;
|
725 | 745 | }
|
726 | 746 |
|
| 747 | + /// Register a MCObjectFileInfo implementation for the given target. |
| 748 | + /// |
| 749 | + /// Clients are responsible for ensuring that registration doesn't occur |
| 750 | + /// while another thread is attempting to access the registry. Typically |
| 751 | + /// this is done by initializing all targets at program startup. |
| 752 | + /// |
| 753 | + /// @param T - The target being registered. |
| 754 | + /// @param Fn - A function to construct a MCObjectFileInfo for the target. |
| 755 | + static void RegisterMCObjectFileInfo(Target &T, |
| 756 | + Target::MCObjectFileInfoCtorFnTy Fn) { |
| 757 | + T.MCObjectFileInfoCtorFn = Fn; |
| 758 | + } |
| 759 | + |
727 | 760 | /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
|
728 | 761 | /// given target.
|
729 | 762 | ///
|
@@ -991,6 +1024,39 @@ struct RegisterMCAsmInfoFn {
|
991 | 1024 | }
|
992 | 1025 | };
|
993 | 1026 |
|
| 1027 | +/// Helper template for registering a target object file info implementation. |
| 1028 | +/// This invokes the static "Create" method on the class to actually do the |
| 1029 | +/// construction. Usage: |
| 1030 | +/// |
| 1031 | +/// extern "C" void LLVMInitializeFooTarget() { |
| 1032 | +/// extern Target TheFooTarget; |
| 1033 | +/// RegisterMCObjectFileInfo<FooMCObjectFileInfo> X(TheFooTarget); |
| 1034 | +/// } |
| 1035 | +template <class MCObjectFileInfoImpl> struct RegisterMCObjectFileInfo { |
| 1036 | + RegisterMCObjectFileInfo(Target &T) { |
| 1037 | + TargetRegistry::RegisterMCObjectFileInfo(T, &Allocator); |
| 1038 | + } |
| 1039 | + |
| 1040 | +private: |
| 1041 | + static MCObjectFileInfo *Allocator(MCContext &Ctx, bool PIC, |
| 1042 | + bool LargeCodeModel = false) { |
| 1043 | + return new MCObjectFileInfoImpl(Ctx, PIC, LargeCodeModel); |
| 1044 | + } |
| 1045 | +}; |
| 1046 | + |
| 1047 | +/// Helper template for registering a target object file info implementation. |
| 1048 | +/// This invokes the specified function to do the construction. Usage: |
| 1049 | +/// |
| 1050 | +/// extern "C" void LLVMInitializeFooTarget() { |
| 1051 | +/// extern Target TheFooTarget; |
| 1052 | +/// RegisterMCObjectFileInfoFn X(TheFooTarget, TheFunction); |
| 1053 | +/// } |
| 1054 | +struct RegisterMCObjectFileInfoFn { |
| 1055 | + RegisterMCObjectFileInfoFn(Target &T, Target::MCObjectFileInfoCtorFnTy Fn) { |
| 1056 | + TargetRegistry::RegisterMCObjectFileInfo(T, Fn); |
| 1057 | + } |
| 1058 | +}; |
| 1059 | + |
994 | 1060 | /// RegisterMCInstrInfo - Helper template for registering a target instruction
|
995 | 1061 | /// info implementation. This invokes the static "Create" method on the class
|
996 | 1062 | /// to actually do the construction. Usage:
|
|
0 commit comments