blob: 077a7bdbdc1621eee58655fccba61852d33a56db [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"
Chris Lattner4b009652007-07-25 00:24:17 +000021#include <vector>
22
23namespace llvm {
24 class Module;
25}
26
27namespace clang {
28 class ASTContext;
29 class Decl;
30 class FunctionDecl;
Chris Lattnerb326b172008-03-30 23:03:07 +000031 class ObjCMethodDecl;
Chris Lattner4b009652007-07-25 00:24:17 +000032 class TargetInfo;
Chris Lattner4b009652007-07-25 00:24:17 +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 Patele58e0802007-10-04 23:45:31 +000045 class CaseStmt;
46 class DefaultStmt;
47 class SwitchStmt;
Anders Carlssonaf6a6c22008-02-05 16:35:33 +000048 class AsmStmt;
49
Chris Lattner4b009652007-07-25 00:24:17 +000050 class Expr;
51 class DeclRefExpr;
52 class StringLiteral;
53 class IntegerLiteral;
54 class FloatingLiteral;
55 class CharacterLiteral;
Chris Lattner4ca7e752007-08-03 17:51:03 +000056 class TypesCompatibleExpr;
57
Chris Lattnerb2cb9cb2007-08-20 22:37:10 +000058 class ImplicitCastExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000059 class CastExpr;
60 class CallExpr;
61 class UnaryOperator;
62 class BinaryOperator;
63 class CompoundAssignOperator;
64 class ArraySubscriptExpr;
Nate Begemanaf6ed502008-04-18 23:10:10 +000065 class ExtVectorElementExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000066 class ConditionalOperator;
Chris Lattner44fcf4f2007-08-04 00:20:15 +000067 class ChooseExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000068 class PreDefinedExpr;
Anders Carlssona66cad42007-08-21 17:43:55 +000069 class ObjCStringLiteral;
Chris Lattnerb326b172008-03-30 23:03:07 +000070 class ObjCIvarRefExpr;
Devang Patelaebd83f2007-10-23 02:10:49 +000071 class MemberExpr;
Eli Friedmanf3c2cb42008-05-13 23:18:27 +000072 class CompoundLiteralExpr;
Devang Patelaebd83f2007-10-23 02:10:49 +000073
Steve Naroff72a6ebc2008-04-15 22:42:06 +000074 class VarDecl;
Chris Lattner4b009652007-07-25 00:24:17 +000075 class EnumConstantDecl;
76 class ParmVarDecl;
Eli Friedmand3550112008-02-09 08:50:58 +000077 class FieldDecl;
Chris Lattner4b009652007-07-25 00:24:17 +000078namespace CodeGen {
79 class CodeGenModule;
Devang Patelaebd83f2007-10-23 02:10:49 +000080 class CodeGenTypes;
Devang Patel7a78e432007-11-01 19:11:01 +000081 class CGRecordLayout;
Chris Lattner4b009652007-07-25 00:24:17 +000082
83/// RValue - This trivial value class is used to represent the result of an
Chris Lattnere24c4cf2007-08-31 22:49:20 +000084/// expression that is evaluated. It can be one of three things: either a
85/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
86/// address of an aggregate value in memory.
Chris Lattner4b009652007-07-25 00:24:17 +000087class RValue {
Chris Lattnere24c4cf2007-08-31 22:49:20 +000088 llvm::Value *V1, *V2;
Chris Lattner4b009652007-07-25 00:24:17 +000089 // TODO: Encode this into the low bit of pointer for more efficient
90 // return-by-value.
Chris Lattnere24c4cf2007-08-31 22:49:20 +000091 enum { Scalar, Complex, Aggregate } Flavor;
Chris Lattner4b009652007-07-25 00:24:17 +000092
93 // FIXME: Aggregate rvalues need to retain information about whether they are
94 // volatile or not.
95public:
96
Chris Lattnere24c4cf2007-08-31 22:49:20 +000097 bool isScalar() const { return Flavor == Scalar; }
98 bool isComplex() const { return Flavor == Complex; }
99 bool isAggregate() const { return Flavor == Aggregate; }
Chris Lattner4b009652007-07-25 00:24:17 +0000100
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000101 /// getScalar() - Return the Value* of this scalar value.
102 llvm::Value *getScalarVal() const {
103 assert(isScalar() && "Not a scalar!");
104 return V1;
Chris Lattner4b009652007-07-25 00:24:17 +0000105 }
106
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000107 /// getComplexVal - Return the real/imag components of this complex value.
108 ///
109 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
110 return std::pair<llvm::Value *, llvm::Value *>(V1, V2);
111 }
112
Chris Lattner4b009652007-07-25 00:24:17 +0000113 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
114 llvm::Value *getAggregateAddr() const {
115 assert(isAggregate() && "Not an aggregate!");
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000116 return V1;
Chris Lattner4b009652007-07-25 00:24:17 +0000117 }
118
119 static RValue get(llvm::Value *V) {
120 RValue ER;
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000121 ER.V1 = V;
122 ER.Flavor = Scalar;
123 return ER;
124 }
125 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
126 RValue ER;
127 ER.V1 = V1;
128 ER.V2 = V2;
129 ER.Flavor = Complex;
130 return ER;
131 }
132 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
133 RValue ER;
134 ER.V1 = C.first;
135 ER.V2 = C.second;
136 ER.Flavor = Complex;
Chris Lattner4b009652007-07-25 00:24:17 +0000137 return ER;
138 }
139 static RValue getAggregate(llvm::Value *V) {
140 RValue ER;
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000141 ER.V1 = V;
142 ER.Flavor = Aggregate;
Chris Lattner4b009652007-07-25 00:24:17 +0000143 return ER;
144 }
145};
146
147
148/// LValue - This represents an lvalue references. Because C/C++ allow
149/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
150/// bitrange.
151class LValue {
152 // FIXME: Volatility. Restrict?
153 // alignment?
154
155 enum {
Chris Lattner65520192007-08-02 23:37:31 +0000156 Simple, // This is a normal l-value, use getAddress().
157 VectorElt, // This is a vector element l-value (V[i]), use getVector*
158 BitField, // This is a bitfield l-value, use getBitfield*.
Nate Begemanaf6ed502008-04-18 23:10:10 +0000159 ExtVectorElt // This is an extended vector subset, use getExtVectorComp
Chris Lattner4b009652007-07-25 00:24:17 +0000160 } LVType;
161
162 llvm::Value *V;
163
164 union {
Nate Begemanc8e51f82008-05-09 06:41:27 +0000165 // Index into a vector subscript: V[i]
166 llvm::Value *VectorIdx;
167
168 // ExtVector element subset: V.xyx
169 llvm::Constant *VectorElts;
170
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000171 struct {
172 unsigned short StartBit;
173 unsigned short Size;
174 bool IsSigned;
175 } BitfieldData; // BitField start bit and size
Chris Lattner4b009652007-07-25 00:24:17 +0000176 };
177public:
178 bool isSimple() const { return LVType == Simple; }
179 bool isVectorElt() const { return LVType == VectorElt; }
180 bool isBitfield() const { return LVType == BitField; }
Nate Begemanaf6ed502008-04-18 23:10:10 +0000181 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Chris Lattner4b009652007-07-25 00:24:17 +0000182
183 // simple lvalue
184 llvm::Value *getAddress() const { assert(isSimple()); return V; }
185 // vector elt lvalue
186 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
187 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Nate Begemanaf6ed502008-04-18 23:10:10 +0000188 // extended vector elements.
189 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
Nate Begemanc8e51f82008-05-09 06:41:27 +0000190 llvm::Constant *getExtVectorElts() const {
Nate Begemanaf6ed502008-04-18 23:10:10 +0000191 assert(isExtVectorElt());
Chris Lattnera0d03a72007-08-03 17:31:20 +0000192 return VectorElts;
Chris Lattner65520192007-08-02 23:37:31 +0000193 }
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000194 // bitfield lvalue
195 llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; }
196 unsigned short getBitfieldStartBit() const {
197 assert(isBitfield());
198 return BitfieldData.StartBit;
199 }
200 unsigned short getBitfieldSize() const {
201 assert(isBitfield());
202 return BitfieldData.Size;
203 }
204 bool isBitfieldSigned() const {
205 assert(isBitfield());
206 return BitfieldData.IsSigned;
207 }
208
Chris Lattner4b009652007-07-25 00:24:17 +0000209 static LValue MakeAddr(llvm::Value *V) {
210 LValue R;
211 R.LVType = Simple;
212 R.V = V;
213 return R;
214 }
215
216 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx) {
217 LValue R;
218 R.LVType = VectorElt;
219 R.V = Vec;
220 R.VectorIdx = Idx;
221 return R;
222 }
223
Nate Begemanc8e51f82008-05-09 06:41:27 +0000224 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts) {
Chris Lattner65520192007-08-02 23:37:31 +0000225 LValue R;
Nate Begemanaf6ed502008-04-18 23:10:10 +0000226 R.LVType = ExtVectorElt;
Chris Lattner65520192007-08-02 23:37:31 +0000227 R.V = Vec;
Nate Begemanc8e51f82008-05-09 06:41:27 +0000228 R.VectorElts = Elts;
Chris Lattner65520192007-08-02 23:37:31 +0000229 return R;
230 }
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000231
232 static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
233 unsigned short Size, bool IsSigned) {
234 LValue R;
235 R.LVType = BitField;
236 R.V = V;
237 R.BitfieldData.StartBit = StartBit;
238 R.BitfieldData.Size = Size;
239 R.BitfieldData.IsSigned = IsSigned;
240 return R;
241 }
Chris Lattner4b009652007-07-25 00:24:17 +0000242};
243
244/// CodeGenFunction - This class organizes the per-function state that is used
245/// while generating LLVM code.
246class CodeGenFunction {
Chris Lattner41b1fca2007-08-26 23:13:56 +0000247public:
Chris Lattner4b009652007-07-25 00:24:17 +0000248 CodeGenModule &CGM; // Per-module state.
249 TargetInfo &Target;
Chris Lattner41b1fca2007-08-26 23:13:56 +0000250
Chris Lattner5280c5f2007-08-21 16:57:55 +0000251 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Chris Lattner676bf212008-04-13 07:32:11 +0000252 llvm::IRBuilder Builder;
Chris Lattner4b009652007-07-25 00:24:17 +0000253
Chris Lattner6e6a5972008-04-04 04:07:35 +0000254 // Holds the Decl for the current function or method
Eli Friedmanbb0b9a52008-05-22 01:16:59 +0000255 const FunctionDecl *CurFuncDecl;
Chris Lattnerb326b172008-03-30 23:03:07 +0000256 QualType FnRetTy;
Chris Lattner4b009652007-07-25 00:24:17 +0000257 llvm::Function *CurFn;
258
259 /// AllocaInsertPoint - This is an instruction in the entry block before which
260 /// we prefer to insert allocas.
261 llvm::Instruction *AllocaInsertPt;
262
263 const llvm::Type *LLVMIntTy;
Hartmut Kaiserff08d2c2007-10-17 15:00:17 +0000264 uint32_t LLVMPointerWidth;
Chris Lattner4b009652007-07-25 00:24:17 +0000265
Chris Lattner9fba49a2007-08-24 05:35:26 +0000266private:
Chris Lattner4b009652007-07-25 00:24:17 +0000267 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
268 /// decls.
269 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
270
271 /// LabelMap - This keeps track of the LLVM basic block for each C label.
272 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
273
274 // BreakContinueStack - This keeps track of where break and continue
275 // statements should jump to.
276 struct BreakContinue {
277 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
278 : BreakBlock(bb), ContinueBlock(cb) {}
279
280 llvm::BasicBlock *BreakBlock;
281 llvm::BasicBlock *ContinueBlock;
282 };
283 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
284
Devang Patelbc372382007-10-09 17:08:50 +0000285 /// SwitchInsn - This is nearest current switch instruction. It is null if
286 /// if current context is not in a switch.
Devang Patele58e0802007-10-04 23:45:31 +0000287 llvm::SwitchInst *SwitchInsn;
288
Devang Patelbc372382007-10-09 17:08:50 +0000289 /// CaseRangeBlock - This block holds if condition check for last case
290 /// statement range in current switch instruction.
Devang Patel347ca322007-10-08 20:57:48 +0000291 llvm::BasicBlock *CaseRangeBlock;
292
Chris Lattner4b009652007-07-25 00:24:17 +0000293public:
294 CodeGenFunction(CodeGenModule &cgm);
295
296 ASTContext &getContext() const;
297
Chris Lattnerb326b172008-03-30 23:03:07 +0000298 void GenerateObjCMethod(const ObjCMethodDecl *OMD);
Chris Lattner4b009652007-07-25 00:24:17 +0000299 void GenerateCode(const FunctionDecl *FD);
300
301 const llvm::Type *ConvertType(QualType T);
Chris Lattner6e6a5972008-04-04 04:07:35 +0000302
303 llvm::Value *LoadObjCSelf();
Chris Lattner4b009652007-07-25 00:24:17 +0000304
305 /// hasAggregateLLVMType - Return true if the specified AST type will map into
306 /// an aggregate LLVM type or is void.
307 static bool hasAggregateLLVMType(QualType T);
308
309 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
310 /// label maps to.
311 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
312
313
314 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattner9d4e6202007-12-02 01:43:38 +0000315
316 /// WarnUnsupported - Print out a warning that codegen doesn't support the
317 /// specified stmt yet.
Chris Lattnere8f49632007-12-02 01:49:16 +0000318 void WarnUnsupported(const Stmt *S, const char *Type);
Chris Lattner4b009652007-07-25 00:24:17 +0000319
320 //===--------------------------------------------------------------------===//
321 // Helpers
322 //===--------------------------------------------------------------------===//
323
324 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
325 /// block.
326 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
327 const char *Name = "tmp");
328
329 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
330 /// expression and compare the result against zero, returning an Int1Ty value.
331 llvm::Value *EvaluateExprAsBool(const Expr *E);
332
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000333 /// EmitAnyExpr - Emit code to compute the specified expression which can have
334 /// any type. The result is returned as an RValue struct. If this is an
335 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
336 /// the result should be returned.
337 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
338 bool isAggLocVolatile = false);
Devang Patel97299362007-09-28 21:49:18 +0000339
340 /// isDummyBlock - Return true if BB is an empty basic block
341 /// with no predecessors.
342 static bool isDummyBlock(const llvm::BasicBlock *BB);
343
Devang Patele58e0802007-10-04 23:45:31 +0000344 /// StartBlock - Start new block named N. If insert block is a dummy block
345 /// then reuse it.
346 void StartBlock(const char *N);
347
Devang Patel7a78e432007-11-01 19:11:01 +0000348 /// getCGRecordLayout - Return record layout info.
349 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Lauro Ramos Venancio934fb022008-02-26 21:41:45 +0000350
351 /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000352 llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
Dan Gohman4751a3a2008-05-22 00:50:06 +0000353
354 /// getAccessedFieldNo - Given an encoded value and a result number, return
355 /// the input field number being accessed.
356 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
357
Chris Lattner4b009652007-07-25 00:24:17 +0000358 //===--------------------------------------------------------------------===//
Chris Lattner4b009652007-07-25 00:24:17 +0000359 // Declaration Emission
360 //===--------------------------------------------------------------------===//
361
362 void EmitDecl(const Decl &D);
363 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000364 void EmitBlockVarDecl(const VarDecl &D);
365 void EmitLocalBlockVarDecl(const VarDecl &D);
366 void EmitStaticBlockVarDecl(const VarDecl &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000367 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
368
369 //===--------------------------------------------------------------------===//
370 // Statement Emission
371 //===--------------------------------------------------------------------===//
372
373 void EmitStmt(const Stmt *S);
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000374 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
375 llvm::Value *AggLoc = 0, bool isAggVol = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000376 void EmitLabelStmt(const LabelStmt &S);
377 void EmitGotoStmt(const GotoStmt &S);
378 void EmitIfStmt(const IfStmt &S);
379 void EmitWhileStmt(const WhileStmt &S);
380 void EmitDoStmt(const DoStmt &S);
381 void EmitForStmt(const ForStmt &S);
382 void EmitReturnStmt(const ReturnStmt &S);
383 void EmitDeclStmt(const DeclStmt &S);
384 void EmitBreakStmt();
385 void EmitContinueStmt();
Devang Patele58e0802007-10-04 23:45:31 +0000386 void EmitSwitchStmt(const SwitchStmt &S);
387 void EmitDefaultStmt(const DefaultStmt &S);
388 void EmitCaseStmt(const CaseStmt &S);
Devang Patel347ca322007-10-08 20:57:48 +0000389 void EmitCaseStmtRange(const CaseStmt &S);
Anders Carlssonaf6a6c22008-02-05 16:35:33 +0000390 void EmitAsmStmt(const AsmStmt &S);
391
Chris Lattner4b009652007-07-25 00:24:17 +0000392 //===--------------------------------------------------------------------===//
393 // LValue Expression Emission
394 //===--------------------------------------------------------------------===//
395
396 /// EmitLValue - Emit code to compute a designator that specifies the location
397 /// of the expression.
398 ///
399 /// This can return one of two things: a simple address or a bitfield
400 /// reference. In either case, the LLVM Value* in the LValue structure is
401 /// guaranteed to be an LLVM pointer type.
402 ///
403 /// If this returns a bitfield reference, nothing about the pointee type of
404 /// the LLVM value is known: For example, it may not be a pointer to an
405 /// integer.
406 ///
407 /// If this returns a normal address, and if the lvalue's C type is fixed
408 /// size, this method guarantees that the returned pointer type will point to
409 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
410 /// variable length type, this is not possible.
411 ///
412 LValue EmitLValue(const Expr *E);
413
414 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
415 /// this method emits the address of the lvalue, then loads the result as an
416 /// rvalue, returning the rvalue.
Chris Lattner4b009652007-07-25 00:24:17 +0000417 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Nate Begemanaf6ed502008-04-18 23:10:10 +0000418 RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000419 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
Chris Lattner4b009652007-07-25 00:24:17 +0000420
Chris Lattner944f7962007-08-03 16:18:34 +0000421
Chris Lattner4b009652007-07-25 00:24:17 +0000422 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
423 /// lvalue, where both are guaranteed to the have the same type, and that type
424 /// is 'Ty'.
425 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Nate Begemanaf6ed502008-04-18 23:10:10 +0000426 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
427 QualType Ty);
Lauro Ramos Venancio2d7a34c2008-01-22 22:36:45 +0000428 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
Christopher Lambad327ba2007-12-29 05:02:41 +0000429
430 // Note: only availabe for agg return types
431 LValue EmitCallExprLValue(const CallExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000432
433 LValue EmitDeclRefLValue(const DeclRefExpr *E);
434 LValue EmitStringLiteralLValue(const StringLiteral *E);
435 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
436 LValue EmitUnaryOpLValue(const UnaryOperator *E);
437 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Nate Begemanaf6ed502008-04-18 23:10:10 +0000438 LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
Devang Patelaebd83f2007-10-23 02:10:49 +0000439 LValue EmitMemberExpr(const MemberExpr *E);
Eli Friedmanf3c2cb42008-05-13 23:18:27 +0000440 LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
Eli Friedmand3550112008-02-09 08:50:58 +0000441
442 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
443 bool isUnion);
Chris Lattnerb326b172008-03-30 23:03:07 +0000444
445 LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000446 //===--------------------------------------------------------------------===//
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000447 // Scalar Expression Emission
Chris Lattner4b009652007-07-25 00:24:17 +0000448 //===--------------------------------------------------------------------===//
449
Chris Lattner4b009652007-07-25 00:24:17 +0000450 RValue EmitCallExpr(const CallExpr *E);
Eli Friedman261f4ad2008-01-30 01:32:06 +0000451 RValue EmitCallExpr(Expr *FnExpr, Expr *const *Args, unsigned NumArgs);
452 RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
453 Expr *const *Args, unsigned NumArgs);
Chris Lattner35055b82007-08-26 22:58:05 +0000454 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000455
Anders Carlssone1449c12007-12-09 23:17:02 +0000456 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
457 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
458
Anders Carlssona9234fe2007-12-10 19:35:18 +0000459 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
Nate Begemanec2d1062007-12-30 02:59:45 +0000460 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
461 bool isSplat = false);
Anders Carlsson68b8be92007-12-15 21:23:30 +0000462
Chris Lattner9fba49a2007-08-24 05:35:26 +0000463 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Anders Carlssona66cad42007-08-21 17:43:55 +0000464
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000465 //===--------------------------------------------------------------------===//
Chris Lattner41b1fca2007-08-26 23:13:56 +0000466 // Expression Emission
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000467 //===--------------------------------------------------------------------===//
Chris Lattner41b1fca2007-08-26 23:13:56 +0000468
469 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000470
Chris Lattner9fba49a2007-08-24 05:35:26 +0000471 /// EmitScalarExpr - Emit the computation of the specified expression of
472 /// LLVM scalar type, returning the result.
473 llvm::Value *EmitScalarExpr(const Expr *E);
474
Chris Lattner4e05d1e2007-08-26 06:48:56 +0000475 /// EmitScalarConversion - Emit a conversion from the specified type to the
476 /// specified destination type, both of which are LLVM scalar types.
477 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
478 QualType DstTy);
479
Chris Lattnerfb182ee2007-08-26 16:34:22 +0000480 /// EmitComplexToScalarConversion - Emit a conversion from the specified
481 /// complex type to the specified destination type, where the destination
482 /// type is an LLVM scalar type.
483 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
484 QualType DstTy);
485
Chris Lattner4e05d1e2007-08-26 06:48:56 +0000486
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000487 /// EmitAggExpr - Emit the computation of the specified expression of
488 /// aggregate type. The result is computed into DestPtr. Note that if
489 /// DestPtr is null, the value of the aggregate expression is not needed.
490 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattner8d0cc2f2007-08-21 05:54:00 +0000491
492 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner348c8a22007-08-23 23:43:33 +0000493 /// complex type, returning the result.
Chris Lattner5280c5f2007-08-21 16:57:55 +0000494 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner348c8a22007-08-23 23:43:33 +0000495
496 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
497 /// of complex type, storing into the specified Value*.
Chris Lattner8e1f6e02007-08-26 16:22:13 +0000498 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
499 bool DestIsVolatile);
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000500 /// LoadComplexFromAddr - Load a complex number from the specified address.
501 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Chris Lattner85970f32008-05-08 05:58:21 +0000502
503 /// GenerateStaticBlockVarDecl - return the the static
504 /// declaration of local variable.
505 llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D,
506 bool NoInit,
507 const char *Separator);
Chris Lattner4b009652007-07-25 00:24:17 +0000508};
509} // end namespace CodeGen
510} // end namespace clang
511
512#endif