blob: e4bf09b15eac90c32cd7cca0932ae7e4c2b29026 [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;
Devang Patelda5d6bb2007-10-04 23:45:31 +000044 class CaseStmt;
45 class DefaultStmt;
46 class SwitchStmt;
47
Chris Lattner208ae962007-05-30 17:57:17 +000048 class Expr;
Chris Lattnerd7f58862007-06-02 05:24:33 +000049 class DeclRefExpr;
Chris Lattner4347e3692007-06-06 04:54:52 +000050 class StringLiteral;
Chris Lattner208ae962007-05-30 17:57:17 +000051 class IntegerLiteral;
Chris Lattner2ada32e2007-07-09 23:03:16 +000052 class FloatingLiteral;
Chris Lattner6e9d9b32007-07-13 05:18:11 +000053 class CharacterLiteral;
Chris Lattner40480052007-08-03 17:51:03 +000054 class TypesCompatibleExpr;
55
Chris Lattner76ba8492007-08-20 22:37:10 +000056 class ImplicitCastExpr;
Chris Lattner8394d792007-06-05 20:53:16 +000057 class CastExpr;
Chris Lattner2b228c92007-06-15 21:34:29 +000058 class CallExpr;
Chris Lattnerf0106d22007-06-02 19:33:17 +000059 class UnaryOperator;
Chris Lattnerdb91b162007-06-02 00:16:28 +000060 class BinaryOperator;
Chris Lattner9369a562007-06-29 16:31:29 +000061 class CompoundAssignOperator;
Chris Lattnerd9d2fb12007-06-08 23:31:14 +000062 class ArraySubscriptExpr;
Chris Lattnerd268a7a2007-08-03 17:31:20 +000063 class OCUVectorElementExpr;
Chris Lattner6e9d9b32007-07-13 05:18:11 +000064 class ConditionalOperator;
Chris Lattner81a96882007-08-04 00:20:15 +000065 class ChooseExpr;
Anders Carlsson625bfc82007-07-21 05:21:51 +000066 class PreDefinedExpr;
Anders Carlsson76f4a902007-08-21 17:43:55 +000067 class ObjCStringLiteral;
Devang Patel3e11cce2007-10-23 02:10:49 +000068 class MemberExpr;
69
Chris Lattner84915fa2007-06-02 04:16:21 +000070 class BlockVarDecl;
71 class EnumConstantDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000072 class ParmVarDecl;
Chris Lattnerbed31442007-05-28 01:07:47 +000073namespace CodeGen {
74 class CodeGenModule;
Devang Patel3e11cce2007-10-23 02:10:49 +000075 class CodeGenTypes;
Devang Patele11664a2007-11-01 19:11:01 +000076 class CGRecordLayout;
Chris Lattnerd7f58862007-06-02 05:24:33 +000077
Chris Lattner8394d792007-06-05 20:53:16 +000078/// RValue - This trivial value class is used to represent the result of an
Chris Lattner4647a212007-08-31 22:49:20 +000079/// expression that is evaluated. It can be one of three things: either a
80/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
81/// address of an aggregate value in memory.
Chris Lattner8394d792007-06-05 20:53:16 +000082class RValue {
Chris Lattner4647a212007-08-31 22:49:20 +000083 llvm::Value *V1, *V2;
Chris Lattnerdb91b162007-06-02 00:16:28 +000084 // TODO: Encode this into the low bit of pointer for more efficient
85 // return-by-value.
Chris Lattner4647a212007-08-31 22:49:20 +000086 enum { Scalar, Complex, Aggregate } Flavor;
Chris Lattner09153c02007-06-22 18:48:09 +000087
88 // FIXME: Aggregate rvalues need to retain information about whether they are
89 // volatile or not.
Chris Lattner5269c032007-05-30 21:03:58 +000090public:
91
Chris Lattner4647a212007-08-31 22:49:20 +000092 bool isScalar() const { return Flavor == Scalar; }
93 bool isComplex() const { return Flavor == Complex; }
94 bool isAggregate() const { return Flavor == Aggregate; }
Chris Lattner5269c032007-05-30 21:03:58 +000095
Chris Lattner4647a212007-08-31 22:49:20 +000096 /// getScalar() - Return the Value* of this scalar value.
97 llvm::Value *getScalarVal() const {
98 assert(isScalar() && "Not a scalar!");
99 return V1;
Chris Lattner5269c032007-05-30 21:03:58 +0000100 }
101
Chris Lattner4647a212007-08-31 22:49:20 +0000102 /// getComplexVal - Return the real/imag components of this complex value.
103 ///
104 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
105 return std::pair<llvm::Value *, llvm::Value *>(V1, V2);
106 }
107
Chris Lattner09153c02007-06-22 18:48:09 +0000108 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
109 llvm::Value *getAggregateAddr() const {
Chris Lattner5269c032007-05-30 21:03:58 +0000110 assert(isAggregate() && "Not an aggregate!");
Chris Lattner4647a212007-08-31 22:49:20 +0000111 return V1;
Chris Lattner5269c032007-05-30 21:03:58 +0000112 }
Chris Lattner208ae962007-05-30 17:57:17 +0000113
Chris Lattner23b7eb62007-06-15 23:05:46 +0000114 static RValue get(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +0000115 RValue ER;
Chris Lattner4647a212007-08-31 22:49:20 +0000116 ER.V1 = V;
117 ER.Flavor = Scalar;
118 return ER;
119 }
120 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
121 RValue ER;
122 ER.V1 = V1;
123 ER.V2 = V2;
124 ER.Flavor = Complex;
125 return ER;
126 }
127 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
128 RValue ER;
129 ER.V1 = C.first;
130 ER.V2 = C.second;
131 ER.Flavor = Complex;
Chris Lattner208ae962007-05-30 17:57:17 +0000132 return ER;
133 }
Chris Lattner23b7eb62007-06-15 23:05:46 +0000134 static RValue getAggregate(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +0000135 RValue ER;
Chris Lattner4647a212007-08-31 22:49:20 +0000136 ER.V1 = V;
137 ER.Flavor = Aggregate;
Chris Lattner208ae962007-05-30 17:57:17 +0000138 return ER;
139 }
140};
Chris Lattnerd7f58862007-06-02 05:24:33 +0000141
142
143/// LValue - This represents an lvalue references. Because C/C++ allow
144/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
145/// bitrange.
146class LValue {
147 // FIXME: Volatility. Restrict?
Chris Lattner8394d792007-06-05 20:53:16 +0000148 // alignment?
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000149
150 enum {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000151 Simple, // This is a normal l-value, use getAddress().
152 VectorElt, // This is a vector element l-value (V[i]), use getVector*
153 BitField, // This is a bitfield l-value, use getBitfield*.
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000154 OCUVectorElt // This is an ocu vector subset, use getOCUVectorComp
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000155 } LVType;
156
Chris Lattnerd7f58862007-06-02 05:24:33 +0000157 llvm::Value *V;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000158
159 union {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000160 llvm::Value *VectorIdx; // Index into a vector subscript: V[i]
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000161 unsigned VectorElts; // Encoded OCUVector element subset: V.xyx
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000162 };
Chris Lattnerd7f58862007-06-02 05:24:33 +0000163public:
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000164 bool isSimple() const { return LVType == Simple; }
165 bool isVectorElt() const { return LVType == VectorElt; }
166 bool isBitfield() const { return LVType == BitField; }
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000167 bool isOCUVectorElt() const { return LVType == OCUVectorElt; }
Chris Lattner208ae962007-05-30 17:57:17 +0000168
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000169 // simple lvalue
170 llvm::Value *getAddress() const { assert(isSimple()); return V; }
171 // vector elt lvalue
172 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
173 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000174 // ocu vector elements.
175 llvm::Value *getOCUVectorAddr() const { assert(isOCUVectorElt()); return V; }
176 unsigned getOCUVectorElts() const {
177 assert(isOCUVectorElt());
178 return VectorElts;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000179 }
180
Chris Lattnerd7f58862007-06-02 05:24:33 +0000181
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000182 static LValue MakeAddr(llvm::Value *V) {
Chris Lattnerd7f58862007-06-02 05:24:33 +0000183 LValue R;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000184 R.LVType = Simple;
Chris Lattnerd7f58862007-06-02 05:24:33 +0000185 R.V = V;
186 return R;
187 }
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000188
189 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx) {
190 LValue R;
191 R.LVType = VectorElt;
192 R.V = Vec;
193 R.VectorIdx = Idx;
194 return R;
195 }
196
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000197 static LValue MakeOCUVectorElt(llvm::Value *Vec, unsigned Elements) {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000198 LValue R;
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000199 R.LVType = OCUVectorElt;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000200 R.V = Vec;
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000201 R.VectorElts = Elements;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000202 return R;
203 }
Chris Lattnerd7f58862007-06-02 05:24:33 +0000204};
205
Chris Lattnerbed31442007-05-28 01:07:47 +0000206/// CodeGenFunction - This class organizes the per-function state that is used
207/// while generating LLVM code.
208class CodeGenFunction {
Chris Lattnerbda69f82007-08-26 23:13:56 +0000209public:
Chris Lattnerbed31442007-05-28 01:07:47 +0000210 CodeGenModule &CGM; // Per-module state.
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000211 TargetInfo &Target;
Chris Lattnerbda69f82007-08-26 23:13:56 +0000212
Chris Lattner96d72562007-08-21 16:57:55 +0000213 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Devang Patel7ad0c2f2007-10-09 19:49:58 +0000214 llvm::LLVMFoldingBuilder Builder;
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000215
216 const FunctionDecl *CurFuncDecl;
Chris Lattnerac248202007-05-30 00:13:02 +0000217 llvm::Function *CurFn;
218
Chris Lattner03df1222007-06-02 04:53:11 +0000219 /// AllocaInsertPoint - This is an instruction in the entry block before which
220 /// we prefer to insert allocas.
221 llvm::Instruction *AllocaInsertPt;
222
Chris Lattner6db1fb82007-06-02 22:49:07 +0000223 const llvm::Type *LLVMIntTy;
Hartmut Kaiser7078da82007-10-17 15:00:17 +0000224 uint32_t LLVMPointerWidth;
Chris Lattner6db1fb82007-06-02 22:49:07 +0000225
Chris Lattner2da04b32007-08-24 05:35:26 +0000226private:
Chris Lattner84915fa2007-06-02 04:16:21 +0000227 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
228 /// decls.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000229 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
Chris Lattner84915fa2007-06-02 04:16:21 +0000230
Chris Lattnerac248202007-05-30 00:13:02 +0000231 /// LabelMap - This keeps track of the LLVM basic block for each C label.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000232 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnere73e4322007-07-16 21:28:45 +0000233
234 // BreakContinueStack - This keeps track of where break and continue
235 // statements should jump to.
236 struct BreakContinue {
237 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
238 : BreakBlock(bb), ContinueBlock(cb) {}
239
240 llvm::BasicBlock *BreakBlock;
241 llvm::BasicBlock *ContinueBlock;
242 };
243 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
244
Devang Patel49a44f32007-10-09 17:08:50 +0000245 /// SwitchInsn - This is nearest current switch instruction. It is null if
246 /// if current context is not in a switch.
Devang Patelda5d6bb2007-10-04 23:45:31 +0000247 llvm::SwitchInst *SwitchInsn;
248
Devang Patel49a44f32007-10-09 17:08:50 +0000249 /// CaseRangeBlock - This block holds if condition check for last case
250 /// statement range in current switch instruction.
Devang Patel11663122007-10-08 20:57:48 +0000251 llvm::BasicBlock *CaseRangeBlock;
252
Chris Lattnerbed31442007-05-28 01:07:47 +0000253public:
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000254 CodeGenFunction(CodeGenModule &cgm);
Chris Lattnerbed31442007-05-28 01:07:47 +0000255
Chris Lattner6db1fb82007-06-02 22:49:07 +0000256 ASTContext &getContext() const;
257
Chris Lattner308f4312007-05-29 23:50:05 +0000258 void GenerateCode(const FunctionDecl *FD);
259
Chris Lattnerf033c142007-06-22 19:05:19 +0000260 const llvm::Type *ConvertType(QualType T);
Chris Lattnerac248202007-05-30 00:13:02 +0000261
Chris Lattner54fb19e2007-06-22 22:02:34 +0000262 /// hasAggregateLLVMType - Return true if the specified AST type will map into
263 /// an aggregate LLVM type or is void.
264 static bool hasAggregateLLVMType(QualType T);
265
Chris Lattnerac248202007-05-30 00:13:02 +0000266 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
267 /// label maps to.
268 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
269
270
Chris Lattner23b7eb62007-06-15 23:05:46 +0000271 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattner84915fa2007-06-02 04:16:21 +0000272
Chris Lattnere9a64532007-06-22 21:44:33 +0000273 //===--------------------------------------------------------------------===//
274 // Helpers
275 //===--------------------------------------------------------------------===//
276
277 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
278 /// block.
279 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
280 const char *Name = "tmp");
281
Chris Lattner8394d792007-06-05 20:53:16 +0000282 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
283 /// expression and compare the result against zero, returning an Int1Ty value.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000284 llvm::Value *EvaluateExprAsBool(const Expr *E);
Chris Lattnere9a64532007-06-22 21:44:33 +0000285
Chris Lattner4647a212007-08-31 22:49:20 +0000286 /// EmitAnyExpr - Emit code to compute the specified expression which can have
287 /// any type. The result is returned as an RValue struct. If this is an
288 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
289 /// the result should be returned.
290 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
291 bool isAggLocVolatile = false);
Devang Patel8ec4f832007-09-28 21:49:18 +0000292
293 /// isDummyBlock - Return true if BB is an empty basic block
294 /// with no predecessors.
295 static bool isDummyBlock(const llvm::BasicBlock *BB);
296
Devang Patelda5d6bb2007-10-04 23:45:31 +0000297 /// StartBlock - Start new block named N. If insert block is a dummy block
298 /// then reuse it.
299 void StartBlock(const char *N);
300
Devang Patele11664a2007-11-01 19:11:01 +0000301 /// getCGRecordLayout - Return record layout info.
302 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Chris Lattner8394d792007-06-05 20:53:16 +0000303 //===--------------------------------------------------------------------===//
Chris Lattner53621a52007-06-13 20:44:40 +0000304 // Declaration Emission
Chris Lattner84915fa2007-06-02 04:16:21 +0000305 //===--------------------------------------------------------------------===//
306
Chris Lattner1ad38f82007-06-09 01:20:56 +0000307 void EmitDecl(const Decl &D);
Chris Lattner84915fa2007-06-02 04:16:21 +0000308 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Chris Lattner03df1222007-06-02 04:53:11 +0000309 void EmitBlockVarDecl(const BlockVarDecl &D);
310 void EmitLocalBlockVarDecl(const BlockVarDecl &D);
Anders Carlssonf94cd1f2007-10-17 00:52:43 +0000311 void EmitStaticBlockVarDecl(const BlockVarDecl &D);
Chris Lattner53621a52007-06-13 20:44:40 +0000312 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
Chris Lattner03df1222007-06-02 04:53:11 +0000313
Chris Lattner84915fa2007-06-02 04:16:21 +0000314 //===--------------------------------------------------------------------===//
Chris Lattner308f4312007-05-29 23:50:05 +0000315 // Statement Emission
316 //===--------------------------------------------------------------------===//
317
318 void EmitStmt(const Stmt *S);
Chris Lattner4647a212007-08-31 22:49:20 +0000319 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
320 llvm::Value *AggLoc = 0, bool isAggVol = false);
Chris Lattnerac248202007-05-30 00:13:02 +0000321 void EmitLabelStmt(const LabelStmt &S);
322 void EmitGotoStmt(const GotoStmt &S);
Chris Lattner5269c032007-05-30 21:03:58 +0000323 void EmitIfStmt(const IfStmt &S);
Chris Lattner946aa312007-06-05 03:59:43 +0000324 void EmitWhileStmt(const WhileStmt &S);
Chris Lattner8394d792007-06-05 20:53:16 +0000325 void EmitDoStmt(const DoStmt &S);
326 void EmitForStmt(const ForStmt &S);
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000327 void EmitReturnStmt(const ReturnStmt &S);
Chris Lattner1ad38f82007-06-09 01:20:56 +0000328 void EmitDeclStmt(const DeclStmt &S);
Chris Lattnere73e4322007-07-16 21:28:45 +0000329 void EmitBreakStmt();
330 void EmitContinueStmt();
Devang Patelda5d6bb2007-10-04 23:45:31 +0000331 void EmitSwitchStmt(const SwitchStmt &S);
332 void EmitDefaultStmt(const DefaultStmt &S);
333 void EmitCaseStmt(const CaseStmt &S);
Devang Patel11663122007-10-08 20:57:48 +0000334 void EmitCaseStmtRange(const CaseStmt &S);
Devang Patelda5d6bb2007-10-04 23:45:31 +0000335
Chris Lattner208ae962007-05-30 17:57:17 +0000336 //===--------------------------------------------------------------------===//
Chris Lattnerd7f58862007-06-02 05:24:33 +0000337 // LValue Expression Emission
338 //===--------------------------------------------------------------------===//
Chris Lattner8394d792007-06-05 20:53:16 +0000339
340 /// EmitLValue - Emit code to compute a designator that specifies the location
341 /// of the expression.
342 ///
343 /// This can return one of two things: a simple address or a bitfield
344 /// reference. In either case, the LLVM Value* in the LValue structure is
345 /// guaranteed to be an LLVM pointer type.
346 ///
347 /// If this returns a bitfield reference, nothing about the pointee type of
348 /// the LLVM value is known: For example, it may not be a pointer to an
349 /// integer.
350 ///
351 /// If this returns a normal address, and if the lvalue's C type is fixed
352 /// size, this method guarantees that the returned pointer type will point to
353 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
354 /// variable length type, this is not possible.
355 ///
Chris Lattnerd7f58862007-06-02 05:24:33 +0000356 LValue EmitLValue(const Expr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000357
358 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
359 /// this method emits the address of the lvalue, then loads the result as an
360 /// rvalue, returning the rvalue.
Chris Lattner9369a562007-06-29 16:31:29 +0000361 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000362 RValue EmitLoadOfOCUElementLValue(LValue V, QualType LVType);
Chris Lattner9369a562007-06-29 16:31:29 +0000363
Chris Lattner40ff7012007-08-03 16:18:34 +0000364
Chris Lattner8394d792007-06-05 20:53:16 +0000365 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
366 /// lvalue, where both are guaranteed to the have the same type, and that type
367 /// is 'Ty'.
368 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Chris Lattner41d480e2007-08-03 16:28:33 +0000369 void EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, QualType Ty);
Chris Lattner8394d792007-06-05 20:53:16 +0000370
Chris Lattnerd7f58862007-06-02 05:24:33 +0000371 LValue EmitDeclRefLValue(const DeclRefExpr *E);
Chris Lattner4347e3692007-06-06 04:54:52 +0000372 LValue EmitStringLiteralLValue(const StringLiteral *E);
Anders Carlsson625bfc82007-07-21 05:21:51 +0000373 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000374 LValue EmitUnaryOpLValue(const UnaryOperator *E);
Chris Lattnerd9d2fb12007-06-08 23:31:14 +0000375 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000376 LValue EmitOCUVectorElementExpr(const OCUVectorElementExpr *E);
Devang Patel3e11cce2007-10-23 02:10:49 +0000377 LValue EmitMemberExpr(const MemberExpr *E);
Chris Lattnerd7f58862007-06-02 05:24:33 +0000378
379 //===--------------------------------------------------------------------===//
Chris Lattner6278e6a2007-08-11 00:04:45 +0000380 // Scalar Expression Emission
Chris Lattner208ae962007-05-30 17:57:17 +0000381 //===--------------------------------------------------------------------===//
382
Chris Lattner2b228c92007-06-15 21:34:29 +0000383 RValue EmitCallExpr(const CallExpr *E);
Chris Lattner9e47ead2007-08-31 04:44:06 +0000384 RValue EmitCallExpr(llvm::Value *Callee, const CallExpr *E);
Chris Lattner6c555f92007-08-26 22:58:05 +0000385 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000386
Chris Lattner2da04b32007-08-24 05:35:26 +0000387 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Anders Carlsson76f4a902007-08-21 17:43:55 +0000388
Chris Lattner6278e6a2007-08-11 00:04:45 +0000389 //===--------------------------------------------------------------------===//
Chris Lattnerbda69f82007-08-26 23:13:56 +0000390 // Expression Emission
Chris Lattner6278e6a2007-08-11 00:04:45 +0000391 //===--------------------------------------------------------------------===//
Chris Lattnerbda69f82007-08-26 23:13:56 +0000392
393 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattner6278e6a2007-08-11 00:04:45 +0000394
Chris Lattner2da04b32007-08-24 05:35:26 +0000395 /// EmitScalarExpr - Emit the computation of the specified expression of
396 /// LLVM scalar type, returning the result.
397 llvm::Value *EmitScalarExpr(const Expr *E);
398
Chris Lattner3474c202007-08-26 06:48:56 +0000399 /// EmitScalarConversion - Emit a conversion from the specified type to the
400 /// specified destination type, both of which are LLVM scalar types.
401 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
402 QualType DstTy);
403
Chris Lattner42e6b812007-08-26 16:34:22 +0000404 /// EmitComplexToScalarConversion - Emit a conversion from the specified
405 /// complex type to the specified destination type, where the destination
406 /// type is an LLVM scalar type.
407 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
408 QualType DstTy);
409
Chris Lattner3474c202007-08-26 06:48:56 +0000410
Chris Lattner6278e6a2007-08-11 00:04:45 +0000411 /// 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 Lattnercbfc73b2007-08-21 05:54:00 +0000415
416 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner08b15df2007-08-23 23:43:33 +0000417 /// complex type, returning the result.
Chris Lattner96d72562007-08-21 16:57:55 +0000418 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner08b15df2007-08-23 23:43:33 +0000419
420 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
421 /// of complex type, storing into the specified Value*.
Chris Lattnerb84bb952007-08-26 16:22:13 +0000422 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
423 bool DestIsVolatile);
Chris Lattner4647a212007-08-31 22:49:20 +0000424 /// LoadComplexFromAddr - Load a complex number from the specified address.
425 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Chris Lattnerbed31442007-05-28 01:07:47 +0000426};
427} // end namespace CodeGen
428} // end namespace clang
Chris Lattnerbed31442007-05-28 01:07:47 +0000429
430#endif