1 //===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These classes wrap the information about a call or function
11 // definition used to handle ABI compliancy.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_CODEGEN_CGCALL_H
16 #define LLVM_CLANG_LIB_CODEGEN_CGCALL_H
19 #include "EHScopeStack.h"
20 #include "clang/AST/CanonicalType.h"
21 #include "clang/AST/Type.h"
22 #include "llvm/ADT/FoldingSet.h"
23 #include "llvm/IR/Value.h"
25 // FIXME: Restructure so we don't have to expose so much stuff.
43 typedef SmallVector<llvm::AttributeSet, 8> AttributeListType;
49 CallArg(RValue rv, QualType ty, bool needscopy)
50 : RV(rv), Ty(ty), NeedsCopy(needscopy)
54 /// CallArgList - Type for representing both the value and type of
55 /// arguments in a call.
57 public SmallVector<CallArg, 16> {
59 CallArgList() : StackBase(nullptr), StackBaseMem(nullptr) {}
62 /// The original argument. Note that the argument l-value
63 /// is potentially null.
66 /// The temporary alloca.
67 llvm::Value *Temporary;
69 /// A value to "use" after the writeback, or null.
73 struct CallArgCleanup {
74 EHScopeStack::stable_iterator Cleanup;
76 /// The "is active" insertion point. This instruction is temporary and
77 /// will be removed after insertion.
78 llvm::Instruction *IsActiveIP;
81 void add(RValue rvalue, QualType type, bool needscopy = false) {
82 push_back(CallArg(rvalue, type, needscopy));
85 void addFrom(const CallArgList &other) {
86 insert(end(), other.begin(), other.end());
87 Writebacks.insert(Writebacks.end(),
88 other.Writebacks.begin(), other.Writebacks.end());
91 void addWriteback(LValue srcLV, llvm::Value *temporary,
94 writeback.Source = srcLV;
95 writeback.Temporary = temporary;
96 writeback.ToUse = toUse;
97 Writebacks.push_back(writeback);
100 bool hasWritebacks() const { return !Writebacks.empty(); }
102 typedef llvm::iterator_range<SmallVectorImpl<Writeback>::const_iterator>
103 writeback_const_range;
105 writeback_const_range writebacks() const {
106 return writeback_const_range(Writebacks.begin(), Writebacks.end());
109 void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup,
110 llvm::Instruction *IsActiveIP) {
111 CallArgCleanup ArgCleanup;
112 ArgCleanup.Cleanup = Cleanup;
113 ArgCleanup.IsActiveIP = IsActiveIP;
114 CleanupsToDeactivate.push_back(ArgCleanup);
117 ArrayRef<CallArgCleanup> getCleanupsToDeactivate() const {
118 return CleanupsToDeactivate;
121 void allocateArgumentMemory(CodeGenFunction &CGF);
122 llvm::Instruction *getStackBase() const { return StackBase; }
123 void freeArgumentMemory(CodeGenFunction &CGF) const;
125 /// \brief Returns if we're using an inalloca struct to pass arguments in
127 bool isUsingInAlloca() const { return StackBase; }
130 SmallVector<Writeback, 1> Writebacks;
132 /// Deactivate these cleanups immediately before making the call. This
133 /// is used to cleanup objects that are owned by the callee once the call
135 SmallVector<CallArgCleanup, 1> CleanupsToDeactivate;
137 /// The stacksave call. It dominates all of the argument evaluation.
138 llvm::CallInst *StackBase;
140 /// The alloca holding the stackbase. We need it to maintain SSA form.
141 llvm::AllocaInst *StackBaseMem;
143 /// The iterator pointing to the stack restore cleanup. We manually run and
144 /// deactivate this cleanup after the call in the unexceptional case because
145 /// it doesn't run in the normal order.
146 EHScopeStack::stable_iterator StackCleanup;
149 /// FunctionArgList - Type for representing both the decl and type
150 /// of parameters to a function. The decl must be either a
151 /// ParmVarDecl or ImplicitParamDecl.
152 class FunctionArgList : public SmallVector<const VarDecl*, 16> {
155 /// ReturnValueSlot - Contains the address where the return value of a
156 /// function can be stored, and whether the address is volatile or not.
157 class ReturnValueSlot {
158 llvm::PointerIntPair<llvm::Value *, 2, unsigned int> Value;
160 // Return value slot flags
168 ReturnValueSlot(llvm::Value *Value, bool IsVolatile, bool IsUnused = false)
170 (IsVolatile ? IS_VOLATILE : 0) | (IsUnused ? IS_UNUSED : 0)) {}
172 bool isNull() const { return !getValue(); }
174 bool isVolatile() const { return Value.getInt() & IS_VOLATILE; }
175 llvm::Value *getValue() const { return Value.getPointer(); }
176 bool isUnused() const { return Value.getInt() & IS_UNUSED; }
179 } // end namespace CodeGen
180 } // end namespace clang