1 // AsmJit - Machine code generation for C++
2 //
3 //  * Official AsmJit Home Page: https://asmjit.com
4 //  * Official Github Repository: https://github.com/asmjit/asmjit
5 //
6 // Copyright (c) 2008-2020 The AsmJit Authors
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 //    claim that you wrote the original software. If you use this software
18 //    in a product, an acknowledgment in the product documentation would be
19 //    appreciated but is not required.
20 // 2. Altered source versions must be plainly marked as such, and must not be
21 //    misrepresented as being the original software.
22 // 3. This notice may not be removed or altered from any source distribution.
23 
24 #ifndef ASMJIT_X86_X86RAPASS_P_H_INCLUDED
25 #define ASMJIT_X86_X86RAPASS_P_H_INCLUDED
26 
27 #include "../core/api-config.h"
28 #ifndef ASMJIT_NO_COMPILER
29 
30 #include "../core/compiler.h"
31 #include "../core/rabuilders_p.h"
32 #include "../core/rapass_p.h"
33 #include "../x86/x86assembler.h"
34 #include "../x86/x86compiler.h"
35 
ASMJIT_BEGIN_SUB_NAMESPACE(x86)36 ASMJIT_BEGIN_SUB_NAMESPACE(x86)
37 
38 //! \cond INTERNAL
39 
40 //! \brief X86/X64 register allocation.
41 
42 //! \addtogroup asmjit_ra
43 //! \{
44 
45 // ============================================================================
46 // [asmjit::X86RAPass]
47 // ============================================================================
48 
49 //! X86 register allocation pass.
50 //!
51 //! Takes care of generating function prologs and epilogs, and also performs
52 //! register allocation.
53 class X86RAPass : public RAPass {
54 public:
55   ASMJIT_NONCOPYABLE(X86RAPass)
56   typedef RAPass Base;
57 
58   bool _avxEnabled;
59 
60   // --------------------------------------------------------------------------
61   // [Construction / Destruction]
62   // --------------------------------------------------------------------------
63 
64   X86RAPass() noexcept;
65   virtual ~X86RAPass() noexcept;
66 
67   // --------------------------------------------------------------------------
68   // [Accessors]
69   // --------------------------------------------------------------------------
70 
71   //! Returns the compiler casted to `x86::Compiler`.
72   inline Compiler* cc() const noexcept { return static_cast<Compiler*>(_cb); }
73 
74   // --------------------------------------------------------------------------
75   // [Utilities]
76   // --------------------------------------------------------------------------
77 
78   inline uint32_t choose(uint32_t sseInstId, uint32_t avxInstId) noexcept {
79     return _avxEnabled ? avxInstId : sseInstId;
80   }
81 
82   // --------------------------------------------------------------------------
83   // [OnInit / OnDone]
84   // --------------------------------------------------------------------------
85 
86   void onInit() noexcept override;
87   void onDone() noexcept override;
88 
89   // --------------------------------------------------------------------------
90   // [CFG]
91   // --------------------------------------------------------------------------
92 
93   Error buildCFG() noexcept override;
94 
95   // --------------------------------------------------------------------------
96   // [Emit]
97   // --------------------------------------------------------------------------
98 
99   Error onEmitMove(uint32_t workId, uint32_t dstPhysId, uint32_t srcPhysId) noexcept override;
100   Error onEmitSwap(uint32_t aWorkId, uint32_t aPhysId, uint32_t bWorkId, uint32_t bPhysId) noexcept override;
101 
102   Error onEmitLoad(uint32_t workId, uint32_t dstPhysId) noexcept override;
103   Error onEmitSave(uint32_t workId, uint32_t srcPhysId) noexcept override;
104 
105   Error onEmitJump(const Label& label) noexcept override;
106   Error onEmitPreCall(InvokeNode* invokeNode) noexcept override;
107 };
108 
109 //! \}
110 //! \endcond
111 
112 ASMJIT_END_SUB_NAMESPACE
113 
114 #endif // !ASMJIT_NO_COMPILER
115 #endif // ASMJIT_X86_X86RAPASS_P_H_INCLUDED
116