blob: 6712d2f05f1780bb821fbfa1da7e6cade402838e [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-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 Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This is the internal per-function state used for llvm translation.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner2629b882008-02-29 17:10:38 +000014#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
15#define CLANG_CODEGEN_CODEGENFUNCTION_H
Chris Lattner4b009652007-07-25 00:24:17 +000016
Chris Lattnerb326b172008-03-30 23:03:07 +000017#include "clang/AST/Type.h"
Chris Lattner4b009652007-07-25 00:24:17 +000018#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/SmallVector.h"
Chris Lattner676bf212008-04-13 07:32:11 +000020#include "llvm/Support/IRBuilder.h"
Ted Kremenek2719e982008-06-17 02:43:46 +000021#include "clang/AST/Expr.h"
22#include "clang/AST/ExprObjC.h"
23
Chris Lattner4b009652007-07-25 00:24:17 +000024#include <vector>
25
26namespace llvm {
27 class Module;
28}
29
30namespace clang {
31 class ASTContext;
32 class Decl;
33 class FunctionDecl;
Chris Lattnerb326b172008-03-30 23:03:07 +000034 class ObjCMethodDecl;
Chris Lattner4b009652007-07-25 00:24:17 +000035 class TargetInfo;
Chris Lattner4b009652007-07-25 00:24:17 +000036 class FunctionTypeProto;
Devang Patelaebd83f2007-10-23 02:10:49 +000037
Chris Lattner4b009652007-07-25 00:24:17 +000038namespace CodeGen {
39 class CodeGenModule;
Devang Patelaebd83f2007-10-23 02:10:49 +000040 class CodeGenTypes;
Devang Patel7a78e432007-11-01 19:11:01 +000041 class CGRecordLayout;
Chris Lattner4b009652007-07-25 00:24:17 +000042
43/// RValue - This trivial value class is used to represent the result of an
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +000047class RValue {
Chris Lattnere24c4cf2007-08-31 22:49:20 +000048 llvm::Value *V1, *V2;
Chris Lattner4b009652007-07-25 00:24:17 +000049 // TODO: Encode this into the low bit of pointer for more efficient
50 // return-by-value.
Chris Lattnere24c4cf2007-08-31 22:49:20 +000051 enum { Scalar, Complex, Aggregate } Flavor;
Chris Lattner4b009652007-07-25 00:24:17 +000052
53 // FIXME: Aggregate rvalues need to retain information about whether they are
54 // volatile or not.
55public:
56
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +000060
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +000065 }
66
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +000073 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
74 llvm::Value *getAggregateAddr() const {
75 assert(isAggregate() && "Not an aggregate!");
Chris Lattnere24c4cf2007-08-31 22:49:20 +000076 return V1;
Chris Lattner4b009652007-07-25 00:24:17 +000077 }
78
79 static RValue get(llvm::Value *V) {
80 RValue ER;
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +000097 return ER;
98 }
99 static RValue getAggregate(llvm::Value *V) {
100 RValue ER;
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000101 ER.V1 = V;
102 ER.Flavor = Aggregate;
Chris Lattner4b009652007-07-25 00:24:17 +0000103 return ER;
104 }
105};
106
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 Friedman2e630542008-06-13 23:01:12 +0000112 // FIXME: alignment?
Chris Lattner4b009652007-07-25 00:24:17 +0000113
114 enum {
Chris Lattner65520192007-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 Begemanaf6ed502008-04-18 23:10:10 +0000118 ExtVectorElt // This is an extended vector subset, use getExtVectorComp
Chris Lattner4b009652007-07-25 00:24:17 +0000119 } LVType;
120
121 llvm::Value *V;
122
123 union {
Nate Begemanc8e51f82008-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
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000130 struct {
131 unsigned short StartBit;
132 unsigned short Size;
133 bool IsSigned;
134 } BitfieldData; // BitField start bit and size
Chris Lattner4b009652007-07-25 00:24:17 +0000135 };
Eli Friedman2e630542008-06-13 23:01:12 +0000136
137 bool Volatile:1;
138 // FIXME: set but never used, what effect should it have?
139 bool Restrict:1;
140
141private:
142 static void SetQualifiers(unsigned Qualifiers, LValue& R) {
143 R.Volatile = (Qualifiers&QualType::Volatile)!=0;
144 R.Restrict = (Qualifiers&QualType::Restrict)!=0;
145 }
146
Chris Lattner4b009652007-07-25 00:24:17 +0000147public:
148 bool isSimple() const { return LVType == Simple; }
149 bool isVectorElt() const { return LVType == VectorElt; }
150 bool isBitfield() const { return LVType == BitField; }
Nate Begemanaf6ed502008-04-18 23:10:10 +0000151 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Chris Lattner4b009652007-07-25 00:24:17 +0000152
Eli Friedman2e630542008-06-13 23:01:12 +0000153 bool isVolatileQualified() const { return Volatile; }
154 bool isRestrictQualified() const { return Restrict; }
155
Chris Lattner4b009652007-07-25 00:24:17 +0000156 // simple lvalue
157 llvm::Value *getAddress() const { assert(isSimple()); return V; }
158 // vector elt lvalue
159 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
160 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Nate Begemanaf6ed502008-04-18 23:10:10 +0000161 // extended vector elements.
162 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
Nate Begemanc8e51f82008-05-09 06:41:27 +0000163 llvm::Constant *getExtVectorElts() const {
Nate Begemanaf6ed502008-04-18 23:10:10 +0000164 assert(isExtVectorElt());
Chris Lattnera0d03a72007-08-03 17:31:20 +0000165 return VectorElts;
Chris Lattner65520192007-08-02 23:37:31 +0000166 }
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000167 // bitfield lvalue
168 llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; }
169 unsigned short getBitfieldStartBit() const {
170 assert(isBitfield());
171 return BitfieldData.StartBit;
172 }
173 unsigned short getBitfieldSize() const {
174 assert(isBitfield());
175 return BitfieldData.Size;
176 }
177 bool isBitfieldSigned() const {
178 assert(isBitfield());
179 return BitfieldData.IsSigned;
180 }
181
Eli Friedman2e630542008-06-13 23:01:12 +0000182 static LValue MakeAddr(llvm::Value *V, unsigned Qualifiers) {
Chris Lattner4b009652007-07-25 00:24:17 +0000183 LValue R;
184 R.LVType = Simple;
185 R.V = V;
Eli Friedman2e630542008-06-13 23:01:12 +0000186 SetQualifiers(Qualifiers,R);
Chris Lattner4b009652007-07-25 00:24:17 +0000187 return R;
188 }
189
Eli Friedman2e630542008-06-13 23:01:12 +0000190 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
191 unsigned Qualifiers) {
Chris Lattner4b009652007-07-25 00:24:17 +0000192 LValue R;
193 R.LVType = VectorElt;
194 R.V = Vec;
195 R.VectorIdx = Idx;
Eli Friedman2e630542008-06-13 23:01:12 +0000196 SetQualifiers(Qualifiers,R);
Chris Lattner4b009652007-07-25 00:24:17 +0000197 return R;
198 }
199
Eli Friedman2e630542008-06-13 23:01:12 +0000200 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
201 unsigned Qualifiers) {
Chris Lattner65520192007-08-02 23:37:31 +0000202 LValue R;
Nate Begemanaf6ed502008-04-18 23:10:10 +0000203 R.LVType = ExtVectorElt;
Chris Lattner65520192007-08-02 23:37:31 +0000204 R.V = Vec;
Nate Begemanc8e51f82008-05-09 06:41:27 +0000205 R.VectorElts = Elts;
Eli Friedman2e630542008-06-13 23:01:12 +0000206 SetQualifiers(Qualifiers,R);
Chris Lattner65520192007-08-02 23:37:31 +0000207 return R;
208 }
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000209
210 static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
Eli Friedman2e630542008-06-13 23:01:12 +0000211 unsigned short Size, bool IsSigned,
212 unsigned Qualifiers) {
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000213 LValue R;
214 R.LVType = BitField;
215 R.V = V;
216 R.BitfieldData.StartBit = StartBit;
217 R.BitfieldData.Size = Size;
218 R.BitfieldData.IsSigned = IsSigned;
Eli Friedman2e630542008-06-13 23:01:12 +0000219 SetQualifiers(Qualifiers,R);
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000220 return R;
221 }
Chris Lattner4b009652007-07-25 00:24:17 +0000222};
223
224/// CodeGenFunction - This class organizes the per-function state that is used
225/// while generating LLVM code.
226class CodeGenFunction {
Chris Lattner41b1fca2007-08-26 23:13:56 +0000227public:
Chris Lattner4b009652007-07-25 00:24:17 +0000228 CodeGenModule &CGM; // Per-module state.
229 TargetInfo &Target;
Chris Lattner41b1fca2007-08-26 23:13:56 +0000230
Chris Lattner5280c5f2007-08-21 16:57:55 +0000231 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Chris Lattner676bf212008-04-13 07:32:11 +0000232 llvm::IRBuilder Builder;
Chris Lattner4b009652007-07-25 00:24:17 +0000233
Chris Lattner6e6a5972008-04-04 04:07:35 +0000234 // Holds the Decl for the current function or method
Eli Friedmanbb0b9a52008-05-22 01:16:59 +0000235 const FunctionDecl *CurFuncDecl;
Chris Lattnerb326b172008-03-30 23:03:07 +0000236 QualType FnRetTy;
Chris Lattner4b009652007-07-25 00:24:17 +0000237 llvm::Function *CurFn;
238
239 /// AllocaInsertPoint - This is an instruction in the entry block before which
240 /// we prefer to insert allocas.
241 llvm::Instruction *AllocaInsertPt;
242
243 const llvm::Type *LLVMIntTy;
Hartmut Kaiserff08d2c2007-10-17 15:00:17 +0000244 uint32_t LLVMPointerWidth;
Chris Lattner4b009652007-07-25 00:24:17 +0000245
Chris Lattner9fba49a2007-08-24 05:35:26 +0000246private:
Chris Lattner4b009652007-07-25 00:24:17 +0000247 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
248 /// decls.
249 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
250
251 /// LabelMap - This keeps track of the LLVM basic block for each C label.
252 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
253
254 // BreakContinueStack - This keeps track of where break and continue
255 // statements should jump to.
256 struct BreakContinue {
257 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
258 : BreakBlock(bb), ContinueBlock(cb) {}
259
260 llvm::BasicBlock *BreakBlock;
261 llvm::BasicBlock *ContinueBlock;
262 };
263 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
264
Devang Patelbc372382007-10-09 17:08:50 +0000265 /// SwitchInsn - This is nearest current switch instruction. It is null if
266 /// if current context is not in a switch.
Devang Patele58e0802007-10-04 23:45:31 +0000267 llvm::SwitchInst *SwitchInsn;
268
Devang Patelbc372382007-10-09 17:08:50 +0000269 /// CaseRangeBlock - This block holds if condition check for last case
270 /// statement range in current switch instruction.
Devang Patel347ca322007-10-08 20:57:48 +0000271 llvm::BasicBlock *CaseRangeBlock;
272
Chris Lattner4b009652007-07-25 00:24:17 +0000273public:
274 CodeGenFunction(CodeGenModule &cgm);
275
276 ASTContext &getContext() const;
277
Chris Lattnerb326b172008-03-30 23:03:07 +0000278 void GenerateObjCMethod(const ObjCMethodDecl *OMD);
Chris Lattner4b009652007-07-25 00:24:17 +0000279 void GenerateCode(const FunctionDecl *FD);
280
281 const llvm::Type *ConvertType(QualType T);
Chris Lattner6e6a5972008-04-04 04:07:35 +0000282
283 llvm::Value *LoadObjCSelf();
Chris Lattner4b009652007-07-25 00:24:17 +0000284
285 /// hasAggregateLLVMType - Return true if the specified AST type will map into
286 /// an aggregate LLVM type or is void.
287 static bool hasAggregateLLVMType(QualType T);
288
289 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
290 /// label maps to.
291 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
292
293
294 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattner9d4e6202007-12-02 01:43:38 +0000295
296 /// WarnUnsupported - Print out a warning that codegen doesn't support the
297 /// specified stmt yet.
Chris Lattnere8f49632007-12-02 01:49:16 +0000298 void WarnUnsupported(const Stmt *S, const char *Type);
Chris Lattner4b009652007-07-25 00:24:17 +0000299
300 //===--------------------------------------------------------------------===//
301 // Helpers
302 //===--------------------------------------------------------------------===//
303
304 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
305 /// block.
306 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
307 const char *Name = "tmp");
308
309 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
310 /// expression and compare the result against zero, returning an Int1Ty value.
311 llvm::Value *EvaluateExprAsBool(const Expr *E);
312
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000313 /// EmitAnyExpr - Emit code to compute the specified expression which can have
314 /// any type. The result is returned as an RValue struct. If this is an
315 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
316 /// the result should be returned.
317 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
318 bool isAggLocVolatile = false);
Devang Patel97299362007-09-28 21:49:18 +0000319
320 /// isDummyBlock - Return true if BB is an empty basic block
321 /// with no predecessors.
322 static bool isDummyBlock(const llvm::BasicBlock *BB);
323
Devang Patele58e0802007-10-04 23:45:31 +0000324 /// StartBlock - Start new block named N. If insert block is a dummy block
325 /// then reuse it.
326 void StartBlock(const char *N);
327
Devang Patel7a78e432007-11-01 19:11:01 +0000328 /// getCGRecordLayout - Return record layout info.
329 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Lauro Ramos Venancio934fb022008-02-26 21:41:45 +0000330
331 /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000332 llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
Dan Gohman4751a3a2008-05-22 00:50:06 +0000333
334 /// getAccessedFieldNo - Given an encoded value and a result number, return
335 /// the input field number being accessed.
336 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
337
Chris Lattner4b009652007-07-25 00:24:17 +0000338 //===--------------------------------------------------------------------===//
Chris Lattner4b009652007-07-25 00:24:17 +0000339 // Declaration Emission
340 //===--------------------------------------------------------------------===//
341
342 void EmitDecl(const Decl &D);
343 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000344 void EmitBlockVarDecl(const VarDecl &D);
345 void EmitLocalBlockVarDecl(const VarDecl &D);
346 void EmitStaticBlockVarDecl(const VarDecl &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000347 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
348
349 //===--------------------------------------------------------------------===//
350 // Statement Emission
351 //===--------------------------------------------------------------------===//
352
353 void EmitStmt(const Stmt *S);
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000354 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
355 llvm::Value *AggLoc = 0, bool isAggVol = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000356 void EmitLabelStmt(const LabelStmt &S);
357 void EmitGotoStmt(const GotoStmt &S);
358 void EmitIfStmt(const IfStmt &S);
359 void EmitWhileStmt(const WhileStmt &S);
360 void EmitDoStmt(const DoStmt &S);
361 void EmitForStmt(const ForStmt &S);
362 void EmitReturnStmt(const ReturnStmt &S);
363 void EmitDeclStmt(const DeclStmt &S);
364 void EmitBreakStmt();
365 void EmitContinueStmt();
Devang Patele58e0802007-10-04 23:45:31 +0000366 void EmitSwitchStmt(const SwitchStmt &S);
367 void EmitDefaultStmt(const DefaultStmt &S);
368 void EmitCaseStmt(const CaseStmt &S);
Devang Patel347ca322007-10-08 20:57:48 +0000369 void EmitCaseStmtRange(const CaseStmt &S);
Anders Carlssonaf6a6c22008-02-05 16:35:33 +0000370 void EmitAsmStmt(const AsmStmt &S);
371
Chris Lattner4b009652007-07-25 00:24:17 +0000372 //===--------------------------------------------------------------------===//
373 // LValue Expression Emission
374 //===--------------------------------------------------------------------===//
375
376 /// EmitLValue - Emit code to compute a designator that specifies the location
377 /// of the expression.
378 ///
379 /// This can return one of two things: a simple address or a bitfield
380 /// reference. In either case, the LLVM Value* in the LValue structure is
381 /// guaranteed to be an LLVM pointer type.
382 ///
383 /// If this returns a bitfield reference, nothing about the pointee type of
384 /// the LLVM value is known: For example, it may not be a pointer to an
385 /// integer.
386 ///
387 /// If this returns a normal address, and if the lvalue's C type is fixed
388 /// size, this method guarantees that the returned pointer type will point to
389 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
390 /// variable length type, this is not possible.
391 ///
392 LValue EmitLValue(const Expr *E);
393
394 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
395 /// this method emits the address of the lvalue, then loads the result as an
396 /// rvalue, returning the rvalue.
Chris Lattner4b009652007-07-25 00:24:17 +0000397 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Nate Begemanaf6ed502008-04-18 23:10:10 +0000398 RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000399 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
Chris Lattner4b009652007-07-25 00:24:17 +0000400
Chris Lattner944f7962007-08-03 16:18:34 +0000401
Chris Lattner4b009652007-07-25 00:24:17 +0000402 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
403 /// lvalue, where both are guaranteed to the have the same type, and that type
404 /// is 'Ty'.
405 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Nate Begemanaf6ed502008-04-18 23:10:10 +0000406 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
407 QualType Ty);
Lauro Ramos Venancio2d7a34c2008-01-22 22:36:45 +0000408 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
Christopher Lambad327ba2007-12-29 05:02:41 +0000409
410 // Note: only availabe for agg return types
411 LValue EmitCallExprLValue(const CallExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000412
413 LValue EmitDeclRefLValue(const DeclRefExpr *E);
414 LValue EmitStringLiteralLValue(const StringLiteral *E);
415 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
416 LValue EmitUnaryOpLValue(const UnaryOperator *E);
417 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Nate Begemanaf6ed502008-04-18 23:10:10 +0000418 LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
Devang Patelaebd83f2007-10-23 02:10:49 +0000419 LValue EmitMemberExpr(const MemberExpr *E);
Eli Friedmanf3c2cb42008-05-13 23:18:27 +0000420 LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
Eli Friedmand3550112008-02-09 08:50:58 +0000421
422 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
Eli Friedman2e630542008-06-13 23:01:12 +0000423 bool isUnion, unsigned CVRQualifiers);
Chris Lattnerb326b172008-03-30 23:03:07 +0000424
425 LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000426 //===--------------------------------------------------------------------===//
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000427 // Scalar Expression Emission
Chris Lattner4b009652007-07-25 00:24:17 +0000428 //===--------------------------------------------------------------------===//
429
Chris Lattner4b009652007-07-25 00:24:17 +0000430 RValue EmitCallExpr(const CallExpr *E);
Ted Kremenek2719e982008-06-17 02:43:46 +0000431
432 RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg,
433 CallExpr::const_arg_iterator ArgEnd);
434
Eli Friedman261f4ad2008-01-30 01:32:06 +0000435 RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
Ted Kremenek2719e982008-06-17 02:43:46 +0000436 CallExpr::const_arg_iterator ArgBeg,
437 CallExpr::const_arg_iterator ArgEnd);
438
Chris Lattner35055b82007-08-26 22:58:05 +0000439 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000440
Anders Carlssone1449c12007-12-09 23:17:02 +0000441 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
442 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
443
Anders Carlssona9234fe2007-12-10 19:35:18 +0000444 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
Nate Begemanec2d1062007-12-30 02:59:45 +0000445 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
446 bool isSplat = false);
Anders Carlsson68b8be92007-12-15 21:23:30 +0000447
Chris Lattner9fba49a2007-08-24 05:35:26 +0000448 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Anders Carlssona66cad42007-08-21 17:43:55 +0000449
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000450 //===--------------------------------------------------------------------===//
Chris Lattner41b1fca2007-08-26 23:13:56 +0000451 // Expression Emission
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000452 //===--------------------------------------------------------------------===//
Chris Lattner41b1fca2007-08-26 23:13:56 +0000453
454 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000455
Chris Lattner9fba49a2007-08-24 05:35:26 +0000456 /// EmitScalarExpr - Emit the computation of the specified expression of
457 /// LLVM scalar type, returning the result.
458 llvm::Value *EmitScalarExpr(const Expr *E);
459
Chris Lattner4e05d1e2007-08-26 06:48:56 +0000460 /// EmitScalarConversion - Emit a conversion from the specified type to the
461 /// specified destination type, both of which are LLVM scalar types.
462 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
463 QualType DstTy);
464
Chris Lattnerfb182ee2007-08-26 16:34:22 +0000465 /// EmitComplexToScalarConversion - Emit a conversion from the specified
466 /// complex type to the specified destination type, where the destination
467 /// type is an LLVM scalar type.
468 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
469 QualType DstTy);
470
Chris Lattner4e05d1e2007-08-26 06:48:56 +0000471
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000472 /// EmitAggExpr - Emit the computation of the specified expression of
473 /// aggregate type. The result is computed into DestPtr. Note that if
474 /// DestPtr is null, the value of the aggregate expression is not needed.
475 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattner8d0cc2f2007-08-21 05:54:00 +0000476
477 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner348c8a22007-08-23 23:43:33 +0000478 /// complex type, returning the result.
Chris Lattner5280c5f2007-08-21 16:57:55 +0000479 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner348c8a22007-08-23 23:43:33 +0000480
481 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
482 /// of complex type, storing into the specified Value*.
Chris Lattner8e1f6e02007-08-26 16:22:13 +0000483 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
484 bool DestIsVolatile);
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000485 /// LoadComplexFromAddr - Load a complex number from the specified address.
486 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Chris Lattner85970f32008-05-08 05:58:21 +0000487
488 /// GenerateStaticBlockVarDecl - return the the static
489 /// declaration of local variable.
490 llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D,
491 bool NoInit,
492 const char *Separator);
Chris Lattner4b009652007-07-25 00:24:17 +0000493};
494} // end namespace CodeGen
495} // end namespace clang
496
497#endif