blob: a188b9c6c281ff2a8470858d6cffb9436950fe00 [file] [log] [blame]
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00001//===---- 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
Chris Lattner686775d2011-07-20 06:58:45 +000018#include "clang/Basic/LLVM.h"
Peter Collingbourne4b93d662011-02-19 23:03:58 +000019#include "llvm/ADT/StringRef.h"
20
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000021namespace llvm {
22 class GlobalValue;
Peter Collingbourne4b93d662011-02-19 23:03:58 +000023 class Type;
John McCall492c4f92010-03-03 04:15:11 +000024 class Value;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000025}
26
27namespace clang {
28 class ABIInfo;
29 class Decl;
30
31 namespace CodeGen {
32 class CodeGenModule;
John McCall492c4f92010-03-03 04:15:11 +000033 class CodeGenFunction;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000034 }
35
36 /// TargetCodeGenInfo - This class organizes various target-specific
37 /// codegeneration issues, like target-specific attributes, builtins and so
38 /// on.
39 class TargetCodeGenInfo {
40 ABIInfo *Info;
41 public:
42 // WARNING: Acquires the ownership of ABIInfo.
Douglas Gregor568bb2d2010-01-22 15:41:14 +000043 TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { }
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000044 virtual ~TargetCodeGenInfo();
45
46 /// getABIInfo() - Returns ABI info helper for the target.
47 const ABIInfo& getABIInfo() const { return *Info; }
48
49 /// SetTargetAttributes - Provides a convenient hook to handle extra
50 /// target-specific attributes for the given global.
51 virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
Douglas Gregor568bb2d2010-01-22 15:41:14 +000052 CodeGen::CodeGenModule &M) const { }
John McCalld0b76ca2010-03-02 03:50:12 +000053
John McCall204b0752010-07-20 22:17:55 +000054 /// Determines the size of struct _Unwind_Exception on this platform,
55 /// in 8-bit units. The Itanium ABI defines this as:
56 /// struct _Unwind_Exception {
57 /// uint64 exception_class;
58 /// _Unwind_Exception_Cleanup_Fn exception_cleanup;
59 /// uint64 private_1;
60 /// uint64 private_2;
61 /// };
62 unsigned getSizeOfUnwindException() const { return 32; }
63
John McCalld0b76ca2010-03-02 03:50:12 +000064 /// Controls whether __builtin_extend_pointer should sign-extend
65 /// pointers to uint64_t or zero-extend them (the default). Has
66 /// no effect for targets:
67 /// - that have 64-bit pointers, or
68 /// - that cannot address through registers larger than pointers, or
69 /// - that implicitly ignore/truncate the top bits when addressing
70 /// through such registers.
71 virtual bool extendPointerWithSExt() const { return false; }
John McCall492c4f92010-03-03 04:15:11 +000072
John McCall6374c332010-03-06 00:35:14 +000073 /// Determines the DWARF register number for the stack pointer, for
74 /// exception-handling purposes. Implements __builtin_dwarf_sp_column.
75 ///
76 /// Returns -1 if the operation is unsupported by this target.
77 virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
78 return -1;
79 }
80
81 /// Initializes the given DWARF EH register-size table, a char*.
82 /// Implements __builtin_init_dwarf_reg_size_table.
83 ///
84 /// Returns true if the operation is unsupported by this target.
85 virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
86 llvm::Value *Address) const {
87 return true;
88 }
89
John McCall492c4f92010-03-03 04:15:11 +000090 /// Performs the code-generation required to convert a return
91 /// address as stored by the system into the actual address of the
92 /// next instruction that will be executed.
93 ///
94 /// Used by __builtin_extract_return_addr().
95 virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
96 llvm::Value *Address) const {
97 return Address;
98 }
99
100 /// Performs the code-generation required to convert the address
101 /// of an instruction into a return address suitable for storage
102 /// by the system in a return slot.
103 ///
104 /// Used by __builtin_frob_return_addr().
105 virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
106 llvm::Value *Address) const {
107 return Address;
108 }
Peter Collingbourne4b93d662011-02-19 23:03:58 +0000109
Jay Foadef6de3d2011-07-11 09:56:20 +0000110 virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
Chris Lattner686775d2011-07-20 06:58:45 +0000111 StringRef Constraint,
Jay Foadef6de3d2011-07-11 09:56:20 +0000112 llvm::Type* Ty) const {
Peter Collingbourne4b93d662011-02-19 23:03:58 +0000113 return Ty;
114 }
John McCallf85e1932011-06-15 23:02:42 +0000115
116 /// Retrieve the address of a function to call immediately before
117 /// calling objc_retainAutoreleasedReturnValue. The
118 /// implementation of objc_autoreleaseReturnValue sniffs the
119 /// instruction stream following its return address to decide
120 /// whether it's a call to objc_retainAutoreleasedReturnValue.
121 /// This can be prohibitively expensive, depending on the
122 /// relocation model, and so on some targets it instead sniffs for
123 /// a particular instruction sequence. This functions returns
124 /// that instruction sequence in inline assembly, which will be
125 /// empty if none is required.
Chris Lattner686775d2011-07-20 06:58:45 +0000126 virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const {
John McCallf85e1932011-06-15 23:02:42 +0000127 return "";
128 }
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000129 };
130}
131
132#endif // CLANG_CODEGEN_TARGETINFO_H