Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is the internal per-function state used for llvm translation. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CODEGEN_CODEGENFUNCTION_H |
| 15 | #define CODEGEN_CODEGENFUNCTION_H |
| 16 | |
| 17 | #include "llvm/ADT/DenseMap.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include "llvm/Support/LLVMBuilder.h" |
| 20 | #include <vector> |
| 21 | |
| 22 | namespace llvm { |
| 23 | class Module; |
| 24 | } |
| 25 | |
| 26 | namespace 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 Patel | e58e080 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 44 | class CaseStmt; |
| 45 | class DefaultStmt; |
| 46 | class SwitchStmt; |
Anders Carlsson | af6a6c2 | 2008-02-05 16:35:33 +0000 | [diff] [blame] | 47 | class AsmStmt; |
| 48 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 49 | class Expr; |
| 50 | class DeclRefExpr; |
| 51 | class StringLiteral; |
| 52 | class IntegerLiteral; |
| 53 | class FloatingLiteral; |
| 54 | class CharacterLiteral; |
Chris Lattner | 4ca7e75 | 2007-08-03 17:51:03 +0000 | [diff] [blame] | 55 | class TypesCompatibleExpr; |
| 56 | |
Chris Lattner | b2cb9cb | 2007-08-20 22:37:10 +0000 | [diff] [blame] | 57 | class ImplicitCastExpr; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 58 | class CastExpr; |
| 59 | class CallExpr; |
| 60 | class UnaryOperator; |
| 61 | class BinaryOperator; |
| 62 | class CompoundAssignOperator; |
| 63 | class ArraySubscriptExpr; |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 64 | class OCUVectorElementExpr; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 65 | class ConditionalOperator; |
Chris Lattner | 44fcf4f | 2007-08-04 00:20:15 +0000 | [diff] [blame] | 66 | class ChooseExpr; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 67 | class PreDefinedExpr; |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 68 | class ObjCStringLiteral; |
Devang Patel | aebd83f | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 69 | class MemberExpr; |
| 70 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 71 | class BlockVarDecl; |
| 72 | class EnumConstantDecl; |
| 73 | class ParmVarDecl; |
| 74 | namespace CodeGen { |
| 75 | class CodeGenModule; |
Devang Patel | aebd83f | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 76 | class CodeGenTypes; |
Devang Patel | 7a78e43 | 2007-11-01 19:11:01 +0000 | [diff] [blame] | 77 | class CGRecordLayout; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 78 | |
| 79 | /// RValue - This trivial value class is used to represent the result of an |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 80 | /// expression that is evaluated. It can be one of three things: either a |
| 81 | /// simple LLVM SSA value, a pair of SSA values for complex numbers, or the |
| 82 | /// address of an aggregate value in memory. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 83 | class RValue { |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 84 | llvm::Value *V1, *V2; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 85 | // TODO: Encode this into the low bit of pointer for more efficient |
| 86 | // return-by-value. |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 87 | enum { Scalar, Complex, Aggregate } Flavor; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 88 | |
| 89 | // FIXME: Aggregate rvalues need to retain information about whether they are |
| 90 | // volatile or not. |
| 91 | public: |
| 92 | |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 93 | bool isScalar() const { return Flavor == Scalar; } |
| 94 | bool isComplex() const { return Flavor == Complex; } |
| 95 | bool isAggregate() const { return Flavor == Aggregate; } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 96 | |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 97 | /// getScalar() - Return the Value* of this scalar value. |
| 98 | llvm::Value *getScalarVal() const { |
| 99 | assert(isScalar() && "Not a scalar!"); |
| 100 | return V1; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 103 | /// getComplexVal - Return the real/imag components of this complex value. |
| 104 | /// |
| 105 | std::pair<llvm::Value *, llvm::Value *> getComplexVal() const { |
| 106 | return std::pair<llvm::Value *, llvm::Value *>(V1, V2); |
| 107 | } |
| 108 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 109 | /// getAggregateAddr() - Return the Value* of the address of the aggregate. |
| 110 | llvm::Value *getAggregateAddr() const { |
| 111 | assert(isAggregate() && "Not an aggregate!"); |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 112 | return V1; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static RValue get(llvm::Value *V) { |
| 116 | RValue ER; |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 117 | ER.V1 = V; |
| 118 | ER.Flavor = Scalar; |
| 119 | return ER; |
| 120 | } |
| 121 | static RValue getComplex(llvm::Value *V1, llvm::Value *V2) { |
| 122 | RValue ER; |
| 123 | ER.V1 = V1; |
| 124 | ER.V2 = V2; |
| 125 | ER.Flavor = Complex; |
| 126 | return ER; |
| 127 | } |
| 128 | static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) { |
| 129 | RValue ER; |
| 130 | ER.V1 = C.first; |
| 131 | ER.V2 = C.second; |
| 132 | ER.Flavor = Complex; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 133 | return ER; |
| 134 | } |
| 135 | static RValue getAggregate(llvm::Value *V) { |
| 136 | RValue ER; |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 137 | ER.V1 = V; |
| 138 | ER.Flavor = Aggregate; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 139 | return ER; |
| 140 | } |
| 141 | }; |
| 142 | |
| 143 | |
| 144 | /// LValue - This represents an lvalue references. Because C/C++ allow |
| 145 | /// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a |
| 146 | /// bitrange. |
| 147 | class LValue { |
| 148 | // FIXME: Volatility. Restrict? |
| 149 | // alignment? |
| 150 | |
| 151 | enum { |
Chris Lattner | 6552019 | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 152 | Simple, // This is a normal l-value, use getAddress(). |
| 153 | VectorElt, // This is a vector element l-value (V[i]), use getVector* |
| 154 | BitField, // This is a bitfield l-value, use getBitfield*. |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 155 | OCUVectorElt // This is an ocu vector subset, use getOCUVectorComp |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 156 | } LVType; |
| 157 | |
| 158 | llvm::Value *V; |
| 159 | |
| 160 | union { |
Chris Lattner | 6552019 | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 161 | llvm::Value *VectorIdx; // Index into a vector subscript: V[i] |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 162 | unsigned VectorElts; // Encoded OCUVector element subset: V.xyx |
Lauro Ramos Venancio | b40307c | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 163 | struct { |
| 164 | unsigned short StartBit; |
| 165 | unsigned short Size; |
| 166 | bool IsSigned; |
| 167 | } BitfieldData; // BitField start bit and size |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 168 | }; |
| 169 | public: |
| 170 | bool isSimple() const { return LVType == Simple; } |
| 171 | bool isVectorElt() const { return LVType == VectorElt; } |
| 172 | bool isBitfield() const { return LVType == BitField; } |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 173 | bool isOCUVectorElt() const { return LVType == OCUVectorElt; } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 174 | |
| 175 | // simple lvalue |
| 176 | llvm::Value *getAddress() const { assert(isSimple()); return V; } |
| 177 | // vector elt lvalue |
| 178 | llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; } |
| 179 | llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; } |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 180 | // ocu vector elements. |
| 181 | llvm::Value *getOCUVectorAddr() const { assert(isOCUVectorElt()); return V; } |
| 182 | unsigned getOCUVectorElts() const { |
| 183 | assert(isOCUVectorElt()); |
| 184 | return VectorElts; |
Chris Lattner | 6552019 | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 185 | } |
Lauro Ramos Venancio | b40307c | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 186 | // bitfield lvalue |
| 187 | llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; } |
| 188 | unsigned short getBitfieldStartBit() const { |
| 189 | assert(isBitfield()); |
| 190 | return BitfieldData.StartBit; |
| 191 | } |
| 192 | unsigned short getBitfieldSize() const { |
| 193 | assert(isBitfield()); |
| 194 | return BitfieldData.Size; |
| 195 | } |
| 196 | bool isBitfieldSigned() const { |
| 197 | assert(isBitfield()); |
| 198 | return BitfieldData.IsSigned; |
| 199 | } |
| 200 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 201 | static LValue MakeAddr(llvm::Value *V) { |
| 202 | LValue R; |
| 203 | R.LVType = Simple; |
| 204 | R.V = V; |
| 205 | return R; |
| 206 | } |
| 207 | |
| 208 | static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx) { |
| 209 | LValue R; |
| 210 | R.LVType = VectorElt; |
| 211 | R.V = Vec; |
| 212 | R.VectorIdx = Idx; |
| 213 | return R; |
| 214 | } |
| 215 | |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 216 | static LValue MakeOCUVectorElt(llvm::Value *Vec, unsigned Elements) { |
Chris Lattner | 6552019 | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 217 | LValue R; |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 218 | R.LVType = OCUVectorElt; |
Chris Lattner | 6552019 | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 219 | R.V = Vec; |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 220 | R.VectorElts = Elements; |
Chris Lattner | 6552019 | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 221 | return R; |
| 222 | } |
Lauro Ramos Venancio | b40307c | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 223 | |
| 224 | static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit, |
| 225 | unsigned short Size, bool IsSigned) { |
| 226 | LValue R; |
| 227 | R.LVType = BitField; |
| 228 | R.V = V; |
| 229 | R.BitfieldData.StartBit = StartBit; |
| 230 | R.BitfieldData.Size = Size; |
| 231 | R.BitfieldData.IsSigned = IsSigned; |
| 232 | return R; |
| 233 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | /// CodeGenFunction - This class organizes the per-function state that is used |
| 237 | /// while generating LLVM code. |
| 238 | class CodeGenFunction { |
Chris Lattner | 41b1fca | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 239 | public: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 240 | CodeGenModule &CGM; // Per-module state. |
| 241 | TargetInfo &Target; |
Chris Lattner | 41b1fca | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 242 | |
Chris Lattner | 5280c5f | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 243 | typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; |
Devang Patel | 638b64c | 2007-10-09 19:49:58 +0000 | [diff] [blame] | 244 | llvm::LLVMFoldingBuilder Builder; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 245 | |
| 246 | const FunctionDecl *CurFuncDecl; |
| 247 | llvm::Function *CurFn; |
| 248 | |
| 249 | /// AllocaInsertPoint - This is an instruction in the entry block before which |
| 250 | /// we prefer to insert allocas. |
| 251 | llvm::Instruction *AllocaInsertPt; |
| 252 | |
| 253 | const llvm::Type *LLVMIntTy; |
Hartmut Kaiser | ff08d2c | 2007-10-17 15:00:17 +0000 | [diff] [blame] | 254 | uint32_t LLVMPointerWidth; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 255 | |
Chris Lattner | 9fba49a | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 256 | private: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 257 | /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C |
| 258 | /// decls. |
| 259 | llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; |
| 260 | |
| 261 | /// LabelMap - This keeps track of the LLVM basic block for each C label. |
| 262 | llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap; |
| 263 | |
| 264 | // BreakContinueStack - This keeps track of where break and continue |
| 265 | // statements should jump to. |
| 266 | struct BreakContinue { |
| 267 | BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb) |
| 268 | : BreakBlock(bb), ContinueBlock(cb) {} |
| 269 | |
| 270 | llvm::BasicBlock *BreakBlock; |
| 271 | llvm::BasicBlock *ContinueBlock; |
| 272 | }; |
| 273 | llvm::SmallVector<BreakContinue, 8> BreakContinueStack; |
| 274 | |
Devang Patel | bc37238 | 2007-10-09 17:08:50 +0000 | [diff] [blame] | 275 | /// SwitchInsn - This is nearest current switch instruction. It is null if |
| 276 | /// if current context is not in a switch. |
Devang Patel | e58e080 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 277 | llvm::SwitchInst *SwitchInsn; |
| 278 | |
Devang Patel | bc37238 | 2007-10-09 17:08:50 +0000 | [diff] [blame] | 279 | /// CaseRangeBlock - This block holds if condition check for last case |
| 280 | /// statement range in current switch instruction. |
Devang Patel | 347ca32 | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 281 | llvm::BasicBlock *CaseRangeBlock; |
| 282 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 283 | public: |
| 284 | CodeGenFunction(CodeGenModule &cgm); |
| 285 | |
| 286 | ASTContext &getContext() const; |
| 287 | |
| 288 | void GenerateCode(const FunctionDecl *FD); |
| 289 | |
| 290 | const llvm::Type *ConvertType(QualType T); |
| 291 | |
| 292 | /// hasAggregateLLVMType - Return true if the specified AST type will map into |
| 293 | /// an aggregate LLVM type or is void. |
| 294 | static bool hasAggregateLLVMType(QualType T); |
| 295 | |
| 296 | /// getBasicBlockForLabel - Return the LLVM basicblock that the specified |
| 297 | /// label maps to. |
| 298 | llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S); |
| 299 | |
| 300 | |
| 301 | void EmitBlock(llvm::BasicBlock *BB); |
Chris Lattner | 9d4e620 | 2007-12-02 01:43:38 +0000 | [diff] [blame] | 302 | |
| 303 | /// WarnUnsupported - Print out a warning that codegen doesn't support the |
| 304 | /// specified stmt yet. |
Chris Lattner | e8f4963 | 2007-12-02 01:49:16 +0000 | [diff] [blame] | 305 | void WarnUnsupported(const Stmt *S, const char *Type); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 306 | |
| 307 | //===--------------------------------------------------------------------===// |
| 308 | // Helpers |
| 309 | //===--------------------------------------------------------------------===// |
| 310 | |
| 311 | /// CreateTempAlloca - This creates a alloca and inserts it into the entry |
| 312 | /// block. |
| 313 | llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, |
| 314 | const char *Name = "tmp"); |
| 315 | |
| 316 | /// EvaluateExprAsBool - Perform the usual unary conversions on the specified |
| 317 | /// expression and compare the result against zero, returning an Int1Ty value. |
| 318 | llvm::Value *EvaluateExprAsBool(const Expr *E); |
| 319 | |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 320 | /// EmitAnyExpr - Emit code to compute the specified expression which can have |
| 321 | /// any type. The result is returned as an RValue struct. If this is an |
| 322 | /// aggregate expression, the aggloc/agglocvolatile arguments indicate where |
| 323 | /// the result should be returned. |
| 324 | RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, |
| 325 | bool isAggLocVolatile = false); |
Devang Patel | 9729936 | 2007-09-28 21:49:18 +0000 | [diff] [blame] | 326 | |
| 327 | /// isDummyBlock - Return true if BB is an empty basic block |
| 328 | /// with no predecessors. |
| 329 | static bool isDummyBlock(const llvm::BasicBlock *BB); |
| 330 | |
Devang Patel | e58e080 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 331 | /// StartBlock - Start new block named N. If insert block is a dummy block |
| 332 | /// then reuse it. |
| 333 | void StartBlock(const char *N); |
| 334 | |
Devang Patel | 7a78e43 | 2007-11-01 19:11:01 +0000 | [diff] [blame] | 335 | /// getCGRecordLayout - Return record layout info. |
| 336 | const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 337 | //===--------------------------------------------------------------------===// |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 338 | // Declaration Emission |
| 339 | //===--------------------------------------------------------------------===// |
| 340 | |
| 341 | void EmitDecl(const Decl &D); |
| 342 | void EmitEnumConstantDecl(const EnumConstantDecl &D); |
| 343 | void EmitBlockVarDecl(const BlockVarDecl &D); |
| 344 | void EmitLocalBlockVarDecl(const BlockVarDecl &D); |
Anders Carlsson | 855d78d | 2007-10-17 00:52:43 +0000 | [diff] [blame] | 345 | void EmitStaticBlockVarDecl(const BlockVarDecl &D); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 346 | void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg); |
| 347 | |
| 348 | //===--------------------------------------------------------------------===// |
| 349 | // Statement Emission |
| 350 | //===--------------------------------------------------------------------===// |
| 351 | |
| 352 | void EmitStmt(const Stmt *S); |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 353 | RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, |
| 354 | llvm::Value *AggLoc = 0, bool isAggVol = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 355 | void EmitLabelStmt(const LabelStmt &S); |
| 356 | void EmitGotoStmt(const GotoStmt &S); |
| 357 | void EmitIfStmt(const IfStmt &S); |
| 358 | void EmitWhileStmt(const WhileStmt &S); |
| 359 | void EmitDoStmt(const DoStmt &S); |
| 360 | void EmitForStmt(const ForStmt &S); |
| 361 | void EmitReturnStmt(const ReturnStmt &S); |
| 362 | void EmitDeclStmt(const DeclStmt &S); |
| 363 | void EmitBreakStmt(); |
| 364 | void EmitContinueStmt(); |
Devang Patel | e58e080 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 365 | void EmitSwitchStmt(const SwitchStmt &S); |
| 366 | void EmitDefaultStmt(const DefaultStmt &S); |
| 367 | void EmitCaseStmt(const CaseStmt &S); |
Devang Patel | 347ca32 | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 368 | void EmitCaseStmtRange(const CaseStmt &S); |
Anders Carlsson | af6a6c2 | 2008-02-05 16:35:33 +0000 | [diff] [blame] | 369 | void EmitAsmStmt(const AsmStmt &S); |
| 370 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 371 | //===--------------------------------------------------------------------===// |
| 372 | // LValue Expression Emission |
| 373 | //===--------------------------------------------------------------------===// |
| 374 | |
| 375 | /// EmitLValue - Emit code to compute a designator that specifies the location |
| 376 | /// of the expression. |
| 377 | /// |
| 378 | /// This can return one of two things: a simple address or a bitfield |
| 379 | /// reference. In either case, the LLVM Value* in the LValue structure is |
| 380 | /// guaranteed to be an LLVM pointer type. |
| 381 | /// |
| 382 | /// If this returns a bitfield reference, nothing about the pointee type of |
| 383 | /// the LLVM value is known: For example, it may not be a pointer to an |
| 384 | /// integer. |
| 385 | /// |
| 386 | /// If this returns a normal address, and if the lvalue's C type is fixed |
| 387 | /// size, this method guarantees that the returned pointer type will point to |
| 388 | /// an LLVM type of the same size of the lvalue's type. If the lvalue has a |
| 389 | /// variable length type, this is not possible. |
| 390 | /// |
| 391 | LValue EmitLValue(const Expr *E); |
| 392 | |
| 393 | /// EmitLoadOfLValue - Given an expression that represents a value lvalue, |
| 394 | /// this method emits the address of the lvalue, then loads the result as an |
| 395 | /// rvalue, returning the rvalue. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 396 | RValue EmitLoadOfLValue(LValue V, QualType LVType); |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 397 | RValue EmitLoadOfOCUElementLValue(LValue V, QualType LVType); |
Lauro Ramos Venancio | b40307c | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 398 | RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 399 | |
Chris Lattner | 944f796 | 2007-08-03 16:18:34 +0000 | [diff] [blame] | 400 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 401 | /// EmitStoreThroughLValue - Store the specified rvalue into the specified |
| 402 | /// lvalue, where both are guaranteed to the have the same type, and that type |
| 403 | /// is 'Ty'. |
| 404 | void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); |
Chris Lattner | 5bfdd23 | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 405 | void EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, QualType Ty); |
Lauro Ramos Venancio | 2d7a34c | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 406 | void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty); |
Christopher Lamb | ad327ba | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 407 | |
| 408 | // Note: only availabe for agg return types |
| 409 | LValue EmitCallExprLValue(const CallExpr *E); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 410 | |
| 411 | LValue EmitDeclRefLValue(const DeclRefExpr *E); |
| 412 | LValue EmitStringLiteralLValue(const StringLiteral *E); |
| 413 | LValue EmitPreDefinedLValue(const PreDefinedExpr *E); |
| 414 | LValue EmitUnaryOpLValue(const UnaryOperator *E); |
| 415 | LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); |
Chris Lattner | a0d03a7 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 416 | LValue EmitOCUVectorElementExpr(const OCUVectorElementExpr *E); |
Devang Patel | aebd83f | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 417 | LValue EmitMemberExpr(const MemberExpr *E); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 418 | |
| 419 | //===--------------------------------------------------------------------===// |
Chris Lattner | bdb8ffb | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 420 | // Scalar Expression Emission |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 421 | //===--------------------------------------------------------------------===// |
| 422 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 423 | RValue EmitCallExpr(const CallExpr *E); |
Eli Friedman | 261f4ad | 2008-01-30 01:32:06 +0000 | [diff] [blame] | 424 | RValue EmitCallExpr(Expr *FnExpr, Expr *const *Args, unsigned NumArgs); |
| 425 | RValue EmitCallExpr(llvm::Value *Callee, QualType FnType, |
| 426 | Expr *const *Args, unsigned NumArgs); |
Chris Lattner | 35055b8 | 2007-08-26 22:58:05 +0000 | [diff] [blame] | 427 | RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 428 | |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 429 | llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 430 | llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 431 | |
Anders Carlsson | a9234fe | 2007-12-10 19:35:18 +0000 | [diff] [blame] | 432 | llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...); |
Nate Begeman | ec2d106 | 2007-12-30 02:59:45 +0000 | [diff] [blame] | 433 | llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals, |
| 434 | bool isSplat = false); |
Anders Carlsson | 68b8be9 | 2007-12-15 21:23:30 +0000 | [diff] [blame] | 435 | |
Chris Lattner | 9fba49a | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 436 | llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 437 | |
Chris Lattner | bdb8ffb | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 438 | //===--------------------------------------------------------------------===// |
Chris Lattner | 41b1fca | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 439 | // Expression Emission |
Chris Lattner | bdb8ffb | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 440 | //===--------------------------------------------------------------------===// |
Chris Lattner | 41b1fca | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 441 | |
| 442 | // Expressions are broken into three classes: scalar, complex, aggregate. |
Chris Lattner | bdb8ffb | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 443 | |
Chris Lattner | 9fba49a | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 444 | /// EmitScalarExpr - Emit the computation of the specified expression of |
| 445 | /// LLVM scalar type, returning the result. |
| 446 | llvm::Value *EmitScalarExpr(const Expr *E); |
| 447 | |
Chris Lattner | 4e05d1e | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 448 | /// EmitScalarConversion - Emit a conversion from the specified type to the |
| 449 | /// specified destination type, both of which are LLVM scalar types. |
| 450 | llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, |
| 451 | QualType DstTy); |
| 452 | |
Chris Lattner | fb182ee | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 453 | /// EmitComplexToScalarConversion - Emit a conversion from the specified |
| 454 | /// complex type to the specified destination type, where the destination |
| 455 | /// type is an LLVM scalar type. |
| 456 | llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, |
| 457 | QualType DstTy); |
| 458 | |
Chris Lattner | 4e05d1e | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 459 | |
Chris Lattner | bdb8ffb | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 460 | /// EmitAggExpr - Emit the computation of the specified expression of |
| 461 | /// aggregate type. The result is computed into DestPtr. Note that if |
| 462 | /// DestPtr is null, the value of the aggregate expression is not needed. |
| 463 | void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest); |
Chris Lattner | 8d0cc2f | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 464 | |
| 465 | /// EmitComplexExpr - Emit the computation of the specified expression of |
Chris Lattner | 348c8a2 | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 466 | /// complex type, returning the result. |
Chris Lattner | 5280c5f | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 467 | ComplexPairTy EmitComplexExpr(const Expr *E); |
Chris Lattner | 348c8a2 | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 468 | |
| 469 | /// EmitComplexExprIntoAddr - Emit the computation of the specified expression |
| 470 | /// of complex type, storing into the specified Value*. |
Chris Lattner | 8e1f6e0 | 2007-08-26 16:22:13 +0000 | [diff] [blame] | 471 | void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, |
| 472 | bool DestIsVolatile); |
Chris Lattner | e24c4cf | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 473 | /// LoadComplexFromAddr - Load a complex number from the specified address. |
| 474 | ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 475 | }; |
| 476 | } // end namespace CodeGen |
| 477 | } // end namespace clang |
| 478 | |
| 479 | #endif |