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