blob: 30dfaabd645841e507939e9e13eaa0ca1856641a [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This is the internal per-function state used for llvm translation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CODEGEN_CODEGENFUNCTION_H
15#define CODEGEN_CODEGENFUNCTION_H
16
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/SmallVector.h"
19#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 Patele58e0802007-10-04 23:45:31 +000044 class CaseStmt;
45 class DefaultStmt;
46 class SwitchStmt;
47
Chris Lattner4b009652007-07-25 00:24:17 +000048 class Expr;
49 class DeclRefExpr;
50 class StringLiteral;
51 class IntegerLiteral;
52 class FloatingLiteral;
53 class CharacterLiteral;
Chris Lattner4ca7e752007-08-03 17:51:03 +000054 class TypesCompatibleExpr;
55
Chris Lattnerb2cb9cb2007-08-20 22:37:10 +000056 class ImplicitCastExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000057 class CastExpr;
58 class CallExpr;
59 class UnaryOperator;
60 class BinaryOperator;
61 class CompoundAssignOperator;
62 class ArraySubscriptExpr;
Chris Lattnera0d03a72007-08-03 17:31:20 +000063 class OCUVectorElementExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000064 class ConditionalOperator;
Chris Lattner44fcf4f2007-08-04 00:20:15 +000065 class ChooseExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000066 class PreDefinedExpr;
Anders Carlssona66cad42007-08-21 17:43:55 +000067 class ObjCStringLiteral;
Devang Patelaebd83f2007-10-23 02:10:49 +000068 class MemberExpr;
69
Chris Lattner4b009652007-07-25 00:24:17 +000070 class BlockVarDecl;
71 class EnumConstantDecl;
72 class ParmVarDecl;
73namespace CodeGen {
74 class CodeGenModule;
Devang Patelaebd83f2007-10-23 02:10:49 +000075 class CodeGenTypes;
Devang Patel7a78e432007-11-01 19:11:01 +000076 class CGRecordLayout;
Chris Lattner4b009652007-07-25 00:24:17 +000077
78/// RValue - This trivial value class is used to represent the result of an
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +000082class RValue {
Chris Lattnere24c4cf2007-08-31 22:49:20 +000083 llvm::Value *V1, *V2;
Chris Lattner4b009652007-07-25 00:24:17 +000084 // TODO: Encode this into the low bit of pointer for more efficient
85 // return-by-value.
Chris Lattnere24c4cf2007-08-31 22:49:20 +000086 enum { Scalar, Complex, Aggregate } Flavor;
Chris Lattner4b009652007-07-25 00:24:17 +000087
88 // FIXME: Aggregate rvalues need to retain information about whether they are
89 // volatile or not.
90public:
91
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +000095
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +0000100 }
101
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +0000108 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
109 llvm::Value *getAggregateAddr() const {
110 assert(isAggregate() && "Not an aggregate!");
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000111 return V1;
Chris Lattner4b009652007-07-25 00:24:17 +0000112 }
113
114 static RValue get(llvm::Value *V) {
115 RValue ER;
Chris Lattnere24c4cf2007-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 Lattner4b009652007-07-25 00:24:17 +0000132 return ER;
133 }
134 static RValue getAggregate(llvm::Value *V) {
135 RValue ER;
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000136 ER.V1 = V;
137 ER.Flavor = Aggregate;
Chris Lattner4b009652007-07-25 00:24:17 +0000138 return ER;
139 }
140};
141
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?
148 // alignment?
149
150 enum {
Chris Lattner65520192007-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 Lattnera0d03a72007-08-03 17:31:20 +0000154 OCUVectorElt // This is an ocu vector subset, use getOCUVectorComp
Chris Lattner4b009652007-07-25 00:24:17 +0000155 } LVType;
156
157 llvm::Value *V;
158
159 union {
Chris Lattner65520192007-08-02 23:37:31 +0000160 llvm::Value *VectorIdx; // Index into a vector subscript: V[i]
Chris Lattnera0d03a72007-08-03 17:31:20 +0000161 unsigned VectorElts; // Encoded OCUVector element subset: V.xyx
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000162 struct {
163 unsigned short StartBit;
164 unsigned short Size;
165 bool IsSigned;
166 } BitfieldData; // BitField start bit and size
Chris Lattner4b009652007-07-25 00:24:17 +0000167 };
168public:
169 bool isSimple() const { return LVType == Simple; }
170 bool isVectorElt() const { return LVType == VectorElt; }
171 bool isBitfield() const { return LVType == BitField; }
Chris Lattnera0d03a72007-08-03 17:31:20 +0000172 bool isOCUVectorElt() const { return LVType == OCUVectorElt; }
Chris Lattner4b009652007-07-25 00:24:17 +0000173
174 // simple lvalue
175 llvm::Value *getAddress() const { assert(isSimple()); return V; }
176 // vector elt lvalue
177 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
178 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Chris Lattnera0d03a72007-08-03 17:31:20 +0000179 // ocu vector elements.
180 llvm::Value *getOCUVectorAddr() const { assert(isOCUVectorElt()); return V; }
181 unsigned getOCUVectorElts() const {
182 assert(isOCUVectorElt());
183 return VectorElts;
Chris Lattner65520192007-08-02 23:37:31 +0000184 }
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000185 // bitfield lvalue
186 llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; }
187 unsigned short getBitfieldStartBit() const {
188 assert(isBitfield());
189 return BitfieldData.StartBit;
190 }
191 unsigned short getBitfieldSize() const {
192 assert(isBitfield());
193 return BitfieldData.Size;
194 }
195 bool isBitfieldSigned() const {
196 assert(isBitfield());
197 return BitfieldData.IsSigned;
198 }
199
Chris Lattner4b009652007-07-25 00:24:17 +0000200 static LValue MakeAddr(llvm::Value *V) {
201 LValue R;
202 R.LVType = Simple;
203 R.V = V;
204 return R;
205 }
206
207 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx) {
208 LValue R;
209 R.LVType = VectorElt;
210 R.V = Vec;
211 R.VectorIdx = Idx;
212 return R;
213 }
214
Chris Lattnera0d03a72007-08-03 17:31:20 +0000215 static LValue MakeOCUVectorElt(llvm::Value *Vec, unsigned Elements) {
Chris Lattner65520192007-08-02 23:37:31 +0000216 LValue R;
Chris Lattnera0d03a72007-08-03 17:31:20 +0000217 R.LVType = OCUVectorElt;
Chris Lattner65520192007-08-02 23:37:31 +0000218 R.V = Vec;
Chris Lattnera0d03a72007-08-03 17:31:20 +0000219 R.VectorElts = Elements;
Chris Lattner65520192007-08-02 23:37:31 +0000220 return R;
221 }
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000222
223 static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
224 unsigned short Size, bool IsSigned) {
225 LValue R;
226 R.LVType = BitField;
227 R.V = V;
228 R.BitfieldData.StartBit = StartBit;
229 R.BitfieldData.Size = Size;
230 R.BitfieldData.IsSigned = IsSigned;
231 return R;
232 }
Chris Lattner4b009652007-07-25 00:24:17 +0000233};
234
235/// CodeGenFunction - This class organizes the per-function state that is used
236/// while generating LLVM code.
237class CodeGenFunction {
Chris Lattner41b1fca2007-08-26 23:13:56 +0000238public:
Chris Lattner4b009652007-07-25 00:24:17 +0000239 CodeGenModule &CGM; // Per-module state.
240 TargetInfo &Target;
Chris Lattner41b1fca2007-08-26 23:13:56 +0000241
Chris Lattner5280c5f2007-08-21 16:57:55 +0000242 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Devang Patel638b64c2007-10-09 19:49:58 +0000243 llvm::LLVMFoldingBuilder Builder;
Chris Lattner4b009652007-07-25 00:24:17 +0000244
245 const FunctionDecl *CurFuncDecl;
246 llvm::Function *CurFn;
247
248 /// AllocaInsertPoint - This is an instruction in the entry block before which
249 /// we prefer to insert allocas.
250 llvm::Instruction *AllocaInsertPt;
251
252 const llvm::Type *LLVMIntTy;
Hartmut Kaiserff08d2c2007-10-17 15:00:17 +0000253 uint32_t LLVMPointerWidth;
Chris Lattner4b009652007-07-25 00:24:17 +0000254
Chris Lattner9fba49a2007-08-24 05:35:26 +0000255private:
Chris Lattner4b009652007-07-25 00:24:17 +0000256 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
257 /// decls.
258 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
259
260 /// LabelMap - This keeps track of the LLVM basic block for each C label.
261 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
262
263 // BreakContinueStack - This keeps track of where break and continue
264 // statements should jump to.
265 struct BreakContinue {
266 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
267 : BreakBlock(bb), ContinueBlock(cb) {}
268
269 llvm::BasicBlock *BreakBlock;
270 llvm::BasicBlock *ContinueBlock;
271 };
272 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
273
Devang Patelbc372382007-10-09 17:08:50 +0000274 /// SwitchInsn - This is nearest current switch instruction. It is null if
275 /// if current context is not in a switch.
Devang Patele58e0802007-10-04 23:45:31 +0000276 llvm::SwitchInst *SwitchInsn;
277
Devang Patelbc372382007-10-09 17:08:50 +0000278 /// CaseRangeBlock - This block holds if condition check for last case
279 /// statement range in current switch instruction.
Devang Patel347ca322007-10-08 20:57:48 +0000280 llvm::BasicBlock *CaseRangeBlock;
281
Chris Lattner4b009652007-07-25 00:24:17 +0000282public:
283 CodeGenFunction(CodeGenModule &cgm);
284
285 ASTContext &getContext() const;
286
287 void GenerateCode(const FunctionDecl *FD);
288
289 const llvm::Type *ConvertType(QualType T);
290
291 /// hasAggregateLLVMType - Return true if the specified AST type will map into
292 /// an aggregate LLVM type or is void.
293 static bool hasAggregateLLVMType(QualType T);
294
295 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
296 /// label maps to.
297 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
298
299
300 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattner9d4e6202007-12-02 01:43:38 +0000301
302 /// WarnUnsupported - Print out a warning that codegen doesn't support the
303 /// specified stmt yet.
Chris Lattnere8f49632007-12-02 01:49:16 +0000304 void WarnUnsupported(const Stmt *S, const char *Type);
Chris Lattner4b009652007-07-25 00:24:17 +0000305
306 //===--------------------------------------------------------------------===//
307 // Helpers
308 //===--------------------------------------------------------------------===//
309
310 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
311 /// block.
312 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
313 const char *Name = "tmp");
314
315 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
316 /// expression and compare the result against zero, returning an Int1Ty value.
317 llvm::Value *EvaluateExprAsBool(const Expr *E);
318
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000319 /// EmitAnyExpr - Emit code to compute the specified expression which can have
320 /// any type. The result is returned as an RValue struct. If this is an
321 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
322 /// the result should be returned.
323 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
324 bool isAggLocVolatile = false);
Devang Patel97299362007-09-28 21:49:18 +0000325
326 /// isDummyBlock - Return true if BB is an empty basic block
327 /// with no predecessors.
328 static bool isDummyBlock(const llvm::BasicBlock *BB);
329
Devang Patele58e0802007-10-04 23:45:31 +0000330 /// StartBlock - Start new block named N. If insert block is a dummy block
331 /// then reuse it.
332 void StartBlock(const char *N);
333
Devang Patel7a78e432007-11-01 19:11:01 +0000334 /// getCGRecordLayout - Return record layout info.
335 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Chris Lattner4b009652007-07-25 00:24:17 +0000336 //===--------------------------------------------------------------------===//
Chris Lattner4b009652007-07-25 00:24:17 +0000337 // Declaration Emission
338 //===--------------------------------------------------------------------===//
339
340 void EmitDecl(const Decl &D);
341 void EmitEnumConstantDecl(const EnumConstantDecl &D);
342 void EmitBlockVarDecl(const BlockVarDecl &D);
343 void EmitLocalBlockVarDecl(const BlockVarDecl &D);
Anders Carlsson855d78d2007-10-17 00:52:43 +0000344 void EmitStaticBlockVarDecl(const BlockVarDecl &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000345 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
346
347 //===--------------------------------------------------------------------===//
348 // Statement Emission
349 //===--------------------------------------------------------------------===//
350
351 void EmitStmt(const Stmt *S);
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000352 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
353 llvm::Value *AggLoc = 0, bool isAggVol = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000354 void EmitLabelStmt(const LabelStmt &S);
355 void EmitGotoStmt(const GotoStmt &S);
356 void EmitIfStmt(const IfStmt &S);
357 void EmitWhileStmt(const WhileStmt &S);
358 void EmitDoStmt(const DoStmt &S);
359 void EmitForStmt(const ForStmt &S);
360 void EmitReturnStmt(const ReturnStmt &S);
361 void EmitDeclStmt(const DeclStmt &S);
362 void EmitBreakStmt();
363 void EmitContinueStmt();
Devang Patele58e0802007-10-04 23:45:31 +0000364 void EmitSwitchStmt(const SwitchStmt &S);
365 void EmitDefaultStmt(const DefaultStmt &S);
366 void EmitCaseStmt(const CaseStmt &S);
Devang Patel347ca322007-10-08 20:57:48 +0000367 void EmitCaseStmtRange(const CaseStmt &S);
Devang Patele58e0802007-10-04 23:45:31 +0000368
Chris Lattner4b009652007-07-25 00:24:17 +0000369 //===--------------------------------------------------------------------===//
370 // LValue Expression Emission
371 //===--------------------------------------------------------------------===//
372
373 /// EmitLValue - Emit code to compute a designator that specifies the location
374 /// of the expression.
375 ///
376 /// This can return one of two things: a simple address or a bitfield
377 /// reference. In either case, the LLVM Value* in the LValue structure is
378 /// guaranteed to be an LLVM pointer type.
379 ///
380 /// If this returns a bitfield reference, nothing about the pointee type of
381 /// the LLVM value is known: For example, it may not be a pointer to an
382 /// integer.
383 ///
384 /// If this returns a normal address, and if the lvalue's C type is fixed
385 /// size, this method guarantees that the returned pointer type will point to
386 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
387 /// variable length type, this is not possible.
388 ///
389 LValue EmitLValue(const Expr *E);
390
391 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
392 /// this method emits the address of the lvalue, then loads the result as an
393 /// rvalue, returning the rvalue.
Chris Lattner4b009652007-07-25 00:24:17 +0000394 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Chris Lattnera0d03a72007-08-03 17:31:20 +0000395 RValue EmitLoadOfOCUElementLValue(LValue V, QualType LVType);
Lauro Ramos Venanciob40307c2008-01-22 20:17:04 +0000396 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
Chris Lattner4b009652007-07-25 00:24:17 +0000397
Chris Lattner944f7962007-08-03 16:18:34 +0000398
Chris Lattner4b009652007-07-25 00:24:17 +0000399 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
400 /// lvalue, where both are guaranteed to the have the same type, and that type
401 /// is 'Ty'.
402 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Chris Lattner5bfdd232007-08-03 16:28:33 +0000403 void EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, QualType Ty);
Lauro Ramos Venancio2d7a34c2008-01-22 22:36:45 +0000404 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
Christopher Lambad327ba2007-12-29 05:02:41 +0000405
406 // Note: only availabe for agg return types
407 LValue EmitCallExprLValue(const CallExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000408
409 LValue EmitDeclRefLValue(const DeclRefExpr *E);
410 LValue EmitStringLiteralLValue(const StringLiteral *E);
411 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
412 LValue EmitUnaryOpLValue(const UnaryOperator *E);
413 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Chris Lattnera0d03a72007-08-03 17:31:20 +0000414 LValue EmitOCUVectorElementExpr(const OCUVectorElementExpr *E);
Devang Patelaebd83f2007-10-23 02:10:49 +0000415 LValue EmitMemberExpr(const MemberExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000416
417 //===--------------------------------------------------------------------===//
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000418 // Scalar Expression Emission
Chris Lattner4b009652007-07-25 00:24:17 +0000419 //===--------------------------------------------------------------------===//
420
Chris Lattner4b009652007-07-25 00:24:17 +0000421 RValue EmitCallExpr(const CallExpr *E);
Eli Friedman261f4ad2008-01-30 01:32:06 +0000422 RValue EmitCallExpr(Expr *FnExpr, Expr *const *Args, unsigned NumArgs);
423 RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
424 Expr *const *Args, unsigned NumArgs);
Chris Lattner35055b82007-08-26 22:58:05 +0000425 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Chris Lattner4b009652007-07-25 00:24:17 +0000426
Anders Carlssone1449c12007-12-09 23:17:02 +0000427 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
428 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
429
Anders Carlssona9234fe2007-12-10 19:35:18 +0000430 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
Nate Begemanec2d1062007-12-30 02:59:45 +0000431 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
432 bool isSplat = false);
Anders Carlsson68b8be92007-12-15 21:23:30 +0000433
Chris Lattner9fba49a2007-08-24 05:35:26 +0000434 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Anders Carlssona66cad42007-08-21 17:43:55 +0000435
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000436 //===--------------------------------------------------------------------===//
Chris Lattner41b1fca2007-08-26 23:13:56 +0000437 // Expression Emission
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000438 //===--------------------------------------------------------------------===//
Chris Lattner41b1fca2007-08-26 23:13:56 +0000439
440 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000441
Chris Lattner9fba49a2007-08-24 05:35:26 +0000442 /// EmitScalarExpr - Emit the computation of the specified expression of
443 /// LLVM scalar type, returning the result.
444 llvm::Value *EmitScalarExpr(const Expr *E);
445
Chris Lattner4e05d1e2007-08-26 06:48:56 +0000446 /// EmitScalarConversion - Emit a conversion from the specified type to the
447 /// specified destination type, both of which are LLVM scalar types.
448 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
449 QualType DstTy);
450
Chris Lattnerfb182ee2007-08-26 16:34:22 +0000451 /// EmitComplexToScalarConversion - Emit a conversion from the specified
452 /// complex type to the specified destination type, where the destination
453 /// type is an LLVM scalar type.
454 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
455 QualType DstTy);
456
Chris Lattner4e05d1e2007-08-26 06:48:56 +0000457
Chris Lattnerbdb8ffb2007-08-11 00:04:45 +0000458 /// EmitAggExpr - Emit the computation of the specified expression of
459 /// aggregate type. The result is computed into DestPtr. Note that if
460 /// DestPtr is null, the value of the aggregate expression is not needed.
461 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattner8d0cc2f2007-08-21 05:54:00 +0000462
463 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner348c8a22007-08-23 23:43:33 +0000464 /// complex type, returning the result.
Chris Lattner5280c5f2007-08-21 16:57:55 +0000465 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner348c8a22007-08-23 23:43:33 +0000466
467 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
468 /// of complex type, storing into the specified Value*.
Chris Lattner8e1f6e02007-08-26 16:22:13 +0000469 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
470 bool DestIsVolatile);
Chris Lattnere24c4cf2007-08-31 22:49:20 +0000471 /// LoadComplexFromAddr - Load a complex number from the specified address.
472 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Chris Lattner4b009652007-07-25 00:24:17 +0000473};
474} // end namespace CodeGen
475} // end namespace clang
476
477#endif