]> granicus.if.org Git - clang/blob - lib/CodeGen/CGCXXABI.h
Abstract out everything having to do with member pointers into the ABI
[clang] / lib / CodeGen / CGCXXABI.h
1 //===----- CGCXXABI.h - Interface to C++ ABIs -------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This provides an abstract class for C++ code generation. Concrete subclasses
11 // of this implement code generation for specific C++ ABIs.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef CLANG_CODEGEN_CXXABI_H
16 #define CLANG_CODEGEN_CXXABI_H
17
18 namespace llvm {
19   class Constant;
20   class Type;
21   class Value;
22 }
23
24 namespace clang {
25   class CastExpr;
26   class CXXMethodDecl;
27   class CXXRecordDecl;
28   class FieldDecl;
29   class MemberPointerType;
30   class QualType;
31
32 namespace CodeGen {
33   class CodeGenFunction;
34   class CodeGenModule;
35   class MangleContext;
36
37 /// Implements C++ ABI-specific code generation functions.
38 class CGCXXABI {
39 protected:
40   CodeGenModule &CGM;
41
42   CGCXXABI(CodeGenModule &CGM) : CGM(CGM) {}
43
44 public:
45
46   virtual ~CGCXXABI();
47
48   /// Gets the mangle context.
49   virtual MangleContext &getMangleContext() = 0;
50
51   /// Find the LLVM type used to represent the given member pointer
52   /// type.
53   virtual const llvm::Type *
54   ConvertMemberPointerType(const MemberPointerType *MPT);
55
56   /// Load a member function from an object and a member function
57   /// pointer.  Apply the this-adjustment and set 'This' to the
58   /// adjusted value.
59   virtual llvm::Value *
60   EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF,
61                                   llvm::Value *&This,
62                                   llvm::Value *MemPtr,
63                                   const MemberPointerType *MPT);
64
65   /// Perform a derived-to-base or base-to-derived member pointer
66   /// conversion.
67   virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
68                                                    const CastExpr *E,
69                                                    llvm::Value *Src);
70
71   /// Perform a derived-to-base or base-to-derived member pointer
72   /// conversion on a constant member pointer.
73   virtual llvm::Constant *EmitMemberPointerConversion(llvm::Constant *C,
74                                                       const CastExpr *E);
75
76   /// Return true if the given member pointer can be zero-initialized
77   /// (in the C++ sense) with an LLVM zeroinitializer.
78   virtual bool isZeroInitializable(const MemberPointerType *MPT);
79
80   /// Create a null member pointer of the given type.
81   virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
82
83   /// Create a member pointer for the given method.
84   virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
85
86   /// Create a member pointer for the given field.
87   virtual llvm::Constant *EmitMemberPointer(const FieldDecl *FD);
88
89   /// Emit a comparison between two member pointers.  Returns an i1.
90   virtual llvm::Value *
91   EmitMemberPointerComparison(CodeGenFunction &CGF,
92                               llvm::Value *L,
93                               llvm::Value *R,
94                               const MemberPointerType *MPT,
95                               bool Inequality);
96
97   /// Determine if a member pointer is non-null.  Returns an i1.
98   virtual llvm::Value *
99   EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
100                              llvm::Value *MemPtr,
101                              const MemberPointerType *MPT);
102 };
103
104 /// Creates an instance of a C++ ABI class.
105 CGCXXABI *CreateARMCXXABI(CodeGenModule &CGM);
106 CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
107 CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
108
109 }
110 }
111
112 #endif