xref: /minix3/external/bsd/llvm/dist/clang/lib/CodeGen/CGCall.h (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc //===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===//
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7*f4a2713aSLionel Sambuc //
8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9*f4a2713aSLionel Sambuc //
10*f4a2713aSLionel Sambuc // These classes wrap the information about a call or function
11*f4a2713aSLionel Sambuc // definition used to handle ABI compliancy.
12*f4a2713aSLionel Sambuc //
13*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc #ifndef CLANG_CODEGEN_CGCALL_H
16*f4a2713aSLionel Sambuc #define CLANG_CODEGEN_CGCALL_H
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc #include "CGValue.h"
19*f4a2713aSLionel Sambuc #include "EHScopeStack.h"
20*f4a2713aSLionel Sambuc #include "clang/AST/CanonicalType.h"
21*f4a2713aSLionel Sambuc #include "clang/AST/Type.h"
22*f4a2713aSLionel Sambuc #include "llvm/ADT/FoldingSet.h"
23*f4a2713aSLionel Sambuc #include "llvm/IR/Value.h"
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc // FIXME: Restructure so we don't have to expose so much stuff.
26*f4a2713aSLionel Sambuc #include "ABIInfo.h"
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc namespace llvm {
29*f4a2713aSLionel Sambuc   class AttributeSet;
30*f4a2713aSLionel Sambuc   class Function;
31*f4a2713aSLionel Sambuc   class Type;
32*f4a2713aSLionel Sambuc   class Value;
33*f4a2713aSLionel Sambuc }
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc namespace clang {
36*f4a2713aSLionel Sambuc   class ASTContext;
37*f4a2713aSLionel Sambuc   class Decl;
38*f4a2713aSLionel Sambuc   class FunctionDecl;
39*f4a2713aSLionel Sambuc   class ObjCMethodDecl;
40*f4a2713aSLionel Sambuc   class VarDecl;
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc namespace CodeGen {
43*f4a2713aSLionel Sambuc   typedef SmallVector<llvm::AttributeSet, 8> AttributeListType;
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc   struct CallArg {
46*f4a2713aSLionel Sambuc     RValue RV;
47*f4a2713aSLionel Sambuc     QualType Ty;
48*f4a2713aSLionel Sambuc     bool NeedsCopy;
49*f4a2713aSLionel Sambuc     CallArg(RValue rv, QualType ty, bool needscopy)
50*f4a2713aSLionel Sambuc     : RV(rv), Ty(ty), NeedsCopy(needscopy)
51*f4a2713aSLionel Sambuc     { }
52*f4a2713aSLionel Sambuc   };
53*f4a2713aSLionel Sambuc 
54*f4a2713aSLionel Sambuc   /// CallArgList - Type for representing both the value and type of
55*f4a2713aSLionel Sambuc   /// arguments in a call.
56*f4a2713aSLionel Sambuc   class CallArgList :
57*f4a2713aSLionel Sambuc     public SmallVector<CallArg, 16> {
58*f4a2713aSLionel Sambuc   public:
59*f4a2713aSLionel Sambuc     struct Writeback {
60*f4a2713aSLionel Sambuc       /// The original argument.  Note that the argument l-value
61*f4a2713aSLionel Sambuc       /// is potentially null.
62*f4a2713aSLionel Sambuc       LValue Source;
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc       /// The temporary alloca.
65*f4a2713aSLionel Sambuc       llvm::Value *Temporary;
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc       /// A value to "use" after the writeback, or null.
68*f4a2713aSLionel Sambuc       llvm::Value *ToUse;
69*f4a2713aSLionel Sambuc     };
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc     struct CallArgCleanup {
72*f4a2713aSLionel Sambuc       EHScopeStack::stable_iterator Cleanup;
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc       /// The "is active" insertion point.  This instruction is temporary and
75*f4a2713aSLionel Sambuc       /// will be removed after insertion.
76*f4a2713aSLionel Sambuc       llvm::Instruction *IsActiveIP;
77*f4a2713aSLionel Sambuc     };
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc     void add(RValue rvalue, QualType type, bool needscopy = false) {
80*f4a2713aSLionel Sambuc       push_back(CallArg(rvalue, type, needscopy));
81*f4a2713aSLionel Sambuc     }
82*f4a2713aSLionel Sambuc 
83*f4a2713aSLionel Sambuc     void addFrom(const CallArgList &other) {
84*f4a2713aSLionel Sambuc       insert(end(), other.begin(), other.end());
85*f4a2713aSLionel Sambuc       Writebacks.insert(Writebacks.end(),
86*f4a2713aSLionel Sambuc                         other.Writebacks.begin(), other.Writebacks.end());
87*f4a2713aSLionel Sambuc     }
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc     void addWriteback(LValue srcLV, llvm::Value *temporary,
90*f4a2713aSLionel Sambuc                       llvm::Value *toUse) {
91*f4a2713aSLionel Sambuc       Writeback writeback;
92*f4a2713aSLionel Sambuc       writeback.Source = srcLV;
93*f4a2713aSLionel Sambuc       writeback.Temporary = temporary;
94*f4a2713aSLionel Sambuc       writeback.ToUse = toUse;
95*f4a2713aSLionel Sambuc       Writebacks.push_back(writeback);
96*f4a2713aSLionel Sambuc     }
97*f4a2713aSLionel Sambuc 
98*f4a2713aSLionel Sambuc     bool hasWritebacks() const { return !Writebacks.empty(); }
99*f4a2713aSLionel Sambuc 
100*f4a2713aSLionel Sambuc     typedef SmallVectorImpl<Writeback>::const_iterator writeback_iterator;
101*f4a2713aSLionel Sambuc     writeback_iterator writeback_begin() const { return Writebacks.begin(); }
102*f4a2713aSLionel Sambuc     writeback_iterator writeback_end() const { return Writebacks.end(); }
103*f4a2713aSLionel Sambuc 
104*f4a2713aSLionel Sambuc     void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup,
105*f4a2713aSLionel Sambuc                                    llvm::Instruction *IsActiveIP) {
106*f4a2713aSLionel Sambuc       CallArgCleanup ArgCleanup;
107*f4a2713aSLionel Sambuc       ArgCleanup.Cleanup = Cleanup;
108*f4a2713aSLionel Sambuc       ArgCleanup.IsActiveIP = IsActiveIP;
109*f4a2713aSLionel Sambuc       CleanupsToDeactivate.push_back(ArgCleanup);
110*f4a2713aSLionel Sambuc     }
111*f4a2713aSLionel Sambuc 
112*f4a2713aSLionel Sambuc     ArrayRef<CallArgCleanup> getCleanupsToDeactivate() const {
113*f4a2713aSLionel Sambuc       return CleanupsToDeactivate;
114*f4a2713aSLionel Sambuc     }
115*f4a2713aSLionel Sambuc 
116*f4a2713aSLionel Sambuc   private:
117*f4a2713aSLionel Sambuc     SmallVector<Writeback, 1> Writebacks;
118*f4a2713aSLionel Sambuc 
119*f4a2713aSLionel Sambuc     /// Deactivate these cleanups immediately before making the call.  This
120*f4a2713aSLionel Sambuc     /// is used to cleanup objects that are owned by the callee once the call
121*f4a2713aSLionel Sambuc     /// occurs.
122*f4a2713aSLionel Sambuc     SmallVector<CallArgCleanup, 1> CleanupsToDeactivate;
123*f4a2713aSLionel Sambuc   };
124*f4a2713aSLionel Sambuc 
125*f4a2713aSLionel Sambuc   /// FunctionArgList - Type for representing both the decl and type
126*f4a2713aSLionel Sambuc   /// of parameters to a function. The decl must be either a
127*f4a2713aSLionel Sambuc   /// ParmVarDecl or ImplicitParamDecl.
128*f4a2713aSLionel Sambuc   class FunctionArgList : public SmallVector<const VarDecl*, 16> {
129*f4a2713aSLionel Sambuc   };
130*f4a2713aSLionel Sambuc 
131*f4a2713aSLionel Sambuc   /// ReturnValueSlot - Contains the address where the return value of a
132*f4a2713aSLionel Sambuc   /// function can be stored, and whether the address is volatile or not.
133*f4a2713aSLionel Sambuc   class ReturnValueSlot {
134*f4a2713aSLionel Sambuc     llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
135*f4a2713aSLionel Sambuc 
136*f4a2713aSLionel Sambuc   public:
137*f4a2713aSLionel Sambuc     ReturnValueSlot() {}
138*f4a2713aSLionel Sambuc     ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
139*f4a2713aSLionel Sambuc       : Value(Value, IsVolatile) {}
140*f4a2713aSLionel Sambuc 
141*f4a2713aSLionel Sambuc     bool isNull() const { return !getValue(); }
142*f4a2713aSLionel Sambuc 
143*f4a2713aSLionel Sambuc     bool isVolatile() const { return Value.getInt(); }
144*f4a2713aSLionel Sambuc     llvm::Value *getValue() const { return Value.getPointer(); }
145*f4a2713aSLionel Sambuc   };
146*f4a2713aSLionel Sambuc 
147*f4a2713aSLionel Sambuc }  // end namespace CodeGen
148*f4a2713aSLionel Sambuc }  // end namespace clang
149*f4a2713aSLionel Sambuc 
150*f4a2713aSLionel Sambuc #endif
151