• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===---- TargetInfo.h - Encapsulate target details -------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // These classes wrap the information about a call or function
11 // definition used to handle ABI compliancy.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef CLANG_CODEGEN_TARGETINFO_H
16 #define CLANG_CODEGEN_TARGETINFO_H
17 
18 #include "llvm/ADT/StringRef.h"
19 
20 namespace llvm {
21   class GlobalValue;
22   class Type;
23   class Value;
24 }
25 
26 namespace clang {
27   class ABIInfo;
28   class Decl;
29 
30   namespace CodeGen {
31     class CodeGenModule;
32     class CodeGenFunction;
33   }
34 
35   /// TargetCodeGenInfo - This class organizes various target-specific
36   /// codegeneration issues, like target-specific attributes, builtins and so
37   /// on.
38   class TargetCodeGenInfo {
39     ABIInfo *Info;
40   public:
41     // WARNING: Acquires the ownership of ABIInfo.
Info(info)42     TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { }
43     virtual ~TargetCodeGenInfo();
44 
45     /// getABIInfo() - Returns ABI info helper for the target.
getABIInfo()46     const ABIInfo& getABIInfo() const { return *Info; }
47 
48     /// SetTargetAttributes - Provides a convenient hook to handle extra
49     /// target-specific attributes for the given global.
SetTargetAttributes(const Decl * D,llvm::GlobalValue * GV,CodeGen::CodeGenModule & M)50     virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
51                                      CodeGen::CodeGenModule &M) const { }
52 
53     /// Determines the size of struct _Unwind_Exception on this platform,
54     /// in 8-bit units.  The Itanium ABI defines this as:
55     ///   struct _Unwind_Exception {
56     ///     uint64 exception_class;
57     ///     _Unwind_Exception_Cleanup_Fn exception_cleanup;
58     ///     uint64 private_1;
59     ///     uint64 private_2;
60     ///   };
getSizeOfUnwindException()61     unsigned getSizeOfUnwindException() const { return 32; }
62 
63     /// Controls whether __builtin_extend_pointer should sign-extend
64     /// pointers to uint64_t or zero-extend them (the default).  Has
65     /// no effect for targets:
66     ///   - that have 64-bit pointers, or
67     ///   - that cannot address through registers larger than pointers, or
68     ///   - that implicitly ignore/truncate the top bits when addressing
69     ///     through such registers.
extendPointerWithSExt()70     virtual bool extendPointerWithSExt() const { return false; }
71 
72     /// Determines the DWARF register number for the stack pointer, for
73     /// exception-handling purposes.  Implements __builtin_dwarf_sp_column.
74     ///
75     /// Returns -1 if the operation is unsupported by this target.
getDwarfEHStackPointer(CodeGen::CodeGenModule & M)76     virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
77       return -1;
78     }
79 
80     /// Initializes the given DWARF EH register-size table, a char*.
81     /// Implements __builtin_init_dwarf_reg_size_table.
82     ///
83     /// Returns true if the operation is unsupported by this target.
initDwarfEHRegSizeTable(CodeGen::CodeGenFunction & CGF,llvm::Value * Address)84     virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
85                                          llvm::Value *Address) const {
86       return true;
87     }
88 
89     /// Performs the code-generation required to convert a return
90     /// address as stored by the system into the actual address of the
91     /// next instruction that will be executed.
92     ///
93     /// Used by __builtin_extract_return_addr().
decodeReturnAddress(CodeGen::CodeGenFunction & CGF,llvm::Value * Address)94     virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
95                                              llvm::Value *Address) const {
96       return Address;
97     }
98 
99     /// Performs the code-generation required to convert the address
100     /// of an instruction into a return address suitable for storage
101     /// by the system in a return slot.
102     ///
103     /// Used by __builtin_frob_return_addr().
encodeReturnAddress(CodeGen::CodeGenFunction & CGF,llvm::Value * Address)104     virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
105                                              llvm::Value *Address) const {
106       return Address;
107     }
108 
adjustInlineAsmType(CodeGen::CodeGenFunction & CGF,llvm::StringRef Constraint,llvm::Type * Ty)109     virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
110                                             llvm::StringRef Constraint,
111                                             llvm::Type* Ty) const {
112       return Ty;
113     }
114 
115     /// Retrieve the address of a function to call immediately before
116     /// calling objc_retainAutoreleasedReturnValue.  The
117     /// implementation of objc_autoreleaseReturnValue sniffs the
118     /// instruction stream following its return address to decide
119     /// whether it's a call to objc_retainAutoreleasedReturnValue.
120     /// This can be prohibitively expensive, depending on the
121     /// relocation model, and so on some targets it instead sniffs for
122     /// a particular instruction sequence.  This functions returns
123     /// that instruction sequence in inline assembly, which will be
124     /// empty if none is required.
getARCRetainAutoreleasedReturnValueMarker()125     virtual llvm::StringRef getARCRetainAutoreleasedReturnValueMarker() const {
126       return "";
127     }
128   };
129 }
130 
131 #endif // CLANG_CODEGEN_TARGETINFO_H
132