1 //===-- jitcs_machine.h - Machine info --------------------------*- C++ -*-===//
3 // IMachineInfo holds the complete state necessary for the compiler component
4 // to handle machine instructions for a particular machine. Particular
5 // architectures (e.g. x86) are defined in different header files and will fill
6 // in all fields with the relevant values.
8 //===----------------------------------------------------------------------===//
10 #ifndef _JITCS_MACHINE_H_
11 #define _JITCS_MACHINE_H_
13 #include "jitcs_adt_ref.h"
14 #include "jitcs_adt_refcounter.h"
15 #include "jitcs_adt_slice.h"
16 #include "jitcs_base.h"
17 #include "jitcs_cpu.h"
18 #include "jitcs_fnctypeinfo.h"
19 #include "jitcs_ids.h"
23 #define INLINEIT inline __attribute__((always_inline))
25 #define INLINEIT inline
30 struct VirtualRegister
;
34 class CallingConvention
;
40 class IMachineDetails
;
44 IMachineInfo(const CPUInfo
&);
45 virtual ~IMachineInfo() = default;
47 IMachineInfo() = delete;
48 IMachineInfo(const IMachineInfo
&) = delete;
49 IMachineInfo
& operator =(const IMachineInfo
&) = delete;
53 virtual Ref
<const IMachineDetails
> details() const = 0;
54 virtual std::shared_ptr
<const CallingConvention
>
55 getCC(FTSubType
, Slice
<FTTypeId
> results
, Slice
<FTTypeId
> params
) = 0;
57 std::unique_ptr
<Function
>
58 createFnc(RefCounter
<TempAllocator
>, std::shared_ptr
<const CallingConvention
>);
61 INLINEIT
std::shared_ptr
<const CallingConvention
> getCC() {
62 return _getCC
<typename GetFTSubType
<T
>::FType
>(GetFTSubType
<T
>::Value
);
65 INLINEIT
std::unique_ptr
<Function
> createFnc(RefCounter
<TempAllocator
> tmp
) {
66 return createFnc(tmp
, _getCC
<typename GetFTSubType
<T
>::FType
>
67 (GetFTSubType
<T
>::Value
));
72 std::shared_ptr
<const CallingConvention
> _getCC(FTSubType sub
) {
75 res
[0] = GetFTResultId
<T
>::Value
;
76 static const int N
= GetFTParamCount
<T
>::Value
;
77 static_assert(N
<= 10, "too many parameters in function type");
78 _fillFTParams
<T
, N
>(par
);
79 return getCC(sub
, Slice
<FTTypeId
>(res
, 1), Slice
<FTTypeId
>(par
, N
));
83 template <typename T
, uint N
, bool B
> struct _FTParamsFiller_
;
84 template <typename T
, uint N
>
85 struct _FTParamsFiller_
<T
, N
, true> {
86 static inline void run(FTTypeId
* arr
) {
87 static_assert(GetFTParamId
<T
, N
>::OK
, "unsupported parameter type");
88 arr
[N
] = GetFTParamId
<T
, N
>::Value
;
89 _FTParamsFiller_
<T
, N
+ 1, (N
+ 1 < GetFTParamCount
<T
>::Value
)>::run(arr
);
92 template <typename T
, uint N
>
93 struct _FTParamsFiller_
<T
, N
, false> {
94 static inline void run(FTTypeId
* arr
) {}
96 template <typename T
, uint N
>
97 void _fillFTParams(FTTypeId
* arr
) {
98 _FTParamsFiller_
<T
, 0, (0 < GetFTParamCount
<T
>::Value
)>::run(arr
);
102 // called from RefCounter
103 friend class RefCounter
<IMachineInfo
>;
104 void _incRef() { ++_refCnt
; }
105 void _decRef() { if (!--_refCnt
) _release(); }
112 } // end namespace jitcs