blob: 5bf6bc1fea43365ef3630a61cba5bf851398d783 [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
Nate Begemana3554e72008-07-25 20:15:41 +0000130 // BitField start bit and size
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000131 struct {
132 unsigned short StartBit;
133 unsigned short Size;
134 bool IsSigned;
Nate Begemana3554e72008-07-25 20:15:41 +0000135 } BitfieldData;
Chris Lattner4b009652007-07-25 00:24:17 +0000136 };
Eli Friedman2e630542008-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 Lattner4b009652007-07-25 00:24:17 +0000148public:
149 bool isSimple() const { return LVType == Simple; }
150 bool isVectorElt() const { return LVType == VectorElt; }
151 bool isBitfield() const { return LVType == BitField; }
Nate Begemanaf6ed502008-04-18 23:10:10 +0000152 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Chris Lattner4b009652007-07-25 00:24:17 +0000153
Eli Friedman2e630542008-06-13 23:01:12 +0000154 bool isVolatileQualified() const { return Volatile; }
155 bool isRestrictQualified() const { return Restrict; }
156
Chris Lattner4b009652007-07-25 00:24:17 +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 Begemanaf6ed502008-04-18 23:10:10 +0000162 // extended vector elements.
163 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
Nate Begemanc8e51f82008-05-09 06:41:27 +0000164 llvm::Constant *getExtVectorElts() const {
Nate Begemanaf6ed502008-04-18 23:10:10 +0000165 assert(isExtVectorElt());
Chris Lattnera0d03a72007-08-03 17:31:20 +0000166 return VectorElts;
Chris Lattner65520192007-08-02 23:37:31 +0000167 }
Lauro Ramos Venanciob40307c2008-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 Friedman2e630542008-06-13 23:01:12 +0000183 static LValue MakeAddr(llvm::Value *V, unsigned Qualifiers) {
Chris Lattner4b009652007-07-25 00:24:17 +0000184 LValue R;
185 R.LVType = Simple;
186 R.V = V;
Eli Friedman2e630542008-06-13 23:01:12 +0000187 SetQualifiers(Qualifiers,R);
Chris Lattner4b009652007-07-25 00:24:17 +0000188 return R;
189 }
190
Eli Friedman2e630542008-06-13 23:01:12 +0000191 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
192 unsigned Qualifiers) {
Chris Lattner4b009652007-07-25 00:24:17 +0000193 LValue R;
194 R.LVType = VectorElt;
195 R.V = Vec;
196 R.VectorIdx = Idx;
Eli Friedman2e630542008-06-13 23:01:12 +0000197 SetQualifiers(Qualifiers,R);
Chris Lattner4b009652007-07-25 00:24:17 +0000198 return R;
199 }
200
Eli Friedman2e630542008-06-13 23:01:12 +0000201 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
202 unsigned Qualifiers) {
Chris Lattner65520192007-08-02 23:37:31 +0000203 LValue R;
Nate Begemanaf6ed502008-04-18 23:10:10 +0000204 R.LVType = ExtVectorElt;
Chris Lattner65520192007-08-02 23:37:31 +0000205 R.V = Vec;
Nate Begemanc8e51f82008-05-09 06:41:27 +0000206 R.VectorElts = Elts;
Eli Friedman2e630542008-06-13 23:01:12 +0000207 SetQualifiers(Qualifiers,R);
Chris Lattner65520192007-08-02 23:37:31 +0000208 return R;
209 }
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000210
211 static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
Eli Friedman2e630542008-06-13 23:01:12 +0000212 unsigned short Size, bool IsSigned,
213 unsigned Qualifiers) {
Lauro Ramos Venanciob40307c2008-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 Friedman2e630542008-06-13 23:01:12 +0000220 SetQualifiers(Qualifiers,R);
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000221 return R;
222 }
Chris Lattner4b009652007-07-25 00:24:17 +0000223};
224
225/// CodeGenFunction - This class organizes the per-function state that is used
226/// while generating LLVM code.
227class CodeGenFunction {
Chris Lattner41b1fca2007-08-26 23:13:56 +0000228public:
Chris Lattner4b009652007-07-25 00:24:17 +0000229 CodeGenModule &CGM; // Per-module state.
230 TargetInfo &Target;
Chris Lattner41b1fca2007-08-26 23:13:56 +0000231
Chris Lattner5280c5f2007-08-21 16:57:55 +0000232 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Chris Lattner676bf212008-04-13 07:32:11 +0000233 llvm::IRBuilder Builder;
Chris Lattner4b009652007-07-25 00:24:17 +0000234
Chris Lattner6e6a5972008-04-04 04:07:35 +0000235 // Holds the Decl for the current function or method
Chris Lattner8c7c6a12008-06-17 18:05:57 +0000236 const Decl *CurFuncDecl;
Chris Lattnerb326b172008-03-30 23:03:07 +0000237 QualType FnRetTy;
Chris Lattner4b009652007-07-25 00:24:17 +0000238 llvm::Function *CurFn;
239
240 /// AllocaInsertPoint - This is an instruction in the entry block before which
241 /// we prefer to insert allocas.
242 llvm::Instruction *AllocaInsertPt;
243
244 const llvm::Type *LLVMIntTy;
Hartmut Kaiserff08d2c2007-10-17 15:00:17 +0000245 uint32_t LLVMPointerWidth;
Chris Lattner4b009652007-07-25 00:24:17 +0000246
Chris Lattner9fba49a2007-08-24 05:35:26 +0000247private:
Chris Lattner4b009652007-07-25 00:24:17 +0000248 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
249 /// decls.
250 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
251
252 /// LabelMap - This keeps track of the LLVM basic block for each C label.
253 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
254
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 Patelbc372382007-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 Patele58e0802007-10-04 23:45:31 +0000268 llvm::SwitchInst *SwitchInsn;
269
Devang Patelbc372382007-10-09 17:08:50 +0000270 /// CaseRangeBlock - This block holds if condition check for last case
271 /// statement range in current switch instruction.
Devang Patel347ca322007-10-08 20:57:48 +0000272 llvm::BasicBlock *CaseRangeBlock;
273
Chris Lattner4b009652007-07-25 00:24:17 +0000274public:
275 CodeGenFunction(CodeGenModule &cgm);
276
277 ASTContext &getContext() const;
278
Chris Lattnerb326b172008-03-30 23:03:07 +0000279 void GenerateObjCMethod(const ObjCMethodDecl *OMD);
Chris Lattner4b009652007-07-25 00:24:17 +0000280 void GenerateCode(const FunctionDecl *FD);
Chris Lattner8c7c6a12008-06-17 18:05:57 +0000281 void GenerateFunction(const Stmt *Body);
Chris Lattner4b009652007-07-25 00:24:17 +0000282
283 const llvm::Type *ConvertType(QualType T);
Chris Lattner6e6a5972008-04-04 04:07:35 +0000284
285 llvm::Value *LoadObjCSelf();
Chris Lattner8c7c6a12008-06-17 18:05:57 +0000286
287 /// isObjCPointerType - Return true if the specificed AST type will map onto
288 /// some Objective-C pointer type.
289 static bool isObjCPointerType(QualType T);
290
Chris Lattner4b009652007-07-25 00:24:17 +0000291 /// hasAggregateLLVMType - Return true if the specified AST type will map into
292 /// an aggregate LLVM type or is void.
293 static bool hasAggregateLLVMType(QualType T);
294
295 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
296 /// label maps to.
297 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
298
299
300 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattner9d4e6202007-12-02 01:43:38 +0000301
302 /// WarnUnsupported - Print out a warning that codegen doesn't support the
303 /// specified stmt yet.
Chris Lattnere8f49632007-12-02 01:49:16 +0000304 void WarnUnsupported(const Stmt *S, const char *Type);
Chris Lattner4b009652007-07-25 00:24:17 +0000305
306 //===--------------------------------------------------------------------===//
307 // Helpers
308 //===--------------------------------------------------------------------===//
309
310 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
311 /// block.
312 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
313 const char *Name = "tmp");
314
315 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
316 /// expression and compare the result against zero, returning an Int1Ty value.
317 llvm::Value *EvaluateExprAsBool(const Expr *E);
318
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000319 /// EmitAnyExpr - Emit code to compute the specified expression which can have
320 /// any type. The result is returned as an RValue struct. If this is an
321 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
322 /// the result should be returned.
323 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
324 bool isAggLocVolatile = false);
Devang Patel97299362007-09-28 21:49:18 +0000325
326 /// isDummyBlock - Return true if BB is an empty basic block
327 /// with no predecessors.
328 static bool isDummyBlock(const llvm::BasicBlock *BB);
329
Devang Patele58e0802007-10-04 23:45:31 +0000330 /// StartBlock - Start new block named N. If insert block is a dummy block
331 /// then reuse it.
332 void StartBlock(const char *N);
333
Devang Patel7a78e432007-11-01 19:11:01 +0000334 /// getCGRecordLayout - Return record layout info.
335 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Lauro Ramos Venancio934fb022008-02-26 21:41:45 +0000336
337 /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000338 llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
Dan Gohman4751a3a2008-05-22 00:50:06 +0000339
340 /// getAccessedFieldNo - Given an encoded value and a result number, return
341 /// the input field number being accessed.
342 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
343
Chris Lattner4b009652007-07-25 00:24:17 +0000344 //===--------------------------------------------------------------------===//
Chris Lattner4b009652007-07-25 00:24:17 +0000345 // Declaration Emission
346 //===--------------------------------------------------------------------===//
347
348 void EmitDecl(const Decl &D);
349 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000350 void EmitBlockVarDecl(const VarDecl &D);
351 void EmitLocalBlockVarDecl(const VarDecl &D);
352 void EmitStaticBlockVarDecl(const VarDecl &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000353 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
354
355 //===--------------------------------------------------------------------===//
356 // Statement Emission
357 //===--------------------------------------------------------------------===//
358
359 void EmitStmt(const Stmt *S);
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000360 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
361 llvm::Value *AggLoc = 0, bool isAggVol = false);
Chris Lattner09cee852008-07-26 20:23:23 +0000362 void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
Chris Lattner4b009652007-07-25 00:24:17 +0000363 void EmitLabelStmt(const LabelStmt &S);
364 void EmitGotoStmt(const GotoStmt &S);
365 void EmitIfStmt(const IfStmt &S);
366 void EmitWhileStmt(const WhileStmt &S);
367 void EmitDoStmt(const DoStmt &S);
368 void EmitForStmt(const ForStmt &S);
369 void EmitReturnStmt(const ReturnStmt &S);
370 void EmitDeclStmt(const DeclStmt &S);
371 void EmitBreakStmt();
372 void EmitContinueStmt();
Devang Patele58e0802007-10-04 23:45:31 +0000373 void EmitSwitchStmt(const SwitchStmt &S);
374 void EmitDefaultStmt(const DefaultStmt &S);
375 void EmitCaseStmt(const CaseStmt &S);
Devang Patel347ca322007-10-08 20:57:48 +0000376 void EmitCaseStmtRange(const CaseStmt &S);
Anders Carlssonaf6a6c22008-02-05 16:35:33 +0000377 void EmitAsmStmt(const AsmStmt &S);
378
Chris Lattner4b009652007-07-25 00:24:17 +0000379 //===--------------------------------------------------------------------===//
380 // LValue Expression Emission
381 //===--------------------------------------------------------------------===//
382
383 /// EmitLValue - Emit code to compute a designator that specifies the location
384 /// of the expression.
385 ///
386 /// This can return one of two things: a simple address or a bitfield
387 /// reference. In either case, the LLVM Value* in the LValue structure is
388 /// guaranteed to be an LLVM pointer type.
389 ///
390 /// If this returns a bitfield reference, nothing about the pointee type of
391 /// the LLVM value is known: For example, it may not be a pointer to an
392 /// integer.
393 ///
394 /// If this returns a normal address, and if the lvalue's C type is fixed
395 /// size, this method guarantees that the returned pointer type will point to
396 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
397 /// variable length type, this is not possible.
398 ///
399 LValue EmitLValue(const Expr *E);
400
401 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
402 /// this method emits the address of the lvalue, then loads the result as an
403 /// rvalue, returning the rvalue.
Chris Lattner4b009652007-07-25 00:24:17 +0000404 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Nate Begemanaf6ed502008-04-18 23:10:10 +0000405 RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000406 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
Chris Lattner4b009652007-07-25 00:24:17 +0000407
Chris Lattner944f7962007-08-03 16:18:34 +0000408
Chris Lattner4b009652007-07-25 00:24:17 +0000409 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
410 /// lvalue, where both are guaranteed to the have the same type, and that type
411 /// is 'Ty'.
412 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Nate Begemanaf6ed502008-04-18 23:10:10 +0000413 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
414 QualType Ty);
Lauro Ramos Venancio2d7a34c2008-01-22 22:36:45 +0000415 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
Christopher Lambad327ba2007-12-29 05:02:41 +0000416
417 // Note: only availabe for agg return types
418 LValue EmitCallExprLValue(const CallExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000419
420 LValue EmitDeclRefLValue(const DeclRefExpr *E);
421 LValue EmitStringLiteralLValue(const StringLiteral *E);
422 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
423 LValue EmitUnaryOpLValue(const UnaryOperator *E);
424 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Nate Begemanaf6ed502008-04-18 23:10:10 +0000425 LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
Devang Patelaebd83f2007-10-23 02:10:49 +0000426 LValue EmitMemberExpr(const MemberExpr *E);
Eli Friedmanf3c2cb42008-05-13 23:18:27 +0000427 LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
Eli Friedmand3550112008-02-09 08:50:58 +0000428
429 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
Eli Friedman2e630542008-06-13 23:01:12 +0000430 bool isUnion, unsigned CVRQualifiers);
Chris Lattnerb326b172008-03-30 23:03:07 +0000431
432 LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000433 //===--------------------------------------------------------------------===//
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000434 // Scalar Expression Emission
Chris Lattner4b009652007-07-25 00:24:17 +0000435 //===--------------------------------------------------------------------===//
436
Chris Lattner4b009652007-07-25 00:24:17 +0000437 RValue EmitCallExpr(const CallExpr *E);
Ted Kremenek2719e982008-06-17 02:43:46 +0000438
439 RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg,
440 CallExpr::const_arg_iterator ArgEnd);
441
Eli Friedman261f4ad2008-01-30 01:32:06 +0000442 RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
Ted Kremenek2719e982008-06-17 02:43:46 +0000443 CallExpr::const_arg_iterator ArgBeg,
444 CallExpr::const_arg_iterator ArgEnd);
445
Chris Lattner35055b82007-08-26 22:58:05 +0000446 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000447
Anders Carlssone1449c12007-12-09 23:17:02 +0000448 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
449 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
450
Anders Carlssona9234fe2007-12-10 19:35:18 +0000451 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
Nate Begemanec2d1062007-12-30 02:59:45 +0000452 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
453 bool isSplat = false);
Anders Carlsson68b8be92007-12-15 21:23:30 +0000454
Chris Lattner9fba49a2007-08-24 05:35:26 +0000455 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Chris Lattner6ee20e32008-06-24 17:04:18 +0000456 llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
457 llvm::Value *EmitObjCMessageExpr(const ObjCMessageExpr *E);
458
459
Anders Carlssona66cad42007-08-21 17:43:55 +0000460
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000461 //===--------------------------------------------------------------------===//
Chris Lattner41b1fca2007-08-26 23:13:56 +0000462 // Expression Emission
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000463 //===--------------------------------------------------------------------===//
Chris Lattner41b1fca2007-08-26 23:13:56 +0000464
465 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000466
Chris Lattner9fba49a2007-08-24 05:35:26 +0000467 /// EmitScalarExpr - Emit the computation of the specified expression of
468 /// LLVM scalar type, returning the result.
469 llvm::Value *EmitScalarExpr(const Expr *E);
470
Chris Lattner4e05d1e2007-08-26 06:48:56 +0000471 /// EmitScalarConversion - Emit a conversion from the specified type to the
472 /// specified destination type, both of which are LLVM scalar types.
473 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
474 QualType DstTy);
475
Chris Lattnerfb182ee2007-08-26 16:34:22 +0000476 /// EmitComplexToScalarConversion - Emit a conversion from the specified
477 /// complex type to the specified destination type, where the destination
478 /// type is an LLVM scalar type.
479 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
480 QualType DstTy);
481
Chris Lattner4e05d1e2007-08-26 06:48:56 +0000482
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000483 /// EmitAggExpr - Emit the computation of the specified expression of
484 /// aggregate type. The result is computed into DestPtr. Note that if
485 /// DestPtr is null, the value of the aggregate expression is not needed.
486 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattner8d0cc2f2007-08-21 05:54:00 +0000487
488 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner348c8a22007-08-23 23:43:33 +0000489 /// complex type, returning the result.
Chris Lattner5280c5f2007-08-21 16:57:55 +0000490 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner348c8a22007-08-23 23:43:33 +0000491
492 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
493 /// of complex type, storing into the specified Value*.
Chris Lattner8e1f6e02007-08-26 16:22:13 +0000494 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
495 bool DestIsVolatile);
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000496 /// LoadComplexFromAddr - Load a complex number from the specified address.
497 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Chris Lattner85970f32008-05-08 05:58:21 +0000498
499 /// GenerateStaticBlockVarDecl - return the the static
500 /// declaration of local variable.
501 llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D,
502 bool NoInit,
503 const char *Separator);
Chris Lattner4b009652007-07-25 00:24:17 +0000504};
505} // end namespace CodeGen
506} // end namespace clang
507
508#endif