John Porto | d58f01c | 2015-06-23 15:55:17 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceTargetLoweringX8664.h - lowering for x86-64 -*- C++ -*-=// |
John Porto | 7e93c62 | 2015-06-23 10:58:57 -0700 | [diff] [blame] | 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Jim Stichnoth | 92a6e5b | 2015-12-02 16:52:44 -0800 | [diff] [blame] | 11 | /// \brief Declares the TargetLoweringX8664 class, which implements the |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 12 | /// TargetLowering interface for the X86 64-bit architecture. |
| 13 | /// |
John Porto | 7e93c62 | 2015-06-23 10:58:57 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
John Porto | d58f01c | 2015-06-23 15:55:17 -0700 | [diff] [blame] | 15 | |
John Porto | 7e93c62 | 2015-06-23 10:58:57 -0700 | [diff] [blame] | 16 | #ifndef SUBZERO_SRC_ICETARGETLOWERINGX8664_H |
| 17 | #define SUBZERO_SRC_ICETARGETLOWERINGX8664_H |
| 18 | |
John Porto | 453660f | 2015-07-31 14:52:52 -0700 | [diff] [blame] | 19 | #include "IceAssemblerX8664.h" |
John Porto | d58f01c | 2015-06-23 15:55:17 -0700 | [diff] [blame] | 20 | #include "IceCfg.h" |
| 21 | #include "IceGlobalContext.h" |
John Porto | 453660f | 2015-07-31 14:52:52 -0700 | [diff] [blame] | 22 | #include "IceInstX8664.h" |
John Porto | 7e93c62 | 2015-06-23 10:58:57 -0700 | [diff] [blame] | 23 | #include "IceTargetLowering.h" |
John Porto | 4a56686 | 2016-01-04 09:33:41 -0800 | [diff] [blame] | 24 | #define X86NAMESPACE X8664 |
John Porto | 453660f | 2015-07-31 14:52:52 -0700 | [diff] [blame] | 25 | #include "IceTargetLoweringX86Base.h" |
John Porto | 4a56686 | 2016-01-04 09:33:41 -0800 | [diff] [blame] | 26 | #undef X86NAMESPACE |
| 27 | #include "IceTargetLoweringX8664Traits.h" |
John Porto | 7e93c62 | 2015-06-23 10:58:57 -0700 | [diff] [blame] | 28 | |
| 29 | namespace Ice { |
John Porto | 4a56686 | 2016-01-04 09:33:41 -0800 | [diff] [blame] | 30 | namespace X8664 { |
John Porto | 7e93c62 | 2015-06-23 10:58:57 -0700 | [diff] [blame] | 31 | |
John Porto | 4a56686 | 2016-01-04 09:33:41 -0800 | [diff] [blame] | 32 | class TargetX8664 final : public X8664::TargetX86Base<X8664::Traits> { |
John Porto | 7e93c62 | 2015-06-23 10:58:57 -0700 | [diff] [blame] | 33 | TargetX8664() = delete; |
| 34 | TargetX8664(const TargetX8664 &) = delete; |
| 35 | TargetX8664 &operator=(const TargetX8664 &) = delete; |
| 36 | |
| 37 | public: |
John Porto | 53611e2 | 2015-12-30 07:30:10 -0800 | [diff] [blame] | 38 | ~TargetX8664() = default; |
| 39 | |
| 40 | static std::unique_ptr<::Ice::TargetLowering> create(Cfg *Func) { |
| 41 | return makeUnique<TargetX8664>(Func); |
| 42 | } |
| 43 | |
| 44 | std::unique_ptr<::Ice::Assembler> createAssembler() const override { |
Nicolas Capens | f53580b | 2016-09-28 07:20:30 -0400 | [diff] [blame] | 45 | const bool EmitAddrSizeOverridePrefix = |
| 46 | !NeedSandboxing && |
| 47 | getFlags().getApplicationBinaryInterface() == ABI_PNaCl; |
John Porto | 56958cb | 2016-01-14 09:18:18 -0800 | [diff] [blame] | 48 | return makeUnique<X8664::AssemblerX8664>(EmitAddrSizeOverridePrefix); |
John Porto | 53611e2 | 2015-12-30 07:30:10 -0800 | [diff] [blame] | 49 | } |
John Porto | d58f01c | 2015-06-23 15:55:17 -0700 | [diff] [blame] | 50 | |
John Porto | e0d9afa | 2015-08-05 10:13:44 -0700 | [diff] [blame] | 51 | protected: |
John Porto | 56958cb | 2016-01-14 09:18:18 -0800 | [diff] [blame] | 52 | void _add_sp(Operand *Adjustment); |
| 53 | void _mov_sp(Operand *NewValue); |
John Porto | 56958cb | 2016-01-14 09:18:18 -0800 | [diff] [blame] | 54 | Traits::X86OperandMem *_sandbox_mem_reference(X86OperandMem *Mem); |
| 55 | void _sub_sp(Operand *Adjustment); |
David Sehr | b9a404d | 2016-01-21 08:09:27 -0800 | [diff] [blame] | 56 | void _link_bp(); |
| 57 | void _unlink_bp(); |
Stephen White | 17078c7 | 2019-02-27 14:39:14 -0500 | [diff] [blame] | 58 | void _push_reg(RegNumT RegNum); |
| 59 | void _pop_reg(RegNumT RegNum); |
John Porto | 56958cb | 2016-01-14 09:18:18 -0800 | [diff] [blame] | 60 | |
John Porto | ac2388c | 2016-01-22 07:10:56 -0800 | [diff] [blame] | 61 | void initRebasePtr(); |
John Porto | 56958cb | 2016-01-14 09:18:18 -0800 | [diff] [blame] | 62 | void initSandbox(); |
John Porto | ac2388c | 2016-01-22 07:10:56 -0800 | [diff] [blame] | 63 | bool legalizeOptAddrForSandbox(OptAddr *Addr); |
David Sehr | b9a404d | 2016-01-21 08:09:27 -0800 | [diff] [blame] | 64 | void emitSandboxedReturn(); |
John Porto | 56958cb | 2016-01-14 09:18:18 -0800 | [diff] [blame] | 65 | void lowerIndirectJump(Variable *JumpTarget); |
David Sehr | b9a404d | 2016-01-21 08:09:27 -0800 | [diff] [blame] | 66 | void emitGetIP(CfgNode *Node); |
David Sehr | 0c68bef | 2016-01-20 10:00:23 -0800 | [diff] [blame] | 67 | Inst *emitCallToTarget(Operand *CallTarget, Variable *ReturnReg) override; |
| 68 | Variable *moveReturnValueToRegister(Operand *Value, Type ReturnType) override; |
John Porto | e0d9afa | 2015-08-05 10:13:44 -0700 | [diff] [blame] | 69 | |
John Porto | d58f01c | 2015-06-23 15:55:17 -0700 | [diff] [blame] | 70 | private: |
John Porto | 53611e2 | 2015-12-30 07:30:10 -0800 | [diff] [blame] | 71 | ENABLE_MAKE_UNIQUE; |
John Porto | 4a56686 | 2016-01-04 09:33:41 -0800 | [diff] [blame] | 72 | friend class X8664::TargetX86Base<X8664::Traits>; |
John Porto | 453660f | 2015-07-31 14:52:52 -0700 | [diff] [blame] | 73 | |
David Sehr | 6b80cf1 | 2016-01-21 23:16:58 -0800 | [diff] [blame] | 74 | explicit TargetX8664(Cfg *Func) : TargetX86Base(Func) {} |
| 75 | |
| 76 | void _push_rbp(); |
John Porto | 453660f | 2015-07-31 14:52:52 -0700 | [diff] [blame] | 77 | |
| 78 | Operand *createNaClReadTPSrcOperand() { |
| 79 | Variable *TDB = makeReg(IceType_i32); |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 80 | InstCall *Call = makeHelperCall(RuntimeHelper::H_call_read_tp, TDB, 0); |
John Porto | 453660f | 2015-07-31 14:52:52 -0700 | [diff] [blame] | 81 | lowerCall(Call); |
| 82 | return TDB; |
| 83 | } |
John Porto | 7e93c62 | 2015-06-23 10:58:57 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
John Porto | 4a56686 | 2016-01-04 09:33:41 -0800 | [diff] [blame] | 86 | } // end of namespace X8664 |
John Porto | 7e93c62 | 2015-06-23 10:58:57 -0700 | [diff] [blame] | 87 | } // end of namespace Ice |
| 88 | |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 89 | #endif // SUBZERO_SRC_ICETARGETLOWERINGX8664_H |