blob: 509e8296d20cdadca15f7aef3771c694bf80e255 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This is the internal per-function state used for llvm translation.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattneref52a2f2008-02-29 17:10:38 +000014#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
15#define CLANG_CODEGEN_CODEGENFUNCTION_H
Reid Spencer5f016e22007-07-11 17:01:13 +000016
17#include "llvm/ADT/DenseMap.h"
Chris Lattnerda138702007-07-16 21:28:45 +000018#include "llvm/ADT/SmallVector.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000019#include "llvm/Support/LLVMBuilder.h"
20#include <vector>
21
22namespace llvm {
23 class Module;
24}
25
26namespace clang {
27 class ASTContext;
28 class Decl;
29 class FunctionDecl;
30 class TargetInfo;
31 class QualType;
32 class FunctionTypeProto;
33
34 class Stmt;
35 class CompoundStmt;
36 class LabelStmt;
37 class GotoStmt;
38 class IfStmt;
39 class WhileStmt;
40 class DoStmt;
41 class ForStmt;
42 class ReturnStmt;
43 class DeclStmt;
Devang Patel51b09f22007-10-04 23:45:31 +000044 class CaseStmt;
45 class DefaultStmt;
46 class SwitchStmt;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000047 class AsmStmt;
48
Reid Spencer5f016e22007-07-11 17:01:13 +000049 class Expr;
50 class DeclRefExpr;
51 class StringLiteral;
52 class IntegerLiteral;
53 class FloatingLiteral;
Chris Lattnerb0a721a2007-07-13 05:18:11 +000054 class CharacterLiteral;
Chris Lattner30bf3ae2007-08-03 17:51:03 +000055 class TypesCompatibleExpr;
56
Chris Lattner7016a702007-08-20 22:37:10 +000057 class ImplicitCastExpr;
Reid Spencer5f016e22007-07-11 17:01:13 +000058 class CastExpr;
59 class CallExpr;
60 class UnaryOperator;
61 class BinaryOperator;
62 class CompoundAssignOperator;
63 class ArraySubscriptExpr;
Chris Lattner6481a572007-08-03 17:31:20 +000064 class OCUVectorElementExpr;
Chris Lattnerb0a721a2007-07-13 05:18:11 +000065 class ConditionalOperator;
Chris Lattner94f05e32007-08-04 00:20:15 +000066 class ChooseExpr;
Anders Carlsson22742662007-07-21 05:21:51 +000067 class PreDefinedExpr;
Anders Carlsson55085182007-08-21 17:43:55 +000068 class ObjCStringLiteral;
Devang Patelb84a06e2007-10-23 02:10:49 +000069 class MemberExpr;
70
Reid Spencer5f016e22007-07-11 17:01:13 +000071 class BlockVarDecl;
72 class EnumConstantDecl;
73 class ParmVarDecl;
Eli Friedman472778e2008-02-09 08:50:58 +000074 class FieldDecl;
Reid Spencer5f016e22007-07-11 17:01:13 +000075namespace CodeGen {
76 class CodeGenModule;
Devang Patelb84a06e2007-10-23 02:10:49 +000077 class CodeGenTypes;
Devang Patel88a981b2007-11-01 19:11:01 +000078 class CGRecordLayout;
Reid Spencer5f016e22007-07-11 17:01:13 +000079
80/// RValue - This trivial value class is used to represent the result of an
Chris Lattner9b655512007-08-31 22:49:20 +000081/// expression that is evaluated. It can be one of three things: either a
82/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
83/// address of an aggregate value in memory.
Reid Spencer5f016e22007-07-11 17:01:13 +000084class RValue {
Chris Lattner9b655512007-08-31 22:49:20 +000085 llvm::Value *V1, *V2;
Reid Spencer5f016e22007-07-11 17:01:13 +000086 // TODO: Encode this into the low bit of pointer for more efficient
87 // return-by-value.
Chris Lattner9b655512007-08-31 22:49:20 +000088 enum { Scalar, Complex, Aggregate } Flavor;
Reid Spencer5f016e22007-07-11 17:01:13 +000089
90 // FIXME: Aggregate rvalues need to retain information about whether they are
91 // volatile or not.
92public:
93
Chris Lattner9b655512007-08-31 22:49:20 +000094 bool isScalar() const { return Flavor == Scalar; }
95 bool isComplex() const { return Flavor == Complex; }
96 bool isAggregate() const { return Flavor == Aggregate; }
Reid Spencer5f016e22007-07-11 17:01:13 +000097
Chris Lattner9b655512007-08-31 22:49:20 +000098 /// getScalar() - Return the Value* of this scalar value.
99 llvm::Value *getScalarVal() const {
100 assert(isScalar() && "Not a scalar!");
101 return V1;
Reid Spencer5f016e22007-07-11 17:01:13 +0000102 }
103
Chris Lattner9b655512007-08-31 22:49:20 +0000104 /// getComplexVal - Return the real/imag components of this complex value.
105 ///
106 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
107 return std::pair<llvm::Value *, llvm::Value *>(V1, V2);
108 }
109
Reid Spencer5f016e22007-07-11 17:01:13 +0000110 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
111 llvm::Value *getAggregateAddr() const {
112 assert(isAggregate() && "Not an aggregate!");
Chris Lattner9b655512007-08-31 22:49:20 +0000113 return V1;
Reid Spencer5f016e22007-07-11 17:01:13 +0000114 }
115
116 static RValue get(llvm::Value *V) {
117 RValue ER;
Chris Lattner9b655512007-08-31 22:49:20 +0000118 ER.V1 = V;
119 ER.Flavor = Scalar;
120 return ER;
121 }
122 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
123 RValue ER;
124 ER.V1 = V1;
125 ER.V2 = V2;
126 ER.Flavor = Complex;
127 return ER;
128 }
129 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
130 RValue ER;
131 ER.V1 = C.first;
132 ER.V2 = C.second;
133 ER.Flavor = Complex;
Reid Spencer5f016e22007-07-11 17:01:13 +0000134 return ER;
135 }
136 static RValue getAggregate(llvm::Value *V) {
137 RValue ER;
Chris Lattner9b655512007-08-31 22:49:20 +0000138 ER.V1 = V;
139 ER.Flavor = Aggregate;
Reid Spencer5f016e22007-07-11 17:01:13 +0000140 return ER;
141 }
142};
143
144
145/// LValue - This represents an lvalue references. Because C/C++ allow
146/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
147/// bitrange.
148class LValue {
149 // FIXME: Volatility. Restrict?
150 // alignment?
151
152 enum {
Chris Lattner349aaec2007-08-02 23:37:31 +0000153 Simple, // This is a normal l-value, use getAddress().
154 VectorElt, // This is a vector element l-value (V[i]), use getVector*
155 BitField, // This is a bitfield l-value, use getBitfield*.
Chris Lattner6481a572007-08-03 17:31:20 +0000156 OCUVectorElt // This is an ocu vector subset, use getOCUVectorComp
Reid Spencer5f016e22007-07-11 17:01:13 +0000157 } LVType;
158
159 llvm::Value *V;
160
161 union {
Chris Lattner349aaec2007-08-02 23:37:31 +0000162 llvm::Value *VectorIdx; // Index into a vector subscript: V[i]
Chris Lattner6481a572007-08-03 17:31:20 +0000163 unsigned VectorElts; // Encoded OCUVector element subset: V.xyx
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000164 struct {
165 unsigned short StartBit;
166 unsigned short Size;
167 bool IsSigned;
168 } BitfieldData; // BitField start bit and size
Reid Spencer5f016e22007-07-11 17:01:13 +0000169 };
170public:
171 bool isSimple() const { return LVType == Simple; }
172 bool isVectorElt() const { return LVType == VectorElt; }
173 bool isBitfield() const { return LVType == BitField; }
Chris Lattner6481a572007-08-03 17:31:20 +0000174 bool isOCUVectorElt() const { return LVType == OCUVectorElt; }
Reid Spencer5f016e22007-07-11 17:01:13 +0000175
176 // simple lvalue
177 llvm::Value *getAddress() const { assert(isSimple()); return V; }
178 // vector elt lvalue
179 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
180 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Chris Lattner6481a572007-08-03 17:31:20 +0000181 // ocu vector elements.
182 llvm::Value *getOCUVectorAddr() const { assert(isOCUVectorElt()); return V; }
183 unsigned getOCUVectorElts() const {
184 assert(isOCUVectorElt());
185 return VectorElts;
Chris Lattner349aaec2007-08-02 23:37:31 +0000186 }
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000187 // bitfield lvalue
188 llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; }
189 unsigned short getBitfieldStartBit() const {
190 assert(isBitfield());
191 return BitfieldData.StartBit;
192 }
193 unsigned short getBitfieldSize() const {
194 assert(isBitfield());
195 return BitfieldData.Size;
196 }
197 bool isBitfieldSigned() const {
198 assert(isBitfield());
199 return BitfieldData.IsSigned;
200 }
201
Reid Spencer5f016e22007-07-11 17:01:13 +0000202 static LValue MakeAddr(llvm::Value *V) {
203 LValue R;
204 R.LVType = Simple;
205 R.V = V;
206 return R;
207 }
208
209 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx) {
210 LValue R;
211 R.LVType = VectorElt;
212 R.V = Vec;
213 R.VectorIdx = Idx;
214 return R;
215 }
216
Chris Lattner6481a572007-08-03 17:31:20 +0000217 static LValue MakeOCUVectorElt(llvm::Value *Vec, unsigned Elements) {
Chris Lattner349aaec2007-08-02 23:37:31 +0000218 LValue R;
Chris Lattner6481a572007-08-03 17:31:20 +0000219 R.LVType = OCUVectorElt;
Chris Lattner349aaec2007-08-02 23:37:31 +0000220 R.V = Vec;
Chris Lattner6481a572007-08-03 17:31:20 +0000221 R.VectorElts = Elements;
Chris Lattner349aaec2007-08-02 23:37:31 +0000222 return R;
223 }
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000224
225 static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
226 unsigned short Size, bool IsSigned) {
227 LValue R;
228 R.LVType = BitField;
229 R.V = V;
230 R.BitfieldData.StartBit = StartBit;
231 R.BitfieldData.Size = Size;
232 R.BitfieldData.IsSigned = IsSigned;
233 return R;
234 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000235};
236
237/// CodeGenFunction - This class organizes the per-function state that is used
238/// while generating LLVM code.
239class CodeGenFunction {
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000240public:
Reid Spencer5f016e22007-07-11 17:01:13 +0000241 CodeGenModule &CGM; // Per-module state.
242 TargetInfo &Target;
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000243
Chris Lattner58dee102007-08-21 16:57:55 +0000244 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Devang Patel50c90342007-10-09 19:49:58 +0000245 llvm::LLVMFoldingBuilder Builder;
Reid Spencer5f016e22007-07-11 17:01:13 +0000246
247 const FunctionDecl *CurFuncDecl;
248 llvm::Function *CurFn;
249
250 /// AllocaInsertPoint - This is an instruction in the entry block before which
251 /// we prefer to insert allocas.
252 llvm::Instruction *AllocaInsertPt;
253
254 const llvm::Type *LLVMIntTy;
Hartmut Kaiser7b660002007-10-17 15:00:17 +0000255 uint32_t LLVMPointerWidth;
Reid Spencer5f016e22007-07-11 17:01:13 +0000256
Chris Lattner7f02f722007-08-24 05:35:26 +0000257private:
Reid Spencer5f016e22007-07-11 17:01:13 +0000258 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
259 /// decls.
260 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
261
262 /// LabelMap - This keeps track of the LLVM basic block for each C label.
263 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnerda138702007-07-16 21:28:45 +0000264
265 // BreakContinueStack - This keeps track of where break and continue
266 // statements should jump to.
267 struct BreakContinue {
268 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
269 : BreakBlock(bb), ContinueBlock(cb) {}
270
271 llvm::BasicBlock *BreakBlock;
272 llvm::BasicBlock *ContinueBlock;
273 };
274 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
275
Devang Patel80fd5f92007-10-09 17:08:50 +0000276 /// SwitchInsn - This is nearest current switch instruction. It is null if
277 /// if current context is not in a switch.
Devang Patel51b09f22007-10-04 23:45:31 +0000278 llvm::SwitchInst *SwitchInsn;
279
Devang Patel80fd5f92007-10-09 17:08:50 +0000280 /// CaseRangeBlock - This block holds if condition check for last case
281 /// statement range in current switch instruction.
Devang Patelc049e4f2007-10-08 20:57:48 +0000282 llvm::BasicBlock *CaseRangeBlock;
283
Reid Spencer5f016e22007-07-11 17:01:13 +0000284public:
285 CodeGenFunction(CodeGenModule &cgm);
286
287 ASTContext &getContext() const;
288
289 void GenerateCode(const FunctionDecl *FD);
290
291 const llvm::Type *ConvertType(QualType T);
292
293 /// hasAggregateLLVMType - Return true if the specified AST type will map into
294 /// an aggregate LLVM type or is void.
295 static bool hasAggregateLLVMType(QualType T);
296
297 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
298 /// label maps to.
299 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
300
301
302 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattnerdc5e8262007-12-02 01:43:38 +0000303
304 /// WarnUnsupported - Print out a warning that codegen doesn't support the
305 /// specified stmt yet.
Chris Lattnerdc4d2802007-12-02 01:49:16 +0000306 void WarnUnsupported(const Stmt *S, const char *Type);
Reid Spencer5f016e22007-07-11 17:01:13 +0000307
308 //===--------------------------------------------------------------------===//
309 // Helpers
310 //===--------------------------------------------------------------------===//
311
312 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
313 /// block.
314 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
315 const char *Name = "tmp");
316
317 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
318 /// expression and compare the result against zero, returning an Int1Ty value.
319 llvm::Value *EvaluateExprAsBool(const Expr *E);
320
Chris Lattner9b655512007-08-31 22:49:20 +0000321 /// EmitAnyExpr - Emit code to compute the specified expression which can have
322 /// any type. The result is returned as an RValue struct. If this is an
323 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
324 /// the result should be returned.
325 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
326 bool isAggLocVolatile = false);
Devang Pateld9363c32007-09-28 21:49:18 +0000327
328 /// isDummyBlock - Return true if BB is an empty basic block
329 /// with no predecessors.
330 static bool isDummyBlock(const llvm::BasicBlock *BB);
331
Devang Patel51b09f22007-10-04 23:45:31 +0000332 /// StartBlock - Start new block named N. If insert block is a dummy block
333 /// then reuse it.
334 void StartBlock(const char *N);
335
Devang Patel88a981b2007-11-01 19:11:01 +0000336 /// getCGRecordLayout - Return record layout info.
337 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Lauro Ramos Venancio81373352008-02-26 21:41:45 +0000338
339 /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
340 llvm::Constant *GetAddrOfStaticLocalVar(const BlockVarDecl *BVD);
Reid Spencer5f016e22007-07-11 17:01:13 +0000341 //===--------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +0000342 // Declaration Emission
343 //===--------------------------------------------------------------------===//
344
345 void EmitDecl(const Decl &D);
346 void EmitEnumConstantDecl(const EnumConstantDecl &D);
347 void EmitBlockVarDecl(const BlockVarDecl &D);
348 void EmitLocalBlockVarDecl(const BlockVarDecl &D);
Anders Carlsson1a86b332007-10-17 00:52:43 +0000349 void EmitStaticBlockVarDecl(const BlockVarDecl &D);
Reid Spencer5f016e22007-07-11 17:01:13 +0000350 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
351
352 //===--------------------------------------------------------------------===//
353 // Statement Emission
354 //===--------------------------------------------------------------------===//
355
356 void EmitStmt(const Stmt *S);
Chris Lattner9b655512007-08-31 22:49:20 +0000357 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
358 llvm::Value *AggLoc = 0, bool isAggVol = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000359 void EmitLabelStmt(const LabelStmt &S);
360 void EmitGotoStmt(const GotoStmt &S);
361 void EmitIfStmt(const IfStmt &S);
362 void EmitWhileStmt(const WhileStmt &S);
363 void EmitDoStmt(const DoStmt &S);
364 void EmitForStmt(const ForStmt &S);
365 void EmitReturnStmt(const ReturnStmt &S);
366 void EmitDeclStmt(const DeclStmt &S);
Chris Lattnerda138702007-07-16 21:28:45 +0000367 void EmitBreakStmt();
368 void EmitContinueStmt();
Devang Patel51b09f22007-10-04 23:45:31 +0000369 void EmitSwitchStmt(const SwitchStmt &S);
370 void EmitDefaultStmt(const DefaultStmt &S);
371 void EmitCaseStmt(const CaseStmt &S);
Devang Patelc049e4f2007-10-08 20:57:48 +0000372 void EmitCaseStmtRange(const CaseStmt &S);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000373 void EmitAsmStmt(const AsmStmt &S);
374
Reid Spencer5f016e22007-07-11 17:01:13 +0000375 //===--------------------------------------------------------------------===//
376 // LValue Expression Emission
377 //===--------------------------------------------------------------------===//
378
379 /// EmitLValue - Emit code to compute a designator that specifies the location
380 /// of the expression.
381 ///
382 /// This can return one of two things: a simple address or a bitfield
383 /// reference. In either case, the LLVM Value* in the LValue structure is
384 /// guaranteed to be an LLVM pointer type.
385 ///
386 /// If this returns a bitfield reference, nothing about the pointee type of
387 /// the LLVM value is known: For example, it may not be a pointer to an
388 /// integer.
389 ///
390 /// If this returns a normal address, and if the lvalue's C type is fixed
391 /// size, this method guarantees that the returned pointer type will point to
392 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
393 /// variable length type, this is not possible.
394 ///
395 LValue EmitLValue(const Expr *E);
396
397 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
398 /// this method emits the address of the lvalue, then loads the result as an
399 /// rvalue, returning the rvalue.
Reid Spencer5f016e22007-07-11 17:01:13 +0000400 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Chris Lattner6481a572007-08-03 17:31:20 +0000401 RValue EmitLoadOfOCUElementLValue(LValue V, QualType LVType);
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000402 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000403
Chris Lattner34cdc862007-08-03 16:18:34 +0000404
Reid Spencer5f016e22007-07-11 17:01:13 +0000405 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
406 /// lvalue, where both are guaranteed to the have the same type, and that type
407 /// is 'Ty'.
408 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Chris Lattner017d6aa2007-08-03 16:28:33 +0000409 void EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, QualType Ty);
Lauro Ramos Venancioa0c5d0e2008-01-22 22:36:45 +0000410 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
Christopher Lamb22c940e2007-12-29 05:02:41 +0000411
412 // Note: only availabe for agg return types
413 LValue EmitCallExprLValue(const CallExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000414
415 LValue EmitDeclRefLValue(const DeclRefExpr *E);
416 LValue EmitStringLiteralLValue(const StringLiteral *E);
Anders Carlsson22742662007-07-21 05:21:51 +0000417 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000418 LValue EmitUnaryOpLValue(const UnaryOperator *E);
419 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Chris Lattner6481a572007-08-03 17:31:20 +0000420 LValue EmitOCUVectorElementExpr(const OCUVectorElementExpr *E);
Devang Patelb84a06e2007-10-23 02:10:49 +0000421 LValue EmitMemberExpr(const MemberExpr *E);
Eli Friedman472778e2008-02-09 08:50:58 +0000422
423 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
424 bool isUnion);
Reid Spencer5f016e22007-07-11 17:01:13 +0000425
426 //===--------------------------------------------------------------------===//
Chris Lattner883f6a72007-08-11 00:04:45 +0000427 // Scalar Expression Emission
Reid Spencer5f016e22007-07-11 17:01:13 +0000428 //===--------------------------------------------------------------------===//
429
Reid Spencer5f016e22007-07-11 17:01:13 +0000430 RValue EmitCallExpr(const CallExpr *E);
Eli Friedman5193b8a2008-01-30 01:32:06 +0000431 RValue EmitCallExpr(Expr *FnExpr, Expr *const *Args, unsigned NumArgs);
432 RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
433 Expr *const *Args, unsigned NumArgs);
Chris Lattner1e4d21e2007-08-26 22:58:05 +0000434 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000435
Anders Carlsson564f1de2007-12-09 23:17:02 +0000436 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
437 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
438
Anders Carlssoncc23aca2007-12-10 19:35:18 +0000439 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
Nate Begeman4119d1a2007-12-30 02:59:45 +0000440 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
441 bool isSplat = false);
Anders Carlsson6086bbd2007-12-15 21:23:30 +0000442
Chris Lattner7f02f722007-08-24 05:35:26 +0000443 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Anders Carlsson55085182007-08-21 17:43:55 +0000444
Chris Lattner883f6a72007-08-11 00:04:45 +0000445 //===--------------------------------------------------------------------===//
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000446 // Expression Emission
Chris Lattner883f6a72007-08-11 00:04:45 +0000447 //===--------------------------------------------------------------------===//
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000448
449 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattner883f6a72007-08-11 00:04:45 +0000450
Chris Lattner7f02f722007-08-24 05:35:26 +0000451 /// EmitScalarExpr - Emit the computation of the specified expression of
452 /// LLVM scalar type, returning the result.
453 llvm::Value *EmitScalarExpr(const Expr *E);
454
Chris Lattner3707b252007-08-26 06:48:56 +0000455 /// EmitScalarConversion - Emit a conversion from the specified type to the
456 /// specified destination type, both of which are LLVM scalar types.
457 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
458 QualType DstTy);
459
Chris Lattner4f1a7b32007-08-26 16:34:22 +0000460 /// EmitComplexToScalarConversion - Emit a conversion from the specified
461 /// complex type to the specified destination type, where the destination
462 /// type is an LLVM scalar type.
463 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
464 QualType DstTy);
465
Chris Lattner3707b252007-08-26 06:48:56 +0000466
Chris Lattner883f6a72007-08-11 00:04:45 +0000467 /// EmitAggExpr - Emit the computation of the specified expression of
468 /// aggregate type. The result is computed into DestPtr. Note that if
469 /// DestPtr is null, the value of the aggregate expression is not needed.
470 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattnerb6ef18a2007-08-21 05:54:00 +0000471
472 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner23b1cdb2007-08-23 23:43:33 +0000473 /// complex type, returning the result.
Chris Lattner58dee102007-08-21 16:57:55 +0000474 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner23b1cdb2007-08-23 23:43:33 +0000475
476 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
477 /// of complex type, storing into the specified Value*.
Chris Lattner190dbe22007-08-26 16:22:13 +0000478 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
479 bool DestIsVolatile);
Chris Lattner9b655512007-08-31 22:49:20 +0000480 /// LoadComplexFromAddr - Load a complex number from the specified address.
481 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Reid Spencer5f016e22007-07-11 17:01:13 +0000482};
483} // end namespace CodeGen
484} // end namespace clang
485
486#endif