blob: 38e10e90cefd04233108f2dfcd72b10696f9566a [file] [log] [blame]
Daniel Dunbar9c426522008-07-29 23:18:29 +00001//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===//
Chris Lattnerbed31442007-05-28 01:07:47 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerbed31442007-05-28 01:07:47 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This is the internal per-function state used for llvm translation.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattnerc18bfbb2008-02-29 17:10:38 +000014#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
15#define CLANG_CODEGEN_CODEGENFUNCTION_H
Chris Lattnerbed31442007-05-28 01:07:47 +000016
Chris Lattner4bd55962008-03-30 23:03:07 +000017#include "clang/AST/Type.h"
Chris Lattnerac248202007-05-30 00:13:02 +000018#include "llvm/ADT/DenseMap.h"
Chris Lattnere73e4322007-07-16 21:28:45 +000019#include "llvm/ADT/SmallVector.h"
Chris Lattner61705c12008-04-13 07:32:11 +000020#include "llvm/Support/IRBuilder.h"
Ted Kremenek08e17112008-06-17 02:43:46 +000021#include "clang/AST/Expr.h"
22#include "clang/AST/ExprObjC.h"
23
Chris Lattner2ccb73b2007-06-16 00:16:26 +000024#include <vector>
Chris Lattner308f4312007-05-29 23:50:05 +000025
Chris Lattnerbed31442007-05-28 01:07:47 +000026namespace llvm {
27 class Module;
Chris Lattner23b7eb62007-06-15 23:05:46 +000028}
29
Chris Lattnerbed31442007-05-28 01:07:47 +000030namespace clang {
31 class ASTContext;
Chris Lattner84915fa2007-06-02 04:16:21 +000032 class Decl;
Chris Lattnerbed31442007-05-28 01:07:47 +000033 class FunctionDecl;
Chris Lattner4bd55962008-03-30 23:03:07 +000034 class ObjCMethodDecl;
Chris Lattner2ccb73b2007-06-16 00:16:26 +000035 class TargetInfo;
Chris Lattner2ccb73b2007-06-16 00:16:26 +000036 class FunctionTypeProto;
Devang Patel3e11cce2007-10-23 02:10:49 +000037
Chris Lattnerbed31442007-05-28 01:07:47 +000038namespace CodeGen {
39 class CodeGenModule;
Devang Patel3e11cce2007-10-23 02:10:49 +000040 class CodeGenTypes;
Devang Patele11664a2007-11-01 19:11:01 +000041 class CGRecordLayout;
Chris Lattnerd7f58862007-06-02 05:24:33 +000042
Chris Lattner8394d792007-06-05 20:53:16 +000043/// RValue - This trivial value class is used to represent the result of an
Chris Lattner4647a212007-08-31 22:49:20 +000044/// expression that is evaluated. It can be one of three things: either a
45/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
46/// address of an aggregate value in memory.
Chris Lattner8394d792007-06-05 20:53:16 +000047class RValue {
Chris Lattner4647a212007-08-31 22:49:20 +000048 llvm::Value *V1, *V2;
Chris Lattnerdb91b162007-06-02 00:16:28 +000049 // TODO: Encode this into the low bit of pointer for more efficient
50 // return-by-value.
Chris Lattner4647a212007-08-31 22:49:20 +000051 enum { Scalar, Complex, Aggregate } Flavor;
Chris Lattner09153c02007-06-22 18:48:09 +000052
53 // FIXME: Aggregate rvalues need to retain information about whether they are
54 // volatile or not.
Chris Lattner5269c032007-05-30 21:03:58 +000055public:
56
Chris Lattner4647a212007-08-31 22:49:20 +000057 bool isScalar() const { return Flavor == Scalar; }
58 bool isComplex() const { return Flavor == Complex; }
59 bool isAggregate() const { return Flavor == Aggregate; }
Chris Lattner5269c032007-05-30 21:03:58 +000060
Chris Lattner4647a212007-08-31 22:49:20 +000061 /// getScalar() - Return the Value* of this scalar value.
62 llvm::Value *getScalarVal() const {
63 assert(isScalar() && "Not a scalar!");
64 return V1;
Chris Lattner5269c032007-05-30 21:03:58 +000065 }
66
Chris Lattner4647a212007-08-31 22:49:20 +000067 /// getComplexVal - Return the real/imag components of this complex value.
68 ///
69 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
70 return std::pair<llvm::Value *, llvm::Value *>(V1, V2);
71 }
72
Chris Lattner09153c02007-06-22 18:48:09 +000073 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
74 llvm::Value *getAggregateAddr() const {
Chris Lattner5269c032007-05-30 21:03:58 +000075 assert(isAggregate() && "Not an aggregate!");
Chris Lattner4647a212007-08-31 22:49:20 +000076 return V1;
Chris Lattner5269c032007-05-30 21:03:58 +000077 }
Chris Lattner208ae962007-05-30 17:57:17 +000078
Chris Lattner23b7eb62007-06-15 23:05:46 +000079 static RValue get(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +000080 RValue ER;
Chris Lattner4647a212007-08-31 22:49:20 +000081 ER.V1 = V;
82 ER.Flavor = Scalar;
83 return ER;
84 }
85 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
86 RValue ER;
87 ER.V1 = V1;
88 ER.V2 = V2;
89 ER.Flavor = Complex;
90 return ER;
91 }
92 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
93 RValue ER;
94 ER.V1 = C.first;
95 ER.V2 = C.second;
96 ER.Flavor = Complex;
Chris Lattner208ae962007-05-30 17:57:17 +000097 return ER;
98 }
Chris Lattner23b7eb62007-06-15 23:05:46 +000099 static RValue getAggregate(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +0000100 RValue ER;
Chris Lattner4647a212007-08-31 22:49:20 +0000101 ER.V1 = V;
102 ER.Flavor = Aggregate;
Chris Lattner208ae962007-05-30 17:57:17 +0000103 return ER;
104 }
105};
Chris Lattnerd7f58862007-06-02 05:24:33 +0000106
107
108/// LValue - This represents an lvalue references. Because C/C++ allow
109/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
110/// bitrange.
111class LValue {
Eli Friedman327944b2008-06-13 23:01:12 +0000112 // FIXME: alignment?
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000113
114 enum {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000115 Simple, // This is a normal l-value, use getAddress().
116 VectorElt, // This is a vector element l-value (V[i]), use getVector*
117 BitField, // This is a bitfield l-value, use getBitfield*.
Nate Begemance4d7fc2008-04-18 23:10:10 +0000118 ExtVectorElt // This is an extended vector subset, use getExtVectorComp
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000119 } LVType;
120
Chris Lattnerd7f58862007-06-02 05:24:33 +0000121 llvm::Value *V;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000122
123 union {
Nate Begemanf322eab2008-05-09 06:41:27 +0000124 // Index into a vector subscript: V[i]
125 llvm::Value *VectorIdx;
126
127 // ExtVector element subset: V.xyx
128 llvm::Constant *VectorElts;
129
Nate Begemane7f45b22008-07-25 20:15:41 +0000130 // BitField start bit and size
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000131 struct {
132 unsigned short StartBit;
133 unsigned short Size;
134 bool IsSigned;
Nate Begemane7f45b22008-07-25 20:15:41 +0000135 } BitfieldData;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000136 };
Eli Friedman327944b2008-06-13 23:01:12 +0000137
138 bool Volatile:1;
139 // FIXME: set but never used, what effect should it have?
140 bool Restrict:1;
141
142private:
143 static void SetQualifiers(unsigned Qualifiers, LValue& R) {
144 R.Volatile = (Qualifiers&QualType::Volatile)!=0;
145 R.Restrict = (Qualifiers&QualType::Restrict)!=0;
146 }
147
Chris Lattnerd7f58862007-06-02 05:24:33 +0000148public:
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000149 bool isSimple() const { return LVType == Simple; }
150 bool isVectorElt() const { return LVType == VectorElt; }
151 bool isBitfield() const { return LVType == BitField; }
Nate Begemance4d7fc2008-04-18 23:10:10 +0000152 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Chris Lattner208ae962007-05-30 17:57:17 +0000153
Eli Friedman327944b2008-06-13 23:01:12 +0000154 bool isVolatileQualified() const { return Volatile; }
155 bool isRestrictQualified() const { return Restrict; }
156
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000157 // simple lvalue
158 llvm::Value *getAddress() const { assert(isSimple()); return V; }
159 // vector elt lvalue
160 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
161 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Nate Begemance4d7fc2008-04-18 23:10:10 +0000162 // extended vector elements.
163 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
Nate Begemanf322eab2008-05-09 06:41:27 +0000164 llvm::Constant *getExtVectorElts() const {
Nate Begemance4d7fc2008-04-18 23:10:10 +0000165 assert(isExtVectorElt());
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000166 return VectorElts;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000167 }
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000168 // bitfield lvalue
169 llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; }
170 unsigned short getBitfieldStartBit() const {
171 assert(isBitfield());
172 return BitfieldData.StartBit;
173 }
174 unsigned short getBitfieldSize() const {
175 assert(isBitfield());
176 return BitfieldData.Size;
177 }
178 bool isBitfieldSigned() const {
179 assert(isBitfield());
180 return BitfieldData.IsSigned;
181 }
182
Eli Friedman327944b2008-06-13 23:01:12 +0000183 static LValue MakeAddr(llvm::Value *V, unsigned Qualifiers) {
Chris Lattnerd7f58862007-06-02 05:24:33 +0000184 LValue R;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000185 R.LVType = Simple;
Chris Lattnerd7f58862007-06-02 05:24:33 +0000186 R.V = V;
Eli Friedman327944b2008-06-13 23:01:12 +0000187 SetQualifiers(Qualifiers,R);
Chris Lattnerd7f58862007-06-02 05:24:33 +0000188 return R;
189 }
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000190
Eli Friedman327944b2008-06-13 23:01:12 +0000191 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
192 unsigned Qualifiers) {
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000193 LValue R;
194 R.LVType = VectorElt;
195 R.V = Vec;
196 R.VectorIdx = Idx;
Eli Friedman327944b2008-06-13 23:01:12 +0000197 SetQualifiers(Qualifiers,R);
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000198 return R;
199 }
200
Eli Friedman327944b2008-06-13 23:01:12 +0000201 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
202 unsigned Qualifiers) {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000203 LValue R;
Nate Begemance4d7fc2008-04-18 23:10:10 +0000204 R.LVType = ExtVectorElt;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000205 R.V = Vec;
Nate Begemanf322eab2008-05-09 06:41:27 +0000206 R.VectorElts = Elts;
Eli Friedman327944b2008-06-13 23:01:12 +0000207 SetQualifiers(Qualifiers,R);
Chris Lattner9e751ca2007-08-02 23:37:31 +0000208 return R;
209 }
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000210
211 static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
Eli Friedman327944b2008-06-13 23:01:12 +0000212 unsigned short Size, bool IsSigned,
213 unsigned Qualifiers) {
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000214 LValue R;
215 R.LVType = BitField;
216 R.V = V;
217 R.BitfieldData.StartBit = StartBit;
218 R.BitfieldData.Size = Size;
219 R.BitfieldData.IsSigned = IsSigned;
Eli Friedman327944b2008-06-13 23:01:12 +0000220 SetQualifiers(Qualifiers,R);
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000221 return R;
222 }
Chris Lattnerd7f58862007-06-02 05:24:33 +0000223};
224
Chris Lattnerbed31442007-05-28 01:07:47 +0000225/// CodeGenFunction - This class organizes the per-function state that is used
226/// while generating LLVM code.
227class CodeGenFunction {
Chris Lattnerbda69f82007-08-26 23:13:56 +0000228public:
Chris Lattnerbed31442007-05-28 01:07:47 +0000229 CodeGenModule &CGM; // Per-module state.
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000230 TargetInfo &Target;
Chris Lattnerbda69f82007-08-26 23:13:56 +0000231
Chris Lattner96d72562007-08-21 16:57:55 +0000232 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Chris Lattner61705c12008-04-13 07:32:11 +0000233 llvm::IRBuilder Builder;
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000234
Chris Lattner5506f8c2008-04-04 04:07:35 +0000235 // Holds the Decl for the current function or method
Chris Lattner5696e7b2008-06-17 18:05:57 +0000236 const Decl *CurFuncDecl;
Chris Lattner4bd55962008-03-30 23:03:07 +0000237 QualType FnRetTy;
Chris Lattnerac248202007-05-30 00:13:02 +0000238 llvm::Function *CurFn;
239
Chris Lattner03df1222007-06-02 04:53:11 +0000240 /// AllocaInsertPoint - This is an instruction in the entry block before which
241 /// we prefer to insert allocas.
242 llvm::Instruction *AllocaInsertPt;
243
Chris Lattner6db1fb82007-06-02 22:49:07 +0000244 const llvm::Type *LLVMIntTy;
Hartmut Kaiser7078da82007-10-17 15:00:17 +0000245 uint32_t LLVMPointerWidth;
Chris Lattner6db1fb82007-06-02 22:49:07 +0000246
Chris Lattner2da04b32007-08-24 05:35:26 +0000247private:
Chris Lattner84915fa2007-06-02 04:16:21 +0000248 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
249 /// decls.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000250 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
Chris Lattner84915fa2007-06-02 04:16:21 +0000251
Chris Lattnerac248202007-05-30 00:13:02 +0000252 /// LabelMap - This keeps track of the LLVM basic block for each C label.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000253 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnere73e4322007-07-16 21:28:45 +0000254
255 // BreakContinueStack - This keeps track of where break and continue
256 // statements should jump to.
257 struct BreakContinue {
258 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
259 : BreakBlock(bb), ContinueBlock(cb) {}
260
261 llvm::BasicBlock *BreakBlock;
262 llvm::BasicBlock *ContinueBlock;
263 };
264 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
265
Devang Patel49a44f32007-10-09 17:08:50 +0000266 /// SwitchInsn - This is nearest current switch instruction. It is null if
267 /// if current context is not in a switch.
Devang Patelda5d6bb2007-10-04 23:45:31 +0000268 llvm::SwitchInst *SwitchInsn;
269
Devang Patel49a44f32007-10-09 17:08:50 +0000270 /// CaseRangeBlock - This block holds if condition check for last case
271 /// statement range in current switch instruction.
Devang Patel11663122007-10-08 20:57:48 +0000272 llvm::BasicBlock *CaseRangeBlock;
273
Chris Lattnerbed31442007-05-28 01:07:47 +0000274public:
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000275 CodeGenFunction(CodeGenModule &cgm);
Chris Lattnerbed31442007-05-28 01:07:47 +0000276
Chris Lattner6db1fb82007-06-02 22:49:07 +0000277 ASTContext &getContext() const;
278
Chris Lattner4bd55962008-03-30 23:03:07 +0000279 void GenerateObjCMethod(const ObjCMethodDecl *OMD);
Daniel Dunbar9c426522008-07-29 23:18:29 +0000280 void GenerateCode(const FunctionDecl *FD,
281 llvm::Function *Fn);
Chris Lattner5696e7b2008-06-17 18:05:57 +0000282 void GenerateFunction(const Stmt *Body);
Chris Lattner308f4312007-05-29 23:50:05 +0000283
Chris Lattnerf033c142007-06-22 19:05:19 +0000284 const llvm::Type *ConvertType(QualType T);
Chris Lattner5506f8c2008-04-04 04:07:35 +0000285
286 llvm::Value *LoadObjCSelf();
Chris Lattner5696e7b2008-06-17 18:05:57 +0000287
288 /// isObjCPointerType - Return true if the specificed AST type will map onto
289 /// some Objective-C pointer type.
290 static bool isObjCPointerType(QualType T);
291
Chris Lattner54fb19e2007-06-22 22:02:34 +0000292 /// hasAggregateLLVMType - Return true if the specified AST type will map into
293 /// an aggregate LLVM type or is void.
294 static bool hasAggregateLLVMType(QualType T);
295
Chris Lattnerac248202007-05-30 00:13:02 +0000296 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
297 /// label maps to.
298 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
299
300
Chris Lattner23b7eb62007-06-15 23:05:46 +0000301 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattnerfc944342007-12-02 01:43:38 +0000302
303 /// WarnUnsupported - Print out a warning that codegen doesn't support the
304 /// specified stmt yet.
Chris Lattnerf0780fa2007-12-02 01:49:16 +0000305 void WarnUnsupported(const Stmt *S, const char *Type);
Chris Lattner84915fa2007-06-02 04:16:21 +0000306
Chris Lattnere9a64532007-06-22 21:44:33 +0000307 //===--------------------------------------------------------------------===//
308 // Helpers
309 //===--------------------------------------------------------------------===//
310
311 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
312 /// block.
313 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
314 const char *Name = "tmp");
315
Chris Lattner8394d792007-06-05 20:53:16 +0000316 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
317 /// expression and compare the result against zero, returning an Int1Ty value.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000318 llvm::Value *EvaluateExprAsBool(const Expr *E);
Chris Lattnere9a64532007-06-22 21:44:33 +0000319
Chris Lattner4647a212007-08-31 22:49:20 +0000320 /// EmitAnyExpr - Emit code to compute the specified expression which can have
321 /// any type. The result is returned as an RValue struct. If this is an
322 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
323 /// the result should be returned.
324 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
325 bool isAggLocVolatile = false);
Devang Patel8ec4f832007-09-28 21:49:18 +0000326
327 /// isDummyBlock - Return true if BB is an empty basic block
328 /// with no predecessors.
329 static bool isDummyBlock(const llvm::BasicBlock *BB);
330
Devang Patelda5d6bb2007-10-04 23:45:31 +0000331 /// StartBlock - Start new block named N. If insert block is a dummy block
332 /// then reuse it.
333 void StartBlock(const char *N);
334
Devang Patele11664a2007-11-01 19:11:01 +0000335 /// getCGRecordLayout - Return record layout info.
336 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Lauro Ramos Venancio01a72ff2008-02-26 21:41:45 +0000337
338 /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
Steve Naroff08899ff2008-04-15 22:42:06 +0000339 llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
Dan Gohman75d69da2008-05-22 00:50:06 +0000340
341 /// getAccessedFieldNo - Given an encoded value and a result number, return
342 /// the input field number being accessed.
343 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
344
Chris Lattner8394d792007-06-05 20:53:16 +0000345 //===--------------------------------------------------------------------===//
Chris Lattner53621a52007-06-13 20:44:40 +0000346 // Declaration Emission
Chris Lattner84915fa2007-06-02 04:16:21 +0000347 //===--------------------------------------------------------------------===//
348
Chris Lattner1ad38f82007-06-09 01:20:56 +0000349 void EmitDecl(const Decl &D);
Chris Lattner84915fa2007-06-02 04:16:21 +0000350 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Steve Naroff08899ff2008-04-15 22:42:06 +0000351 void EmitBlockVarDecl(const VarDecl &D);
352 void EmitLocalBlockVarDecl(const VarDecl &D);
353 void EmitStaticBlockVarDecl(const VarDecl &D);
Chris Lattner53621a52007-06-13 20:44:40 +0000354 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
Chris Lattner03df1222007-06-02 04:53:11 +0000355
Chris Lattner84915fa2007-06-02 04:16:21 +0000356 //===--------------------------------------------------------------------===//
Chris Lattner308f4312007-05-29 23:50:05 +0000357 // Statement Emission
358 //===--------------------------------------------------------------------===//
359
360 void EmitStmt(const Stmt *S);
Chris Lattner4647a212007-08-31 22:49:20 +0000361 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
362 llvm::Value *AggLoc = 0, bool isAggVol = false);
Chris Lattner7e800972008-07-26 20:23:23 +0000363 void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
Chris Lattnerac248202007-05-30 00:13:02 +0000364 void EmitLabelStmt(const LabelStmt &S);
365 void EmitGotoStmt(const GotoStmt &S);
Chris Lattner5269c032007-05-30 21:03:58 +0000366 void EmitIfStmt(const IfStmt &S);
Chris Lattner946aa312007-06-05 03:59:43 +0000367 void EmitWhileStmt(const WhileStmt &S);
Chris Lattner8394d792007-06-05 20:53:16 +0000368 void EmitDoStmt(const DoStmt &S);
369 void EmitForStmt(const ForStmt &S);
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000370 void EmitReturnStmt(const ReturnStmt &S);
Chris Lattner1ad38f82007-06-09 01:20:56 +0000371 void EmitDeclStmt(const DeclStmt &S);
Chris Lattnere73e4322007-07-16 21:28:45 +0000372 void EmitBreakStmt();
373 void EmitContinueStmt();
Devang Patelda5d6bb2007-10-04 23:45:31 +0000374 void EmitSwitchStmt(const SwitchStmt &S);
375 void EmitDefaultStmt(const DefaultStmt &S);
376 void EmitCaseStmt(const CaseStmt &S);
Devang Patel11663122007-10-08 20:57:48 +0000377 void EmitCaseStmtRange(const CaseStmt &S);
Anders Carlsson952a9952008-02-05 16:35:33 +0000378 void EmitAsmStmt(const AsmStmt &S);
379
Chris Lattner208ae962007-05-30 17:57:17 +0000380 //===--------------------------------------------------------------------===//
Chris Lattnerd7f58862007-06-02 05:24:33 +0000381 // LValue Expression Emission
382 //===--------------------------------------------------------------------===//
Chris Lattner8394d792007-06-05 20:53:16 +0000383
384 /// EmitLValue - Emit code to compute a designator that specifies the location
385 /// of the expression.
386 ///
387 /// This can return one of two things: a simple address or a bitfield
388 /// reference. In either case, the LLVM Value* in the LValue structure is
389 /// guaranteed to be an LLVM pointer type.
390 ///
391 /// If this returns a bitfield reference, nothing about the pointee type of
392 /// the LLVM value is known: For example, it may not be a pointer to an
393 /// integer.
394 ///
395 /// If this returns a normal address, and if the lvalue's C type is fixed
396 /// size, this method guarantees that the returned pointer type will point to
397 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
398 /// variable length type, this is not possible.
399 ///
Chris Lattnerd7f58862007-06-02 05:24:33 +0000400 LValue EmitLValue(const Expr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000401
402 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
403 /// this method emits the address of the lvalue, then loads the result as an
404 /// rvalue, returning the rvalue.
Chris Lattner9369a562007-06-29 16:31:29 +0000405 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Nate Begemance4d7fc2008-04-18 23:10:10 +0000406 RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000407 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
Chris Lattner9369a562007-06-29 16:31:29 +0000408
Chris Lattner40ff7012007-08-03 16:18:34 +0000409
Chris Lattner8394d792007-06-05 20:53:16 +0000410 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
411 /// lvalue, where both are guaranteed to the have the same type, and that type
412 /// is 'Ty'.
413 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Nate Begemance4d7fc2008-04-18 23:10:10 +0000414 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
415 QualType Ty);
Lauro Ramos Venancio09af71c2008-01-22 22:36:45 +0000416 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
Christopher Lambd91c3d42007-12-29 05:02:41 +0000417
418 // Note: only availabe for agg return types
419 LValue EmitCallExprLValue(const CallExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000420
Chris Lattnerd7f58862007-06-02 05:24:33 +0000421 LValue EmitDeclRefLValue(const DeclRefExpr *E);
Chris Lattner4347e3692007-06-06 04:54:52 +0000422 LValue EmitStringLiteralLValue(const StringLiteral *E);
Anders Carlsson625bfc82007-07-21 05:21:51 +0000423 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000424 LValue EmitUnaryOpLValue(const UnaryOperator *E);
Chris Lattnerd9d2fb12007-06-08 23:31:14 +0000425 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Nate Begemance4d7fc2008-04-18 23:10:10 +0000426 LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
Devang Patel3e11cce2007-10-23 02:10:49 +0000427 LValue EmitMemberExpr(const MemberExpr *E);
Eli Friedman9fd8b682008-05-13 23:18:27 +0000428 LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
Eli Friedmana62f3e12008-02-09 08:50:58 +0000429
430 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
Eli Friedman327944b2008-06-13 23:01:12 +0000431 bool isUnion, unsigned CVRQualifiers);
Chris Lattner4bd55962008-03-30 23:03:07 +0000432
433 LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
Chris Lattnerd7f58862007-06-02 05:24:33 +0000434 //===--------------------------------------------------------------------===//
Chris Lattner6278e6a2007-08-11 00:04:45 +0000435 // Scalar Expression Emission
Chris Lattner208ae962007-05-30 17:57:17 +0000436 //===--------------------------------------------------------------------===//
437
Chris Lattner2b228c92007-06-15 21:34:29 +0000438 RValue EmitCallExpr(const CallExpr *E);
Ted Kremenek08e17112008-06-17 02:43:46 +0000439
440 RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg,
441 CallExpr::const_arg_iterator ArgEnd);
442
Eli Friedman9d92ce82008-01-30 01:32:06 +0000443 RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
Ted Kremenek08e17112008-06-17 02:43:46 +0000444 CallExpr::const_arg_iterator ArgBeg,
445 CallExpr::const_arg_iterator ArgEnd);
446
Chris Lattner6c555f92007-08-26 22:58:05 +0000447 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000448
Anders Carlsson895af082007-12-09 23:17:02 +0000449 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
450 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
451
Anders Carlssonb9eb82c2007-12-10 19:35:18 +0000452 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
Nate Begeman330aaa72007-12-30 02:59:45 +0000453 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
454 bool isSplat = false);
Anders Carlssonf5f65442007-12-15 21:23:30 +0000455
Chris Lattner2da04b32007-08-24 05:35:26 +0000456 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Chris Lattnerb1d329d2008-06-24 17:04:18 +0000457 llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
458 llvm::Value *EmitObjCMessageExpr(const ObjCMessageExpr *E);
459
460
Anders Carlsson76f4a902007-08-21 17:43:55 +0000461
Chris Lattner6278e6a2007-08-11 00:04:45 +0000462 //===--------------------------------------------------------------------===//
Chris Lattnerbda69f82007-08-26 23:13:56 +0000463 // Expression Emission
Chris Lattner6278e6a2007-08-11 00:04:45 +0000464 //===--------------------------------------------------------------------===//
Chris Lattnerbda69f82007-08-26 23:13:56 +0000465
466 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattner6278e6a2007-08-11 00:04:45 +0000467
Chris Lattner2da04b32007-08-24 05:35:26 +0000468 /// EmitScalarExpr - Emit the computation of the specified expression of
469 /// LLVM scalar type, returning the result.
470 llvm::Value *EmitScalarExpr(const Expr *E);
471
Chris Lattner3474c202007-08-26 06:48:56 +0000472 /// EmitScalarConversion - Emit a conversion from the specified type to the
473 /// specified destination type, both of which are LLVM scalar types.
474 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
475 QualType DstTy);
476
Chris Lattner42e6b812007-08-26 16:34:22 +0000477 /// EmitComplexToScalarConversion - Emit a conversion from the specified
478 /// complex type to the specified destination type, where the destination
479 /// type is an LLVM scalar type.
480 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
481 QualType DstTy);
482
Chris Lattner3474c202007-08-26 06:48:56 +0000483
Chris Lattner6278e6a2007-08-11 00:04:45 +0000484 /// EmitAggExpr - Emit the computation of the specified expression of
485 /// aggregate type. The result is computed into DestPtr. Note that if
486 /// DestPtr is null, the value of the aggregate expression is not needed.
487 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattnercbfc73b2007-08-21 05:54:00 +0000488
489 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner08b15df2007-08-23 23:43:33 +0000490 /// complex type, returning the result.
Chris Lattner96d72562007-08-21 16:57:55 +0000491 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner08b15df2007-08-23 23:43:33 +0000492
493 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
494 /// of complex type, storing into the specified Value*.
Chris Lattnerb84bb952007-08-26 16:22:13 +0000495 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
496 bool DestIsVolatile);
Chris Lattner4647a212007-08-31 22:49:20 +0000497 /// LoadComplexFromAddr - Load a complex number from the specified address.
498 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Chris Lattnerb781dc792008-05-08 05:58:21 +0000499
500 /// GenerateStaticBlockVarDecl - return the the static
501 /// declaration of local variable.
502 llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D,
503 bool NoInit,
504 const char *Separator);
Chris Lattnerbed31442007-05-28 01:07:47 +0000505};
506} // end namespace CodeGen
507} // end namespace clang
Chris Lattnerbed31442007-05-28 01:07:47 +0000508
509#endif