blob: 314896a874fba19d4694bdf8b05b274411e5a0a2 [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 Lattner8394d792007-06-05 20:53:16 +000053 class CastExpr;
Chris Lattner2b228c92007-06-15 21:34:29 +000054 class CallExpr;
Chris Lattnerf0106d22007-06-02 19:33:17 +000055 class UnaryOperator;
Chris Lattnerdb91b162007-06-02 00:16:28 +000056 class BinaryOperator;
Chris Lattner9369a562007-06-29 16:31:29 +000057 class CompoundAssignOperator;
Chris Lattnerd9d2fb12007-06-08 23:31:14 +000058 class ArraySubscriptExpr;
Chris Lattnerd268a7a2007-08-03 17:31:20 +000059 class OCUVectorElementExpr;
Chris Lattner6e9d9b32007-07-13 05:18:11 +000060 class ConditionalOperator;
Chris Lattner81a96882007-08-04 00:20:15 +000061 class ChooseExpr;
Anders Carlsson625bfc82007-07-21 05:21:51 +000062 class PreDefinedExpr;
Chris Lattner208ae962007-05-30 17:57:17 +000063
Chris Lattner84915fa2007-06-02 04:16:21 +000064 class BlockVarDecl;
65 class EnumConstantDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000066 class ParmVarDecl;
Chris Lattnerbed31442007-05-28 01:07:47 +000067namespace CodeGen {
68 class CodeGenModule;
69
Chris Lattnerd7f58862007-06-02 05:24:33 +000070
Chris Lattner8394d792007-06-05 20:53:16 +000071/// RValue - This trivial value class is used to represent the result of an
Chris Lattnerd7f58862007-06-02 05:24:33 +000072/// expression that is evaluated. It can be one of two things: either a simple
73/// LLVM SSA value, or the address of an aggregate value in memory. These two
74/// possibilities are discriminated by isAggregate/isScalar.
Chris Lattner8394d792007-06-05 20:53:16 +000075class RValue {
Chris Lattner23b7eb62007-06-15 23:05:46 +000076 llvm::Value *V;
Chris Lattnerdb91b162007-06-02 00:16:28 +000077 // TODO: Encode this into the low bit of pointer for more efficient
78 // return-by-value.
Chris Lattner5269c032007-05-30 21:03:58 +000079 bool IsAggregate;
Chris Lattner09153c02007-06-22 18:48:09 +000080
81 // FIXME: Aggregate rvalues need to retain information about whether they are
82 // volatile or not.
Chris Lattner5269c032007-05-30 21:03:58 +000083public:
84
85 bool isAggregate() const { return IsAggregate; }
86 bool isScalar() const { return !IsAggregate; }
87
88 /// getVal() - Return the Value* of this scalar value.
Chris Lattner23b7eb62007-06-15 23:05:46 +000089 llvm::Value *getVal() const {
Chris Lattner5269c032007-05-30 21:03:58 +000090 assert(!isAggregate() && "Not a scalar!");
91 return V;
92 }
93
Chris Lattner09153c02007-06-22 18:48:09 +000094 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
95 llvm::Value *getAggregateAddr() const {
Chris Lattner5269c032007-05-30 21:03:58 +000096 assert(isAggregate() && "Not an aggregate!");
97 return V;
98 }
Chris Lattner208ae962007-05-30 17:57:17 +000099
Chris Lattner23b7eb62007-06-15 23:05:46 +0000100 static RValue get(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +0000101 RValue ER;
Chris Lattner208ae962007-05-30 17:57:17 +0000102 ER.V = V;
Chris Lattner5269c032007-05-30 21:03:58 +0000103 ER.IsAggregate = false;
Chris Lattner208ae962007-05-30 17:57:17 +0000104 return ER;
105 }
Chris Lattner23b7eb62007-06-15 23:05:46 +0000106 static RValue getAggregate(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +0000107 RValue ER;
Chris Lattner208ae962007-05-30 17:57:17 +0000108 ER.V = V;
Chris Lattner5269c032007-05-30 21:03:58 +0000109 ER.IsAggregate = true;
Chris Lattner208ae962007-05-30 17:57:17 +0000110 return ER;
111 }
112};
Chris Lattnerd7f58862007-06-02 05:24:33 +0000113
114
115/// LValue - This represents an lvalue references. Because C/C++ allow
116/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
117/// bitrange.
118class LValue {
119 // FIXME: Volatility. Restrict?
Chris Lattner8394d792007-06-05 20:53:16 +0000120 // alignment?
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000121
122 enum {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000123 Simple, // This is a normal l-value, use getAddress().
124 VectorElt, // This is a vector element l-value (V[i]), use getVector*
125 BitField, // This is a bitfield l-value, use getBitfield*.
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000126 OCUVectorElt // This is an ocu vector subset, use getOCUVectorComp
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000127 } LVType;
128
Chris Lattnerd7f58862007-06-02 05:24:33 +0000129 llvm::Value *V;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000130
131 union {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000132 llvm::Value *VectorIdx; // Index into a vector subscript: V[i]
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000133 unsigned VectorElts; // Encoded OCUVector element subset: V.xyx
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000134 };
Chris Lattnerd7f58862007-06-02 05:24:33 +0000135public:
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000136 bool isSimple() const { return LVType == Simple; }
137 bool isVectorElt() const { return LVType == VectorElt; }
138 bool isBitfield() const { return LVType == BitField; }
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000139 bool isOCUVectorElt() const { return LVType == OCUVectorElt; }
Chris Lattner208ae962007-05-30 17:57:17 +0000140
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000141 // simple lvalue
142 llvm::Value *getAddress() const { assert(isSimple()); return V; }
143 // vector elt lvalue
144 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
145 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000146 // ocu vector elements.
147 llvm::Value *getOCUVectorAddr() const { assert(isOCUVectorElt()); return V; }
148 unsigned getOCUVectorElts() const {
149 assert(isOCUVectorElt());
150 return VectorElts;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000151 }
152
Chris Lattnerd7f58862007-06-02 05:24:33 +0000153
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000154 static LValue MakeAddr(llvm::Value *V) {
Chris Lattnerd7f58862007-06-02 05:24:33 +0000155 LValue R;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000156 R.LVType = Simple;
Chris Lattnerd7f58862007-06-02 05:24:33 +0000157 R.V = V;
158 return R;
159 }
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000160
161 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx) {
162 LValue R;
163 R.LVType = VectorElt;
164 R.V = Vec;
165 R.VectorIdx = Idx;
166 return R;
167 }
168
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000169 static LValue MakeOCUVectorElt(llvm::Value *Vec, unsigned Elements) {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000170 LValue R;
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000171 R.LVType = OCUVectorElt;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000172 R.V = Vec;
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000173 R.VectorElts = Elements;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000174 return R;
175 }
Chris Lattnerd7f58862007-06-02 05:24:33 +0000176};
177
Chris Lattnerbed31442007-05-28 01:07:47 +0000178/// CodeGenFunction - This class organizes the per-function state that is used
179/// while generating LLVM code.
180class CodeGenFunction {
181 CodeGenModule &CGM; // Per-module state.
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000182 TargetInfo &Target;
Chris Lattner23b7eb62007-06-15 23:05:46 +0000183 llvm::LLVMBuilder Builder;
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000184
185 const FunctionDecl *CurFuncDecl;
Chris Lattnerac248202007-05-30 00:13:02 +0000186 llvm::Function *CurFn;
187
Chris Lattner03df1222007-06-02 04:53:11 +0000188 /// AllocaInsertPoint - This is an instruction in the entry block before which
189 /// we prefer to insert allocas.
190 llvm::Instruction *AllocaInsertPt;
191
Chris Lattner6db1fb82007-06-02 22:49:07 +0000192 const llvm::Type *LLVMIntTy;
Chris Lattnerd9d2fb12007-06-08 23:31:14 +0000193 unsigned LLVMPointerWidth;
Chris Lattner6db1fb82007-06-02 22:49:07 +0000194
Chris Lattner84915fa2007-06-02 04:16:21 +0000195 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
196 /// decls.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000197 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
Chris Lattner84915fa2007-06-02 04:16:21 +0000198
Chris Lattnerac248202007-05-30 00:13:02 +0000199 /// LabelMap - This keeps track of the LLVM basic block for each C label.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000200 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnere73e4322007-07-16 21:28:45 +0000201
202 // BreakContinueStack - This keeps track of where break and continue
203 // statements should jump to.
204 struct BreakContinue {
205 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
206 : BreakBlock(bb), ContinueBlock(cb) {}
207
208 llvm::BasicBlock *BreakBlock;
209 llvm::BasicBlock *ContinueBlock;
210 };
211 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
212
Chris Lattnerbed31442007-05-28 01:07:47 +0000213public:
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000214 CodeGenFunction(CodeGenModule &cgm);
Chris Lattnerbed31442007-05-28 01:07:47 +0000215
Chris Lattner6db1fb82007-06-02 22:49:07 +0000216 ASTContext &getContext() const;
217
Chris Lattner308f4312007-05-29 23:50:05 +0000218 void GenerateCode(const FunctionDecl *FD);
219
Chris Lattnerf033c142007-06-22 19:05:19 +0000220 const llvm::Type *ConvertType(QualType T);
Chris Lattnerac248202007-05-30 00:13:02 +0000221
Chris Lattner54fb19e2007-06-22 22:02:34 +0000222 /// hasAggregateLLVMType - Return true if the specified AST type will map into
223 /// an aggregate LLVM type or is void.
224 static bool hasAggregateLLVMType(QualType T);
225
Chris Lattnerac248202007-05-30 00:13:02 +0000226 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
227 /// label maps to.
228 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
229
230
Chris Lattner23b7eb62007-06-15 23:05:46 +0000231 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattner84915fa2007-06-02 04:16:21 +0000232
Chris Lattnere9a64532007-06-22 21:44:33 +0000233 //===--------------------------------------------------------------------===//
234 // Helpers
235 //===--------------------------------------------------------------------===//
236
237 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
238 /// block.
239 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
240 const char *Name = "tmp");
241
Chris Lattner8394d792007-06-05 20:53:16 +0000242 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
243 /// expression and compare the result against zero, returning an Int1Ty value.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000244 llvm::Value *EvaluateExprAsBool(const Expr *E);
Chris Lattnere9a64532007-06-22 21:44:33 +0000245
Chris Lattnerac248202007-05-30 00:13:02 +0000246
Chris Lattnere9a64532007-06-22 21:44:33 +0000247 /// EmitLoadOfComplex - Given an RValue reference for a complex, emit code to
248 /// load the real and imaginary pieces, returning them as Real/Imag.
249 void EmitLoadOfComplex(RValue V, llvm::Value *&Real, llvm::Value *&Imag);
250
251 /// EmitStoreOfComplex - Store the specified real/imag parts into the
252 /// specified value pointer.
253 void EmitStoreOfComplex(llvm::Value *Real, llvm::Value *Imag,
254 llvm::Value *ResPtr);
255
Chris Lattner8394d792007-06-05 20:53:16 +0000256 //===--------------------------------------------------------------------===//
257 // Conversions
258 //===--------------------------------------------------------------------===//
259
260 /// EmitConversion - Convert the value specied by Val, whose type is ValTy, to
261 /// the type specified by DstTy, following the rules of C99 6.3.
Chris Lattnerf033c142007-06-22 19:05:19 +0000262 RValue EmitConversion(RValue Val, QualType ValTy, QualType DstTy);
Chris Lattner8394d792007-06-05 20:53:16 +0000263
264 /// ConvertScalarValueToBool - Convert the specified expression value to a
Chris Lattnerf0106d22007-06-02 19:33:17 +0000265 /// boolean (i1) truth value. This is equivalent to "Val == 0".
Chris Lattner23b7eb62007-06-15 23:05:46 +0000266 llvm::Value *ConvertScalarValueToBool(RValue Val, QualType Ty);
Chris Lattnerf0106d22007-06-02 19:33:17 +0000267
Chris Lattner308f4312007-05-29 23:50:05 +0000268 //===--------------------------------------------------------------------===//
Chris Lattner53621a52007-06-13 20:44:40 +0000269 // Declaration Emission
Chris Lattner84915fa2007-06-02 04:16:21 +0000270 //===--------------------------------------------------------------------===//
271
Chris Lattner1ad38f82007-06-09 01:20:56 +0000272 void EmitDecl(const Decl &D);
Chris Lattner84915fa2007-06-02 04:16:21 +0000273 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Chris Lattner03df1222007-06-02 04:53:11 +0000274 void EmitBlockVarDecl(const BlockVarDecl &D);
275 void EmitLocalBlockVarDecl(const BlockVarDecl &D);
Chris Lattner53621a52007-06-13 20:44:40 +0000276 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
Chris Lattner03df1222007-06-02 04:53:11 +0000277
Chris Lattner84915fa2007-06-02 04:16:21 +0000278 //===--------------------------------------------------------------------===//
Chris Lattner308f4312007-05-29 23:50:05 +0000279 // Statement Emission
280 //===--------------------------------------------------------------------===//
281
282 void EmitStmt(const Stmt *S);
283 void EmitCompoundStmt(const CompoundStmt &S);
Chris Lattnerac248202007-05-30 00:13:02 +0000284 void EmitLabelStmt(const LabelStmt &S);
285 void EmitGotoStmt(const GotoStmt &S);
Chris Lattner5269c032007-05-30 21:03:58 +0000286 void EmitIfStmt(const IfStmt &S);
Chris Lattner946aa312007-06-05 03:59:43 +0000287 void EmitWhileStmt(const WhileStmt &S);
Chris Lattner8394d792007-06-05 20:53:16 +0000288 void EmitDoStmt(const DoStmt &S);
289 void EmitForStmt(const ForStmt &S);
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000290 void EmitReturnStmt(const ReturnStmt &S);
Chris Lattner1ad38f82007-06-09 01:20:56 +0000291 void EmitDeclStmt(const DeclStmt &S);
Chris Lattnere73e4322007-07-16 21:28:45 +0000292 void EmitBreakStmt();
293 void EmitContinueStmt();
294
Chris Lattner208ae962007-05-30 17:57:17 +0000295 //===--------------------------------------------------------------------===//
Chris Lattnerd7f58862007-06-02 05:24:33 +0000296 // LValue Expression Emission
297 //===--------------------------------------------------------------------===//
Chris Lattner8394d792007-06-05 20:53:16 +0000298
299 /// EmitLValue - Emit code to compute a designator that specifies the location
300 /// of the expression.
301 ///
302 /// This can return one of two things: a simple address or a bitfield
303 /// reference. In either case, the LLVM Value* in the LValue structure is
304 /// guaranteed to be an LLVM pointer type.
305 ///
306 /// If this returns a bitfield reference, nothing about the pointee type of
307 /// the LLVM value is known: For example, it may not be a pointer to an
308 /// integer.
309 ///
310 /// If this returns a normal address, and if the lvalue's C type is fixed
311 /// size, this method guarantees that the returned pointer type will point to
312 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
313 /// variable length type, this is not possible.
314 ///
Chris Lattnerd7f58862007-06-02 05:24:33 +0000315 LValue EmitLValue(const Expr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000316
317 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
318 /// this method emits the address of the lvalue, then loads the result as an
319 /// rvalue, returning the rvalue.
320 RValue EmitLoadOfLValue(const Expr *E);
Chris Lattner9369a562007-06-29 16:31:29 +0000321 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000322 RValue EmitLoadOfOCUElementLValue(LValue V, QualType LVType);
Chris Lattner9369a562007-06-29 16:31:29 +0000323
Chris Lattner40ff7012007-08-03 16:18:34 +0000324
Chris Lattner8394d792007-06-05 20:53:16 +0000325 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
326 /// lvalue, where both are guaranteed to the have the same type, and that type
327 /// is 'Ty'.
328 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Chris Lattner41d480e2007-08-03 16:28:33 +0000329 void EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, QualType Ty);
Chris Lattner8394d792007-06-05 20:53:16 +0000330
Chris Lattnerd7f58862007-06-02 05:24:33 +0000331 LValue EmitDeclRefLValue(const DeclRefExpr *E);
Chris Lattner4347e3692007-06-06 04:54:52 +0000332 LValue EmitStringLiteralLValue(const StringLiteral *E);
Anders Carlsson625bfc82007-07-21 05:21:51 +0000333 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000334 LValue EmitUnaryOpLValue(const UnaryOperator *E);
Chris Lattnerd9d2fb12007-06-08 23:31:14 +0000335 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000336 LValue EmitOCUVectorElementExpr(const OCUVectorElementExpr *E);
Chris Lattnerd7f58862007-06-02 05:24:33 +0000337
338 //===--------------------------------------------------------------------===//
Chris Lattner6278e6a2007-08-11 00:04:45 +0000339 // Scalar Expression Emission
Chris Lattner208ae962007-05-30 17:57:17 +0000340 //===--------------------------------------------------------------------===//
341
Chris Lattnercd215f02007-06-29 16:52:55 +0000342 void EmitCompoundAssignmentOperands(const CompoundAssignOperator *CAO,
343 LValue &LHSLV, RValue &LHS, RValue &RHS);
344 RValue EmitCompoundAssignmentResult(const CompoundAssignOperator *E,
345 LValue LHSLV, RValue ResV);
346
Chris Lattner8394d792007-06-05 20:53:16 +0000347 RValue EmitExpr(const Expr *E);
348 RValue EmitIntegerLiteral(const IntegerLiteral *E);
Chris Lattner2ada32e2007-07-09 23:03:16 +0000349 RValue EmitFloatingLiteral(const FloatingLiteral *E);
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000350 RValue EmitCharacterLiteral(const CharacterLiteral *E);
Chris Lattner40480052007-08-03 17:51:03 +0000351 RValue EmitTypesCompatibleExpr(const TypesCompatibleExpr *E);
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000352
Chris Lattner388cf762007-07-13 20:25:53 +0000353 RValue EmitCastExpr(const Expr *Op, QualType DestTy);
Chris Lattner2b228c92007-06-15 21:34:29 +0000354 RValue EmitCallExpr(const CallExpr *E);
Chris Lattnera779b3d2007-07-10 21:58:36 +0000355 RValue EmitArraySubscriptExprRV(const ArraySubscriptExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000356
Chris Lattnerf0106d22007-06-02 19:33:17 +0000357 // Unary Operators.
Chris Lattner8394d792007-06-05 20:53:16 +0000358 RValue EmitUnaryOperator(const UnaryOperator *E);
Chris Lattnerdcca4872007-07-11 23:43:46 +0000359 RValue EmitUnaryIncDec (const UnaryOperator *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000360 RValue EmitUnaryAddrOf (const UnaryOperator *E);
361 RValue EmitUnaryPlus (const UnaryOperator *E);
362 RValue EmitUnaryMinus (const UnaryOperator *E);
363 RValue EmitUnaryNot (const UnaryOperator *E);
364 RValue EmitUnaryLNot (const UnaryOperator *E);
Chris Lattner3f8c6e62007-07-18 18:12:07 +0000365 RValue EmitSizeAlignOf (QualType TypeToSize, QualType RetType,bool isSizeOf);
Chris Lattner8394d792007-06-05 20:53:16 +0000366 // FIXME: real/imag
Chris Lattnerf0106d22007-06-02 19:33:17 +0000367
Chris Lattnerdb91b162007-06-02 00:16:28 +0000368 // Binary Operators.
Chris Lattner8394d792007-06-05 20:53:16 +0000369 RValue EmitBinaryOperator(const BinaryOperator *E);
370 RValue EmitBinaryMul(const BinaryOperator *E);
371 RValue EmitBinaryDiv(const BinaryOperator *E);
372 RValue EmitBinaryRem(const BinaryOperator *E);
Chris Lattnerb25a9432007-06-29 17:03:06 +0000373 RValue EmitMul(RValue LHS, RValue RHS, QualType EltTy);
374 RValue EmitDiv(RValue LHS, RValue RHS, QualType EltTy);
375 RValue EmitRem(RValue LHS, RValue RHS, QualType EltTy);
Chris Lattnercd215f02007-06-29 16:52:55 +0000376 RValue EmitAdd(RValue LHS, RValue RHS, QualType EltTy);
Chris Lattnerd2b88ab2007-07-13 03:05:23 +0000377 RValue EmitPointerAdd(RValue LHS, QualType LHSTy,
378 RValue RHS, QualType RHSTy, QualType EltTy);
Chris Lattnercd215f02007-06-29 16:52:55 +0000379 RValue EmitSub(RValue LHS, RValue RHS, QualType EltTy);
Chris Lattnerd2b88ab2007-07-13 03:05:23 +0000380 RValue EmitPointerSub(RValue LHS, QualType LHSTy,
381 RValue RHS, QualType RHSTy, QualType EltTy);
Chris Lattner47c247e2007-06-29 17:26:27 +0000382 RValue EmitShl(RValue LHS, RValue RHS, QualType ResTy);
383 RValue EmitShr(RValue LHS, RValue RHS, QualType ResTy);
Chris Lattner1fde0b32007-06-20 18:30:55 +0000384 RValue EmitBinaryCompare(const BinaryOperator *E, unsigned UICmpOpc,
385 unsigned SICmpOpc, unsigned FCmpOpc);
Chris Lattnerb25a9432007-06-29 17:03:06 +0000386 RValue EmitAnd(RValue LHS, RValue RHS, QualType EltTy);
387 RValue EmitOr (RValue LHS, RValue RHS, QualType EltTy);
388 RValue EmitXor(RValue LHS, RValue RHS, QualType EltTy);
Chris Lattner8394d792007-06-05 20:53:16 +0000389 RValue EmitBinaryLAnd(const BinaryOperator *E);
390 RValue EmitBinaryLOr(const BinaryOperator *E);
391
392 RValue EmitBinaryAssign(const BinaryOperator *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000393 RValue EmitBinaryComma(const BinaryOperator *E);
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000394
395 // Conditional Operator.
396 RValue EmitConditionalOperator(const ConditionalOperator *E);
Chris Lattner81a96882007-08-04 00:20:15 +0000397 RValue EmitChooseExpr(const ChooseExpr *E);
Chris Lattner6278e6a2007-08-11 00:04:45 +0000398
399 //===--------------------------------------------------------------------===//
400 // Aggregate Expression Emission
401 //===--------------------------------------------------------------------===//
402
403 void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
404 QualType EltTy);
405
406 /// EmitAggExpr - Emit the computation of the specified expression of
407 /// aggregate type. The result is computed into DestPtr. Note that if
408 /// DestPtr is null, the value of the aggregate expression is not needed.
409 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
410
411 /// EmitAggLoadOfLValue - Given an expression with aggregate type that
412 /// represents a value lvalue, this method emits the address of the lvalue,
413 /// then loads the result into DestPtr.
414 void EmitAggLoadOfLValue(const Expr *E, llvm::Value *DestPtr, bool VolDest);
415
416
417
418 // Binary Operators.
419 void EmitAggBinaryOperator(const BinaryOperator *E,
420 llvm::Value *DestPtr, bool VolatileDest);
421
422
423 void EmitAggBinaryAssign(const BinaryOperator *E, llvm::Value *DestPtr,
424 bool VolatileDest);
425
426 void EmitAggConditionalOperator(const ConditionalOperator *E,
427 llvm::Value *DestPtr, bool VolatileDest);
Chris Lattnerbed31442007-05-28 01:07:47 +0000428};
429} // end namespace CodeGen
430} // end namespace clang
Chris Lattnerbed31442007-05-28 01:07:47 +0000431
432#endif