blob: 313d2d1829a2012ceee352e2d6c82f20542dbab8 [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//
Chris Lattner5b12ab82007-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 Lattnerbed31442007-05-28 01:07:47 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This is the internal per-function state used for llvm translation.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattnerc18bfbb2008-02-29 17:10:38 +000014#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
15#define CLANG_CODEGEN_CODEGENFUNCTION_H
Chris Lattnerbed31442007-05-28 01:07:47 +000016
Chris Lattner4bd55962008-03-30 23:03:07 +000017#include "clang/AST/Type.h"
Chris Lattnerac248202007-05-30 00:13:02 +000018#include "llvm/ADT/DenseMap.h"
Chris Lattnere73e4322007-07-16 21:28:45 +000019#include "llvm/ADT/SmallVector.h"
Chris Lattner61705c12008-04-13 07:32:11 +000020#include "llvm/Support/IRBuilder.h"
Chris Lattner2ccb73b2007-06-16 00:16:26 +000021#include <vector>
Chris Lattner308f4312007-05-29 23:50:05 +000022
Chris Lattnerbed31442007-05-28 01:07:47 +000023namespace llvm {
24 class Module;
Chris Lattner23b7eb62007-06-15 23:05:46 +000025}
26
Chris Lattnerbed31442007-05-28 01:07:47 +000027namespace clang {
28 class ASTContext;
Chris Lattner84915fa2007-06-02 04:16:21 +000029 class Decl;
Chris Lattnerbed31442007-05-28 01:07:47 +000030 class FunctionDecl;
Chris Lattner4bd55962008-03-30 23:03:07 +000031 class ObjCMethodDecl;
Chris Lattner2ccb73b2007-06-16 00:16:26 +000032 class TargetInfo;
Chris Lattner2ccb73b2007-06-16 00:16:26 +000033 class FunctionTypeProto;
Chris Lattner84915fa2007-06-02 04:16:21 +000034
Chris Lattner308f4312007-05-29 23:50:05 +000035 class Stmt;
36 class CompoundStmt;
Chris Lattnerac248202007-05-30 00:13:02 +000037 class LabelStmt;
38 class GotoStmt;
Chris Lattner5269c032007-05-30 21:03:58 +000039 class IfStmt;
Chris Lattner946aa312007-06-05 03:59:43 +000040 class WhileStmt;
Chris Lattner8394d792007-06-05 20:53:16 +000041 class DoStmt;
42 class ForStmt;
Chris Lattner3f3dbee2007-06-02 03:19:07 +000043 class ReturnStmt;
Chris Lattner84915fa2007-06-02 04:16:21 +000044 class DeclStmt;
Devang Patelda5d6bb2007-10-04 23:45:31 +000045 class CaseStmt;
46 class DefaultStmt;
47 class SwitchStmt;
Anders Carlsson952a9952008-02-05 16:35:33 +000048 class AsmStmt;
49
Chris Lattner208ae962007-05-30 17:57:17 +000050 class Expr;
Chris Lattnerd7f58862007-06-02 05:24:33 +000051 class DeclRefExpr;
Chris Lattner4347e3692007-06-06 04:54:52 +000052 class StringLiteral;
Chris Lattner208ae962007-05-30 17:57:17 +000053 class IntegerLiteral;
Chris Lattner2ada32e2007-07-09 23:03:16 +000054 class FloatingLiteral;
Chris Lattner6e9d9b32007-07-13 05:18:11 +000055 class CharacterLiteral;
Chris Lattner40480052007-08-03 17:51:03 +000056 class TypesCompatibleExpr;
57
Chris Lattner76ba8492007-08-20 22:37:10 +000058 class ImplicitCastExpr;
Chris Lattner8394d792007-06-05 20:53:16 +000059 class CastExpr;
Chris Lattner2b228c92007-06-15 21:34:29 +000060 class CallExpr;
Chris Lattnerf0106d22007-06-02 19:33:17 +000061 class UnaryOperator;
Chris Lattnerdb91b162007-06-02 00:16:28 +000062 class BinaryOperator;
Chris Lattner9369a562007-06-29 16:31:29 +000063 class CompoundAssignOperator;
Chris Lattnerd9d2fb12007-06-08 23:31:14 +000064 class ArraySubscriptExpr;
Nate Begemance4d7fc2008-04-18 23:10:10 +000065 class ExtVectorElementExpr;
Chris Lattner6e9d9b32007-07-13 05:18:11 +000066 class ConditionalOperator;
Chris Lattner81a96882007-08-04 00:20:15 +000067 class ChooseExpr;
Anders Carlsson625bfc82007-07-21 05:21:51 +000068 class PreDefinedExpr;
Anders Carlsson76f4a902007-08-21 17:43:55 +000069 class ObjCStringLiteral;
Chris Lattner4bd55962008-03-30 23:03:07 +000070 class ObjCIvarRefExpr;
Devang Patel3e11cce2007-10-23 02:10:49 +000071 class MemberExpr;
Eli Friedman9fd8b682008-05-13 23:18:27 +000072 class CompoundLiteralExpr;
Devang Patel3e11cce2007-10-23 02:10:49 +000073
Steve Naroff08899ff2008-04-15 22:42:06 +000074 class VarDecl;
Chris Lattner84915fa2007-06-02 04:16:21 +000075 class EnumConstantDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000076 class ParmVarDecl;
Eli Friedmana62f3e12008-02-09 08:50:58 +000077 class FieldDecl;
Chris Lattnerbed31442007-05-28 01:07:47 +000078namespace CodeGen {
79 class CodeGenModule;
Devang Patel3e11cce2007-10-23 02:10:49 +000080 class CodeGenTypes;
Devang Patele11664a2007-11-01 19:11:01 +000081 class CGRecordLayout;
Chris Lattnerd7f58862007-06-02 05:24:33 +000082
Chris Lattner8394d792007-06-05 20:53:16 +000083/// RValue - This trivial value class is used to represent the result of an
Chris Lattner4647a212007-08-31 22:49:20 +000084/// expression that is evaluated. It can be one of three things: either a
85/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
86/// address of an aggregate value in memory.
Chris Lattner8394d792007-06-05 20:53:16 +000087class RValue {
Chris Lattner4647a212007-08-31 22:49:20 +000088 llvm::Value *V1, *V2;
Chris Lattnerdb91b162007-06-02 00:16:28 +000089 // TODO: Encode this into the low bit of pointer for more efficient
90 // return-by-value.
Chris Lattner4647a212007-08-31 22:49:20 +000091 enum { Scalar, Complex, Aggregate } Flavor;
Chris Lattner09153c02007-06-22 18:48:09 +000092
93 // FIXME: Aggregate rvalues need to retain information about whether they are
94 // volatile or not.
Chris Lattner5269c032007-05-30 21:03:58 +000095public:
96
Chris Lattner4647a212007-08-31 22:49:20 +000097 bool isScalar() const { return Flavor == Scalar; }
98 bool isComplex() const { return Flavor == Complex; }
99 bool isAggregate() const { return Flavor == Aggregate; }
Chris Lattner5269c032007-05-30 21:03:58 +0000100
Chris Lattner4647a212007-08-31 22:49:20 +0000101 /// getScalar() - Return the Value* of this scalar value.
102 llvm::Value *getScalarVal() const {
103 assert(isScalar() && "Not a scalar!");
104 return V1;
Chris Lattner5269c032007-05-30 21:03:58 +0000105 }
106
Chris Lattner4647a212007-08-31 22:49:20 +0000107 /// getComplexVal - Return the real/imag components of this complex value.
108 ///
109 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
110 return std::pair<llvm::Value *, llvm::Value *>(V1, V2);
111 }
112
Chris Lattner09153c02007-06-22 18:48:09 +0000113 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
114 llvm::Value *getAggregateAddr() const {
Chris Lattner5269c032007-05-30 21:03:58 +0000115 assert(isAggregate() && "Not an aggregate!");
Chris Lattner4647a212007-08-31 22:49:20 +0000116 return V1;
Chris Lattner5269c032007-05-30 21:03:58 +0000117 }
Chris Lattner208ae962007-05-30 17:57:17 +0000118
Chris Lattner23b7eb62007-06-15 23:05:46 +0000119 static RValue get(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +0000120 RValue ER;
Chris Lattner4647a212007-08-31 22:49:20 +0000121 ER.V1 = V;
122 ER.Flavor = Scalar;
123 return ER;
124 }
125 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
126 RValue ER;
127 ER.V1 = V1;
128 ER.V2 = V2;
129 ER.Flavor = Complex;
130 return ER;
131 }
132 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
133 RValue ER;
134 ER.V1 = C.first;
135 ER.V2 = C.second;
136 ER.Flavor = Complex;
Chris Lattner208ae962007-05-30 17:57:17 +0000137 return ER;
138 }
Chris Lattner23b7eb62007-06-15 23:05:46 +0000139 static RValue getAggregate(llvm::Value *V) {
Chris Lattner8394d792007-06-05 20:53:16 +0000140 RValue ER;
Chris Lattner4647a212007-08-31 22:49:20 +0000141 ER.V1 = V;
142 ER.Flavor = Aggregate;
Chris Lattner208ae962007-05-30 17:57:17 +0000143 return ER;
144 }
145};
Chris Lattnerd7f58862007-06-02 05:24:33 +0000146
147
148/// LValue - This represents an lvalue references. Because C/C++ allow
149/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
150/// bitrange.
151class LValue {
Eli Friedman327944b2008-06-13 23:01:12 +0000152 // FIXME: alignment?
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000153
154 enum {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000155 Simple, // This is a normal l-value, use getAddress().
156 VectorElt, // This is a vector element l-value (V[i]), use getVector*
157 BitField, // This is a bitfield l-value, use getBitfield*.
Nate Begemance4d7fc2008-04-18 23:10:10 +0000158 ExtVectorElt // This is an extended vector subset, use getExtVectorComp
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000159 } LVType;
160
Chris Lattnerd7f58862007-06-02 05:24:33 +0000161 llvm::Value *V;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000162
163 union {
Nate Begemanf322eab2008-05-09 06:41:27 +0000164 // Index into a vector subscript: V[i]
165 llvm::Value *VectorIdx;
166
167 // ExtVector element subset: V.xyx
168 llvm::Constant *VectorElts;
169
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000170 struct {
171 unsigned short StartBit;
172 unsigned short Size;
173 bool IsSigned;
174 } BitfieldData; // BitField start bit and size
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000175 };
Eli Friedman327944b2008-06-13 23:01:12 +0000176
177 bool Volatile:1;
178 // FIXME: set but never used, what effect should it have?
179 bool Restrict:1;
180
181private:
182 static void SetQualifiers(unsigned Qualifiers, LValue& R) {
183 R.Volatile = (Qualifiers&QualType::Volatile)!=0;
184 R.Restrict = (Qualifiers&QualType::Restrict)!=0;
185 }
186
Chris Lattnerd7f58862007-06-02 05:24:33 +0000187public:
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000188 bool isSimple() const { return LVType == Simple; }
189 bool isVectorElt() const { return LVType == VectorElt; }
190 bool isBitfield() const { return LVType == BitField; }
Nate Begemance4d7fc2008-04-18 23:10:10 +0000191 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Chris Lattner208ae962007-05-30 17:57:17 +0000192
Eli Friedman327944b2008-06-13 23:01:12 +0000193 bool isVolatileQualified() const { return Volatile; }
194 bool isRestrictQualified() const { return Restrict; }
195
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000196 // simple lvalue
197 llvm::Value *getAddress() const { assert(isSimple()); return V; }
198 // vector elt lvalue
199 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
200 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Nate Begemance4d7fc2008-04-18 23:10:10 +0000201 // extended vector elements.
202 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
Nate Begemanf322eab2008-05-09 06:41:27 +0000203 llvm::Constant *getExtVectorElts() const {
Nate Begemance4d7fc2008-04-18 23:10:10 +0000204 assert(isExtVectorElt());
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000205 return VectorElts;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000206 }
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000207 // bitfield lvalue
208 llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; }
209 unsigned short getBitfieldStartBit() const {
210 assert(isBitfield());
211 return BitfieldData.StartBit;
212 }
213 unsigned short getBitfieldSize() const {
214 assert(isBitfield());
215 return BitfieldData.Size;
216 }
217 bool isBitfieldSigned() const {
218 assert(isBitfield());
219 return BitfieldData.IsSigned;
220 }
221
Eli Friedman327944b2008-06-13 23:01:12 +0000222 static LValue MakeAddr(llvm::Value *V, unsigned Qualifiers) {
Chris Lattnerd7f58862007-06-02 05:24:33 +0000223 LValue R;
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000224 R.LVType = Simple;
Chris Lattnerd7f58862007-06-02 05:24:33 +0000225 R.V = V;
Eli Friedman327944b2008-06-13 23:01:12 +0000226 SetQualifiers(Qualifiers,R);
Chris Lattnerd7f58862007-06-02 05:24:33 +0000227 return R;
228 }
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000229
Eli Friedman327944b2008-06-13 23:01:12 +0000230 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
231 unsigned Qualifiers) {
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000232 LValue R;
233 R.LVType = VectorElt;
234 R.V = Vec;
235 R.VectorIdx = Idx;
Eli Friedman327944b2008-06-13 23:01:12 +0000236 SetQualifiers(Qualifiers,R);
Chris Lattner08c4b9f2007-07-10 21:17:59 +0000237 return R;
238 }
239
Eli Friedman327944b2008-06-13 23:01:12 +0000240 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
241 unsigned Qualifiers) {
Chris Lattner9e751ca2007-08-02 23:37:31 +0000242 LValue R;
Nate Begemance4d7fc2008-04-18 23:10:10 +0000243 R.LVType = ExtVectorElt;
Chris Lattner9e751ca2007-08-02 23:37:31 +0000244 R.V = Vec;
Nate Begemanf322eab2008-05-09 06:41:27 +0000245 R.VectorElts = Elts;
Eli Friedman327944b2008-06-13 23:01:12 +0000246 SetQualifiers(Qualifiers,R);
Chris Lattner9e751ca2007-08-02 23:37:31 +0000247 return R;
248 }
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000249
250 static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
Eli Friedman327944b2008-06-13 23:01:12 +0000251 unsigned short Size, bool IsSigned,
252 unsigned Qualifiers) {
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000253 LValue R;
254 R.LVType = BitField;
255 R.V = V;
256 R.BitfieldData.StartBit = StartBit;
257 R.BitfieldData.Size = Size;
258 R.BitfieldData.IsSigned = IsSigned;
Eli Friedman327944b2008-06-13 23:01:12 +0000259 SetQualifiers(Qualifiers,R);
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000260 return R;
261 }
Chris Lattnerd7f58862007-06-02 05:24:33 +0000262};
263
Chris Lattnerbed31442007-05-28 01:07:47 +0000264/// CodeGenFunction - This class organizes the per-function state that is used
265/// while generating LLVM code.
266class CodeGenFunction {
Chris Lattnerbda69f82007-08-26 23:13:56 +0000267public:
Chris Lattnerbed31442007-05-28 01:07:47 +0000268 CodeGenModule &CGM; // Per-module state.
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000269 TargetInfo &Target;
Chris Lattnerbda69f82007-08-26 23:13:56 +0000270
Chris Lattner96d72562007-08-21 16:57:55 +0000271 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
Chris Lattner61705c12008-04-13 07:32:11 +0000272 llvm::IRBuilder Builder;
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000273
Chris Lattner5506f8c2008-04-04 04:07:35 +0000274 // Holds the Decl for the current function or method
Eli Friedmane53d1532008-05-22 01:16:59 +0000275 const FunctionDecl *CurFuncDecl;
Chris Lattner4bd55962008-03-30 23:03:07 +0000276 QualType FnRetTy;
Chris Lattnerac248202007-05-30 00:13:02 +0000277 llvm::Function *CurFn;
278
Chris Lattner03df1222007-06-02 04:53:11 +0000279 /// AllocaInsertPoint - This is an instruction in the entry block before which
280 /// we prefer to insert allocas.
281 llvm::Instruction *AllocaInsertPt;
282
Chris Lattner6db1fb82007-06-02 22:49:07 +0000283 const llvm::Type *LLVMIntTy;
Hartmut Kaiser7078da82007-10-17 15:00:17 +0000284 uint32_t LLVMPointerWidth;
Chris Lattner6db1fb82007-06-02 22:49:07 +0000285
Chris Lattner2da04b32007-08-24 05:35:26 +0000286private:
Chris Lattner84915fa2007-06-02 04:16:21 +0000287 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
288 /// decls.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000289 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
Chris Lattner84915fa2007-06-02 04:16:21 +0000290
Chris Lattnerac248202007-05-30 00:13:02 +0000291 /// LabelMap - This keeps track of the LLVM basic block for each C label.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000292 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
Chris Lattnere73e4322007-07-16 21:28:45 +0000293
294 // BreakContinueStack - This keeps track of where break and continue
295 // statements should jump to.
296 struct BreakContinue {
297 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
298 : BreakBlock(bb), ContinueBlock(cb) {}
299
300 llvm::BasicBlock *BreakBlock;
301 llvm::BasicBlock *ContinueBlock;
302 };
303 llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
304
Devang Patel49a44f32007-10-09 17:08:50 +0000305 /// SwitchInsn - This is nearest current switch instruction. It is null if
306 /// if current context is not in a switch.
Devang Patelda5d6bb2007-10-04 23:45:31 +0000307 llvm::SwitchInst *SwitchInsn;
308
Devang Patel49a44f32007-10-09 17:08:50 +0000309 /// CaseRangeBlock - This block holds if condition check for last case
310 /// statement range in current switch instruction.
Devang Patel11663122007-10-08 20:57:48 +0000311 llvm::BasicBlock *CaseRangeBlock;
312
Chris Lattnerbed31442007-05-28 01:07:47 +0000313public:
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000314 CodeGenFunction(CodeGenModule &cgm);
Chris Lattnerbed31442007-05-28 01:07:47 +0000315
Chris Lattner6db1fb82007-06-02 22:49:07 +0000316 ASTContext &getContext() const;
317
Chris Lattner4bd55962008-03-30 23:03:07 +0000318 void GenerateObjCMethod(const ObjCMethodDecl *OMD);
Chris Lattner308f4312007-05-29 23:50:05 +0000319 void GenerateCode(const FunctionDecl *FD);
320
Chris Lattnerf033c142007-06-22 19:05:19 +0000321 const llvm::Type *ConvertType(QualType T);
Chris Lattner5506f8c2008-04-04 04:07:35 +0000322
323 llvm::Value *LoadObjCSelf();
Chris Lattnerac248202007-05-30 00:13:02 +0000324
Chris Lattner54fb19e2007-06-22 22:02:34 +0000325 /// hasAggregateLLVMType - Return true if the specified AST type will map into
326 /// an aggregate LLVM type or is void.
327 static bool hasAggregateLLVMType(QualType T);
328
Chris Lattnerac248202007-05-30 00:13:02 +0000329 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
330 /// label maps to.
331 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
332
333
Chris Lattner23b7eb62007-06-15 23:05:46 +0000334 void EmitBlock(llvm::BasicBlock *BB);
Chris Lattnerfc944342007-12-02 01:43:38 +0000335
336 /// WarnUnsupported - Print out a warning that codegen doesn't support the
337 /// specified stmt yet.
Chris Lattnerf0780fa2007-12-02 01:49:16 +0000338 void WarnUnsupported(const Stmt *S, const char *Type);
Chris Lattner84915fa2007-06-02 04:16:21 +0000339
Chris Lattnere9a64532007-06-22 21:44:33 +0000340 //===--------------------------------------------------------------------===//
341 // Helpers
342 //===--------------------------------------------------------------------===//
343
344 /// CreateTempAlloca - This creates a alloca and inserts it into the entry
345 /// block.
346 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
347 const char *Name = "tmp");
348
Chris Lattner8394d792007-06-05 20:53:16 +0000349 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
350 /// expression and compare the result against zero, returning an Int1Ty value.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000351 llvm::Value *EvaluateExprAsBool(const Expr *E);
Chris Lattnere9a64532007-06-22 21:44:33 +0000352
Chris Lattner4647a212007-08-31 22:49:20 +0000353 /// EmitAnyExpr - Emit code to compute the specified expression which can have
354 /// any type. The result is returned as an RValue struct. If this is an
355 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
356 /// the result should be returned.
357 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
358 bool isAggLocVolatile = false);
Devang Patel8ec4f832007-09-28 21:49:18 +0000359
360 /// isDummyBlock - Return true if BB is an empty basic block
361 /// with no predecessors.
362 static bool isDummyBlock(const llvm::BasicBlock *BB);
363
Devang Patelda5d6bb2007-10-04 23:45:31 +0000364 /// StartBlock - Start new block named N. If insert block is a dummy block
365 /// then reuse it.
366 void StartBlock(const char *N);
367
Devang Patele11664a2007-11-01 19:11:01 +0000368 /// getCGRecordLayout - Return record layout info.
369 const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
Lauro Ramos Venancio01a72ff2008-02-26 21:41:45 +0000370
371 /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
Steve Naroff08899ff2008-04-15 22:42:06 +0000372 llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
Dan Gohman75d69da2008-05-22 00:50:06 +0000373
374 /// getAccessedFieldNo - Given an encoded value and a result number, return
375 /// the input field number being accessed.
376 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
377
Chris Lattner8394d792007-06-05 20:53:16 +0000378 //===--------------------------------------------------------------------===//
Chris Lattner53621a52007-06-13 20:44:40 +0000379 // Declaration Emission
Chris Lattner84915fa2007-06-02 04:16:21 +0000380 //===--------------------------------------------------------------------===//
381
Chris Lattner1ad38f82007-06-09 01:20:56 +0000382 void EmitDecl(const Decl &D);
Chris Lattner84915fa2007-06-02 04:16:21 +0000383 void EmitEnumConstantDecl(const EnumConstantDecl &D);
Steve Naroff08899ff2008-04-15 22:42:06 +0000384 void EmitBlockVarDecl(const VarDecl &D);
385 void EmitLocalBlockVarDecl(const VarDecl &D);
386 void EmitStaticBlockVarDecl(const VarDecl &D);
Chris Lattner53621a52007-06-13 20:44:40 +0000387 void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
Chris Lattner03df1222007-06-02 04:53:11 +0000388
Chris Lattner84915fa2007-06-02 04:16:21 +0000389 //===--------------------------------------------------------------------===//
Chris Lattner308f4312007-05-29 23:50:05 +0000390 // Statement Emission
391 //===--------------------------------------------------------------------===//
392
393 void EmitStmt(const Stmt *S);
Chris Lattner4647a212007-08-31 22:49:20 +0000394 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
395 llvm::Value *AggLoc = 0, bool isAggVol = false);
Chris Lattnerac248202007-05-30 00:13:02 +0000396 void EmitLabelStmt(const LabelStmt &S);
397 void EmitGotoStmt(const GotoStmt &S);
Chris Lattner5269c032007-05-30 21:03:58 +0000398 void EmitIfStmt(const IfStmt &S);
Chris Lattner946aa312007-06-05 03:59:43 +0000399 void EmitWhileStmt(const WhileStmt &S);
Chris Lattner8394d792007-06-05 20:53:16 +0000400 void EmitDoStmt(const DoStmt &S);
401 void EmitForStmt(const ForStmt &S);
Chris Lattner3f3dbee2007-06-02 03:19:07 +0000402 void EmitReturnStmt(const ReturnStmt &S);
Chris Lattner1ad38f82007-06-09 01:20:56 +0000403 void EmitDeclStmt(const DeclStmt &S);
Chris Lattnere73e4322007-07-16 21:28:45 +0000404 void EmitBreakStmt();
405 void EmitContinueStmt();
Devang Patelda5d6bb2007-10-04 23:45:31 +0000406 void EmitSwitchStmt(const SwitchStmt &S);
407 void EmitDefaultStmt(const DefaultStmt &S);
408 void EmitCaseStmt(const CaseStmt &S);
Devang Patel11663122007-10-08 20:57:48 +0000409 void EmitCaseStmtRange(const CaseStmt &S);
Anders Carlsson952a9952008-02-05 16:35:33 +0000410 void EmitAsmStmt(const AsmStmt &S);
411
Chris Lattner208ae962007-05-30 17:57:17 +0000412 //===--------------------------------------------------------------------===//
Chris Lattnerd7f58862007-06-02 05:24:33 +0000413 // LValue Expression Emission
414 //===--------------------------------------------------------------------===//
Chris Lattner8394d792007-06-05 20:53:16 +0000415
416 /// EmitLValue - Emit code to compute a designator that specifies the location
417 /// of the expression.
418 ///
419 /// This can return one of two things: a simple address or a bitfield
420 /// reference. In either case, the LLVM Value* in the LValue structure is
421 /// guaranteed to be an LLVM pointer type.
422 ///
423 /// If this returns a bitfield reference, nothing about the pointee type of
424 /// the LLVM value is known: For example, it may not be a pointer to an
425 /// integer.
426 ///
427 /// If this returns a normal address, and if the lvalue's C type is fixed
428 /// size, this method guarantees that the returned pointer type will point to
429 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a
430 /// variable length type, this is not possible.
431 ///
Chris Lattnerd7f58862007-06-02 05:24:33 +0000432 LValue EmitLValue(const Expr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000433
434 /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
435 /// this method emits the address of the lvalue, then loads the result as an
436 /// rvalue, returning the rvalue.
Chris Lattner9369a562007-06-29 16:31:29 +0000437 RValue EmitLoadOfLValue(LValue V, QualType LVType);
Nate Begemance4d7fc2008-04-18 23:10:10 +0000438 RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
Lauro Ramos Venancio2ddcb25a32008-01-22 20:17:04 +0000439 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
Chris Lattner9369a562007-06-29 16:31:29 +0000440
Chris Lattner40ff7012007-08-03 16:18:34 +0000441
Chris Lattner8394d792007-06-05 20:53:16 +0000442 /// EmitStoreThroughLValue - Store the specified rvalue into the specified
443 /// lvalue, where both are guaranteed to the have the same type, and that type
444 /// is 'Ty'.
445 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
Nate Begemance4d7fc2008-04-18 23:10:10 +0000446 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
447 QualType Ty);
Lauro Ramos Venancio09af71c2008-01-22 22:36:45 +0000448 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
Christopher Lambd91c3d42007-12-29 05:02:41 +0000449
450 // Note: only availabe for agg return types
451 LValue EmitCallExprLValue(const CallExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000452
Chris Lattnerd7f58862007-06-02 05:24:33 +0000453 LValue EmitDeclRefLValue(const DeclRefExpr *E);
Chris Lattner4347e3692007-06-06 04:54:52 +0000454 LValue EmitStringLiteralLValue(const StringLiteral *E);
Anders Carlsson625bfc82007-07-21 05:21:51 +0000455 LValue EmitPreDefinedLValue(const PreDefinedExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000456 LValue EmitUnaryOpLValue(const UnaryOperator *E);
Chris Lattnerd9d2fb12007-06-08 23:31:14 +0000457 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
Nate Begemance4d7fc2008-04-18 23:10:10 +0000458 LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
Devang Patel3e11cce2007-10-23 02:10:49 +0000459 LValue EmitMemberExpr(const MemberExpr *E);
Eli Friedman9fd8b682008-05-13 23:18:27 +0000460 LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
Eli Friedmana62f3e12008-02-09 08:50:58 +0000461
462 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
Eli Friedman327944b2008-06-13 23:01:12 +0000463 bool isUnion, unsigned CVRQualifiers);
Chris Lattner4bd55962008-03-30 23:03:07 +0000464
465 LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
Chris Lattnerd7f58862007-06-02 05:24:33 +0000466 //===--------------------------------------------------------------------===//
Chris Lattner6278e6a2007-08-11 00:04:45 +0000467 // Scalar Expression Emission
Chris Lattner208ae962007-05-30 17:57:17 +0000468 //===--------------------------------------------------------------------===//
469
Chris Lattner2b228c92007-06-15 21:34:29 +0000470 RValue EmitCallExpr(const CallExpr *E);
Eli Friedman9d92ce82008-01-30 01:32:06 +0000471 RValue EmitCallExpr(Expr *FnExpr, Expr *const *Args, unsigned NumArgs);
472 RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
473 Expr *const *Args, unsigned NumArgs);
Chris Lattner6c555f92007-08-26 22:58:05 +0000474 RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
Chris Lattner8394d792007-06-05 20:53:16 +0000475
Anders Carlsson895af082007-12-09 23:17:02 +0000476 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
477 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
478
Anders Carlssonb9eb82c2007-12-10 19:35:18 +0000479 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
Nate Begeman330aaa72007-12-30 02:59:45 +0000480 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
481 bool isSplat = false);
Anders Carlssonf5f65442007-12-15 21:23:30 +0000482
Chris Lattner2da04b32007-08-24 05:35:26 +0000483 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Anders Carlsson76f4a902007-08-21 17:43:55 +0000484
Chris Lattner6278e6a2007-08-11 00:04:45 +0000485 //===--------------------------------------------------------------------===//
Chris Lattnerbda69f82007-08-26 23:13:56 +0000486 // Expression Emission
Chris Lattner6278e6a2007-08-11 00:04:45 +0000487 //===--------------------------------------------------------------------===//
Chris Lattnerbda69f82007-08-26 23:13:56 +0000488
489 // Expressions are broken into three classes: scalar, complex, aggregate.
Chris Lattner6278e6a2007-08-11 00:04:45 +0000490
Chris Lattner2da04b32007-08-24 05:35:26 +0000491 /// EmitScalarExpr - Emit the computation of the specified expression of
492 /// LLVM scalar type, returning the result.
493 llvm::Value *EmitScalarExpr(const Expr *E);
494
Chris Lattner3474c202007-08-26 06:48:56 +0000495 /// EmitScalarConversion - Emit a conversion from the specified type to the
496 /// specified destination type, both of which are LLVM scalar types.
497 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
498 QualType DstTy);
499
Chris Lattner42e6b812007-08-26 16:34:22 +0000500 /// EmitComplexToScalarConversion - Emit a conversion from the specified
501 /// complex type to the specified destination type, where the destination
502 /// type is an LLVM scalar type.
503 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
504 QualType DstTy);
505
Chris Lattner3474c202007-08-26 06:48:56 +0000506
Chris Lattner6278e6a2007-08-11 00:04:45 +0000507 /// EmitAggExpr - Emit the computation of the specified expression of
508 /// aggregate type. The result is computed into DestPtr. Note that if
509 /// DestPtr is null, the value of the aggregate expression is not needed.
510 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
Chris Lattnercbfc73b2007-08-21 05:54:00 +0000511
512 /// EmitComplexExpr - Emit the computation of the specified expression of
Chris Lattner08b15df2007-08-23 23:43:33 +0000513 /// complex type, returning the result.
Chris Lattner96d72562007-08-21 16:57:55 +0000514 ComplexPairTy EmitComplexExpr(const Expr *E);
Chris Lattner08b15df2007-08-23 23:43:33 +0000515
516 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
517 /// of complex type, storing into the specified Value*.
Chris Lattnerb84bb952007-08-26 16:22:13 +0000518 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
519 bool DestIsVolatile);
Chris Lattner4647a212007-08-31 22:49:20 +0000520 /// LoadComplexFromAddr - Load a complex number from the specified address.
521 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
Chris Lattnerb781dc792008-05-08 05:58:21 +0000522
523 /// GenerateStaticBlockVarDecl - return the the static
524 /// declaration of local variable.
525 llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D,
526 bool NoInit,
527 const char *Separator);
Chris Lattnerbed31442007-05-28 01:07:47 +0000528};
529} // end namespace CodeGen
530} // end namespace clang
Chris Lattnerbed31442007-05-28 01:07:47 +0000531
532#endif