Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1 | //===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 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. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 10 | // This is the internal per-function state used for llvm translation. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | ef52a2f | 2008-02-29 17:10:38 +0000 | [diff] [blame] | 14 | #ifndef CLANG_CODEGEN_CODEGENFUNCTION_H |
| 15 | #define CLANG_CODEGEN_CODEGENFUNCTION_H |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
Argyrios Kyrtzidis | e3a09e6 | 2008-09-10 02:36:38 +0000 | [diff] [blame] | 18 | #include "clang/AST/ExprCXX.h" |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 19 | #include "clang/AST/ExprObjC.h" |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/CharUnits.h" |
Chris Lattner | 481769b | 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 | 6924382 | 2009-07-13 04:10:07 +0000 | [diff] [blame] | 25 | #include "CodeGenModule.h" |
Mike Stump | 96bd13a | 2009-03-04 15:32:52 +0000 | [diff] [blame] | 26 | #include "CGBlocks.h" |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 27 | #include "CGBuilder.h" |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 28 | #include "CGCall.h" |
Anders Carlsson | b14095a | 2009-04-17 00:06:03 +0000 | [diff] [blame] | 29 | #include "CGCXX.h" |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 30 | #include "CGValue.h" |
| 31 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | namespace llvm { |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 33 | class BasicBlock; |
Benjamin Kramer | f21efe9 | 2009-08-11 17:46:57 +0000 | [diff] [blame] | 34 | class LLVMContext; |
David Chisnall | dd5c98f | 2010-05-01 11:15:56 +0000 | [diff] [blame] | 35 | class MDNode; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 36 | class Module; |
Daniel Dunbar | 898d508 | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 37 | class SwitchInst; |
Daniel Dunbar | 259e9cc | 2009-10-19 01:21:05 +0000 | [diff] [blame] | 38 | class Twine; |
Daniel Dunbar | ed3849b | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 39 | class Value; |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 40 | class CallSite; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | namespace clang { |
| 44 | class ASTContext; |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 45 | class CXXDestructorDecl; |
Anders Carlsson | 6815e94 | 2009-09-27 18:58:34 +0000 | [diff] [blame] | 46 | class CXXTryStmt; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 47 | class Decl; |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 48 | class EnumConstantDecl; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 49 | class FunctionDecl; |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 50 | class FunctionProtoType; |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 51 | class LabelStmt; |
Fariborz Jahanian | 679a502 | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 52 | class ObjCContainerDecl; |
Daniel Dunbar | 29e0bcc | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 53 | class ObjCInterfaceDecl; |
| 54 | class ObjCIvarDecl; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 55 | class ObjCMethodDecl; |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 56 | class ObjCImplementationDecl; |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 57 | class ObjCPropertyImplDecl; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 58 | class TargetInfo; |
John McCall | 492c4f9 | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 59 | class TargetCodeGenInfo; |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 60 | class VarDecl; |
Chris Lattner | 16f0049 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 61 | class ObjCForCollectionStmt; |
| 62 | class ObjCAtTryStmt; |
| 63 | class ObjCAtThrowStmt; |
| 64 | class ObjCAtSynchronizedStmt; |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 65 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 66 | namespace CodeGen { |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 67 | class CodeGenTypes; |
Anders Carlsson | e896d98 | 2009-02-13 08:11:52 +0000 | [diff] [blame] | 68 | class CGDebugInfo; |
Daniel Dunbar | bb36d33 | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 69 | class CGFunctionInfo; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 70 | class CGRecordLayout; |
John McCall | ee50429 | 2010-05-21 04:11:14 +0000 | [diff] [blame] | 71 | class CGBlockInfo; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 72 | |
John McCall | f1549f6 | 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 { |
| 80 | /// The origin of the branch. Any switch-index stores required by |
| 81 | /// cleanup threading are added before this instruction. |
| 82 | llvm::Instruction *Origin; |
| 83 | |
| 84 | /// The destination of the branch. |
| 85 | /// |
| 86 | /// This can be set to null to indicate that this fixup was |
| 87 | /// successfully resolved. |
| 88 | llvm::BasicBlock *Destination; |
| 89 | |
| 90 | /// The last branch of the fixup. It is an invariant that |
| 91 | /// LatestBranch->getSuccessor(LatestBranchIndex) == Destination. |
| 92 | /// |
| 93 | /// The branch is always either a BranchInst or a SwitchInst. |
| 94 | llvm::TerminatorInst *LatestBranch; |
| 95 | unsigned LatestBranchIndex; |
| 96 | }; |
| 97 | |
| 98 | /// A stack of scopes which respond to exceptions, including cleanups |
| 99 | /// and catch blocks. |
| 100 | class EHScopeStack { |
| 101 | public: |
| 102 | /// A saved depth on the scope stack. This is necessary because |
| 103 | /// pushing scopes onto the stack invalidates iterators. |
| 104 | class stable_iterator { |
| 105 | friend class EHScopeStack; |
| 106 | |
| 107 | /// Offset from StartOfData to EndOfBuffer. |
| 108 | ptrdiff_t Size; |
| 109 | |
| 110 | stable_iterator(ptrdiff_t Size) : Size(Size) {} |
| 111 | |
| 112 | public: |
| 113 | static stable_iterator invalid() { return stable_iterator(-1); } |
| 114 | stable_iterator() : Size(-1) {} |
| 115 | |
| 116 | bool isValid() const { return Size >= 0; } |
| 117 | |
| 118 | friend bool operator==(stable_iterator A, stable_iterator B) { |
| 119 | return A.Size == B.Size; |
| 120 | } |
| 121 | friend bool operator!=(stable_iterator A, stable_iterator B) { |
| 122 | return A.Size != B.Size; |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | private: |
| 127 | // The implementation for this class is in CGException.h and |
| 128 | // CGException.cpp; the definition is here because it's used as a |
| 129 | // member of CodeGenFunction. |
| 130 | |
| 131 | /// The start of the scope-stack buffer, i.e. the allocated pointer |
| 132 | /// for the buffer. All of these pointers are either simultaneously |
| 133 | /// null or simultaneously valid. |
| 134 | char *StartOfBuffer; |
| 135 | |
| 136 | /// The end of the buffer. |
| 137 | char *EndOfBuffer; |
| 138 | |
| 139 | /// The first valid entry in the buffer. |
| 140 | char *StartOfData; |
| 141 | |
| 142 | /// The innermost normal cleanup on the stack. |
| 143 | stable_iterator InnermostNormalCleanup; |
| 144 | |
| 145 | /// The innermost EH cleanup on the stack. |
| 146 | stable_iterator InnermostEHCleanup; |
| 147 | |
| 148 | /// The number of catches on the stack. |
| 149 | unsigned CatchDepth; |
| 150 | |
| 151 | /// The current set of branch fixups. A branch fixup is a jump to |
| 152 | /// an as-yet unemitted label, i.e. a label for which we don't yet |
| 153 | /// know the EH stack depth. Whenever we pop a cleanup, we have |
| 154 | /// to thread all the current branch fixups through it. |
| 155 | /// |
| 156 | /// Fixups are recorded as the Use of the respective branch or |
| 157 | /// switch statement. The use points to the final destination. |
| 158 | /// When popping out of a cleanup, these uses are threaded through |
| 159 | /// the cleanup and adjusted to point to the new cleanup. |
| 160 | /// |
| 161 | /// Note that branches are allowed to jump into protected scopes |
| 162 | /// in certain situations; e.g. the following code is legal: |
| 163 | /// struct A { ~A(); }; // trivial ctor, non-trivial dtor |
| 164 | /// goto foo; |
| 165 | /// A a; |
| 166 | /// foo: |
| 167 | /// bar(); |
| 168 | llvm::SmallVector<BranchFixup, 8> BranchFixups; |
| 169 | |
| 170 | char *allocate(size_t Size); |
| 171 | |
| 172 | void popNullFixups(); |
| 173 | |
| 174 | public: |
| 175 | EHScopeStack() : StartOfBuffer(0), EndOfBuffer(0), StartOfData(0), |
| 176 | InnermostNormalCleanup(stable_end()), |
| 177 | InnermostEHCleanup(stable_end()), |
| 178 | CatchDepth(0) {} |
| 179 | ~EHScopeStack() { delete[] StartOfBuffer; } |
| 180 | |
| 181 | /// Push a cleanup on the stack. |
| 182 | void pushCleanup(llvm::BasicBlock *NormalEntry, |
| 183 | llvm::BasicBlock *NormalExit, |
| 184 | llvm::BasicBlock *EHEntry, |
| 185 | llvm::BasicBlock *EHExit); |
| 186 | |
| 187 | /// Pops a cleanup scope off the stack. This should only be called |
| 188 | /// by CodeGenFunction::PopCleanupBlock. |
| 189 | void popCleanup(); |
| 190 | |
| 191 | /// Push a set of catch handlers on the stack. The catch is |
| 192 | /// uninitialized and will need to have the given number of handlers |
| 193 | /// set on it. |
| 194 | class EHCatchScope *pushCatch(unsigned NumHandlers); |
| 195 | |
| 196 | /// Pops a catch scope off the stack. |
| 197 | void popCatch(); |
| 198 | |
| 199 | /// Push an exceptions filter on the stack. |
| 200 | class EHFilterScope *pushFilter(unsigned NumFilters); |
| 201 | |
| 202 | /// Pops an exceptions filter off the stack. |
| 203 | void popFilter(); |
| 204 | |
| 205 | /// Push a terminate handler on the stack. |
| 206 | void pushTerminate(); |
| 207 | |
| 208 | /// Pops a terminate handler off the stack. |
| 209 | void popTerminate(); |
| 210 | |
| 211 | /// Determines whether the exception-scopes stack is empty. |
| 212 | bool empty() const { return StartOfData == EndOfBuffer; } |
| 213 | |
| 214 | bool requiresLandingPad() const { |
| 215 | return (CatchDepth || hasEHCleanups()); |
| 216 | } |
| 217 | |
| 218 | /// Determines whether there are any normal cleanups on the stack. |
| 219 | bool hasNormalCleanups() const { |
| 220 | return InnermostNormalCleanup != stable_end(); |
| 221 | } |
| 222 | |
| 223 | /// Returns the innermost normal cleanup on the stack, or |
| 224 | /// stable_end() if there are no normal cleanups. |
| 225 | stable_iterator getInnermostNormalCleanup() const { |
| 226 | return InnermostNormalCleanup; |
| 227 | } |
| 228 | |
| 229 | /// Determines whether there are any EH cleanups on the stack. |
| 230 | bool hasEHCleanups() const { |
| 231 | return InnermostEHCleanup != stable_end(); |
| 232 | } |
| 233 | |
| 234 | /// Returns the innermost EH cleanup on the stack, or stable_end() |
| 235 | /// if there are no EH cleanups. |
| 236 | stable_iterator getInnermostEHCleanup() const { |
| 237 | return InnermostEHCleanup; |
| 238 | } |
| 239 | |
| 240 | /// An unstable reference to a scope-stack depth. Invalidated by |
| 241 | /// pushes but not pops. |
| 242 | class iterator; |
| 243 | |
| 244 | /// Returns an iterator pointing to the innermost EH scope. |
| 245 | iterator begin() const; |
| 246 | |
| 247 | /// Returns an iterator pointing to the outermost EH scope. |
| 248 | iterator end() const; |
| 249 | |
| 250 | /// Create a stable reference to the top of the EH stack. The |
| 251 | /// returned reference is valid until that scope is popped off the |
| 252 | /// stack. |
| 253 | stable_iterator stable_begin() const { |
| 254 | return stable_iterator(EndOfBuffer - StartOfData); |
| 255 | } |
| 256 | |
| 257 | /// Create a stable reference to the bottom of the EH stack. |
| 258 | static stable_iterator stable_end() { |
| 259 | return stable_iterator(0); |
| 260 | } |
| 261 | |
| 262 | /// Translates an iterator into a stable_iterator. |
| 263 | stable_iterator stabilize(iterator it) const; |
| 264 | |
| 265 | /// Finds the nearest cleanup enclosing the given iterator. |
| 266 | /// Returns stable_iterator::invalid() if there are no such cleanups. |
| 267 | stable_iterator getEnclosingEHCleanup(iterator it) const; |
| 268 | |
| 269 | /// Turn a stable reference to a scope depth into a unstable pointer |
| 270 | /// to the EH stack. |
| 271 | iterator find(stable_iterator save) const; |
| 272 | |
| 273 | /// Removes the cleanup pointed to by the given stable_iterator. |
| 274 | void removeCleanup(stable_iterator save); |
| 275 | |
| 276 | /// Add a branch fixup to the current cleanup scope. |
| 277 | BranchFixup &addBranchFixup() { |
| 278 | assert(hasNormalCleanups() && "adding fixup in scope without cleanups"); |
| 279 | BranchFixups.push_back(BranchFixup()); |
| 280 | return BranchFixups.back(); |
| 281 | } |
| 282 | |
| 283 | unsigned getNumBranchFixups() const { return BranchFixups.size(); } |
| 284 | BranchFixup &getBranchFixup(unsigned I) { |
| 285 | assert(I < getNumBranchFixups()); |
| 286 | return BranchFixups[I]; |
| 287 | } |
| 288 | |
| 289 | /// Mark any branch fixups leading to the given block as resolved. |
| 290 | void resolveBranchFixups(llvm::BasicBlock *Dest); |
| 291 | }; |
| 292 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 293 | /// CodeGenFunction - This class organizes the per-function state that is used |
| 294 | /// while generating LLVM code. |
Mike Stump | 2a99814 | 2009-03-04 18:17:45 +0000 | [diff] [blame] | 295 | class CodeGenFunction : public BlockFunction { |
Anders Carlsson | 8a219ce | 2009-02-24 04:21:31 +0000 | [diff] [blame] | 296 | CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT |
| 297 | void operator=(const CodeGenFunction&); // DO NOT IMPLEMENT |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 298 | public: |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 299 | /// A jump destination is a pair of a basic block and a cleanup |
| 300 | /// depth. They are used to implement direct jumps across cleanup |
| 301 | /// scopes, e.g. goto, break, continue, and return. |
| 302 | struct JumpDest { |
| 303 | JumpDest() : Block(0), ScopeDepth() {} |
| 304 | JumpDest(llvm::BasicBlock *Block, EHScopeStack::stable_iterator Depth) |
| 305 | : Block(Block), ScopeDepth(Depth) {} |
| 306 | |
| 307 | llvm::BasicBlock *Block; |
| 308 | EHScopeStack::stable_iterator ScopeDepth; |
| 309 | }; |
| 310 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 311 | CodeGenModule &CGM; // Per-module state. |
Daniel Dunbar | 444be73 | 2009-11-13 05:51:54 +0000 | [diff] [blame] | 312 | const TargetInfo &Target; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 313 | |
Chris Lattner | 58dee10 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 314 | typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 315 | CGBuilderTy Builder; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 316 | |
Chris Lattner | b5437d2 | 2009-04-23 05:30:27 +0000 | [diff] [blame] | 317 | /// CurFuncDecl - Holds the Decl for the current function or ObjC method. |
| 318 | /// This excludes BlockDecls. |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 319 | const Decl *CurFuncDecl; |
Chris Lattner | b5437d2 | 2009-04-23 05:30:27 +0000 | [diff] [blame] | 320 | /// CurCodeDecl - This is the inner-most code context, which includes blocks. |
| 321 | const Decl *CurCodeDecl; |
Daniel Dunbar | 88b5396 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 322 | const CGFunctionInfo *CurFnInfo; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 323 | QualType FnRetTy; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 324 | llvm::Function *CurFn; |
| 325 | |
Mike Stump | 6a1e0eb | 2009-12-04 23:26:17 +0000 | [diff] [blame] | 326 | /// CurGD - The GlobalDecl for the current function being compiled. |
| 327 | GlobalDecl CurGD; |
Mike Stump | 6a1e0eb | 2009-12-04 23:26:17 +0000 | [diff] [blame] | 328 | |
Daniel Dunbar | 5ca2084 | 2008-09-09 21:00:17 +0000 | [diff] [blame] | 329 | /// ReturnBlock - Unified return block. |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 330 | JumpDest ReturnBlock; |
| 331 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 332 | /// ReturnValue - The temporary alloca to hold the return value. This is null |
| 333 | /// iff the function has no return value. |
Eli Friedman | b17daf9 | 2009-12-04 02:43:40 +0000 | [diff] [blame] | 334 | llvm::Value *ReturnValue; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 335 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 336 | /// AllocaInsertPoint - This is an instruction in the entry block before which |
| 337 | /// we prefer to insert allocas. |
Chris Lattner | 481769b | 2009-03-31 22:17:44 +0000 | [diff] [blame] | 338 | llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; |
Daniel Dunbar | 0ffb125 | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 339 | |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 340 | // intptr_t, i32, i64 |
| 341 | const llvm::IntegerType *IntPtrTy, *Int32Ty, *Int64Ty; |
Hartmut Kaiser | 7b66000 | 2007-10-17 15:00:17 +0000 | [diff] [blame] | 342 | uint32_t LLVMPointerWidth; |
Daniel Dunbar | 18ccc77 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 343 | |
Mike Stump | d88ea56 | 2009-12-09 03:35:49 +0000 | [diff] [blame] | 344 | bool Exceptions; |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 345 | bool CatchUndefined; |
Douglas Gregor | 3d91bbc | 2010-05-17 15:52:46 +0000 | [diff] [blame] | 346 | |
| 347 | /// \brief A mapping from NRVO variables to the flags used to indicate |
| 348 | /// when the NRVO has been applied to this variable. |
| 349 | llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags; |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 350 | |
| 351 | EHScopeStack EHStack; |
| 352 | |
| 353 | /// The exception slot. All landing pads write the current |
| 354 | /// exception pointer into this alloca. |
| 355 | llvm::Value *ExceptionSlot; |
| 356 | |
| 357 | /// Emits a landing pad for the current EH stack. |
| 358 | llvm::BasicBlock *EmitLandingPad(); |
| 359 | |
| 360 | llvm::BasicBlock *getInvokeDestImpl(); |
| 361 | |
Daniel Dunbar | 18ccc77 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 362 | public: |
Anders Carlsson | fa1f756 | 2009-02-10 06:07:49 +0000 | [diff] [blame] | 363 | /// ObjCEHValueStack - Stack of Objective-C exception values, used for |
| 364 | /// rethrows. |
Anders Carlsson | 273558f | 2009-02-07 21:37:21 +0000 | [diff] [blame] | 365 | llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 366 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 367 | // A struct holding information about a finally block's IR |
| 368 | // generation. For now, doesn't actually hold anything. |
| 369 | struct FinallyInfo { |
Anders Carlsson | bb66f9f | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 370 | }; |
| 371 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 372 | FinallyInfo EnterFinallyBlock(const Stmt *Stmt, |
| 373 | llvm::Constant *BeginCatchFn, |
| 374 | llvm::Constant *EndCatchFn, |
| 375 | llvm::Constant *RethrowFn); |
| 376 | void ExitFinallyBlock(FinallyInfo &FinallyInfo); |
Mike Stump | d88ea56 | 2009-12-09 03:35:49 +0000 | [diff] [blame] | 377 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 378 | enum CleanupKind { NormalAndEHCleanup, EHCleanup, NormalCleanup }; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 379 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 380 | /// PushDestructorCleanup - Push a cleanup to call the |
| 381 | /// complete-object destructor of an object of the given type at the |
| 382 | /// given address. Does nothing if T is not a C++ class type with a |
| 383 | /// non-trivial destructor. |
| 384 | void PushDestructorCleanup(QualType T, llvm::Value *Addr); |
| 385 | |
| 386 | /// PopCleanupBlock - Will pop the cleanup entry on the stack and |
| 387 | /// process all branch fixups. |
| 388 | void PopCleanupBlock(); |
| 389 | |
| 390 | /// CleanupBlock - RAII object that will create a cleanup block and |
| 391 | /// set the insert point to that block. When destructed, it sets the |
| 392 | /// insert point to the previous block and pushes a new cleanup |
| 393 | /// entry on the stack. |
| 394 | class CleanupBlock { |
| 395 | CodeGenFunction &CGF; |
| 396 | CGBuilderTy::InsertPoint SavedIP; |
| 397 | llvm::BasicBlock *NormalCleanupEntryBB; |
| 398 | llvm::BasicBlock *NormalCleanupExitBB; |
| 399 | llvm::BasicBlock *EHCleanupEntryBB; |
Fariborz Jahanian | 7799621 | 2009-11-04 17:57:40 +0000 | [diff] [blame] | 400 | |
Anders Carlsson | 0d5c685 | 2009-02-07 23:30:41 +0000 | [diff] [blame] | 401 | public: |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 402 | CleanupBlock(CodeGenFunction &CGF, CleanupKind Kind); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 403 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 404 | /// If we're currently writing a normal cleanup, tie that off and |
| 405 | /// start writing an EH cleanup. |
| 406 | void beginEHCleanup(); |
Fariborz Jahanian | 7799621 | 2009-11-04 17:57:40 +0000 | [diff] [blame] | 407 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 408 | ~CleanupBlock(); |
Anders Carlsson | 0d5c685 | 2009-02-07 23:30:41 +0000 | [diff] [blame] | 409 | }; |
| 410 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 411 | /// \brief Enters a new scope for capturing cleanups, all of which |
| 412 | /// will be executed once the scope is exited. |
| 413 | class RunCleanupsScope { |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 414 | CodeGenFunction& CGF; |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 415 | EHScopeStack::stable_iterator CleanupStackDepth; |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 416 | bool OldDidCallStackSave; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 417 | bool PerformCleanup; |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 418 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 419 | RunCleanupsScope(const RunCleanupsScope &); // DO NOT IMPLEMENT |
| 420 | RunCleanupsScope &operator=(const RunCleanupsScope &); // DO NOT IMPLEMENT |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 421 | |
| 422 | public: |
| 423 | /// \brief Enter a new cleanup scope. |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 424 | explicit RunCleanupsScope(CodeGenFunction &CGF) |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 425 | : CGF(CGF), PerformCleanup(true) |
| 426 | { |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 427 | CleanupStackDepth = CGF.EHStack.stable_begin(); |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 428 | OldDidCallStackSave = CGF.DidCallStackSave; |
| 429 | } |
| 430 | |
| 431 | /// \brief Exit this cleanup scope, emitting any accumulated |
| 432 | /// cleanups. |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 433 | ~RunCleanupsScope() { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 434 | if (PerformCleanup) { |
| 435 | CGF.DidCallStackSave = OldDidCallStackSave; |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 436 | CGF.PopCleanupBlocks(CleanupStackDepth); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
| 440 | /// \brief Determine whether this scope requires any cleanups. |
| 441 | bool requiresCleanups() const { |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 442 | return CGF.EHStack.stable_begin() != CleanupStackDepth; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /// \brief Force the emission of cleanups now, instead of waiting |
| 446 | /// until this object is destroyed. |
| 447 | void ForceCleanup() { |
| 448 | assert(PerformCleanup && "Already forced cleanup"); |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 449 | CGF.DidCallStackSave = OldDidCallStackSave; |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 450 | CGF.PopCleanupBlocks(CleanupStackDepth); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 451 | PerformCleanup = false; |
Douglas Gregor | 01234bb | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 452 | } |
| 453 | }; |
| 454 | |
Anders Carlsson | 44ec82b | 2010-03-30 03:14:41 +0000 | [diff] [blame] | 455 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 456 | /// PopCleanupBlocks - Takes the old cleanup stack size and emits |
| 457 | /// the cleanup blocks that have been added. |
| 458 | void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize); |
Anders Carlsson | 44ec82b | 2010-03-30 03:14:41 +0000 | [diff] [blame] | 459 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 460 | /// The given basic block lies in the current EH scope, but may be a |
| 461 | /// target of a potentially scope-crossing jump; get a stable handle |
| 462 | /// to which we can perform this jump later. |
| 463 | JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) const { |
| 464 | return JumpDest(Target, EHStack.stable_begin()); |
| 465 | } |
Anders Carlsson | c71c845 | 2009-02-07 23:50:39 +0000 | [diff] [blame] | 466 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 467 | /// The given basic block lies in the current EH scope, but may be a |
| 468 | /// target of a potentially scope-crossing jump; get a stable handle |
| 469 | /// to which we can perform this jump later. |
| 470 | JumpDest getJumpDestInCurrentScope(const char *Name = 0) { |
| 471 | return JumpDest(createBasicBlock(Name), EHStack.stable_begin()); |
| 472 | } |
| 473 | |
| 474 | /// EmitBranchThroughCleanup - Emit a branch from the current insert |
| 475 | /// block through the normal cleanup handling code (if any) and then |
| 476 | /// on to \arg Dest. |
| 477 | void EmitBranchThroughCleanup(JumpDest Dest); |
| 478 | |
| 479 | /// EmitBranchThroughEHCleanup - Emit a branch from the current |
| 480 | /// insert block through the EH cleanup handling code (if any) and |
| 481 | /// then on to \arg Dest. |
| 482 | void EmitBranchThroughEHCleanup(JumpDest Dest); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 483 | |
Anders Carlsson | 72119a8 | 2010-02-04 17:18:07 +0000 | [diff] [blame] | 484 | /// BeginConditionalBranch - Should be called before a conditional part of an |
Anders Carlsson | a36bf8f | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 485 | /// expression is emitted. For example, before the RHS of the expression below |
| 486 | /// is emitted: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 487 | /// |
Anders Carlsson | 1d84750 | 2009-06-04 02:22:12 +0000 | [diff] [blame] | 488 | /// b && f(T()); |
| 489 | /// |
Anders Carlsson | a36bf8f | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 490 | /// This is used to make sure that any temporaries created in the conditional |
Anders Carlsson | 1d84750 | 2009-06-04 02:22:12 +0000 | [diff] [blame] | 491 | /// branch are only destroyed if the branch is taken. |
Anders Carlsson | 72119a8 | 2010-02-04 17:18:07 +0000 | [diff] [blame] | 492 | void BeginConditionalBranch() { |
Anders Carlsson | a36bf8f | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 493 | ++ConditionalBranchLevel; |
| 494 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | |
Anders Carlsson | 72119a8 | 2010-02-04 17:18:07 +0000 | [diff] [blame] | 496 | /// EndConditionalBranch - Should be called after a conditional part of an |
Anders Carlsson | a36bf8f | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 497 | /// expression has been emitted. |
Anders Carlsson | 72119a8 | 2010-02-04 17:18:07 +0000 | [diff] [blame] | 498 | void EndConditionalBranch() { |
Anders Carlsson | 08e9e45 | 2010-01-24 00:20:05 +0000 | [diff] [blame] | 499 | assert(ConditionalBranchLevel != 0 && |
| 500 | "Conditional branch mismatch!"); |
| 501 | |
Anders Carlsson | a36bf8f | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 502 | --ConditionalBranchLevel; |
| 503 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Chris Lattner | 7f02f72 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 505 | private: |
Chris Lattner | d9becd1 | 2009-10-28 23:59:40 +0000 | [diff] [blame] | 506 | CGDebugInfo *DebugInfo; |
Mike Stump | 09429b9 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 507 | |
Mike Stump | f71d232 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 508 | /// IndirectBranch - The first time an indirect goto is seen we create a block |
| 509 | /// with an indirect branch. Every time we see the address of a label taken, |
| 510 | /// we add the label to the indirect goto. Every subsequent indirect goto is |
| 511 | /// codegen'd as a jump to the IndirectBranch's basic block. |
Chris Lattner | d9becd1 | 2009-10-28 23:59:40 +0000 | [diff] [blame] | 512 | llvm::IndirectBrInst *IndirectBranch; |
Daniel Dunbar | 0ffb125 | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 513 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 514 | /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C |
| 515 | /// decls. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 516 | llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; |
| 517 | |
| 518 | /// LabelMap - This keeps track of the LLVM basic block for each C label. |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 519 | llvm::DenseMap<const LabelStmt*, JumpDest> LabelMap; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 520 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 521 | // BreakContinueStack - This keeps track of where break and continue |
Anders Carlsson | e4b6d34 | 2009-02-10 05:52:02 +0000 | [diff] [blame] | 522 | // statements should jump to. |
Chris Lattner | da13870 | 2007-07-16 21:28:45 +0000 | [diff] [blame] | 523 | struct BreakContinue { |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 524 | BreakContinue(JumpDest Break, JumpDest Continue) |
| 525 | : BreakBlock(Break), ContinueBlock(Continue) {} |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 526 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 527 | JumpDest BreakBlock; |
| 528 | JumpDest ContinueBlock; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 529 | }; |
Chris Lattner | da13870 | 2007-07-16 21:28:45 +0000 | [diff] [blame] | 530 | llvm::SmallVector<BreakContinue, 8> BreakContinueStack; |
Daniel Dunbar | 18ccc77 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 531 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 532 | /// SwitchInsn - This is nearest current switch instruction. It is null if if |
| 533 | /// current context is not in a switch. |
Devang Patel | 51b09f2 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 534 | llvm::SwitchInst *SwitchInsn; |
| 535 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 536 | /// CaseRangeBlock - This block holds if condition check for last case |
Devang Patel | 80fd5f9 | 2007-10-09 17:08:50 +0000 | [diff] [blame] | 537 | /// statement range in current switch instruction. |
Devang Patel | c049e4f | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 538 | llvm::BasicBlock *CaseRangeBlock; |
| 539 | |
Daniel Dunbar | 9834ffb | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 540 | /// InvokeDest - This is the nearest exception target for calls |
| 541 | /// which can unwind, when exceptions are being used. |
| 542 | llvm::BasicBlock *InvokeDest; |
| 543 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 544 | // VLASizeMap - This keeps track of the associated size for each VLA type. |
Eli Friedman | bbed6b9 | 2009-08-15 02:50:32 +0000 | [diff] [blame] | 545 | // We track this by the size expression rather than the type itself because |
| 546 | // in certain situations, like a const qualifier applied to an VLA typedef, |
| 547 | // multiple VLA types can share the same size expression. |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 548 | // FIXME: Maybe this could be a stack of maps that is pushed/popped as we |
| 549 | // enter/leave scopes. |
Eli Friedman | bbed6b9 | 2009-08-15 02:50:32 +0000 | [diff] [blame] | 550 | llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 551 | |
Anders Carlsson | 4cc1a47 | 2009-02-09 20:20:56 +0000 | [diff] [blame] | 552 | /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid |
| 553 | /// calling llvm.stacksave for multiple VLAs in the same scope. |
| 554 | bool DidCallStackSave; |
Mike Stump | 09429b9 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 555 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 556 | /// A block containing a single 'unreachable' instruction. Created |
| 557 | /// lazily by getUnreachableBlock(). |
| 558 | llvm::BasicBlock *UnreachableBlock; |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 559 | |
Anders Carlsson | f6c56e2 | 2009-11-25 03:15:49 +0000 | [diff] [blame] | 560 | /// CXXThisDecl - When generating code for a C++ member function, |
| 561 | /// this will hold the implicit 'this' declaration. |
Anders Carlsson | 2b77ba8 | 2009-04-04 20:47:02 +0000 | [diff] [blame] | 562 | ImplicitParamDecl *CXXThisDecl; |
John McCall | 2504941 | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 563 | llvm::Value *CXXThisValue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 564 | |
Anders Carlsson | f6c56e2 | 2009-11-25 03:15:49 +0000 | [diff] [blame] | 565 | /// CXXVTTDecl - When generating code for a base object constructor or |
| 566 | /// base object destructor with virtual bases, this will hold the implicit |
| 567 | /// VTT parameter. |
| 568 | ImplicitParamDecl *CXXVTTDecl; |
John McCall | 2504941 | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 569 | llvm::Value *CXXVTTValue; |
Anders Carlsson | f6c56e2 | 2009-11-25 03:15:49 +0000 | [diff] [blame] | 570 | |
Anders Carlsson | a36bf8f | 2009-11-20 17:27:56 +0000 | [diff] [blame] | 571 | /// ConditionalBranchLevel - Contains the nesting level of the current |
| 572 | /// conditional branch. This is used so that we know if a temporary should be |
| 573 | /// destroyed conditionally. |
| 574 | unsigned ConditionalBranchLevel; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 575 | |
Anders Carlsson | 7dfa407 | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 576 | |
| 577 | /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM |
| 578 | /// type as well as the field number that contains the actual data. |
| 579 | llvm::DenseMap<const ValueDecl *, std::pair<const llvm::Type *, |
| 580 | unsigned> > ByRefValueInfo; |
| 581 | |
| 582 | /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field |
| 583 | /// number that holds the value. |
| 584 | unsigned getByRefValueLLVMField(const ValueDecl *VD) const; |
Mike Stump | 182f383 | 2009-12-10 00:02:42 +0000 | [diff] [blame] | 585 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 586 | llvm::BasicBlock *TerminateLandingPad; |
Mike Stump | 182f383 | 2009-12-10 00:02:42 +0000 | [diff] [blame] | 587 | llvm::BasicBlock *TerminateHandler; |
Mike Stump | 15037ca | 2009-12-15 00:35:12 +0000 | [diff] [blame] | 588 | llvm::BasicBlock *TrapBB; |
Eli Friedman | 9406705 | 2009-12-10 02:21:21 +0000 | [diff] [blame] | 589 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 590 | public: |
| 591 | CodeGenFunction(CodeGenModule &cgm); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 592 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 593 | ASTContext &getContext() const; |
Anders Carlsson | e896d98 | 2009-02-13 08:11:52 +0000 | [diff] [blame] | 594 | CGDebugInfo *getDebugInfo() { return DebugInfo; } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 595 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 596 | /// Returns a pointer to the function's exception object slot, which |
| 597 | /// is assigned in every landing pad. |
| 598 | llvm::Value *getExceptionSlot(); |
| 599 | |
| 600 | llvm::BasicBlock *getUnreachableBlock() { |
| 601 | if (!UnreachableBlock) { |
| 602 | UnreachableBlock = createBasicBlock("unreachable"); |
| 603 | new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock); |
| 604 | } |
| 605 | return UnreachableBlock; |
| 606 | } |
| 607 | |
| 608 | llvm::BasicBlock *getInvokeDest() { |
| 609 | if (!EHStack.requiresLandingPad()) return 0; |
| 610 | return getInvokeDestImpl(); |
| 611 | } |
Daniel Dunbar | 9834ffb | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 612 | |
Owen Anderson | a1cf15f | 2009-07-14 23:10:40 +0000 | [diff] [blame] | 613 | llvm::LLVMContext &getLLVMContext() { return VMContext; } |
Owen Anderson | 6924382 | 2009-07-13 04:10:07 +0000 | [diff] [blame] | 614 | |
Daniel Dunbar | 9834ffb | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 615 | //===--------------------------------------------------------------------===// |
| 616 | // Objective-C |
| 617 | //===--------------------------------------------------------------------===// |
| 618 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 619 | void GenerateObjCMethod(const ObjCMethodDecl *OMD); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 620 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 621 | void StartObjCMethod(const ObjCMethodDecl *MD, |
Fariborz Jahanian | 679a502 | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 622 | const ObjCContainerDecl *CD); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 623 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 624 | /// GenerateObjCGetter - Synthesize an Objective-C property getter function. |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 625 | void GenerateObjCGetter(ObjCImplementationDecl *IMP, |
| 626 | const ObjCPropertyImplDecl *PID); |
Fariborz Jahanian | 109dfc6 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 627 | void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, |
| 628 | ObjCMethodDecl *MD, bool ctor); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 629 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 630 | /// GenerateObjCSetter - Synthesize an Objective-C property setter function |
| 631 | /// for the given property. |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 632 | void GenerateObjCSetter(ObjCImplementationDecl *IMP, |
| 633 | const ObjCPropertyImplDecl *PID); |
Fariborz Jahanian | 0b2bd47 | 2010-04-13 00:38:05 +0000 | [diff] [blame] | 634 | bool IndirectObjCSetterArg(const CGFunctionInfo &FI); |
Fariborz Jahanian | 15bd588 | 2010-04-13 18:32:24 +0000 | [diff] [blame] | 635 | bool IvarTypeWithAggrGCObjects(QualType Ty); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 636 | |
Mike Stump | 4e7a1f7 | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 637 | //===--------------------------------------------------------------------===// |
| 638 | // Block Bits |
| 639 | //===--------------------------------------------------------------------===// |
| 640 | |
Mike Stump | 8a2b4b1 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 641 | llvm::Value *BuildBlockLiteralTmp(const BlockExpr *); |
Blaine Garst | 2a7eb28 | 2010-02-23 21:51:17 +0000 | [diff] [blame] | 642 | llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *, |
| 643 | bool BlockHasCopyDispose, |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 644 | CharUnits Size, |
Mike Stump | 0892099 | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 645 | const llvm::StructType *, |
| 646 | std::vector<HelperInfo> *); |
Mike Stump | 4e7a1f7 | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 647 | |
Fariborz Jahanian | 564360b | 2010-06-24 00:08:06 +0000 | [diff] [blame] | 648 | llvm::Function *GenerateBlockFunction(GlobalDecl GD, |
| 649 | const BlockExpr *BExpr, |
John McCall | ee50429 | 2010-05-21 04:11:14 +0000 | [diff] [blame] | 650 | CGBlockInfo &Info, |
Mike Stump | 6cc88f7 | 2009-03-20 21:53:12 +0000 | [diff] [blame] | 651 | const Decl *OuterFuncDecl, |
John McCall | ee50429 | 2010-05-21 04:11:14 +0000 | [diff] [blame] | 652 | llvm::DenseMap<const Decl*, llvm::Value*> ldm); |
Mike Stump | 4e7a1f7 | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 653 | |
| 654 | llvm::Value *LoadBlockStruct(); |
| 655 | |
John McCall | ea1471e | 2010-05-20 01:18:31 +0000 | [diff] [blame] | 656 | void AllocateBlockCXXThisPointer(const CXXThisExpr *E); |
| 657 | void AllocateBlockDecl(const BlockDeclRefExpr *E); |
John McCall | ee50429 | 2010-05-21 04:11:14 +0000 | [diff] [blame] | 658 | llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E) { |
| 659 | return GetAddrOfBlockDecl(E->getDecl(), E->isByRef()); |
| 660 | } |
| 661 | llvm::Value *GetAddrOfBlockDecl(const ValueDecl *D, bool ByRef); |
Anders Carlsson | 9ad5513 | 2009-09-09 02:51:03 +0000 | [diff] [blame] | 662 | const llvm::Type *BuildByRefType(const ValueDecl *D); |
Mike Stump | dab514f | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 663 | |
Anders Carlsson | 0ff8baf | 2009-09-11 00:07:24 +0000 | [diff] [blame] | 664 | void GenerateCode(GlobalDecl GD, llvm::Function *Fn); |
| 665 | void StartFunction(GlobalDecl GD, QualType RetTy, |
Daniel Dunbar | 7c08651 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 666 | llvm::Function *Fn, |
Daniel Dunbar | 2284ac9 | 2008-10-18 18:22:23 +0000 | [diff] [blame] | 667 | const FunctionArgList &Args, |
| 668 | SourceLocation StartLoc); |
Daniel Dunbar | a448fb2 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 669 | |
John McCall | 9fc6a77 | 2010-02-19 09:25:03 +0000 | [diff] [blame] | 670 | void EmitConstructorBody(FunctionArgList &Args); |
| 671 | void EmitDestructorBody(FunctionArgList &Args); |
| 672 | void EmitFunctionBody(FunctionArgList &Args); |
John McCall | a355e07 | 2010-02-18 03:17:58 +0000 | [diff] [blame] | 673 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 674 | /// EmitReturnBlock - Emit the unified return block, trying to avoid its |
| 675 | /// emission when possible. |
Daniel Dunbar | 1c1d607 | 2009-01-26 23:27:52 +0000 | [diff] [blame] | 676 | void EmitReturnBlock(); |
| 677 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 678 | /// FinishFunction - Complete IR generation of the current function. It is |
| 679 | /// legal to call this function even if there is no current insertion point. |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 680 | void FinishFunction(SourceLocation EndLoc=SourceLocation()); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 681 | |
Anders Carlsson | 519c328 | 2010-03-24 00:39:18 +0000 | [diff] [blame] | 682 | /// GenerateThunk - Generate a thunk for the given method. |
| 683 | void GenerateThunk(llvm::Function *Fn, GlobalDecl GD, const ThunkInfo &Thunk); |
| 684 | |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 685 | void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, |
| 686 | FunctionArgList &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | |
Anders Carlsson | d103f9f | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 688 | /// InitializeVTablePointer - Initialize the vtable pointer of the given |
| 689 | /// subobject. |
| 690 | /// |
Anders Carlsson | b3b772e | 2010-04-20 05:22:15 +0000 | [diff] [blame] | 691 | void InitializeVTablePointer(BaseSubobject Base, |
| 692 | const CXXRecordDecl *NearestVBase, |
Anders Carlsson | 4235840 | 2010-05-03 00:07:07 +0000 | [diff] [blame] | 693 | uint64_t OffsetFromNearestVBase, |
Anders Carlsson | d103f9f | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 694 | llvm::Constant *VTable, |
| 695 | const CXXRecordDecl *VTableClass); |
| 696 | |
| 697 | typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy; |
Anders Carlsson | b3b772e | 2010-04-20 05:22:15 +0000 | [diff] [blame] | 698 | void InitializeVTablePointers(BaseSubobject Base, |
| 699 | const CXXRecordDecl *NearestVBase, |
Anders Carlsson | 4235840 | 2010-05-03 00:07:07 +0000 | [diff] [blame] | 700 | uint64_t OffsetFromNearestVBase, |
Anders Carlsson | 603d6d1 | 2010-03-28 21:07:49 +0000 | [diff] [blame] | 701 | bool BaseIsNonVirtualPrimaryBase, |
| 702 | llvm::Constant *VTable, |
| 703 | const CXXRecordDecl *VTableClass, |
| 704 | VisitedVirtualBasesSetTy& VBases); |
Eli Friedman | 77a259c | 2009-12-08 06:46:18 +0000 | [diff] [blame] | 705 | |
Anders Carlsson | 603d6d1 | 2010-03-28 21:07:49 +0000 | [diff] [blame] | 706 | void InitializeVTablePointers(const CXXRecordDecl *ClassDecl); |
Anders Carlsson | d103f9f | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 707 | |
| 708 | |
Fariborz Jahanian | 426cc38 | 2009-07-30 17:49:11 +0000 | [diff] [blame] | 709 | /// EmitDtorEpilogue - Emit all code that comes at the end of class's |
Mike Stump | f71d232 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 710 | /// destructor. This is to call destructors on members and base classes in |
| 711 | /// reverse order of their construction. |
Anders Carlsson | de1d26b | 2009-09-14 05:32:02 +0000 | [diff] [blame] | 712 | void EmitDtorEpilogue(const CXXDestructorDecl *Dtor, |
| 713 | CXXDtorType Type); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 714 | |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 715 | /// ShouldInstrumentFunction - Return true if the current function should be |
| 716 | /// instrumented with __cyg_profile_func_* calls |
| 717 | bool ShouldInstrumentFunction(); |
| 718 | |
| 719 | /// EmitFunctionInstrumentation - Emit LLVM code to call the specified |
| 720 | /// instrumentation function with the current function and the call site, if |
| 721 | /// function instrumentation is enabled. |
| 722 | void EmitFunctionInstrumentation(const char *Fn); |
| 723 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 724 | /// EmitFunctionProlog - Emit the target specific LLVM code to load the |
| 725 | /// arguments for the given function. This is also responsible for naming the |
| 726 | /// LLVM function arguments. |
Daniel Dunbar | 88b5396 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 727 | void EmitFunctionProlog(const CGFunctionInfo &FI, |
| 728 | llvm::Function *Fn, |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 729 | const FunctionArgList &Args); |
| 730 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 731 | /// EmitFunctionEpilog - Emit the target specific LLVM code to return the |
| 732 | /// given temporary. |
Chris Lattner | 35b21b8 | 2010-06-27 01:06:27 +0000 | [diff] [blame] | 733 | void EmitFunctionEpilog(const CGFunctionInfo &FI); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 734 | |
Mike Stump | cce3d4f | 2009-12-07 23:38:24 +0000 | [diff] [blame] | 735 | /// EmitStartEHSpec - Emit the start of the exception spec. |
| 736 | void EmitStartEHSpec(const Decl *D); |
| 737 | |
| 738 | /// EmitEndEHSpec - Emit the end of the exception spec. |
| 739 | void EmitEndEHSpec(const Decl *D); |
| 740 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 741 | /// getTerminateLandingPad - Return a landing pad that just calls terminate. |
| 742 | llvm::BasicBlock *getTerminateLandingPad(); |
| 743 | |
| 744 | /// getTerminateHandler - Return a handler (not a landing pad, just |
| 745 | /// a catch handler) that just calls terminate. This is used when |
| 746 | /// a terminate scope encloses a try. |
Mike Stump | 9b39c51 | 2009-12-09 22:59:31 +0000 | [diff] [blame] | 747 | llvm::BasicBlock *getTerminateHandler(); |
| 748 | |
Daniel Dunbar | 8b1a343 | 2009-02-03 23:03:55 +0000 | [diff] [blame] | 749 | const llvm::Type *ConvertTypeForMem(QualType T); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 750 | const llvm::Type *ConvertType(QualType T); |
John McCall | bff225e | 2010-02-16 04:15:37 +0000 | [diff] [blame] | 751 | const llvm::Type *ConvertType(const TypeDecl *T) { |
| 752 | return ConvertType(getContext().getTypeDeclType(T)); |
| 753 | } |
Chris Lattner | c8aa5f1 | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 754 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 755 | /// LoadObjCSelf - Load the value of self. This function is only valid while |
| 756 | /// generating code for an Objective-C method. |
Chris Lattner | c8aa5f1 | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 757 | llvm::Value *LoadObjCSelf(); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 758 | |
| 759 | /// TypeOfSelfObject - Return type of object that this self represents. |
Fariborz Jahanian | 45012a7 | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 760 | QualType TypeOfSelfObject(); |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 761 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 762 | /// hasAggregateLLVMType - Return true if the specified AST type will map into |
| 763 | /// an aggregate LLVM type or is void. |
| 764 | static bool hasAggregateLLVMType(QualType T); |
Daniel Dunbar | 55e8742 | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 765 | |
| 766 | /// createBasicBlock - Create an LLVM basic block. |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 767 | llvm::BasicBlock *createBasicBlock(const char *Name="", |
Daniel Dunbar | 55e8742 | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 768 | llvm::Function *Parent=0, |
| 769 | llvm::BasicBlock *InsertBefore=0) { |
Daniel Dunbar | 29ea672 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 770 | #ifdef NDEBUG |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 771 | return llvm::BasicBlock::Create(VMContext, "", Parent, InsertBefore); |
Daniel Dunbar | 29ea672 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 772 | #else |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 773 | return llvm::BasicBlock::Create(VMContext, Name, Parent, InsertBefore); |
Daniel Dunbar | 29ea672 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 774 | #endif |
Daniel Dunbar | 55e8742 | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 775 | } |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 776 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 777 | /// getBasicBlockForLabel - Return the LLVM basicblock that the specified |
| 778 | /// label maps to. |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 779 | JumpDest getJumpDestForLabel(const LabelStmt *S); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 780 | |
Mike Stump | f71d232 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 781 | /// SimplifyForwardingBlocks - If the given basic block is only a branch to |
| 782 | /// another basic block, simplify it. This assumes that no other code could |
| 783 | /// potentially reference the basic block. |
Daniel Dunbar | aa5bd87 | 2009-04-01 04:37:47 +0000 | [diff] [blame] | 784 | void SimplifyForwardingBlocks(llvm::BasicBlock *BB); |
| 785 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 786 | /// EmitBlock - Emit the given block \arg BB and set it as the insert point, |
| 787 | /// adding a fall-through branch from the current insert block if |
| 788 | /// necessary. It is legal to call this function even if there is no current |
| 789 | /// insertion point. |
Daniel Dunbar | a0c21a8 | 2008-11-13 01:24:05 +0000 | [diff] [blame] | 790 | /// |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 791 | /// IsFinished - If true, indicates that the caller has finished emitting |
| 792 | /// branches to the given block and does not expect to emit code into it. This |
| 793 | /// means the block can be ignored if it is unreachable. |
Daniel Dunbar | a0c21a8 | 2008-11-13 01:24:05 +0000 | [diff] [blame] | 794 | void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); |
Daniel Dunbar | 824e3bd | 2008-11-11 04:34:23 +0000 | [diff] [blame] | 795 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 796 | /// EmitBranch - Emit a branch to the specified basic block from the current |
| 797 | /// insert block, taking care to avoid creation of branches from dummy |
| 798 | /// blocks. It is legal to call this function even if there is no current |
| 799 | /// insertion point. |
Daniel Dunbar | 5e08ad3 | 2008-11-11 22:06:59 +0000 | [diff] [blame] | 800 | /// |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 801 | /// This function clears the current insertion point. The caller should follow |
| 802 | /// calls to this function with calls to Emit*Block prior to generation new |
| 803 | /// code. |
Daniel Dunbar | d57a871 | 2008-11-11 09:41:28 +0000 | [diff] [blame] | 804 | void EmitBranch(llvm::BasicBlock *Block); |
| 805 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 806 | /// HaveInsertPoint - True if an insertion point is defined. If not, this |
| 807 | /// indicates that the current code being emitted is unreachable. |
| 808 | bool HaveInsertPoint() const { |
Daniel Dunbar | a448fb2 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 809 | return Builder.GetInsertBlock() != 0; |
| 810 | } |
| 811 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 812 | /// EnsureInsertPoint - Ensure that an insertion point is defined so that |
| 813 | /// emitted IR has a place to go. Note that by definition, if this function |
| 814 | /// creates a block then that block is unreachable; callers may do better to |
| 815 | /// detect when no insertion point is defined and simply skip IR generation. |
Daniel Dunbar | a448fb2 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 816 | void EnsureInsertPoint() { |
| 817 | if (!HaveInsertPoint()) |
| 818 | EmitBlock(createBasicBlock()); |
| 819 | } |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 820 | |
Daniel Dunbar | 488e993 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 821 | /// ErrorUnsupported - Print out an error that codegen doesn't support the |
Chris Lattner | dc5e826 | 2007-12-02 01:43:38 +0000 | [diff] [blame] | 822 | /// specified stmt yet. |
Daniel Dunbar | 90df4b6 | 2008-09-04 03:43:08 +0000 | [diff] [blame] | 823 | void ErrorUnsupported(const Stmt *S, const char *Type, |
| 824 | bool OmitOnError=false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 825 | |
| 826 | //===--------------------------------------------------------------------===// |
| 827 | // Helpers |
| 828 | //===--------------------------------------------------------------------===// |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 829 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 830 | Qualifiers MakeQualifiers(QualType T) { |
Mike Stump | df317bf | 2009-11-03 23:25:48 +0000 | [diff] [blame] | 831 | Qualifiers Quals = getContext().getCanonicalType(T).getQualifiers(); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 832 | Quals.setObjCGCAttr(getContext().getObjCGCAttrKind(T)); |
| 833 | return Quals; |
| 834 | } |
| 835 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 836 | /// CreateTempAlloca - This creates a alloca and inserts it into the entry |
Daniel Dunbar | 195337d | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 837 | /// block. The caller is responsible for setting an appropriate alignment on |
| 838 | /// the alloca. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 839 | llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, |
Daniel Dunbar | 259e9cc | 2009-10-19 01:21:05 +0000 | [diff] [blame] | 840 | const llvm::Twine &Name = "tmp"); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 841 | |
John McCall | ac41816 | 2010-04-22 01:10:34 +0000 | [diff] [blame] | 842 | /// InitTempAlloca - Provide an initial value for the given alloca. |
| 843 | void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value); |
| 844 | |
Daniel Dunbar | 9bd4da2 | 2010-02-16 19:44:13 +0000 | [diff] [blame] | 845 | /// CreateIRTemp - Create a temporary IR object of the given type, with |
| 846 | /// appropriate alignment. This routine should only be used when an temporary |
| 847 | /// value needs to be stored into an alloca (for example, to avoid explicit |
| 848 | /// PHI construction), but the type is the IR type, not the type appropriate |
| 849 | /// for storing in memory. |
Chris Lattner | 121b3fa | 2010-07-05 20:21:00 +0000 | [diff] [blame] | 850 | llvm::AllocaInst *CreateIRTemp(QualType T, const llvm::Twine &Name = "tmp"); |
Daniel Dunbar | 9bd4da2 | 2010-02-16 19:44:13 +0000 | [diff] [blame] | 851 | |
Daniel Dunbar | 195337d | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 852 | /// CreateMemTemp - Create a temporary memory object of the given type, with |
| 853 | /// appropriate alignment. |
Chris Lattner | 121b3fa | 2010-07-05 20:21:00 +0000 | [diff] [blame] | 854 | llvm::AllocaInst *CreateMemTemp(QualType T, const llvm::Twine &Name = "tmp"); |
Daniel Dunbar | 195337d | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 855 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 856 | /// EvaluateExprAsBool - Perform the usual unary conversions on the specified |
| 857 | /// expression and compare the result against zero, returning an Int1Ty value. |
| 858 | llvm::Value *EvaluateExprAsBool(const Expr *E); |
| 859 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 860 | /// EmitAnyExpr - Emit code to compute the specified expression which can have |
| 861 | /// any type. The result is returned as an RValue struct. If this is an |
| 862 | /// aggregate expression, the aggloc/agglocvolatile arguments indicate where |
| 863 | /// the result should be returned. |
Mike Stump | 49d1cd5 | 2009-05-26 22:03:21 +0000 | [diff] [blame] | 864 | /// |
| 865 | /// \param IgnoreResult - True if the resulting value isn't used. |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 866 | RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, |
Anders Carlsson | 14c5cbf | 2009-08-16 07:36:22 +0000 | [diff] [blame] | 867 | bool IsAggLocVolatile = false, bool IgnoreResult = false, |
| 868 | bool IsInitializer = false); |
Devang Patel | d9363c3 | 2007-09-28 21:49:18 +0000 | [diff] [blame] | 869 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 870 | // EmitVAListRef - Emit a "reference" to a va_list; this is either the address |
| 871 | // or the value of the expression, depending on how va_list is defined. |
Eli Friedman | 4fd0aa5 | 2009-01-20 17:46:04 +0000 | [diff] [blame] | 872 | llvm::Value *EmitVAListRef(const Expr *E); |
| 873 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 874 | /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will |
| 875 | /// always be accessible even if no aggregate location is provided. |
Anders Carlsson | 14c5cbf | 2009-08-16 07:36:22 +0000 | [diff] [blame] | 876 | RValue EmitAnyExprToTemp(const Expr *E, bool IsAggLocVolatile = false, |
| 877 | bool IsInitializer = false); |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 878 | |
John McCall | 3d3ec1c | 2010-04-21 10:05:39 +0000 | [diff] [blame] | 879 | /// EmitsAnyExprToMem - Emits the code necessary to evaluate an |
| 880 | /// arbitrary expression into the given memory location. |
| 881 | void EmitAnyExprToMem(const Expr *E, llvm::Value *Location, |
| 882 | bool IsLocationVolatile = false, |
| 883 | bool IsInitializer = false); |
| 884 | |
Mike Stump | 27fe2e6 | 2009-05-23 22:29:41 +0000 | [diff] [blame] | 885 | /// EmitAggregateCopy - Emit an aggrate copy. |
| 886 | /// |
| 887 | /// \param isVolatile - True iff either the source or the destination is |
| 888 | /// volatile. |
Daniel Dunbar | 7482d12 | 2008-09-09 20:49:46 +0000 | [diff] [blame] | 889 | void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, |
Mike Stump | 27fe2e6 | 2009-05-23 22:29:41 +0000 | [diff] [blame] | 890 | QualType EltTy, bool isVolatile=false); |
Daniel Dunbar | 7482d12 | 2008-09-09 20:49:46 +0000 | [diff] [blame] | 891 | |
Devang Patel | 51b09f2 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 892 | /// StartBlock - Start new block named N. If insert block is a dummy block |
| 893 | /// then reuse it. |
| 894 | void StartBlock(const char *N); |
| 895 | |
Lauro Ramos Venancio | 8137335 | 2008-02-26 21:41:45 +0000 | [diff] [blame] | 896 | /// GetAddrOfStaticLocalVar - Return the address of a static local variable. |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 897 | llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD); |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 898 | |
Anders Carlsson | dde0a94 | 2008-09-11 09:15:33 +0000 | [diff] [blame] | 899 | /// GetAddrOfLocalVar - Return the address of a local variable. |
| 900 | llvm::Value *GetAddrOfLocalVar(const VarDecl *VD); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 901 | |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 902 | /// getAccessedFieldNo - Given an encoded value and a result number, return |
| 903 | /// the input field number being accessed. |
| 904 | static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); |
| 905 | |
Chris Lattner | d9becd1 | 2009-10-28 23:59:40 +0000 | [diff] [blame] | 906 | llvm::BlockAddress *GetAddrOfLabel(const LabelStmt *L); |
Chris Lattner | 3d00fdc | 2009-10-13 06:55:33 +0000 | [diff] [blame] | 907 | llvm::BasicBlock *GetIndirectGotoBlock(); |
Daniel Dunbar | 0ffb125 | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 908 | |
Anders Carlsson | 1884eb0 | 2010-05-22 17:35:42 +0000 | [diff] [blame] | 909 | /// EmitNullInitialization - Generate code to set a value of the given type to |
| 910 | /// null, If the type contains data member pointers, they will be initialized |
| 911 | /// to -1 in accordance with the Itanium C++ ABI. |
| 912 | void EmitNullInitialization(llvm::Value *DestPtr, QualType Ty); |
Anders Carlsson | ddf7cac | 2008-11-04 05:30:00 +0000 | [diff] [blame] | 913 | |
| 914 | // EmitVAArg - Generate code to get an argument from the passed in pointer |
| 915 | // and update it accordingly. The return value is a pointer to the argument. |
| 916 | // FIXME: We should be able to get rid of this method and use the va_arg |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 917 | // instruction in LLVM instead once it works well enough. |
Anders Carlsson | ddf7cac | 2008-11-04 05:30:00 +0000 | [diff] [blame] | 918 | llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); |
Anders Carlsson | f666b77 | 2008-12-20 20:27:15 +0000 | [diff] [blame] | 919 | |
Mike Stump | f71d232 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 920 | /// EmitVLASize - Generate code for any VLA size expressions that might occur |
| 921 | /// in a variably modified type. If Ty is a VLA, will return the value that |
| 922 | /// corresponds to the size in bytes of the VLA type. Will return 0 otherwise. |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 923 | /// |
| 924 | /// This function can be called with a null (unreachable) insert point. |
Anders Carlsson | 60d3541 | 2008-12-20 20:46:34 +0000 | [diff] [blame] | 925 | llvm::Value *EmitVLASize(QualType Ty); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 926 | |
Anders Carlsson | dcc90d8 | 2008-12-12 07:19:02 +0000 | [diff] [blame] | 927 | // GetVLASize - Returns an LLVM value that corresponds to the size in bytes |
| 928 | // of a variable length array type. |
| 929 | llvm::Value *GetVLASize(const VariableArrayType *); |
| 930 | |
Anders Carlsson | 5f4307b | 2009-04-14 16:58:56 +0000 | [diff] [blame] | 931 | /// LoadCXXThis - Load the value of 'this'. This function is only valid while |
| 932 | /// generating code for an C++ member function. |
John McCall | 2504941 | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 933 | llvm::Value *LoadCXXThis() { |
| 934 | assert(CXXThisValue && "no 'this' value for this function"); |
| 935 | return CXXThisValue; |
| 936 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 937 | |
Anders Carlsson | c997d42 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 938 | /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have |
| 939 | /// virtual bases. |
John McCall | 2504941 | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 940 | llvm::Value *LoadCXXVTT() { |
| 941 | assert(CXXVTTValue && "no VTT value for this function"); |
| 942 | return CXXVTTValue; |
| 943 | } |
John McCall | bff225e | 2010-02-16 04:15:37 +0000 | [diff] [blame] | 944 | |
| 945 | /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a |
Anders Carlsson | 8561a86 | 2010-04-24 23:01:49 +0000 | [diff] [blame] | 946 | /// complete class to the given direct base. |
| 947 | llvm::Value * |
| 948 | GetAddressOfDirectBaseInCompleteClass(llvm::Value *Value, |
| 949 | const CXXRecordDecl *Derived, |
| 950 | const CXXRecordDecl *Base, |
| 951 | bool BaseIsVirtual); |
Anders Carlsson | a88ad56 | 2010-04-24 21:51:08 +0000 | [diff] [blame] | 952 | |
Mike Stump | f71d232 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 953 | /// GetAddressOfBaseClass - This function will add the necessary delta to the |
| 954 | /// load of 'this' and returns address of the base class. |
Anders Carlsson | 34a2d38 | 2010-04-24 21:06:20 +0000 | [diff] [blame] | 955 | llvm::Value *GetAddressOfBaseClass(llvm::Value *Value, |
Anders Carlsson | 8561a86 | 2010-04-24 23:01:49 +0000 | [diff] [blame] | 956 | const CXXRecordDecl *Derived, |
Anders Carlsson | 34a2d38 | 2010-04-24 21:06:20 +0000 | [diff] [blame] | 957 | const CXXBaseSpecifierArray &BasePath, |
| 958 | bool NullCheckValue); |
| 959 | |
Anders Carlsson | a3697c9 | 2009-11-23 17:57:54 +0000 | [diff] [blame] | 960 | llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value, |
Anders Carlsson | 8561a86 | 2010-04-24 23:01:49 +0000 | [diff] [blame] | 961 | const CXXRecordDecl *Derived, |
Anders Carlsson | a04efdf | 2010-04-24 21:23:59 +0000 | [diff] [blame] | 962 | const CXXBaseSpecifierArray &BasePath, |
Anders Carlsson | a3697c9 | 2009-11-23 17:57:54 +0000 | [diff] [blame] | 963 | bool NullCheckValue); |
| 964 | |
Anders Carlsson | bb7e17b | 2010-01-31 01:36:53 +0000 | [diff] [blame] | 965 | llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This, |
| 966 | const CXXRecordDecl *ClassDecl, |
| 967 | const CXXRecordDecl *BaseClassDecl); |
Anders Carlsson | 2f1986b | 2009-10-06 22:43:30 +0000 | [diff] [blame] | 968 | |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 969 | void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, |
| 970 | CXXCtorType CtorType, |
| 971 | const FunctionArgList &Args); |
Anders Carlsson | 155ed4a | 2010-05-02 23:20:53 +0000 | [diff] [blame] | 972 | void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, |
| 973 | bool ForVirtualBase, llvm::Value *This, |
Anders Carlsson | b14095a | 2009-04-17 00:06:03 +0000 | [diff] [blame] | 974 | CallExpr::const_arg_iterator ArgBeg, |
| 975 | CallExpr::const_arg_iterator ArgEnd); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 976 | |
Fariborz Jahanian | 288dcaf | 2009-08-19 20:55:16 +0000 | [diff] [blame] | 977 | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
Anders Carlsson | 569c1f4 | 2009-09-23 02:45:36 +0000 | [diff] [blame] | 978 | const ConstantArrayType *ArrayTy, |
Anders Carlsson | 5d4d946 | 2009-11-24 18:43:52 +0000 | [diff] [blame] | 979 | llvm::Value *ArrayPtr, |
| 980 | CallExpr::const_arg_iterator ArgBeg, |
| 981 | CallExpr::const_arg_iterator ArgEnd); |
| 982 | |
Anders Carlsson | 569c1f4 | 2009-09-23 02:45:36 +0000 | [diff] [blame] | 983 | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
| 984 | llvm::Value *NumElements, |
Anders Carlsson | 5d4d946 | 2009-11-24 18:43:52 +0000 | [diff] [blame] | 985 | llvm::Value *ArrayPtr, |
| 986 | CallExpr::const_arg_iterator ArgBeg, |
| 987 | CallExpr::const_arg_iterator ArgEnd); |
Anders Carlsson | b14095a | 2009-04-17 00:06:03 +0000 | [diff] [blame] | 988 | |
Fariborz Jahanian | f800f6c | 2009-08-20 20:54:15 +0000 | [diff] [blame] | 989 | void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, |
| 990 | const ArrayType *Array, |
| 991 | llvm::Value *This); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | |
Fariborz Jahanian | 72c2153 | 2009-11-13 19:27:47 +0000 | [diff] [blame] | 993 | void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, |
| 994 | llvm::Value *NumElements, |
| 995 | llvm::Value *This); |
| 996 | |
Anders Carlsson | 02e370a | 2010-06-08 22:14:59 +0000 | [diff] [blame] | 997 | llvm::Function *GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D, |
| 998 | const ArrayType *Array, |
| 999 | llvm::Value *This); |
Fariborz Jahanian | 88f4280 | 2009-11-10 19:24:06 +0000 | [diff] [blame] | 1000 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 1001 | void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, |
Anders Carlsson | 8e6404c | 2010-05-02 23:29:11 +0000 | [diff] [blame] | 1002 | bool ForVirtualBase, llvm::Value *This); |
Fariborz Jahanian | ef66872 | 2010-06-25 18:26:07 +0000 | [diff] [blame] | 1003 | |
| 1004 | void EmitNewArrayInitializer(const CXXNewExpr *E, llvm::Value *NewPtr, |
| 1005 | llvm::Value *NumElements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1006 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1007 | void EmitCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1008 | |
Anders Carlsson | a00703d | 2009-05-31 01:40:14 +0000 | [diff] [blame] | 1009 | llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); |
Anders Carlsson | 60e282c | 2009-08-16 21:13:42 +0000 | [diff] [blame] | 1010 | void EmitCXXDeleteExpr(const CXXDeleteExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | |
Eli Friedman | 4bf8152 | 2009-11-18 00:57:03 +0000 | [diff] [blame] | 1012 | void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, |
| 1013 | QualType DeleteTy); |
| 1014 | |
Mike Stump | c2e84ae | 2009-11-15 08:09:41 +0000 | [diff] [blame] | 1015 | llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E); |
Mike Stump | c849c05 | 2009-11-16 06:50:58 +0000 | [diff] [blame] | 1016 | llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE); |
Mike Stump | c2e84ae | 2009-11-15 08:09:41 +0000 | [diff] [blame] | 1017 | |
Mike Stump | b14e62d | 2009-12-16 02:57:00 +0000 | [diff] [blame] | 1018 | void EmitCheck(llvm::Value *, unsigned Size); |
| 1019 | |
Chris Lattner | dd36d32 | 2010-01-09 21:40:03 +0000 | [diff] [blame] | 1020 | llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, |
| 1021 | bool isInc, bool isPre); |
| 1022 | ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, |
| 1023 | bool isInc, bool isPre); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1024 | //===--------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1025 | // Declaration Emission |
| 1026 | //===--------------------------------------------------------------------===// |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1027 | |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1028 | /// EmitDecl - Emit a declaration. |
| 1029 | /// |
| 1030 | /// This function can be called with a null (unreachable) insert point. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1031 | void EmitDecl(const Decl &D); |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1032 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1033 | /// EmitBlockVarDecl - Emit a block variable declaration. |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1034 | /// |
| 1035 | /// This function can be called with a null (unreachable) insert point. |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 1036 | void EmitBlockVarDecl(const VarDecl &D); |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1037 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1038 | typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, |
| 1039 | llvm::Value *Address); |
| 1040 | |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1041 | /// EmitLocalBlockVarDecl - Emit a local block variable declaration. |
| 1042 | /// |
| 1043 | /// This function can be called with a null (unreachable) insert point. |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1044 | void EmitLocalBlockVarDecl(const VarDecl &D, SpecialInitFn *SpecialInit = 0); |
Daniel Dunbar | d286f05 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1045 | |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 1046 | void EmitStaticBlockVarDecl(const VarDecl &D, |
| 1047 | llvm::GlobalValue::LinkageTypes Linkage); |
Daniel Dunbar | b7ec246 | 2008-08-16 03:19:19 +0000 | [diff] [blame] | 1048 | |
| 1049 | /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. |
| 1050 | void EmitParmDecl(const VarDecl &D, llvm::Value *Arg); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1051 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1052 | //===--------------------------------------------------------------------===// |
| 1053 | // Statement Emission |
| 1054 | //===--------------------------------------------------------------------===// |
| 1055 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1056 | /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. |
Daniel Dunbar | 0912425 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1057 | void EmitStopPoint(const Stmt *S); |
| 1058 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1059 | /// EmitStmt - Emit the code for the statement \arg S. It is legal to call |
| 1060 | /// this function even if there is no current insertion point. |
| 1061 | /// |
| 1062 | /// This function may clear the current insertion point; callers should use |
| 1063 | /// EnsureInsertPoint if they wish to subsequently generate code without first |
| 1064 | /// calling EmitBlock, EmitBranch, or EmitStmt. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1065 | void EmitStmt(const Stmt *S); |
Daniel Dunbar | a448fb2 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1066 | |
Daniel Dunbar | 0912425 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1067 | /// EmitSimpleStmt - Try to emit a "simple" statement which does not |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1068 | /// necessarily require an insertion point or debug information; typically |
| 1069 | /// because the statement amounts to a jump or a container of other |
| 1070 | /// statements. |
Daniel Dunbar | 0912425 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1071 | /// |
| 1072 | /// \return True if the statement was handled. |
| 1073 | bool EmitSimpleStmt(const Stmt *S); |
| 1074 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 1075 | RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, |
| 1076 | llvm::Value *AggLoc = 0, bool isAggVol = false); |
Daniel Dunbar | a448fb2 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1077 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1078 | /// EmitLabel - Emit the block for the given label. It is legal to call this |
| 1079 | /// function even if there is no current insertion point. |
Chris Lattner | 91d723d | 2008-07-26 20:23:23 +0000 | [diff] [blame] | 1080 | void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt. |
Daniel Dunbar | a448fb2 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1081 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1082 | void EmitLabelStmt(const LabelStmt &S); |
| 1083 | void EmitGotoStmt(const GotoStmt &S); |
Daniel Dunbar | 0ffb125 | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 1084 | void EmitIndirectGotoStmt(const IndirectGotoStmt &S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1085 | void EmitIfStmt(const IfStmt &S); |
| 1086 | void EmitWhileStmt(const WhileStmt &S); |
| 1087 | void EmitDoStmt(const DoStmt &S); |
| 1088 | void EmitForStmt(const ForStmt &S); |
| 1089 | void EmitReturnStmt(const ReturnStmt &S); |
| 1090 | void EmitDeclStmt(const DeclStmt &S); |
Daniel Dunbar | 0912425 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1091 | void EmitBreakStmt(const BreakStmt &S); |
| 1092 | void EmitContinueStmt(const ContinueStmt &S); |
Devang Patel | 51b09f2 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 1093 | void EmitSwitchStmt(const SwitchStmt &S); |
| 1094 | void EmitDefaultStmt(const DefaultStmt &S); |
| 1095 | void EmitCaseStmt(const CaseStmt &S); |
Devang Patel | c049e4f | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 1096 | void EmitCaseStmtRange(const CaseStmt &S); |
Anders Carlsson | fb1aeb8 | 2008-02-05 16:35:33 +0000 | [diff] [blame] | 1097 | void EmitAsmStmt(const AsmStmt &S); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1098 | |
Anders Carlsson | 3d8400d | 2008-08-30 19:51:14 +0000 | [diff] [blame] | 1099 | void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); |
Anders Carlsson | 64d5d6c | 2008-09-09 10:04:29 +0000 | [diff] [blame] | 1100 | void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); |
| 1101 | void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); |
Chris Lattner | 10cac6f | 2008-11-15 21:26:17 +0000 | [diff] [blame] | 1102 | void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1103 | |
Douglas Gregor | 86a3a03 | 2010-05-16 01:24:12 +0000 | [diff] [blame] | 1104 | llvm::Constant *getUnwindResumeOrRethrowFn(); |
John McCall | 59a7000 | 2010-07-07 06:56:46 +0000 | [diff] [blame] | 1105 | void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
| 1106 | void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
John McCall | 9fc6a77 | 2010-02-19 09:25:03 +0000 | [diff] [blame] | 1107 | |
Anders Carlsson | 6815e94 | 2009-09-27 18:58:34 +0000 | [diff] [blame] | 1108 | void EmitCXXTryStmt(const CXXTryStmt &S); |
| 1109 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1110 | //===--------------------------------------------------------------------===// |
| 1111 | // LValue Expression Emission |
| 1112 | //===--------------------------------------------------------------------===// |
| 1113 | |
Daniel Dunbar | 13e8173 | 2009-02-05 07:09:07 +0000 | [diff] [blame] | 1114 | /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. |
| 1115 | RValue GetUndefRValue(QualType Ty); |
| 1116 | |
Daniel Dunbar | ce1d38b | 2009-01-09 16:50:52 +0000 | [diff] [blame] | 1117 | /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E |
| 1118 | /// and issue an ErrorUnsupported style diagnostic (using the |
| 1119 | /// provided Name). |
| 1120 | RValue EmitUnsupportedRValue(const Expr *E, |
| 1121 | const char *Name); |
| 1122 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1123 | /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue |
| 1124 | /// an ErrorUnsupported style diagnostic (using the provided Name). |
Daniel Dunbar | 6ba82a4 | 2008-08-25 20:45:57 +0000 | [diff] [blame] | 1125 | LValue EmitUnsupportedLValue(const Expr *E, |
| 1126 | const char *Name); |
| 1127 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1128 | /// EmitLValue - Emit code to compute a designator that specifies the location |
| 1129 | /// of the expression. |
| 1130 | /// |
| 1131 | /// This can return one of two things: a simple address or a bitfield |
| 1132 | /// reference. In either case, the LLVM Value* in the LValue structure is |
| 1133 | /// guaranteed to be an LLVM pointer type. |
| 1134 | /// |
| 1135 | /// If this returns a bitfield reference, nothing about the pointee type of |
| 1136 | /// the LLVM value is known: For example, it may not be a pointer to an |
| 1137 | /// integer. |
| 1138 | /// |
| 1139 | /// If this returns a normal address, and if the lvalue's C type is fixed |
| 1140 | /// size, this method guarantees that the returned pointer type will point to |
| 1141 | /// an LLVM type of the same size of the lvalue's type. If the lvalue has a |
| 1142 | /// variable length type, this is not possible. |
| 1143 | /// |
| 1144 | LValue EmitLValue(const Expr *E); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1145 | |
Mike Stump | b14e62d | 2009-12-16 02:57:00 +0000 | [diff] [blame] | 1146 | /// EmitCheckedLValue - Same as EmitLValue but additionally we generate |
| 1147 | /// checking code to guard against undefined behavior. This is only |
| 1148 | /// suitable when we know that the address will be used to access the |
| 1149 | /// object. |
| 1150 | LValue EmitCheckedLValue(const Expr *E); |
| 1151 | |
Daniel Dunbar | 9d9cc87 | 2009-02-10 00:57:50 +0000 | [diff] [blame] | 1152 | /// EmitLoadOfScalar - Load a scalar value from an address, taking |
| 1153 | /// care to appropriately convert from the memory representation to |
| 1154 | /// the LLVM value representation. |
Mike Stump | 09429b9 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 1155 | llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, |
Daniel Dunbar | 9d9cc87 | 2009-02-10 00:57:50 +0000 | [diff] [blame] | 1156 | QualType Ty); |
| 1157 | |
| 1158 | /// EmitStoreOfScalar - Store a scalar value to an address, taking |
| 1159 | /// care to appropriately convert from the memory representation to |
| 1160 | /// the LLVM value representation. |
Mike Stump | 09429b9 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 1161 | void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, |
Anders Carlsson | b4aa466 | 2009-05-19 18:50:41 +0000 | [diff] [blame] | 1162 | bool Volatile, QualType Ty); |
Daniel Dunbar | 9d9cc87 | 2009-02-10 00:57:50 +0000 | [diff] [blame] | 1163 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1164 | /// EmitLoadOfLValue - Given an expression that represents a value lvalue, |
| 1165 | /// this method emits the address of the lvalue, then loads the result as an |
| 1166 | /// rvalue, returning the rvalue. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1167 | RValue EmitLoadOfLValue(LValue V, QualType LVType); |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1168 | RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType); |
Lauro Ramos Venancio | 3b8c22d | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 1169 | RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 1170 | RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType); |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 1171 | RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1172 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1173 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1174 | /// EmitStoreThroughLValue - Store the specified rvalue into the specified |
| 1175 | /// lvalue, where both are guaranteed to the have the same type, and that type |
| 1176 | /// is 'Ty'. |
| 1177 | void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1178 | void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst, |
| 1179 | QualType Ty); |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 1180 | void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty); |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 1181 | void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty); |
Daniel Dunbar | ed3849b | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 1182 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1183 | /// EmitStoreThroughLValue - Store Src into Dst with same constraints as |
| 1184 | /// EmitStoreThroughLValue. |
Daniel Dunbar | ed3849b | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 1185 | /// |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1186 | /// \param Result [out] - If non-null, this will be set to a Value* for the |
| 1187 | /// bit-field contents after the store, appropriate for use as the result of |
| 1188 | /// an assignment to the bit-field. |
Daniel Dunbar | ed3849b | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 1189 | void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty, |
| 1190 | llvm::Value **Result=0); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1191 | |
Christopher Lamb | 22c940e | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 1192 | // Note: only availabe for agg return types |
Daniel Dunbar | 80e62c2 | 2008-09-04 03:20:13 +0000 | [diff] [blame] | 1193 | LValue EmitBinaryOperatorLValue(const BinaryOperator *E); |
Douglas Gregor | 6a03e34 | 2010-04-23 04:16:32 +0000 | [diff] [blame] | 1194 | LValue EmitCompoundAssignOperatorLValue(const CompoundAssignOperator *E); |
Daniel Dunbar | 5b5c9ef | 2009-02-11 20:59:32 +0000 | [diff] [blame] | 1195 | // Note: only available for agg return types |
Christopher Lamb | 22c940e | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 1196 | LValue EmitCallExprLValue(const CallExpr *E); |
Daniel Dunbar | 5b5c9ef | 2009-02-11 20:59:32 +0000 | [diff] [blame] | 1197 | // Note: only available for agg return types |
| 1198 | LValue EmitVAArgExprLValue(const VAArgExpr *E); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1199 | LValue EmitDeclRefLValue(const DeclRefExpr *E); |
| 1200 | LValue EmitStringLiteralLValue(const StringLiteral *E); |
Chris Lattner | eaf2bb8 | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 1201 | LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); |
Daniel Dunbar | 662b71e | 2008-10-17 21:58:32 +0000 | [diff] [blame] | 1202 | LValue EmitPredefinedFunctionName(unsigned Type); |
Chris Lattner | d9f6910 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 1203 | LValue EmitPredefinedLValue(const PredefinedExpr *E); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1204 | LValue EmitUnaryOpLValue(const UnaryOperator *E); |
| 1205 | LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1206 | LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 1207 | LValue EmitMemberExpr(const MemberExpr *E); |
Fariborz Jahanian | 820bca4 | 2009-12-09 23:35:29 +0000 | [diff] [blame] | 1208 | LValue EmitObjCIsaExpr(const ObjCIsaExpr *E); |
Eli Friedman | 06e863f | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 1209 | LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); |
Anders Carlsson | 6fcec8b | 2009-09-15 16:35:24 +0000 | [diff] [blame] | 1210 | LValue EmitConditionalOperatorLValue(const ConditionalOperator *E); |
Chris Lattner | 75dfeda | 2009-03-18 18:28:57 +0000 | [diff] [blame] | 1211 | LValue EmitCastLValue(const CastExpr *E); |
Douglas Gregor | 016a4a9 | 2010-07-07 22:43:56 +0000 | [diff] [blame^] | 1212 | LValue EmitNullInitializationLValue(const CXXScalarValueInitExpr *E); |
Anders Carlsson | 909fbf7 | 2009-11-07 22:00:15 +0000 | [diff] [blame] | 1213 | |
Daniel Dunbar | 2a03192 | 2009-04-22 05:08:15 +0000 | [diff] [blame] | 1214 | llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, |
Daniel Dunbar | 29e0bcc | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 1215 | const ObjCIvarDecl *Ivar); |
John McCall | a9976d3 | 2010-05-21 01:18:57 +0000 | [diff] [blame] | 1216 | LValue EmitLValueForAnonRecordField(llvm::Value* Base, |
| 1217 | const FieldDecl* Field, |
| 1218 | unsigned CVRQualifiers); |
Anders Carlsson | 0ed303c | 2009-11-17 03:57:07 +0000 | [diff] [blame] | 1219 | LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field, |
Anders Carlsson | e6d2a53 | 2010-01-29 05:05:36 +0000 | [diff] [blame] | 1220 | unsigned CVRQualifiers); |
Anders Carlsson | 06a2970 | 2010-01-29 05:24:29 +0000 | [diff] [blame] | 1221 | |
| 1222 | /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that |
| 1223 | /// if the Field is a reference, this will return the address of the reference |
| 1224 | /// and not the address of the value stored in the reference. |
| 1225 | LValue EmitLValueForFieldInitialization(llvm::Value* Base, |
| 1226 | const FieldDecl* Field, |
| 1227 | unsigned CVRQualifiers); |
| 1228 | |
Fariborz Jahanian | 45012a7 | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 1229 | LValue EmitLValueForIvar(QualType ObjectTy, |
| 1230 | llvm::Value* Base, const ObjCIvarDecl *Ivar, |
Daniel Dunbar | 29e0bcc | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 1231 | unsigned CVRQualifiers); |
| 1232 | |
Anders Carlsson | 0ed303c | 2009-11-17 03:57:07 +0000 | [diff] [blame] | 1233 | LValue EmitLValueForBitfield(llvm::Value* Base, const FieldDecl* Field, |
Fariborz Jahanian | 598d3f6 | 2009-02-03 19:03:09 +0000 | [diff] [blame] | 1234 | unsigned CVRQualifiers); |
Fariborz Jahanian | fd64bb6 | 2008-12-15 20:35:07 +0000 | [diff] [blame] | 1235 | |
Mike Stump | a99038c | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 1236 | LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E); |
| 1237 | |
Anders Carlsson | b58d017 | 2009-05-30 23:23:33 +0000 | [diff] [blame] | 1238 | LValue EmitCXXConstructLValue(const CXXConstructExpr *E); |
Anders Carlsson | e61c9e8 | 2009-05-30 23:30:54 +0000 | [diff] [blame] | 1239 | LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); |
Anders Carlsson | b9ea0b5 | 2009-09-14 01:10:45 +0000 | [diff] [blame] | 1240 | LValue EmitCXXExprWithTemporariesLValue(const CXXExprWithTemporaries *E); |
Mike Stump | c2e84ae | 2009-11-15 08:09:41 +0000 | [diff] [blame] | 1241 | LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); |
Anders Carlsson | b9ea0b5 | 2009-09-14 01:10:45 +0000 | [diff] [blame] | 1242 | |
Daniel Dunbar | 0a04d77 | 2008-08-23 10:51:21 +0000 | [diff] [blame] | 1243 | LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 1244 | LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 1245 | LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E); |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 1246 | LValue EmitObjCKVCRefLValue(const ObjCImplicitSetterGetterRefExpr *E); |
Chris Lattner | 6545994 | 2009-04-25 19:35:26 +0000 | [diff] [blame] | 1247 | LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E); |
| 1248 | LValue EmitStmtExprLValue(const StmtExpr *E); |
Fariborz Jahanian | 8bfd31f | 2009-10-22 22:57:31 +0000 | [diff] [blame] | 1249 | LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); |
Fariborz Jahanian | 03b2960 | 2010-06-17 19:56:20 +0000 | [diff] [blame] | 1250 | LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); |
Fariborz Jahanian | 8bfd31f | 2009-10-22 22:57:31 +0000 | [diff] [blame] | 1251 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1252 | //===--------------------------------------------------------------------===// |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 1253 | // Scalar Expression Emission |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1254 | //===--------------------------------------------------------------------===// |
| 1255 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1256 | /// EmitCall - Generate a call of the given function, expecting the given |
| 1257 | /// result type, and using the given argument list which specifies both the |
| 1258 | /// LLVM arguments and the types they were derived from. |
Daniel Dunbar | c0ef9f5 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 1259 | /// |
Mike Stump | f71d232 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1260 | /// \param TargetDecl - If given, the decl of the function in a direct call; |
| 1261 | /// used to set attributes on the call (noreturn, etc.). |
Daniel Dunbar | 88b5396 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 1262 | RValue EmitCall(const CGFunctionInfo &FnInfo, |
| 1263 | llvm::Value *Callee, |
Anders Carlsson | f3c47c9 | 2009-12-24 19:25:24 +0000 | [diff] [blame] | 1264 | ReturnValueSlot ReturnValue, |
Daniel Dunbar | c0ef9f5 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 1265 | const CallArgList &Args, |
David Chisnall | dd5c98f | 2010-05-01 11:15:56 +0000 | [diff] [blame] | 1266 | const Decl *TargetDecl = 0, |
David Chisnall | 4b02afc | 2010-05-02 13:41:58 +0000 | [diff] [blame] | 1267 | llvm::Instruction **callOrInvoke = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1268 | |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 1269 | RValue EmitCall(QualType FnType, llvm::Value *Callee, |
Anders Carlsson | d2490a9 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 1270 | ReturnValueSlot ReturnValue, |
Anders Carlsson | 9864771 | 2009-05-27 01:22:39 +0000 | [diff] [blame] | 1271 | CallExpr::const_arg_iterator ArgBeg, |
| 1272 | CallExpr::const_arg_iterator ArgEnd, |
| 1273 | const Decl *TargetDecl = 0); |
Anders Carlsson | d2490a9 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 1274 | RValue EmitCallExpr(const CallExpr *E, |
| 1275 | ReturnValueSlot ReturnValue = ReturnValueSlot()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1276 | |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1277 | llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, |
| 1278 | llvm::Value * const *ArgBegin, |
| 1279 | llvm::Value * const *ArgEnd, |
| 1280 | const llvm::Twine &Name = ""); |
| 1281 | |
Anders Carlsson | 566abee | 2009-11-13 04:45:41 +0000 | [diff] [blame] | 1282 | llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This, |
Mike Stump | f0070db | 2009-08-26 20:46:33 +0000 | [diff] [blame] | 1283 | const llvm::Type *Ty); |
Anders Carlsson | 566abee | 2009-11-13 04:45:41 +0000 | [diff] [blame] | 1284 | llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type, |
| 1285 | llvm::Value *&This, const llvm::Type *Ty); |
| 1286 | |
Anders Carlsson | b9de2c5 | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 1287 | RValue EmitCXXMemberCall(const CXXMethodDecl *MD, |
| 1288 | llvm::Value *Callee, |
Anders Carlsson | a1736c0 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 1289 | ReturnValueSlot ReturnValue, |
Anders Carlsson | b9de2c5 | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 1290 | llvm::Value *This, |
Anders Carlsson | c997d42 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 1291 | llvm::Value *VTT, |
Anders Carlsson | b9de2c5 | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 1292 | CallExpr::const_arg_iterator ArgBeg, |
| 1293 | CallExpr::const_arg_iterator ArgEnd); |
Anders Carlsson | a1736c0 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 1294 | RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, |
| 1295 | ReturnValueSlot ReturnValue); |
| 1296 | RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, |
| 1297 | ReturnValueSlot ReturnValue); |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 1298 | |
Anders Carlsson | 0f29463 | 2009-05-27 04:18:27 +0000 | [diff] [blame] | 1299 | RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, |
Anders Carlsson | a1736c0 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 1300 | const CXXMethodDecl *MD, |
| 1301 | ReturnValueSlot ReturnValue); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1302 | |
Anders Carlsson | 375c31c | 2009-10-03 19:43:08 +0000 | [diff] [blame] | 1303 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | RValue EmitBuiltinExpr(const FunctionDecl *FD, |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1305 | unsigned BuiltinID, const CallExpr *E); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1306 | |
Anders Carlsson | a1736c0 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 1307 | RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); |
Mike Stump | 09429b9 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 1308 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1309 | /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call |
| 1310 | /// is unhandled by the current target. |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 1311 | llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 1312 | |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1313 | llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1314 | llvm::Value *EmitNeonCall(llvm::Function *F, |
| 1315 | llvm::SmallVectorImpl<llvm::Value*> &O, |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1316 | const char *name, bool splat = false, |
| 1317 | unsigned shift = 0, bool rightshift = false); |
Nate Begeman | d075c01 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 1318 | llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1319 | llvm::Value *EmitNeonShiftVector(llvm::Value *V, const llvm::Type *Ty, |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1320 | bool negateForRightShift); |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1321 | |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 1322 | llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 1323 | llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1324 | |
Daniel Dunbar | ed7c618 | 2008-08-20 00:28:19 +0000 | [diff] [blame] | 1325 | llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); |
Chris Lattner | 7f02f72 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 1326 | llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 1327 | llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); |
John McCall | ef072fd | 2010-05-22 01:48:05 +0000 | [diff] [blame] | 1328 | RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, |
| 1329 | ReturnValueSlot Return = ReturnValueSlot()); |
| 1330 | RValue EmitObjCPropertyGet(const Expr *E, |
| 1331 | ReturnValueSlot Return = ReturnValueSlot()); |
| 1332 | RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S, |
| 1333 | ReturnValueSlot Return = ReturnValueSlot()); |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 1334 | void EmitObjCPropertySet(const Expr *E, RValue Src); |
Fariborz Jahanian | f469557 | 2009-03-20 19:18:21 +0000 | [diff] [blame] | 1335 | void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src); |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 1336 | |
| 1337 | |
Anders Carlsson | 4029ca7 | 2009-05-20 00:24:07 +0000 | [diff] [blame] | 1338 | /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in |
| 1339 | /// expression. Will emit a temporary variable if E is not an LValue. |
Anders Carlsson | 32f36ba | 2010-06-26 16:35:32 +0000 | [diff] [blame] | 1340 | RValue EmitReferenceBindingToExpr(const Expr* E, |
| 1341 | const NamedDecl *InitializedDecl); |
Anders Carlsson | 3aba093 | 2010-01-31 18:34:51 +0000 | [diff] [blame] | 1342 | |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 1343 | //===--------------------------------------------------------------------===// |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 1344 | // Expression Emission |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 1345 | //===--------------------------------------------------------------------===// |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 1346 | |
| 1347 | // Expressions are broken into three classes: scalar, complex, aggregate. |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1348 | |
| 1349 | /// EmitScalarExpr - Emit the computation of the specified expression of LLVM |
| 1350 | /// scalar type, returning the result. |
Anders Carlsson | 14c5cbf | 2009-08-16 07:36:22 +0000 | [diff] [blame] | 1351 | llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1352 | |
Chris Lattner | 3707b25 | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 1353 | /// EmitScalarConversion - Emit a conversion from the specified type to the |
| 1354 | /// specified destination type, both of which are LLVM scalar types. |
| 1355 | llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, |
| 1356 | QualType DstTy); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1357 | |
Chris Lattner | 4f1a7b3 | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 1358 | /// EmitComplexToScalarConversion - Emit a conversion from the specified |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1359 | /// complex type to the specified destination type, where the destination type |
| 1360 | /// is an LLVM scalar type. |
Chris Lattner | 4f1a7b3 | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 1361 | llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, |
| 1362 | QualType DstTy); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1363 | |
| 1364 | |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 1365 | /// EmitAggExpr - Emit the computation of the specified expression of |
| 1366 | /// aggregate type. The result is computed into DestPtr. Note that if |
| 1367 | /// DestPtr is null, the value of the aggregate expression is not needed. |
Mike Stump | 49d1cd5 | 2009-05-26 22:03:21 +0000 | [diff] [blame] | 1368 | void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest, |
Fariborz Jahanian | 08c3213 | 2009-08-31 19:33:16 +0000 | [diff] [blame] | 1369 | bool IgnoreResult = false, bool IsInitializer = false, |
| 1370 | bool RequiresGCollection = false); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1371 | |
Daniel Dunbar | 18aba0d | 2010-02-05 19:38:31 +0000 | [diff] [blame] | 1372 | /// EmitAggExprToLValue - Emit the computation of the specified expression of |
| 1373 | /// aggregate type into a temporary LValue. |
| 1374 | LValue EmitAggExprToLValue(const Expr *E); |
| 1375 | |
Fariborz Jahanian | 082b02e | 2009-07-08 01:18:33 +0000 | [diff] [blame] | 1376 | /// EmitGCMemmoveCollectable - Emit special API for structs with object |
| 1377 | /// pointers. |
| 1378 | void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr, |
Fariborz Jahanian | 08c3213 | 2009-08-31 19:33:16 +0000 | [diff] [blame] | 1379 | QualType Ty); |
Fariborz Jahanian | 082b02e | 2009-07-08 01:18:33 +0000 | [diff] [blame] | 1380 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 1381 | /// EmitComplexExpr - Emit the computation of the specified expression of |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 1382 | /// complex type, returning the result. |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 1383 | ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false, |
| 1384 | bool IgnoreImag = false, |
| 1385 | bool IgnoreRealAssign = false, |
| 1386 | bool IgnoreImagAssign = false); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1387 | |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 1388 | /// EmitComplexExprIntoAddr - Emit the computation of the specified expression |
| 1389 | /// of complex type, storing into the specified Value*. |
Chris Lattner | 190dbe2 | 2007-08-26 16:22:13 +0000 | [diff] [blame] | 1390 | void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, |
| 1391 | bool DestIsVolatile); |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 1392 | |
| 1393 | /// StoreComplexToAddr - Store a complex number into the specified address. |
| 1394 | void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr, |
| 1395 | bool DestIsVolatile); |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 1396 | /// LoadComplexFromAddr - Load a complex number from the specified address. |
| 1397 | ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 1398 | |
Mike Stump | f71d232 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1399 | /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global for a |
| 1400 | /// static block var decl. |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 1401 | llvm::GlobalVariable *CreateStaticBlockVarDecl(const VarDecl &D, |
| 1402 | const char *Separator, |
Mike Stump | f71d232 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1403 | llvm::GlobalValue::LinkageTypes Linkage); |
Chris Lattner | 761acc1 | 2009-12-05 08:22:11 +0000 | [diff] [blame] | 1404 | |
| 1405 | /// AddInitializerToGlobalBlockVarDecl - Add the initializer for 'D' to the |
| 1406 | /// global variable that has already been created for it. If the initializer |
| 1407 | /// has a different type than GV does, this may free GV and return a different |
| 1408 | /// one. Otherwise it just returns GV. |
| 1409 | llvm::GlobalVariable * |
| 1410 | AddInitializerToGlobalBlockVarDecl(const VarDecl &D, |
| 1411 | llvm::GlobalVariable *GV); |
| 1412 | |
Daniel Dunbar | 0096acf | 2009-02-25 19:24:29 +0000 | [diff] [blame] | 1413 | |
Mike Stump | f71d232 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1414 | /// EmitStaticCXXBlockVarDeclInit - Create the initializer for a C++ runtime |
| 1415 | /// initialized static block var decl. |
Anders Carlsson | 3b2e16b | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 1416 | void EmitStaticCXXBlockVarDeclInit(const VarDecl &D, |
| 1417 | llvm::GlobalVariable *GV); |
Anders Carlsson | e1b29ef | 2008-08-22 16:00:37 +0000 | [diff] [blame] | 1418 | |
Anders Carlsson | 3b2e16b | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 1419 | /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ |
| 1420 | /// variable with global storage. |
| 1421 | void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr); |
| 1422 | |
| 1423 | /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr |
| 1424 | /// with the C++ runtime so that its destructor will be called at exit. |
Fariborz Jahanian | 88f4280 | 2009-11-10 19:24:06 +0000 | [diff] [blame] | 1425 | void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn, |
Anders Carlsson | 3b2e16b | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 1426 | llvm::Constant *DeclPtr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1428 | /// GenerateCXXGlobalInitFunc - Generates code for initializing global |
| 1429 | /// variables. |
| 1430 | void GenerateCXXGlobalInitFunc(llvm::Function *Fn, |
| 1431 | llvm::Constant **Decls, |
| 1432 | unsigned NumDecls); |
| 1433 | |
| 1434 | /// GenerateCXXGlobalDtorFunc - Generates code for destroying global |
| 1435 | /// variables. |
| 1436 | void GenerateCXXGlobalDtorFunc(llvm::Function *Fn, |
Chris Lattner | 810112e | 2010-06-19 05:52:45 +0000 | [diff] [blame] | 1437 | const std::vector<std::pair<llvm::WeakVH, |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1438 | llvm::Constant*> > &DtorsAndObjects); |
| 1439 | |
| 1440 | void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D); |
| 1441 | |
Anders Carlsson | 31ccf37 | 2009-05-03 17:47:16 +0000 | [diff] [blame] | 1442 | void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1443 | |
Anders Carlsson | b58d017 | 2009-05-30 23:23:33 +0000 | [diff] [blame] | 1444 | RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1445 | llvm::Value *AggLoc = 0, |
Anders Carlsson | 14c5cbf | 2009-08-16 07:36:22 +0000 | [diff] [blame] | 1446 | bool IsAggLocVolatile = false, |
| 1447 | bool IsInitializer = false); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1448 | |
Anders Carlsson | 756b5c4 | 2009-10-30 01:42:31 +0000 | [diff] [blame] | 1449 | void EmitCXXThrowExpr(const CXXThrowExpr *E); |
Douglas Gregor | 1eb2e59 | 2010-05-16 00:44:00 +0000 | [diff] [blame] | 1450 | |
Daniel Dunbar | 0ffb125 | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 1451 | //===--------------------------------------------------------------------===// |
| 1452 | // Internal Helpers |
| 1453 | //===--------------------------------------------------------------------===// |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1454 | |
Chris Lattner | 0946ccd | 2008-11-11 07:41:27 +0000 | [diff] [blame] | 1455 | /// ContainsLabel - Return true if the statement contains a label in it. If |
| 1456 | /// this statement is not executed normally, it not containing a label means |
| 1457 | /// that we can just remove the code. |
| 1458 | static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1459 | |
Daniel Dunbar | 4bc0455 | 2008-11-12 10:12:14 +0000 | [diff] [blame] | 1460 | /// ConstantFoldsToSimpleInteger - If the specified expression does not fold |
Chris Lattner | 31a0984 | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 1461 | /// to a constant, or if it does but contains a label, return 0. If it |
| 1462 | /// constant folds to 'true' and does not contain a label, return 1, if it |
| 1463 | /// constant folds to 'false' and does not contain a label, return -1. |
| 1464 | int ConstantFoldsToSimpleInteger(const Expr *Cond); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1465 | |
Chris Lattner | 31a0984 | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 1466 | /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an |
| 1467 | /// if statement) to the specified blocks. Based on the condition, this might |
| 1468 | /// try to simplify the codegen of the conditional based on the branch. |
Chris Lattner | 9bc47e2 | 2008-11-12 07:46:33 +0000 | [diff] [blame] | 1469 | void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, |
Daniel Dunbar | 4bc0455 | 2008-11-12 10:12:14 +0000 | [diff] [blame] | 1470 | llvm::BasicBlock *FalseBlock); |
Mike Stump | be07f60 | 2009-12-14 21:58:14 +0000 | [diff] [blame] | 1471 | |
Mike Stump | 15037ca | 2009-12-15 00:35:12 +0000 | [diff] [blame] | 1472 | /// getTrapBB - Create a basic block that will call the trap intrinsic. We'll |
| 1473 | /// generate a branch around the created basic block as necessary. |
| 1474 | llvm::BasicBlock* getTrapBB(); |
Anders Carlsson | 21c9ad9 | 2010-03-30 03:27:09 +0000 | [diff] [blame] | 1475 | |
| 1476 | /// EmitCallArg - Emit a single call argument. |
| 1477 | RValue EmitCallArg(const Expr *E, QualType ArgType); |
| 1478 | |
John McCall | 2736071 | 2010-05-26 22:34:26 +0000 | [diff] [blame] | 1479 | /// EmitDelegateCallArg - We are performing a delegate call; that |
| 1480 | /// is, the current function is delegating to another one. Produce |
| 1481 | /// a r-value suitable for passing the given parameter. |
| 1482 | RValue EmitDelegateCallArg(const VarDecl *Param); |
| 1483 | |
Chris Lattner | 31a0984 | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 1484 | private: |
Daniel Dunbar | 29e0bcc | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 1485 | void EmitReturnOfRValue(RValue RV, QualType Ty); |
| 1486 | |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1487 | /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty |
| 1488 | /// from function arguments into \arg Dst. See ABIArgInfo::Expand. |
| 1489 | /// |
| 1490 | /// \param AI - The first function argument of the expansion. |
| 1491 | /// \return The argument following the last expanded function |
| 1492 | /// argument. |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1493 | llvm::Function::arg_iterator |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1494 | ExpandTypeFromArgs(QualType Ty, LValue Dst, |
| 1495 | llvm::Function::arg_iterator AI); |
| 1496 | |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1497 | /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg |
| 1498 | /// Ty, into individual arguments on the provided vector \arg Args. See |
| 1499 | /// ABIArgInfo::Expand. |
| 1500 | void ExpandTypeToArgs(QualType Ty, RValue Src, |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1501 | llvm::SmallVector<llvm::Value*, 16> &Args); |
Anders Carlsson | c8c7b18 | 2009-01-11 19:40:10 +0000 | [diff] [blame] | 1502 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1503 | llvm::Value* EmitAsmInput(const AsmStmt &S, |
Daniel Dunbar | b84e8a6 | 2009-05-04 06:56:16 +0000 | [diff] [blame] | 1504 | const TargetInfo::ConstraintInfo &Info, |
Anders Carlsson | c8c7b18 | 2009-01-11 19:40:10 +0000 | [diff] [blame] | 1505 | const Expr *InputExpr, std::string &ConstraintStr); |
Mike Stump | 0dd9e88 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1506 | |
Anders Carlsson | 0139bb9 | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 1507 | /// EmitCallArgs - Emit call arguments for a function. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1508 | /// The CallArgTypeInfo parameter is used for iterating over the known |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1509 | /// argument types of the function being called. |
| 1510 | template<typename T> |
| 1511 | void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo, |
Anders Carlsson | 0139bb9 | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 1512 | CallExpr::const_arg_iterator ArgBeg, |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1513 | CallExpr::const_arg_iterator ArgEnd) { |
| 1514 | CallExpr::const_arg_iterator Arg = ArgBeg; |
Anders Carlsson | 0139bb9 | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 1515 | |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1516 | // First, use the argument types that the type info knows about |
| 1517 | if (CallArgTypeInfo) { |
| 1518 | for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(), |
| 1519 | E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) { |
Eli Friedman | 44b0a3e | 2009-11-18 03:42:04 +0000 | [diff] [blame] | 1520 | assert(Arg != ArgEnd && "Running over edge of argument list!"); |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1521 | QualType ArgType = *I; |
| 1522 | |
| 1523 | assert(getContext().getCanonicalType(ArgType.getNonReferenceType()). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1524 | getTypePtr() == |
| 1525 | getContext().getCanonicalType(Arg->getType()).getTypePtr() && |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1526 | "type mismatch in call argument!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1527 | |
| 1528 | Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1529 | ArgType)); |
| 1530 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1531 | |
| 1532 | // Either we've emitted all the call args, or we have a call to a |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1533 | // variadic function. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1534 | assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) && |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1535 | "Extra arguments in non-variadic function!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1536 | |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1537 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1538 | |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1539 | // If we still have any arguments, emit them using the type of the argument. |
| 1540 | for (; Arg != ArgEnd; ++Arg) { |
| 1541 | QualType ArgType = Arg->getType(); |
| 1542 | Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), |
| 1543 | ArgType)); |
| 1544 | } |
| 1545 | } |
John McCall | 492c4f9 | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 1546 | |
| 1547 | const TargetCodeGenInfo &getTargetHooks() const { |
| 1548 | return CGM.getTargetCodeGenInfo(); |
| 1549 | } |
John McCall | 744016d | 2010-07-06 23:57:41 +0000 | [diff] [blame] | 1550 | |
| 1551 | void EmitDeclMetadata(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1552 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1553 | |
Anders Carlsson | af23f69 | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 1554 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1555 | } // end namespace CodeGen |
| 1556 | } // end namespace clang |
| 1557 | |
| 1558 | #endif |