Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- CodeGenFunction.h - Per-Function state for LLVM CodeGen ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 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. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +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" |
Chris Lattner | da13870 | 2007-07-16 21:28:45 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallVector.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 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 | 51b09f2 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 44 | class CaseStmt; |
| 45 | class DefaultStmt; |
| 46 | class SwitchStmt; |
| 47 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 48 | class Expr; |
| 49 | class DeclRefExpr; |
| 50 | class StringLiteral; |
| 51 | class IntegerLiteral; |
| 52 | class FloatingLiteral; |
Chris Lattner | b0a721a | 2007-07-13 05:18:11 +0000 | [diff] [blame] | 53 | class CharacterLiteral; |
Chris Lattner | 30bf3ae | 2007-08-03 17:51:03 +0000 | [diff] [blame] | 54 | class TypesCompatibleExpr; |
| 55 | |
Chris Lattner | 7016a70 | 2007-08-20 22:37:10 +0000 | [diff] [blame] | 56 | class ImplicitCastExpr; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 57 | class CastExpr; |
| 58 | class CallExpr; |
| 59 | class UnaryOperator; |
| 60 | class BinaryOperator; |
| 61 | class CompoundAssignOperator; |
| 62 | class ArraySubscriptExpr; |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 63 | class OCUVectorElementExpr; |
Chris Lattner | b0a721a | 2007-07-13 05:18:11 +0000 | [diff] [blame] | 64 | class ConditionalOperator; |
Chris Lattner | 94f05e3 | 2007-08-04 00:20:15 +0000 | [diff] [blame] | 65 | class ChooseExpr; |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 66 | class PreDefinedExpr; |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 67 | class ObjCStringLiteral; |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 68 | class MemberExpr; |
| 69 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 70 | class BlockVarDecl; |
| 71 | class EnumConstantDecl; |
| 72 | class ParmVarDecl; |
| 73 | namespace CodeGen { |
| 74 | class CodeGenModule; |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 75 | class CodeGenTypes; |
Devang Patel | 88a981b | 2007-11-01 19:11:01 +0000 | [diff] [blame] | 76 | class CGRecordLayout; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 77 | |
| 78 | /// RValue - This trivial value class is used to represent the result of an |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 79 | /// 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. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 82 | class RValue { |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 83 | llvm::Value *V1, *V2; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 84 | // TODO: Encode this into the low bit of pointer for more efficient |
| 85 | // return-by-value. |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 86 | enum { Scalar, Complex, Aggregate } Flavor; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 87 | |
| 88 | // FIXME: Aggregate rvalues need to retain information about whether they are |
| 89 | // volatile or not. |
| 90 | public: |
| 91 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 92 | bool isScalar() const { return Flavor == Scalar; } |
| 93 | bool isComplex() const { return Flavor == Complex; } |
| 94 | bool isAggregate() const { return Flavor == Aggregate; } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 95 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 96 | /// getScalar() - Return the Value* of this scalar value. |
| 97 | llvm::Value *getScalarVal() const { |
| 98 | assert(isScalar() && "Not a scalar!"); |
| 99 | return V1; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 102 | /// 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 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 108 | /// getAggregateAddr() - Return the Value* of the address of the aggregate. |
| 109 | llvm::Value *getAggregateAddr() const { |
| 110 | assert(isAggregate() && "Not an aggregate!"); |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 111 | return V1; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static RValue get(llvm::Value *V) { |
| 115 | RValue ER; |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 116 | 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; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 132 | return ER; |
| 133 | } |
| 134 | static RValue getAggregate(llvm::Value *V) { |
| 135 | RValue ER; |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 136 | ER.V1 = V; |
| 137 | ER.Flavor = Aggregate; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 138 | 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. |
| 146 | class LValue { |
| 147 | // FIXME: Volatility. Restrict? |
| 148 | // alignment? |
| 149 | |
| 150 | enum { |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 151 | 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 Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 154 | OCUVectorElt // This is an ocu vector subset, use getOCUVectorComp |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 155 | } LVType; |
| 156 | |
| 157 | llvm::Value *V; |
| 158 | |
| 159 | union { |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 160 | llvm::Value *VectorIdx; // Index into a vector subscript: V[i] |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 161 | unsigned VectorElts; // Encoded OCUVector element subset: V.xyx |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 162 | }; |
| 163 | public: |
| 164 | bool isSimple() const { return LVType == Simple; } |
| 165 | bool isVectorElt() const { return LVType == VectorElt; } |
| 166 | bool isBitfield() const { return LVType == BitField; } |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 167 | bool isOCUVectorElt() const { return LVType == OCUVectorElt; } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 168 | |
| 169 | // simple lvalue |
| 170 | llvm::Value *getAddress() const { assert(isSimple()); return V; } |
| 171 | // vector elt lvalue |
| 172 | llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; } |
| 173 | llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; } |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 174 | // ocu vector elements. |
| 175 | llvm::Value *getOCUVectorAddr() const { assert(isOCUVectorElt()); return V; } |
| 176 | unsigned getOCUVectorElts() const { |
| 177 | assert(isOCUVectorElt()); |
| 178 | return VectorElts; |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 181 | |
| 182 | static LValue MakeAddr(llvm::Value *V) { |
| 183 | LValue R; |
| 184 | R.LVType = Simple; |
| 185 | R.V = V; |
| 186 | return R; |
| 187 | } |
| 188 | |
| 189 | static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx) { |
| 190 | LValue R; |
| 191 | R.LVType = VectorElt; |
| 192 | R.V = Vec; |
| 193 | R.VectorIdx = Idx; |
| 194 | return R; |
| 195 | } |
| 196 | |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 197 | static LValue MakeOCUVectorElt(llvm::Value *Vec, unsigned Elements) { |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 198 | LValue R; |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 199 | R.LVType = OCUVectorElt; |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 200 | R.V = Vec; |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 201 | R.VectorElts = Elements; |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 202 | return R; |
| 203 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | /// CodeGenFunction - This class organizes the per-function state that is used |
| 207 | /// while generating LLVM code. |
| 208 | class CodeGenFunction { |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 209 | public: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 210 | CodeGenModule &CGM; // Per-module state. |
| 211 | TargetInfo &Target; |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 212 | |
Chris Lattner | 58dee10 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 213 | typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; |
Devang Patel | 50c9034 | 2007-10-09 19:49:58 +0000 | [diff] [blame] | 214 | llvm::LLVMFoldingBuilder Builder; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 215 | |
| 216 | const FunctionDecl *CurFuncDecl; |
| 217 | llvm::Function *CurFn; |
| 218 | |
| 219 | /// AllocaInsertPoint - This is an instruction in the entry block before which |
| 220 | /// we prefer to insert allocas. |
| 221 | llvm::Instruction *AllocaInsertPt; |
| 222 | |
| 223 | const llvm::Type *LLVMIntTy; |
Hartmut Kaiser | 7b66000 | 2007-10-17 15:00:17 +0000 | [diff] [blame] | 224 | uint32_t LLVMPointerWidth; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 225 | |
Chris Lattner | 7f02f72 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 226 | private: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 227 | /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C |
| 228 | /// decls. |
| 229 | llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; |
| 230 | |
| 231 | /// LabelMap - This keeps track of the LLVM basic block for each C label. |
| 232 | llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap; |
Chris Lattner | da13870 | 2007-07-16 21:28:45 +0000 | [diff] [blame] | 233 | |
| 234 | // BreakContinueStack - This keeps track of where break and continue |
| 235 | // statements should jump to. |
| 236 | struct BreakContinue { |
| 237 | BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb) |
| 238 | : BreakBlock(bb), ContinueBlock(cb) {} |
| 239 | |
| 240 | llvm::BasicBlock *BreakBlock; |
| 241 | llvm::BasicBlock *ContinueBlock; |
| 242 | }; |
| 243 | llvm::SmallVector<BreakContinue, 8> BreakContinueStack; |
| 244 | |
Devang Patel | 80fd5f9 | 2007-10-09 17:08:50 +0000 | [diff] [blame] | 245 | /// SwitchInsn - This is nearest current switch instruction. It is null if |
| 246 | /// if current context is not in a switch. |
Devang Patel | 51b09f2 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 247 | llvm::SwitchInst *SwitchInsn; |
| 248 | |
Devang Patel | 80fd5f9 | 2007-10-09 17:08:50 +0000 | [diff] [blame] | 249 | /// CaseRangeBlock - This block holds if condition check for last case |
| 250 | /// statement range in current switch instruction. |
Devang Patel | c049e4f | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 251 | llvm::BasicBlock *CaseRangeBlock; |
| 252 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 253 | public: |
| 254 | CodeGenFunction(CodeGenModule &cgm); |
| 255 | |
| 256 | ASTContext &getContext() const; |
| 257 | |
| 258 | void GenerateCode(const FunctionDecl *FD); |
| 259 | |
| 260 | const llvm::Type *ConvertType(QualType T); |
| 261 | |
| 262 | /// hasAggregateLLVMType - Return true if the specified AST type will map into |
| 263 | /// an aggregate LLVM type or is void. |
| 264 | static bool hasAggregateLLVMType(QualType T); |
| 265 | |
| 266 | /// getBasicBlockForLabel - Return the LLVM basicblock that the specified |
| 267 | /// label maps to. |
| 268 | llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S); |
| 269 | |
| 270 | |
| 271 | void EmitBlock(llvm::BasicBlock *BB); |
Chris Lattner | dc5e826 | 2007-12-02 01:43:38 +0000 | [diff] [blame] | 272 | |
| 273 | /// WarnUnsupported - Print out a warning that codegen doesn't support the |
| 274 | /// specified stmt yet. |
Chris Lattner | dc4d280 | 2007-12-02 01:49:16 +0000 | [diff] [blame] | 275 | void WarnUnsupported(const Stmt *S, const char *Type); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 276 | |
| 277 | //===--------------------------------------------------------------------===// |
| 278 | // Helpers |
| 279 | //===--------------------------------------------------------------------===// |
| 280 | |
| 281 | /// CreateTempAlloca - This creates a alloca and inserts it into the entry |
| 282 | /// block. |
| 283 | llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, |
| 284 | const char *Name = "tmp"); |
| 285 | |
| 286 | /// EvaluateExprAsBool - Perform the usual unary conversions on the specified |
| 287 | /// expression and compare the result against zero, returning an Int1Ty value. |
| 288 | llvm::Value *EvaluateExprAsBool(const Expr *E); |
| 289 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 290 | /// EmitAnyExpr - Emit code to compute the specified expression which can have |
| 291 | /// any type. The result is returned as an RValue struct. If this is an |
| 292 | /// aggregate expression, the aggloc/agglocvolatile arguments indicate where |
| 293 | /// the result should be returned. |
| 294 | RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, |
| 295 | bool isAggLocVolatile = false); |
Devang Patel | d9363c3 | 2007-09-28 21:49:18 +0000 | [diff] [blame] | 296 | |
| 297 | /// isDummyBlock - Return true if BB is an empty basic block |
| 298 | /// with no predecessors. |
| 299 | static bool isDummyBlock(const llvm::BasicBlock *BB); |
| 300 | |
Devang Patel | 51b09f2 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 301 | /// StartBlock - Start new block named N. If insert block is a dummy block |
| 302 | /// then reuse it. |
| 303 | void StartBlock(const char *N); |
| 304 | |
Devang Patel | 88a981b | 2007-11-01 19:11:01 +0000 | [diff] [blame] | 305 | /// getCGRecordLayout - Return record layout info. |
| 306 | const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 307 | //===--------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 308 | // Declaration Emission |
| 309 | //===--------------------------------------------------------------------===// |
| 310 | |
| 311 | void EmitDecl(const Decl &D); |
| 312 | void EmitEnumConstantDecl(const EnumConstantDecl &D); |
| 313 | void EmitBlockVarDecl(const BlockVarDecl &D); |
| 314 | void EmitLocalBlockVarDecl(const BlockVarDecl &D); |
Anders Carlsson | 1a86b33 | 2007-10-17 00:52:43 +0000 | [diff] [blame] | 315 | void EmitStaticBlockVarDecl(const BlockVarDecl &D); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 316 | void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg); |
| 317 | |
| 318 | //===--------------------------------------------------------------------===// |
| 319 | // Statement Emission |
| 320 | //===--------------------------------------------------------------------===// |
| 321 | |
| 322 | void EmitStmt(const Stmt *S); |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 323 | RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, |
| 324 | llvm::Value *AggLoc = 0, bool isAggVol = false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 325 | void EmitLabelStmt(const LabelStmt &S); |
| 326 | void EmitGotoStmt(const GotoStmt &S); |
| 327 | void EmitIfStmt(const IfStmt &S); |
| 328 | void EmitWhileStmt(const WhileStmt &S); |
| 329 | void EmitDoStmt(const DoStmt &S); |
| 330 | void EmitForStmt(const ForStmt &S); |
| 331 | void EmitReturnStmt(const ReturnStmt &S); |
| 332 | void EmitDeclStmt(const DeclStmt &S); |
Chris Lattner | da13870 | 2007-07-16 21:28:45 +0000 | [diff] [blame] | 333 | void EmitBreakStmt(); |
| 334 | void EmitContinueStmt(); |
Devang Patel | 51b09f2 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 335 | void EmitSwitchStmt(const SwitchStmt &S); |
| 336 | void EmitDefaultStmt(const DefaultStmt &S); |
| 337 | void EmitCaseStmt(const CaseStmt &S); |
Devang Patel | c049e4f | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 338 | void EmitCaseStmtRange(const CaseStmt &S); |
Devang Patel | 51b09f2 | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 339 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 340 | //===--------------------------------------------------------------------===// |
| 341 | // LValue Expression Emission |
| 342 | //===--------------------------------------------------------------------===// |
| 343 | |
| 344 | /// EmitLValue - Emit code to compute a designator that specifies the location |
| 345 | /// of the expression. |
| 346 | /// |
| 347 | /// This can return one of two things: a simple address or a bitfield |
| 348 | /// reference. In either case, the LLVM Value* in the LValue structure is |
| 349 | /// guaranteed to be an LLVM pointer type. |
| 350 | /// |
| 351 | /// If this returns a bitfield reference, nothing about the pointee type of |
| 352 | /// the LLVM value is known: For example, it may not be a pointer to an |
| 353 | /// integer. |
| 354 | /// |
| 355 | /// If this returns a normal address, and if the lvalue's C type is fixed |
| 356 | /// size, this method guarantees that the returned pointer type will point to |
| 357 | /// an LLVM type of the same size of the lvalue's type. If the lvalue has a |
| 358 | /// variable length type, this is not possible. |
| 359 | /// |
| 360 | LValue EmitLValue(const Expr *E); |
| 361 | |
| 362 | /// EmitLoadOfLValue - Given an expression that represents a value lvalue, |
| 363 | /// this method emits the address of the lvalue, then loads the result as an |
| 364 | /// rvalue, returning the rvalue. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 365 | RValue EmitLoadOfLValue(LValue V, QualType LVType); |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 366 | RValue EmitLoadOfOCUElementLValue(LValue V, QualType LVType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 367 | |
Chris Lattner | 34cdc86 | 2007-08-03 16:18:34 +0000 | [diff] [blame] | 368 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 369 | /// EmitStoreThroughLValue - Store the specified rvalue into the specified |
| 370 | /// lvalue, where both are guaranteed to the have the same type, and that type |
| 371 | /// is 'Ty'. |
| 372 | void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 373 | void EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, QualType Ty); |
Christopher Lamb | 22c940e | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 374 | |
| 375 | // Note: only availabe for agg return types |
| 376 | LValue EmitCallExprLValue(const CallExpr *E); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 377 | |
| 378 | LValue EmitDeclRefLValue(const DeclRefExpr *E); |
| 379 | LValue EmitStringLiteralLValue(const StringLiteral *E); |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 380 | LValue EmitPreDefinedLValue(const PreDefinedExpr *E); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 381 | LValue EmitUnaryOpLValue(const UnaryOperator *E); |
| 382 | LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 383 | LValue EmitOCUVectorElementExpr(const OCUVectorElementExpr *E); |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 384 | LValue EmitMemberExpr(const MemberExpr *E); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 385 | |
| 386 | //===--------------------------------------------------------------------===// |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 387 | // Scalar Expression Emission |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 388 | //===--------------------------------------------------------------------===// |
| 389 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 390 | RValue EmitCallExpr(const CallExpr *E); |
Chris Lattner | c5e940f | 2007-08-31 04:44:06 +0000 | [diff] [blame] | 391 | RValue EmitCallExpr(llvm::Value *Callee, const CallExpr *E); |
Chris Lattner | 1e4d21e | 2007-08-26 22:58:05 +0000 | [diff] [blame] | 392 | RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 393 | |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 394 | llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 395 | llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 396 | |
Anders Carlsson | cc23aca | 2007-12-10 19:35:18 +0000 | [diff] [blame] | 397 | llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...); |
Anders Carlsson | 6086bbd | 2007-12-15 21:23:30 +0000 | [diff] [blame] | 398 | llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals); |
| 399 | |
Chris Lattner | 7f02f72 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 400 | llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 401 | |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 402 | //===--------------------------------------------------------------------===// |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 403 | // Expression Emission |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 404 | //===--------------------------------------------------------------------===// |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 405 | |
| 406 | // Expressions are broken into three classes: scalar, complex, aggregate. |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 407 | |
Chris Lattner | 7f02f72 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 408 | /// EmitScalarExpr - Emit the computation of the specified expression of |
| 409 | /// LLVM scalar type, returning the result. |
| 410 | llvm::Value *EmitScalarExpr(const Expr *E); |
| 411 | |
Chris Lattner | 3707b25 | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 412 | /// EmitScalarConversion - Emit a conversion from the specified type to the |
| 413 | /// specified destination type, both of which are LLVM scalar types. |
| 414 | llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, |
| 415 | QualType DstTy); |
| 416 | |
Chris Lattner | 4f1a7b3 | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 417 | /// EmitComplexToScalarConversion - Emit a conversion from the specified |
| 418 | /// complex type to the specified destination type, where the destination |
| 419 | /// type is an LLVM scalar type. |
| 420 | llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, |
| 421 | QualType DstTy); |
| 422 | |
Chris Lattner | 3707b25 | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 423 | |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 424 | /// EmitAggExpr - Emit the computation of the specified expression of |
| 425 | /// aggregate type. The result is computed into DestPtr. Note that if |
| 426 | /// DestPtr is null, the value of the aggregate expression is not needed. |
| 427 | void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 428 | |
| 429 | /// EmitComplexExpr - Emit the computation of the specified expression of |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 430 | /// complex type, returning the result. |
Chris Lattner | 58dee10 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 431 | ComplexPairTy EmitComplexExpr(const Expr *E); |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 432 | |
| 433 | /// EmitComplexExprIntoAddr - Emit the computation of the specified expression |
| 434 | /// of complex type, storing into the specified Value*. |
Chris Lattner | 190dbe2 | 2007-08-26 16:22:13 +0000 | [diff] [blame] | 435 | void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, |
| 436 | bool DestIsVolatile); |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 437 | /// LoadComplexFromAddr - Load a complex number from the specified address. |
| 438 | ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 439 | }; |
| 440 | } // end namespace CodeGen |
| 441 | } // end namespace clang |
| 442 | |
| 443 | #endif |