blob: 7d11a74d8c05be247fe1d6a4cfd2517583e3bc0f [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
Chris Lattner391d77a2008-03-30 23:03:07 +000017#include "clang/AST/Type.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000018#include "llvm/ADT/DenseMap.h"
Chris Lattnerda138702007-07-16 21:28:45 +000019#include "llvm/ADT/SmallVector.h"
Chris Lattner50b36742008-04-13 07:32:11 +000020#include "llvm/Support/IRBuilder.h"
Ted Kremenek55499762008-06-17 02:43:46 +000021#include "clang/AST/Expr.h"
22#include "clang/AST/ExprObjC.h"
23
Reid Spencer5f016e22007-07-11 17:01:13 +000024#include <vector>
25
26namespace llvm {
27 class Module;
28}
29
30namespace clang {
31 class ASTContext;
32 class Decl;
33 class FunctionDecl;
Chris Lattner391d77a2008-03-30 23:03:07 +000034 class ObjCMethodDecl;
Reid Spencer5f016e22007-07-11 17:01:13 +000035 class TargetInfo;
Reid Spencer5f016e22007-07-11 17:01:13 +000036 class FunctionTypeProto;
Devang Patelb84a06e2007-10-23 02:10:49 +000037
Reid Spencer5f016e22007-07-11 17:01:13 +000038namespace CodeGen {
39 class CodeGenModule;
Devang Patelb84a06e2007-10-23 02:10:49 +000040 class CodeGenTypes;
Devang Patel88a981b2007-11-01 19:11:01 +000041 class CGRecordLayout;
Reid Spencer5f016e22007-07-11 17:01:13 +000042
43/// RValue - This trivial value class is used to represent the result of an
Chris Lattner9b655512007-08-31 22:49:20 +000044/// expression that is evaluated. It can be one of three things: either a
45/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
46/// address of an aggregate value in memory.
Reid Spencer5f016e22007-07-11 17:01:13 +000047class RValue {
Chris Lattner9b655512007-08-31 22:49:20 +000048 llvm::Value *V1, *V2;
Reid Spencer5f016e22007-07-11 17:01:13 +000049 // TODO: Encode this into the low bit of pointer for more efficient
50 // return-by-value.
Chris Lattner9b655512007-08-31 22:49:20 +000051 enum { Scalar, Complex, Aggregate } Flavor;
Reid Spencer5f016e22007-07-11 17:01:13 +000052
53 // FIXME: Aggregate rvalues need to retain information about whether they are
54 // volatile or not.
55public:
56
Chris Lattner9b655512007-08-31 22:49:20 +000057 bool isScalar() const { return Flavor == Scalar; }
58 bool isComplex() const { return Flavor == Complex; }
59 bool isAggregate() const { return Flavor == Aggregate; }
Reid Spencer5f016e22007-07-11 17:01:13 +000060
Chris Lattner9b655512007-08-31 22:49:20 +000061 /// getScalar() - Return the Value* of this scalar value.
62 llvm::Value *getScalarVal() const {
63 assert(isScalar() && "Not a scalar!");
64 return V1;
Reid Spencer5f016e22007-07-11 17:01:13 +000065 }
66
Chris Lattner9b655512007-08-31 22:49:20 +000067 /// getComplexVal - Return the real/imag components of this complex value.
68 ///
69 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
70 return std::pair<llvm::Value *, llvm::Value *>(V1, V2);
71 }
72
Reid Spencer5f016e22007-07-11 17:01:13 +000073 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
74 llvm::Value *getAggregateAddr() const {
75 assert(isAggregate() && "Not an aggregate!");
Chris Lattner9b655512007-08-31 22:49:20 +000076 return V1;
Reid Spencer5f016e22007-07-11 17:01:13 +000077 }
78
79 static RValue get(llvm::Value *V) {
80 RValue ER;
Chris Lattner9b655512007-08-31 22:49:20 +000081 ER.V1 = V;
82 ER.Flavor = Scalar;
83 return ER;
84 }
85 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
86 RValue ER;
87 ER.V1 = V1;
88 ER.V2 = V2;
89 ER.Flavor = Complex;
90 return ER;
91 }
92 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
93 RValue ER;
94 ER.V1 = C.first;
95 ER.V2 = C.second;
96 ER.Flavor = Complex;
Reid Spencer5f016e22007-07-11 17:01:13 +000097 return ER;
98 }
99 static RValue getAggregate(llvm::Value *V) {
100 RValue ER;
Chris Lattner9b655512007-08-31 22:49:20 +0000101 ER.V1 = V;
102 ER.Flavor = Aggregate;
Reid Spencer5f016e22007-07-11 17:01:13 +0000103 return ER;
104 }
105};
106
107
108/// LValue - This represents an lvalue references. Because C/C++ allow
109/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
110/// bitrange.
111class LValue {
Eli Friedman1e692ac2008-06-13 23:01:12 +0000112 // FIXME: alignment?
Reid Spencer5f016e22007-07-11 17:01:13 +0000113
114 enum {
Chris Lattner349aaec2007-08-02 23:37:31 +0000115 Simple, // This is a normal l-value, use getAddress().
116 VectorElt, // This is a vector element l-value (V[i]), use getVector*
117 BitField, // This is a bitfield l-value, use getBitfield*.
Nate Begeman213541a2008-04-18 23:10:10 +0000118 ExtVectorElt // This is an extended vector subset, use getExtVectorComp
Reid Spencer5f016e22007-07-11 17:01:13 +0000119 } LVType;
120
121 llvm::Value *V;
122
123 union {
Nate Begeman8a997642008-05-09 06:41:27 +0000124 // Index into a vector subscript: V[i]
125 llvm::Value *VectorIdx;
126
127 // ExtVector element subset: V.xyx
128 llvm::Constant *VectorElts;
129
Nate Begeman69ce1df2008-07-25 20:15:41 +0000130 // BitField start bit and size
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000131 struct {
132 unsigned short StartBit;
133 unsigned short Size;
134 bool IsSigned;
Nate Begeman69ce1df2008-07-25 20:15:41 +0000135 } BitfieldData;
Reid Spencer5f016e22007-07-11 17:01:13 +0000136 };
Eli Friedman1e692ac2008-06-13 23:01:12 +0000137
138 bool Volatile:1;
139 // FIXME: set but never used, what effect should it have?
140 bool Restrict:1;
141
142private:
143 static void SetQualifiers(unsigned Qualifiers, LValue& R) {
144 R.Volatile = (Qualifiers&QualType::Volatile)!=0;
145 R.Restrict = (Qualifiers&QualType::Restrict)!=0;
146 }
147
Reid Spencer5f016e22007-07-11 17:01:13 +0000148public:
149 bool isSimple() const { return LVType == Simple; }
150 bool isVectorElt() const { return LVType == VectorElt; }
151 bool isBitfield() const { return LVType == BitField; }
Nate Begeman213541a2008-04-18 23:10:10 +0000152 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Reid Spencer5f016e22007-07-11 17:01:13 +0000153
Eli Friedman1e692ac2008-06-13 23:01:12 +0000154 bool isVolatileQualified() const { return Volatile; }
155 bool isRestrictQualified() const { return Restrict; }
156
Reid Spencer5f016e22007-07-11 17:01:13 +0000157 // simple lvalue
158 llvm::Value *getAddress() const { assert(isSimple()); return V; }
159 // vector elt lvalue
160 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
161 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Nate Begeman213541a2008-04-18 23:10:10 +0000162 // extended vector elements.
163 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
Nate Begeman8a997642008-05-09 06:41:27 +0000164 llvm::Constant *getExtVectorElts() const {
Nate Begeman213541a2008-04-18 23:10:10 +0000165 assert(isExtVectorElt());
Chris Lattner6481a572007-08-03 17:31:20 +0000166 return VectorElts;
Chris Lattner349aaec2007-08-02 23:37:31 +0000167 }
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000168 // bitfield lvalue
169 llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; }
170 unsigned short getBitfieldStartBit() const {
171 assert(isBitfield());
172 return BitfieldData.StartBit;
173 }
174 unsigned short getBitfieldSize() const {
175 assert(isBitfield());
176 return BitfieldData.Size;
177 }
178 bool isBitfieldSigned() const {
179 assert(isBitfield());
180 return BitfieldData.IsSigned;
181 }
182
Eli Friedman1e692ac2008-06-13 23:01:12 +0000183 static LValue MakeAddr(llvm::Value *V, unsigned Qualifiers) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000184 LValue R;
185 R.LVType = Simple;
186 R.V = V;
Eli Friedman1e692ac2008-06-13 23:01:12 +0000187 SetQualifiers(Qualifiers,R);
Reid Spencer5f016e22007-07-11 17:01:13 +0000188 return R;
189 }
190
Eli Friedman1e692ac2008-06-13 23:01:12 +0000191 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
192 unsigned Qualifiers) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000193 LValue R;
194 R.LVType = VectorElt;
195 R.V = Vec;
196 R.VectorIdx = Idx;
Eli Friedman1e692ac2008-06-13 23:01:12 +0000197 SetQualifiers(Qualifiers,R);
Reid Spencer5f016e22007-07-11 17:01:13 +0000198 return R;
199 }
200
Eli Friedman1e692ac2008-06-13 23:01:12 +0000201 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
202 unsigned Qualifiers) {
Chris Lattner349aaec2007-08-02 23:37:31 +0000203 LValue R;
Nate Begeman213541a2008-04-18 23:10:10 +0000204 R.LVType = ExtVectorElt;
Chris Lattner349aaec2007-08-02 23:37:31 +0000205 R.V = Vec;
Nate Begeman8a997642008-05-09 06:41:27 +0000206 R.VectorElts = Elts;
Eli Friedman1e692ac2008-06-13 23:01:12 +0000207 SetQualifiers(Qualifiers,R);
Chris Lattner349aaec2007-08-02 23:37:31 +0000208 return R;
209 }
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000210
211 static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
Eli Friedman1e692ac2008-06-13 23:01:12 +0000212 unsigned short Size, bool IsSigned,
213 unsigned Qualifiers) {
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000214 LValue R;
215 R.LVType = BitField;
216 R.V = V;
217 R.BitfieldData.StartBit = StartBit;
218 R.BitfieldData.Size = Size;
219 R.BitfieldData.IsSigned = IsSigned;
Eli Friedman1e692ac2008-06-13 23:01:12 +0000220 SetQualifiers(Qualifiers,R);
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000221 return R;
222 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000223};
224
225/// CodeGenFunction - This class organizes the per-function state that is used
226/// while generating LLVM code.
227class CodeGenFunction {
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000228public:
Reid Spencer5f016e22007-07-11 17:01:13 +0000229 CodeGenModule &CGM; // Per-module state.
230 TargetInfo &Target;
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000231
Chris Lattner58dee102007-08-21 16:57:55 +0000232 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Chris Lattner50b36742008-04-13 07:32:11 +0000233 llvm::IRBuilder Builder;
Reid Spencer5f016e22007-07-11 17:01:13 +0000234
Chris Lattnerc8aa5f12008-04-04 04:07:35 +0000235 // Holds the Decl for the current function or method
Chris Lattner41110242008-06-17 18:05:57 +0000236 const Decl *CurFuncDecl;
Chris Lattner391d77a2008-03-30 23:03:07 +0000237 QualType FnRetTy;
Reid Spencer5f016e22007-07-11 17:01:13 +0000238 llvm::Function *CurFn;
239
240 /// AllocaInsertPoint - This is an instruction in the entry block before which
241 /// we prefer to insert allocas.
242 llvm::Instruction *AllocaInsertPt;
243
244 const llvm::Type *LLVMIntTy;
Hartmut Kaiser7b660002007-10-17 15:00:17 +0000245 uint32_t LLVMPointerWidth;
Reid Spencer5f016e22007-07-11 17:01:13 +0000246
Chris Lattner7f02f722007-08-24 05:35:26 +0000247private:
Reid Spencer5f016e22007-07-11 17:01:13 +0000248 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
249 /// decls.
250 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
251
252 /// LabelMap - This keeps track of the LLVM basic block for each C label.
253 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnerda138702007-07-16 21:28:45 +0000254
255 // BreakContinueStack - This keeps track of where break and continue
256 // statements should jump to.
257 struct BreakContinue {
258 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
259 : BreakBlock(bb), ContinueBlock(cb) {}
260
261 llvm::BasicBlock *BreakBlock;
262 llvm::BasicBlock *ContinueBlock;
263 };
264 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
265
Devang Patel80fd5f92007-10-09 17:08:50 +0000266 /// SwitchInsn - This is nearest current switch instruction. It is null if
267 /// if current context is not in a switch.
Devang Patel51b09f22007-10-04 23:45:31 +0000268 llvm::SwitchInst *SwitchInsn;
269
Devang Patel80fd5f92007-10-09 17:08:50 +0000270 /// CaseRangeBlock - This block holds if condition check for last case
271 /// statement range in current switch instruction.
Devang Patelc049e4f2007-10-08 20:57:48 +0000272 llvm::BasicBlock *CaseRangeBlock;
273
Reid Spencer5f016e22007-07-11 17:01:13 +0000274public:
275 CodeGenFunction(CodeGenModule &cgm);
276
277 ASTContext &getContext() const;
278
Chris Lattner391d77a2008-03-30 23:03:07 +0000279 void GenerateObjCMethod(const ObjCMethodDecl *OMD);
Reid Spencer5f016e22007-07-11 17:01:13 +0000280 void GenerateCode(const FunctionDecl *FD);
Chris Lattner41110242008-06-17 18:05:57 +0000281 void GenerateFunction(const Stmt *Body);
Reid Spencer5f016e22007-07-11 17:01:13 +0000282
283 const llvm::Type *ConvertType(QualType T);
Chris Lattnerc8aa5f12008-04-04 04:07:35 +0000284
285 llvm::Value *LoadObjCSelf();
Chris Lattner41110242008-06-17 18:05:57 +0000286
287 /// isObjCPointerType - Return true if the specificed AST type will map onto
288 /// some Objective-C pointer type.
289 static bool isObjCPointerType(QualType T);
290
Reid Spencer5f016e22007-07-11 17:01:13 +0000291 /// 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 Lattnerdc5e8262007-12-02 01:43:38 +0000301
302 /// WarnUnsupported - Print out a warning that codegen doesn't support the
303 /// specified stmt yet.
Chris Lattnerdc4d2802007-12-02 01:49:16 +0000304 void WarnUnsupported(const Stmt *S, const char *Type);
Reid Spencer5f016e22007-07-11 17:01:13 +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 Lattner9b655512007-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 Pateld9363c32007-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 Patel51b09f22007-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 Patel88a981b2007-11-01 19:11:01 +0000334 /// getCGRecordLayout - Return record layout info.
335 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Lauro Ramos Venancio81373352008-02-26 21:41:45 +0000336
337 /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
Steve Naroff248a7532008-04-15 22:42:06 +0000338 llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
Dan Gohman4f8d1232008-05-22 00:50:06 +0000339
340 /// getAccessedFieldNo - Given an encoded value and a result number, return
341 /// the input field number being accessed.
342 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
343
Reid Spencer5f016e22007-07-11 17:01:13 +0000344 //===--------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +0000345 // Declaration Emission
346 //===--------------------------------------------------------------------===//
347
348 void EmitDecl(const Decl &D);
349 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Steve Naroff248a7532008-04-15 22:42:06 +0000350 void EmitBlockVarDecl(const VarDecl &D);
351 void EmitLocalBlockVarDecl(const VarDecl &D);
352 void EmitStaticBlockVarDecl(const VarDecl &D);
Reid Spencer5f016e22007-07-11 17:01:13 +0000353 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
354
355 //===--------------------------------------------------------------------===//
356 // Statement Emission
357 //===--------------------------------------------------------------------===//
358
359 void EmitStmt(const Stmt *S);
Chris Lattner9b655512007-08-31 22:49:20 +0000360 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
361 llvm::Value *AggLoc = 0, bool isAggVol = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000362 void EmitLabelStmt(const LabelStmt &S);
363 void EmitGotoStmt(const GotoStmt &S);
364 void EmitIfStmt(const IfStmt &S);
365 void EmitWhileStmt(const WhileStmt &S);
366 void EmitDoStmt(const DoStmt &S);
367 void EmitForStmt(const ForStmt &S);
368 void EmitReturnStmt(const ReturnStmt &S);
369 void EmitDeclStmt(const DeclStmt &S);
Chris Lattnerda138702007-07-16 21:28:45 +0000370 void EmitBreakStmt();
371 void EmitContinueStmt();
Devang Patel51b09f22007-10-04 23:45:31 +0000372 void EmitSwitchStmt(const SwitchStmt &S);
373 void EmitDefaultStmt(const DefaultStmt &S);
374 void EmitCaseStmt(const CaseStmt &S);
Devang Patelc049e4f2007-10-08 20:57:48 +0000375 void EmitCaseStmtRange(const CaseStmt &S);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000376 void EmitAsmStmt(const AsmStmt &S);
377
Reid Spencer5f016e22007-07-11 17:01:13 +0000378 //===--------------------------------------------------------------------===//
379 // LValue Expression Emission
380 //===--------------------------------------------------------------------===//
381
382 /// EmitLValue - Emit code to compute a designator that specifies the location
383 /// of the expression.
384 ///
385 /// This can return one of two things: a simple address or a bitfield
386 /// reference. In either case, the LLVM Value* in the LValue structure is
387 /// guaranteed to be an LLVM pointer type.
388 ///
389 /// If this returns a bitfield reference, nothing about the pointee type of
390 /// the LLVM value is known: For example, it may not be a pointer to an
391 /// integer.
392 ///
393 /// If this returns a normal address, and if the lvalue's C type is fixed
394 /// size, this method guarantees that the returned pointer type will point to
395 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
396 /// variable length type, this is not possible.
397 ///
398 LValue EmitLValue(const Expr *E);
399
400 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
401 /// this method emits the address of the lvalue, then loads the result as an
402 /// rvalue, returning the rvalue.
Reid Spencer5f016e22007-07-11 17:01:13 +0000403 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Nate Begeman213541a2008-04-18 23:10:10 +0000404 RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
Lauro Ramos Venancio3b8c22d2008-01-22 20:17:04 +0000405 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000406
Chris Lattner34cdc862007-08-03 16:18:34 +0000407
Reid Spencer5f016e22007-07-11 17:01:13 +0000408 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
409 /// lvalue, where both are guaranteed to the have the same type, and that type
410 /// is 'Ty'.
411 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Nate Begeman213541a2008-04-18 23:10:10 +0000412 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
413 QualType Ty);
Lauro Ramos Venancioa0c5d0e2008-01-22 22:36:45 +0000414 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
Christopher Lamb22c940e2007-12-29 05:02:41 +0000415
416 // Note: only availabe for agg return types
417 LValue EmitCallExprLValue(const CallExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000418
419 LValue EmitDeclRefLValue(const DeclRefExpr *E);
420 LValue EmitStringLiteralLValue(const StringLiteral *E);
Anders Carlsson22742662007-07-21 05:21:51 +0000421 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000422 LValue EmitUnaryOpLValue(const UnaryOperator *E);
423 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Nate Begeman213541a2008-04-18 23:10:10 +0000424 LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
Devang Patelb84a06e2007-10-23 02:10:49 +0000425 LValue EmitMemberExpr(const MemberExpr *E);
Eli Friedman06e863f2008-05-13 23:18:27 +0000426 LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
Eli Friedman472778e2008-02-09 08:50:58 +0000427
428 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
Eli Friedman1e692ac2008-06-13 23:01:12 +0000429 bool isUnion, unsigned CVRQualifiers);
Chris Lattner391d77a2008-03-30 23:03:07 +0000430
431 LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000432 //===--------------------------------------------------------------------===//
Chris Lattner883f6a72007-08-11 00:04:45 +0000433 // Scalar Expression Emission
Reid Spencer5f016e22007-07-11 17:01:13 +0000434 //===--------------------------------------------------------------------===//
435
Reid Spencer5f016e22007-07-11 17:01:13 +0000436 RValue EmitCallExpr(const CallExpr *E);
Ted Kremenek55499762008-06-17 02:43:46 +0000437
438 RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg,
439 CallExpr::const_arg_iterator ArgEnd);
440
Eli Friedman5193b8a2008-01-30 01:32:06 +0000441 RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
Ted Kremenek55499762008-06-17 02:43:46 +0000442 CallExpr::const_arg_iterator ArgBeg,
443 CallExpr::const_arg_iterator ArgEnd);
444
Chris Lattner1e4d21e2007-08-26 22:58:05 +0000445 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Reid Spencer5f016e22007-07-11 17:01:13 +0000446
Anders Carlsson564f1de2007-12-09 23:17:02 +0000447 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
448 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
449
Anders Carlssoncc23aca2007-12-10 19:35:18 +0000450 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
Nate Begeman4119d1a2007-12-30 02:59:45 +0000451 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
452 bool isSplat = false);
Anders Carlsson6086bbd2007-12-15 21:23:30 +0000453
Chris Lattner7f02f722007-08-24 05:35:26 +0000454 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Chris Lattner8fdf3282008-06-24 17:04:18 +0000455 llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
456 llvm::Value *EmitObjCMessageExpr(const ObjCMessageExpr *E);
457
458
Anders Carlsson55085182007-08-21 17:43:55 +0000459
Chris Lattner883f6a72007-08-11 00:04:45 +0000460 //===--------------------------------------------------------------------===//
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000461 // Expression Emission
Chris Lattner883f6a72007-08-11 00:04:45 +0000462 //===--------------------------------------------------------------------===//
Chris Lattnerbfc0c1a2007-08-26 23:13:56 +0000463
464 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattner883f6a72007-08-11 00:04:45 +0000465
Chris Lattner7f02f722007-08-24 05:35:26 +0000466 /// EmitScalarExpr - Emit the computation of the specified expression of
467 /// LLVM scalar type, returning the result.
468 llvm::Value *EmitScalarExpr(const Expr *E);
469
Chris Lattner3707b252007-08-26 06:48:56 +0000470 /// EmitScalarConversion - Emit a conversion from the specified type to the
471 /// specified destination type, both of which are LLVM scalar types.
472 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
473 QualType DstTy);
474
Chris Lattner4f1a7b32007-08-26 16:34:22 +0000475 /// EmitComplexToScalarConversion - Emit a conversion from the specified
476 /// complex type to the specified destination type, where the destination
477 /// type is an LLVM scalar type.
478 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
479 QualType DstTy);
480
Chris Lattner3707b252007-08-26 06:48:56 +0000481
Chris Lattner883f6a72007-08-11 00:04:45 +0000482 /// EmitAggExpr - Emit the computation of the specified expression of
483 /// aggregate type. The result is computed into DestPtr. Note that if
484 /// DestPtr is null, the value of the aggregate expression is not needed.
485 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattnerb6ef18a2007-08-21 05:54:00 +0000486
487 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner23b1cdb2007-08-23 23:43:33 +0000488 /// complex type, returning the result.
Chris Lattner58dee102007-08-21 16:57:55 +0000489 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner23b1cdb2007-08-23 23:43:33 +0000490
491 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
492 /// of complex type, storing into the specified Value*.
Chris Lattner190dbe22007-08-26 16:22:13 +0000493 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
494 bool DestIsVolatile);
Chris Lattner9b655512007-08-31 22:49:20 +0000495 /// LoadComplexFromAddr - Load a complex number from the specified address.
496 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Chris Lattner2621fd12008-05-08 05:58:21 +0000497
498 /// GenerateStaticBlockVarDecl - return the the static
499 /// declaration of local variable.
500 llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D,
501 bool NoInit,
502 const char *Separator);
Reid Spencer5f016e22007-07-11 17:01:13 +0000503};
504} // end namespace CodeGen
505} // end namespace clang
506
507#endif