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