CodeGenFunction.h revision d9f6910f4ef37c0e8eeee2a01287d9572c3176ef
1bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This is the internal per-function state used for llvm translation. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H 15ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#define CLANG_CODEGEN_CODEGENFUNCTION_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner#include "clang/AST/Type.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/DenseMap.h" 19da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner#include "llvm/ADT/SmallVector.h" 2050b36741673258aaebcd3c7fe1260031901cae57Chris Lattner#include "llvm/Support/IRBuilder.h" 215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/Expr.h" 225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h" 235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <vector> 250ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar#include <map> 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Module; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class FunctionDecl; 35391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner class ObjCMethodDecl; 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TargetInfo; 375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class FunctionTypeProto; 385549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen { 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class CodeGenModule; 41b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel class CodeGenTypes; 4288a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel class CGRecordLayout; 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// RValue - This trivial value class is used to represent the result of an 459b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner/// expression that is evaluated. It can be one of three things: either a 469b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the 479b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner/// address of an aggregate value in memory. 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass RValue { 499b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner llvm::Value *V1, *V2; 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // TODO: Encode this into the low bit of pointer for more efficient 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // return-by-value. 529b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner enum { Scalar, Complex, Aggregate } Flavor; 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // FIXME: Aggregate rvalues need to retain information about whether they are 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // volatile or not. 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 589b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner bool isScalar() const { return Flavor == Scalar; } 599b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner bool isComplex() const { return Flavor == Complex; } 609b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner bool isAggregate() const { return Flavor == Aggregate; } 615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 629b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// getScalar() - Return the Value* of this scalar value. 639b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner llvm::Value *getScalarVal() const { 649b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner assert(isScalar() && "Not a scalar!"); 659b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner return V1; 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 689b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// getComplexVal - Return the real/imag components of this complex value. 699b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// 709b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner std::pair<llvm::Value *, llvm::Value *> getComplexVal() const { 719b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner return std::pair<llvm::Value *, llvm::Value *>(V1, V2); 729b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner } 739b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getAggregateAddr() - Return the Value* of the address of the aggregate. 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *getAggregateAddr() const { 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isAggregate() && "Not an aggregate!"); 779b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner return V1; 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static RValue get(llvm::Value *V) { 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RValue ER; 829b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.V1 = V; 839b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.Flavor = Scalar; 849b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner return ER; 859b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner } 869b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner static RValue getComplex(llvm::Value *V1, llvm::Value *V2) { 879b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue ER; 889b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.V1 = V1; 899b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.V2 = V2; 909b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.Flavor = Complex; 919b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner return ER; 929b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner } 939b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) { 949b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue ER; 959b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.V1 = C.first; 969b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.V2 = C.second; 979b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.Flavor = Complex; 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ER; 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static RValue getAggregate(llvm::Value *V) { 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RValue ER; 1029b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.V1 = V; 1039b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ER.Flavor = Aggregate; 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ER; 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// LValue - This represents an lvalue references. Because C/C++ allow 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// bitrange. 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass LValue { 1131e692ace08959399794363e77499b73da5494af9Eli Friedman // FIXME: alignment? 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum { 116349aaec106b459206479f7600990230b9d799c61Chris Lattner Simple, // This is a normal l-value, use getAddress(). 117349aaec106b459206479f7600990230b9d799c61Chris Lattner VectorElt, // This is a vector element l-value (V[i]), use getVector* 118349aaec106b459206479f7600990230b9d799c61Chris Lattner BitField, // This is a bitfield l-value, use getBitfield*. 119213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorElt // This is an extended vector subset, use getExtVectorComp 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } LVType; 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *V; 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer union { 1258a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman // Index into a vector subscript: V[i] 1268a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman llvm::Value *VectorIdx; 1278a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 1288a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman // ExtVector element subset: V.xyx 1298a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman llvm::Constant *VectorElts; 1308a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 13169ce1dff4a1f86d5bd7135c0491fd628d2d76cc7Nate Begeman // BitField start bit and size 1323b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio struct { 1333b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio unsigned short StartBit; 1343b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio unsigned short Size; 1353b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio bool IsSigned; 13669ce1dff4a1f86d5bd7135c0491fd628d2d76cc7Nate Begeman } BitfieldData; 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1381e692ace08959399794363e77499b73da5494af9Eli Friedman 1391e692ace08959399794363e77499b73da5494af9Eli Friedman bool Volatile:1; 1401e692ace08959399794363e77499b73da5494af9Eli Friedman // FIXME: set but never used, what effect should it have? 1411e692ace08959399794363e77499b73da5494af9Eli Friedman bool Restrict:1; 1421e692ace08959399794363e77499b73da5494af9Eli Friedman 1431e692ace08959399794363e77499b73da5494af9Eli Friedmanprivate: 1441e692ace08959399794363e77499b73da5494af9Eli Friedman static void SetQualifiers(unsigned Qualifiers, LValue& R) { 1451e692ace08959399794363e77499b73da5494af9Eli Friedman R.Volatile = (Qualifiers&QualType::Volatile)!=0; 1461e692ace08959399794363e77499b73da5494af9Eli Friedman R.Restrict = (Qualifiers&QualType::Restrict)!=0; 1471e692ace08959399794363e77499b73da5494af9Eli Friedman } 1481e692ace08959399794363e77499b73da5494af9Eli Friedman 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSimple() const { return LVType == Simple; } 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVectorElt() const { return LVType == VectorElt; } 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isBitfield() const { return LVType == BitField; } 153213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorElt() const { return LVType == ExtVectorElt; } 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1551e692ace08959399794363e77499b73da5494af9Eli Friedman bool isVolatileQualified() const { return Volatile; } 1561e692ace08959399794363e77499b73da5494af9Eli Friedman bool isRestrictQualified() const { return Restrict; } 1571e692ace08959399794363e77499b73da5494af9Eli Friedman 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // simple lvalue 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *getAddress() const { assert(isSimple()); return V; } 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // vector elt lvalue 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; } 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; } 163213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman // extended vector elements. 164213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; } 1658a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman llvm::Constant *getExtVectorElts() const { 166213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman assert(isExtVectorElt()); 1676481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner return VectorElts; 168349aaec106b459206479f7600990230b9d799c61Chris Lattner } 1693b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio // bitfield lvalue 1703b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; } 1713b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio unsigned short getBitfieldStartBit() const { 1723b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio assert(isBitfield()); 1733b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio return BitfieldData.StartBit; 1743b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio } 1753b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio unsigned short getBitfieldSize() const { 1763b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio assert(isBitfield()); 1773b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio return BitfieldData.Size; 1783b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio } 1793b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio bool isBitfieldSigned() const { 1803b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio assert(isBitfield()); 1813b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio return BitfieldData.IsSigned; 1823b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio } 1833b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio 1841e692ace08959399794363e77499b73da5494af9Eli Friedman static LValue MakeAddr(llvm::Value *V, unsigned Qualifiers) { 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue R; 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer R.LVType = Simple; 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer R.V = V; 1881e692ace08959399794363e77499b73da5494af9Eli Friedman SetQualifiers(Qualifiers,R); 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return R; 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1921e692ace08959399794363e77499b73da5494af9Eli Friedman static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx, 1931e692ace08959399794363e77499b73da5494af9Eli Friedman unsigned Qualifiers) { 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue R; 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer R.LVType = VectorElt; 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer R.V = Vec; 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer R.VectorIdx = Idx; 1981e692ace08959399794363e77499b73da5494af9Eli Friedman SetQualifiers(Qualifiers,R); 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return R; 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2021e692ace08959399794363e77499b73da5494af9Eli Friedman static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts, 2031e692ace08959399794363e77499b73da5494af9Eli Friedman unsigned Qualifiers) { 204349aaec106b459206479f7600990230b9d799c61Chris Lattner LValue R; 205213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman R.LVType = ExtVectorElt; 206349aaec106b459206479f7600990230b9d799c61Chris Lattner R.V = Vec; 2078a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman R.VectorElts = Elts; 2081e692ace08959399794363e77499b73da5494af9Eli Friedman SetQualifiers(Qualifiers,R); 209349aaec106b459206479f7600990230b9d799c61Chris Lattner return R; 210349aaec106b459206479f7600990230b9d799c61Chris Lattner } 2113b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio 2123b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit, 2131e692ace08959399794363e77499b73da5494af9Eli Friedman unsigned short Size, bool IsSigned, 2141e692ace08959399794363e77499b73da5494af9Eli Friedman unsigned Qualifiers) { 2153b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio LValue R; 2163b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio R.LVType = BitField; 2173b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio R.V = V; 2183b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio R.BitfieldData.StartBit = StartBit; 2193b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio R.BitfieldData.Size = Size; 2203b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio R.BitfieldData.IsSigned = IsSigned; 2211e692ace08959399794363e77499b73da5494af9Eli Friedman SetQualifiers(Qualifiers,R); 2223b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio return R; 2233b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio } 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code. 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CodeGenFunction { 229bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic: 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenModule &CGM; // Per-module state. 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TargetInfo &Target; 232bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 23358dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; 23485e356825b291f86c6e926638914222b834b71a3Chris Lattner llvm::IRBuilder<> Builder; 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 236c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner // Holds the Decl for the current function or method 2374111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner const Decl *CurFuncDecl; 238391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner QualType FnRetTy; 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Function *CurFn; 2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// AllocaInsertPoint - This is an instruction in the entry block before which 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// we prefer to insert allocas. 2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Instruction *AllocaInsertPt; 2440ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::Type *LLVMIntTy; 2467b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser uint32_t LLVMPointerWidth; 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2487f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate: 2490ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// LabelIDs - Track arbitrary ids assigned to labels for use in 2500ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// implementing the GCC address-of-label extension and indirect 2510ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// goto. IDs are assigned to labels inside getIDForAddrOfLabel(). 2520ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar std::map<const LabelStmt*, unsigned> LabelIDs; 2530ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 2540ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// IndirectSwitches - Record the list of switches for indirect 2550ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// gotos. Emission of the actual switching code needs to be delayed 2560ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// until all AddrLabelExprs have been seen. 2570ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar std::vector<llvm::SwitchInst*> IndirectSwitches; 2580ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// decls. 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LabelMap - This keeps track of the LLVM basic block for each C label. 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap; 265da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner 266da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner // BreakContinueStack - This keeps track of where break and continue 267da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner // statements should jump to. 268da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner struct BreakContinue { 269da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb) 270da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner : BreakBlock(bb), ContinueBlock(cb) {} 271da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner 272da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::BasicBlock *BreakBlock; 273da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::BasicBlock *ContinueBlock; 274da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner }; 275da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::SmallVector<BreakContinue, 8> BreakContinueStack; 276da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner 27780fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// SwitchInsn - This is nearest current switch instruction. It is null if 27880fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// if current context is not in a switch. 27951b09f2c528c8460b5465c676173324e44176d62Devang Patel llvm::SwitchInst *SwitchInsn; 28051b09f2c528c8460b5465c676173324e44176d62Devang Patel 28180fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// CaseRangeBlock - This block holds if condition check for last case 28280fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// statement range in current switch instruction. 283c049e4f406a7f7179eba98659044a32508e53289Devang Patel llvm::BasicBlock *CaseRangeBlock; 284c049e4f406a7f7179eba98659044a32508e53289Devang Patel 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenFunction(CodeGenModule &cgm); 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASTContext &getContext() const; 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 290391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner void GenerateObjCMethod(const ObjCMethodDecl *OMD); 291bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar void GenerateCode(const FunctionDecl *FD, 292bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar llvm::Function *Fn); 2934111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner void GenerateFunction(const Stmt *Body); 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::Type *ConvertType(QualType T); 296c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner 297c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner llvm::Value *LoadObjCSelf(); 2984111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 2994111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner /// isObjCPointerType - Return true if the specificed AST type will map onto 3004111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner /// some Objective-C pointer type. 3014111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner static bool isObjCPointerType(QualType T); 3024111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasAggregateLLVMType - Return true if the specified AST type will map into 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an aggregate LLVM type or is void. 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool hasAggregateLLVMType(QualType T); 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getBasicBlockForLabel - Return the LLVM basicblock that the specified 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// label maps to. 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S); 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitBlock(llvm::BasicBlock *BB); 313dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner 314dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner /// WarnUnsupported - Print out a warning that codegen doesn't support the 315dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner /// specified stmt yet. 316dc4d280136d3301fcbf3c7b4b2782c8bd804342cChris Lattner void WarnUnsupported(const Stmt *S, const char *Type); 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helpers 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CreateTempAlloca - This creates a alloca and inserts it into the entry 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// block. 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *Name = "tmp"); 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EvaluateExprAsBool - Perform the usual unary conversions on the specified 3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression and compare the result against zero, returning an Int1Ty value. 3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *EvaluateExprAsBool(const Expr *E); 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3319b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// EmitAnyExpr - Emit code to compute the specified expression which can have 3329b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// any type. The result is returned as an RValue struct. If this is an 3339b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// aggregate expression, the aggloc/agglocvolatile arguments indicate where 3349b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// the result should be returned. 3359b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, 3369b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner bool isAggLocVolatile = false); 337d9363c3a80168283b3da518b4e17f545a6246857Devang Patel 338d9363c3a80168283b3da518b4e17f545a6246857Devang Patel /// isDummyBlock - Return true if BB is an empty basic block 339d9363c3a80168283b3da518b4e17f545a6246857Devang Patel /// with no predecessors. 340d9363c3a80168283b3da518b4e17f545a6246857Devang Patel static bool isDummyBlock(const llvm::BasicBlock *BB); 341d9363c3a80168283b3da518b4e17f545a6246857Devang Patel 34251b09f2c528c8460b5465c676173324e44176d62Devang Patel /// StartBlock - Start new block named N. If insert block is a dummy block 34351b09f2c528c8460b5465c676173324e44176d62Devang Patel /// then reuse it. 34451b09f2c528c8460b5465c676173324e44176d62Devang Patel void StartBlock(const char *N); 34551b09f2c528c8460b5465c676173324e44176d62Devang Patel 34688a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel /// getCGRecordLayout - Return record layout info. 34788a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy); 348813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio 349813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio /// GetAddrOfStaticLocalVar - Return the address of a static local variable. 350248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD); 3514f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 3524f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// getAccessedFieldNo - Given an encoded value and a result number, return 3534f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// the input field number being accessed. 3544f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); 3554f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 3560ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar unsigned GetIDForAddrOfLabel(const LabelStmt *L); 3570ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Declaration Emission 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDecl(const Decl &D); 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitEnumConstantDecl(const EnumConstantDecl &D); 364248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitBlockVarDecl(const VarDecl &D); 365248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitLocalBlockVarDecl(const VarDecl &D); 366248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitStaticBlockVarDecl(const VarDecl &D); 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg); 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Statement Emission 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStmt(const Stmt *S); 3749b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, 3759b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner llvm::Value *AggLoc = 0, bool isAggVol = false); 37691d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt. 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitLabelStmt(const LabelStmt &S); 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitGotoStmt(const GotoStmt &S); 3790ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectGotoStmt(const IndirectGotoStmt &S); 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitIfStmt(const IfStmt &S); 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitWhileStmt(const WhileStmt &S); 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDoStmt(const DoStmt &S); 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitForStmt(const ForStmt &S); 3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitReturnStmt(const ReturnStmt &S); 3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDeclStmt(const DeclStmt &S); 386da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner void EmitBreakStmt(); 387da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner void EmitContinueStmt(); 38851b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitSwitchStmt(const SwitchStmt &S); 38951b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitDefaultStmt(const DefaultStmt &S); 39051b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitCaseStmt(const CaseStmt &S); 391c049e4f406a7f7179eba98659044a32508e53289Devang Patel void EmitCaseStmtRange(const CaseStmt &S); 392fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson void EmitAsmStmt(const AsmStmt &S); 393fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // LValue Expression Emission 3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLValue - Emit code to compute a designator that specifies the location 3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the expression. 4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This can return one of two things: a simple address or a bitfield 4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// reference. In either case, the LLVM Value* in the LValue structure is 4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// guaranteed to be an LLVM pointer type. 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a bitfield reference, nothing about the pointee type of 4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the LLVM value is known: For example, it may not be a pointer to an 4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// integer. 4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a normal address, and if the lvalue's C type is fixed 4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// size, this method guarantees that the returned pointer type will point to 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an LLVM type of the same size of the lvalue's type. If the lvalue has a 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// variable length type, this is not possible. 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitLValue(const Expr *E); 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLoadOfLValue - Given an expression that represents a value lvalue, 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this method emits the address of the lvalue, then loads the result as an 4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// rvalue, returning the rvalue. 4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RValue EmitLoadOfLValue(LValue V, QualType LVType); 420213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType); 4213b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); 4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 42334cdc86af5b0a54084a512a1b2643365b8f5bdd2Chris Lattner 4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitStoreThroughLValue - Store the specified rvalue into the specified 4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lvalue, where both are guaranteed to the have the same type, and that type 4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// is 'Ty'. 4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); 428213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst, 429213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman QualType Ty); 430a0c5d0eacede0f67ce46707263ddf4d8de0df706Lauro Ramos Venancio void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty); 43122c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb 43222c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb // Note: only availabe for agg return types 43322c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb LValue EmitCallExprLValue(const CallExpr *E); 4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitDeclRefLValue(const DeclRefExpr *E); 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitStringLiteralLValue(const StringLiteral *E); 437d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner LValue EmitPredefinedLValue(const PredefinedExpr *E); 4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitUnaryOpLValue(const UnaryOperator *E); 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); 440213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); 441b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel LValue EmitMemberExpr(const MemberExpr *E); 44206e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); 443472778eb4fce241721c563280886e98389bc7219Eli Friedman 444472778eb4fce241721c563280886e98389bc7219Eli Friedman LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field, 4451e692ace08959399794363e77499b73da5494af9Eli Friedman bool isUnion, unsigned CVRQualifiers); 446391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner 447391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 449883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner // Scalar Expression Emission 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RValue EmitCallExpr(const CallExpr *E); 4535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 4545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg, 4555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CallExpr::const_arg_iterator ArgEnd); 4565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 4575193b8a3e57c4f696161aeddfe8227c294c0a7feEli Friedman RValue EmitCallExpr(llvm::Value *Callee, QualType FnType, 4585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CallExpr::const_arg_iterator ArgBeg, 4595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CallExpr::const_arg_iterator ArgEnd); 4605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 4611e4d21ea5849637c49fd4222b09c4b5dedff7765Chris Lattner RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 463564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 464564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 465564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson 466cc23acae84c6d5c37b4805edbcd95ee5d821c400Anders Carlsson llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...); 4674119d1aeca8016654d381ce079864058d1709571Nate Begeman llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals, 4684119d1aeca8016654d381ce079864058d1709571Nate Begeman bool isSplat = false); 4696086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson 4707f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); 4718fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); 4728fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner llvm::Value *EmitObjCMessageExpr(const ObjCMessageExpr *E); 4738fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 4748fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 4755508518a2702b00be3b15a26d772bde968972f54Anders Carlsson 476883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 477bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expression Emission 478883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 479bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 480bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expressions are broken into three classes: scalar, complex, aggregate. 481883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner 4827f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner /// EmitScalarExpr - Emit the computation of the specified expression of 4837f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner /// LLVM scalar type, returning the result. 4847f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitScalarExpr(const Expr *E); 4857f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner 4863707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// EmitScalarConversion - Emit a conversion from the specified type to the 4873707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// specified destination type, both of which are LLVM scalar types. 4883707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, 4893707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner QualType DstTy); 4903707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner 4914f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// EmitComplexToScalarConversion - Emit a conversion from the specified 4924f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// complex type to the specified destination type, where the destination 4934f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// type is an LLVM scalar type. 4944f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, 4954f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner QualType DstTy); 4964f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner 4973707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner 498883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// EmitAggExpr - Emit the computation of the specified expression of 499883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// aggregate type. The result is computed into DestPtr. Note that if 500883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// DestPtr is null, the value of the aggregate expression is not needed. 501883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest); 502b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner 503b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner /// EmitComplexExpr - Emit the computation of the specified expression of 50423b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// complex type, returning the result. 50558dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner ComplexPairTy EmitComplexExpr(const Expr *E); 50623b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner 50723b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// EmitComplexExprIntoAddr - Emit the computation of the specified expression 50823b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// of complex type, storing into the specified Value*. 509190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, 510190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner bool DestIsVolatile); 5119b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// LoadComplexFromAddr - Load a complex number from the specified address. 5129b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); 5132621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner 5142621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner /// GenerateStaticBlockVarDecl - return the the static 5152621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner /// declaration of local variable. 5162621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D, 5172621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner bool NoInit, 5182621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner const char *Separator); 5190ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 5200ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 5210ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar // Internal Helpers 5220ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 5230ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 5240ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbarprivate: 5250ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// EmitIndirectSwitches - Emit code for all of the switch 5260ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// instructions in IndirectSwitches. 5270ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectSwitches(); 5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace CodeGen 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 533