1 //===- subzero/src/IceTargetLoweringX8664.h - lowering for x86-64 -*- 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 TargetLoweringX8664 class, which implements the 12 /// TargetLowering interface for the X86 64-bit architecture. 13 /// 14 //===----------------------------------------------------------------------===// 15 16 #ifndef SUBZERO_SRC_ICETARGETLOWERINGX8664_H 17 #define SUBZERO_SRC_ICETARGETLOWERINGX8664_H 18 19 #include "IceAssemblerX8664.h" 20 #include "IceCfg.h" 21 #include "IceGlobalContext.h" 22 #include "IceInstX8664.h" 23 #include "IceTargetLowering.h" 24 #define X86NAMESPACE X8664 25 #include "IceTargetLoweringX86Base.h" 26 #undef X86NAMESPACE 27 #include "IceTargetLoweringX8664Traits.h" 28 29 namespace Ice { 30 namespace X8664 { 31 32 class TargetX8664 final : public X8664::TargetX86Base<X8664::Traits> { 33 TargetX8664() = delete; 34 TargetX8664(const TargetX8664 &) = delete; 35 TargetX8664 &operator=(const TargetX8664 &) = delete; 36 37 public: 38 ~TargetX8664() = default; 39 create(Cfg * Func)40 static std::unique_ptr<::Ice::TargetLowering> create(Cfg *Func) { 41 return makeUnique<TargetX8664>(Func); 42 } 43 createAssembler()44 std::unique_ptr<::Ice::Assembler> createAssembler() const override { 45 const bool EmitAddrSizeOverridePrefix = 46 !NeedSandboxing && 47 getFlags().getApplicationBinaryInterface() == ABI_PNaCl; 48 return makeUnique<X8664::AssemblerX8664>(EmitAddrSizeOverridePrefix); 49 } 50 51 protected: 52 void _add_sp(Operand *Adjustment); 53 void _mov_sp(Operand *NewValue); 54 Traits::X86OperandMem *_sandbox_mem_reference(X86OperandMem *Mem); 55 void _sub_sp(Operand *Adjustment); 56 void _link_bp(); 57 void _unlink_bp(); 58 void _push_reg(RegNumT RegNum); 59 void _pop_reg(RegNumT RegNum); 60 61 void initRebasePtr(); 62 void initSandbox(); 63 bool legalizeOptAddrForSandbox(OptAddr *Addr); 64 void emitSandboxedReturn(); 65 void emitStackProbe(size_t StackSizeBytes); 66 void lowerIndirectJump(Variable *JumpTarget); 67 void emitGetIP(CfgNode *Node); 68 Inst *emitCallToTarget(Operand *CallTarget, Variable *ReturnReg, 69 size_t NumVariadicFpArgs = 0) override; 70 Variable *moveReturnValueToRegister(Operand *Value, Type ReturnType) override; 71 72 private: 73 ENABLE_MAKE_UNIQUE; 74 friend class X8664::TargetX86Base<X8664::Traits>; 75 TargetX8664(Cfg * Func)76 explicit TargetX8664(Cfg *Func) : TargetX86Base(Func) {} 77 78 void _push_rbp(); 79 createNaClReadTPSrcOperand()80 Operand *createNaClReadTPSrcOperand() { 81 Variable *TDB = makeReg(IceType_i32); 82 InstCall *Call = makeHelperCall(RuntimeHelper::H_call_read_tp, TDB, 0); 83 lowerCall(Call); 84 return TDB; 85 } 86 }; 87 88 } // end of namespace X8664 89 } // end of namespace Ice 90 91 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8664_H 92