blob: f067a0e2250b67412e1ac7287ca4e1577683fe1d [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This is the internal per-function state used for llvm translation.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattneref52a2f2008-02-29 17:10:38 +000014#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
15#define CLANG_CODEGEN_CODEGENFUNCTION_H
Reid Spencer5f016e22007-07-11 17:01:13 +000016
Chris Lattner391d77a2008-03-30 23:03:07 +000017#include "clang/AST/Type.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000018#include "llvm/ADT/DenseMap.h"
Chris Lattnerda138702007-07-16 21:28:45 +000019#include "llvm/ADT/SmallVector.h"
Chris Lattner50b36742008-04-13 07:32:11 +000020#include "llvm/Support/IRBuilder.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000021#include <vector>
22
23namespace llvm {
24 class Module;
25}
26
27namespace clang {
28 class ASTContext;
29 class Decl;
30 class FunctionDecl;
Chris Lattner391d77a2008-03-30 23:03:07 +000031 class ObjCMethodDecl;
Reid Spencer5f016e22007-07-11 17:01:13 +000032 class TargetInfo;
Reid Spencer5f016e22007-07-11 17:01:13 +000033 class FunctionTypeProto;
34
35 class Stmt;
36 class CompoundStmt;
37 class LabelStmt;
38 class GotoStmt;
39 class IfStmt;
40 class WhileStmt;
41 class DoStmt;
42 class ForStmt;
43 class ReturnStmt;
44 class DeclStmt;
Devang Patel51b09f22007-10-04 23:45:31 +000045 class CaseStmt;
46 class DefaultStmt;
47 class SwitchStmt;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000048 class AsmStmt;
49
Reid Spencer5f016e22007-07-11 17:01:13 +000050 class Expr;
51 class DeclRefExpr;
52 class StringLiteral;
53 class IntegerLiteral;
54 class FloatingLiteral;
Chris Lattnerb0a721a2007-07-13 05:18:11 +000055 class CharacterLiteral;
Chris Lattner30bf3ae2007-08-03 17:51:03 +000056 class TypesCompatibleExpr;
57
Chris Lattner7016a702007-08-20 22:37:10 +000058 class ImplicitCastExpr;
Reid Spencer5f016e22007-07-11 17:01:13 +000059 class CastExpr;
60 class CallExpr;
61 class UnaryOperator;
62 class BinaryOperator;
63 class CompoundAssignOperator;
64 class ArraySubscriptExpr;
Nate Begeman213541a2008-04-18 23:10:10 +000065 class ExtVectorElementExpr;
Chris Lattnerb0a721a2007-07-13 05:18:11 +000066 class ConditionalOperator;
Chris Lattner94f05e32007-08-04 00:20:15 +000067 class ChooseExpr;
Anders Carlsson22742662007-07-21 05:21:51 +000068 class PreDefinedExpr;
Anders Carlsson55085182007-08-21 17:43:55 +000069 class ObjCStringLiteral;
Chris Lattner391d77a2008-03-30 23:03:07 +000070 class ObjCIvarRefExpr;
Devang Patelb84a06e2007-10-23 02:10:49 +000071 class MemberExpr;
72
Steve Naroff248a7532008-04-15 22:42:06 +000073 class VarDecl;
Reid Spencer5f016e22007-07-11 17:01:13 +000074 class EnumConstantDecl;
75 class ParmVarDecl;
Eli Friedman472778e2008-02-09 08:50:58 +000076 class FieldDecl;
Reid Spencer5f016e22007-07-11 17:01:13 +000077namespace CodeGen {
78 class CodeGenModule;
Devang Patelb84a06e2007-10-23 02:10:49 +000079 class CodeGenTypes;
Devang Patel88a981b2007-11-01 19:11:01 +000080 class CGRecordLayout;
Reid Spencer5f016e22007-07-11 17:01:13 +000081
82/// RValue - This trivial value class is used to represent the result of an
Chris Lattner9b655512007-08-31 22:49:20 +000083/// expression that is evaluated. It can be one of three things: either a
84/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
85/// address of an aggregate value in memory.
Reid Spencer5f016e22007-07-11 17:01:13 +000086class RValue {
Chris Lattner9b655512007-08-31 22:49:20 +000087 llvm::Value *V1, *V2;
Reid Spencer5f016e22007-07-11 17:01:13 +000088 // TODO: Encode this into the low bit of pointer for more efficient
89 // return-by-value.
Chris Lattner9b655512007-08-31 22:49:20 +000090 enum { Scalar, Complex, Aggregate } Flavor;
Reid Spencer5f016e22007-07-11 17:01:13 +000091
92 // FIXME: Aggregate rvalues need to retain information about whether they are
93 // volatile or not.
94public:
95
Chris Lattner9b655512007-08-31 22:49:20 +000096 bool isScalar() const { return Flavor == Scalar; }
97 bool isComplex() const { return Flavor == Complex; }
98 bool isAggregate() const { return Flavor == Aggregate; }
Reid Spencer5f016e22007-07-11 17:01:13 +000099
Chris Lattner9b655512007-08-31 22:49:20 +0000100 /// getScalar() - Return the Value* of this scalar value.
101 llvm::Value *getScalarVal() const {
102 assert(isScalar() && "Not a scalar!");
103 return V1;
Reid Spencer5f016e22007-07-11 17:01:13 +0000104 }
105
Chris Lattner9b655512007-08-31 22:49:20 +0000106 /// getComplexVal - Return the real/imag components of this complex value.
107 ///
108 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
109 return std::pair<llvm::Value *, llvm::Value *>(V1, V2);
110 }
111
Reid Spencer5f016e22007-07-11 17:01:13 +0000112 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
113 llvm::Value *getAggregateAddr() const {
114 assert(isAggregate() && "Not an aggregate!");
Chris Lattner9b655512007-08-31 22:49:20 +0000115 return V1;
Reid Spencer5f016e22007-07-11 17:01:13 +0000116 }
117
118 static RValue get(llvm::Value *V) {
119 RValue ER;
Chris Lattner9b655512007-08-31 22:49:20 +0000120 ER.V1 = V;
121 ER.Flavor = Scalar;
122 return ER;
123 }
124 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
125 RValue ER;
126 ER.V1 = V1;
127 ER.V2 = V2;
128 ER.Flavor = Complex;
129 return ER;
130 }
131 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
132 RValue ER;
133 ER.V1 = C.first;
134 ER.V2 = C.second;
135 ER.Flavor = Complex;
Reid Spencer5f016e22007-07-11 17:01:13 +0000136 return ER;
137 }
138 static RValue getAggregate(llvm::Value *V) {
139 RValue ER;
Chris Lattner9b655512007-08-31 22:49:20 +0000140 ER.V1 = V;
141 ER.Flavor = Aggregate;
Reid Spencer5f016e22007-07-11 17:01:13 +0000142 return ER;
143 }
144};
145
146
147/// LValue - This represents an lvalue references. Because C/C++ allow
148/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
149/// bitrange.
150class LValue {
151 // FIXME: Volatility. Restrict?
152 // alignment?
153
154 enum {
Chris Lattner349aaec2007-08-02 23:37:31 +0000155 Simple, // This is a normal l-value, use getAddress().
156 VectorElt, // This is a vector element l-value (V[i]), use getVector*
157 BitField, // This is a bitfield l-value, use getBitfield*.
Nate Begeman213541a2008-04-18 23:10:10 +0000158 ExtVectorElt // This is an extended vector subset, use getExtVectorComp
Reid Spencer5f016e22007-07-11 17:01:13 +0000159 } LVType;
160
161 llvm::Value *V;
162
163 union {
Nate Begeman8a997642008-05-09 06:41:27 +0000164 // Index into a vector subscript: V[i]
165 llvm::Value *VectorIdx;
166
167 // ExtVector element subset: V.xyx
168 llvm::Constant *VectorElts;
169
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000170 struct {
171 unsigned short StartBit;
172 unsigned short Size;
173 bool IsSigned;
174 } BitfieldData; // BitField start bit and size
Reid Spencer5f016e22007-07-11 17:01:13 +0000175 };
176public:
177 bool isSimple() const { return LVType == Simple; }
178 bool isVectorElt() const { return LVType == VectorElt; }
179 bool isBitfield() const { return LVType == BitField; }
Nate Begeman213541a2008-04-18 23:10:10 +0000180 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Reid Spencer5f016e22007-07-11 17:01:13 +0000181
182 // simple lvalue
183 llvm::Value *getAddress() const { assert(isSimple()); return V; }
184 // vector elt lvalue
185 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
186 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Nate Begeman213541a2008-04-18 23:10:10 +0000187 // extended vector elements.
188 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
Nate Begeman8a997642008-05-09 06:41:27 +0000189 llvm::Constant *getExtVectorElts() const {
Nate Begeman213541a2008-04-18 23:10:10 +0000190 assert(isExtVectorElt());
Chris Lattner6481a572007-08-03 17:31:20 +0000191 return VectorElts;
Chris Lattner349aaec2007-08-02 23:37:31 +0000192 }
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000193 // bitfield lvalue
194 llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; }
195 unsigned short getBitfieldStartBit() const {
196 assert(isBitfield());
197 return BitfieldData.StartBit;
198 }
199 unsigned short getBitfieldSize() const {
200 assert(isBitfield());
201 return BitfieldData.Size;
202 }
203 bool isBitfieldSigned() const {
204 assert(isBitfield());
205 return BitfieldData.IsSigned;
206 }
207
Reid Spencer5f016e22007-07-11 17:01:13 +0000208 static LValue MakeAddr(llvm::Value *V) {
209 LValue R;
210 R.LVType = Simple;
211 R.V = V;
212 return R;
213 }
214
215 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx) {
216 LValue R;
217 R.LVType = VectorElt;
218 R.V = Vec;
219 R.VectorIdx = Idx;
220 return R;
221 }
222
Nate Begeman8a997642008-05-09 06:41:27 +0000223 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts) {
Chris Lattner349aaec2007-08-02 23:37:31 +0000224 LValue R;
Nate Begeman213541a2008-04-18 23:10:10 +0000225 R.LVType = ExtVectorElt;
Chris Lattner349aaec2007-08-02 23:37:31 +0000226 R.V = Vec;
Nate Begeman8a997642008-05-09 06:41:27 +0000227 R.VectorElts = Elts;
Chris Lattner349aaec2007-08-02 23:37:31 +0000228 return R;
229 }
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000230
231 static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
232 unsigned short Size, bool IsSigned) {
233 LValue R;
234 R.LVType = BitField;
235 R.V = V;
236 R.BitfieldData.StartBit = StartBit;
237 R.BitfieldData.Size = Size;
238 R.BitfieldData.IsSigned = IsSigned;
239 return R;
240 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000241};
242
243/// CodeGenFunction - This class organizes the per-function state that is used
244/// while generating LLVM code.
245class CodeGenFunction {
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000246public:
Reid Spencer5f016e22007-07-11 17:01:13 +0000247 CodeGenModule &CGM; // Per-module state.
248 TargetInfo &Target;
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000249
Chris Lattner58dee102007-08-21 16:57:55 +0000250 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Chris Lattner50b36742008-04-13 07:32:11 +0000251 llvm::IRBuilder Builder;
Reid Spencer5f016e22007-07-11 17:01:13 +0000252
Chris Lattnerc8aa5f12008-04-04 04:07:35 +0000253 // Holds the Decl for the current function or method
254 const Decl *CurFuncDecl;
Chris Lattner391d77a2008-03-30 23:03:07 +0000255 QualType FnRetTy;
Reid Spencer5f016e22007-07-11 17:01:13 +0000256 llvm::Function *CurFn;
257
258 /// AllocaInsertPoint - This is an instruction in the entry block before which
259 /// we prefer to insert allocas.
260 llvm::Instruction *AllocaInsertPt;
261
262 const llvm::Type *LLVMIntTy;
Hartmut Kaiser7b660002007-10-17 15:00:17 +0000263 uint32_t LLVMPointerWidth;
Reid Spencer5f016e22007-07-11 17:01:13 +0000264
Chris Lattner7f02f722007-08-24 05:35:26 +0000265private:
Reid Spencer5f016e22007-07-11 17:01:13 +0000266 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
267 /// decls.
268 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
269
270 /// LabelMap - This keeps track of the LLVM basic block for each C label.
271 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnerda138702007-07-16 21:28:45 +0000272
273 // BreakContinueStack - This keeps track of where break and continue
274 // statements should jump to.
275 struct BreakContinue {
276 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
277 : BreakBlock(bb), ContinueBlock(cb) {}
278
279 llvm::BasicBlock *BreakBlock;
280 llvm::BasicBlock *ContinueBlock;
281 };
282 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
283
Devang Patel80fd5f92007-10-09 17:08:50 +0000284 /// SwitchInsn - This is nearest current switch instruction. It is null if
285 /// if current context is not in a switch.
Devang Patel51b09f22007-10-04 23:45:31 +0000286 llvm::SwitchInst *SwitchInsn;
287
Devang Patel80fd5f92007-10-09 17:08:50 +0000288 /// CaseRangeBlock - This block holds if condition check for last case
289 /// statement range in current switch instruction.
Devang Patelc049e4f2007-10-08 20:57:48 +0000290 llvm::BasicBlock *CaseRangeBlock;
291
Reid Spencer5f016e22007-07-11 17:01:13 +0000292public:
293 CodeGenFunction(CodeGenModule &cgm);
294
295 ASTContext &getContext() const;
296
Chris Lattner391d77a2008-03-30 23:03:07 +0000297 void GenerateObjCMethod(const ObjCMethodDecl *OMD);
Reid Spencer5f016e22007-07-11 17:01:13 +0000298 void GenerateCode(const FunctionDecl *FD);
299
300 const llvm::Type *ConvertType(QualType T);
Chris Lattnerc8aa5f12008-04-04 04:07:35 +0000301
302 llvm::Value *LoadObjCSelf();
Reid Spencer5f016e22007-07-11 17:01:13 +0000303
304 /// hasAggregateLLVMType - Return true if the specified AST type will map into
305 /// an aggregate LLVM type or is void.
306 static bool hasAggregateLLVMType(QualType T);
307
308 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
309 /// label maps to.
310 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
311
312
313 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattnerdc5e8262007-12-02 01:43:38 +0000314
315 /// WarnUnsupported - Print out a warning that codegen doesn't support the
316 /// specified stmt yet.
Chris Lattnerdc4d2802007-12-02 01:49:16 +0000317 void WarnUnsupported(const Stmt *S, const char *Type);
Reid Spencer5f016e22007-07-11 17:01:13 +0000318
319 //===--------------------------------------------------------------------===//
320 // Helpers
321 //===--------------------------------------------------------------------===//
322
323 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
324 /// block.
325 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
326 const char *Name = "tmp");
327
328 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
329 /// expression and compare the result against zero, returning an Int1Ty value.
330 llvm::Value *EvaluateExprAsBool(const Expr *E);
331
Chris Lattner9b655512007-08-31 22:49:20 +0000332 /// EmitAnyExpr - Emit code to compute the specified expression which can have
333 /// any type. The result is returned as an RValue struct. If this is an
334 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
335 /// the result should be returned.
336 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
337 bool isAggLocVolatile = false);
Devang Pateld9363c32007-09-28 21:49:18 +0000338
339 /// isDummyBlock - Return true if BB is an empty basic block
340 /// with no predecessors.
341 static bool isDummyBlock(const llvm::BasicBlock *BB);
342
Devang Patel51b09f22007-10-04 23:45:31 +0000343 /// StartBlock - Start new block named N. If insert block is a dummy block
344 /// then reuse it.
345 void StartBlock(const char *N);
346
Devang Patel88a981b2007-11-01 19:11:01 +0000347 /// getCGRecordLayout - Return record layout info.
348 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Lauro Ramos Venancio81373352008-02-26 21:41:45 +0000349
350 /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
Steve Naroff248a7532008-04-15 22:42:06 +0000351 llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
Reid Spencer5f016e22007-07-11 17:01:13 +0000352 //===--------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +0000353 // Declaration Emission
354 //===--------------------------------------------------------------------===//
355
356 void EmitDecl(const Decl &D);
357 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Steve Naroff248a7532008-04-15 22:42:06 +0000358 void EmitBlockVarDecl(const VarDecl &D);
359 void EmitLocalBlockVarDecl(const VarDecl &D);
360 void EmitStaticBlockVarDecl(const VarDecl &D);
Reid Spencer5f016e22007-07-11 17:01:13 +0000361 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
362
363 //===--------------------------------------------------------------------===//
364 // Statement Emission
365 //===--------------------------------------------------------------------===//
366
367 void EmitStmt(const Stmt *S);
Chris Lattner9b655512007-08-31 22:49:20 +0000368 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
369 llvm::Value *AggLoc = 0, bool isAggVol = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000370 void EmitLabelStmt(const LabelStmt &S);
371 void EmitGotoStmt(const GotoStmt &S);
372 void EmitIfStmt(const IfStmt &S);
373 void EmitWhileStmt(const WhileStmt &S);
374 void EmitDoStmt(const DoStmt &S);
375 void EmitForStmt(const ForStmt &S);
376 void EmitReturnStmt(const ReturnStmt &S);
377 void EmitDeclStmt(const DeclStmt &S);
Chris Lattnerda138702007-07-16 21:28:45 +0000378 void EmitBreakStmt();
379 void EmitContinueStmt();
Devang Patel51b09f22007-10-04 23:45:31 +0000380 void EmitSwitchStmt(const SwitchStmt &S);
381 void EmitDefaultStmt(const DefaultStmt &S);
382 void EmitCaseStmt(const CaseStmt &S);
Devang Patelc049e4f2007-10-08 20:57:48 +0000383 void EmitCaseStmtRange(const CaseStmt &S);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000384 void EmitAsmStmt(const AsmStmt &S);
385
Reid Spencer5f016e22007-07-11 17:01:13 +0000386 //===--------------------------------------------------------------------===//
387 // LValue Expression Emission
388 //===--------------------------------------------------------------------===//
389
390 /// EmitLValue - Emit code to compute a designator that specifies the location
391 /// of the expression.
392 ///
393 /// This can return one of two things: a simple address or a bitfield
394 /// reference. In either case, the LLVM Value* in the LValue structure is
395 /// guaranteed to be an LLVM pointer type.
396 ///
397 /// If this returns a bitfield reference, nothing about the pointee type of
398 /// the LLVM value is known: For example, it may not be a pointer to an
399 /// integer.
400 ///
401 /// If this returns a normal address, and if the lvalue's C type is fixed
402 /// size, this method guarantees that the returned pointer type will point to
403 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
404 /// variable length type, this is not possible.
405 ///
406 LValue EmitLValue(const Expr *E);
407
408 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
409 /// this method emits the address of the lvalue, then loads the result as an
410 /// rvalue, returning the rvalue.
Reid Spencer5f016e22007-07-11 17:01:13 +0000411 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Nate Begeman213541a2008-04-18 23:10:10 +0000412 RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000413 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000414
Chris Lattner34cdc862007-08-03 16:18:34 +0000415
Reid Spencer5f016e22007-07-11 17:01:13 +0000416 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
417 /// lvalue, where both are guaranteed to the have the same type, and that type
418 /// is 'Ty'.
419 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Nate Begeman213541a2008-04-18 23:10:10 +0000420 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
421 QualType Ty);
Lauro Ramos Venancioa0c5d0e2008-01-22 22:36:45 +0000422 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
Christopher Lamb22c940e2007-12-29 05:02:41 +0000423
424 // Note: only availabe for agg return types
425 LValue EmitCallExprLValue(const CallExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000426
427 LValue EmitDeclRefLValue(const DeclRefExpr *E);
428 LValue EmitStringLiteralLValue(const StringLiteral *E);
Anders Carlsson22742662007-07-21 05:21:51 +0000429 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000430 LValue EmitUnaryOpLValue(const UnaryOperator *E);
431 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Nate Begeman213541a2008-04-18 23:10:10 +0000432 LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
Devang Patelb84a06e2007-10-23 02:10:49 +0000433 LValue EmitMemberExpr(const MemberExpr *E);
Eli Friedman472778e2008-02-09 08:50:58 +0000434
435 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
436 bool isUnion);
Chris Lattner391d77a2008-03-30 23:03:07 +0000437
438 LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000439 //===--------------------------------------------------------------------===//
Chris Lattner883f6a72007-08-11 00:04:45 +0000440 // Scalar Expression Emission
Reid Spencer5f016e22007-07-11 17:01:13 +0000441 //===--------------------------------------------------------------------===//
442
Reid Spencer5f016e22007-07-11 17:01:13 +0000443 RValue EmitCallExpr(const CallExpr *E);
Eli Friedman5193b8a2008-01-30 01:32:06 +0000444 RValue EmitCallExpr(Expr *FnExpr, Expr *const *Args, unsigned NumArgs);
445 RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
446 Expr *const *Args, unsigned NumArgs);
Chris Lattner1e4d21e2007-08-26 22:58:05 +0000447 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000448
Anders Carlsson564f1de2007-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 Carlssoncc23aca2007-12-10 19:35:18 +0000452 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
Nate Begeman4119d1a2007-12-30 02:59:45 +0000453 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
454 bool isSplat = false);
Anders Carlsson6086bbd2007-12-15 21:23:30 +0000455
Chris Lattner7f02f722007-08-24 05:35:26 +0000456 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Anders Carlsson55085182007-08-21 17:43:55 +0000457
Chris Lattner883f6a72007-08-11 00:04:45 +0000458 //===--------------------------------------------------------------------===//
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000459 // Expression Emission
Chris Lattner883f6a72007-08-11 00:04:45 +0000460 //===--------------------------------------------------------------------===//
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000461
462 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattner883f6a72007-08-11 00:04:45 +0000463
Chris Lattner7f02f722007-08-24 05:35:26 +0000464 /// EmitScalarExpr - Emit the computation of the specified expression of
465 /// LLVM scalar type, returning the result.
466 llvm::Value *EmitScalarExpr(const Expr *E);
467
Chris Lattner3707b252007-08-26 06:48:56 +0000468 /// EmitScalarConversion - Emit a conversion from the specified type to the
469 /// specified destination type, both of which are LLVM scalar types.
470 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
471 QualType DstTy);
472
Chris Lattner4f1a7b32007-08-26 16:34:22 +0000473 /// EmitComplexToScalarConversion - Emit a conversion from the specified
474 /// complex type to the specified destination type, where the destination
475 /// type is an LLVM scalar type.
476 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
477 QualType DstTy);
478
Chris Lattner3707b252007-08-26 06:48:56 +0000479
Chris Lattner883f6a72007-08-11 00:04:45 +0000480 /// EmitAggExpr - Emit the computation of the specified expression of
481 /// aggregate type. The result is computed into DestPtr. Note that if
482 /// DestPtr is null, the value of the aggregate expression is not needed.
483 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattnerb6ef18a2007-08-21 05:54:00 +0000484
485 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner23b1cdb2007-08-23 23:43:33 +0000486 /// complex type, returning the result.
Chris Lattner58dee102007-08-21 16:57:55 +0000487 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner23b1cdb2007-08-23 23:43:33 +0000488
489 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
490 /// of complex type, storing into the specified Value*.
Chris Lattner190dbe22007-08-26 16:22:13 +0000491 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
492 bool DestIsVolatile);
Chris Lattner9b655512007-08-31 22:49:20 +0000493 /// LoadComplexFromAddr - Load a complex number from the specified address.
494 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Chris Lattner2621fd12008-05-08 05:58:21 +0000495
496 /// GenerateStaticBlockVarDecl - return the the static
497 /// declaration of local variable.
498 llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D,
499 bool NoInit,
500 const char *Separator);
Reid Spencer5f016e22007-07-11 17:01:13 +0000501};
502} // end namespace CodeGen
503} // end namespace clang
504
505#endif