2010-01-10 20:58:08 +08:00
|
|
|
//===---- TargetInfo.h - Encapsulate target 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CLANG_CODEGEN_TARGETINFO_H
|
|
|
|
#define CLANG_CODEGEN_TARGETINFO_H
|
|
|
|
|
2011-09-21 16:08:30 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2011-02-20 07:03:58 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2013-05-08 21:44:39 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2011-02-20 07:03:58 +08:00
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
namespace llvm {
|
|
|
|
class GlobalValue;
|
2011-02-20 07:03:58 +08:00
|
|
|
class Type;
|
2010-03-03 12:15:11 +08:00
|
|
|
class Value;
|
2010-01-10 20:58:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class ABIInfo;
|
|
|
|
class Decl;
|
|
|
|
|
|
|
|
namespace CodeGen {
|
2012-02-17 11:33:10 +08:00
|
|
|
class CallArgList;
|
2010-01-10 20:58:08 +08:00
|
|
|
class CodeGenModule;
|
2010-03-03 12:15:11 +08:00
|
|
|
class CodeGenFunction;
|
2011-12-01 12:53:19 +08:00
|
|
|
class CGFunctionInfo;
|
2010-01-10 20:58:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// TargetCodeGenInfo - This class organizes various target-specific
|
|
|
|
/// codegeneration issues, like target-specific attributes, builtins and so
|
|
|
|
/// on.
|
|
|
|
class TargetCodeGenInfo {
|
|
|
|
ABIInfo *Info;
|
|
|
|
public:
|
|
|
|
// WARNING: Acquires the ownership of ABIInfo.
|
2010-01-22 23:41:14 +08:00
|
|
|
TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { }
|
2010-01-10 20:58:08 +08:00
|
|
|
virtual ~TargetCodeGenInfo();
|
|
|
|
|
|
|
|
/// getABIInfo() - Returns ABI info helper for the target.
|
|
|
|
const ABIInfo& getABIInfo() const { return *Info; }
|
|
|
|
|
|
|
|
/// SetTargetAttributes - Provides a convenient hook to handle extra
|
|
|
|
/// target-specific attributes for the given global.
|
|
|
|
virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
2010-01-22 23:41:14 +08:00
|
|
|
CodeGen::CodeGenModule &M) const { }
|
2010-03-02 11:50:12 +08:00
|
|
|
|
2010-07-21 06:17:55 +08:00
|
|
|
/// Determines the size of struct _Unwind_Exception on this platform,
|
|
|
|
/// in 8-bit units. The Itanium ABI defines this as:
|
|
|
|
/// struct _Unwind_Exception {
|
|
|
|
/// uint64 exception_class;
|
|
|
|
/// _Unwind_Exception_Cleanup_Fn exception_cleanup;
|
|
|
|
/// uint64 private_1;
|
|
|
|
/// uint64 private_2;
|
|
|
|
/// };
|
2011-08-30 09:42:09 +08:00
|
|
|
virtual unsigned getSizeOfUnwindException() const;
|
2010-07-21 06:17:55 +08:00
|
|
|
|
2010-03-02 11:50:12 +08:00
|
|
|
/// Controls whether __builtin_extend_pointer should sign-extend
|
|
|
|
/// pointers to uint64_t or zero-extend them (the default). Has
|
|
|
|
/// no effect for targets:
|
|
|
|
/// - that have 64-bit pointers, or
|
|
|
|
/// - that cannot address through registers larger than pointers, or
|
|
|
|
/// - that implicitly ignore/truncate the top bits when addressing
|
|
|
|
/// through such registers.
|
|
|
|
virtual bool extendPointerWithSExt() const { return false; }
|
2010-03-03 12:15:11 +08:00
|
|
|
|
2010-03-06 08:35:14 +08:00
|
|
|
/// Determines the DWARF register number for the stack pointer, for
|
|
|
|
/// exception-handling purposes. Implements __builtin_dwarf_sp_column.
|
|
|
|
///
|
|
|
|
/// Returns -1 if the operation is unsupported by this target.
|
|
|
|
virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Initializes the given DWARF EH register-size table, a char*.
|
|
|
|
/// Implements __builtin_init_dwarf_reg_size_table.
|
|
|
|
///
|
|
|
|
/// Returns true if the operation is unsupported by this target.
|
|
|
|
virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-03 12:15:11 +08:00
|
|
|
/// Performs the code-generation required to convert a return
|
|
|
|
/// address as stored by the system into the actual address of the
|
|
|
|
/// next instruction that will be executed.
|
|
|
|
///
|
|
|
|
/// Used by __builtin_extract_return_addr().
|
|
|
|
virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
return Address;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Performs the code-generation required to convert the address
|
|
|
|
/// of an instruction into a return address suitable for storage
|
|
|
|
/// by the system in a return slot.
|
|
|
|
///
|
|
|
|
/// Used by __builtin_frob_return_addr().
|
|
|
|
virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
return Address;
|
|
|
|
}
|
2011-02-20 07:03:58 +08:00
|
|
|
|
2011-07-11 17:56:20 +08:00
|
|
|
virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
|
2011-07-20 14:58:45 +08:00
|
|
|
StringRef Constraint,
|
2011-07-11 17:56:20 +08:00
|
|
|
llvm::Type* Ty) const {
|
2011-02-20 07:03:58 +08:00
|
|
|
return Ty;
|
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// Retrieve the address of a function to call immediately before
|
|
|
|
/// calling objc_retainAutoreleasedReturnValue. The
|
|
|
|
/// implementation of objc_autoreleaseReturnValue sniffs the
|
|
|
|
/// instruction stream following its return address to decide
|
|
|
|
/// whether it's a call to objc_retainAutoreleasedReturnValue.
|
|
|
|
/// This can be prohibitively expensive, depending on the
|
|
|
|
/// relocation model, and so on some targets it instead sniffs for
|
|
|
|
/// a particular instruction sequence. This functions returns
|
|
|
|
/// that instruction sequence in inline assembly, which will be
|
|
|
|
/// empty if none is required.
|
2011-07-20 14:58:45 +08:00
|
|
|
virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const {
|
2011-06-16 07:02:42 +08:00
|
|
|
return "";
|
|
|
|
}
|
2011-09-21 16:08:30 +08:00
|
|
|
|
|
|
|
/// Determine whether a call to an unprototyped functions under
|
|
|
|
/// the given calling convention should use the variadic
|
|
|
|
/// convention or the non-variadic convention.
|
|
|
|
///
|
|
|
|
/// There's a good reason to make a platform's variadic calling
|
|
|
|
/// convention be different from its non-variadic calling
|
|
|
|
/// convention: the non-variadic arguments can be passed in
|
|
|
|
/// registers (better for performance), and the variadic arguments
|
|
|
|
/// can be passed on the stack (also better for performance). If
|
|
|
|
/// this is done, however, unprototyped functions *must* use the
|
|
|
|
/// non-variadic convention, because C99 states that a call
|
|
|
|
/// through an unprototyped function type must succeed if the
|
|
|
|
/// function was defined with a non-variadic prototype with
|
|
|
|
/// compatible parameters. Therefore, splitting the conventions
|
|
|
|
/// makes it impossible to call a variadic function through an
|
|
|
|
/// unprototyped type. Since function prototypes came out in the
|
|
|
|
/// late 1970s, this is probably an acceptable trade-off.
|
|
|
|
/// Nonetheless, not all platforms are willing to make it, and in
|
|
|
|
/// particularly x86-64 bends over backwards to make the
|
|
|
|
/// conventions compatible.
|
|
|
|
///
|
|
|
|
/// The default is false. This is correct whenever:
|
|
|
|
/// - the conventions are exactly the same, because it does not
|
|
|
|
/// matter and the resulting IR will be somewhat prettier in
|
|
|
|
/// certain cases; or
|
|
|
|
/// - the conventions are substantively different in how they pass
|
|
|
|
/// arguments, because in this case using the variadic convention
|
|
|
|
/// will lead to C99 violations.
|
Fix the required args count for variadic blocks.
We were emitting calls to blocks as if all arguments were
required --- i.e. with signature (A,B,C,D,...) rather than
(A,B,...). This patch fixes that and accounts for the
implicit block-context argument as a required argument.
In addition, this patch changes the function type under which
we call unprototyped functions on platforms like x86-64 that
guarantee compatibility of variadic functions with unprototyped
function types; previously we would always call such functions
under the LLVM type T (...)*, but now we will call them under
the type T (A,B,C,D,...)*. This last change should have no
material effect except for making the type conventions more
explicit; it was a side-effect of the most convenient implementation.
llvm-svn: 169588
2012-12-07 15:03:17 +08:00
|
|
|
///
|
|
|
|
/// However, some platforms make the conventions identical except
|
|
|
|
/// for passing additional out-of-band information to a variadic
|
|
|
|
/// function: for example, x86-64 passes the number of SSE
|
|
|
|
/// arguments in %al. On these platforms, it is desireable to
|
|
|
|
/// call unprototyped functions using the variadic convention so
|
|
|
|
/// that unprototyped calls to varargs functions still succeed.
|
2012-02-17 11:33:10 +08:00
|
|
|
virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args,
|
|
|
|
const FunctionNoProtoType *fnType) const;
|
2013-05-08 21:44:39 +08:00
|
|
|
|
|
|
|
/// Gets the linker options necessary to link a dependent library on this
|
|
|
|
/// platform.
|
|
|
|
virtual void getDependentLibraryOption(llvm::StringRef Lib,
|
|
|
|
llvm::SmallString<24> &Opt) const;
|
2013-06-04 10:07:14 +08:00
|
|
|
|
|
|
|
/// Gets the linker options necessary to detect object file mismatches on
|
|
|
|
/// this platform.
|
|
|
|
virtual void getDetectMismatchOption(llvm::StringRef Name,
|
|
|
|
llvm::StringRef Value,
|
|
|
|
llvm::SmallString<32> &Opt) const {}
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CLANG_CODEGEN_TARGETINFO_H
|