blob: d5e8884cdffeaa61a47080cb141bba968d1b5fe7 [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
Peter Collingbourne4b93d662011-02-19 23:03:58 +000018#include "llvm/ADT/StringRef.h"
19
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000020namespace llvm {
21 class GlobalValue;
Peter Collingbourne4b93d662011-02-19 23:03:58 +000022 class Type;
John McCall492c4f92010-03-03 04:15:11 +000023 class Value;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000024}
25
26namespace clang {
27 class ABIInfo;
28 class Decl;
29
30 namespace CodeGen {
31 class CodeGenModule;
John McCall492c4f92010-03-03 04:15:11 +000032 class CodeGenFunction;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000033 }
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.
Douglas Gregor568bb2d2010-01-22 15:41:14 +000042 TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { }
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000043 virtual ~TargetCodeGenInfo();
44
45 /// getABIInfo() - Returns ABI info helper for the target.
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.
50 virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
Douglas Gregor568bb2d2010-01-22 15:41:14 +000051 CodeGen::CodeGenModule &M) const { }
John McCalld0b76ca2010-03-02 03:50:12 +000052
John McCall204b0752010-07-20 22:17:55 +000053 /// 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 /// };
61 unsigned getSizeOfUnwindException() const { return 32; }
62
John McCalld0b76ca2010-03-02 03:50:12 +000063 /// 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.
70 virtual bool extendPointerWithSExt() const { return false; }
John McCall492c4f92010-03-03 04:15:11 +000071
John McCall6374c332010-03-06 00:35:14 +000072 /// 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.
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.
84 virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
85 llvm::Value *Address) const {
86 return true;
87 }
88
John McCall492c4f92010-03-03 04:15:11 +000089 /// 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().
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().
104 virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
105 llvm::Value *Address) const {
106 return Address;
107 }
Peter Collingbourne4b93d662011-02-19 23:03:58 +0000108
Jay Foadef6de3d2011-07-11 09:56:20 +0000109 virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
110 llvm::StringRef Constraint,
111 llvm::Type* Ty) const {
Peter Collingbourne4b93d662011-02-19 23:03:58 +0000112 return Ty;
113 }
John McCallf85e1932011-06-15 23:02:42 +0000114
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.
125 virtual llvm::StringRef getARCRetainAutoreleasedReturnValueMarker() const {
126 return "";
127 }
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000128 };
129}
130
131#endif // CLANG_CODEGEN_TARGETINFO_H