2008-09-09 05:33:45 +08:00
|
|
|
//===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These classes wrap the information about a call or function
|
|
|
|
// definition used to handle ABI compliancy.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CGCALL_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CGCALL_H
|
2008-09-09 05:33:45 +08:00
|
|
|
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "CGValue.h"
|
2013-06-21 20:45:15 +08:00
|
|
|
#include "EHScopeStack.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/CanonicalType.h"
|
|
|
|
#include "clang/AST/Type.h"
|
2009-12-25 03:08:58 +08:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/Value.h"
|
2008-09-09 09:06:48 +08:00
|
|
|
|
2009-02-03 13:31:23 +08:00
|
|
|
// FIXME: Restructure so we don't have to expose so much stuff.
|
|
|
|
#include "ABIInfo.h"
|
|
|
|
|
2008-09-09 05:33:45 +08:00
|
|
|
namespace llvm {
|
2013-01-27 10:46:53 +08:00
|
|
|
class AttributeSet;
|
2009-02-03 13:31:23 +08:00
|
|
|
class Function;
|
|
|
|
class Type;
|
2008-09-09 05:33:45 +08:00
|
|
|
class Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class ASTContext;
|
|
|
|
class Decl;
|
|
|
|
class FunctionDecl;
|
|
|
|
class ObjCMethodDecl;
|
2008-09-10 07:14:03 +08:00
|
|
|
class VarDecl;
|
2008-09-09 05:33:45 +08:00
|
|
|
|
|
|
|
namespace CodeGen {
|
2013-01-27 10:46:53 +08:00
|
|
|
typedef SmallVector<llvm::AttributeSet, 8> AttributeListType;
|
2008-09-09 05:33:45 +08:00
|
|
|
|
2011-05-03 02:05:27 +08:00
|
|
|
struct CallArg {
|
|
|
|
RValue RV;
|
|
|
|
QualType Ty;
|
2011-05-26 08:10:27 +08:00
|
|
|
bool NeedsCopy;
|
|
|
|
CallArg(RValue rv, QualType ty, bool needscopy)
|
|
|
|
: RV(rv), Ty(ty), NeedsCopy(needscopy)
|
2011-05-03 02:05:27 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2008-09-09 05:33:45 +08:00
|
|
|
/// CallArgList - Type for representing both the value and type of
|
|
|
|
/// arguments in a call.
|
2011-03-09 12:27:21 +08:00
|
|
|
class CallArgList :
|
2011-07-20 14:58:45 +08:00
|
|
|
public SmallVector<CallArg, 16> {
|
2011-03-12 04:59:21 +08:00
|
|
|
public:
|
2014-05-21 13:09:00 +08:00
|
|
|
CallArgList() : StackBase(nullptr), StackBaseMem(nullptr) {}
|
2014-02-01 08:04:45 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
struct Writeback {
|
2013-03-23 10:35:54 +08:00
|
|
|
/// The original argument. Note that the argument l-value
|
|
|
|
/// is potentially null.
|
|
|
|
LValue Source;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// The temporary alloca.
|
|
|
|
llvm::Value *Temporary;
|
2013-03-23 10:35:54 +08:00
|
|
|
|
|
|
|
/// A value to "use" after the writeback, or null.
|
|
|
|
llvm::Value *ToUse;
|
2011-06-16 07:02:42 +08:00
|
|
|
};
|
|
|
|
|
2013-06-21 20:45:15 +08:00
|
|
|
struct CallArgCleanup {
|
|
|
|
EHScopeStack::stable_iterator Cleanup;
|
|
|
|
|
|
|
|
/// The "is active" insertion point. This instruction is temporary and
|
|
|
|
/// will be removed after insertion.
|
|
|
|
llvm::Instruction *IsActiveIP;
|
|
|
|
};
|
|
|
|
|
2011-05-26 08:10:27 +08:00
|
|
|
void add(RValue rvalue, QualType type, bool needscopy = false) {
|
|
|
|
push_back(CallArg(rvalue, type, needscopy));
|
2011-03-12 04:59:21 +08:00
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
void addFrom(const CallArgList &other) {
|
|
|
|
insert(end(), other.begin(), other.end());
|
|
|
|
Writebacks.insert(Writebacks.end(),
|
|
|
|
other.Writebacks.begin(), other.Writebacks.end());
|
|
|
|
}
|
|
|
|
|
2013-03-23 10:35:54 +08:00
|
|
|
void addWriteback(LValue srcLV, llvm::Value *temporary,
|
|
|
|
llvm::Value *toUse) {
|
2011-06-16 07:02:42 +08:00
|
|
|
Writeback writeback;
|
2013-03-23 10:35:54 +08:00
|
|
|
writeback.Source = srcLV;
|
2011-06-16 07:02:42 +08:00
|
|
|
writeback.Temporary = temporary;
|
2013-03-23 10:35:54 +08:00
|
|
|
writeback.ToUse = toUse;
|
2011-06-16 07:02:42 +08:00
|
|
|
Writebacks.push_back(writeback);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasWritebacks() const { return !Writebacks.empty(); }
|
|
|
|
|
2014-03-18 01:22:27 +08:00
|
|
|
typedef llvm::iterator_range<SmallVectorImpl<Writeback>::const_iterator>
|
|
|
|
writeback_const_range;
|
|
|
|
|
|
|
|
writeback_const_range writebacks() const {
|
|
|
|
return writeback_const_range(Writebacks.begin(), Writebacks.end());
|
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2013-06-21 20:45:15 +08:00
|
|
|
void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup,
|
|
|
|
llvm::Instruction *IsActiveIP) {
|
|
|
|
CallArgCleanup ArgCleanup;
|
|
|
|
ArgCleanup.Cleanup = Cleanup;
|
|
|
|
ArgCleanup.IsActiveIP = IsActiveIP;
|
|
|
|
CleanupsToDeactivate.push_back(ArgCleanup);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayRef<CallArgCleanup> getCleanupsToDeactivate() const {
|
|
|
|
return CleanupsToDeactivate;
|
|
|
|
}
|
|
|
|
|
2014-02-01 08:04:45 +08:00
|
|
|
void allocateArgumentMemory(CodeGenFunction &CGF);
|
|
|
|
llvm::Instruction *getStackBase() const { return StackBase; }
|
|
|
|
void freeArgumentMemory(CodeGenFunction &CGF) const;
|
|
|
|
|
|
|
|
/// \brief Returns if we're using an inalloca struct to pass arguments in
|
|
|
|
/// memory.
|
|
|
|
bool isUsingInAlloca() const { return StackBase; }
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
private:
|
2011-07-20 14:58:45 +08:00
|
|
|
SmallVector<Writeback, 1> Writebacks;
|
2013-06-21 20:45:15 +08:00
|
|
|
|
|
|
|
/// Deactivate these cleanups immediately before making the call. This
|
|
|
|
/// is used to cleanup objects that are owned by the callee once the call
|
|
|
|
/// occurs.
|
|
|
|
SmallVector<CallArgCleanup, 1> CleanupsToDeactivate;
|
2014-02-01 08:04:45 +08:00
|
|
|
|
|
|
|
/// The stacksave call. It dominates all of the argument evaluation.
|
|
|
|
llvm::CallInst *StackBase;
|
|
|
|
|
|
|
|
/// The alloca holding the stackbase. We need it to maintain SSA form.
|
|
|
|
llvm::AllocaInst *StackBaseMem;
|
|
|
|
|
|
|
|
/// The iterator pointing to the stack restore cleanup. We manually run and
|
|
|
|
/// deactivate this cleanup after the call in the unexceptional case because
|
|
|
|
/// it doesn't run in the normal order.
|
|
|
|
EHScopeStack::stable_iterator StackCleanup;
|
2011-03-09 12:27:21 +08:00
|
|
|
};
|
2008-09-09 05:33:45 +08:00
|
|
|
|
2008-09-10 07:14:03 +08:00
|
|
|
/// FunctionArgList - Type for representing both the decl and type
|
|
|
|
/// of parameters to a function. The decl must be either a
|
|
|
|
/// ParmVarDecl or ImplicitParamDecl.
|
2011-07-20 14:58:45 +08:00
|
|
|
class FunctionArgList : public SmallVector<const VarDecl*, 16> {
|
2011-03-09 12:27:21 +08:00
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-12-25 04:40:36 +08:00
|
|
|
/// ReturnValueSlot - Contains the address where the return value of a
|
|
|
|
/// function can be stored, and whether the address is volatile or not.
|
2009-12-25 03:08:58 +08:00
|
|
|
class ReturnValueSlot {
|
|
|
|
llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ReturnValueSlot() {}
|
|
|
|
ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
|
|
|
|
: Value(Value, IsVolatile) {}
|
|
|
|
|
|
|
|
bool isNull() const { return !getValue(); }
|
|
|
|
|
|
|
|
bool isVolatile() const { return Value.getInt(); }
|
|
|
|
llvm::Value *getValue() const { return Value.getPointer(); }
|
|
|
|
};
|
|
|
|
|
2008-09-09 05:33:45 +08:00
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|