blob: eaf2b1ded2127d7d77372e71076c15aa8c0d3d87 [file] [log] [blame]
Chris Lattnerbed31442007-05-28 01:07:47 +00001//===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This is the internal per-function state used for llvm translation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CODEGEN_CODEGENFUNCTION_H
15#define CODEGEN_CODEGENFUNCTION_H
16
Chris Lattnerac248202007-05-30 00:13:02 +000017#include "llvm/ADT/DenseMap.h"
Chris Lattnere73e4322007-07-16 21:28:45 +000018#include "llvm/ADT/SmallVector.h"
Chris Lattner308f4312007-05-29 23:50:05 +000019#include "llvm/Support/LLVMBuilder.h"
Chris Lattner2ccb73b2007-06-16 00:16:26 +000020#include <vector>
Chris Lattner308f4312007-05-29 23:50:05 +000021
Chris Lattnerbed31442007-05-28 01:07:47 +000022namespace llvm {
23 class Module;
Chris Lattner23b7eb62007-06-15 23:05:46 +000024}
25
Chris Lattnerbed31442007-05-28 01:07:47 +000026namespace clang {
27 class ASTContext;
Chris Lattner84915fa2007-06-02 04:16:21 +000028 class Decl;
Chris Lattnerbed31442007-05-28 01:07:47 +000029 class FunctionDecl;
Chris Lattner2ccb73b2007-06-16 00:16:26 +000030 class TargetInfo;
Chris Lattner2ccb73b2007-06-16 00:16:26 +000031 class QualType;
32 class FunctionTypeProto;
Chris Lattner84915fa2007-06-02 04:16:21 +000033
Chris Lattner308f4312007-05-29 23:50:05 +000034 class Stmt;
35 class CompoundStmt;
Chris Lattnerac248202007-05-30 00:13:02 +000036 class LabelStmt;
37 class GotoStmt;
Chris Lattner5269c032007-05-30 21:03:58 +000038 class IfStmt;
Chris Lattner946aa312007-06-05 03:59:43 +000039 class WhileStmt;
Chris Lattner8394d792007-06-05 20:53:16 +000040 class DoStmt;
41 class ForStmt;
Chris Lattner3f3dbee2007-06-02 03:19:07 +000042 class ReturnStmt;
Chris Lattner84915fa2007-06-02 04:16:21 +000043 class DeclStmt;
Chris Lattnerbed31442007-05-28 01:07:47 +000044
Chris Lattner208ae962007-05-30 17:57:17 +000045 class Expr;
Chris Lattnerd7f58862007-06-02 05:24:33 +000046 class DeclRefExpr;
Chris Lattner4347e3692007-06-06 04:54:52 +000047 class StringLiteral;
Chris Lattner208ae962007-05-30 17:57:17 +000048 class IntegerLiteral;
Chris Lattner2ada32e2007-07-09 23:03:16 +000049 class FloatingLiteral;
Chris Lattner6e9d9b32007-07-13 05:18:11 +000050 class CharacterLiteral;
Chris Lattner40480052007-08-03 17:51:03 +000051 class TypesCompatibleExpr;
52
Chris Lattner76ba8492007-08-20 22:37:10 +000053 class ImplicitCastExpr;
Chris Lattner8394d792007-06-05 20:53:16 +000054 class CastExpr;
Chris Lattner2b228c92007-06-15 21:34:29 +000055 class CallExpr;
Chris Lattnerf0106d22007-06-02 19:33:17 +000056 class UnaryOperator;
Chris Lattnerdb91b162007-06-02 00:16:28 +000057 class BinaryOperator;
Chris Lattner9369a562007-06-29 16:31:29 +000058 class CompoundAssignOperator;
Chris Lattnerd9d2fb12007-06-08 23:31:14 +000059 class ArraySubscriptExpr;
Chris Lattnerd268a7a2007-08-03 17:31:20 +000060 class OCUVectorElementExpr;
Chris Lattner6e9d9b32007-07-13 05:18:11 +000061 class ConditionalOperator;
Chris Lattner81a96882007-08-04 00:20:15 +000062 class ChooseExpr;
Anders Carlsson625bfc82007-07-21 05:21:51 +000063 class PreDefinedExpr;
Chris Lattner208ae962007-05-30 17:57:17 +000064
Chris Lattner84915fa2007-06-02 04:16:21 +000065 class BlockVarDecl;
66 class EnumConstantDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000067 class ParmVarDecl;
Chris Lattnerbed31442007-05-28 01:07:47 +000068namespace CodeGen {
69 class CodeGenModule;
70
Chris Lattnerd7f58862007-06-02 05:24:33 +000071
Chris Lattner8394d792007-06-05 20:53:16 +000072/// RValue - This trivial value class is used to represent the result of an
Chris Lattnerd7f58862007-06-02 05:24:33 +000073/// expression that is evaluated. It can be one of two things: either a simple
74/// LLVM SSA value, or the address of an aggregate value in memory. These two
75/// possibilities are discriminated by isAggregate/isScalar.
Chris Lattner8394d792007-06-05 20:53:16 +000076class RValue {
Chris Lattner23b7eb62007-06-15 23:05:46 +000077 llvm::Value *V;
Chris Lattnerdb91b162007-06-02 00:16:28 +000078 // TODO: Encode this into the low bit of pointer for more efficient
79 // return-by-value.
Chris Lattner5269c032007-05-30 21:03:58 +000080 bool IsAggregate;
Chris Lattner09153c02007-06-22 18:48:09 +000081
82 // FIXME: Aggregate rvalues need to retain information about whether they are
83 // volatile or not.
Chris Lattner5269c032007-05-30 21:03:58 +000084public:
85
86 bool isAggregate() const { return IsAggregate; }
87 bool isScalar() const { return !IsAggregate; }
88
89 /// getVal() - Return the Value* of this scalar value.
Chris Lattner23b7eb62007-06-15 23:05:46 +000090 llvm::Value *getVal() const {
Chris Lattner5269c032007-05-30 21:03:58 +000091 assert(!isAggregate() && "Not a scalar!");
92 return V;
93 }
94
Chris Lattner09153c02007-06-22 18:48:09 +000095 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
96 llvm::Value *getAggregateAddr() const {
Chris Lattner5269c032007-05-30 21:03:58 +000097 assert(isAggregate() && "Not an aggregate!");
98 return V;
99 }
Chris Lattner208ae962007-05-30 17:57:17 +0000100
Chris Lattner23b7eb62007-06-15 23:05:46 +0000101 static RValue get(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +0000102 RValue ER;
Chris Lattner208ae962007-05-30 17:57:17 +0000103 ER.V = V;
Chris Lattner5269c032007-05-30 21:03:58 +0000104 ER.IsAggregate = false;
Chris Lattner208ae962007-05-30 17:57:17 +0000105 return ER;
106 }
Chris Lattner23b7eb62007-06-15 23:05:46 +0000107 static RValue getAggregate(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +0000108 RValue ER;
Chris Lattner208ae962007-05-30 17:57:17 +0000109 ER.V = V;
Chris Lattner5269c032007-05-30 21:03:58 +0000110 ER.IsAggregate = true;
Chris Lattner208ae962007-05-30 17:57:17 +0000111 return ER;
112 }
113};
Chris Lattnerd7f58862007-06-02 05:24:33 +0000114
115
116/// LValue - This represents an lvalue references. Because C/C++ allow
117/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
118/// bitrange.
119class LValue {
120 // FIXME: Volatility. Restrict?
Chris Lattner8394d792007-06-05 20:53:16 +0000121 // alignment?
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000122
123 enum {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000124 Simple, // This is a normal l-value, use getAddress().
125 VectorElt, // This is a vector element l-value (V[i]), use getVector*
126 BitField, // This is a bitfield l-value, use getBitfield*.
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000127 OCUVectorElt // This is an ocu vector subset, use getOCUVectorComp
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000128 } LVType;
129
Chris Lattnerd7f58862007-06-02 05:24:33 +0000130 llvm::Value *V;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000131
132 union {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000133 llvm::Value *VectorIdx; // Index into a vector subscript: V[i]
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000134 unsigned VectorElts; // Encoded OCUVector element subset: V.xyx
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000135 };
Chris Lattnerd7f58862007-06-02 05:24:33 +0000136public:
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000137 bool isSimple() const { return LVType == Simple; }
138 bool isVectorElt() const { return LVType == VectorElt; }
139 bool isBitfield() const { return LVType == BitField; }
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000140 bool isOCUVectorElt() const { return LVType == OCUVectorElt; }
Chris Lattner208ae962007-05-30 17:57:17 +0000141
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000142 // simple lvalue
143 llvm::Value *getAddress() const { assert(isSimple()); return V; }
144 // vector elt lvalue
145 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
146 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000147 // ocu vector elements.
148 llvm::Value *getOCUVectorAddr() const { assert(isOCUVectorElt()); return V; }
149 unsigned getOCUVectorElts() const {
150 assert(isOCUVectorElt());
151 return VectorElts;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000152 }
153
Chris Lattnerd7f58862007-06-02 05:24:33 +0000154
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000155 static LValue MakeAddr(llvm::Value *V) {
Chris Lattnerd7f58862007-06-02 05:24:33 +0000156 LValue R;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000157 R.LVType = Simple;
Chris Lattnerd7f58862007-06-02 05:24:33 +0000158 R.V = V;
159 return R;
160 }
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000161
162 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx) {
163 LValue R;
164 R.LVType = VectorElt;
165 R.V = Vec;
166 R.VectorIdx = Idx;
167 return R;
168 }
169
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000170 static LValue MakeOCUVectorElt(llvm::Value *Vec, unsigned Elements) {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000171 LValue R;
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000172 R.LVType = OCUVectorElt;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000173 R.V = Vec;
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000174 R.VectorElts = Elements;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000175 return R;
176 }
Chris Lattnerd7f58862007-06-02 05:24:33 +0000177};
178
Chris Lattnerbed31442007-05-28 01:07:47 +0000179/// CodeGenFunction - This class organizes the per-function state that is used
180/// while generating LLVM code.
181class CodeGenFunction {
182 CodeGenModule &CGM; // Per-module state.
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000183 TargetInfo &Target;
Chris Lattner4758b402007-08-21 04:25:47 +0000184public:
Chris Lattner23b7eb62007-06-15 23:05:46 +0000185 llvm::LLVMBuilder Builder;
Chris Lattner4758b402007-08-21 04:25:47 +0000186private:
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000187
188 const FunctionDecl *CurFuncDecl;
Chris Lattnerac248202007-05-30 00:13:02 +0000189 llvm::Function *CurFn;
190
Chris Lattner03df1222007-06-02 04:53:11 +0000191 /// AllocaInsertPoint - This is an instruction in the entry block before which
192 /// we prefer to insert allocas.
193 llvm::Instruction *AllocaInsertPt;
194
Chris Lattner6db1fb82007-06-02 22:49:07 +0000195 const llvm::Type *LLVMIntTy;
Chris Lattnerd9d2fb12007-06-08 23:31:14 +0000196 unsigned LLVMPointerWidth;
Chris Lattner6db1fb82007-06-02 22:49:07 +0000197
Chris Lattner84915fa2007-06-02 04:16:21 +0000198 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
199 /// decls.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000200 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
Chris Lattner84915fa2007-06-02 04:16:21 +0000201
Chris Lattnerac248202007-05-30 00:13:02 +0000202 /// LabelMap - This keeps track of the LLVM basic block for each C label.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000203 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnere73e4322007-07-16 21:28:45 +0000204
205 // BreakContinueStack - This keeps track of where break and continue
206 // statements should jump to.
207 struct BreakContinue {
208 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
209 : BreakBlock(bb), ContinueBlock(cb) {}
210
211 llvm::BasicBlock *BreakBlock;
212 llvm::BasicBlock *ContinueBlock;
213 };
214 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
215
Chris Lattnerbed31442007-05-28 01:07:47 +0000216public:
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000217 CodeGenFunction(CodeGenModule &cgm);
Chris Lattnerbed31442007-05-28 01:07:47 +0000218
Chris Lattner6db1fb82007-06-02 22:49:07 +0000219 ASTContext &getContext() const;
220
Chris Lattner308f4312007-05-29 23:50:05 +0000221 void GenerateCode(const FunctionDecl *FD);
222
Chris Lattnerf033c142007-06-22 19:05:19 +0000223 const llvm::Type *ConvertType(QualType T);
Chris Lattnerac248202007-05-30 00:13:02 +0000224
Chris Lattner54fb19e2007-06-22 22:02:34 +0000225 /// hasAggregateLLVMType - Return true if the specified AST type will map into
226 /// an aggregate LLVM type or is void.
227 static bool hasAggregateLLVMType(QualType T);
228
Chris Lattnerac248202007-05-30 00:13:02 +0000229 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
230 /// label maps to.
231 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
232
233
Chris Lattner23b7eb62007-06-15 23:05:46 +0000234 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattner84915fa2007-06-02 04:16:21 +0000235
Chris Lattnere9a64532007-06-22 21:44:33 +0000236 //===--------------------------------------------------------------------===//
237 // Helpers
238 //===--------------------------------------------------------------------===//
239
240 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
241 /// block.
242 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
243 const char *Name = "tmp");
244
Chris Lattner8394d792007-06-05 20:53:16 +0000245 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
246 /// expression and compare the result against zero, returning an Int1Ty value.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000247 llvm::Value *EvaluateExprAsBool(const Expr *E);
Chris Lattnere9a64532007-06-22 21:44:33 +0000248
Chris Lattnerac248202007-05-30 00:13:02 +0000249
Chris Lattnere9a64532007-06-22 21:44:33 +0000250 /// EmitLoadOfComplex - Given an RValue reference for a complex, emit code to
251 /// load the real and imaginary pieces, returning them as Real/Imag.
252 void EmitLoadOfComplex(RValue V, llvm::Value *&Real, llvm::Value *&Imag);
253
254 /// EmitStoreOfComplex - Store the specified real/imag parts into the
255 /// specified value pointer.
256 void EmitStoreOfComplex(llvm::Value *Real, llvm::Value *Imag,
257 llvm::Value *ResPtr);
258
Chris Lattner8394d792007-06-05 20:53:16 +0000259 //===--------------------------------------------------------------------===//
260 // Conversions
261 //===--------------------------------------------------------------------===//
262
263 /// EmitConversion - Convert the value specied by Val, whose type is ValTy, to
264 /// the type specified by DstTy, following the rules of C99 6.3.
Chris Lattnerf033c142007-06-22 19:05:19 +0000265 RValue EmitConversion(RValue Val, QualType ValTy, QualType DstTy);
Chris Lattner8394d792007-06-05 20:53:16 +0000266
267 /// ConvertScalarValueToBool - Convert the specified expression value to a
Chris Lattnerf0106d22007-06-02 19:33:17 +0000268 /// boolean (i1) truth value. This is equivalent to "Val == 0".
Chris Lattner23b7eb62007-06-15 23:05:46 +0000269 llvm::Value *ConvertScalarValueToBool(RValue Val, QualType Ty);
Chris Lattnerf0106d22007-06-02 19:33:17 +0000270
Chris Lattner308f4312007-05-29 23:50:05 +0000271 //===--------------------------------------------------------------------===//
Chris Lattner53621a52007-06-13 20:44:40 +0000272 // Declaration Emission
Chris Lattner84915fa2007-06-02 04:16:21 +0000273 //===--------------------------------------------------------------------===//
274
Chris Lattner1ad38f82007-06-09 01:20:56 +0000275 void EmitDecl(const Decl &D);
Chris Lattner84915fa2007-06-02 04:16:21 +0000276 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Chris Lattner03df1222007-06-02 04:53:11 +0000277 void EmitBlockVarDecl(const BlockVarDecl &D);
278 void EmitLocalBlockVarDecl(const BlockVarDecl &D);
Chris Lattner53621a52007-06-13 20:44:40 +0000279 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
Chris Lattner03df1222007-06-02 04:53:11 +0000280
Chris Lattner84915fa2007-06-02 04:16:21 +0000281 //===--------------------------------------------------------------------===//
Chris Lattner308f4312007-05-29 23:50:05 +0000282 // Statement Emission
283 //===--------------------------------------------------------------------===//
284
285 void EmitStmt(const Stmt *S);
286 void EmitCompoundStmt(const CompoundStmt &S);
Chris Lattnerac248202007-05-30 00:13:02 +0000287 void EmitLabelStmt(const LabelStmt &S);
288 void EmitGotoStmt(const GotoStmt &S);
Chris Lattner5269c032007-05-30 21:03:58 +0000289 void EmitIfStmt(const IfStmt &S);
Chris Lattner946aa312007-06-05 03:59:43 +0000290 void EmitWhileStmt(const WhileStmt &S);
Chris Lattner8394d792007-06-05 20:53:16 +0000291 void EmitDoStmt(const DoStmt &S);
292 void EmitForStmt(const ForStmt &S);
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000293 void EmitReturnStmt(const ReturnStmt &S);
Chris Lattner1ad38f82007-06-09 01:20:56 +0000294 void EmitDeclStmt(const DeclStmt &S);
Chris Lattnere73e4322007-07-16 21:28:45 +0000295 void EmitBreakStmt();
296 void EmitContinueStmt();
297
Chris Lattner208ae962007-05-30 17:57:17 +0000298 //===--------------------------------------------------------------------===//
Chris Lattnerd7f58862007-06-02 05:24:33 +0000299 // LValue Expression Emission
300 //===--------------------------------------------------------------------===//
Chris Lattner8394d792007-06-05 20:53:16 +0000301
302 /// EmitLValue - Emit code to compute a designator that specifies the location
303 /// of the expression.
304 ///
305 /// This can return one of two things: a simple address or a bitfield
306 /// reference. In either case, the LLVM Value* in the LValue structure is
307 /// guaranteed to be an LLVM pointer type.
308 ///
309 /// If this returns a bitfield reference, nothing about the pointee type of
310 /// the LLVM value is known: For example, it may not be a pointer to an
311 /// integer.
312 ///
313 /// If this returns a normal address, and if the lvalue's C type is fixed
314 /// size, this method guarantees that the returned pointer type will point to
315 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
316 /// variable length type, this is not possible.
317 ///
Chris Lattnerd7f58862007-06-02 05:24:33 +0000318 LValue EmitLValue(const Expr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000319
320 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
321 /// this method emits the address of the lvalue, then loads the result as an
322 /// rvalue, returning the rvalue.
323 RValue EmitLoadOfLValue(const Expr *E);
Chris Lattner9369a562007-06-29 16:31:29 +0000324 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000325 RValue EmitLoadOfOCUElementLValue(LValue V, QualType LVType);
Chris Lattner9369a562007-06-29 16:31:29 +0000326
Chris Lattner40ff7012007-08-03 16:18:34 +0000327
Chris Lattner8394d792007-06-05 20:53:16 +0000328 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
329 /// lvalue, where both are guaranteed to the have the same type, and that type
330 /// is 'Ty'.
331 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Chris Lattner41d480e2007-08-03 16:28:33 +0000332 void EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, QualType Ty);
Chris Lattner8394d792007-06-05 20:53:16 +0000333
Chris Lattnerd7f58862007-06-02 05:24:33 +0000334 LValue EmitDeclRefLValue(const DeclRefExpr *E);
Chris Lattner4347e3692007-06-06 04:54:52 +0000335 LValue EmitStringLiteralLValue(const StringLiteral *E);
Anders Carlsson625bfc82007-07-21 05:21:51 +0000336 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000337 LValue EmitUnaryOpLValue(const UnaryOperator *E);
Chris Lattnerd9d2fb12007-06-08 23:31:14 +0000338 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000339 LValue EmitOCUVectorElementExpr(const OCUVectorElementExpr *E);
Chris Lattnerd7f58862007-06-02 05:24:33 +0000340
341 //===--------------------------------------------------------------------===//
Chris Lattner6278e6a2007-08-11 00:04:45 +0000342 // Scalar Expression Emission
Chris Lattner208ae962007-05-30 17:57:17 +0000343 //===--------------------------------------------------------------------===//
344
Chris Lattnercd215f02007-06-29 16:52:55 +0000345 void EmitCompoundAssignmentOperands(const CompoundAssignOperator *CAO,
346 LValue &LHSLV, RValue &LHS, RValue &RHS);
347 RValue EmitCompoundAssignmentResult(const CompoundAssignOperator *E,
348 LValue LHSLV, RValue ResV);
349
Chris Lattner8394d792007-06-05 20:53:16 +0000350 RValue EmitExpr(const Expr *E);
351 RValue EmitIntegerLiteral(const IntegerLiteral *E);
Chris Lattner2ada32e2007-07-09 23:03:16 +0000352 RValue EmitFloatingLiteral(const FloatingLiteral *E);
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000353 RValue EmitCharacterLiteral(const CharacterLiteral *E);
Chris Lattner40480052007-08-03 17:51:03 +0000354 RValue EmitTypesCompatibleExpr(const TypesCompatibleExpr *E);
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000355
Chris Lattner76ba8492007-08-20 22:37:10 +0000356 RValue EmitImplicitCastExpr(const ImplicitCastExpr *Op);
Chris Lattner388cf762007-07-13 20:25:53 +0000357 RValue EmitCastExpr(const Expr *Op, QualType DestTy);
Chris Lattner2b228c92007-06-15 21:34:29 +0000358 RValue EmitCallExpr(const CallExpr *E);
Anders Carlsson1d8e5212007-08-20 18:05:56 +0000359 RValue EmitBuiltinExpr(unsigned builtinID, const CallExpr *E);
Chris Lattnera779b3d2007-07-10 21:58:36 +0000360 RValue EmitArraySubscriptExprRV(const ArraySubscriptExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000361
Chris Lattnerf0106d22007-06-02 19:33:17 +0000362 // Unary Operators.
Chris Lattner8394d792007-06-05 20:53:16 +0000363 RValue EmitUnaryOperator(const UnaryOperator *E);
Chris Lattnerdcca4872007-07-11 23:43:46 +0000364 RValue EmitUnaryIncDec (const UnaryOperator *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000365 RValue EmitUnaryAddrOf (const UnaryOperator *E);
366 RValue EmitUnaryPlus (const UnaryOperator *E);
367 RValue EmitUnaryMinus (const UnaryOperator *E);
368 RValue EmitUnaryNot (const UnaryOperator *E);
369 RValue EmitUnaryLNot (const UnaryOperator *E);
Chris Lattner3f8c6e62007-07-18 18:12:07 +0000370 RValue EmitSizeAlignOf (QualType TypeToSize, QualType RetType,bool isSizeOf);
Chris Lattner8394d792007-06-05 20:53:16 +0000371 // FIXME: real/imag
Chris Lattnerf0106d22007-06-02 19:33:17 +0000372
Chris Lattnerdb91b162007-06-02 00:16:28 +0000373 // Binary Operators.
Chris Lattner8394d792007-06-05 20:53:16 +0000374 RValue EmitBinaryOperator(const BinaryOperator *E);
375 RValue EmitBinaryMul(const BinaryOperator *E);
376 RValue EmitBinaryDiv(const BinaryOperator *E);
377 RValue EmitBinaryRem(const BinaryOperator *E);
Chris Lattnerb25a9432007-06-29 17:03:06 +0000378 RValue EmitMul(RValue LHS, RValue RHS, QualType EltTy);
379 RValue EmitDiv(RValue LHS, RValue RHS, QualType EltTy);
380 RValue EmitRem(RValue LHS, RValue RHS, QualType EltTy);
Chris Lattnercd215f02007-06-29 16:52:55 +0000381 RValue EmitAdd(RValue LHS, RValue RHS, QualType EltTy);
Chris Lattnerd2b88ab2007-07-13 03:05:23 +0000382 RValue EmitPointerAdd(RValue LHS, QualType LHSTy,
383 RValue RHS, QualType RHSTy, QualType EltTy);
Chris Lattnercd215f02007-06-29 16:52:55 +0000384 RValue EmitSub(RValue LHS, RValue RHS, QualType EltTy);
Chris Lattnerd2b88ab2007-07-13 03:05:23 +0000385 RValue EmitPointerSub(RValue LHS, QualType LHSTy,
386 RValue RHS, QualType RHSTy, QualType EltTy);
Chris Lattner47c247e2007-06-29 17:26:27 +0000387 RValue EmitShl(RValue LHS, RValue RHS, QualType ResTy);
388 RValue EmitShr(RValue LHS, RValue RHS, QualType ResTy);
Chris Lattner1fde0b32007-06-20 18:30:55 +0000389 RValue EmitBinaryCompare(const BinaryOperator *E, unsigned UICmpOpc,
390 unsigned SICmpOpc, unsigned FCmpOpc);
Chris Lattnerb25a9432007-06-29 17:03:06 +0000391 RValue EmitAnd(RValue LHS, RValue RHS, QualType EltTy);
392 RValue EmitOr (RValue LHS, RValue RHS, QualType EltTy);
393 RValue EmitXor(RValue LHS, RValue RHS, QualType EltTy);
Chris Lattner8394d792007-06-05 20:53:16 +0000394 RValue EmitBinaryLAnd(const BinaryOperator *E);
395 RValue EmitBinaryLOr(const BinaryOperator *E);
396
397 RValue EmitBinaryAssign(const BinaryOperator *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000398 RValue EmitBinaryComma(const BinaryOperator *E);
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000399
400 // Conditional Operator.
401 RValue EmitConditionalOperator(const ConditionalOperator *E);
Chris Lattner81a96882007-08-04 00:20:15 +0000402 RValue EmitChooseExpr(const ChooseExpr *E);
Chris Lattner6278e6a2007-08-11 00:04:45 +0000403
404 //===--------------------------------------------------------------------===//
405 // Aggregate Expression Emission
406 //===--------------------------------------------------------------------===//
407
408 void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
409 QualType EltTy);
410
411 /// EmitAggExpr - Emit the computation of the specified expression of
412 /// aggregate type. The result is computed into DestPtr. Note that if
413 /// DestPtr is null, the value of the aggregate expression is not needed.
414 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattnerbed31442007-05-28 01:07:47 +0000415};
416} // end namespace CodeGen
417} // end namespace clang
Chris Lattnerbed31442007-05-28 01:07:47 +0000418
419#endif