CGCall.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //===----- CGCall.h - Encapsulate calling convention details ----*- 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. // These classes wrap the information about a call or function
  11. // definition used to handle ABI compliancy.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CLANG_LIB_CODEGEN_CGCALL_H
  15. #define LLVM_CLANG_LIB_CODEGEN_CGCALL_H
  16. #include "CGValue.h"
  17. #include "EHScopeStack.h"
  18. #include "clang/AST/CanonicalType.h"
  19. #include "clang/AST/Type.h"
  20. #include "llvm/ADT/FoldingSet.h"
  21. #include "llvm/IR/Value.h"
  22. // FIXME: Restructure so we don't have to expose so much stuff.
  23. #include "ABIInfo.h"
  24. namespace llvm {
  25. class AttributeSet;
  26. class Function;
  27. class Type;
  28. class Value;
  29. }
  30. namespace clang {
  31. class ASTContext;
  32. class Decl;
  33. class FunctionDecl;
  34. class ObjCMethodDecl;
  35. class VarDecl;
  36. namespace CodeGen {
  37. typedef SmallVector<llvm::AttributeSet, 8> AttributeListType;
  38. struct CallArg {
  39. RValue RV;
  40. QualType Ty;
  41. bool NeedsCopy;
  42. CallArg(RValue rv, QualType ty, bool needscopy)
  43. : RV(rv), Ty(ty), NeedsCopy(needscopy)
  44. { }
  45. };
  46. /// CallArgList - Type for representing both the value and type of
  47. /// arguments in a call.
  48. class CallArgList :
  49. public SmallVector<CallArg, 16> {
  50. public:
  51. CallArgList() : StackBase(nullptr), StackBaseMem(nullptr) {}
  52. struct Writeback {
  53. /// The original argument. Note that the argument l-value
  54. /// is potentially null.
  55. LValue Source;
  56. /// The temporary alloca.
  57. llvm::Value *Temporary;
  58. /// A value to "use" after the writeback, or null.
  59. llvm::Value *ToUse;
  60. };
  61. struct CallArgCleanup {
  62. EHScopeStack::stable_iterator Cleanup;
  63. /// The "is active" insertion point. This instruction is temporary and
  64. /// will be removed after insertion.
  65. llvm::Instruction *IsActiveIP;
  66. };
  67. void add(RValue rvalue, QualType type, bool needscopy = false) {
  68. push_back(CallArg(rvalue, type, needscopy));
  69. }
  70. void addFrom(const CallArgList &other) {
  71. insert(end(), other.begin(), other.end());
  72. #if 0 // HLSL Change - no ObjC support
  73. Writebacks.insert(Writebacks.end(),
  74. other.Writebacks.begin(), other.Writebacks.end());
  75. #else
  76. assert(!other.hasWritebacks() && "writeback is unreachable in HLSL");
  77. #endif // HLSL Change - no ObjC support
  78. }
  79. void addWriteback(LValue srcLV, llvm::Value *temporary,
  80. llvm::Value *toUse) {
  81. #if 0 // HLSL Change - no ObjC support
  82. Writeback writeback;
  83. writeback.Source = srcLV;
  84. writeback.Temporary = temporary;
  85. writeback.ToUse = toUse;
  86. Writebacks.push_back(writeback);
  87. #else
  88. llvm_unreachable("addWriteback is unreachable in HLSL");
  89. #endif // HLSL Change - no ObjC support
  90. }
  91. bool hasWritebacks() const { return !Writebacks.empty(); }
  92. typedef llvm::iterator_range<SmallVectorImpl<Writeback>::const_iterator>
  93. writeback_const_range;
  94. writeback_const_range writebacks() const {
  95. return writeback_const_range(Writebacks.begin(), Writebacks.end());
  96. }
  97. void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup,
  98. llvm::Instruction *IsActiveIP) {
  99. CallArgCleanup ArgCleanup;
  100. ArgCleanup.Cleanup = Cleanup;
  101. ArgCleanup.IsActiveIP = IsActiveIP;
  102. CleanupsToDeactivate.push_back(ArgCleanup);
  103. }
  104. ArrayRef<CallArgCleanup> getCleanupsToDeactivate() const {
  105. return CleanupsToDeactivate;
  106. }
  107. void allocateArgumentMemory(CodeGenFunction &CGF);
  108. llvm::Instruction *getStackBase() const { return StackBase; }
  109. void freeArgumentMemory(CodeGenFunction &CGF) const;
  110. /// \brief Returns if we're using an inalloca struct to pass arguments in
  111. /// memory.
  112. bool isUsingInAlloca() const { return StackBase; }
  113. private:
  114. SmallVector<Writeback, 1> Writebacks;
  115. /// Deactivate these cleanups immediately before making the call. This
  116. /// is used to cleanup objects that are owned by the callee once the call
  117. /// occurs.
  118. SmallVector<CallArgCleanup, 1> CleanupsToDeactivate;
  119. /// The stacksave call. It dominates all of the argument evaluation.
  120. llvm::CallInst *StackBase;
  121. /// The alloca holding the stackbase. We need it to maintain SSA form.
  122. llvm::AllocaInst *StackBaseMem;
  123. /// The iterator pointing to the stack restore cleanup. We manually run and
  124. /// deactivate this cleanup after the call in the unexceptional case because
  125. /// it doesn't run in the normal order.
  126. EHScopeStack::stable_iterator StackCleanup;
  127. };
  128. /// FunctionArgList - Type for representing both the decl and type
  129. /// of parameters to a function. The decl must be either a
  130. /// ParmVarDecl or ImplicitParamDecl.
  131. class FunctionArgList : public SmallVector<const VarDecl*, 16> {
  132. };
  133. /// ReturnValueSlot - Contains the address where the return value of a
  134. /// function can be stored, and whether the address is volatile or not.
  135. class ReturnValueSlot {
  136. llvm::PointerIntPair<llvm::Value *, 2, unsigned int> Value;
  137. // Return value slot flags
  138. enum Flags {
  139. IS_VOLATILE = 0x1,
  140. IS_UNUSED = 0x2,
  141. };
  142. public:
  143. ReturnValueSlot() {}
  144. ReturnValueSlot(llvm::Value *Value, bool IsVolatile, bool IsUnused = false)
  145. : Value(Value,
  146. (IsVolatile ? IS_VOLATILE : 0) | (IsUnused ? IS_UNUSED : 0)) {}
  147. bool isNull() const { return !getValue(); }
  148. bool isVolatile() const { return Value.getInt() & IS_VOLATILE; }
  149. llvm::Value *getValue() const { return Value.getPointer(); }
  150. bool isUnused() const { return Value.getInt() & IS_UNUSED; }
  151. };
  152. } // end namespace CodeGen
  153. } // end namespace clang
  154. #endif