182d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov//===---- TargetInfo.h - Encapsulate target details -------------*- C++ -*-===// 282d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// 382d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// The LLVM Compiler Infrastructure 482d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// 582d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// This file is distributed under the University of Illinois Open Source 682d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// License. See LICENSE.TXT for details. 782d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// 882d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov//===----------------------------------------------------------------------===// 982d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// 1082d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// These classes wrap the information about a call or function 1182d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// definition used to handle ABI compliancy. 1282d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov// 1382d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov//===----------------------------------------------------------------------===// 1482d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov 1582d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov#ifndef CLANG_CODEGEN_TARGETINFO_H 1682d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov#define CLANG_CODEGEN_TARGETINFO_H 1782d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov 18686775deca8b8685eb90801495880e3abdd844c2Chris Lattner#include "clang/Basic/LLVM.h" 1901f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall#include "clang/AST/Type.h" 204b93d660c6326ec79b5e369317d1051cf826c2f3Peter Collingbourne#include "llvm/ADT/StringRef.h" 214b93d660c6326ec79b5e369317d1051cf826c2f3Peter Collingbourne 2282d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikovnamespace llvm { 2382d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov class GlobalValue; 244b93d660c6326ec79b5e369317d1051cf826c2f3Peter Collingbourne class Type; 25492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall class Value; 2682d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov} 2782d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov 2882d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikovnamespace clang { 2982d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov class ABIInfo; 3082d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov class Decl; 3182d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov 3282d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov namespace CodeGen { 33de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall class CallArgList; 3482d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov class CodeGenModule; 35492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall class CodeGenFunction; 363ed7903d27f0e7e0cd3a61c165d39eca70f3cff5Eli Friedman class CGFunctionInfo; 3782d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov } 3882d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov 3982d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov /// TargetCodeGenInfo - This class organizes various target-specific 4082d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov /// codegeneration issues, like target-specific attributes, builtins and so 4182d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov /// on. 4282d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov class TargetCodeGenInfo { 4382d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov ABIInfo *Info; 4482d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov public: 4582d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov // WARNING: Acquires the ownership of ABIInfo. 46568bb2d3189108b6d510a6233d1e6e003a47cbdcDouglas Gregor TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { } 4782d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov virtual ~TargetCodeGenInfo(); 4882d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov 4982d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov /// getABIInfo() - Returns ABI info helper for the target. 5082d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov const ABIInfo& getABIInfo() const { return *Info; } 5182d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov 5282d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov /// SetTargetAttributes - Provides a convenient hook to handle extra 5382d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov /// target-specific attributes for the given global. 5482d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV, 55568bb2d3189108b6d510a6233d1e6e003a47cbdcDouglas Gregor CodeGen::CodeGenModule &M) const { } 56d0b76ca10feefcfda5cb16698e50197e87a7d876John McCall 57204b075fcc47c3f2aa7276dfba9b42eb25840b53John McCall /// Determines the size of struct _Unwind_Exception on this platform, 58204b075fcc47c3f2aa7276dfba9b42eb25840b53John McCall /// in 8-bit units. The Itanium ABI defines this as: 59204b075fcc47c3f2aa7276dfba9b42eb25840b53John McCall /// struct _Unwind_Exception { 60204b075fcc47c3f2aa7276dfba9b42eb25840b53John McCall /// uint64 exception_class; 61204b075fcc47c3f2aa7276dfba9b42eb25840b53John McCall /// _Unwind_Exception_Cleanup_Fn exception_cleanup; 62204b075fcc47c3f2aa7276dfba9b42eb25840b53John McCall /// uint64 private_1; 63204b075fcc47c3f2aa7276dfba9b42eb25840b53John McCall /// uint64 private_2; 64204b075fcc47c3f2aa7276dfba9b42eb25840b53John McCall /// }; 6549e34be6ae0c25b9843610cdd2fd6fea9cd8b870John McCall virtual unsigned getSizeOfUnwindException() const; 66204b075fcc47c3f2aa7276dfba9b42eb25840b53John McCall 67d0b76ca10feefcfda5cb16698e50197e87a7d876John McCall /// Controls whether __builtin_extend_pointer should sign-extend 68d0b76ca10feefcfda5cb16698e50197e87a7d876John McCall /// pointers to uint64_t or zero-extend them (the default). Has 69d0b76ca10feefcfda5cb16698e50197e87a7d876John McCall /// no effect for targets: 70d0b76ca10feefcfda5cb16698e50197e87a7d876John McCall /// - that have 64-bit pointers, or 71d0b76ca10feefcfda5cb16698e50197e87a7d876John McCall /// - that cannot address through registers larger than pointers, or 72d0b76ca10feefcfda5cb16698e50197e87a7d876John McCall /// - that implicitly ignore/truncate the top bits when addressing 73d0b76ca10feefcfda5cb16698e50197e87a7d876John McCall /// through such registers. 74d0b76ca10feefcfda5cb16698e50197e87a7d876John McCall virtual bool extendPointerWithSExt() const { return false; } 75492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall 766374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall /// Determines the DWARF register number for the stack pointer, for 776374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall /// exception-handling purposes. Implements __builtin_dwarf_sp_column. 786374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall /// 796374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall /// Returns -1 if the operation is unsupported by this target. 806374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const { 816374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall return -1; 826374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall } 836374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall 846374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall /// Initializes the given DWARF EH register-size table, a char*. 856374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall /// Implements __builtin_init_dwarf_reg_size_table. 866374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall /// 876374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall /// Returns true if the operation is unsupported by this target. 886374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, 896374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall llvm::Value *Address) const { 906374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall return true; 916374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall } 926374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall 93492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// Performs the code-generation required to convert a return 94492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// address as stored by the system into the actual address of the 95492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// next instruction that will be executed. 96492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// 97492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// Used by __builtin_extract_return_addr(). 98492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF, 99492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall llvm::Value *Address) const { 100492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall return Address; 101492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall } 102492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall 103492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// Performs the code-generation required to convert the address 104492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// of an instruction into a return address suitable for storage 105492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// by the system in a return slot. 106492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// 107492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall /// Used by __builtin_frob_return_addr(). 108492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF, 109492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall llvm::Value *Address) const { 110492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall return Address; 111492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall } 1124b93d660c6326ec79b5e369317d1051cf826c2f3Peter Collingbourne 113ef6de3da8572607f786303c07150daa6e140ab19Jay Foad virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, 114686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Constraint, 115ef6de3da8572607f786303c07150daa6e140ab19Jay Foad llvm::Type* Ty) const { 1164b93d660c6326ec79b5e369317d1051cf826c2f3Peter Collingbourne return Ty; 1174b93d660c6326ec79b5e369317d1051cf826c2f3Peter Collingbourne } 118f85e193739c953358c865005855253af4f68a497John McCall 119f85e193739c953358c865005855253af4f68a497John McCall /// Retrieve the address of a function to call immediately before 120f85e193739c953358c865005855253af4f68a497John McCall /// calling objc_retainAutoreleasedReturnValue. The 121f85e193739c953358c865005855253af4f68a497John McCall /// implementation of objc_autoreleaseReturnValue sniffs the 122f85e193739c953358c865005855253af4f68a497John McCall /// instruction stream following its return address to decide 123f85e193739c953358c865005855253af4f68a497John McCall /// whether it's a call to objc_retainAutoreleasedReturnValue. 124f85e193739c953358c865005855253af4f68a497John McCall /// This can be prohibitively expensive, depending on the 125f85e193739c953358c865005855253af4f68a497John McCall /// relocation model, and so on some targets it instead sniffs for 126f85e193739c953358c865005855253af4f68a497John McCall /// a particular instruction sequence. This functions returns 127f85e193739c953358c865005855253af4f68a497John McCall /// that instruction sequence in inline assembly, which will be 128f85e193739c953358c865005855253af4f68a497John McCall /// empty if none is required. 129686775deca8b8685eb90801495880e3abdd844c2Chris Lattner virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const { 130f85e193739c953358c865005855253af4f68a497John McCall return ""; 131f85e193739c953358c865005855253af4f68a497John McCall } 13201f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall 13301f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// Determine whether a call to an unprototyped functions under 13401f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// the given calling convention should use the variadic 13501f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// convention or the non-variadic convention. 13601f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// 13701f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// There's a good reason to make a platform's variadic calling 13801f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// convention be different from its non-variadic calling 13901f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// convention: the non-variadic arguments can be passed in 14001f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// registers (better for performance), and the variadic arguments 14101f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// can be passed on the stack (also better for performance). If 14201f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// this is done, however, unprototyped functions *must* use the 14301f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// non-variadic convention, because C99 states that a call 14401f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// through an unprototyped function type must succeed if the 14501f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// function was defined with a non-variadic prototype with 14601f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// compatible parameters. Therefore, splitting the conventions 14701f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// makes it impossible to call a variadic function through an 14801f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// unprototyped type. Since function prototypes came out in the 14901f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// late 1970s, this is probably an acceptable trade-off. 15001f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// Nonetheless, not all platforms are willing to make it, and in 15101f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// particularly x86-64 bends over backwards to make the 15201f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// conventions compatible. 15301f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// 15401f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// The default is false. This is correct whenever: 15501f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// - the conventions are exactly the same, because it does not 15601f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// matter and the resulting IR will be somewhat prettier in 15701f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// certain cases; or 15801f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// - the conventions are substantively different in how they pass 15901f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// arguments, because in this case using the variadic convention 16001f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// will lead to C99 violations. 16101f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// It is not necessarily correct when arguments are passed in the 16201f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// same way and some out-of-band information is passed for the 16301f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// benefit of variadic callees, as is the case for x86-64. 16401f151e0ffba72bcad770bea5f563a9b68ca050eJohn McCall /// In this case the ABI should be consulted. 165de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args, 166de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall const FunctionNoProtoType *fnType) const; 16782d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov }; 16882d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov} 16982d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov 17082d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov#endif // CLANG_CODEGEN_TARGETINFO_H 171