@@ -59,6 +59,11 @@ class raw_ostream;
59
59
class raw_pwrite_stream ;
60
60
class TargetMachine ;
61
61
class TargetOptions ;
62
+ namespace mca {
63
+ class CustomBehaviour ;
64
+ class InstrPostProcess ;
65
+ class SourceMgr ;
66
+ } // namespace mca
62
67
63
68
MCStreamer *createNullStreamer (MCContext &Ctx);
64
69
// Takes ownership of \p TAB and \p CE.
@@ -114,6 +119,13 @@ MCSymbolizer *createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
114
119
void *DisInfo, MCContext *Ctx,
115
120
std::unique_ptr<MCRelocationInfo> &&RelInfo);
116
121
122
+ mca::CustomBehaviour *createCustomBehaviour (const MCSubtargetInfo &STI,
123
+ const mca::SourceMgr &SrcMgr,
124
+ const MCInstrInfo &MCII);
125
+
126
+ mca::InstrPostProcess *createInstrPostProcess (const MCSubtargetInfo &STI,
127
+ const MCInstrInfo &MCII);
128
+
117
129
// / Target - Wrapper for Target specific information.
118
130
// /
119
131
// / For registration purposes, this is a POD type so that targets can be
@@ -206,6 +218,15 @@ class Target {
206
218
LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
207
219
std::unique_ptr<MCRelocationInfo> &&RelInfo);
208
220
221
+ using CustomBehaviourCtorTy =
222
+ mca::CustomBehaviour *(*)(const MCSubtargetInfo &STI,
223
+ const mca::SourceMgr &SrcMgr,
224
+ const MCInstrInfo &MCII);
225
+
226
+ using InstrPostProcessCtorTy =
227
+ mca::InstrPostProcess *(*)(const MCSubtargetInfo &STI,
228
+ const MCInstrInfo &MCII);
229
+
209
230
private:
210
231
// / Next - The next registered target in the linked list, maintained by the
211
232
// / TargetRegistry.
@@ -305,6 +326,14 @@ class Target {
305
326
// / MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
306
327
MCSymbolizerCtorTy MCSymbolizerCtorFn = nullptr ;
307
328
329
+ // / CustomBehaviourCtorFn - Construction function for this target's
330
+ // / CustomBehaviour, if registered (default = nullptr).
331
+ CustomBehaviourCtorTy CustomBehaviourCtorFn = nullptr ;
332
+
333
+ // / InstrPostProcessCtorFn - Construction function for this target's
334
+ // / InstrPostProcess, if registered (default = nullptr).
335
+ InstrPostProcessCtorTy InstrPostProcessCtorFn = nullptr ;
336
+
308
337
public:
309
338
Target () = default ;
310
339
@@ -623,6 +652,25 @@ class Target {
623
652
std::move (RelInfo));
624
653
}
625
654
655
+ // / createCustomBehaviour - Create a target specific CustomBehaviour.
656
+ // / This class is used by llvm-mca and requires backend functionality.
657
+ mca::CustomBehaviour *createCustomBehaviour (const MCSubtargetInfo &STI,
658
+ const mca::SourceMgr &SrcMgr,
659
+ const MCInstrInfo &MCII) const {
660
+ if (CustomBehaviourCtorFn)
661
+ return CustomBehaviourCtorFn (STI, SrcMgr, MCII);
662
+ return nullptr ;
663
+ }
664
+
665
+ // / createInstrPostProcess - Create a target specific InstrPostProcess.
666
+ // / This class is used by llvm-mca and requires backend functionality.
667
+ mca::InstrPostProcess *createInstrPostProcess (const MCSubtargetInfo &STI,
668
+ const MCInstrInfo &MCII) const {
669
+ if (InstrPostProcessCtorFn)
670
+ return InstrPostProcessCtorFn (STI, MCII);
671
+ return nullptr ;
672
+ }
673
+
626
674
// / @}
627
675
};
628
676
@@ -959,6 +1007,34 @@ struct TargetRegistry {
959
1007
T.MCSymbolizerCtorFn = Fn;
960
1008
}
961
1009
1010
+ // / RegisterCustomBehaviour - Register a CustomBehaviour
1011
+ // / implementation for the given target.
1012
+ // /
1013
+ // / Clients are responsible for ensuring that registration doesn't occur
1014
+ // / while another thread is attempting to access the registry. Typically
1015
+ // / this is done by initializing all targets at program startup.
1016
+ // /
1017
+ // / @param T - The target being registered.
1018
+ // / @param Fn - A function to construct a CustomBehaviour for the target.
1019
+ static void RegisterCustomBehaviour (Target &T,
1020
+ Target::CustomBehaviourCtorTy Fn) {
1021
+ T.CustomBehaviourCtorFn = Fn;
1022
+ }
1023
+
1024
+ // / RegisterInstrPostProcess - Register an InstrPostProcess
1025
+ // / implementation for the given target.
1026
+ // /
1027
+ // / Clients are responsible for ensuring that registration doesn't occur
1028
+ // / while another thread is attempting to access the registry. Typically
1029
+ // / this is done by initializing all targets at program startup.
1030
+ // /
1031
+ // / @param T - The target being registered.
1032
+ // / @param Fn - A function to construct an InstrPostProcess for the target.
1033
+ static void RegisterInstrPostProcess (Target &T,
1034
+ Target::InstrPostProcessCtorTy Fn) {
1035
+ T.InstrPostProcessCtorFn = Fn;
1036
+ }
1037
+
962
1038
// / @}
963
1039
};
964
1040
0 commit comments