1 //===- 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 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Declares the TargetLoweringX8632 class, which implements the
12 /// TargetLowering interface for the x86-32 architecture.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef SUBZERO_SRC_ICETARGETLOWERINGX8632_H
17 #define SUBZERO_SRC_ICETARGETLOWERINGX8632_H
18 
19 #include "IceAssemblerX8632.h"
20 #include "IceDefs.h"
21 #include "IceRegistersX8632.h"
22 #include "IceTargetLowering.h"
23 #include "IceInstX8632.h"
24 #define X86NAMESPACE X8632
25 #include "IceTargetLoweringX86Base.h"
26 #undef X86NAMESPACE
27 #include "IceTargetLoweringX8632Traits.h"
28 
29 namespace Ice {
30 namespace X8632 {
31 
32 class TargetX8632 final : public ::Ice::X8632::TargetX86Base<X8632::Traits> {
33   TargetX8632() = delete;
34   TargetX8632(const TargetX8632 &) = delete;
35   TargetX8632 &operator=(const TargetX8632 &) = delete;
36 
37 public:
38   ~TargetX8632() = default;
39 
40   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   }
47 
48 protected:
49   void _add_sp(Operand *Adjustment);
50   void _mov_sp(Operand *NewValue);
51   Traits::X86OperandMem *_sandbox_mem_reference(X86OperandMem *Mem);
52   void _sub_sp(Operand *Adjustment);
53   void _link_bp();
54   void _unlink_bp();
55   void _push_reg(Variable *Reg);
56 
57   void initRebasePtr();
58   void initSandbox();
59   bool legalizeOptAddrForSandbox(OptAddr *Addr);
60   void emitSandboxedReturn();
61   void lowerIndirectJump(Variable *JumpTarget);
62   void emitGetIP(CfgNode *Node);
63   Inst *emitCallToTarget(Operand *CallTarget, Variable *ReturnReg) override;
64   Variable *moveReturnValueToRegister(Operand *Value, Type ReturnType) override;
65 
66 private:
67   ENABLE_MAKE_UNIQUE;
68   friend class X8632::TargetX86Base<X8632::Traits>;
69 
70   explicit TargetX8632(Cfg *Func) : TargetX86Base(Func) {}
71 
72   Operand *createNaClReadTPSrcOperand() {
73     Constant *Zero = Ctx->getConstantZero(IceType_i32);
74     return Traits::X86OperandMem::create(Func, IceType_i32, nullptr, Zero,
75                                          nullptr, 0,
76                                          Traits::X86OperandMem::SegReg_GS);
77   }
78 };
79 
80 } // end of namespace X8632
81 } // end of namespace Ice
82 
83 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8632_H
84