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(Variable *Reg); 59 60 void initRebasePtr(); 61 void initSandbox(); 62 bool legalizeOptAddrForSandbox(OptAddr *Addr); 63 void emitSandboxedReturn(); 64 void lowerIndirectJump(Variable *JumpTarget); 65 void emitGetIP(CfgNode *Node); 66 Inst *emitCallToTarget(Operand *CallTarget, Variable *ReturnReg) override; 67 Variable *moveReturnValueToRegister(Operand *Value, Type ReturnType) override; 68 69 private: 70 ENABLE_MAKE_UNIQUE; 71 friend class X8664::TargetX86Base<X8664::Traits>; 72 TargetX8664(Cfg * Func)73 explicit TargetX8664(Cfg *Func) : TargetX86Base(Func) {} 74 75 void _push_rbp(); 76 createNaClReadTPSrcOperand()77 Operand *createNaClReadTPSrcOperand() { 78 Variable *TDB = makeReg(IceType_i32); 79 InstCall *Call = makeHelperCall(RuntimeHelper::H_call_read_tp, TDB, 0); 80 lowerCall(Call); 81 return TDB; 82 } 83 }; 84 85 } // end of namespace X8664 86 } // end of namespace Ice 87 88 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8664_H 89