1c17a4d3b16a2624a76de5d7508805534545bd3bfDaniel Dunbar//===----- CGObjCRuntime.h - Interface to ObjC Runtimes ---------*- C++ -*-===//
20f984268b05edab2cc555a427c441baa9c252658Chris Lattner//
30f984268b05edab2cc555a427c441baa9c252658Chris Lattner//                     The LLVM Compiler Infrastructure
40f984268b05edab2cc555a427c441baa9c252658Chris Lattner//
50f984268b05edab2cc555a427c441baa9c252658Chris Lattner// This file is distributed under the University of Illinois Open Source
60f984268b05edab2cc555a427c441baa9c252658Chris Lattner// License. See LICENSE.TXT for details.
70f984268b05edab2cc555a427c441baa9c252658Chris Lattner//
80f984268b05edab2cc555a427c441baa9c252658Chris Lattner//===----------------------------------------------------------------------===//
90f984268b05edab2cc555a427c441baa9c252658Chris Lattner//
100f984268b05edab2cc555a427c441baa9c252658Chris Lattner// This provides an abstract class for Objective-C code generation.  Concrete
110f984268b05edab2cc555a427c441baa9c252658Chris Lattner// subclasses of this implement code generation for specific Objective-C
120f984268b05edab2cc555a427c441baa9c252658Chris Lattner// runtime libraries.
130f984268b05edab2cc555a427c441baa9c252658Chris Lattner//
140f984268b05edab2cc555a427c441baa9c252658Chris Lattner//===----------------------------------------------------------------------===//
150f984268b05edab2cc555a427c441baa9c252658Chris Lattner
160f984268b05edab2cc555a427c441baa9c252658Chris Lattner#ifndef CLANG_CODEGEN_OBCJRUNTIME_H
170f984268b05edab2cc555a427c441baa9c252658Chris Lattner#define CLANG_CODEGEN_OBCJRUNTIME_H
1845d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGBuilder.h"
1946f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar#include "CGCall.h"
2045d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGValue.h"
2155fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/DeclObjC.h"
2255fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Basic/IdentifierTable.h" // Selector
238f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar
240f984268b05edab2cc555a427c441baa9c252658Chris Lattnernamespace llvm {
250f984268b05edab2cc555a427c441baa9c252658Chris Lattner  class Constant;
269777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar  class Function;
279777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar  class Module;
289777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar  class StructLayout;
2984ad77a8f83121713ea69d8002d1fd19565f87abDaniel Dunbar  class StructType;
300f984268b05edab2cc555a427c441baa9c252658Chris Lattner  class Type;
310f984268b05edab2cc555a427c441baa9c252658Chris Lattner  class Value;
320f984268b05edab2cc555a427c441baa9c252658Chris Lattner}
330f984268b05edab2cc555a427c441baa9c252658Chris Lattner
340f984268b05edab2cc555a427c441baa9c252658Chris Lattnernamespace clang {
3546f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbarnamespace CodeGen {
3646f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar  class CodeGenFunction;
3746f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar}
388f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar
399777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar  class FieldDecl;
4064d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  class ObjCAtTryStmt;
4164d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  class ObjCAtThrowStmt;
4210cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner  class ObjCAtSynchronizedStmt;
43679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian  class ObjCContainerDecl;
447ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  class ObjCCategoryImplDecl;
457ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  class ObjCImplementationDecl;
46ddb2a3d55a24a1dbdf9152621642d9a4b4fc2f61Daniel Dunbar  class ObjCInterfaceDecl;
478f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  class ObjCMessageExpr;
487ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  class ObjCMethodDecl;
49af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar  class ObjCProtocolDecl;
508e67b63530b4f39a48bc12d97376f373a6901279Chris Lattner  class Selector;
510bb20361a321593887f067515dd04cf109f4c74aFariborz Jahanian  class ObjCIvarDecl;
5233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  class ObjCStringLiteral;
5389ecd41e0a6bfb3b0913dbe41c3c666340b308c7Fariborz Jahanian  class BlockDeclRefExpr;
54af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar
550f984268b05edab2cc555a427c441baa9c252658Chris Lattnernamespace CodeGen {
56dce1406f1c1f572cfd61c494546572d63461c741Chris Lattner  class CodeGenModule;
576b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  class CGBlockInfo;
580f984268b05edab2cc555a427c441baa9c252658Chris Lattner
59f5408fe484495ee4efbdd709c8a2c2fdbbbdb328Mike Stump// FIXME: Several methods should be pure virtual but aren't to avoid the
60f5408fe484495ee4efbdd709c8a2c2fdbbbdb328Mike Stump// partially-implemented subclass breaking.
6120ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov
6220ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov/// Implements runtime-specific code generation functions.
630f984268b05edab2cc555a427c441baa9c252658Chris Lattnerclass CGObjCRuntime {
64f0fe5bc0e46038dc79cdd27fcf0c77ad4789fdffDaniel Dunbarprotected:
65de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  CodeGen::CodeGenModule &CGM;
66de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  CGObjCRuntime(CodeGen::CodeGenModule &CGM) : CGM(CGM) {}
67de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
689777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar  // Utility functions for unified ivar access. These need to
699777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar  // eventually be folded into other places (the structure layout
709777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar  // code).
719777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar
7284ad77a8f83121713ea69d8002d1fd19565f87abDaniel Dunbar  /// Compute an offset to the given ivar, suitable for passing to
7384ad77a8f83121713ea69d8002d1fd19565f87abDaniel Dunbar  /// EmitValueForIvarAtOffset.  Note that the correct handling of
7484ad77a8f83121713ea69d8002d1fd19565f87abDaniel Dunbar  /// bit-fields is carefully coordinated by these two, use caution!
759f89f2bc111339ee7fa0df3c2f18e39493b460c4Daniel Dunbar  ///
769f89f2bc111339ee7fa0df3c2f18e39493b460c4Daniel Dunbar  /// The latter overload is suitable for computing the offset of a
779f89f2bc111339ee7fa0df3c2f18e39493b460c4Daniel Dunbar  /// sythesized ivar.
78e5b4666d9b86ea30b90b599691e75d380f84ddd6Eli Friedman  uint64_t ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
79e5b4666d9b86ea30b90b599691e75d380f84ddd6Eli Friedman                                 const ObjCInterfaceDecl *OID,
80e5b4666d9b86ea30b90b599691e75d380f84ddd6Eli Friedman                                 const ObjCIvarDecl *Ivar);
81e5b4666d9b86ea30b90b599691e75d380f84ddd6Eli Friedman  uint64_t ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
82e5b4666d9b86ea30b90b599691e75d380f84ddd6Eli Friedman                                 const ObjCImplementationDecl *OID,
83e5b4666d9b86ea30b90b599691e75d380f84ddd6Eli Friedman                                 const ObjCIvarDecl *Ivar);
849777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar
859777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar  LValue EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
869777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar                                  const ObjCInterfaceDecl *OID,
879777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar                                  llvm::Value *BaseValue,
889777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar                                  const ObjCIvarDecl *Ivar,
899777687562c338601c2f17906e65e1c1a0aad96fDaniel Dunbar                                  unsigned CVRQualifiers,
901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  llvm::Value *Offset);
919735ca6e01113aec6a825dd5b1cb1b98fb377d31David Chisnall  /// Emits a try / catch statement.  This function is intended to be called by
929735ca6e01113aec6a825dd5b1cb1b98fb377d31David Chisnall  /// subclasses, and provides a generic mechanism for generating these, which
932ee5ba35febf830d366b65dd0dcbf8e291c41342James Dennett  /// should be usable by all runtimes.  The caller must provide the functions
942ee5ba35febf830d366b65dd0dcbf8e291c41342James Dennett  /// to call when entering and exiting a \@catch() block, and the function
952ee5ba35febf830d366b65dd0dcbf8e291c41342James Dennett  /// used to rethrow exceptions.  If the begin and end catch functions are
962ee5ba35febf830d366b65dd0dcbf8e291c41342James Dennett  /// NULL, then the function assumes that the EH personality function provides
972ee5ba35febf830d366b65dd0dcbf8e291c41342James Dennett  /// the thrown object directly.
989735ca6e01113aec6a825dd5b1cb1b98fb377d31David Chisnall  void EmitTryCatchStmt(CodeGenFunction &CGF,
999735ca6e01113aec6a825dd5b1cb1b98fb377d31David Chisnall                        const ObjCAtTryStmt &S,
100789ecdebd04aebdb2d6b801ebe8e04a189ebc023David Chisnall                        llvm::Constant *beginCatchFn,
101789ecdebd04aebdb2d6b801ebe8e04a189ebc023David Chisnall                        llvm::Constant *endCatchFn,
102789ecdebd04aebdb2d6b801ebe8e04a189ebc023David Chisnall                        llvm::Constant *exceptionRethrowFn);
1032ee5ba35febf830d366b65dd0dcbf8e291c41342James Dennett  /// Emits an \@synchronize() statement, using the \p syncEnterFn and
1042ee5ba35febf830d366b65dd0dcbf8e291c41342James Dennett  /// \p syncExitFn arguments as the functions called to lock and unlock
1052ee5ba35febf830d366b65dd0dcbf8e291c41342James Dennett  /// the object.  This function can be called by subclasses that use
1062ee5ba35febf830d366b65dd0dcbf8e291c41342James Dennett  /// zero-cost exception handling.
1079735ca6e01113aec6a825dd5b1cb1b98fb377d31David Chisnall  void EmitAtSynchronizedStmt(CodeGenFunction &CGF,
1089735ca6e01113aec6a825dd5b1cb1b98fb377d31David Chisnall                            const ObjCAtSynchronizedStmt &S,
1099735ca6e01113aec6a825dd5b1cb1b98fb377d31David Chisnall                            llvm::Function *syncEnterFn,
1109735ca6e01113aec6a825dd5b1cb1b98fb377d31David Chisnall                            llvm::Function *syncExitFn);
11158bf6101062867ca4b3028f9e77e4ae642f09b44Daniel Dunbar
1120f984268b05edab2cc555a427c441baa9c252658Chris Lattnerpublic:
1130f984268b05edab2cc555a427c441baa9c252658Chris Lattner  virtual ~CGObjCRuntime();
114af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar
115391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  /// Generate the function required to register all Objective-C components in
116391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  /// this compilation unit with the runtime library.
1177ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  virtual llvm::Function *ModuleInitFunction() = 0;
118af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar
1197ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  /// Get a selector for the specified name and type values. The
1207ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  /// return value should have the LLVM type for pointer-to
1217ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  /// ASTContext::getObjCSelType().
122bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  virtual llvm::Value *GetSelector(CodeGenFunction &CGF,
12303b2960c14aede6ac82bdef32247094ebb72fa69Fariborz Jahanian                                   Selector Sel, bool lval=false) = 0;
124af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar
1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Get a typed selector.
126bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  virtual llvm::Value *GetSelector(CodeGenFunction &CGF,
127df9ccc6381314ccca6407abb209155e9273a631dFariborz Jahanian                                   const ObjCMethodDecl *Method) = 0;
128df9ccc6381314ccca6407abb209155e9273a631dFariborz Jahanian
1295a180397870944548aaadeaebf58e415885b9489John McCall  /// Get the type constant to catch for the given ObjC pointer type.
1305a180397870944548aaadeaebf58e415885b9489John McCall  /// This is used externally to implement catching ObjC types in C++.
1315a180397870944548aaadeaebf58e415885b9489John McCall  /// Runtimes which don't support this should add the appropriate
1325a180397870944548aaadeaebf58e415885b9489John McCall  /// error to Sema.
133cf5abc7ba032bd35158e4d75b0bc92a482fc67e8Fariborz Jahanian  virtual llvm::Constant *GetEHType(QualType T) = 0;
1345a180397870944548aaadeaebf58e415885b9489John McCall
1357ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  /// Generate a constant string object.
1360d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall  virtual llvm::Constant *GenerateConstantString(const StringLiteral *) = 0;
137ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
13820ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov  /// Generate a category.  A category contains a list of methods (and
13920ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov  /// accompanying metadata) and a list of protocols.
1407ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0;
141af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar
142fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// Generate a class structure for this class.
1437ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
1441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14529254f4dd114fe2dd5c4e7a261ebea941973ad3dDavid Chisnall  /// Register an class alias.
14629254f4dd114fe2dd5c4e7a261ebea941973ad3dDavid Chisnall  virtual void RegisterAlias(const ObjCCompatibleAliasDecl *OAD) = 0;
14729254f4dd114fe2dd5c4e7a261ebea941973ad3dDavid Chisnall
1481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Generate an Objective-C message send operation.
149d6c93d703541c992e06eb9a59a2d826a30da65b2Daniel Dunbar  ///
150d6c93d703541c992e06eb9a59a2d826a30da65b2Daniel Dunbar  /// \param Method - The method being called, this may be null if synthesizing
151d6c93d703541c992e06eb9a59a2d826a30da65b2Daniel Dunbar  /// a property setter or getter.
1521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual CodeGen::RValue
1538f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
154ef072fd2f3347cfd857d6eb787b245b950771430John McCall                      ReturnValueSlot ReturnSlot,
1557f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                      QualType ResultType,
1567f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                      Selector Sel,
157f56f1913e91ad32bed52dd3f6afc26735d336584Daniel Dunbar                      llvm::Value *Receiver,
158df9ccc6381314ccca6407abb209155e9273a631dFariborz Jahanian                      const CallArgList &CallArgs,
159c6cd5fd3eae71f8841504a396563343cfaaf503eDavid Chisnall                      const ObjCInterfaceDecl *Class = 0,
160d6c93d703541c992e06eb9a59a2d826a30da65b2Daniel Dunbar                      const ObjCMethodDecl *Method = 0) = 0;
161af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar
1627ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  /// Generate an Objective-C message send operation to the super
163f56f1913e91ad32bed52dd3f6afc26735d336584Daniel Dunbar  /// class initiated in a method for Class and with the given Self
164f56f1913e91ad32bed52dd3f6afc26735d336584Daniel Dunbar  /// object.
165d6c93d703541c992e06eb9a59a2d826a30da65b2Daniel Dunbar  ///
166d6c93d703541c992e06eb9a59a2d826a30da65b2Daniel Dunbar  /// \param Method - The method being called, this may be null if synthesizing
167d6c93d703541c992e06eb9a59a2d826a30da65b2Daniel Dunbar  /// a property setter or getter.
1688f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  virtual CodeGen::RValue
1698f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
170ef072fd2f3347cfd857d6eb787b245b950771430John McCall                           ReturnValueSlot ReturnSlot,
1717f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                           QualType ResultType,
1727f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                           Selector Sel,
173f56f1913e91ad32bed52dd3f6afc26735d336584Daniel Dunbar                           const ObjCInterfaceDecl *Class,
1747ce77920a35060f1c8dd72e541e42ce296ccd168Fariborz Jahanian                           bool isCategoryImpl,
175f56f1913e91ad32bed52dd3f6afc26735d336584Daniel Dunbar                           llvm::Value *Self,
17619cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar                           bool IsClassMessage,
177d6c93d703541c992e06eb9a59a2d826a30da65b2Daniel Dunbar                           const CallArgList &CallArgs,
178d6c93d703541c992e06eb9a59a2d826a30da65b2Daniel Dunbar                           const ObjCMethodDecl *Method = 0) = 0;
17998c5ead87d720d8b68b6f236c3c3579a388fc882Daniel Dunbar
18098c5ead87d720d8b68b6f236c3c3579a388fc882Daniel Dunbar  /// Emit the code to return the named protocol as an object, as in a
18117d26a6c1f2cb921d0000c337b4967699dc928fdJames Dennett  /// \@protocol expression.
182bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  virtual llvm::Value *GenerateProtocolRef(CodeGenFunction &CGF,
1837ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar                                           const ObjCProtocolDecl *OPD) = 0;
18498c5ead87d720d8b68b6f236c3c3579a388fc882Daniel Dunbar
1851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Generate the named protocol.  Protocols contain method metadata but no
1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// implementations.
1877ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
1887ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar
1897ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar  /// Generate a function preamble for a method with the specified
1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// types.
1917ded7f4983dc4a20561db7a8d02c6b2435030961Daniel Dunbar
192f5408fe484495ee4efbdd709c8a2c2fdbbbdb328Mike Stump  // FIXME: Current this just generates the Function definition, but really this
193f5408fe484495ee4efbdd709c8a2c2fdbbbdb328Mike Stump  // should also be generating the loads of the parameters, as the runtime
194f5408fe484495ee4efbdd709c8a2c2fdbbbdb328Mike Stump  // should have full control over how parameters are passed.
1951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
196679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian                                         const ObjCContainerDecl *CD) = 0;
197af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar
19849f6602707887eea1a558a1dffe0213102f887f2Daniel Dunbar  /// Return the runtime function for getting properties.
19974391b48b4791cded373683a3baf67314f358d50Chris Lattner  virtual llvm::Constant *GetPropertyGetFunction() = 0;
2001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20149f6602707887eea1a558a1dffe0213102f887f2Daniel Dunbar  /// Return the runtime function for setting properties.
20274391b48b4791cded373683a3baf67314f358d50Chris Lattner  virtual llvm::Constant *GetPropertySetFunction() = 0;
20349f6602707887eea1a558a1dffe0213102f887f2Daniel Dunbar
204ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  /// Return the runtime function for optimized setting properties.
205ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  virtual llvm::Constant *GetOptimizedPropertySetFunction(bool atomic,
206ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                                          bool copy) = 0;
207ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2088fac25d33b13e25f512dd921d4d5a4b565f5d175David Chisnall  // API for atomic copying of qualified aggregates in getter.
2098fac25d33b13e25f512dd921d4d5a4b565f5d175David Chisnall  virtual llvm::Constant *GetGetStructFunction() = 0;
2108fac25d33b13e25f512dd921d4d5a4b565f5d175David Chisnall  // API for atomic copying of qualified aggregates in setter.
2118fac25d33b13e25f512dd921d4d5a4b565f5d175David Chisnall  virtual llvm::Constant *GetSetStructFunction() = 0;
212d397cfef01d49a41554309d67ea26340c39e1e94David Chisnall  /// API for atomic copying of qualified aggregates with non-trivial copy
213d397cfef01d49a41554309d67ea26340c39e1e94David Chisnall  /// assignment (c++) in setter.
214d397cfef01d49a41554309d67ea26340c39e1e94David Chisnall  virtual llvm::Constant *GetCppAtomicObjectSetFunction() = 0;
215d397cfef01d49a41554309d67ea26340c39e1e94David Chisnall  /// API for atomic copying of qualified aggregates with non-trivial copy
216d397cfef01d49a41554309d67ea26340c39e1e94David Chisnall  /// assignment (c++) in getter.
217d397cfef01d49a41554309d67ea26340c39e1e94David Chisnall  virtual llvm::Constant *GetCppAtomicObjectGetFunction() = 0;
2186cc590602f41c3e98e8af0023d54296c8eca7910Fariborz Jahanian
219ddb2a3d55a24a1dbdf9152621642d9a4b4fc2f61Daniel Dunbar  /// GetClass - Return a reference to the class for the given
220ddb2a3d55a24a1dbdf9152621642d9a4b4fc2f61Daniel Dunbar  /// interface decl.
221bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  virtual llvm::Value *GetClass(CodeGenFunction &CGF,
222ddb2a3d55a24a1dbdf9152621642d9a4b4fc2f61Daniel Dunbar                                const ObjCInterfaceDecl *OID) = 0;
223f85e193739c953358c865005855253af4f68a497John McCall
224f85e193739c953358c865005855253af4f68a497John McCall
225bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  virtual llvm::Value *EmitNSAutoreleasePoolClassRef(CodeGenFunction &CGF) {
226b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("autoreleasepool unsupported in this ABI");
227f85e193739c953358c865005855253af4f68a497John McCall  }
228f85e193739c953358c865005855253af4f68a497John McCall
2292abd89c039e835e84519a4cd8a7495899a70153dAnders Carlsson  /// EnumerationMutationFunction - Return the function that's called by the
2302abd89c039e835e84519a4cd8a7495899a70153dAnders Carlsson  /// compiler when a mutation is detected during foreach iteration.
23174391b48b4791cded373683a3baf67314f358d50Chris Lattner  virtual llvm::Constant *EnumerationMutationFunction() = 0;
2321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
233f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
234f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                                    const ObjCAtSynchronizedStmt &S) = 0;
235f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  virtual void EmitTryStmt(CodeGen::CodeGenFunction &CGF,
236f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                           const ObjCAtTryStmt &S) = 0;
23764d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
2386a3c70ec59804347c99e96aa13934f63f4fed573Fariborz Jahanian                             const ObjCAtThrowStmt &S,
2396a3c70ec59804347c99e96aa13934f63f4fed573Fariborz Jahanian                             bool ClearInsertionPoint=true) = 0;
2406bf2ae05c777052e5ec05649710380dea263e7e0Daniel Dunbar  virtual llvm::Value *EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
2416bf2ae05c777052e5ec05649710380dea263e7e0Daniel Dunbar                                        llvm::Value *AddrWeakObj) = 0;
2423e283e344595e0bd499b13b30a92b7d9c10a2140Fariborz Jahanian  virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
2433e283e344595e0bd499b13b30a92b7d9c10a2140Fariborz Jahanian                                  llvm::Value *src, llvm::Value *dest) = 0;
24458626500527695865683d1d65053743de8770b60Fariborz Jahanian  virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
245021a7a63984f0f912dc9e9dae2a1b3e1509a40ceFariborz Jahanian                                    llvm::Value *src, llvm::Value *dest,
246021a7a63984f0f912dc9e9dae2a1b3e1509a40ceFariborz Jahanian                                    bool threadlocal=false) = 0;
2477eda8367cf63caee8acf907356b1d199ccaa6e89Fariborz Jahanian  virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
2486c7a1f364796ce1acb988714e9e42076d1ce332eFariborz Jahanian                                  llvm::Value *src, llvm::Value *dest,
2496c7a1f364796ce1acb988714e9e42076d1ce332eFariborz Jahanian                                  llvm::Value *ivarOffset) = 0;
25058626500527695865683d1d65053743de8770b60Fariborz Jahanian  virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
25158626500527695865683d1d65053743de8770b60Fariborz Jahanian                                        llvm::Value *src, llvm::Value *dest) = 0;
2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
253598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian  virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
254598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                      QualType ObjectTy,
255598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                      llvm::Value *BaseValue,
256598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                      const ObjCIvarDecl *Ivar,
257598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                      unsigned CVRQualifiers) = 0;
258f63aa3fd429cdb9145d78f0b656bc78754efedb9Fariborz Jahanian  virtual llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
2592a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar                                      const ObjCInterfaceDecl *Interface,
260f63aa3fd429cdb9145d78f0b656bc78754efedb9Fariborz Jahanian                                      const ObjCIvarDecl *Ivar) = 0;
261082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF,
2621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        llvm::Value *DestPtr,
263082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian                                        llvm::Value *SrcPtr,
26455bcace250e1ff366e4482714b344b8cbc8be5f3Fariborz Jahanian                                        llvm::Value *Size) = 0;
2656b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  virtual llvm::Constant *BuildGCBlockLayout(CodeGen::CodeGenModule &CGM,
2666b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall                                  const CodeGen::CGBlockInfo &blockInfo) = 0;
267c46b43517a18c8f41934a38a3580bd477ab54265Fariborz Jahanian  virtual llvm::Constant *BuildRCBlockLayout(CodeGen::CodeGenModule &CGM,
268c46b43517a18c8f41934a38a3580bd477ab54265Fariborz Jahanian                                  const CodeGen::CGBlockInfo &blockInfo) = 0;
2693ca23d7dc6cb61e6f363a58d9256d548199d120cFariborz Jahanian  virtual llvm::Constant *BuildByrefLayout(CodeGen::CodeGenModule &CGM,
2703ca23d7dc6cb61e6f363a58d9256d548199d120cFariborz Jahanian                                           QualType T) = 0;
2716f40e2244b0590f144c5ceee07981a962fbbc72eFariborz Jahanian  virtual llvm::GlobalVariable *GetClassGlobal(const std::string &Name) = 0;
272de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
273de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  struct MessageSendInfo {
274de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    const CGFunctionInfo &CallInfo;
275de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    llvm::PointerType *MessengerType;
276de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
277de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall    MessageSendInfo(const CGFunctionInfo &callInfo,
278de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                    llvm::PointerType *messengerType)
279de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall      : CallInfo(callInfo), MessengerType(messengerType) {}
280de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  };
281de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
282de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  MessageSendInfo getMessageSendInfo(const ObjCMethodDecl *method,
283de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                     QualType resultType,
284de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                     CallArgList &callArgs);
2857745786044f159cf9ddf4a8a0f7be8fe2bebfa80Eli Friedman
2867745786044f159cf9ddf4a8a0f7be8fe2bebfa80Eli Friedman  // FIXME: This probably shouldn't be here, but the code to compute
2877745786044f159cf9ddf4a8a0f7be8fe2bebfa80Eli Friedman  // it is here.
2887745786044f159cf9ddf4a8a0f7be8fe2bebfa80Eli Friedman  unsigned ComputeBitfieldBitOffset(CodeGen::CodeGenModule &CGM,
2897745786044f159cf9ddf4a8a0f7be8fe2bebfa80Eli Friedman                                    const ObjCInterfaceDecl *ID,
2907745786044f159cf9ddf4a8a0f7be8fe2bebfa80Eli Friedman                                    const ObjCIvarDecl *Ivar);
2910f984268b05edab2cc555a427c441baa9c252658Chris Lattner};
2920f984268b05edab2cc555a427c441baa9c252658Chris Lattner
2931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Creates an instance of an Objective-C runtime class.
294391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner//TODO: This should include some way of selecting which runtime to target.
295c17a4d3b16a2624a76de5d7508805534545bd3bfDaniel DunbarCGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
296c17a4d3b16a2624a76de5d7508805534545bd3bfDaniel DunbarCGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);
2970f984268b05edab2cc555a427c441baa9c252658Chris Lattner}
2980f984268b05edab2cc555a427c441baa9c252658Chris Lattner}
2990f984268b05edab2cc555a427c441baa9c252658Chris Lattner#endif
300