blob: 2715b0fab12d70b6754176b07d9d629a319188f6 [file] [log] [blame]
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -07001//===- subzero/src/IceTargetLoweringX8632.h - x86-32 lowering ---*- C++ -*-===//
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 Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
Jim Stichnoth92a6e5b2015-12-02 16:52:44 -080011/// \brief Declares the TargetLoweringX8632 class, which implements the
Andrew Scull57e12682015-09-16 11:30:19 -070012/// TargetLowering interface for the x86-32 architecture.
Andrew Scull9612d322015-07-06 14:53:25 -070013///
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070014//===----------------------------------------------------------------------===//
15
16#ifndef SUBZERO_SRC_ICETARGETLOWERINGX8632_H
17#define SUBZERO_SRC_ICETARGETLOWERINGX8632_H
18
John Portoaff4ccf2015-06-10 16:35:06 -070019#include "IceAssemblerX8632.h"
Jim Stichnotha18cc9c2014-09-30 19:10:22 -070020#include "IceDefs.h"
Jan Voungbd385e42014-09-18 18:18:10 -070021#include "IceRegistersX8632.h"
Jim Stichnotha18cc9c2014-09-30 19:10:22 -070022#include "IceTargetLowering.h"
John Porto4a566862016-01-04 09:33:41 -080023#include "IceInstX8632.h"
24#define X86NAMESPACE X8632
John Porto5aeed952015-07-21 13:39:09 -070025#include "IceTargetLoweringX86Base.h"
John Porto4a566862016-01-04 09:33:41 -080026#undef X86NAMESPACE
27#include "IceTargetLoweringX8632Traits.h"
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070028
29namespace Ice {
John Porto4a566862016-01-04 09:33:41 -080030namespace X8632 {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070031
John Porto4a566862016-01-04 09:33:41 -080032class TargetX8632 final : public ::Ice::X8632::TargetX86Base<X8632::Traits> {
Jim Stichnothc6ead202015-02-24 09:30:30 -080033 TargetX8632() = delete;
Jim Stichnoth7b451a92014-10-15 14:39:23 -070034 TargetX8632(const TargetX8632 &) = delete;
35 TargetX8632 &operator=(const TargetX8632 &) = delete;
36
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070037public:
John Porto53611e22015-12-30 07:30:10 -080038 ~TargetX8632() = default;
Matt Wala0a450512014-07-30 12:44:39 -070039
John Porto53611e22015-12-30 07:30:10 -080040 static std::unique_ptr<::Ice::TargetLowering> create(Cfg *Func) {
41 return makeUnique<TargetX8632>(Func);
42 }
43
44 std::unique_ptr<::Ice::Assembler> createAssembler() const override {
45 return makeUnique<X8632::AssemblerX8632>();
46 }
Matt Wala0a450512014-07-30 12:44:39 -070047
John Portoe0d9afa2015-08-05 10:13:44 -070048protected:
John Porto56958cb2016-01-14 09:18:18 -080049 void _add_sp(Operand *Adjustment);
50 void _mov_sp(Operand *NewValue);
John Portoac2388c2016-01-22 07:10:56 -080051 Traits::X86OperandMem *_sandbox_mem_reference(X86OperandMem *Mem);
John Porto56958cb2016-01-14 09:18:18 -080052 void _sub_sp(Operand *Adjustment);
David Sehrb9a404d2016-01-21 08:09:27 -080053 void _link_bp();
54 void _unlink_bp();
Stephen White17078c72019-02-27 14:39:14 -050055 void _push_reg(RegNumT RegNum);
56 void _pop_reg(RegNumT RegNum);
John Porto56958cb2016-01-14 09:18:18 -080057
John Portoac2388c2016-01-22 07:10:56 -080058 void initRebasePtr();
59 void initSandbox();
60 bool legalizeOptAddrForSandbox(OptAddr *Addr);
David Sehrb9a404d2016-01-21 08:09:27 -080061 void emitSandboxedReturn();
John Porto56958cb2016-01-14 09:18:18 -080062 void lowerIndirectJump(Variable *JumpTarget);
David Sehrb9a404d2016-01-21 08:09:27 -080063 void emitGetIP(CfgNode *Node);
David Sehr0c68bef2016-01-20 10:00:23 -080064 Inst *emitCallToTarget(Operand *CallTarget, Variable *ReturnReg) override;
65 Variable *moveReturnValueToRegister(Operand *Value, Type ReturnType) override;
John Portoe0d9afa2015-08-05 10:13:44 -070066
John Porto453660f2015-07-31 14:52:52 -070067private:
John Porto53611e22015-12-30 07:30:10 -080068 ENABLE_MAKE_UNIQUE;
John Porto4a566862016-01-04 09:33:41 -080069 friend class X8632::TargetX86Base<X8632::Traits>;
John Porto453660f2015-07-31 14:52:52 -070070
David Sehr6b80cf12016-01-21 23:16:58 -080071 explicit TargetX8632(Cfg *Func) : TargetX86Base(Func) {}
72
John Porto5aeed952015-07-21 13:39:09 -070073 Operand *createNaClReadTPSrcOperand() {
74 Constant *Zero = Ctx->getConstantZero(IceType_i32);
75 return Traits::X86OperandMem::create(Func, IceType_i32, nullptr, Zero,
76 nullptr, 0,
77 Traits::X86OperandMem::SegReg_GS);
78 }
Jan Voungfb792842015-06-11 15:27:50 -070079};
80
John Porto4a566862016-01-04 09:33:41 -080081} // end of namespace X8632
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070082} // end of namespace Ice
83
84#endif // SUBZERO_SRC_ICETARGETLOWERINGX8632_H