blob: ec24df6fdd958878c126089b60298ad5cef7811a [file] [log] [blame]
John Portod58f01c2015-06-23 15:55:17 -07001//===- subzero/src/IceTargetLoweringX8664.h - lowering for x86-64 -*- C++ -*-=//
John Porto7e93c622015-06-23 10:58:57 -07002//
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 Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
Jim Stichnoth92a6e5b2015-12-02 16:52:44 -080011/// \brief Declares the TargetLoweringX8664 class, which implements the
Andrew Scull9612d322015-07-06 14:53:25 -070012/// TargetLowering interface for the X86 64-bit architecture.
13///
John Porto7e93c622015-06-23 10:58:57 -070014//===----------------------------------------------------------------------===//
John Portod58f01c2015-06-23 15:55:17 -070015
John Porto7e93c622015-06-23 10:58:57 -070016#ifndef SUBZERO_SRC_ICETARGETLOWERINGX8664_H
17#define SUBZERO_SRC_ICETARGETLOWERINGX8664_H
18
John Porto453660f2015-07-31 14:52:52 -070019#include "IceAssemblerX8664.h"
John Portod58f01c2015-06-23 15:55:17 -070020#include "IceCfg.h"
21#include "IceGlobalContext.h"
John Porto453660f2015-07-31 14:52:52 -070022#include "IceInstX8664.h"
John Porto7e93c622015-06-23 10:58:57 -070023#include "IceTargetLowering.h"
John Porto4a566862016-01-04 09:33:41 -080024#define X86NAMESPACE X8664
John Porto453660f2015-07-31 14:52:52 -070025#include "IceTargetLoweringX86Base.h"
John Porto4a566862016-01-04 09:33:41 -080026#undef X86NAMESPACE
27#include "IceTargetLoweringX8664Traits.h"
John Porto7e93c622015-06-23 10:58:57 -070028
29namespace Ice {
John Porto4a566862016-01-04 09:33:41 -080030namespace X8664 {
John Porto7e93c622015-06-23 10:58:57 -070031
John Porto4a566862016-01-04 09:33:41 -080032class TargetX8664 final : public X8664::TargetX86Base<X8664::Traits> {
John Porto7e93c622015-06-23 10:58:57 -070033 TargetX8664() = delete;
34 TargetX8664(const TargetX8664 &) = delete;
35 TargetX8664 &operator=(const TargetX8664 &) = delete;
36
37public:
John Porto53611e22015-12-30 07:30:10 -080038 ~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 Capensf53580b2016-09-28 07:20:30 -040045 const bool EmitAddrSizeOverridePrefix =
46 !NeedSandboxing &&
47 getFlags().getApplicationBinaryInterface() == ABI_PNaCl;
John Porto56958cb2016-01-14 09:18:18 -080048 return makeUnique<X8664::AssemblerX8664>(EmitAddrSizeOverridePrefix);
John Porto53611e22015-12-30 07:30:10 -080049 }
John Portod58f01c2015-06-23 15:55:17 -070050
John Portoe0d9afa2015-08-05 10:13:44 -070051protected:
John Porto56958cb2016-01-14 09:18:18 -080052 void _add_sp(Operand *Adjustment);
53 void _mov_sp(Operand *NewValue);
John Porto56958cb2016-01-14 09:18:18 -080054 Traits::X86OperandMem *_sandbox_mem_reference(X86OperandMem *Mem);
55 void _sub_sp(Operand *Adjustment);
David Sehrb9a404d2016-01-21 08:09:27 -080056 void _link_bp();
57 void _unlink_bp();
Stephen White17078c72019-02-27 14:39:14 -050058 void _push_reg(RegNumT RegNum);
59 void _pop_reg(RegNumT RegNum);
John Porto56958cb2016-01-14 09:18:18 -080060
John Portoac2388c2016-01-22 07:10:56 -080061 void initRebasePtr();
John Porto56958cb2016-01-14 09:18:18 -080062 void initSandbox();
John Portoac2388c2016-01-22 07:10:56 -080063 bool legalizeOptAddrForSandbox(OptAddr *Addr);
David Sehrb9a404d2016-01-21 08:09:27 -080064 void emitSandboxedReturn();
John Porto56958cb2016-01-14 09:18:18 -080065 void lowerIndirectJump(Variable *JumpTarget);
David Sehrb9a404d2016-01-21 08:09:27 -080066 void emitGetIP(CfgNode *Node);
David Sehr0c68bef2016-01-20 10:00:23 -080067 Inst *emitCallToTarget(Operand *CallTarget, Variable *ReturnReg) override;
68 Variable *moveReturnValueToRegister(Operand *Value, Type ReturnType) override;
John Portoe0d9afa2015-08-05 10:13:44 -070069
John Portod58f01c2015-06-23 15:55:17 -070070private:
John Porto53611e22015-12-30 07:30:10 -080071 ENABLE_MAKE_UNIQUE;
John Porto4a566862016-01-04 09:33:41 -080072 friend class X8664::TargetX86Base<X8664::Traits>;
John Porto453660f2015-07-31 14:52:52 -070073
David Sehr6b80cf12016-01-21 23:16:58 -080074 explicit TargetX8664(Cfg *Func) : TargetX86Base(Func) {}
75
76 void _push_rbp();
John Porto453660f2015-07-31 14:52:52 -070077
78 Operand *createNaClReadTPSrcOperand() {
79 Variable *TDB = makeReg(IceType_i32);
Karl Schimpf20070e82016-03-17 13:30:13 -070080 InstCall *Call = makeHelperCall(RuntimeHelper::H_call_read_tp, TDB, 0);
John Porto453660f2015-07-31 14:52:52 -070081 lowerCall(Call);
82 return TDB;
83 }
John Porto7e93c622015-06-23 10:58:57 -070084};
85
John Porto4a566862016-01-04 09:33:41 -080086} // end of namespace X8664
John Porto7e93c622015-06-23 10:58:57 -070087} // end of namespace Ice
88
Jim Stichnoth20b71f52015-06-24 15:52:24 -070089#endif // SUBZERO_SRC_ICETARGETLOWERINGX8664_H