Daniel Dunbar | 7bf5b3d | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1 | //===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 10 | // This is the internal per-function state used for llvm translation. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 2629b88 | 2008-02-29 17:10:38 +0000 | [diff] [blame] | 14 | #ifndef CLANG_CODEGEN_CODEGENFUNCTION_H |
| 15 | #define CLANG_CODEGEN_CODEGENFUNCTION_H |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 16 | |
Chris Lattner | b326b17 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/DenseMap.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
Anders Carlsson | 60bb4d4 | 2009-01-11 19:40:10 +0000 | [diff] [blame] | 20 | #include "clang/Basic/TargetInfo.h" |
Ted Kremenek | 2719e98 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
Argiris Kirtzidis | bf615b0 | 2008-09-10 02:36:38 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExprCXX.h" |
Ted Kremenek | 2719e98 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 23 | #include "clang/AST/ExprObjC.h" |
| 24 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 25 | #include <vector> |
Daniel Dunbar | 879788d | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 26 | #include <map> |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 27 | |
Daniel Dunbar | d916e6e | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 28 | #include "CGBuilder.h" |
Daniel Dunbar | a8f0205 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 29 | #include "CGCall.h" |
Daniel Dunbar | a04840b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 30 | #include "CGValue.h" |
| 31 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 32 | namespace llvm { |
Daniel Dunbar | 64789f8 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 33 | class BasicBlock; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 34 | class Module; |
Daniel Dunbar | e9900eb | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 35 | class SwitchInst; |
Daniel Dunbar | 2668dd1 | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 36 | class Value; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | namespace clang { |
| 40 | class ASTContext; |
| 41 | class Decl; |
Daniel Dunbar | 64789f8 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 42 | class EnumConstantDecl; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 43 | class FunctionDecl; |
Daniel Dunbar | 64789f8 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 44 | class FunctionTypeProto; |
| 45 | class LabelStmt; |
Fariborz Jahanian | 0adaa8a | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 46 | class ObjCContainerDecl; |
Daniel Dunbar | e856ac2 | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 47 | class ObjCInterfaceDecl; |
| 48 | class ObjCIvarDecl; |
Chris Lattner | b326b17 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 49 | class ObjCMethodDecl; |
Fariborz Jahanian | 91dd9d3 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 50 | class ObjCImplementationDecl; |
Daniel Dunbar | 6b57d43 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 51 | class ObjCPropertyImplDecl; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 52 | class TargetInfo; |
Daniel Dunbar | 64789f8 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 53 | class VarDecl; |
Devang Patel | aebd83f | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 55 | namespace CodeGen { |
| 56 | class CodeGenModule; |
Devang Patel | aebd83f | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 57 | class CodeGenTypes; |
Daniel Dunbar | 9fc15a8 | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 58 | class CGFunctionInfo; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 59 | class CGRecordLayout; |
| 60 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 61 | /// CodeGenFunction - This class organizes the per-function state that is used |
| 62 | /// while generating LLVM code. |
| 63 | class CodeGenFunction { |
Chris Lattner | 41b1fca | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 64 | public: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 65 | CodeGenModule &CGM; // Per-module state. |
| 66 | TargetInfo &Target; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 67 | |
Chris Lattner | 5280c5f | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 68 | typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; |
Daniel Dunbar | d916e6e | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 69 | CGBuilderTy Builder; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 70 | |
Chris Lattner | 6e6a597 | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 71 | // Holds the Decl for the current function or method |
Chris Lattner | 8c7c6a1 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 72 | const Decl *CurFuncDecl; |
Daniel Dunbar | 6ee022b | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 73 | const CGFunctionInfo *CurFnInfo; |
Chris Lattner | b326b17 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 74 | QualType FnRetTy; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 75 | llvm::Function *CurFn; |
| 76 | |
Daniel Dunbar | 9fb751f | 2008-09-09 21:00:17 +0000 | [diff] [blame] | 77 | /// ReturnBlock - Unified return block. |
| 78 | llvm::BasicBlock *ReturnBlock; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 79 | /// ReturnValue - The temporary alloca to hold the return value. This is null |
| 80 | /// iff the function has no return value. |
Daniel Dunbar | 9fb751f | 2008-09-09 21:00:17 +0000 | [diff] [blame] | 81 | llvm::Instruction *ReturnValue; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 82 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 83 | /// AllocaInsertPoint - This is an instruction in the entry block before which |
| 84 | /// we prefer to insert allocas. |
| 85 | llvm::Instruction *AllocaInsertPt; |
Daniel Dunbar | 879788d | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 87 | const llvm::Type *LLVMIntTy; |
Hartmut Kaiser | ff08d2c | 2007-10-17 15:00:17 +0000 | [diff] [blame] | 88 | uint32_t LLVMPointerWidth; |
Daniel Dunbar | 8354484 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 89 | |
| 90 | public: |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 91 | // FIXME: The following should be private once EH code is moved out of NeXT |
| 92 | // runtime. |
Daniel Dunbar | 8354484 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 93 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 94 | // ObjCEHStack - This keeps track of which object to rethrow from inside |
| 95 | // @catch blocks and which @finally block exits from an EH scope should be |
| 96 | // chained through. |
Daniel Dunbar | 8354484 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 97 | struct ObjCEHEntry { |
Anders Carlsson | 8559de1 | 2009-02-07 21:26:04 +0000 | [diff] [blame] | 98 | ObjCEHEntry(llvm::BasicBlock *fb, llvm::SwitchInst *fs, llvm::Value *dc) |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 99 | : FinallyBlock(fb), FinallySwitch(fs), |
Anders Carlsson | ecd8183 | 2009-02-07 21:37:21 +0000 | [diff] [blame] | 100 | DestCode(dc) {} |
Daniel Dunbar | 8354484 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 101 | |
Daniel Dunbar | e9900eb | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 102 | /// Entry point to the finally block. |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 103 | llvm::BasicBlock *FinallyBlock; |
Daniel Dunbar | e9900eb | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 104 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 105 | /// Switch instruction which runs at the end of the finally block to forward |
| 106 | /// jumps through the finally block. |
| 107 | llvm::SwitchInst *FinallySwitch; |
Daniel Dunbar | e9900eb | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 108 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 109 | /// Variable holding the code for the destination of a jump through the |
| 110 | /// @finally block. |
Daniel Dunbar | e9900eb | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 111 | llvm::Value *DestCode; |
Daniel Dunbar | 8354484 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 112 | }; |
Daniel Dunbar | e9900eb | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 113 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 114 | /// ObjCEHValueStack - Stack of exception objects being handled, during IR |
| 115 | /// generation for a @catch block. |
Anders Carlsson | ecd8183 | 2009-02-07 21:37:21 +0000 | [diff] [blame] | 116 | llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 117 | |
Daniel Dunbar | e9900eb | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 118 | typedef llvm::SmallVector<ObjCEHEntry*, 8> ObjCEHStackType; |
| 119 | ObjCEHStackType ObjCEHStack; |
| 120 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 121 | /// EmitJumpThroughFinally - Emit a branch from the current insert point |
| 122 | /// through the finally handling code for \arg Entry and then on to \arg |
| 123 | /// Dest. It is legal to call this function even if there is no current |
| 124 | /// insertion point. |
Daniel Dunbar | e9900eb | 2008-09-30 01:06:03 +0000 | [diff] [blame] | 125 | /// |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 126 | /// \param ExecuteTryExit - When true, the try_exit runtime function should be |
| 127 | /// called prior to executing the finally code. |
Anders Carlsson | e833eba | 2009-02-08 22:25:30 +0000 | [diff] [blame] | 128 | void EmitJumpThroughFinally(ObjCEHEntry *Entry, llvm::BasicBlock *Dest); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 129 | |
Anders Carlsson | e833eba | 2009-02-08 22:25:30 +0000 | [diff] [blame] | 130 | void EmitJumpThroughFinally(llvm::BasicBlock *Dest); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 131 | |
Anders Carlsson | 459ee36 | 2009-02-08 03:22:36 +0000 | [diff] [blame] | 132 | /// PushCleanupBlock - Push a new cleanup entry on the stack and set the |
| 133 | /// passed in block as the cleanup block. |
| 134 | void PushCleanupBlock(llvm::BasicBlock *CleanupBlock); |
Anders Carlsson | df27419 | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 135 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 136 | /// CleanupBlockInfo - A struct representing a popped cleanup block. |
Anders Carlsson | df27419 | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 137 | struct CleanupBlockInfo { |
| 138 | /// CleanupBlock - the cleanup block |
| 139 | llvm::BasicBlock *CleanupBlock; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 140 | |
| 141 | /// SwitchBlock - the block (if any) containing the switch instruction used |
| 142 | /// for jumping to the final destination. |
Anders Carlsson | df27419 | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 143 | llvm::BasicBlock *SwitchBlock; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 144 | |
Anders Carlsson | df27419 | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 145 | /// EndBlock - the default destination for the switch instruction. |
| 146 | llvm::BasicBlock *EndBlock; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 147 | |
| 148 | CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb, |
Anders Carlsson | df27419 | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 149 | llvm::BasicBlock *eb) |
| 150 | : CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb) {} |
| 151 | }; |
| 152 | |
| 153 | /// PopCleanupBlock - Will pop the cleanup entry on the stack, process all |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 154 | /// branch fixups and return a block info struct with the switch block and end |
| 155 | /// block. |
Anders Carlsson | df27419 | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 156 | CleanupBlockInfo PopCleanupBlock(); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 157 | |
| 158 | /// CleanupScope - RAII object that will create a cleanup block and set the |
| 159 | /// insert point to that block. When destructed, it sets the insert point to |
| 160 | /// the previous block and pushes a new cleanup entry on the stack. |
Anders Carlsson | ca2fec6 | 2009-02-07 23:30:41 +0000 | [diff] [blame] | 161 | class CleanupScope { |
| 162 | CodeGenFunction& CGF; |
| 163 | llvm::BasicBlock *CurBB; |
Anders Carlsson | 459ee36 | 2009-02-08 03:22:36 +0000 | [diff] [blame] | 164 | llvm::BasicBlock *CleanupBB; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 165 | |
Anders Carlsson | ca2fec6 | 2009-02-07 23:30:41 +0000 | [diff] [blame] | 166 | public: |
| 167 | CleanupScope(CodeGenFunction &cgf) |
| 168 | : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()) { |
Anders Carlsson | 459ee36 | 2009-02-08 03:22:36 +0000 | [diff] [blame] | 169 | CleanupBB = CGF.createBasicBlock("cleanup"); |
| 170 | CGF.Builder.SetInsertPoint(CleanupBB); |
Anders Carlsson | ca2fec6 | 2009-02-07 23:30:41 +0000 | [diff] [blame] | 171 | } |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 172 | |
Anders Carlsson | ca2fec6 | 2009-02-07 23:30:41 +0000 | [diff] [blame] | 173 | ~CleanupScope() { |
Anders Carlsson | 459ee36 | 2009-02-08 03:22:36 +0000 | [diff] [blame] | 174 | CGF.PushCleanupBlock(CleanupBB); |
Anders Carlsson | ca2fec6 | 2009-02-07 23:30:41 +0000 | [diff] [blame] | 175 | CGF.Builder.SetInsertPoint(CurBB); |
| 176 | } |
| 177 | }; |
| 178 | |
Anders Carlsson | 883fa55 | 2009-02-07 23:50:39 +0000 | [diff] [blame] | 179 | /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup |
| 180 | /// blocks that have been added. |
| 181 | void EmitCleanupBlocks(size_t OldCleanupStackSize); |
| 182 | |
Anders Carlsson | ed536bc | 2009-02-08 00:50:42 +0000 | [diff] [blame] | 183 | /// EmitBranchThroughCleanup - Emit a branch from the current insert block |
| 184 | /// through the cleanup handling code (if any) and then on to \arg Dest. |
| 185 | /// |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 186 | /// FIXME: Maybe this should really be in EmitBranch? Don't we always want |
Anders Carlsson | ed536bc | 2009-02-08 00:50:42 +0000 | [diff] [blame] | 187 | /// this behavior for branches? |
| 188 | void EmitBranchThroughCleanup(llvm::BasicBlock *Dest); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 189 | |
Chris Lattner | 9fba49a | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 190 | private: |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 191 | /// LabelIDs - Track arbitrary ids assigned to labels for use in implementing |
| 192 | /// the GCC address-of-label extension and indirect goto. IDs are assigned to |
| 193 | /// labels inside getIDForAddrOfLabel(). |
Daniel Dunbar | 879788d | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 194 | std::map<const LabelStmt*, unsigned> LabelIDs; |
| 195 | |
| 196 | /// IndirectSwitches - Record the list of switches for indirect |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 197 | /// gotos. Emission of the actual switching code needs to be delayed until all |
| 198 | /// AddrLabelExprs have been seen. |
Daniel Dunbar | 879788d | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 199 | std::vector<llvm::SwitchInst*> IndirectSwitches; |
| 200 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 201 | /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C |
| 202 | /// decls. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 203 | llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; |
| 204 | |
| 205 | /// LabelMap - This keeps track of the LLVM basic block for each C label. |
| 206 | llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 207 | |
| 208 | /// BreakContinuePush - Note a new break and continue level. This must be |
| 209 | /// called at the stack depth of the continue block. In particular, this must |
| 210 | /// not be called after the controlling condition has possibly started a vla. |
Mike Stump | 88ad911 | 2009-02-07 12:52:26 +0000 | [diff] [blame] | 211 | void BreakContinuePush(llvm::BasicBlock *bb, llvm::BasicBlock *cb) { |
| 212 | BreakContinueStack.push_back(BreakContinue(bb, cb, StackDepth, |
Mike Stump | a1ac477 | 2009-02-07 23:02:10 +0000 | [diff] [blame] | 213 | StackDepth, |
| 214 | ObjCEHStack.size())); |
| 215 | } |
| 216 | void BreakContinuePush(llvm::BasicBlock *bb, llvm::BasicBlock *cb, |
| 217 | llvm::Value *bsd, llvm::Value *csd) { |
| 218 | BreakContinueStack.push_back(BreakContinue(bb, cb, bsd, csd, |
Mike Stump | 88ad911 | 2009-02-07 12:52:26 +0000 | [diff] [blame] | 219 | ObjCEHStack.size())); |
| 220 | } |
| 221 | |
| 222 | /// BreakContinuePop - Note end of previous break and continue level. |
| 223 | void BreakContinuePop() { |
| 224 | BreakContinueStack.pop_back(); |
| 225 | } |
| 226 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 227 | // BreakContinueStack - This keeps track of where break and continue |
Mike Stump | 88ad911 | 2009-02-07 12:52:26 +0000 | [diff] [blame] | 228 | // statements should jump to, as well as the depth of the stack and the size |
| 229 | // of the eh stack. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 230 | struct BreakContinue { |
Mike Stump | 88ad911 | 2009-02-07 12:52:26 +0000 | [diff] [blame] | 231 | BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb, |
Mike Stump | a1ac477 | 2009-02-07 23:02:10 +0000 | [diff] [blame] | 232 | llvm::Value *bsd, llvm::Value *csd, size_t ehss) |
| 233 | : BreakBlock(bb), ContinueBlock(cb), SaveBreakStackDepth(bsd), |
| 234 | SaveContinueStackDepth(csd), EHStackSize(ehss) {} |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 235 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 236 | llvm::BasicBlock *BreakBlock; |
| 237 | llvm::BasicBlock *ContinueBlock; |
Mike Stump | a1ac477 | 2009-02-07 23:02:10 +0000 | [diff] [blame] | 238 | llvm::Value *SaveBreakStackDepth; |
| 239 | llvm::Value *SaveContinueStackDepth; |
Anders Carlsson | c217619 | 2008-12-13 22:52:24 +0000 | [diff] [blame] | 240 | size_t EHStackSize; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 241 | }; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 242 | llvm::SmallVector<BreakContinue, 8> BreakContinueStack; |
Daniel Dunbar | 8354484 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 243 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 244 | /// SwitchInsn - This is nearest current switch instruction. It is null if if |
| 245 | /// current context is not in a switch. |
Devang Patel | e58e080 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 246 | llvm::SwitchInst *SwitchInsn; |
| 247 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 248 | /// CaseRangeBlock - This block holds if condition check for last case |
Devang Patel | bc37238 | 2007-10-09 17:08:50 +0000 | [diff] [blame] | 249 | /// statement range in current switch instruction. |
Devang Patel | 347ca32 | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 250 | llvm::BasicBlock *CaseRangeBlock; |
| 251 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 252 | // VLASizeMap - This keeps track of the associated size for each VLA type. |
| 253 | // FIXME: Maybe this could be a stack of maps that is pushed/popped as we |
| 254 | // enter/leave scopes. |
Anders Carlsson | 32aa0c2 | 2008-12-12 07:19:02 +0000 | [diff] [blame] | 255 | llvm::DenseMap<const VariableArrayType*, llvm::Value*> VLASizeMap; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 256 | |
| 257 | /// StackDepth - This keeps track of the stack depth. It is used to notice |
| 258 | /// when control flow results in a change in stack depth and to arrange for |
| 259 | /// the appropriate stack depth to be restored. VLAs are the primary means by |
| 260 | /// which the stack depth changes. |
Mike Stump | 88ad911 | 2009-02-07 12:52:26 +0000 | [diff] [blame] | 261 | llvm::Value *StackDepth; |
| 262 | |
Anders Carlsson | 60c4c40 | 2009-02-09 20:20:56 +0000 | [diff] [blame] | 263 | /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid |
| 264 | /// calling llvm.stacksave for multiple VLAs in the same scope. |
| 265 | bool DidCallStackSave; |
| 266 | |
Anders Carlsson | 438ddd8 | 2008-12-12 05:52:00 +0000 | [diff] [blame] | 267 | /// StackSaveValues - A stack(!) of stack save values. When a new scope is |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 268 | /// entered, a null is pushed on this stack. If a VLA is emitted, then the |
| 269 | /// return value of llvm.stacksave() is stored at the top of this stack. |
Anders Carlsson | 438ddd8 | 2008-12-12 05:52:00 +0000 | [diff] [blame] | 270 | llvm::SmallVector<llvm::Value*, 8> StackSaveValues; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 271 | |
| 272 | /// StackDepthMap - A association of stack depth that will be in effect for |
| 273 | /// each label. If control flow is transferred to a label, we have to restore |
| 274 | /// the desired stack depth at the destination label, beore we transfer to |
| 275 | /// that label. |
Mike Stump | 7e39f18 | 2009-02-08 09:22:19 +0000 | [diff] [blame] | 276 | llvm::DenseMap<const void*, llvm::Value *> StackDepthMap; |
| 277 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 278 | /// StackFixupAtLabel - Routine to adjust the stack to the depth the stack |
| 279 | /// should be at by the time we transfer control flow to the label. This is |
| 280 | /// called as we emit destinations for control flow, such as user labels for |
| 281 | /// goto statements and compiler generated labels for break and continue |
| 282 | /// processsing. We return true, if for any reason we can't generate code for |
| 283 | /// the construct yet. See EmitStackUpdate for the paired routine to mark the |
| 284 | /// branch. |
Mike Stump | 7e39f18 | 2009-02-08 09:22:19 +0000 | [diff] [blame] | 285 | bool StackFixupAtLabel(const void *); |
Mike Stump | 88ad911 | 2009-02-07 12:52:26 +0000 | [diff] [blame] | 286 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 287 | /// EmitStackUpdate - Routine to adjust the stack to the depth the stack |
| 288 | /// should be at by the time we transfer control flow to the label. This is |
| 289 | /// called just before emitting branches for user level goto processing, |
| 290 | /// branhes for break or continue processing. The llvm::value overload is |
| 291 | /// used when handling break and continue, as we know the stack depth |
| 292 | /// directly. We return true, if for any reason we can't generate code for |
| 293 | /// the construct yet. See StackFixupAtLabel for the paired routine to mark |
| 294 | /// the destinations. |
Mike Stump | 7e39f18 | 2009-02-08 09:22:19 +0000 | [diff] [blame] | 295 | bool EmitStackUpdate(llvm::Value *V); |
| 296 | bool EmitStackUpdate(const void *S); |
Mike Stump | 88ad911 | 2009-02-07 12:52:26 +0000 | [diff] [blame] | 297 | |
Anders Carlsson | 9c5b2a4 | 2009-02-07 22:53:43 +0000 | [diff] [blame] | 298 | struct CleanupEntry { |
| 299 | /// CleanupBlock - The block of code that does the actual cleanup. |
| 300 | llvm::BasicBlock *CleanupBlock; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 301 | |
Anders Carlsson | 9c5b2a4 | 2009-02-07 22:53:43 +0000 | [diff] [blame] | 302 | /// Blocks - Basic blocks that were emitted in the current cleanup scope. |
Anders Carlsson | df27419 | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 303 | std::vector<llvm::BasicBlock *> Blocks; |
Anders Carlsson | 9c5b2a4 | 2009-02-07 22:53:43 +0000 | [diff] [blame] | 304 | |
| 305 | /// BranchFixups - Branch instructions to basic blocks that haven't been |
| 306 | /// inserted into the current function yet. |
Anders Carlsson | df27419 | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 307 | std::vector<llvm::BranchInst *> BranchFixups; |
Anders Carlsson | 9c5b2a4 | 2009-02-07 22:53:43 +0000 | [diff] [blame] | 308 | |
| 309 | explicit CleanupEntry(llvm::BasicBlock *cb) |
| 310 | : CleanupBlock(cb) {} |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 311 | |
Anders Carlsson | e7de352 | 2009-02-08 00:16:35 +0000 | [diff] [blame] | 312 | ~CleanupEntry() { |
| 313 | assert(Blocks.empty() && "Did not empty blocks!"); |
| 314 | assert(BranchFixups.empty() && "Did not empty branch fixups!"); |
| 315 | } |
Anders Carlsson | 9c5b2a4 | 2009-02-07 22:53:43 +0000 | [diff] [blame] | 316 | }; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 317 | |
Anders Carlsson | 9c5b2a4 | 2009-02-07 22:53:43 +0000 | [diff] [blame] | 318 | /// CleanupEntries - Stack of cleanup entries. |
| 319 | llvm::SmallVector<CleanupEntry, 8> CleanupEntries; |
| 320 | |
Anders Carlsson | e7de352 | 2009-02-08 00:16:35 +0000 | [diff] [blame] | 321 | typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap; |
| 322 | |
| 323 | /// BlockScopes - Map of which "cleanup scope" scope basic blocks have. |
| 324 | BlockScopeMap BlockScopes; |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 325 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 326 | public: |
| 327 | CodeGenFunction(CodeGenModule &cgm); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 328 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 329 | ASTContext &getContext() const; |
| 330 | |
Chris Lattner | b326b17 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 331 | void GenerateObjCMethod(const ObjCMethodDecl *OMD); |
Daniel Dunbar | 6b57d43 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 332 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 333 | void StartObjCMethod(const ObjCMethodDecl *MD, |
Fariborz Jahanian | 0adaa8a | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 334 | const ObjCContainerDecl *CD); |
Daniel Dunbar | 6b57d43 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 335 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 336 | /// GenerateObjCGetter - Synthesize an Objective-C property getter function. |
Fariborz Jahanian | 91dd9d3 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 337 | void GenerateObjCGetter(ObjCImplementationDecl *IMP, |
| 338 | const ObjCPropertyImplDecl *PID); |
Daniel Dunbar | 6b57d43 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 339 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 340 | /// GenerateObjCSetter - Synthesize an Objective-C property setter function |
| 341 | /// for the given property. |
Fariborz Jahanian | 91dd9d3 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 342 | void GenerateObjCSetter(ObjCImplementationDecl *IMP, |
| 343 | const ObjCPropertyImplDecl *PID); |
Daniel Dunbar | 6b57d43 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 344 | |
Daniel Dunbar | 7bf5b3d | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 345 | void GenerateCode(const FunctionDecl *FD, |
| 346 | llvm::Function *Fn); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 347 | void StartFunction(const Decl *D, QualType RetTy, |
Daniel Dunbar | 9681683 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 348 | llvm::Function *Fn, |
Daniel Dunbar | 54968bf | 2008-10-18 18:22:23 +0000 | [diff] [blame] | 349 | const FunctionArgList &Args, |
| 350 | SourceLocation StartLoc); |
Daniel Dunbar | 5aa22bc | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 351 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 352 | /// EmitReturnBlock - Emit the unified return block, trying to avoid its |
| 353 | /// emission when possible. |
Daniel Dunbar | 924f4ea | 2009-01-26 23:27:52 +0000 | [diff] [blame] | 354 | void EmitReturnBlock(); |
| 355 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 356 | /// FinishFunction - Complete IR generation of the current function. It is |
| 357 | /// legal to call this function even if there is no current insertion point. |
Daniel Dunbar | 6b57d43 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 358 | void FinishFunction(SourceLocation EndLoc=SourceLocation()); |
Daniel Dunbar | fc1a9c4 | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 359 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 360 | /// EmitFunctionProlog - Emit the target specific LLVM code to load the |
| 361 | /// arguments for the given function. This is also responsible for naming the |
| 362 | /// LLVM function arguments. |
Daniel Dunbar | 6ee022b | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 363 | void EmitFunctionProlog(const CGFunctionInfo &FI, |
| 364 | llvm::Function *Fn, |
Daniel Dunbar | fc1a9c4 | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 365 | const FunctionArgList &Args); |
| 366 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 367 | /// EmitFunctionEpilog - Emit the target specific LLVM code to return the |
| 368 | /// given temporary. |
Daniel Dunbar | 6ee022b | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 369 | void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue); |
Daniel Dunbar | fc1a9c4 | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 370 | |
Daniel Dunbar | 706059f | 2009-02-03 23:03:55 +0000 | [diff] [blame] | 371 | const llvm::Type *ConvertTypeForMem(QualType T); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 372 | const llvm::Type *ConvertType(QualType T); |
Chris Lattner | 6e6a597 | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 373 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 374 | /// LoadObjCSelf - Load the value of self. This function is only valid while |
| 375 | /// generating code for an Objective-C method. |
Chris Lattner | 6e6a597 | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 376 | llvm::Value *LoadObjCSelf(); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 377 | |
| 378 | /// TypeOfSelfObject - Return type of object that this self represents. |
Fariborz Jahanian | 5534392 | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 379 | QualType TypeOfSelfObject(); |
Chris Lattner | 8c7c6a1 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 380 | |
| 381 | /// isObjCPointerType - Return true if the specificed AST type will map onto |
| 382 | /// some Objective-C pointer type. |
| 383 | static bool isObjCPointerType(QualType T); |
| 384 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 385 | /// hasAggregateLLVMType - Return true if the specified AST type will map into |
| 386 | /// an aggregate LLVM type or is void. |
| 387 | static bool hasAggregateLLVMType(QualType T); |
Daniel Dunbar | 72f9655 | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 388 | |
| 389 | /// createBasicBlock - Create an LLVM basic block. |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 390 | llvm::BasicBlock *createBasicBlock(const char *Name="", |
Daniel Dunbar | 72f9655 | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 391 | llvm::Function *Parent=0, |
| 392 | llvm::BasicBlock *InsertBefore=0) { |
Daniel Dunbar | 4dcabf3 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 393 | #ifdef NDEBUG |
| 394 | return llvm::BasicBlock::Create("", Parent, InsertBefore); |
| 395 | #else |
Daniel Dunbar | 72f9655 | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 396 | return llvm::BasicBlock::Create(Name, Parent, InsertBefore); |
Daniel Dunbar | 4dcabf3 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 397 | #endif |
Daniel Dunbar | 72f9655 | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 398 | } |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 399 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 400 | /// getBasicBlockForLabel - Return the LLVM basicblock that the specified |
| 401 | /// label maps to. |
| 402 | llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 403 | |
| 404 | /// EmitBlock - Emit the given block \arg BB and set it as the insert point, |
| 405 | /// adding a fall-through branch from the current insert block if |
| 406 | /// necessary. It is legal to call this function even if there is no current |
| 407 | /// insertion point. |
Daniel Dunbar | e220261 | 2008-11-13 01:24:05 +0000 | [diff] [blame] | 408 | /// |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 409 | /// IsFinished - If true, indicates that the caller has finished emitting |
| 410 | /// branches to the given block and does not expect to emit code into it. This |
| 411 | /// means the block can be ignored if it is unreachable. |
Daniel Dunbar | e220261 | 2008-11-13 01:24:05 +0000 | [diff] [blame] | 412 | void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); |
Daniel Dunbar | a2209a6 | 2008-11-11 04:34:23 +0000 | [diff] [blame] | 413 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 414 | /// EmitBranch - Emit a branch to the specified basic block from the current |
| 415 | /// insert block, taking care to avoid creation of branches from dummy |
| 416 | /// blocks. It is legal to call this function even if there is no current |
| 417 | /// insertion point. |
Daniel Dunbar | c55b7c5 | 2008-11-11 22:06:59 +0000 | [diff] [blame] | 418 | /// |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 419 | /// This function clears the current insertion point. The caller should follow |
| 420 | /// calls to this function with calls to Emit*Block prior to generation new |
| 421 | /// code. |
Daniel Dunbar | 5276caa | 2008-11-11 09:41:28 +0000 | [diff] [blame] | 422 | void EmitBranch(llvm::BasicBlock *Block); |
| 423 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 424 | /// HaveInsertPoint - True if an insertion point is defined. If not, this |
| 425 | /// indicates that the current code being emitted is unreachable. |
| 426 | bool HaveInsertPoint() const { |
Daniel Dunbar | 5aa22bc | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 427 | return Builder.GetInsertBlock() != 0; |
| 428 | } |
| 429 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 430 | /// EnsureInsertPoint - Ensure that an insertion point is defined so that |
| 431 | /// emitted IR has a place to go. Note that by definition, if this function |
| 432 | /// creates a block then that block is unreachable; callers may do better to |
| 433 | /// detect when no insertion point is defined and simply skip IR generation. |
Daniel Dunbar | 5aa22bc | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 434 | void EnsureInsertPoint() { |
| 435 | if (!HaveInsertPoint()) |
| 436 | EmitBlock(createBasicBlock()); |
| 437 | } |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 438 | |
Daniel Dunbar | 9503b78 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 439 | /// ErrorUnsupported - Print out an error that codegen doesn't support the |
Chris Lattner | 9d4e620 | 2007-12-02 01:43:38 +0000 | [diff] [blame] | 440 | /// specified stmt yet. |
Daniel Dunbar | 49bddf7 | 2008-09-04 03:43:08 +0000 | [diff] [blame] | 441 | void ErrorUnsupported(const Stmt *S, const char *Type, |
| 442 | bool OmitOnError=false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 443 | |
| 444 | //===--------------------------------------------------------------------===// |
| 445 | // Helpers |
| 446 | //===--------------------------------------------------------------------===// |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 447 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 448 | /// CreateTempAlloca - This creates a alloca and inserts it into the entry |
| 449 | /// block. |
| 450 | llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, |
| 451 | const char *Name = "tmp"); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 452 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 453 | /// EvaluateExprAsBool - Perform the usual unary conversions on the specified |
| 454 | /// expression and compare the result against zero, returning an Int1Ty value. |
| 455 | llvm::Value *EvaluateExprAsBool(const Expr *E); |
| 456 | |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 457 | /// EmitAnyExpr - Emit code to compute the specified expression which can have |
| 458 | /// any type. The result is returned as an RValue struct. If this is an |
| 459 | /// aggregate expression, the aggloc/agglocvolatile arguments indicate where |
| 460 | /// the result should be returned. |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 461 | RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 462 | bool isAggLocVolatile = false); |
Devang Patel | 9729936 | 2007-09-28 21:49:18 +0000 | [diff] [blame] | 463 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 464 | // EmitVAListRef - Emit a "reference" to a va_list; this is either the address |
| 465 | // or the value of the expression, depending on how va_list is defined. |
Eli Friedman | 8f5e878 | 2009-01-20 17:46:04 +0000 | [diff] [blame] | 466 | llvm::Value *EmitVAListRef(const Expr *E); |
| 467 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 468 | /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will |
| 469 | /// always be accessible even if no aggregate location is provided. |
| 470 | RValue EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc = 0, |
Daniel Dunbar | 0a2da0f | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 471 | bool isAggLocVolatile = false); |
| 472 | |
Daniel Dunbar | bde0c9d | 2008-09-09 20:49:46 +0000 | [diff] [blame] | 473 | void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, |
| 474 | QualType EltTy); |
| 475 | |
| 476 | void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty); |
| 477 | |
Devang Patel | e58e080 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 478 | /// StartBlock - Start new block named N. If insert block is a dummy block |
| 479 | /// then reuse it. |
| 480 | void StartBlock(const char *N); |
| 481 | |
Devang Patel | 7a78e43 | 2007-11-01 19:11:01 +0000 | [diff] [blame] | 482 | /// getCGRecordLayout - Return record layout info. |
| 483 | const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy); |
Lauro Ramos Venancio | 934fb02 | 2008-02-26 21:41:45 +0000 | [diff] [blame] | 484 | |
| 485 | /// GetAddrOfStaticLocalVar - Return the address of a static local variable. |
Steve Naroff | 72a6ebc | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 486 | llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD); |
Dan Gohman | 4751a3a | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 487 | |
Anders Carlsson | 75d8673 | 2008-09-11 09:15:33 +0000 | [diff] [blame] | 488 | /// GetAddrOfLocalVar - Return the address of a local variable. |
| 489 | llvm::Value *GetAddrOfLocalVar(const VarDecl *VD); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 490 | |
Dan Gohman | 4751a3a | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 491 | /// getAccessedFieldNo - Given an encoded value and a result number, return |
| 492 | /// the input field number being accessed. |
| 493 | static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); |
| 494 | |
Daniel Dunbar | 879788d | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 495 | unsigned GetIDForAddrOfLabel(const LabelStmt *L); |
| 496 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 497 | /// EmitMemSetToZero - Generate code to memset a value of the given type to 0. |
Anders Carlsson | 82b0d0c | 2008-08-30 19:51:14 +0000 | [diff] [blame] | 498 | void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty); |
Anders Carlsson | 285611e | 2008-11-04 05:30:00 +0000 | [diff] [blame] | 499 | |
| 500 | // EmitVAArg - Generate code to get an argument from the passed in pointer |
| 501 | // and update it accordingly. The return value is a pointer to the argument. |
| 502 | // FIXME: We should be able to get rid of this method and use the va_arg |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 503 | // instruction in LLVM instead once it works well enough. |
Anders Carlsson | 285611e | 2008-11-04 05:30:00 +0000 | [diff] [blame] | 504 | llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); |
Anders Carlsson | f860e02 | 2008-12-20 20:27:15 +0000 | [diff] [blame] | 505 | |
Anders Carlsson | d976761 | 2008-12-20 20:46:34 +0000 | [diff] [blame] | 506 | // EmitVLASize - Generate code for any VLA size expressions that might occur |
| 507 | // in a variably modified type. If Ty is a VLA, will return the value that |
| 508 | // corresponds to the size in bytes of the VLA type. Will return 0 otherwise. |
| 509 | llvm::Value *EmitVLASize(QualType Ty); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 510 | |
Anders Carlsson | 32aa0c2 | 2008-12-12 07:19:02 +0000 | [diff] [blame] | 511 | // GetVLASize - Returns an LLVM value that corresponds to the size in bytes |
| 512 | // of a variable length array type. |
| 513 | llvm::Value *GetVLASize(const VariableArrayType *); |
| 514 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 515 | //===--------------------------------------------------------------------===// |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 516 | // Declaration Emission |
| 517 | //===--------------------------------------------------------------------===// |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 518 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 519 | void EmitDecl(const Decl &D); |
Steve Naroff | 72a6ebc | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 520 | void EmitBlockVarDecl(const VarDecl &D); |
| 521 | void EmitLocalBlockVarDecl(const VarDecl &D); |
| 522 | void EmitStaticBlockVarDecl(const VarDecl &D); |
Daniel Dunbar | ace3329 | 2008-08-16 03:19:19 +0000 | [diff] [blame] | 523 | |
| 524 | /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. |
| 525 | void EmitParmDecl(const VarDecl &D, llvm::Value *Arg); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 526 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 527 | //===--------------------------------------------------------------------===// |
| 528 | // Statement Emission |
| 529 | //===--------------------------------------------------------------------===// |
| 530 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 531 | /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. |
Daniel Dunbar | 6c81e56 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 532 | void EmitStopPoint(const Stmt *S); |
| 533 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 534 | /// EmitStmt - Emit the code for the statement \arg S. It is legal to call |
| 535 | /// this function even if there is no current insertion point. |
| 536 | /// |
| 537 | /// This function may clear the current insertion point; callers should use |
| 538 | /// EnsureInsertPoint if they wish to subsequently generate code without first |
| 539 | /// calling EmitBlock, EmitBranch, or EmitStmt. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 540 | void EmitStmt(const Stmt *S); |
Daniel Dunbar | 5aa22bc | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 541 | |
Daniel Dunbar | 6c81e56 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 542 | /// EmitSimpleStmt - Try to emit a "simple" statement which does not |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 543 | /// necessarily require an insertion point or debug information; typically |
| 544 | /// because the statement amounts to a jump or a container of other |
| 545 | /// statements. |
Daniel Dunbar | 6c81e56 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 546 | /// |
| 547 | /// \return True if the statement was handled. |
| 548 | bool EmitSimpleStmt(const Stmt *S); |
| 549 | |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 550 | RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, |
| 551 | llvm::Value *AggLoc = 0, bool isAggVol = false); |
Daniel Dunbar | 5aa22bc | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 552 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 553 | /// EmitLabel - Emit the block for the given label. It is legal to call this |
| 554 | /// function even if there is no current insertion point. |
Chris Lattner | 09cee85 | 2008-07-26 20:23:23 +0000 | [diff] [blame] | 555 | void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt. |
Daniel Dunbar | 5aa22bc | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 556 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 557 | void EmitLabelStmt(const LabelStmt &S); |
| 558 | void EmitGotoStmt(const GotoStmt &S); |
Daniel Dunbar | 879788d | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 559 | void EmitIndirectGotoStmt(const IndirectGotoStmt &S); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 560 | void EmitIfStmt(const IfStmt &S); |
| 561 | void EmitWhileStmt(const WhileStmt &S); |
| 562 | void EmitDoStmt(const DoStmt &S); |
| 563 | void EmitForStmt(const ForStmt &S); |
| 564 | void EmitReturnStmt(const ReturnStmt &S); |
| 565 | void EmitDeclStmt(const DeclStmt &S); |
Daniel Dunbar | 6c81e56 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 566 | void EmitBreakStmt(const BreakStmt &S); |
| 567 | void EmitContinueStmt(const ContinueStmt &S); |
Devang Patel | e58e080 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 568 | void EmitSwitchStmt(const SwitchStmt &S); |
| 569 | void EmitDefaultStmt(const DefaultStmt &S); |
| 570 | void EmitCaseStmt(const CaseStmt &S); |
Devang Patel | 347ca32 | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 571 | void EmitCaseStmtRange(const CaseStmt &S); |
Anders Carlsson | af6a6c2 | 2008-02-05 16:35:33 +0000 | [diff] [blame] | 572 | void EmitAsmStmt(const AsmStmt &S); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 573 | |
Anders Carlsson | 82b0d0c | 2008-08-30 19:51:14 +0000 | [diff] [blame] | 574 | void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); |
Anders Carlsson | b01a211 | 2008-09-09 10:04:29 +0000 | [diff] [blame] | 575 | void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); |
| 576 | void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); |
Chris Lattner | dd97870 | 2008-11-15 21:26:17 +0000 | [diff] [blame] | 577 | void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 578 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 579 | //===--------------------------------------------------------------------===// |
| 580 | // LValue Expression Emission |
| 581 | //===--------------------------------------------------------------------===// |
| 582 | |
Daniel Dunbar | 900c85a | 2009-02-05 07:09:07 +0000 | [diff] [blame] | 583 | /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. |
| 584 | RValue GetUndefRValue(QualType Ty); |
| 585 | |
Daniel Dunbar | e3a6a68 | 2009-01-09 16:50:52 +0000 | [diff] [blame] | 586 | /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E |
| 587 | /// and issue an ErrorUnsupported style diagnostic (using the |
| 588 | /// provided Name). |
| 589 | RValue EmitUnsupportedRValue(const Expr *E, |
| 590 | const char *Name); |
| 591 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 592 | /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue |
| 593 | /// an ErrorUnsupported style diagnostic (using the provided Name). |
Daniel Dunbar | de1bd94 | 2008-08-25 20:45:57 +0000 | [diff] [blame] | 594 | LValue EmitUnsupportedLValue(const Expr *E, |
| 595 | const char *Name); |
| 596 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 597 | /// EmitLValue - Emit code to compute a designator that specifies the location |
| 598 | /// of the expression. |
| 599 | /// |
| 600 | /// This can return one of two things: a simple address or a bitfield |
| 601 | /// reference. In either case, the LLVM Value* in the LValue structure is |
| 602 | /// guaranteed to be an LLVM pointer type. |
| 603 | /// |
| 604 | /// If this returns a bitfield reference, nothing about the pointee type of |
| 605 | /// the LLVM value is known: For example, it may not be a pointer to an |
| 606 | /// integer. |
| 607 | /// |
| 608 | /// If this returns a normal address, and if the lvalue's C type is fixed |
| 609 | /// size, this method guarantees that the returned pointer type will point to |
| 610 | /// an LLVM type of the same size of the lvalue's type. If the lvalue has a |
| 611 | /// variable length type, this is not possible. |
| 612 | /// |
| 613 | LValue EmitLValue(const Expr *E); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 614 | |
Daniel Dunbar | f1c5d84 | 2009-02-10 00:57:50 +0000 | [diff] [blame^] | 615 | /// EmitLoadOfScalar - Load a scalar value from an address, taking |
| 616 | /// care to appropriately convert from the memory representation to |
| 617 | /// the LLVM value representation. |
| 618 | llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, |
| 619 | QualType Ty); |
| 620 | |
| 621 | /// EmitStoreOfScalar - Store a scalar value to an address, taking |
| 622 | /// care to appropriately convert from the memory representation to |
| 623 | /// the LLVM value representation. |
| 624 | void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, |
| 625 | bool Volatile); |
| 626 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 627 | /// EmitLoadOfLValue - Given an expression that represents a value lvalue, |
| 628 | /// this method emits the address of the lvalue, then loads the result as an |
| 629 | /// rvalue, returning the rvalue. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 630 | RValue EmitLoadOfLValue(LValue V, QualType LVType); |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 631 | RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType); |
Lauro Ramos Venancio | b40307c | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 632 | RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); |
Daniel Dunbar | e6c3175 | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 633 | RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType); |
Fariborz Jahanian | b0973da | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 634 | RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 635 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 636 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 637 | /// EmitStoreThroughLValue - Store the specified rvalue into the specified |
| 638 | /// lvalue, where both are guaranteed to the have the same type, and that type |
| 639 | /// is 'Ty'. |
| 640 | void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 641 | void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst, |
| 642 | QualType Ty); |
Daniel Dunbar | e6c3175 | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 643 | void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty); |
Fariborz Jahanian | b0973da | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 644 | void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty); |
Daniel Dunbar | 2668dd1 | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 645 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 646 | /// EmitStoreThroughLValue - Store Src into Dst with same constraints as |
| 647 | /// EmitStoreThroughLValue. |
Daniel Dunbar | 2668dd1 | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 648 | /// |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 649 | /// \param Result [out] - If non-null, this will be set to a Value* for the |
| 650 | /// bit-field contents after the store, appropriate for use as the result of |
| 651 | /// an assignment to the bit-field. |
Daniel Dunbar | 2668dd1 | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 652 | void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty, |
| 653 | llvm::Value **Result=0); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 654 | |
Christopher Lamb | ad327ba | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 655 | // Note: only availabe for agg return types |
Daniel Dunbar | ef0d4c7 | 2008-09-04 03:20:13 +0000 | [diff] [blame] | 656 | LValue EmitBinaryOperatorLValue(const BinaryOperator *E); |
| 657 | // Note: only availabe for agg return types |
Christopher Lamb | ad327ba | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 658 | LValue EmitCallExprLValue(const CallExpr *E); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 659 | LValue EmitDeclRefLValue(const DeclRefExpr *E); |
| 660 | LValue EmitStringLiteralLValue(const StringLiteral *E); |
Daniel Dunbar | a9f0be2 | 2008-10-17 21:58:32 +0000 | [diff] [blame] | 661 | LValue EmitPredefinedFunctionName(unsigned Type); |
Chris Lattner | 6990929 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 662 | LValue EmitPredefinedLValue(const PredefinedExpr *E); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 663 | LValue EmitUnaryOpLValue(const UnaryOperator *E); |
| 664 | LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 665 | LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); |
Devang Patel | aebd83f | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 666 | LValue EmitMemberExpr(const MemberExpr *E); |
Eli Friedman | f3c2cb4 | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 667 | LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); |
Eli Friedman | d355011 | 2008-02-09 08:50:58 +0000 | [diff] [blame] | 668 | |
Daniel Dunbar | e856ac2 | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 669 | llvm::Value *EmitIvarOffset(ObjCInterfaceDecl *Interface, |
| 670 | const ObjCIvarDecl *Ivar); |
Eli Friedman | d355011 | 2008-02-09 08:50:58 +0000 | [diff] [blame] | 671 | LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field, |
Eli Friedman | 2e63054 | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 672 | bool isUnion, unsigned CVRQualifiers); |
Fariborz Jahanian | 5534392 | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 673 | LValue EmitLValueForIvar(QualType ObjectTy, |
| 674 | llvm::Value* Base, const ObjCIvarDecl *Ivar, |
Fariborz Jahanian | 86008c0 | 2008-12-15 20:35:07 +0000 | [diff] [blame] | 675 | const FieldDecl *Field, |
Daniel Dunbar | e856ac2 | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 676 | unsigned CVRQualifiers); |
| 677 | |
Fariborz Jahanian | 86008c0 | 2008-12-15 20:35:07 +0000 | [diff] [blame] | 678 | LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field, |
Fariborz Jahanian | c912eb7 | 2009-02-03 19:03:09 +0000 | [diff] [blame] | 679 | unsigned CVRQualifiers); |
Fariborz Jahanian | 86008c0 | 2008-12-15 20:35:07 +0000 | [diff] [blame] | 680 | |
Argiris Kirtzidis | bf615b0 | 2008-09-10 02:36:38 +0000 | [diff] [blame] | 681 | LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E); |
| 682 | |
Daniel Dunbar | 5e10589 | 2008-08-23 10:51:21 +0000 | [diff] [blame] | 683 | LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); |
Chris Lattner | b326b17 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 684 | LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); |
Daniel Dunbar | e6c3175 | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 685 | LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E); |
Fariborz Jahanian | b0973da | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 686 | LValue EmitObjCKVCRefLValue(const ObjCKVCRefExpr *E); |
Douglas Gregor | d860663 | 2008-11-04 14:56:14 +0000 | [diff] [blame] | 687 | LValue EmitObjCSuperExpr(const ObjCSuperExpr *E); |
Daniel Dunbar | 5e10589 | 2008-08-23 10:51:21 +0000 | [diff] [blame] | 688 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 689 | //===--------------------------------------------------------------------===// |
Chris Lattner | bdb8ffb | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 690 | // Scalar Expression Emission |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 691 | //===--------------------------------------------------------------------===// |
| 692 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 693 | /// EmitCall - Generate a call of the given function, expecting the given |
| 694 | /// result type, and using the given argument list which specifies both the |
| 695 | /// LLVM arguments and the types they were derived from. |
Daniel Dunbar | 6ee022b | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 696 | RValue EmitCall(const CGFunctionInfo &FnInfo, |
| 697 | llvm::Value *Callee, |
Daniel Dunbar | 0ed60b0 | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 698 | const CallArgList &Args); |
| 699 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 700 | RValue EmitCallExpr(const CallExpr *E); |
Ted Kremenek | 2719e98 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 701 | |
| 702 | RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg, |
| 703 | CallExpr::const_arg_iterator ArgEnd); |
| 704 | |
Eli Friedman | 261f4ad | 2008-01-30 01:32:06 +0000 | [diff] [blame] | 705 | RValue EmitCallExpr(llvm::Value *Callee, QualType FnType, |
Ted Kremenek | 2719e98 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 706 | CallExpr::const_arg_iterator ArgBeg, |
| 707 | CallExpr::const_arg_iterator ArgEnd); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 708 | |
Chris Lattner | 35055b8 | 2007-08-26 22:58:05 +0000 | [diff] [blame] | 709 | RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 710 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 711 | /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call |
| 712 | /// is unhandled by the current target. |
Daniel Dunbar | 1cdfe14 | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 713 | llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 714 | |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 715 | llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 716 | llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 717 | |
Anders Carlsson | a9234fe | 2007-12-10 19:35:18 +0000 | [diff] [blame] | 718 | llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...); |
Nate Begeman | ec2d106 | 2007-12-30 02:59:45 +0000 | [diff] [blame] | 719 | llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals, |
| 720 | bool isSplat = false); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 721 | |
Daniel Dunbar | f1f7f19 | 2008-08-20 00:28:19 +0000 | [diff] [blame] | 722 | llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); |
Chris Lattner | 9fba49a | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 723 | llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); |
Chris Lattner | 6ee20e3 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 724 | llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); |
Daniel Dunbar | a04840b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 725 | RValue EmitObjCMessageExpr(const ObjCMessageExpr *E); |
Fariborz Jahanian | f18d4c8 | 2008-11-22 18:39:36 +0000 | [diff] [blame] | 726 | RValue EmitObjCPropertyGet(const Expr *E); |
Fariborz Jahanian | b0973da | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 727 | void EmitObjCPropertySet(const Expr *E, RValue Src); |
Chris Lattner | 6ee20e3 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 728 | |
| 729 | |
Chris Lattner | bdb8ffb | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 730 | //===--------------------------------------------------------------------===// |
Chris Lattner | 41b1fca | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 731 | // Expression Emission |
Chris Lattner | bdb8ffb | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 732 | //===--------------------------------------------------------------------===// |
Chris Lattner | 41b1fca | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 733 | |
| 734 | // Expressions are broken into three classes: scalar, complex, aggregate. |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 735 | |
| 736 | /// EmitScalarExpr - Emit the computation of the specified expression of LLVM |
| 737 | /// scalar type, returning the result. |
Chris Lattner | 9fba49a | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 738 | llvm::Value *EmitScalarExpr(const Expr *E); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 739 | |
Chris Lattner | 4e05d1e | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 740 | /// EmitScalarConversion - Emit a conversion from the specified type to the |
| 741 | /// specified destination type, both of which are LLVM scalar types. |
| 742 | llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, |
| 743 | QualType DstTy); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 744 | |
Chris Lattner | fb182ee | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 745 | /// EmitComplexToScalarConversion - Emit a conversion from the specified |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 746 | /// complex type to the specified destination type, where the destination type |
| 747 | /// is an LLVM scalar type. |
Chris Lattner | fb182ee | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 748 | llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, |
| 749 | QualType DstTy); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 750 | |
| 751 | |
Chris Lattner | bdb8ffb | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 752 | /// EmitAggExpr - Emit the computation of the specified expression of |
| 753 | /// aggregate type. The result is computed into DestPtr. Note that if |
| 754 | /// DestPtr is null, the value of the aggregate expression is not needed. |
| 755 | void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 756 | |
Chris Lattner | 8d0cc2f | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 757 | /// EmitComplexExpr - Emit the computation of the specified expression of |
Chris Lattner | 348c8a2 | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 758 | /// complex type, returning the result. |
Chris Lattner | 5280c5f | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 759 | ComplexPairTy EmitComplexExpr(const Expr *E); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 760 | |
Chris Lattner | 348c8a2 | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 761 | /// EmitComplexExprIntoAddr - Emit the computation of the specified expression |
| 762 | /// of complex type, storing into the specified Value*. |
Chris Lattner | 8e1f6e0 | 2007-08-26 16:22:13 +0000 | [diff] [blame] | 763 | void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, |
| 764 | bool DestIsVolatile); |
Daniel Dunbar | dd85128 | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 765 | |
| 766 | /// StoreComplexToAddr - Store a complex number into the specified address. |
| 767 | void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr, |
| 768 | bool DestIsVolatile); |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 769 | /// LoadComplexFromAddr - Load a complex number from the specified address. |
| 770 | ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); |
Chris Lattner | 85970f3 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 771 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 772 | /// GenerateStaticBlockVarDecl - return the the static declaration of local |
| 773 | /// variable. |
Sanjiv Gupta | f7fd8e5 | 2009-02-03 18:07:49 +0000 | [diff] [blame] | 774 | llvm::GlobalValue * GenerateStaticBlockVarDecl(const VarDecl &D, |
| 775 | bool NoInit, |
| 776 | const char *Separator, |
| 777 | llvm::GlobalValue |
| 778 | ::LinkageTypes Linkage); |
Daniel Dunbar | 879788d | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 779 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 780 | // GenerateStaticCXXBlockVarDecl - return the static declaration of a local |
| 781 | // variable. Performs initialization of the variable if necessary. |
Anders Carlsson | c9f8ccd | 2008-08-22 16:00:37 +0000 | [diff] [blame] | 782 | llvm::GlobalValue *GenerateStaticCXXBlockVarDecl(const VarDecl &D); |
| 783 | |
Daniel Dunbar | 879788d | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 784 | //===--------------------------------------------------------------------===// |
| 785 | // Internal Helpers |
| 786 | //===--------------------------------------------------------------------===// |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 787 | |
Chris Lattner | 3f73d0d | 2008-11-11 07:41:27 +0000 | [diff] [blame] | 788 | /// ContainsLabel - Return true if the statement contains a label in it. If |
| 789 | /// this statement is not executed normally, it not containing a label means |
| 790 | /// that we can just remove the code. |
| 791 | static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 792 | |
Daniel Dunbar | 45e3867 | 2008-11-12 10:12:14 +0000 | [diff] [blame] | 793 | /// ConstantFoldsToSimpleInteger - If the specified expression does not fold |
Chris Lattner | 3d6606b | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 794 | /// to a constant, or if it does but contains a label, return 0. If it |
| 795 | /// constant folds to 'true' and does not contain a label, return 1, if it |
| 796 | /// constant folds to 'false' and does not contain a label, return -1. |
| 797 | int ConstantFoldsToSimpleInteger(const Expr *Cond); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 798 | |
Chris Lattner | 3d6606b | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 799 | /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an |
| 800 | /// if statement) to the specified blocks. Based on the condition, this might |
| 801 | /// try to simplify the codegen of the conditional based on the branch. |
Chris Lattner | 1875ba2 | 2008-11-12 07:46:33 +0000 | [diff] [blame] | 802 | void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, |
Daniel Dunbar | 45e3867 | 2008-11-12 10:12:14 +0000 | [diff] [blame] | 803 | llvm::BasicBlock *FalseBlock); |
Chris Lattner | 3d6606b | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 804 | private: |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 805 | |
Daniel Dunbar | 879788d | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 806 | /// EmitIndirectSwitches - Emit code for all of the switch |
| 807 | /// instructions in IndirectSwitches. |
| 808 | void EmitIndirectSwitches(); |
Daniel Dunbar | 04d3578 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 809 | |
Daniel Dunbar | e856ac2 | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 810 | void EmitReturnOfRValue(RValue RV, QualType Ty); |
| 811 | |
Daniel Dunbar | 04d3578 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 812 | /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty |
| 813 | /// from function arguments into \arg Dst. See ABIArgInfo::Expand. |
| 814 | /// |
| 815 | /// \param AI - The first function argument of the expansion. |
| 816 | /// \return The argument following the last expanded function |
| 817 | /// argument. |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 818 | llvm::Function::arg_iterator |
Daniel Dunbar | 04d3578 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 819 | ExpandTypeFromArgs(QualType Ty, LValue Dst, |
| 820 | llvm::Function::arg_iterator AI); |
| 821 | |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 822 | /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg |
| 823 | /// Ty, into individual arguments on the provided vector \arg Args. See |
| 824 | /// ABIArgInfo::Expand. |
| 825 | void ExpandTypeToArgs(QualType Ty, RValue Src, |
Daniel Dunbar | 04d3578 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 826 | llvm::SmallVector<llvm::Value*, 16> &Args); |
Anders Carlsson | 60bb4d4 | 2009-01-11 19:40:10 +0000 | [diff] [blame] | 827 | |
| 828 | llvm::Value* EmitAsmInput(const AsmStmt &S, TargetInfo::ConstraintInfo Info, |
| 829 | const Expr *InputExpr, std::string &ConstraintStr); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 830 | |
Anders Carlsson | 883fa55 | 2009-02-07 23:50:39 +0000 | [diff] [blame] | 831 | /// EmitCleanupBlock - emits a single cleanup block. |
| 832 | void EmitCleanupBlock(); |
| 833 | |
Anders Carlsson | ed536bc | 2009-02-08 00:50:42 +0000 | [diff] [blame] | 834 | /// AddBranchFixup - adds a branch instruction to the list of fixups for the |
| 835 | /// current cleanup scope. |
| 836 | void AddBranchFixup(llvm::BranchInst *BI); |
Mike Stump | b699aa6 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 837 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 838 | }; |
| 839 | } // end namespace CodeGen |
| 840 | } // end namespace clang |
| 841 | |
| 842 | #endif |