clang API Documentation
00001 //===---- TargetInfo.h - Encapsulate target details -------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // These classes wrap the information about a call or function 00011 // definition used to handle ABI compliancy. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef CLANG_CODEGEN_TARGETINFO_H 00016 #define CLANG_CODEGEN_TARGETINFO_H 00017 00018 #include "clang/Basic/LLVM.h" 00019 #include "clang/AST/Type.h" 00020 #include "llvm/ADT/StringRef.h" 00021 00022 namespace llvm { 00023 class GlobalValue; 00024 class Type; 00025 class Value; 00026 } 00027 00028 namespace clang { 00029 class ABIInfo; 00030 class Decl; 00031 00032 namespace CodeGen { 00033 class CallArgList; 00034 class CodeGenModule; 00035 class CodeGenFunction; 00036 class CGFunctionInfo; 00037 } 00038 00039 /// TargetCodeGenInfo - This class organizes various target-specific 00040 /// codegeneration issues, like target-specific attributes, builtins and so 00041 /// on. 00042 class TargetCodeGenInfo { 00043 ABIInfo *Info; 00044 public: 00045 // WARNING: Acquires the ownership of ABIInfo. 00046 TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { } 00047 virtual ~TargetCodeGenInfo(); 00048 00049 /// getABIInfo() - Returns ABI info helper for the target. 00050 const ABIInfo& getABIInfo() const { return *Info; } 00051 00052 /// SetTargetAttributes - Provides a convenient hook to handle extra 00053 /// target-specific attributes for the given global. 00054 virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV, 00055 CodeGen::CodeGenModule &M) const { } 00056 00057 /// Determines the size of struct _Unwind_Exception on this platform, 00058 /// in 8-bit units. The Itanium ABI defines this as: 00059 /// struct _Unwind_Exception { 00060 /// uint64 exception_class; 00061 /// _Unwind_Exception_Cleanup_Fn exception_cleanup; 00062 /// uint64 private_1; 00063 /// uint64 private_2; 00064 /// }; 00065 virtual unsigned getSizeOfUnwindException() const; 00066 00067 /// Controls whether __builtin_extend_pointer should sign-extend 00068 /// pointers to uint64_t or zero-extend them (the default). Has 00069 /// no effect for targets: 00070 /// - that have 64-bit pointers, or 00071 /// - that cannot address through registers larger than pointers, or 00072 /// - that implicitly ignore/truncate the top bits when addressing 00073 /// through such registers. 00074 virtual bool extendPointerWithSExt() const { return false; } 00075 00076 /// Determines the DWARF register number for the stack pointer, for 00077 /// exception-handling purposes. Implements __builtin_dwarf_sp_column. 00078 /// 00079 /// Returns -1 if the operation is unsupported by this target. 00080 virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const { 00081 return -1; 00082 } 00083 00084 /// Initializes the given DWARF EH register-size table, a char*. 00085 /// Implements __builtin_init_dwarf_reg_size_table. 00086 /// 00087 /// Returns true if the operation is unsupported by this target. 00088 virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, 00089 llvm::Value *Address) const { 00090 return true; 00091 } 00092 00093 /// Performs the code-generation required to convert a return 00094 /// address as stored by the system into the actual address of the 00095 /// next instruction that will be executed. 00096 /// 00097 /// Used by __builtin_extract_return_addr(). 00098 virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF, 00099 llvm::Value *Address) const { 00100 return Address; 00101 } 00102 00103 /// Performs the code-generation required to convert the address 00104 /// of an instruction into a return address suitable for storage 00105 /// by the system in a return slot. 00106 /// 00107 /// Used by __builtin_frob_return_addr(). 00108 virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF, 00109 llvm::Value *Address) const { 00110 return Address; 00111 } 00112 00113 virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, 00114 StringRef Constraint, 00115 llvm::Type* Ty) const { 00116 return Ty; 00117 } 00118 00119 /// Retrieve the address of a function to call immediately before 00120 /// calling objc_retainAutoreleasedReturnValue. The 00121 /// implementation of objc_autoreleaseReturnValue sniffs the 00122 /// instruction stream following its return address to decide 00123 /// whether it's a call to objc_retainAutoreleasedReturnValue. 00124 /// This can be prohibitively expensive, depending on the 00125 /// relocation model, and so on some targets it instead sniffs for 00126 /// a particular instruction sequence. This functions returns 00127 /// that instruction sequence in inline assembly, which will be 00128 /// empty if none is required. 00129 virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const { 00130 return ""; 00131 } 00132 00133 /// Determine whether a call to an unprototyped functions under 00134 /// the given calling convention should use the variadic 00135 /// convention or the non-variadic convention. 00136 /// 00137 /// There's a good reason to make a platform's variadic calling 00138 /// convention be different from its non-variadic calling 00139 /// convention: the non-variadic arguments can be passed in 00140 /// registers (better for performance), and the variadic arguments 00141 /// can be passed on the stack (also better for performance). If 00142 /// this is done, however, unprototyped functions *must* use the 00143 /// non-variadic convention, because C99 states that a call 00144 /// through an unprototyped function type must succeed if the 00145 /// function was defined with a non-variadic prototype with 00146 /// compatible parameters. Therefore, splitting the conventions 00147 /// makes it impossible to call a variadic function through an 00148 /// unprototyped type. Since function prototypes came out in the 00149 /// late 1970s, this is probably an acceptable trade-off. 00150 /// Nonetheless, not all platforms are willing to make it, and in 00151 /// particularly x86-64 bends over backwards to make the 00152 /// conventions compatible. 00153 /// 00154 /// The default is false. This is correct whenever: 00155 /// - the conventions are exactly the same, because it does not 00156 /// matter and the resulting IR will be somewhat prettier in 00157 /// certain cases; or 00158 /// - the conventions are substantively different in how they pass 00159 /// arguments, because in this case using the variadic convention 00160 /// will lead to C99 violations. 00161 /// It is not necessarily correct when arguments are passed in the 00162 /// same way and some out-of-band information is passed for the 00163 /// benefit of variadic callees, as is the case for x86-64. 00164 /// In this case the ABI should be consulted. 00165 virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args, 00166 const FunctionNoProtoType *fnType) const; 00167 }; 00168 } 00169 00170 #endif // CLANG_CODEGEN_TARGETINFO_H