Branch data Line data Source code
1 : : //===-- abi_win64.cpp - Windows x86_64 ABI description ----------*- C++ -*-===// 2 : : // 3 : : // LDC – the LLVM D compiler 4 : : // 5 : : // This file is distributed under the BSD-style LDC license: 6 : : // 7 : : // Copyright (c) 2007-2012 LDC Team. 8 : : // All rights reserved. 9 : : // 10 : : // Redistribution and use in source and binary forms, with or without 11 : : // modification, are permitted provided that the following conditions are met: 12 : : // 13 : : // * Redistributions of source code must retain the above copyright notice, 14 : : // this list of conditions and the following disclaimer. 15 : : // * Redistributions in binary form must reproduce the above copyright notice, 16 : : // this list of conditions and the following disclaimer in the documentation 17 : : // and/or other materials provided with the distribution. 18 : : // * Neither the name of the LDC Team nor the names of its contributors may be 19 : : // used to endorse or promote products derived from this software without 20 : : // specific prior written permission. 21 : : // 22 : : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 : : // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 : : // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 : : // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 26 : : // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 : : // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 : : // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 29 : : // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 : : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 : : // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 : : // 33 : : //===----------------------------------------------------------------------===// 34 : : // 35 : : // The ABI implementation used for 64 bit x86 (i.e. x86_64/AMD64/x64) targets 36 : : // on Windows. 37 : : // 38 : : //===----------------------------------------------------------------------===// 39 : : 40 : : // whether the argument can be passed in register 41 : 0 : static bool win64_reg_size(size_t size) 42 : : { 43 [ # # # # : 0 : return size <= 2 || size == 4 || size == 8; # # ] 44 : : } 45 : : 46 : : struct ABI_Win64Layout : AbiLayout { 47 : : int nargs; 48 : : ABI_Win64Layout() : nargs(0) { } 49 : : 50 : : bool use_sret(jl_datatype_t *dt, LLVMContext &ctx) override 51 : : { 52 : : size_t size = jl_datatype_size(dt); 53 : : if (win64_reg_size(size) || is_native_simd_type(dt)) 54 : : return false; 55 : : nargs++; 56 : : return true; 57 : : } 58 : : 59 : : bool needPassByRef(jl_datatype_t *dt, AttrBuilder &ab, LLVMContext &ctx, Type *Ty) override 60 : : { 61 : : nargs++; 62 : : size_t size = jl_datatype_size(dt); 63 : : if (win64_reg_size(size)) 64 : : return false; 65 : : if (nargs <= 4) { 66 : : ab.addByValAttr(Ty); 67 : : } 68 : : return true; 69 : : } 70 : : 71 : : Type *preferred_llvm_type(jl_datatype_t *dt, bool isret, LLVMContext &ctx) const override 72 : : { 73 : : size_t size = jl_datatype_size(dt); 74 : : if (size > 0 && win64_reg_size(size) && !jl_is_primitivetype(dt)) 75 : : return Type::getIntNTy(ctx, jl_datatype_nbits(dt)); 76 : : return NULL; 77 : : } 78 : : 79 : : };