Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1 | //===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 10 | // This is the internal per-function state used for llvm translation. |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | c18bfbb | 2008-02-29 17:10:38 +0000 | [diff] [blame] | 14 | #ifndef CLANG_CODEGEN_CODEGENFUNCTION_H |
| 15 | #define CLANG_CODEGEN_CODEGENFUNCTION_H |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 16 | |
Chris Lattner | 4bd5596 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
Argyrios Kyrtzidis | 0705235 | 2008-09-10 02:36:38 +0000 | [diff] [blame] | 18 | #include "clang/AST/ExprCXX.h" |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 19 | #include "clang/AST/ExprObjC.h" |
Ken Dyck | 4077500 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/CharUnits.h" |
Chris Lattner | 2739d2b | 2009-03-31 22:17:44 +0000 | [diff] [blame] | 21 | #include "clang/Basic/TargetInfo.h" |
| 22 | #include "llvm/ADT/DenseMap.h" |
| 23 | #include "llvm/ADT/SmallVector.h" |
| 24 | #include "llvm/Support/ValueHandle.h" |
Owen Anderson | ae86c19 | 2009-07-13 04:10:07 +0000 | [diff] [blame] | 25 | #include "CodeGenModule.h" |
Mike Stump | edb252a | 2009-03-04 15:32:52 +0000 | [diff] [blame] | 26 | #include "CGBlocks.h" |
Daniel Dunbar | cb46385 | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 27 | #include "CGBuilder.h" |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 28 | #include "CGCall.h" |
Anders Carlsson | b7f8f59 | 2009-04-17 00:06:03 +0000 | [diff] [blame] | 29 | #include "CGCXX.h" |
Daniel Dunbar | 97db84c | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 30 | #include "CGValue.h" |
| 31 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 32 | namespace llvm { |
Daniel Dunbar | 6e8aa53 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 33 | class BasicBlock; |
Benjamin Kramer | 9cd050a | 2009-08-11 17:46:57 +0000 | [diff] [blame] | 34 | class LLVMContext; |
David Chisnall | 9eecafa | 2010-05-01 11:15:56 +0000 | [diff] [blame] | 35 | class MDNode; |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 36 | class Module; |
Daniel Dunbar | 2efd538 | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 37 | class SwitchInst; |
Daniel Dunbar | b5aacc2 | 2009-10-19 01:21:05 +0000 | [diff] [blame] | 38 | class Twine; |
Daniel Dunbar | 9b1335e | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 39 | class Value; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 40 | class CallSite; |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 43 | namespace clang { |
| 44 | class ASTContext; |
Anders Carlsson | 0a63741 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 45 | class CXXDestructorDecl; |
Anders Carlsson | 52d78a5 | 2009-09-27 18:58:34 +0000 | [diff] [blame] | 46 | class CXXTryStmt; |
Chris Lattner | 84915fa | 2007-06-02 04:16:21 +0000 | [diff] [blame] | 47 | class Decl; |
Daniel Dunbar | 6e8aa53 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 48 | class EnumConstantDecl; |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 49 | class FunctionDecl; |
Douglas Gregor | deaad8c | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 50 | class FunctionProtoType; |
Daniel Dunbar | 6e8aa53 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 51 | class LabelStmt; |
Fariborz Jahanian | 0196a1c | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 52 | class ObjCContainerDecl; |
Daniel Dunbar | 1c64e5d | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 53 | class ObjCInterfaceDecl; |
| 54 | class ObjCIvarDecl; |
Chris Lattner | 4bd5596 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 55 | class ObjCMethodDecl; |
Fariborz Jahanian | 3d8552a | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 56 | class ObjCImplementationDecl; |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 57 | class ObjCPropertyImplDecl; |
Chris Lattner | 2ccb73b | 2007-06-16 00:16:26 +0000 | [diff] [blame] | 58 | class TargetInfo; |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 59 | class TargetCodeGenInfo; |
Daniel Dunbar | 6e8aa53 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 60 | class VarDecl; |
Chris Lattner | f0b64d7 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 61 | class ObjCForCollectionStmt; |
| 62 | class ObjCAtTryStmt; |
| 63 | class ObjCAtThrowStmt; |
| 64 | class ObjCAtSynchronizedStmt; |
Devang Patel | 3e11cce | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 65 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 66 | namespace CodeGen { |
Devang Patel | 3e11cce | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 67 | class CodeGenTypes; |
Anders Carlsson | 63784f4 | 2009-02-13 08:11:52 +0000 | [diff] [blame] | 68 | class CGDebugInfo; |
Daniel Dunbar | 7633cbf | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 69 | class CGFunctionInfo; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 70 | class CGRecordLayout; |
John McCall | 9d42f0f | 2010-05-21 04:11:14 +0000 | [diff] [blame] | 71 | class CGBlockInfo; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 72 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 73 | /// A branch fixup. These are required when emitting a goto to a |
| 74 | /// label which hasn't been emitted yet. The goto is optimistically |
| 75 | /// emitted as a branch to the basic block for the label, and (if it |
| 76 | /// occurs in a scope with non-trivial cleanups) a fixup is added to |
| 77 | /// the innermost cleanup. When a (normal) cleanup is popped, any |
| 78 | /// unresolved fixups in that scope are threaded through the cleanup. |
| 79 | struct BranchFixup { |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 80 | /// The block containing the terminator which needs to be modified |
| 81 | /// into a switch if this fixup is resolved into the current scope. |
| 82 | /// If null, LatestBranch points directly to the destination. |
| 83 | llvm::BasicBlock *OptimisticBranchBlock; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 84 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 85 | /// The ultimate destination of the branch. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 86 | /// |
| 87 | /// This can be set to null to indicate that this fixup was |
| 88 | /// successfully resolved. |
| 89 | llvm::BasicBlock *Destination; |
| 90 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 91 | /// The destination index value. |
| 92 | unsigned DestinationIndex; |
| 93 | |
| 94 | /// The initial branch of the fixup. |
| 95 | llvm::BranchInst *InitialBranch; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 98 | enum CleanupKind { NormalAndEHCleanup, EHCleanup, NormalCleanup }; |
| 99 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 100 | /// A stack of scopes which respond to exceptions, including cleanups |
| 101 | /// and catch blocks. |
| 102 | class EHScopeStack { |
| 103 | public: |
| 104 | /// A saved depth on the scope stack. This is necessary because |
| 105 | /// pushing scopes onto the stack invalidates iterators. |
| 106 | class stable_iterator { |
| 107 | friend class EHScopeStack; |
| 108 | |
| 109 | /// Offset from StartOfData to EndOfBuffer. |
| 110 | ptrdiff_t Size; |
| 111 | |
| 112 | stable_iterator(ptrdiff_t Size) : Size(Size) {} |
| 113 | |
| 114 | public: |
| 115 | static stable_iterator invalid() { return stable_iterator(-1); } |
| 116 | stable_iterator() : Size(-1) {} |
| 117 | |
| 118 | bool isValid() const { return Size >= 0; } |
| 119 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 120 | bool encloses(stable_iterator I) const { return Size <= I.Size; } |
| 121 | bool strictlyEncloses(stable_iterator I) const { return Size < I.Size; } |
John McCall | 8f51041 | 2010-07-21 00:40:03 +0000 | [diff] [blame] | 122 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 123 | friend bool operator==(stable_iterator A, stable_iterator B) { |
| 124 | return A.Size == B.Size; |
| 125 | } |
| 126 | friend bool operator!=(stable_iterator A, stable_iterator B) { |
| 127 | return A.Size != B.Size; |
| 128 | } |
| 129 | }; |
| 130 | |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 131 | /// Information for lazily generating a cleanup. Subclasses must be |
| 132 | /// POD-like: cleanups will not be destructed, and they will be |
| 133 | /// allocated on the cleanup stack and freely copied and moved |
| 134 | /// around. |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 135 | /// |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 136 | /// Cleanup implementations should generally be declared in an |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 137 | /// anonymous namespace. |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 138 | class Cleanup { |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 139 | public: |
John McCall | 11e577b | 2010-07-13 23:19:49 +0000 | [diff] [blame] | 140 | // Anchor the construction vtable. We use the destructor because |
| 141 | // gcc gives an obnoxious warning if there are virtual methods |
| 142 | // with an accessible non-virtual destructor. Unfortunately, |
| 143 | // declaring this destructor makes it non-trivial, but there |
| 144 | // doesn't seem to be any other way around this warning. |
| 145 | // |
| 146 | // This destructor will never be called. |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 147 | virtual ~Cleanup(); |
John McCall | 11e577b | 2010-07-13 23:19:49 +0000 | [diff] [blame] | 148 | |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 149 | /// Emit the cleanup. For normal cleanups, this is run in the |
| 150 | /// same EH context as when the cleanup was pushed, i.e. the |
| 151 | /// immediately-enclosing context of the cleanup scope. For |
| 152 | /// EH cleanups, this is run in a terminate context. |
| 153 | /// |
| 154 | // \param IsForEHCleanup true if this is for an EH cleanup, false |
| 155 | /// if for a normal cleanup. |
| 156 | virtual void Emit(CodeGenFunction &CGF, bool IsForEHCleanup) = 0; |
| 157 | }; |
| 158 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 159 | private: |
| 160 | // The implementation for this class is in CGException.h and |
| 161 | // CGException.cpp; the definition is here because it's used as a |
| 162 | // member of CodeGenFunction. |
| 163 | |
| 164 | /// The start of the scope-stack buffer, i.e. the allocated pointer |
| 165 | /// for the buffer. All of these pointers are either simultaneously |
| 166 | /// null or simultaneously valid. |
| 167 | char *StartOfBuffer; |
| 168 | |
| 169 | /// The end of the buffer. |
| 170 | char *EndOfBuffer; |
| 171 | |
| 172 | /// The first valid entry in the buffer. |
| 173 | char *StartOfData; |
| 174 | |
| 175 | /// The innermost normal cleanup on the stack. |
| 176 | stable_iterator InnermostNormalCleanup; |
| 177 | |
| 178 | /// The innermost EH cleanup on the stack. |
| 179 | stable_iterator InnermostEHCleanup; |
| 180 | |
| 181 | /// The number of catches on the stack. |
| 182 | unsigned CatchDepth; |
| 183 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 184 | /// The current EH destination index. Reset to FirstCatchIndex |
| 185 | /// whenever the last EH cleanup is popped. |
| 186 | unsigned NextEHDestIndex; |
| 187 | enum { FirstEHDestIndex = 1 }; |
| 188 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 189 | /// The current set of branch fixups. A branch fixup is a jump to |
| 190 | /// an as-yet unemitted label, i.e. a label for which we don't yet |
| 191 | /// know the EH stack depth. Whenever we pop a cleanup, we have |
| 192 | /// to thread all the current branch fixups through it. |
| 193 | /// |
| 194 | /// Fixups are recorded as the Use of the respective branch or |
| 195 | /// switch statement. The use points to the final destination. |
| 196 | /// When popping out of a cleanup, these uses are threaded through |
| 197 | /// the cleanup and adjusted to point to the new cleanup. |
| 198 | /// |
| 199 | /// Note that branches are allowed to jump into protected scopes |
| 200 | /// in certain situations; e.g. the following code is legal: |
| 201 | /// struct A { ~A(); }; // trivial ctor, non-trivial dtor |
| 202 | /// goto foo; |
| 203 | /// A a; |
| 204 | /// foo: |
| 205 | /// bar(); |
| 206 | llvm::SmallVector<BranchFixup, 8> BranchFixups; |
| 207 | |
| 208 | char *allocate(size_t Size); |
| 209 | |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 210 | void *pushCleanup(CleanupKind K, size_t DataSize); |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 211 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 212 | public: |
| 213 | EHScopeStack() : StartOfBuffer(0), EndOfBuffer(0), StartOfData(0), |
| 214 | InnermostNormalCleanup(stable_end()), |
| 215 | InnermostEHCleanup(stable_end()), |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 216 | CatchDepth(0), NextEHDestIndex(FirstEHDestIndex) {} |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 217 | ~EHScopeStack() { delete[] StartOfBuffer; } |
| 218 | |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 219 | // Variadic templates would make this not terrible. |
| 220 | |
| 221 | /// Push a lazily-created cleanup on the stack. |
John McCall | 5c08ab9 | 2010-07-13 22:12:14 +0000 | [diff] [blame] | 222 | template <class T> |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 223 | void pushCleanup(CleanupKind Kind) { |
| 224 | void *Buffer = pushCleanup(Kind, sizeof(T)); |
| 225 | Cleanup *Obj = new(Buffer) T(); |
John McCall | 5c08ab9 | 2010-07-13 22:12:14 +0000 | [diff] [blame] | 226 | (void) Obj; |
| 227 | } |
| 228 | |
| 229 | /// Push a lazily-created cleanup on the stack. |
| 230 | template <class T, class A0> |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 231 | void pushCleanup(CleanupKind Kind, A0 a0) { |
| 232 | void *Buffer = pushCleanup(Kind, sizeof(T)); |
| 233 | Cleanup *Obj = new(Buffer) T(a0); |
John McCall | 5c08ab9 | 2010-07-13 22:12:14 +0000 | [diff] [blame] | 234 | (void) Obj; |
| 235 | } |
| 236 | |
| 237 | /// Push a lazily-created cleanup on the stack. |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 238 | template <class T, class A0, class A1> |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 239 | void pushCleanup(CleanupKind Kind, A0 a0, A1 a1) { |
| 240 | void *Buffer = pushCleanup(Kind, sizeof(T)); |
| 241 | Cleanup *Obj = new(Buffer) T(a0, a1); |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 242 | (void) Obj; |
| 243 | } |
| 244 | |
| 245 | /// Push a lazily-created cleanup on the stack. |
| 246 | template <class T, class A0, class A1, class A2> |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 247 | void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2) { |
| 248 | void *Buffer = pushCleanup(Kind, sizeof(T)); |
| 249 | Cleanup *Obj = new(Buffer) T(a0, a1, a2); |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 250 | (void) Obj; |
| 251 | } |
| 252 | |
| 253 | /// Push a lazily-created cleanup on the stack. |
| 254 | template <class T, class A0, class A1, class A2, class A3> |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 255 | void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3) { |
| 256 | void *Buffer = pushCleanup(Kind, sizeof(T)); |
| 257 | Cleanup *Obj = new(Buffer) T(a0, a1, a2, a3); |
John McCall | 2b7fc38 | 2010-07-13 20:32:21 +0000 | [diff] [blame] | 258 | (void) Obj; |
| 259 | } |
| 260 | |
John McCall | 906da4b | 2010-07-21 05:47:49 +0000 | [diff] [blame] | 261 | /// Push a lazily-created cleanup on the stack. |
| 262 | template <class T, class A0, class A1, class A2, class A3, class A4> |
John McCall | cda666c | 2010-07-21 07:22:38 +0000 | [diff] [blame] | 263 | void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
| 264 | void *Buffer = pushCleanup(Kind, sizeof(T)); |
| 265 | Cleanup *Obj = new(Buffer) T(a0, a1, a2, a3, a4); |
John McCall | 906da4b | 2010-07-21 05:47:49 +0000 | [diff] [blame] | 266 | (void) Obj; |
| 267 | } |
| 268 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 269 | /// Pops a cleanup scope off the stack. This should only be called |
| 270 | /// by CodeGenFunction::PopCleanupBlock. |
| 271 | void popCleanup(); |
| 272 | |
| 273 | /// Push a set of catch handlers on the stack. The catch is |
| 274 | /// uninitialized and will need to have the given number of handlers |
| 275 | /// set on it. |
| 276 | class EHCatchScope *pushCatch(unsigned NumHandlers); |
| 277 | |
| 278 | /// Pops a catch scope off the stack. |
| 279 | void popCatch(); |
| 280 | |
| 281 | /// Push an exceptions filter on the stack. |
| 282 | class EHFilterScope *pushFilter(unsigned NumFilters); |
| 283 | |
| 284 | /// Pops an exceptions filter off the stack. |
| 285 | void popFilter(); |
| 286 | |
| 287 | /// Push a terminate handler on the stack. |
| 288 | void pushTerminate(); |
| 289 | |
| 290 | /// Pops a terminate handler off the stack. |
| 291 | void popTerminate(); |
| 292 | |
| 293 | /// Determines whether the exception-scopes stack is empty. |
| 294 | bool empty() const { return StartOfData == EndOfBuffer; } |
| 295 | |
| 296 | bool requiresLandingPad() const { |
| 297 | return (CatchDepth || hasEHCleanups()); |
| 298 | } |
| 299 | |
| 300 | /// Determines whether there are any normal cleanups on the stack. |
| 301 | bool hasNormalCleanups() const { |
| 302 | return InnermostNormalCleanup != stable_end(); |
| 303 | } |
| 304 | |
| 305 | /// Returns the innermost normal cleanup on the stack, or |
| 306 | /// stable_end() if there are no normal cleanups. |
| 307 | stable_iterator getInnermostNormalCleanup() const { |
| 308 | return InnermostNormalCleanup; |
| 309 | } |
| 310 | |
| 311 | /// Determines whether there are any EH cleanups on the stack. |
| 312 | bool hasEHCleanups() const { |
| 313 | return InnermostEHCleanup != stable_end(); |
| 314 | } |
| 315 | |
| 316 | /// Returns the innermost EH cleanup on the stack, or stable_end() |
| 317 | /// if there are no EH cleanups. |
| 318 | stable_iterator getInnermostEHCleanup() const { |
| 319 | return InnermostEHCleanup; |
| 320 | } |
| 321 | |
| 322 | /// An unstable reference to a scope-stack depth. Invalidated by |
| 323 | /// pushes but not pops. |
| 324 | class iterator; |
| 325 | |
| 326 | /// Returns an iterator pointing to the innermost EH scope. |
| 327 | iterator begin() const; |
| 328 | |
| 329 | /// Returns an iterator pointing to the outermost EH scope. |
| 330 | iterator end() const; |
| 331 | |
| 332 | /// Create a stable reference to the top of the EH stack. The |
| 333 | /// returned reference is valid until that scope is popped off the |
| 334 | /// stack. |
| 335 | stable_iterator stable_begin() const { |
| 336 | return stable_iterator(EndOfBuffer - StartOfData); |
| 337 | } |
| 338 | |
| 339 | /// Create a stable reference to the bottom of the EH stack. |
| 340 | static stable_iterator stable_end() { |
| 341 | return stable_iterator(0); |
| 342 | } |
| 343 | |
| 344 | /// Translates an iterator into a stable_iterator. |
| 345 | stable_iterator stabilize(iterator it) const; |
| 346 | |
| 347 | /// Finds the nearest cleanup enclosing the given iterator. |
| 348 | /// Returns stable_iterator::invalid() if there are no such cleanups. |
| 349 | stable_iterator getEnclosingEHCleanup(iterator it) const; |
| 350 | |
| 351 | /// Turn a stable reference to a scope depth into a unstable pointer |
| 352 | /// to the EH stack. |
| 353 | iterator find(stable_iterator save) const; |
| 354 | |
| 355 | /// Removes the cleanup pointed to by the given stable_iterator. |
| 356 | void removeCleanup(stable_iterator save); |
| 357 | |
| 358 | /// Add a branch fixup to the current cleanup scope. |
| 359 | BranchFixup &addBranchFixup() { |
| 360 | assert(hasNormalCleanups() && "adding fixup in scope without cleanups"); |
| 361 | BranchFixups.push_back(BranchFixup()); |
| 362 | return BranchFixups.back(); |
| 363 | } |
| 364 | |
| 365 | unsigned getNumBranchFixups() const { return BranchFixups.size(); } |
| 366 | BranchFixup &getBranchFixup(unsigned I) { |
| 367 | assert(I < getNumBranchFixups()); |
| 368 | return BranchFixups[I]; |
| 369 | } |
| 370 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 371 | /// Pops lazily-removed fixups from the end of the list. This |
| 372 | /// should only be called by procedures which have just popped a |
| 373 | /// cleanup or resolved one or more fixups. |
| 374 | void popNullFixups(); |
| 375 | |
| 376 | /// Clears the branch-fixups list. This should only be called by |
| 377 | /// CodeGenFunction::ResolveAllBranchFixups. |
| 378 | void clearFixups() { BranchFixups.clear(); } |
| 379 | |
| 380 | /// Gets the next EH destination index. |
| 381 | unsigned getNextEHDestIndex() { return NextEHDestIndex++; } |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 384 | /// CodeGenFunction - This class organizes the per-function state that is used |
| 385 | /// while generating LLVM code. |
Mike Stump | 9543567 | 2009-03-04 18:17:45 +0000 | [diff] [blame] | 386 | class CodeGenFunction : public BlockFunction { |
Anders Carlsson | 729a820 | 2009-02-24 04:21:31 +0000 | [diff] [blame] | 387 | CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT |
| 388 | void operator=(const CodeGenFunction&); // DO NOT IMPLEMENT |
Chris Lattner | bda69f8 | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 389 | public: |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 390 | /// A jump destination is an abstract label, branching to which may |
| 391 | /// require a jump out through normal cleanups. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 392 | struct JumpDest { |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 393 | JumpDest() : Block(0), ScopeDepth(), Index(0) {} |
| 394 | JumpDest(llvm::BasicBlock *Block, |
| 395 | EHScopeStack::stable_iterator Depth, |
| 396 | unsigned Index) |
| 397 | : Block(Block), ScopeDepth(Depth), Index(Index) {} |
| 398 | |
| 399 | bool isValid() const { return Block != 0; } |
| 400 | llvm::BasicBlock *getBlock() const { return Block; } |
| 401 | EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; } |
| 402 | unsigned getDestIndex() const { return Index; } |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 403 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 404 | private: |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 405 | llvm::BasicBlock *Block; |
| 406 | EHScopeStack::stable_iterator ScopeDepth; |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 407 | unsigned Index; |
| 408 | }; |
| 409 | |
| 410 | /// An unwind destination is an abstract label, branching to which |
| 411 | /// may require a jump out through EH cleanups. |
| 412 | struct UnwindDest { |
| 413 | UnwindDest() : Block(0), ScopeDepth(), Index(0) {} |
| 414 | UnwindDest(llvm::BasicBlock *Block, |
| 415 | EHScopeStack::stable_iterator Depth, |
| 416 | unsigned Index) |
| 417 | : Block(Block), ScopeDepth(Depth), Index(Index) {} |
| 418 | |
| 419 | bool isValid() const { return Block != 0; } |
| 420 | llvm::BasicBlock *getBlock() const { return Block; } |
| 421 | EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; } |
| 422 | unsigned getDestIndex() const { return Index; } |
| 423 | |
| 424 | private: |
| 425 | llvm::BasicBlock *Block; |
| 426 | EHScopeStack::stable_iterator ScopeDepth; |
| 427 | unsigned Index; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 428 | }; |
| 429 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 430 | CodeGenModule &CGM; // Per-module state. |
Daniel Dunbar | 1b44419 | 2009-11-13 05:51:54 +0000 | [diff] [blame] | 431 | const TargetInfo &Target; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 432 | |
Chris Lattner | 96d7256 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 433 | typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; |
Daniel Dunbar | cb46385 | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 434 | CGBuilderTy Builder; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 435 | |
Chris Lattner | 28ec0cf | 2009-04-23 05:30:27 +0000 | [diff] [blame] | 436 | /// CurFuncDecl - Holds the Decl for the current function or ObjC method. |
| 437 | /// This excludes BlockDecls. |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 438 | const Decl *CurFuncDecl; |
Chris Lattner | 28ec0cf | 2009-04-23 05:30:27 +0000 | [diff] [blame] | 439 | /// CurCodeDecl - This is the inner-most code context, which includes blocks. |
| 440 | const Decl *CurCodeDecl; |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 441 | const CGFunctionInfo *CurFnInfo; |
Chris Lattner | 4bd5596 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 442 | QualType FnRetTy; |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 443 | llvm::Function *CurFn; |
| 444 | |
Mike Stump | bee78dd | 2009-12-04 23:26:17 +0000 | [diff] [blame] | 445 | /// CurGD - The GlobalDecl for the current function being compiled. |
| 446 | GlobalDecl CurGD; |
Mike Stump | bee78dd | 2009-12-04 23:26:17 +0000 | [diff] [blame] | 447 | |
Daniel Dunbar | 54bb193 | 2008-09-09 21:00:17 +0000 | [diff] [blame] | 448 | /// ReturnBlock - Unified return block. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 449 | JumpDest ReturnBlock; |
| 450 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 451 | /// ReturnValue - The temporary alloca to hold the return value. This is null |
| 452 | /// iff the function has no return value. |
Eli Friedman | 4b1942c | 2009-12-04 02:43:40 +0000 | [diff] [blame] | 453 | llvm::Value *ReturnValue; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 454 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 455 | /// RethrowBlock - Unified rethrow block. |
| 456 | UnwindDest RethrowBlock; |
| 457 | |
Chris Lattner | 03df122 | 2007-06-02 04:53:11 +0000 | [diff] [blame] | 458 | /// AllocaInsertPoint - This is an instruction in the entry block before which |
| 459 | /// we prefer to insert allocas. |
Chris Lattner | 2739d2b | 2009-03-31 22:17:44 +0000 | [diff] [blame] | 460 | llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 461 | |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 462 | // intptr_t, i32, i64 |
| 463 | const llvm::IntegerType *IntPtrTy, *Int32Ty, *Int64Ty; |
Hartmut Kaiser | 7078da8 | 2007-10-17 15:00:17 +0000 | [diff] [blame] | 464 | uint32_t LLVMPointerWidth; |
Daniel Dunbar | d3dcb4f8 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 465 | |
Mike Stump | aff69af | 2009-12-09 03:35:49 +0000 | [diff] [blame] | 466 | bool Exceptions; |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 467 | bool CatchUndefined; |
Douglas Gregor | 9154b5d | 2010-05-17 15:52:46 +0000 | [diff] [blame] | 468 | |
| 469 | /// \brief A mapping from NRVO variables to the flags used to indicate |
| 470 | /// when the NRVO has been applied to this variable. |
| 471 | llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 472 | |
| 473 | EHScopeStack EHStack; |
| 474 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 475 | /// i32s containing the indexes of the cleanup destinations. |
| 476 | llvm::AllocaInst *NormalCleanupDest; |
| 477 | llvm::AllocaInst *EHCleanupDest; |
| 478 | |
| 479 | unsigned NextCleanupDestIndex; |
| 480 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 481 | /// The exception slot. All landing pads write the current |
| 482 | /// exception pointer into this alloca. |
| 483 | llvm::Value *ExceptionSlot; |
| 484 | |
| 485 | /// Emits a landing pad for the current EH stack. |
| 486 | llvm::BasicBlock *EmitLandingPad(); |
| 487 | |
| 488 | llvm::BasicBlock *getInvokeDestImpl(); |
| 489 | |
Daniel Dunbar | d3dcb4f8 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 490 | public: |
Anders Carlsson | 33c1b65 | 2009-02-10 06:07:49 +0000 | [diff] [blame] | 491 | /// ObjCEHValueStack - Stack of Objective-C exception values, used for |
| 492 | /// rethrows. |
Anders Carlsson | bf8a1be | 2009-02-07 21:37:21 +0000 | [diff] [blame] | 493 | llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 494 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 495 | // A struct holding information about a finally block's IR |
| 496 | // generation. For now, doesn't actually hold anything. |
| 497 | struct FinallyInfo { |
Anders Carlsson | 66c384a | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 498 | }; |
| 499 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 500 | FinallyInfo EnterFinallyBlock(const Stmt *Stmt, |
| 501 | llvm::Constant *BeginCatchFn, |
| 502 | llvm::Constant *EndCatchFn, |
| 503 | llvm::Constant *RethrowFn); |
| 504 | void ExitFinallyBlock(FinallyInfo &FinallyInfo); |
Mike Stump | aff69af | 2009-12-09 03:35:49 +0000 | [diff] [blame] | 505 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 506 | /// PushDestructorCleanup - Push a cleanup to call the |
| 507 | /// complete-object destructor of an object of the given type at the |
| 508 | /// given address. Does nothing if T is not a C++ class type with a |
| 509 | /// non-trivial destructor. |
| 510 | void PushDestructorCleanup(QualType T, llvm::Value *Addr); |
| 511 | |
John McCall | 8680f87 | 2010-07-21 06:29:51 +0000 | [diff] [blame] | 512 | /// PushDestructorCleanup - Push a cleanup to call the |
| 513 | /// complete-object variant of the given destructor on the object at |
| 514 | /// the given address. |
| 515 | void PushDestructorCleanup(const CXXDestructorDecl *Dtor, |
| 516 | llvm::Value *Addr); |
| 517 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 518 | /// PopCleanupBlock - Will pop the cleanup entry on the stack and |
| 519 | /// process all branch fixups. |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 520 | void PopCleanupBlock(bool FallThroughIsBranchThrough = false); |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 521 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 522 | /// \brief Enters a new scope for capturing cleanups, all of which |
| 523 | /// will be executed once the scope is exited. |
| 524 | class RunCleanupsScope { |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 525 | CodeGenFunction& CGF; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 526 | EHScopeStack::stable_iterator CleanupStackDepth; |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 527 | bool OldDidCallStackSave; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 528 | bool PerformCleanup; |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 529 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 530 | RunCleanupsScope(const RunCleanupsScope &); // DO NOT IMPLEMENT |
| 531 | RunCleanupsScope &operator=(const RunCleanupsScope &); // DO NOT IMPLEMENT |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 532 | |
| 533 | public: |
| 534 | /// \brief Enter a new cleanup scope. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 535 | explicit RunCleanupsScope(CodeGenFunction &CGF) |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 536 | : CGF(CGF), PerformCleanup(true) |
| 537 | { |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 538 | CleanupStackDepth = CGF.EHStack.stable_begin(); |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 539 | OldDidCallStackSave = CGF.DidCallStackSave; |
| 540 | } |
| 541 | |
| 542 | /// \brief Exit this cleanup scope, emitting any accumulated |
| 543 | /// cleanups. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 544 | ~RunCleanupsScope() { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 545 | if (PerformCleanup) { |
| 546 | CGF.DidCallStackSave = OldDidCallStackSave; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 547 | CGF.PopCleanupBlocks(CleanupStackDepth); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
| 551 | /// \brief Determine whether this scope requires any cleanups. |
| 552 | bool requiresCleanups() const { |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 553 | return CGF.EHStack.stable_begin() != CleanupStackDepth; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /// \brief Force the emission of cleanups now, instead of waiting |
| 557 | /// until this object is destroyed. |
| 558 | void ForceCleanup() { |
| 559 | assert(PerformCleanup && "Already forced cleanup"); |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 560 | CGF.DidCallStackSave = OldDidCallStackSave; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 561 | CGF.PopCleanupBlocks(CleanupStackDepth); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 562 | PerformCleanup = false; |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 563 | } |
| 564 | }; |
| 565 | |
Anders Carlsson | b9fd57f | 2010-03-30 03:14:41 +0000 | [diff] [blame] | 566 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 567 | /// PopCleanupBlocks - Takes the old cleanup stack size and emits |
| 568 | /// the cleanup blocks that have been added. |
| 569 | void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize); |
Anders Carlsson | b9fd57f | 2010-03-30 03:14:41 +0000 | [diff] [blame] | 570 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 571 | void ResolveAllBranchFixups(llvm::SwitchInst *Switch); |
| 572 | void ResolveBranchFixups(llvm::BasicBlock *Target); |
| 573 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 574 | /// The given basic block lies in the current EH scope, but may be a |
| 575 | /// target of a potentially scope-crossing jump; get a stable handle |
| 576 | /// to which we can perform this jump later. |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 577 | JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) { |
John McCall | ba80390 | 2010-07-28 01:07:35 +0000 | [diff] [blame] | 578 | return JumpDest(Target, |
| 579 | EHStack.getInnermostNormalCleanup(), |
| 580 | NextCleanupDestIndex++); |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 581 | } |
Anders Carlsson | be0f76a | 2009-02-07 23:50:39 +0000 | [diff] [blame] | 582 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 583 | /// The given basic block lies in the current EH scope, but may be a |
| 584 | /// target of a potentially scope-crossing jump; get a stable handle |
| 585 | /// to which we can perform this jump later. |
| 586 | JumpDest getJumpDestInCurrentScope(const char *Name = 0) { |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 587 | return getJumpDestInCurrentScope(createBasicBlock(Name)); |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /// EmitBranchThroughCleanup - Emit a branch from the current insert |
| 591 | /// block through the normal cleanup handling code (if any) and then |
| 592 | /// on to \arg Dest. |
| 593 | void EmitBranchThroughCleanup(JumpDest Dest); |
| 594 | |
| 595 | /// EmitBranchThroughEHCleanup - Emit a branch from the current |
| 596 | /// insert block through the EH cleanup handling code (if any) and |
| 597 | /// then on to \arg Dest. |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 598 | void EmitBranchThroughEHCleanup(UnwindDest Dest); |
| 599 | |
| 600 | /// getRethrowDest - Returns the unified outermost-scope rethrow |
| 601 | /// destination. |
| 602 | UnwindDest getRethrowDest(); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 603 | |
Anders Carlsson | ae612d2 | 2010-02-04 17:18:07 +0000 | [diff] [blame] | 604 | /// BeginConditionalBranch - Should be called before a conditional part of an |
Anders Carlsson | 0a66c26 | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 605 | /// expression is emitted. For example, before the RHS of the expression below |
| 606 | /// is emitted: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 607 | /// |
Anders Carlsson | 44bfcf0 | 2009-06-04 02:22:12 +0000 | [diff] [blame] | 608 | /// b && f(T()); |
| 609 | /// |
Anders Carlsson | 0a66c26 | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 610 | /// This is used to make sure that any temporaries created in the conditional |
Anders Carlsson | 44bfcf0 | 2009-06-04 02:22:12 +0000 | [diff] [blame] | 611 | /// branch are only destroyed if the branch is taken. |
Anders Carlsson | ae612d2 | 2010-02-04 17:18:07 +0000 | [diff] [blame] | 612 | void BeginConditionalBranch() { |
Anders Carlsson | 0a66c26 | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 613 | ++ConditionalBranchLevel; |
| 614 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 615 | |
Anders Carlsson | ae612d2 | 2010-02-04 17:18:07 +0000 | [diff] [blame] | 616 | /// EndConditionalBranch - Should be called after a conditional part of an |
Anders Carlsson | 0a66c26 | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 617 | /// expression has been emitted. |
Anders Carlsson | ae612d2 | 2010-02-04 17:18:07 +0000 | [diff] [blame] | 618 | void EndConditionalBranch() { |
Anders Carlsson | 60ddba6 | 2010-01-24 00:20:05 +0000 | [diff] [blame] | 619 | assert(ConditionalBranchLevel != 0 && |
| 620 | "Conditional branch mismatch!"); |
| 621 | |
Anders Carlsson | 0a66c26 | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 622 | --ConditionalBranchLevel; |
| 623 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 624 | |
Chris Lattner | 2da04b3 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 625 | private: |
Chris Lattner | 6c4d255 | 2009-10-28 23:59:40 +0000 | [diff] [blame] | 626 | CGDebugInfo *DebugInfo; |
Mike Stump | c6ea7c1 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 627 | |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 628 | /// IndirectBranch - The first time an indirect goto is seen we create a block |
| 629 | /// with an indirect branch. Every time we see the address of a label taken, |
| 630 | /// we add the label to the indirect goto. Every subsequent indirect goto is |
| 631 | /// codegen'd as a jump to the IndirectBranch's basic block. |
Chris Lattner | 6c4d255 | 2009-10-28 23:59:40 +0000 | [diff] [blame] | 632 | llvm::IndirectBrInst *IndirectBranch; |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 633 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 634 | /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C |
| 635 | /// decls. |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 636 | llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; |
Chris Lattner | 84915fa | 2007-06-02 04:16:21 +0000 | [diff] [blame] | 637 | |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 638 | /// LabelMap - This keeps track of the LLVM basic block for each C label. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 639 | llvm::DenseMap<const LabelStmt*, JumpDest> LabelMap; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 640 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 641 | // BreakContinueStack - This keeps track of where break and continue |
Anders Carlsson | 33747b6 | 2009-02-10 05:52:02 +0000 | [diff] [blame] | 642 | // statements should jump to. |
Chris Lattner | e73e432 | 2007-07-16 21:28:45 +0000 | [diff] [blame] | 643 | struct BreakContinue { |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 644 | BreakContinue(JumpDest Break, JumpDest Continue) |
| 645 | : BreakBlock(Break), ContinueBlock(Continue) {} |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 646 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 647 | JumpDest BreakBlock; |
| 648 | JumpDest ContinueBlock; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 649 | }; |
Chris Lattner | e73e432 | 2007-07-16 21:28:45 +0000 | [diff] [blame] | 650 | llvm::SmallVector<BreakContinue, 8> BreakContinueStack; |
Daniel Dunbar | d3dcb4f8 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 651 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 652 | /// SwitchInsn - This is nearest current switch instruction. It is null if if |
| 653 | /// current context is not in a switch. |
Devang Patel | da5d6bb | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 654 | llvm::SwitchInst *SwitchInsn; |
| 655 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 656 | /// CaseRangeBlock - This block holds if condition check for last case |
Devang Patel | 49a44f3 | 2007-10-09 17:08:50 +0000 | [diff] [blame] | 657 | /// statement range in current switch instruction. |
Devang Patel | 1166312 | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 658 | llvm::BasicBlock *CaseRangeBlock; |
| 659 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 660 | // VLASizeMap - This keeps track of the associated size for each VLA type. |
Eli Friedman | 04fddf0 | 2009-08-15 02:50:32 +0000 | [diff] [blame] | 661 | // We track this by the size expression rather than the type itself because |
| 662 | // in certain situations, like a const qualifier applied to an VLA typedef, |
| 663 | // multiple VLA types can share the same size expression. |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 664 | // FIXME: Maybe this could be a stack of maps that is pushed/popped as we |
| 665 | // enter/leave scopes. |
Eli Friedman | 04fddf0 | 2009-08-15 02:50:32 +0000 | [diff] [blame] | 666 | llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 667 | |
Anders Carlsson | f4478e9 | 2009-02-09 20:20:56 +0000 | [diff] [blame] | 668 | /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid |
| 669 | /// calling llvm.stacksave for multiple VLAs in the same scope. |
| 670 | bool DidCallStackSave; |
Mike Stump | c6ea7c1 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 671 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 672 | /// A block containing a single 'unreachable' instruction. Created |
| 673 | /// lazily by getUnreachableBlock(). |
| 674 | llvm::BasicBlock *UnreachableBlock; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 675 | |
Anders Carlsson | 82ba57c | 2009-11-25 03:15:49 +0000 | [diff] [blame] | 676 | /// CXXThisDecl - When generating code for a C++ member function, |
| 677 | /// this will hold the implicit 'this' declaration. |
Anders Carlsson | 468fa63 | 2009-04-04 20:47:02 +0000 | [diff] [blame] | 678 | ImplicitParamDecl *CXXThisDecl; |
John McCall | 347132b | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 679 | llvm::Value *CXXThisValue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 680 | |
Anders Carlsson | 82ba57c | 2009-11-25 03:15:49 +0000 | [diff] [blame] | 681 | /// CXXVTTDecl - When generating code for a base object constructor or |
| 682 | /// base object destructor with virtual bases, this will hold the implicit |
| 683 | /// VTT parameter. |
| 684 | ImplicitParamDecl *CXXVTTDecl; |
John McCall | 347132b | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 685 | llvm::Value *CXXVTTValue; |
Anders Carlsson | 82ba57c | 2009-11-25 03:15:49 +0000 | [diff] [blame] | 686 | |
Anders Carlsson | 0a66c26 | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 687 | /// ConditionalBranchLevel - Contains the nesting level of the current |
| 688 | /// conditional branch. This is used so that we know if a temporary should be |
| 689 | /// destroyed conditionally. |
| 690 | unsigned ConditionalBranchLevel; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 691 | |
Anders Carlsson | 0168f4b | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 692 | |
| 693 | /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM |
| 694 | /// type as well as the field number that contains the actual data. |
| 695 | llvm::DenseMap<const ValueDecl *, std::pair<const llvm::Type *, |
| 696 | unsigned> > ByRefValueInfo; |
| 697 | |
| 698 | /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field |
| 699 | /// number that holds the value. |
| 700 | unsigned getByRefValueLLVMField(const ValueDecl *VD) const; |
Mike Stump | f5cbb08 | 2009-12-10 00:02:42 +0000 | [diff] [blame] | 701 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 702 | llvm::BasicBlock *TerminateLandingPad; |
Mike Stump | f5cbb08 | 2009-12-10 00:02:42 +0000 | [diff] [blame] | 703 | llvm::BasicBlock *TerminateHandler; |
Chris Lattner | f2f3870 | 2010-07-20 21:07:09 +0000 | [diff] [blame] | 704 | llvm::BasicBlock *TrapBB; |
Eli Friedman | d5bc94e | 2009-12-10 02:21:21 +0000 | [diff] [blame] | 705 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 706 | public: |
Chris Lattner | d1af2d2 | 2007-05-29 23:17:50 +0000 | [diff] [blame] | 707 | CodeGenFunction(CodeGenModule &cgm); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 708 | |
Chris Lattner | 6db1fb8 | 2007-06-02 22:49:07 +0000 | [diff] [blame] | 709 | ASTContext &getContext() const; |
Anders Carlsson | 63784f4 | 2009-02-13 08:11:52 +0000 | [diff] [blame] | 710 | CGDebugInfo *getDebugInfo() { return DebugInfo; } |
Chris Lattner | 6db1fb8 | 2007-06-02 22:49:07 +0000 | [diff] [blame] | 711 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 712 | /// Returns a pointer to the function's exception object slot, which |
| 713 | /// is assigned in every landing pad. |
| 714 | llvm::Value *getExceptionSlot(); |
| 715 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 716 | llvm::Value *getNormalCleanupDestSlot(); |
| 717 | llvm::Value *getEHCleanupDestSlot(); |
| 718 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 719 | llvm::BasicBlock *getUnreachableBlock() { |
| 720 | if (!UnreachableBlock) { |
| 721 | UnreachableBlock = createBasicBlock("unreachable"); |
| 722 | new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock); |
| 723 | } |
| 724 | return UnreachableBlock; |
| 725 | } |
| 726 | |
| 727 | llvm::BasicBlock *getInvokeDest() { |
| 728 | if (!EHStack.requiresLandingPad()) return 0; |
| 729 | return getInvokeDestImpl(); |
| 730 | } |
Daniel Dunbar | 1234749 | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 731 | |
Owen Anderson | 170229f | 2009-07-14 23:10:40 +0000 | [diff] [blame] | 732 | llvm::LLVMContext &getLLVMContext() { return VMContext; } |
Owen Anderson | ae86c19 | 2009-07-13 04:10:07 +0000 | [diff] [blame] | 733 | |
Daniel Dunbar | 1234749 | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 734 | //===--------------------------------------------------------------------===// |
| 735 | // Objective-C |
| 736 | //===--------------------------------------------------------------------===// |
| 737 | |
Chris Lattner | 4bd5596 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 738 | void GenerateObjCMethod(const ObjCMethodDecl *OMD); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 739 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 740 | void StartObjCMethod(const ObjCMethodDecl *MD, |
Fariborz Jahanian | 0196a1c | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 741 | const ObjCContainerDecl *CD); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 742 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 743 | /// GenerateObjCGetter - Synthesize an Objective-C property getter function. |
Fariborz Jahanian | 3d8552a | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 744 | void GenerateObjCGetter(ObjCImplementationDecl *IMP, |
| 745 | const ObjCPropertyImplDecl *PID); |
Fariborz Jahanian | 0dec1e0 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 746 | void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, |
| 747 | ObjCMethodDecl *MD, bool ctor); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 748 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 749 | /// GenerateObjCSetter - Synthesize an Objective-C property setter function |
| 750 | /// for the given property. |
Fariborz Jahanian | 3d8552a | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 751 | void GenerateObjCSetter(ObjCImplementationDecl *IMP, |
| 752 | const ObjCPropertyImplDecl *PID); |
Fariborz Jahanian | 08b0f66 | 2010-04-13 00:38:05 +0000 | [diff] [blame] | 753 | bool IndirectObjCSetterArg(const CGFunctionInfo &FI); |
Fariborz Jahanian | 7e9d52a | 2010-04-13 18:32:24 +0000 | [diff] [blame] | 754 | bool IvarTypeWithAggrGCObjects(QualType Ty); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 755 | |
Mike Stump | cb2fbcb | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 756 | //===--------------------------------------------------------------------===// |
| 757 | // Block Bits |
| 758 | //===--------------------------------------------------------------------===// |
| 759 | |
Mike Stump | b750d92 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 760 | llvm::Value *BuildBlockLiteralTmp(const BlockExpr *); |
Blaine Garst | fc83aa0 | 2010-02-23 21:51:17 +0000 | [diff] [blame] | 761 | llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *, |
Fariborz Jahanian | c05349e | 2010-08-04 16:57:49 +0000 | [diff] [blame] | 762 | const CGBlockInfo &Info, |
Mike Stump | aeb0ffd | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 763 | const llvm::StructType *, |
Fariborz Jahanian | afa3c0a | 2010-08-04 18:44:59 +0000 | [diff] [blame] | 764 | llvm::Constant *BlockVarLayout, |
Mike Stump | aeb0ffd | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 765 | std::vector<HelperInfo> *); |
Mike Stump | cb2fbcb | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 766 | |
Fariborz Jahanian | 9b5528d | 2010-06-24 00:08:06 +0000 | [diff] [blame] | 767 | llvm::Function *GenerateBlockFunction(GlobalDecl GD, |
| 768 | const BlockExpr *BExpr, |
John McCall | 9d42f0f | 2010-05-21 04:11:14 +0000 | [diff] [blame] | 769 | CGBlockInfo &Info, |
Mike Stump | 692c6e3 | 2009-03-20 21:53:12 +0000 | [diff] [blame] | 770 | const Decl *OuterFuncDecl, |
Fariborz Jahanian | afa3c0a | 2010-08-04 18:44:59 +0000 | [diff] [blame] | 771 | llvm::Constant *& BlockVarLayout, |
John McCall | 9d42f0f | 2010-05-21 04:11:14 +0000 | [diff] [blame] | 772 | llvm::DenseMap<const Decl*, llvm::Value*> ldm); |
Mike Stump | cb2fbcb | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 773 | |
| 774 | llvm::Value *LoadBlockStruct(); |
| 775 | |
John McCall | 87fe5d5 | 2010-05-20 01:18:31 +0000 | [diff] [blame] | 776 | void AllocateBlockCXXThisPointer(const CXXThisExpr *E); |
| 777 | void AllocateBlockDecl(const BlockDeclRefExpr *E); |
John McCall | 9d42f0f | 2010-05-21 04:11:14 +0000 | [diff] [blame] | 778 | llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E) { |
| 779 | return GetAddrOfBlockDecl(E->getDecl(), E->isByRef()); |
| 780 | } |
| 781 | llvm::Value *GetAddrOfBlockDecl(const ValueDecl *D, bool ByRef); |
Anders Carlsson | 71d1d92 | 2009-09-09 02:51:03 +0000 | [diff] [blame] | 782 | const llvm::Type *BuildByRefType(const ValueDecl *D); |
Mike Stump | 97d01d5 | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 783 | |
Anders Carlsson | 73fcc95 | 2009-09-11 00:07:24 +0000 | [diff] [blame] | 784 | void GenerateCode(GlobalDecl GD, llvm::Function *Fn); |
| 785 | void StartFunction(GlobalDecl GD, QualType RetTy, |
Daniel Dunbar | bc915f4 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 786 | llvm::Function *Fn, |
Daniel Dunbar | 354d278 | 2008-10-18 18:22:23 +0000 | [diff] [blame] | 787 | const FunctionArgList &Args, |
| 788 | SourceLocation StartLoc); |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 789 | |
John McCall | b81884d | 2010-02-19 09:25:03 +0000 | [diff] [blame] | 790 | void EmitConstructorBody(FunctionArgList &Args); |
| 791 | void EmitDestructorBody(FunctionArgList &Args); |
| 792 | void EmitFunctionBody(FunctionArgList &Args); |
John McCall | 89b12b3 | 2010-02-18 03:17:58 +0000 | [diff] [blame] | 793 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 794 | /// EmitReturnBlock - Emit the unified return block, trying to avoid its |
| 795 | /// emission when possible. |
Daniel Dunbar | fd346a3 | 2009-01-26 23:27:52 +0000 | [diff] [blame] | 796 | void EmitReturnBlock(); |
| 797 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 798 | /// FinishFunction - Complete IR generation of the current function. It is |
| 799 | /// legal to call this function even if there is no current insertion point. |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 800 | void FinishFunction(SourceLocation EndLoc=SourceLocation()); |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 801 | |
Anders Carlsson | bad991d | 2010-03-24 00:39:18 +0000 | [diff] [blame] | 802 | /// GenerateThunk - Generate a thunk for the given method. |
| 803 | void GenerateThunk(llvm::Function *Fn, GlobalDecl GD, const ThunkInfo &Thunk); |
| 804 | |
Douglas Gregor | 94f9a48 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 805 | void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, |
| 806 | FunctionArgList &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 807 | |
Anders Carlsson | e87fae9 | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 808 | /// InitializeVTablePointer - Initialize the vtable pointer of the given |
| 809 | /// subobject. |
| 810 | /// |
Anders Carlsson | 652758c | 2010-04-20 05:22:15 +0000 | [diff] [blame] | 811 | void InitializeVTablePointer(BaseSubobject Base, |
| 812 | const CXXRecordDecl *NearestVBase, |
Anders Carlsson | c4d0d0f | 2010-05-03 00:07:07 +0000 | [diff] [blame] | 813 | uint64_t OffsetFromNearestVBase, |
Anders Carlsson | e87fae9 | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 814 | llvm::Constant *VTable, |
| 815 | const CXXRecordDecl *VTableClass); |
| 816 | |
| 817 | typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy; |
Anders Carlsson | 652758c | 2010-04-20 05:22:15 +0000 | [diff] [blame] | 818 | void InitializeVTablePointers(BaseSubobject Base, |
| 819 | const CXXRecordDecl *NearestVBase, |
Anders Carlsson | c4d0d0f | 2010-05-03 00:07:07 +0000 | [diff] [blame] | 820 | uint64_t OffsetFromNearestVBase, |
Anders Carlsson | d589593 | 2010-03-28 21:07:49 +0000 | [diff] [blame] | 821 | bool BaseIsNonVirtualPrimaryBase, |
| 822 | llvm::Constant *VTable, |
| 823 | const CXXRecordDecl *VTableClass, |
| 824 | VisitedVirtualBasesSetTy& VBases); |
Eli Friedman | bb5008a | 2009-12-08 06:46:18 +0000 | [diff] [blame] | 825 | |
Anders Carlsson | d589593 | 2010-03-28 21:07:49 +0000 | [diff] [blame] | 826 | void InitializeVTablePointers(const CXXRecordDecl *ClassDecl); |
Anders Carlsson | e87fae9 | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 827 | |
| 828 | |
John McCall | f99a631 | 2010-07-21 05:30:47 +0000 | [diff] [blame] | 829 | /// EnterDtorCleanups - Enter the cleanups necessary to complete the |
| 830 | /// given phase of destruction for a destructor. The end result |
| 831 | /// should call destructors on members and base classes in reverse |
| 832 | /// order of their construction. |
| 833 | void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 834 | |
Chris Lattner | 3c77a35 | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 835 | /// ShouldInstrumentFunction - Return true if the current function should be |
| 836 | /// instrumented with __cyg_profile_func_* calls |
| 837 | bool ShouldInstrumentFunction(); |
| 838 | |
| 839 | /// EmitFunctionInstrumentation - Emit LLVM code to call the specified |
| 840 | /// instrumentation function with the current function and the call site, if |
| 841 | /// function instrumentation is enabled. |
| 842 | void EmitFunctionInstrumentation(const char *Fn); |
| 843 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 844 | /// EmitFunctionProlog - Emit the target specific LLVM code to load the |
| 845 | /// arguments for the given function. This is also responsible for naming the |
| 846 | /// LLVM function arguments. |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 847 | void EmitFunctionProlog(const CGFunctionInfo &FI, |
| 848 | llvm::Function *Fn, |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 849 | const FunctionArgList &Args); |
| 850 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 851 | /// EmitFunctionEpilog - Emit the target specific LLVM code to return the |
| 852 | /// given temporary. |
Chris Lattner | 3fcc790 | 2010-06-27 01:06:27 +0000 | [diff] [blame] | 853 | void EmitFunctionEpilog(const CGFunctionInfo &FI); |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 854 | |
Mike Stump | 1d84921 | 2009-12-07 23:38:24 +0000 | [diff] [blame] | 855 | /// EmitStartEHSpec - Emit the start of the exception spec. |
| 856 | void EmitStartEHSpec(const Decl *D); |
| 857 | |
| 858 | /// EmitEndEHSpec - Emit the end of the exception spec. |
| 859 | void EmitEndEHSpec(const Decl *D); |
| 860 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 861 | /// getTerminateLandingPad - Return a landing pad that just calls terminate. |
| 862 | llvm::BasicBlock *getTerminateLandingPad(); |
| 863 | |
| 864 | /// getTerminateHandler - Return a handler (not a landing pad, just |
| 865 | /// a catch handler) that just calls terminate. This is used when |
| 866 | /// a terminate scope encloses a try. |
Mike Stump | 2b48887 | 2009-12-09 22:59:31 +0000 | [diff] [blame] | 867 | llvm::BasicBlock *getTerminateHandler(); |
| 868 | |
Daniel Dunbar | ee3da87 | 2009-02-03 23:03:55 +0000 | [diff] [blame] | 869 | const llvm::Type *ConvertTypeForMem(QualType T); |
Chris Lattner | f033c14 | 2007-06-22 19:05:19 +0000 | [diff] [blame] | 870 | const llvm::Type *ConvertType(QualType T); |
John McCall | 6ce7472 | 2010-02-16 04:15:37 +0000 | [diff] [blame] | 871 | const llvm::Type *ConvertType(const TypeDecl *T) { |
| 872 | return ConvertType(getContext().getTypeDeclType(T)); |
| 873 | } |
Chris Lattner | 5506f8c | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 874 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 875 | /// LoadObjCSelf - Load the value of self. This function is only valid while |
| 876 | /// generating code for an Objective-C method. |
Chris Lattner | 5506f8c | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 877 | llvm::Value *LoadObjCSelf(); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 878 | |
| 879 | /// TypeOfSelfObject - Return type of object that this self represents. |
Fariborz Jahanian | c88a70d | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 880 | QualType TypeOfSelfObject(); |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 881 | |
Chris Lattner | 54fb19e | 2007-06-22 22:02:34 +0000 | [diff] [blame] | 882 | /// hasAggregateLLVMType - Return true if the specified AST type will map into |
| 883 | /// an aggregate LLVM type or is void. |
| 884 | static bool hasAggregateLLVMType(QualType T); |
Daniel Dunbar | 75283ff | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 885 | |
| 886 | /// createBasicBlock - Create an LLVM basic block. |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 887 | llvm::BasicBlock *createBasicBlock(const char *Name="", |
Daniel Dunbar | 75283ff | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 888 | llvm::Function *Parent=0, |
| 889 | llvm::BasicBlock *InsertBefore=0) { |
Daniel Dunbar | 851eec1 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 890 | #ifdef NDEBUG |
Owen Anderson | 41a7502 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 891 | return llvm::BasicBlock::Create(VMContext, "", Parent, InsertBefore); |
Daniel Dunbar | 851eec1 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 892 | #else |
Owen Anderson | 41a7502 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 893 | return llvm::BasicBlock::Create(VMContext, Name, Parent, InsertBefore); |
Daniel Dunbar | 851eec1 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 894 | #endif |
Daniel Dunbar | 75283ff | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 895 | } |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 896 | |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 897 | /// getBasicBlockForLabel - Return the LLVM basicblock that the specified |
| 898 | /// label maps to. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 899 | JumpDest getJumpDestForLabel(const LabelStmt *S); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 900 | |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 901 | /// SimplifyForwardingBlocks - If the given basic block is only a branch to |
| 902 | /// another basic block, simplify it. This assumes that no other code could |
| 903 | /// potentially reference the basic block. |
Daniel Dunbar | f77e292 | 2009-04-01 04:37:47 +0000 | [diff] [blame] | 904 | void SimplifyForwardingBlocks(llvm::BasicBlock *BB); |
| 905 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 906 | /// EmitBlock - Emit the given block \arg BB and set it as the insert point, |
| 907 | /// adding a fall-through branch from the current insert block if |
| 908 | /// necessary. It is legal to call this function even if there is no current |
| 909 | /// insertion point. |
Daniel Dunbar | fcac22e | 2008-11-13 01:24:05 +0000 | [diff] [blame] | 910 | /// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 911 | /// IsFinished - If true, indicates that the caller has finished emitting |
| 912 | /// branches to the given block and does not expect to emit code into it. This |
| 913 | /// means the block can be ignored if it is unreachable. |
Daniel Dunbar | fcac22e | 2008-11-13 01:24:05 +0000 | [diff] [blame] | 914 | void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); |
Daniel Dunbar | 29ac59f | 2008-11-11 04:34:23 +0000 | [diff] [blame] | 915 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 916 | /// EmitBranch - Emit a branch to the specified basic block from the current |
| 917 | /// insert block, taking care to avoid creation of branches from dummy |
| 918 | /// blocks. It is legal to call this function even if there is no current |
| 919 | /// insertion point. |
Daniel Dunbar | ab197eb | 2008-11-11 22:06:59 +0000 | [diff] [blame] | 920 | /// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 921 | /// This function clears the current insertion point. The caller should follow |
| 922 | /// calls to this function with calls to Emit*Block prior to generation new |
| 923 | /// code. |
Daniel Dunbar | c56e676 | 2008-11-11 09:41:28 +0000 | [diff] [blame] | 924 | void EmitBranch(llvm::BasicBlock *Block); |
| 925 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 926 | /// HaveInsertPoint - True if an insertion point is defined. If not, this |
| 927 | /// indicates that the current code being emitted is unreachable. |
| 928 | bool HaveInsertPoint() const { |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 929 | return Builder.GetInsertBlock() != 0; |
| 930 | } |
| 931 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 932 | /// EnsureInsertPoint - Ensure that an insertion point is defined so that |
| 933 | /// emitted IR has a place to go. Note that by definition, if this function |
| 934 | /// creates a block then that block is unreachable; callers may do better to |
| 935 | /// detect when no insertion point is defined and simply skip IR generation. |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 936 | void EnsureInsertPoint() { |
| 937 | if (!HaveInsertPoint()) |
| 938 | EmitBlock(createBasicBlock()); |
| 939 | } |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 940 | |
Daniel Dunbar | a7c8cf6 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 941 | /// ErrorUnsupported - Print out an error that codegen doesn't support the |
Chris Lattner | fc94434 | 2007-12-02 01:43:38 +0000 | [diff] [blame] | 942 | /// specified stmt yet. |
Daniel Dunbar | f2cf6d1 | 2008-09-04 03:43:08 +0000 | [diff] [blame] | 943 | void ErrorUnsupported(const Stmt *S, const char *Type, |
| 944 | bool OmitOnError=false); |
Chris Lattner | 84915fa | 2007-06-02 04:16:21 +0000 | [diff] [blame] | 945 | |
Chris Lattner | e9a6453 | 2007-06-22 21:44:33 +0000 | [diff] [blame] | 946 | //===--------------------------------------------------------------------===// |
| 947 | // Helpers |
| 948 | //===--------------------------------------------------------------------===// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 949 | |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 950 | Qualifiers MakeQualifiers(QualType T) { |
Mike Stump | 53f9ded | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 951 | Qualifiers Quals = getContext().getCanonicalType(T).getQualifiers(); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 952 | Quals.setObjCGCAttr(getContext().getObjCGCAttrKind(T)); |
| 953 | return Quals; |
| 954 | } |
| 955 | |
Chris Lattner | e9a6453 | 2007-06-22 21:44:33 +0000 | [diff] [blame] | 956 | /// CreateTempAlloca - This creates a alloca and inserts it into the entry |
Daniel Dunbar | a7566f1 | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 957 | /// block. The caller is responsible for setting an appropriate alignment on |
| 958 | /// the alloca. |
Chris Lattner | e9a6453 | 2007-06-22 21:44:33 +0000 | [diff] [blame] | 959 | llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, |
Daniel Dunbar | b5aacc2 | 2009-10-19 01:21:05 +0000 | [diff] [blame] | 960 | const llvm::Twine &Name = "tmp"); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 961 | |
John McCall | 2e6567a | 2010-04-22 01:10:34 +0000 | [diff] [blame] | 962 | /// InitTempAlloca - Provide an initial value for the given alloca. |
| 963 | void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value); |
| 964 | |
Daniel Dunbar | d004918 | 2010-02-16 19:44:13 +0000 | [diff] [blame] | 965 | /// CreateIRTemp - Create a temporary IR object of the given type, with |
| 966 | /// appropriate alignment. This routine should only be used when an temporary |
| 967 | /// value needs to be stored into an alloca (for example, to avoid explicit |
| 968 | /// PHI construction), but the type is the IR type, not the type appropriate |
| 969 | /// for storing in memory. |
Chris Lattner | c401de9 | 2010-07-05 20:21:00 +0000 | [diff] [blame] | 970 | llvm::AllocaInst *CreateIRTemp(QualType T, const llvm::Twine &Name = "tmp"); |
Daniel Dunbar | d004918 | 2010-02-16 19:44:13 +0000 | [diff] [blame] | 971 | |
Daniel Dunbar | a7566f1 | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 972 | /// CreateMemTemp - Create a temporary memory object of the given type, with |
| 973 | /// appropriate alignment. |
Chris Lattner | c401de9 | 2010-07-05 20:21:00 +0000 | [diff] [blame] | 974 | llvm::AllocaInst *CreateMemTemp(QualType T, const llvm::Twine &Name = "tmp"); |
Daniel Dunbar | a7566f1 | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 975 | |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 976 | /// EvaluateExprAsBool - Perform the usual unary conversions on the specified |
| 977 | /// expression and compare the result against zero, returning an Int1Ty value. |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 978 | llvm::Value *EvaluateExprAsBool(const Expr *E); |
Chris Lattner | e9a6453 | 2007-06-22 21:44:33 +0000 | [diff] [blame] | 979 | |
Chris Lattner | 4647a21 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 980 | /// EmitAnyExpr - Emit code to compute the specified expression which can have |
| 981 | /// any type. The result is returned as an RValue struct. If this is an |
| 982 | /// aggregate expression, the aggloc/agglocvolatile arguments indicate where |
| 983 | /// the result should be returned. |
Mike Stump | ec3cbfe | 2009-05-26 22:03:21 +0000 | [diff] [blame] | 984 | /// |
| 985 | /// \param IgnoreResult - True if the resulting value isn't used. |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 986 | RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, |
Anders Carlsson | 5b106a7 | 2009-08-16 07:36:22 +0000 | [diff] [blame] | 987 | bool IsAggLocVolatile = false, bool IgnoreResult = false, |
| 988 | bool IsInitializer = false); |
Devang Patel | 8ec4f83 | 2007-09-28 21:49:18 +0000 | [diff] [blame] | 989 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 990 | // EmitVAListRef - Emit a "reference" to a va_list; this is either the address |
| 991 | // or the value of the expression, depending on how va_list is defined. |
Eli Friedman | ddea0ad | 2009-01-20 17:46:04 +0000 | [diff] [blame] | 992 | llvm::Value *EmitVAListRef(const Expr *E); |
| 993 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 994 | /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will |
| 995 | /// always be accessible even if no aggregate location is provided. |
Anders Carlsson | 5b106a7 | 2009-08-16 07:36:22 +0000 | [diff] [blame] | 996 | RValue EmitAnyExprToTemp(const Expr *E, bool IsAggLocVolatile = false, |
| 997 | bool IsInitializer = false); |
Daniel Dunbar | 41cf9de | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 998 | |
John McCall | 2188696 | 2010-04-21 10:05:39 +0000 | [diff] [blame] | 999 | /// EmitsAnyExprToMem - Emits the code necessary to evaluate an |
| 1000 | /// arbitrary expression into the given memory location. |
| 1001 | void EmitAnyExprToMem(const Expr *E, llvm::Value *Location, |
| 1002 | bool IsLocationVolatile = false, |
| 1003 | bool IsInitializer = false); |
| 1004 | |
Mike Stump | 5e9e61b | 2009-05-23 22:29:41 +0000 | [diff] [blame] | 1005 | /// EmitAggregateCopy - Emit an aggrate copy. |
| 1006 | /// |
| 1007 | /// \param isVolatile - True iff either the source or the destination is |
| 1008 | /// volatile. |
Daniel Dunbar | 0bc8e86 | 2008-09-09 20:49:46 +0000 | [diff] [blame] | 1009 | void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, |
Mike Stump | 5e9e61b | 2009-05-23 22:29:41 +0000 | [diff] [blame] | 1010 | QualType EltTy, bool isVolatile=false); |
Daniel Dunbar | 0bc8e86 | 2008-09-09 20:49:46 +0000 | [diff] [blame] | 1011 | |
Devang Patel | da5d6bb | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 1012 | /// StartBlock - Start new block named N. If insert block is a dummy block |
| 1013 | /// then reuse it. |
| 1014 | void StartBlock(const char *N); |
| 1015 | |
Lauro Ramos Venancio | 01a72ff | 2008-02-26 21:41:45 +0000 | [diff] [blame] | 1016 | /// GetAddrOfStaticLocalVar - Return the address of a static local variable. |
Steve Naroff | 08899ff | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 1017 | llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD); |
Dan Gohman | 75d69da | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 1018 | |
Anders Carlsson | 9396a89 | 2008-09-11 09:15:33 +0000 | [diff] [blame] | 1019 | /// GetAddrOfLocalVar - Return the address of a local variable. |
| 1020 | llvm::Value *GetAddrOfLocalVar(const VarDecl *VD); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1021 | |
Dan Gohman | 75d69da | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 1022 | /// getAccessedFieldNo - Given an encoded value and a result number, return |
| 1023 | /// the input field number being accessed. |
| 1024 | static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); |
| 1025 | |
Chris Lattner | 6c4d255 | 2009-10-28 23:59:40 +0000 | [diff] [blame] | 1026 | llvm::BlockAddress *GetAddrOfLabel(const LabelStmt *L); |
Chris Lattner | 2bb5cb4 | 2009-10-13 06:55:33 +0000 | [diff] [blame] | 1027 | llvm::BasicBlock *GetIndirectGotoBlock(); |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 1028 | |
Anders Carlsson | c0964b6 | 2010-05-22 17:35:42 +0000 | [diff] [blame] | 1029 | /// EmitNullInitialization - Generate code to set a value of the given type to |
| 1030 | /// null, If the type contains data member pointers, they will be initialized |
| 1031 | /// to -1 in accordance with the Itanium C++ ABI. |
| 1032 | void EmitNullInitialization(llvm::Value *DestPtr, QualType Ty); |
Anders Carlsson | 13abd7e | 2008-11-04 05:30:00 +0000 | [diff] [blame] | 1033 | |
| 1034 | // EmitVAArg - Generate code to get an argument from the passed in pointer |
| 1035 | // and update it accordingly. The return value is a pointer to the argument. |
| 1036 | // FIXME: We should be able to get rid of this method and use the va_arg |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1037 | // instruction in LLVM instead once it works well enough. |
Anders Carlsson | 13abd7e | 2008-11-04 05:30:00 +0000 | [diff] [blame] | 1038 | llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); |
Anders Carlsson | e388a5b | 2008-12-20 20:27:15 +0000 | [diff] [blame] | 1039 | |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1040 | /// EmitVLASize - Generate code for any VLA size expressions that might occur |
| 1041 | /// in a variably modified type. If Ty is a VLA, will return the value that |
| 1042 | /// corresponds to the size in bytes of the VLA type. Will return 0 otherwise. |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1043 | /// |
| 1044 | /// This function can be called with a null (unreachable) insert point. |
Anders Carlsson | 8a01b79 | 2008-12-20 20:46:34 +0000 | [diff] [blame] | 1045 | llvm::Value *EmitVLASize(QualType Ty); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1046 | |
Anders Carlsson | ccbe920 | 2008-12-12 07:19:02 +0000 | [diff] [blame] | 1047 | // GetVLASize - Returns an LLVM value that corresponds to the size in bytes |
| 1048 | // of a variable length array type. |
| 1049 | llvm::Value *GetVLASize(const VariableArrayType *); |
| 1050 | |
Anders Carlsson | a5d077d | 2009-04-14 16:58:56 +0000 | [diff] [blame] | 1051 | /// LoadCXXThis - Load the value of 'this'. This function is only valid while |
| 1052 | /// generating code for an C++ member function. |
John McCall | 347132b | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 1053 | llvm::Value *LoadCXXThis() { |
| 1054 | assert(CXXThisValue && "no 'this' value for this function"); |
| 1055 | return CXXThisValue; |
| 1056 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | |
Anders Carlsson | e36a6b3 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 1058 | /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have |
| 1059 | /// virtual bases. |
John McCall | 347132b | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 1060 | llvm::Value *LoadCXXVTT() { |
| 1061 | assert(CXXVTTValue && "no VTT value for this function"); |
| 1062 | return CXXVTTValue; |
| 1063 | } |
John McCall | 6ce7472 | 2010-02-16 04:15:37 +0000 | [diff] [blame] | 1064 | |
| 1065 | /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a |
Anders Carlsson | c4ba0cd | 2010-04-24 23:01:49 +0000 | [diff] [blame] | 1066 | /// complete class to the given direct base. |
| 1067 | llvm::Value * |
| 1068 | GetAddressOfDirectBaseInCompleteClass(llvm::Value *Value, |
| 1069 | const CXXRecordDecl *Derived, |
| 1070 | const CXXRecordDecl *Base, |
| 1071 | bool BaseIsVirtual); |
Anders Carlsson | bea9e74 | 2010-04-24 21:51:08 +0000 | [diff] [blame] | 1072 | |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1073 | /// GetAddressOfBaseClass - This function will add the necessary delta to the |
| 1074 | /// load of 'this' and returns address of the base class. |
Anders Carlsson | d829a02 | 2010-04-24 21:06:20 +0000 | [diff] [blame] | 1075 | llvm::Value *GetAddressOfBaseClass(llvm::Value *Value, |
Anders Carlsson | c4ba0cd | 2010-04-24 23:01:49 +0000 | [diff] [blame] | 1076 | const CXXRecordDecl *Derived, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame^] | 1077 | CastExpr::path_const_iterator PathBegin, |
| 1078 | CastExpr::path_const_iterator PathEnd, |
Anders Carlsson | d829a02 | 2010-04-24 21:06:20 +0000 | [diff] [blame] | 1079 | bool NullCheckValue); |
| 1080 | |
Anders Carlsson | 8c79317 | 2009-11-23 17:57:54 +0000 | [diff] [blame] | 1081 | llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value, |
Anders Carlsson | c4ba0cd | 2010-04-24 23:01:49 +0000 | [diff] [blame] | 1082 | const CXXRecordDecl *Derived, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame^] | 1083 | CastExpr::path_const_iterator PathBegin, |
| 1084 | CastExpr::path_const_iterator PathEnd, |
Anders Carlsson | 8c79317 | 2009-11-23 17:57:54 +0000 | [diff] [blame] | 1085 | bool NullCheckValue); |
| 1086 | |
Anders Carlsson | 84673e2 | 2010-01-31 01:36:53 +0000 | [diff] [blame] | 1087 | llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This, |
| 1088 | const CXXRecordDecl *ClassDecl, |
| 1089 | const CXXRecordDecl *BaseClassDecl); |
Anders Carlsson | c6d171e | 2009-10-06 22:43:30 +0000 | [diff] [blame] | 1090 | |
John McCall | f8ff7b9 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 1091 | void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, |
| 1092 | CXXCtorType CtorType, |
| 1093 | const FunctionArgList &Args); |
Anders Carlsson | e11f9ce | 2010-05-02 23:20:53 +0000 | [diff] [blame] | 1094 | void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, |
| 1095 | bool ForVirtualBase, llvm::Value *This, |
Anders Carlsson | b7f8f59 | 2009-04-17 00:06:03 +0000 | [diff] [blame] | 1096 | CallExpr::const_arg_iterator ArgBeg, |
| 1097 | CallExpr::const_arg_iterator ArgEnd); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | |
Fariborz Jahanian | 431c883 | 2009-08-19 20:55:16 +0000 | [diff] [blame] | 1099 | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
Anders Carlsson | d49844b | 2009-09-23 02:45:36 +0000 | [diff] [blame] | 1100 | const ConstantArrayType *ArrayTy, |
Anders Carlsson | 3a202f6 | 2009-11-24 18:43:52 +0000 | [diff] [blame] | 1101 | llvm::Value *ArrayPtr, |
| 1102 | CallExpr::const_arg_iterator ArgBeg, |
Douglas Gregor | 05fc5be | 2010-07-21 01:10:17 +0000 | [diff] [blame] | 1103 | CallExpr::const_arg_iterator ArgEnd, |
| 1104 | bool ZeroInitialization = false); |
Anders Carlsson | 3a202f6 | 2009-11-24 18:43:52 +0000 | [diff] [blame] | 1105 | |
Anders Carlsson | d49844b | 2009-09-23 02:45:36 +0000 | [diff] [blame] | 1106 | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
| 1107 | llvm::Value *NumElements, |
Anders Carlsson | 3a202f6 | 2009-11-24 18:43:52 +0000 | [diff] [blame] | 1108 | llvm::Value *ArrayPtr, |
| 1109 | CallExpr::const_arg_iterator ArgBeg, |
Douglas Gregor | 05fc5be | 2010-07-21 01:10:17 +0000 | [diff] [blame] | 1110 | CallExpr::const_arg_iterator ArgEnd, |
| 1111 | bool ZeroInitialization = false); |
Anders Carlsson | b7f8f59 | 2009-04-17 00:06:03 +0000 | [diff] [blame] | 1112 | |
Fariborz Jahanian | 9c83720 | 2009-08-20 20:54:15 +0000 | [diff] [blame] | 1113 | void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, |
| 1114 | const ArrayType *Array, |
| 1115 | llvm::Value *This); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | |
Fariborz Jahanian | 6814eaa | 2009-11-13 19:27:47 +0000 | [diff] [blame] | 1117 | void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, |
| 1118 | llvm::Value *NumElements, |
| 1119 | llvm::Value *This); |
| 1120 | |
Anders Carlsson | 165ec0a | 2010-06-08 22:14:59 +0000 | [diff] [blame] | 1121 | llvm::Function *GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D, |
| 1122 | const ArrayType *Array, |
| 1123 | llvm::Value *This); |
Fariborz Jahanian | 1254a09 | 2009-11-10 19:24:06 +0000 | [diff] [blame] | 1124 | |
Anders Carlsson | 0a63741 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 1125 | void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, |
Anders Carlsson | f8a71f0 | 2010-05-02 23:29:11 +0000 | [diff] [blame] | 1126 | bool ForVirtualBase, llvm::Value *This); |
Fariborz Jahanian | d5202e0 | 2010-06-25 18:26:07 +0000 | [diff] [blame] | 1127 | |
| 1128 | void EmitNewArrayInitializer(const CXXNewExpr *E, llvm::Value *NewPtr, |
| 1129 | llvm::Value *NumElements); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1130 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1131 | void EmitCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1132 | |
Anders Carlsson | 4a7b49b | 2009-05-31 01:40:14 +0000 | [diff] [blame] | 1133 | llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); |
Anders Carlsson | 81f0df9 | 2009-08-16 21:13:42 +0000 | [diff] [blame] | 1134 | void EmitCXXDeleteExpr(const CXXDeleteExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1135 | |
Eli Friedman | 24f5543 | 2009-11-18 00:57:03 +0000 | [diff] [blame] | 1136 | void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, |
| 1137 | QualType DeleteTy); |
| 1138 | |
Mike Stump | c9b231c | 2009-11-15 08:09:41 +0000 | [diff] [blame] | 1139 | llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E); |
Mike Stump | 6551170 | 2009-11-16 06:50:58 +0000 | [diff] [blame] | 1140 | llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE); |
Mike Stump | c9b231c | 2009-11-15 08:09:41 +0000 | [diff] [blame] | 1141 | |
Mike Stump | 3f6f9fe | 2009-12-16 02:57:00 +0000 | [diff] [blame] | 1142 | void EmitCheck(llvm::Value *, unsigned Size); |
| 1143 | |
Chris Lattner | 116ce8f | 2010-01-09 21:40:03 +0000 | [diff] [blame] | 1144 | llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, |
| 1145 | bool isInc, bool isPre); |
| 1146 | ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, |
| 1147 | bool isInc, bool isPre); |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1148 | //===--------------------------------------------------------------------===// |
Chris Lattner | 53621a5 | 2007-06-13 20:44:40 +0000 | [diff] [blame] | 1149 | // Declaration Emission |
Chris Lattner | 84915fa | 2007-06-02 04:16:21 +0000 | [diff] [blame] | 1150 | //===--------------------------------------------------------------------===// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1151 | |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1152 | /// EmitDecl - Emit a declaration. |
| 1153 | /// |
| 1154 | /// This function can be called with a null (unreachable) insert point. |
Chris Lattner | 1ad38f8 | 2007-06-09 01:20:56 +0000 | [diff] [blame] | 1155 | void EmitDecl(const Decl &D); |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1156 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | /// EmitBlockVarDecl - Emit a block variable declaration. |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1158 | /// |
| 1159 | /// This function can be called with a null (unreachable) insert point. |
Steve Naroff | 08899ff | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 1160 | void EmitBlockVarDecl(const VarDecl &D); |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1161 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1162 | typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, |
| 1163 | llvm::Value *Address); |
| 1164 | |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1165 | /// EmitLocalBlockVarDecl - Emit a local block variable declaration. |
| 1166 | /// |
| 1167 | /// This function can be called with a null (unreachable) insert point. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1168 | void EmitLocalBlockVarDecl(const VarDecl &D, SpecialInitFn *SpecialInit = 0); |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1169 | |
Anders Carlsson | cee2d2f | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 1170 | void EmitStaticBlockVarDecl(const VarDecl &D, |
| 1171 | llvm::GlobalValue::LinkageTypes Linkage); |
Daniel Dunbar | a94ecd2 | 2008-08-16 03:19:19 +0000 | [diff] [blame] | 1172 | |
| 1173 | /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. |
| 1174 | void EmitParmDecl(const VarDecl &D, llvm::Value *Arg); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1175 | |
Chris Lattner | 84915fa | 2007-06-02 04:16:21 +0000 | [diff] [blame] | 1176 | //===--------------------------------------------------------------------===// |
Chris Lattner | 308f431 | 2007-05-29 23:50:05 +0000 | [diff] [blame] | 1177 | // Statement Emission |
| 1178 | //===--------------------------------------------------------------------===// |
| 1179 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1180 | /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. |
Daniel Dunbar | 5fc2871 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1181 | void EmitStopPoint(const Stmt *S); |
| 1182 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1183 | /// EmitStmt - Emit the code for the statement \arg S. It is legal to call |
| 1184 | /// this function even if there is no current insertion point. |
| 1185 | /// |
| 1186 | /// This function may clear the current insertion point; callers should use |
| 1187 | /// EnsureInsertPoint if they wish to subsequently generate code without first |
| 1188 | /// calling EmitBlock, EmitBranch, or EmitStmt. |
Chris Lattner | 308f431 | 2007-05-29 23:50:05 +0000 | [diff] [blame] | 1189 | void EmitStmt(const Stmt *S); |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1190 | |
Daniel Dunbar | 5fc2871 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1191 | /// EmitSimpleStmt - Try to emit a "simple" statement which does not |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1192 | /// necessarily require an insertion point or debug information; typically |
| 1193 | /// because the statement amounts to a jump or a container of other |
| 1194 | /// statements. |
Daniel Dunbar | 5fc2871 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1195 | /// |
| 1196 | /// \return True if the statement was handled. |
| 1197 | bool EmitSimpleStmt(const Stmt *S); |
| 1198 | |
Chris Lattner | 4647a21 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 1199 | RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, |
| 1200 | llvm::Value *AggLoc = 0, bool isAggVol = false); |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1201 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1202 | /// EmitLabel - Emit the block for the given label. It is legal to call this |
| 1203 | /// function even if there is no current insertion point. |
Chris Lattner | 7e80097 | 2008-07-26 20:23:23 +0000 | [diff] [blame] | 1204 | void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt. |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1205 | |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 1206 | void EmitLabelStmt(const LabelStmt &S); |
| 1207 | void EmitGotoStmt(const GotoStmt &S); |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 1208 | void EmitIndirectGotoStmt(const IndirectGotoStmt &S); |
Chris Lattner | 5269c03 | 2007-05-30 21:03:58 +0000 | [diff] [blame] | 1209 | void EmitIfStmt(const IfStmt &S); |
Chris Lattner | 946aa31 | 2007-06-05 03:59:43 +0000 | [diff] [blame] | 1210 | void EmitWhileStmt(const WhileStmt &S); |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1211 | void EmitDoStmt(const DoStmt &S); |
| 1212 | void EmitForStmt(const ForStmt &S); |
Chris Lattner | 3f3dbee | 2007-06-02 03:19:07 +0000 | [diff] [blame] | 1213 | void EmitReturnStmt(const ReturnStmt &S); |
Chris Lattner | 1ad38f8 | 2007-06-09 01:20:56 +0000 | [diff] [blame] | 1214 | void EmitDeclStmt(const DeclStmt &S); |
Daniel Dunbar | 5fc2871 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1215 | void EmitBreakStmt(const BreakStmt &S); |
| 1216 | void EmitContinueStmt(const ContinueStmt &S); |
Devang Patel | da5d6bb | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 1217 | void EmitSwitchStmt(const SwitchStmt &S); |
| 1218 | void EmitDefaultStmt(const DefaultStmt &S); |
| 1219 | void EmitCaseStmt(const CaseStmt &S); |
Devang Patel | 1166312 | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 1220 | void EmitCaseStmtRange(const CaseStmt &S); |
Anders Carlsson | 952a995 | 2008-02-05 16:35:33 +0000 | [diff] [blame] | 1221 | void EmitAsmStmt(const AsmStmt &S); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1222 | |
Anders Carlsson | 2e744e8 | 2008-08-30 19:51:14 +0000 | [diff] [blame] | 1223 | void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); |
Anders Carlsson | 1963b0c | 2008-09-09 10:04:29 +0000 | [diff] [blame] | 1224 | void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); |
| 1225 | void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); |
Chris Lattner | e132e24 | 2008-11-15 21:26:17 +0000 | [diff] [blame] | 1226 | void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1227 | |
Douglas Gregor | 51150ab | 2010-05-16 01:24:12 +0000 | [diff] [blame] | 1228 | llvm::Constant *getUnwindResumeOrRethrowFn(); |
John McCall | b609d3f | 2010-07-07 06:56:46 +0000 | [diff] [blame] | 1229 | void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
| 1230 | void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
John McCall | b81884d | 2010-02-19 09:25:03 +0000 | [diff] [blame] | 1231 | |
Anders Carlsson | 52d78a5 | 2009-09-27 18:58:34 +0000 | [diff] [blame] | 1232 | void EmitCXXTryStmt(const CXXTryStmt &S); |
| 1233 | |
Chris Lattner | 208ae96 | 2007-05-30 17:57:17 +0000 | [diff] [blame] | 1234 | //===--------------------------------------------------------------------===// |
Chris Lattner | d7f5886 | 2007-06-02 05:24:33 +0000 | [diff] [blame] | 1235 | // LValue Expression Emission |
| 1236 | //===--------------------------------------------------------------------===// |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1237 | |
Daniel Dunbar | c79407f | 2009-02-05 07:09:07 +0000 | [diff] [blame] | 1238 | /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. |
| 1239 | RValue GetUndefRValue(QualType Ty); |
| 1240 | |
Daniel Dunbar | bb197e4 | 2009-01-09 16:50:52 +0000 | [diff] [blame] | 1241 | /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E |
| 1242 | /// and issue an ErrorUnsupported style diagnostic (using the |
| 1243 | /// provided Name). |
| 1244 | RValue EmitUnsupportedRValue(const Expr *E, |
| 1245 | const char *Name); |
| 1246 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1247 | /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue |
| 1248 | /// an ErrorUnsupported style diagnostic (using the provided Name). |
Daniel Dunbar | f2e6988 | 2008-08-25 20:45:57 +0000 | [diff] [blame] | 1249 | LValue EmitUnsupportedLValue(const Expr *E, |
| 1250 | const char *Name); |
| 1251 | |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1252 | /// EmitLValue - Emit code to compute a designator that specifies the location |
| 1253 | /// of the expression. |
| 1254 | /// |
| 1255 | /// This can return one of two things: a simple address or a bitfield |
| 1256 | /// reference. In either case, the LLVM Value* in the LValue structure is |
| 1257 | /// guaranteed to be an LLVM pointer type. |
| 1258 | /// |
| 1259 | /// If this returns a bitfield reference, nothing about the pointee type of |
| 1260 | /// the LLVM value is known: For example, it may not be a pointer to an |
| 1261 | /// integer. |
| 1262 | /// |
| 1263 | /// If this returns a normal address, and if the lvalue's C type is fixed |
| 1264 | /// size, this method guarantees that the returned pointer type will point to |
| 1265 | /// an LLVM type of the same size of the lvalue's type. If the lvalue has a |
| 1266 | /// variable length type, this is not possible. |
| 1267 | /// |
Chris Lattner | d7f5886 | 2007-06-02 05:24:33 +0000 | [diff] [blame] | 1268 | LValue EmitLValue(const Expr *E); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1269 | |
Mike Stump | 3f6f9fe | 2009-12-16 02:57:00 +0000 | [diff] [blame] | 1270 | /// EmitCheckedLValue - Same as EmitLValue but additionally we generate |
| 1271 | /// checking code to guard against undefined behavior. This is only |
| 1272 | /// suitable when we know that the address will be used to access the |
| 1273 | /// object. |
| 1274 | LValue EmitCheckedLValue(const Expr *E); |
| 1275 | |
Daniel Dunbar | 1d42546 | 2009-02-10 00:57:50 +0000 | [diff] [blame] | 1276 | /// EmitLoadOfScalar - Load a scalar value from an address, taking |
| 1277 | /// care to appropriately convert from the memory representation to |
| 1278 | /// the LLVM value representation. |
Mike Stump | c6ea7c1 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 1279 | llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, |
Daniel Dunbar | 1d42546 | 2009-02-10 00:57:50 +0000 | [diff] [blame] | 1280 | QualType Ty); |
| 1281 | |
| 1282 | /// EmitStoreOfScalar - Store a scalar value to an address, taking |
| 1283 | /// care to appropriately convert from the memory representation to |
| 1284 | /// the LLVM value representation. |
Mike Stump | c6ea7c1 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 1285 | void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, |
Anders Carlsson | 8370964 | 2009-05-19 18:50:41 +0000 | [diff] [blame] | 1286 | bool Volatile, QualType Ty); |
Daniel Dunbar | 1d42546 | 2009-02-10 00:57:50 +0000 | [diff] [blame] | 1287 | |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1288 | /// EmitLoadOfLValue - Given an expression that represents a value lvalue, |
| 1289 | /// this method emits the address of the lvalue, then loads the result as an |
| 1290 | /// rvalue, returning the rvalue. |
Chris Lattner | 9369a56 | 2007-06-29 16:31:29 +0000 | [diff] [blame] | 1291 | RValue EmitLoadOfLValue(LValue V, QualType LVType); |
Nate Begeman | ce4d7fc | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1292 | RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType); |
Lauro Ramos Venancio | 2ddcb25a3 | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 1293 | RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); |
Daniel Dunbar | 9e22c0d | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 1294 | RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType); |
Fariborz Jahanian | 9ac5351 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 1295 | RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType); |
Chris Lattner | 9369a56 | 2007-06-29 16:31:29 +0000 | [diff] [blame] | 1296 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1297 | |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1298 | /// EmitStoreThroughLValue - Store the specified rvalue into the specified |
| 1299 | /// lvalue, where both are guaranteed to the have the same type, and that type |
| 1300 | /// is 'Ty'. |
| 1301 | void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); |
Nate Begeman | ce4d7fc | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1302 | void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst, |
| 1303 | QualType Ty); |
Daniel Dunbar | 9e22c0d | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 1304 | void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty); |
Fariborz Jahanian | 9ac5351 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 1305 | void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty); |
Daniel Dunbar | 9b1335e | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 1306 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1307 | /// EmitStoreThroughLValue - Store Src into Dst with same constraints as |
| 1308 | /// EmitStoreThroughLValue. |
Daniel Dunbar | 9b1335e | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 1309 | /// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1310 | /// \param Result [out] - If non-null, this will be set to a Value* for the |
| 1311 | /// bit-field contents after the store, appropriate for use as the result of |
| 1312 | /// an assignment to the bit-field. |
Daniel Dunbar | 9b1335e | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 1313 | void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty, |
| 1314 | llvm::Value **Result=0); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1315 | |
Christopher Lamb | d91c3d4 | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 1316 | // Note: only availabe for agg return types |
Daniel Dunbar | 8cde00a | 2008-09-04 03:20:13 +0000 | [diff] [blame] | 1317 | LValue EmitBinaryOperatorLValue(const BinaryOperator *E); |
Douglas Gregor | 914af21 | 2010-04-23 04:16:32 +0000 | [diff] [blame] | 1318 | LValue EmitCompoundAssignOperatorLValue(const CompoundAssignOperator *E); |
Daniel Dunbar | 8d9dc4a | 2009-02-11 20:59:32 +0000 | [diff] [blame] | 1319 | // Note: only available for agg return types |
Christopher Lamb | d91c3d4 | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 1320 | LValue EmitCallExprLValue(const CallExpr *E); |
Daniel Dunbar | 8d9dc4a | 2009-02-11 20:59:32 +0000 | [diff] [blame] | 1321 | // Note: only available for agg return types |
| 1322 | LValue EmitVAArgExprLValue(const VAArgExpr *E); |
Chris Lattner | d7f5886 | 2007-06-02 05:24:33 +0000 | [diff] [blame] | 1323 | LValue EmitDeclRefLValue(const DeclRefExpr *E); |
Chris Lattner | 4347e369 | 2007-06-06 04:54:52 +0000 | [diff] [blame] | 1324 | LValue EmitStringLiteralLValue(const StringLiteral *E); |
Chris Lattner | d7e7b8e | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 1325 | LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); |
Daniel Dunbar | b351747 | 2008-10-17 21:58:32 +0000 | [diff] [blame] | 1326 | LValue EmitPredefinedFunctionName(unsigned Type); |
Chris Lattner | 6307f19 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 1327 | LValue EmitPredefinedLValue(const PredefinedExpr *E); |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1328 | LValue EmitUnaryOpLValue(const UnaryOperator *E); |
Chris Lattner | d9d2fb1 | 2007-06-08 23:31:14 +0000 | [diff] [blame] | 1329 | LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); |
Nate Begeman | ce4d7fc | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1330 | LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); |
Devang Patel | 3e11cce | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 1331 | LValue EmitMemberExpr(const MemberExpr *E); |
Fariborz Jahanian | 531c16f | 2009-12-09 23:35:29 +0000 | [diff] [blame] | 1332 | LValue EmitObjCIsaExpr(const ObjCIsaExpr *E); |
Eli Friedman | 9fd8b68 | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 1333 | LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); |
Anders Carlsson | 1450adb | 2009-09-15 16:35:24 +0000 | [diff] [blame] | 1334 | LValue EmitConditionalOperatorLValue(const ConditionalOperator *E); |
Chris Lattner | 28bcf1a | 2009-03-18 18:28:57 +0000 | [diff] [blame] | 1335 | LValue EmitCastLValue(const CastExpr *E); |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 1336 | LValue EmitNullInitializationLValue(const CXXScalarValueInitExpr *E); |
Anders Carlsson | 509850e | 2009-11-07 22:00:15 +0000 | [diff] [blame] | 1337 | |
Daniel Dunbar | 722f424 | 2009-04-22 05:08:15 +0000 | [diff] [blame] | 1338 | llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, |
Daniel Dunbar | 1c64e5d | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 1339 | const ObjCIvarDecl *Ivar); |
John McCall | c409493 | 2010-05-21 01:18:57 +0000 | [diff] [blame] | 1340 | LValue EmitLValueForAnonRecordField(llvm::Value* Base, |
| 1341 | const FieldDecl* Field, |
| 1342 | unsigned CVRQualifiers); |
Anders Carlsson | cfd3012 | 2009-11-17 03:57:07 +0000 | [diff] [blame] | 1343 | LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field, |
Anders Carlsson | 5d8645b | 2010-01-29 05:05:36 +0000 | [diff] [blame] | 1344 | unsigned CVRQualifiers); |
Anders Carlsson | db78f0a | 2010-01-29 05:24:29 +0000 | [diff] [blame] | 1345 | |
| 1346 | /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that |
| 1347 | /// if the Field is a reference, this will return the address of the reference |
| 1348 | /// and not the address of the value stored in the reference. |
| 1349 | LValue EmitLValueForFieldInitialization(llvm::Value* Base, |
| 1350 | const FieldDecl* Field, |
| 1351 | unsigned CVRQualifiers); |
| 1352 | |
Fariborz Jahanian | c88a70d | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 1353 | LValue EmitLValueForIvar(QualType ObjectTy, |
| 1354 | llvm::Value* Base, const ObjCIvarDecl *Ivar, |
Daniel Dunbar | 1c64e5d | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 1355 | unsigned CVRQualifiers); |
| 1356 | |
Anders Carlsson | cfd3012 | 2009-11-17 03:57:07 +0000 | [diff] [blame] | 1357 | LValue EmitLValueForBitfield(llvm::Value* Base, const FieldDecl* Field, |
Fariborz Jahanian | 712bfa6 | 2009-02-03 19:03:09 +0000 | [diff] [blame] | 1358 | unsigned CVRQualifiers); |
Fariborz Jahanian | b517e90 | 2008-12-15 20:35:07 +0000 | [diff] [blame] | 1359 | |
Mike Stump | 1db7d04 | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 1360 | LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E); |
| 1361 | |
Anders Carlsson | 3be22e2 | 2009-05-30 23:23:33 +0000 | [diff] [blame] | 1362 | LValue EmitCXXConstructLValue(const CXXConstructExpr *E); |
Anders Carlsson | fd2af0c | 2009-05-30 23:30:54 +0000 | [diff] [blame] | 1363 | LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); |
Anders Carlsson | 96bad9a | 2009-09-14 01:10:45 +0000 | [diff] [blame] | 1364 | LValue EmitCXXExprWithTemporariesLValue(const CXXExprWithTemporaries *E); |
Mike Stump | c9b231c | 2009-11-15 08:09:41 +0000 | [diff] [blame] | 1365 | LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); |
Anders Carlsson | 96bad9a | 2009-09-14 01:10:45 +0000 | [diff] [blame] | 1366 | |
Daniel Dunbar | c8317a4 | 2008-08-23 10:51:21 +0000 | [diff] [blame] | 1367 | LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); |
Chris Lattner | 4bd5596 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 1368 | LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); |
Daniel Dunbar | 9e22c0d | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 1369 | LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E); |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 1370 | LValue EmitObjCKVCRefLValue(const ObjCImplicitSetterGetterRefExpr *E); |
Chris Lattner | a4185c5 | 2009-04-25 19:35:26 +0000 | [diff] [blame] | 1371 | LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E); |
| 1372 | LValue EmitStmtExprLValue(const StmtExpr *E); |
Fariborz Jahanian | ffba662 | 2009-10-22 22:57:31 +0000 | [diff] [blame] | 1373 | LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); |
Fariborz Jahanian | 9240f3d | 2010-06-17 19:56:20 +0000 | [diff] [blame] | 1374 | LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); |
Fariborz Jahanian | ffba662 | 2009-10-22 22:57:31 +0000 | [diff] [blame] | 1375 | |
Chris Lattner | d7f5886 | 2007-06-02 05:24:33 +0000 | [diff] [blame] | 1376 | //===--------------------------------------------------------------------===// |
Chris Lattner | 6278e6a | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 1377 | // Scalar Expression Emission |
Chris Lattner | 208ae96 | 2007-05-30 17:57:17 +0000 | [diff] [blame] | 1378 | //===--------------------------------------------------------------------===// |
| 1379 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1380 | /// EmitCall - Generate a call of the given function, expecting the given |
| 1381 | /// result type, and using the given argument list which specifies both the |
| 1382 | /// LLVM arguments and the types they were derived from. |
Daniel Dunbar | cdbb5e3 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 1383 | /// |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1384 | /// \param TargetDecl - If given, the decl of the function in a direct call; |
| 1385 | /// used to set attributes on the call (noreturn, etc.). |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 1386 | RValue EmitCall(const CGFunctionInfo &FnInfo, |
| 1387 | llvm::Value *Callee, |
Anders Carlsson | 61a401c | 2009-12-24 19:25:24 +0000 | [diff] [blame] | 1388 | ReturnValueSlot ReturnValue, |
Daniel Dunbar | cdbb5e3 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 1389 | const CallArgList &Args, |
David Chisnall | 9eecafa | 2010-05-01 11:15:56 +0000 | [diff] [blame] | 1390 | const Decl *TargetDecl = 0, |
David Chisnall | ff5f88c | 2010-05-02 13:41:58 +0000 | [diff] [blame] | 1391 | llvm::Instruction **callOrInvoke = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1392 | |
Anders Carlsson | 0435ed5 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 1393 | RValue EmitCall(QualType FnType, llvm::Value *Callee, |
Anders Carlsson | 1749083 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 1394 | ReturnValueSlot ReturnValue, |
Anders Carlsson | 3a9463b | 2009-05-27 01:22:39 +0000 | [diff] [blame] | 1395 | CallExpr::const_arg_iterator ArgBeg, |
| 1396 | CallExpr::const_arg_iterator ArgEnd, |
| 1397 | const Decl *TargetDecl = 0); |
Anders Carlsson | 1749083 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 1398 | RValue EmitCallExpr(const CallExpr *E, |
| 1399 | ReturnValueSlot ReturnValue = ReturnValueSlot()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1400 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1401 | llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, |
| 1402 | llvm::Value * const *ArgBegin, |
| 1403 | llvm::Value * const *ArgEnd, |
| 1404 | const llvm::Twine &Name = ""); |
| 1405 | |
Anders Carlsson | e828c36 | 2009-11-13 04:45:41 +0000 | [diff] [blame] | 1406 | llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This, |
Mike Stump | a5588bf | 2009-08-26 20:46:33 +0000 | [diff] [blame] | 1407 | const llvm::Type *Ty); |
Anders Carlsson | e828c36 | 2009-11-13 04:45:41 +0000 | [diff] [blame] | 1408 | llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type, |
| 1409 | llvm::Value *&This, const llvm::Type *Ty); |
| 1410 | |
Anders Carlsson | bd7d11f | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 1411 | RValue EmitCXXMemberCall(const CXXMethodDecl *MD, |
| 1412 | llvm::Value *Callee, |
Anders Carlsson | bfb3671 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 1413 | ReturnValueSlot ReturnValue, |
Anders Carlsson | bd7d11f | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 1414 | llvm::Value *This, |
Anders Carlsson | e36a6b3 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 1415 | llvm::Value *VTT, |
Anders Carlsson | bd7d11f | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 1416 | CallExpr::const_arg_iterator ArgBeg, |
| 1417 | CallExpr::const_arg_iterator ArgEnd); |
Anders Carlsson | bfb3671 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 1418 | RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, |
| 1419 | ReturnValueSlot ReturnValue); |
| 1420 | RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, |
| 1421 | ReturnValueSlot ReturnValue); |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 1422 | |
Anders Carlsson | 4034a95 | 2009-05-27 04:18:27 +0000 | [diff] [blame] | 1423 | RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, |
Anders Carlsson | bfb3671 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 1424 | const CXXMethodDecl *MD, |
| 1425 | ReturnValueSlot ReturnValue); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1426 | |
Anders Carlsson | 2ee3c01 | 2009-10-03 19:43:08 +0000 | [diff] [blame] | 1427 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | RValue EmitBuiltinExpr(const FunctionDecl *FD, |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1429 | unsigned BuiltinID, const CallExpr *E); |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1430 | |
Anders Carlsson | bfb3671 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 1431 | RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); |
Mike Stump | c6ea7c1 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 1432 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1433 | /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call |
| 1434 | /// is unhandled by the current target. |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 1435 | llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 1436 | |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1437 | llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1438 | llvm::Value *EmitNeonCall(llvm::Function *F, |
| 1439 | llvm::SmallVectorImpl<llvm::Value*> &O, |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1440 | const char *name, bool splat = false, |
| 1441 | unsigned shift = 0, bool rightshift = false); |
Nate Begeman | ad5dd42 | 2010-08-06 01:24:57 +0000 | [diff] [blame] | 1442 | llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx, |
| 1443 | bool widen = false); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1444 | llvm::Value *EmitNeonShiftVector(llvm::Value *V, const llvm::Type *Ty, |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1445 | bool negateForRightShift); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1446 | |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 1447 | llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 1448 | llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1449 | |
Daniel Dunbar | 66912a1 | 2008-08-20 00:28:19 +0000 | [diff] [blame] | 1450 | llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); |
Chris Lattner | 2da04b3 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 1451 | llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); |
Chris Lattner | b1d329d | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 1452 | llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); |
John McCall | 78a1511 | 2010-05-22 01:48:05 +0000 | [diff] [blame] | 1453 | RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, |
| 1454 | ReturnValueSlot Return = ReturnValueSlot()); |
| 1455 | RValue EmitObjCPropertyGet(const Expr *E, |
| 1456 | ReturnValueSlot Return = ReturnValueSlot()); |
| 1457 | RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S, |
| 1458 | ReturnValueSlot Return = ReturnValueSlot()); |
Fariborz Jahanian | 9ac5351 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 1459 | void EmitObjCPropertySet(const Expr *E, RValue Src); |
Fariborz Jahanian | 391d4fc | 2009-03-20 19:18:21 +0000 | [diff] [blame] | 1460 | void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src); |
Chris Lattner | b1d329d | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 1461 | |
| 1462 | |
Anders Carlsson | 6f5a015 | 2009-05-20 00:24:07 +0000 | [diff] [blame] | 1463 | /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in |
| 1464 | /// expression. Will emit a temporary variable if E is not an LValue. |
Anders Carlsson | 04775f8 | 2010-06-26 16:35:32 +0000 | [diff] [blame] | 1465 | RValue EmitReferenceBindingToExpr(const Expr* E, |
| 1466 | const NamedDecl *InitializedDecl); |
Anders Carlsson | ab0ddb5 | 2010-01-31 18:34:51 +0000 | [diff] [blame] | 1467 | |
Chris Lattner | 6278e6a | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 1468 | //===--------------------------------------------------------------------===// |
Chris Lattner | bda69f8 | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 1469 | // Expression Emission |
Chris Lattner | 6278e6a | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 1470 | //===--------------------------------------------------------------------===// |
Chris Lattner | bda69f8 | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 1471 | |
| 1472 | // Expressions are broken into three classes: scalar, complex, aggregate. |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1473 | |
| 1474 | /// EmitScalarExpr - Emit the computation of the specified expression of LLVM |
| 1475 | /// scalar type, returning the result. |
Anders Carlsson | 5b106a7 | 2009-08-16 07:36:22 +0000 | [diff] [blame] | 1476 | llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1477 | |
Chris Lattner | 3474c20 | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 1478 | /// EmitScalarConversion - Emit a conversion from the specified type to the |
| 1479 | /// specified destination type, both of which are LLVM scalar types. |
| 1480 | llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, |
| 1481 | QualType DstTy); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1482 | |
Chris Lattner | 42e6b81 | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 1483 | /// EmitComplexToScalarConversion - Emit a conversion from the specified |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1484 | /// complex type to the specified destination type, where the destination type |
| 1485 | /// is an LLVM scalar type. |
Chris Lattner | 42e6b81 | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 1486 | llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, |
| 1487 | QualType DstTy); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1488 | |
| 1489 | |
Chris Lattner | 6278e6a | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 1490 | /// EmitAggExpr - Emit the computation of the specified expression of |
| 1491 | /// aggregate type. The result is computed into DestPtr. Note that if |
| 1492 | /// DestPtr is null, the value of the aggregate expression is not needed. |
Mike Stump | ec3cbfe | 2009-05-26 22:03:21 +0000 | [diff] [blame] | 1493 | void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest, |
Fariborz Jahanian | 879d726 | 2009-08-31 19:33:16 +0000 | [diff] [blame] | 1494 | bool IgnoreResult = false, bool IsInitializer = false, |
| 1495 | bool RequiresGCollection = false); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1496 | |
Daniel Dunbar | d0bc7b9 | 2010-02-05 19:38:31 +0000 | [diff] [blame] | 1497 | /// EmitAggExprToLValue - Emit the computation of the specified expression of |
| 1498 | /// aggregate type into a temporary LValue. |
| 1499 | LValue EmitAggExprToLValue(const Expr *E); |
| 1500 | |
Fariborz Jahanian | 5f21d2f | 2009-07-08 01:18:33 +0000 | [diff] [blame] | 1501 | /// EmitGCMemmoveCollectable - Emit special API for structs with object |
| 1502 | /// pointers. |
| 1503 | void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr, |
Fariborz Jahanian | 879d726 | 2009-08-31 19:33:16 +0000 | [diff] [blame] | 1504 | QualType Ty); |
Fariborz Jahanian | 5f21d2f | 2009-07-08 01:18:33 +0000 | [diff] [blame] | 1505 | |
Chris Lattner | cbfc73b | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 1506 | /// EmitComplexExpr - Emit the computation of the specified expression of |
Chris Lattner | 08b15df | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 1507 | /// complex type, returning the result. |
Mike Stump | df0fe27 | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 1508 | ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false, |
| 1509 | bool IgnoreImag = false, |
| 1510 | bool IgnoreRealAssign = false, |
| 1511 | bool IgnoreImagAssign = false); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1512 | |
Chris Lattner | 08b15df | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 1513 | /// EmitComplexExprIntoAddr - Emit the computation of the specified expression |
| 1514 | /// of complex type, storing into the specified Value*. |
Chris Lattner | b84bb95 | 2007-08-26 16:22:13 +0000 | [diff] [blame] | 1515 | void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, |
| 1516 | bool DestIsVolatile); |
Daniel Dunbar | 4b8c6db | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 1517 | |
| 1518 | /// StoreComplexToAddr - Store a complex number into the specified address. |
| 1519 | void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr, |
| 1520 | bool DestIsVolatile); |
Chris Lattner | 4647a21 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 1521 | /// LoadComplexFromAddr - Load a complex number from the specified address. |
| 1522 | ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); |
Chris Lattner | b781dc79 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 1523 | |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1524 | /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global for a |
| 1525 | /// static block var decl. |
Chris Lattner | e99c110 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 1526 | llvm::GlobalVariable *CreateStaticBlockVarDecl(const VarDecl &D, |
| 1527 | const char *Separator, |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1528 | llvm::GlobalValue::LinkageTypes Linkage); |
Chris Lattner | e99c110 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 1529 | |
| 1530 | /// AddInitializerToGlobalBlockVarDecl - Add the initializer for 'D' to the |
| 1531 | /// global variable that has already been created for it. If the initializer |
| 1532 | /// has a different type than GV does, this may free GV and return a different |
| 1533 | /// one. Otherwise it just returns GV. |
| 1534 | llvm::GlobalVariable * |
| 1535 | AddInitializerToGlobalBlockVarDecl(const VarDecl &D, |
| 1536 | llvm::GlobalVariable *GV); |
| 1537 | |
Daniel Dunbar | 22a87f9 | 2009-02-25 19:24:29 +0000 | [diff] [blame] | 1538 | |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1539 | /// EmitStaticCXXBlockVarDeclInit - Create the initializer for a C++ runtime |
| 1540 | /// initialized static block var decl. |
Anders Carlsson | f40886a | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 1541 | void EmitStaticCXXBlockVarDeclInit(const VarDecl &D, |
| 1542 | llvm::GlobalVariable *GV); |
Anders Carlsson | 87fc5a5 | 2008-08-22 16:00:37 +0000 | [diff] [blame] | 1543 | |
Anders Carlsson | f40886a | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 1544 | /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ |
| 1545 | /// variable with global storage. |
| 1546 | void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr); |
| 1547 | |
| 1548 | /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr |
| 1549 | /// with the C++ runtime so that its destructor will be called at exit. |
Fariborz Jahanian | 1254a09 | 2009-11-10 19:24:06 +0000 | [diff] [blame] | 1550 | void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn, |
Anders Carlsson | f40886a | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 1551 | llvm::Constant *DeclPtr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1552 | |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1553 | /// GenerateCXXGlobalInitFunc - Generates code for initializing global |
| 1554 | /// variables. |
| 1555 | void GenerateCXXGlobalInitFunc(llvm::Function *Fn, |
| 1556 | llvm::Constant **Decls, |
| 1557 | unsigned NumDecls); |
| 1558 | |
| 1559 | /// GenerateCXXGlobalDtorFunc - Generates code for destroying global |
| 1560 | /// variables. |
| 1561 | void GenerateCXXGlobalDtorFunc(llvm::Function *Fn, |
Chris Lattner | 87233f7 | 2010-06-19 05:52:45 +0000 | [diff] [blame] | 1562 | const std::vector<std::pair<llvm::WeakVH, |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1563 | llvm::Constant*> > &DtorsAndObjects); |
| 1564 | |
| 1565 | void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D); |
| 1566 | |
Anders Carlsson | 1619a504 | 2009-05-03 17:47:16 +0000 | [diff] [blame] | 1567 | void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1568 | |
Anders Carlsson | 3be22e2 | 2009-05-30 23:23:33 +0000 | [diff] [blame] | 1569 | RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1570 | llvm::Value *AggLoc = 0, |
Anders Carlsson | 5b106a7 | 2009-08-16 07:36:22 +0000 | [diff] [blame] | 1571 | bool IsAggLocVolatile = false, |
| 1572 | bool IsInitializer = false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | |
Anders Carlsson | 4b08db7 | 2009-10-30 01:42:31 +0000 | [diff] [blame] | 1574 | void EmitCXXThrowExpr(const CXXThrowExpr *E); |
Douglas Gregor | c278d1b | 2010-05-16 00:44:00 +0000 | [diff] [blame] | 1575 | |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 1576 | //===--------------------------------------------------------------------===// |
| 1577 | // Internal Helpers |
| 1578 | //===--------------------------------------------------------------------===// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1579 | |
Chris Lattner | 5b1964b | 2008-11-11 07:41:27 +0000 | [diff] [blame] | 1580 | /// ContainsLabel - Return true if the statement contains a label in it. If |
| 1581 | /// this statement is not executed normally, it not containing a label means |
| 1582 | /// that we can just remove the code. |
| 1583 | static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1584 | |
Daniel Dunbar | 682712c | 2008-11-12 10:12:14 +0000 | [diff] [blame] | 1585 | /// ConstantFoldsToSimpleInteger - If the specified expression does not fold |
Chris Lattner | cd43929 | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 1586 | /// to a constant, or if it does but contains a label, return 0. If it |
| 1587 | /// constant folds to 'true' and does not contain a label, return 1, if it |
| 1588 | /// constant folds to 'false' and does not contain a label, return -1. |
| 1589 | int ConstantFoldsToSimpleInteger(const Expr *Cond); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1590 | |
Chris Lattner | cd43929 | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 1591 | /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an |
| 1592 | /// if statement) to the specified blocks. Based on the condition, this might |
| 1593 | /// try to simplify the codegen of the conditional based on the branch. |
Chris Lattner | b7a9e16 | 2008-11-12 07:46:33 +0000 | [diff] [blame] | 1594 | void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, |
Daniel Dunbar | 682712c | 2008-11-12 10:12:14 +0000 | [diff] [blame] | 1595 | llvm::BasicBlock *FalseBlock); |
Mike Stump | ba6a0c4 | 2009-12-14 21:58:14 +0000 | [diff] [blame] | 1596 | |
Mike Stump | e8c3b3e | 2009-12-15 00:35:12 +0000 | [diff] [blame] | 1597 | /// getTrapBB - Create a basic block that will call the trap intrinsic. We'll |
| 1598 | /// generate a branch around the created basic block as necessary. |
Chris Lattner | 26008e0 | 2010-07-20 20:19:24 +0000 | [diff] [blame] | 1599 | llvm::BasicBlock *getTrapBB(); |
| 1600 | |
Anders Carlsson | 093bdff | 2010-03-30 03:27:09 +0000 | [diff] [blame] | 1601 | /// EmitCallArg - Emit a single call argument. |
| 1602 | RValue EmitCallArg(const Expr *E, QualType ArgType); |
| 1603 | |
John McCall | 23f6626 | 2010-05-26 22:34:26 +0000 | [diff] [blame] | 1604 | /// EmitDelegateCallArg - We are performing a delegate call; that |
| 1605 | /// is, the current function is delegating to another one. Produce |
| 1606 | /// a r-value suitable for passing the given parameter. |
| 1607 | RValue EmitDelegateCallArg(const VarDecl *Param); |
| 1608 | |
Chris Lattner | cd43929 | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 1609 | private: |
Daniel Dunbar | 1c64e5d | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 1610 | void EmitReturnOfRValue(RValue RV, QualType Ty); |
| 1611 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1612 | /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty |
| 1613 | /// from function arguments into \arg Dst. See ABIArgInfo::Expand. |
| 1614 | /// |
| 1615 | /// \param AI - The first function argument of the expansion. |
| 1616 | /// \return The argument following the last expanded function |
| 1617 | /// argument. |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1618 | llvm::Function::arg_iterator |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1619 | ExpandTypeFromArgs(QualType Ty, LValue Dst, |
| 1620 | llvm::Function::arg_iterator AI); |
| 1621 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1622 | /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg |
| 1623 | /// Ty, into individual arguments on the provided vector \arg Args. See |
| 1624 | /// ABIArgInfo::Expand. |
| 1625 | void ExpandTypeToArgs(QualType Ty, RValue Src, |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1626 | llvm::SmallVector<llvm::Value*, 16> &Args); |
Anders Carlsson | 03aaf11 | 2009-01-11 19:40:10 +0000 | [diff] [blame] | 1627 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1628 | llvm::Value* EmitAsmInput(const AsmStmt &S, |
Daniel Dunbar | d53e07b | 2009-05-04 06:56:16 +0000 | [diff] [blame] | 1629 | const TargetInfo::ConstraintInfo &Info, |
Anders Carlsson | 03aaf11 | 2009-01-11 19:40:10 +0000 | [diff] [blame] | 1630 | const Expr *InputExpr, std::string &ConstraintStr); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1631 | |
Eli Friedman | eca55af | 2010-07-16 00:55:21 +0000 | [diff] [blame] | 1632 | llvm::Value* EmitAsmInputLValue(const AsmStmt &S, |
| 1633 | const TargetInfo::ConstraintInfo &Info, |
| 1634 | LValue InputValue, QualType InputType, |
| 1635 | std::string &ConstraintStr); |
| 1636 | |
Anders Carlsson | 60ce3fe | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 1637 | /// EmitCallArgs - Emit call arguments for a function. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1638 | /// The CallArgTypeInfo parameter is used for iterating over the known |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1639 | /// argument types of the function being called. |
| 1640 | template<typename T> |
| 1641 | void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo, |
Anders Carlsson | 60ce3fe | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 1642 | CallExpr::const_arg_iterator ArgBeg, |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1643 | CallExpr::const_arg_iterator ArgEnd) { |
| 1644 | CallExpr::const_arg_iterator Arg = ArgBeg; |
Anders Carlsson | 60ce3fe | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 1645 | |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1646 | // First, use the argument types that the type info knows about |
| 1647 | if (CallArgTypeInfo) { |
| 1648 | for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(), |
| 1649 | E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) { |
Eli Friedman | 794290c | 2009-11-18 03:42:04 +0000 | [diff] [blame] | 1650 | assert(Arg != ArgEnd && "Running over edge of argument list!"); |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1651 | QualType ArgType = *I; |
| 1652 | |
| 1653 | assert(getContext().getCanonicalType(ArgType.getNonReferenceType()). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1654 | getTypePtr() == |
| 1655 | getContext().getCanonicalType(Arg->getType()).getTypePtr() && |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1656 | "type mismatch in call argument!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | |
| 1658 | Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1659 | ArgType)); |
| 1660 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1661 | |
| 1662 | // Either we've emitted all the call args, or we have a call to a |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1663 | // variadic function. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1664 | assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) && |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1665 | "Extra arguments in non-variadic function!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1667 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1668 | |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1669 | // If we still have any arguments, emit them using the type of the argument. |
| 1670 | for (; Arg != ArgEnd; ++Arg) { |
| 1671 | QualType ArgType = Arg->getType(); |
| 1672 | Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), |
| 1673 | ArgType)); |
| 1674 | } |
| 1675 | } |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 1676 | |
| 1677 | const TargetCodeGenInfo &getTargetHooks() const { |
| 1678 | return CGM.getTargetCodeGenInfo(); |
| 1679 | } |
John McCall | 09ae032 | 2010-07-06 23:57:41 +0000 | [diff] [blame] | 1680 | |
| 1681 | void EmitDeclMetadata(); |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 1682 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1683 | |
Fariborz Jahanian | c05349e | 2010-08-04 16:57:49 +0000 | [diff] [blame] | 1684 | /// CGBlockInfo - Information to generate a block literal. |
| 1685 | class CGBlockInfo { |
| 1686 | public: |
| 1687 | /// Name - The name of the block, kindof. |
| 1688 | const char *Name; |
| 1689 | |
| 1690 | /// DeclRefs - Variables from parent scopes that have been |
| 1691 | /// imported into this block. |
| 1692 | llvm::SmallVector<const BlockDeclRefExpr *, 8> DeclRefs; |
| 1693 | |
| 1694 | /// InnerBlocks - This block and the blocks it encloses. |
| 1695 | llvm::SmallPtrSet<const DeclContext *, 4> InnerBlocks; |
| 1696 | |
| 1697 | /// CXXThisRef - Non-null if 'this' was required somewhere, in |
| 1698 | /// which case this is that expression. |
| 1699 | const CXXThisExpr *CXXThisRef; |
| 1700 | |
| 1701 | /// NeedsObjCSelf - True if something in this block has an implicit |
| 1702 | /// reference to 'self'. |
| 1703 | bool NeedsObjCSelf; |
| 1704 | |
| 1705 | /// These are initialized by GenerateBlockFunction. |
| 1706 | bool BlockHasCopyDispose; |
| 1707 | CharUnits BlockSize; |
| 1708 | CharUnits BlockAlign; |
| 1709 | llvm::SmallVector<const Expr*, 8> BlockLayout; |
| 1710 | |
| 1711 | CGBlockInfo(const char *Name); |
| 1712 | }; |
| 1713 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 1714 | } // end namespace CodeGen |
| 1715 | } // end namespace clang |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 1716 | |
| 1717 | #endif |