• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "IceInstX8632.h"
22 #include "IceRegistersX8632.h"
23 #include "IceTargetLowering.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 
create(Cfg * Func)40   static std::unique_ptr<::Ice::TargetLowering> create(Cfg *Func) {
41     return makeUnique<TargetX8632>(Func);
42   }
43 
createAssembler()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(RegNumT RegNum);
56   void _pop_reg(RegNumT RegNum);
57 
58   void initRebasePtr();
59   void initSandbox();
60   bool legalizeOptAddrForSandbox(OptAddr *Addr);
61   void emitSandboxedReturn();
62   void emitStackProbe(size_t StackSizeBytes);
63   void lowerIndirectJump(Variable *JumpTarget);
64   void emitGetIP(CfgNode *Node);
65   Inst *emitCallToTarget(Operand *CallTarget, Variable *ReturnReg,
66                          size_t NumVariadicFpArgs = 0) override;
67   Variable *moveReturnValueToRegister(Operand *Value, Type ReturnType) override;
68 
69 private:
70   ENABLE_MAKE_UNIQUE;
71   friend class X8632::TargetX86Base<X8632::Traits>;
72 
TargetX8632(Cfg * Func)73   explicit TargetX8632(Cfg *Func) : TargetX86Base(Func) {}
74 
createNaClReadTPSrcOperand()75   Operand *createNaClReadTPSrcOperand() {
76     Constant *Zero = Ctx->getConstantZero(IceType_i32);
77     return Traits::X86OperandMem::create(Func, IceType_i32, nullptr, Zero,
78                                          nullptr, 0,
79                                          Traits::X86OperandMem::SegReg_GS);
80   }
81 };
82 
83 } // end of namespace X8632
84 } // end of namespace Ice
85 
86 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8632_H
87