2008-07-30 07:18:29 +08:00
|
|
|
//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-02-14 03:12:34 +08:00
|
|
|
// This is the internal per-translation-unit state used for llvm translation.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-03-01 01:10:38 +08:00
|
|
|
#ifndef CLANG_CODEGEN_CODEGENMODULE_H
|
|
|
|
#define CLANG_CODEGEN_CODEGENMODULE_H
|
2007-05-24 14:29:05 +08:00
|
|
|
|
2009-04-14 14:00:08 +08:00
|
|
|
#include "clang/Basic/LangOptions.h"
|
2008-05-22 08:50:06 +08:00
|
|
|
#include "clang/AST/Attr.h"
|
2009-05-05 12:44:02 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-09-11 08:07:24 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2009-03-26 13:00:52 +08:00
|
|
|
#include "CGBlocks.h"
|
|
|
|
#include "CGCall.h"
|
2009-04-15 23:55:24 +08:00
|
|
|
#include "CGCXX.h"
|
2009-10-12 06:13:54 +08:00
|
|
|
#include "CGVtable.h"
|
2009-03-26 13:00:52 +08:00
|
|
|
#include "CodeGenTypes.h"
|
2009-11-13 12:25:07 +08:00
|
|
|
#include "GlobalDecl.h"
|
2009-10-07 09:06:45 +08:00
|
|
|
#include "Mangle.h"
|
2009-07-13 12:10:07 +08:00
|
|
|
#include "llvm/Module.h"
|
2007-06-20 12:44:43 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-08-21 08:21:21 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2009-02-19 07:53:56 +08:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2009-04-01 06:37:52 +08:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2009-01-04 10:08:04 +08:00
|
|
|
#include <list>
|
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace llvm {
|
|
|
|
class Module;
|
2007-06-16 08:12:05 +08:00
|
|
|
class Constant;
|
2007-06-23 02:48:09 +08:00
|
|
|
class Function;
|
2008-04-19 12:17:09 +08:00
|
|
|
class GlobalValue;
|
2007-11-01 04:01:01 +08:00
|
|
|
class TargetData;
|
2008-06-01 23:54:49 +08:00
|
|
|
class FunctionType;
|
2009-08-12 01:46:57 +08:00
|
|
|
class LLVMContext;
|
2007-06-16 07:05:46 +08:00
|
|
|
}
|
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace clang {
|
2010-01-10 20:58:08 +08:00
|
|
|
class TargetCodeGenInfo;
|
2007-05-24 14:29:05 +08:00
|
|
|
class ASTContext;
|
|
|
|
class FunctionDecl;
|
2008-08-25 14:18:57 +08:00
|
|
|
class IdentifierInfo;
|
2008-03-31 07:03:07 +08:00
|
|
|
class ObjCMethodDecl;
|
2008-06-01 22:13:53 +08:00
|
|
|
class ObjCImplementationDecl;
|
|
|
|
class ObjCCategoryImplDecl;
|
|
|
|
class ObjCProtocolDecl;
|
2009-02-25 06:18:39 +08:00
|
|
|
class ObjCEncodeExpr;
|
2009-02-13 01:55:02 +08:00
|
|
|
class BlockExpr;
|
2010-01-26 21:48:07 +08:00
|
|
|
class CharUnits;
|
2007-06-16 08:12:05 +08:00
|
|
|
class Decl;
|
2007-12-02 08:11:25 +08:00
|
|
|
class Expr;
|
2007-12-02 15:19:18 +08:00
|
|
|
class Stmt;
|
2008-08-11 04:25:57 +08:00
|
|
|
class StringLiteral;
|
2008-04-21 04:38:08 +08:00
|
|
|
class NamedDecl;
|
2008-07-30 07:18:29 +08:00
|
|
|
class ValueDecl;
|
2007-12-18 16:16:44 +08:00
|
|
|
class VarDecl;
|
2009-03-07 20:16:37 +08:00
|
|
|
class LangOptions;
|
2009-11-13 01:24:48 +08:00
|
|
|
class CodeGenOptions;
|
2007-12-02 09:40:18 +08:00
|
|
|
class Diagnostic;
|
2008-04-19 12:17:09 +08:00
|
|
|
class AnnotateAttr;
|
2009-04-17 09:58:57 +08:00
|
|
|
class CXXDestructorDecl;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace CodeGen {
|
|
|
|
|
2008-02-27 05:41:45 +08:00
|
|
|
class CodeGenFunction;
|
2008-05-08 16:54:20 +08:00
|
|
|
class CGDebugInfo;
|
2008-08-13 08:59:25 +08:00
|
|
|
class CGObjCRuntime;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2009-09-11 07:38:47 +08:00
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// CodeGenModule - This class organizes the cross-function state that is used
|
|
|
|
/// while generating LLVM code.
|
2009-03-05 02:17:45 +08:00
|
|
|
class CodeGenModule : public BlockModule {
|
2009-02-24 12:21:31 +08:00
|
|
|
CodeGenModule(const CodeGenModule&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const CodeGenModule&); // DO NOT IMPLEMENT
|
|
|
|
|
2009-09-13 06:45:21 +08:00
|
|
|
typedef std::vector<std::pair<llvm::Constant*, int> > CtorList;
|
2008-08-01 08:01:51 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
ASTContext &Context;
|
2007-11-28 13:34:05 +08:00
|
|
|
const LangOptions &Features;
|
2009-11-13 01:24:48 +08:00
|
|
|
const CodeGenOptions &CodeGenOpts;
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::Module &TheModule;
|
2007-11-01 04:01:01 +08:00
|
|
|
const llvm::TargetData &TheTargetData;
|
2010-01-10 20:58:08 +08:00
|
|
|
mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
|
2007-12-02 09:40:18 +08:00
|
|
|
Diagnostic &Diags;
|
2007-06-16 08:16:26 +08:00
|
|
|
CodeGenTypes Types;
|
2009-10-07 09:06:45 +08:00
|
|
|
MangleContext MangleCtx;
|
|
|
|
|
2009-10-12 06:13:54 +08:00
|
|
|
/// VtableInfo - Holds information about C++ vtables.
|
|
|
|
CGVtableInfo VtableInfo;
|
|
|
|
|
2008-08-06 02:50:11 +08:00
|
|
|
CGObjCRuntime* Runtime;
|
|
|
|
CGDebugInfo* DebugInfo;
|
2009-10-07 09:06:45 +08:00
|
|
|
|
2007-06-23 02:48:09 +08:00
|
|
|
llvm::Function *MemCpyFn;
|
2008-05-26 20:59:39 +08:00
|
|
|
llvm::Function *MemMoveFn;
|
2008-02-20 06:01:01 +08:00
|
|
|
llvm::Function *MemSetFn;
|
2008-07-31 00:32:24 +08:00
|
|
|
|
2009-02-19 07:53:56 +08:00
|
|
|
/// GlobalDeclMap - Mapping of decl names (represented as unique
|
|
|
|
/// character pointers from either the identifier table or the set
|
|
|
|
/// of mangled names) to global variables we have already
|
|
|
|
/// emitted. Note that the entries in this map are the actual
|
|
|
|
/// globals and therefore may not be of the same type as the decl,
|
|
|
|
/// they should be bitcasted on retrieval. Also note that the
|
2009-03-21 15:48:31 +08:00
|
|
|
/// globals are keyed on their source mangled name, not the global name
|
2009-03-21 17:44:56 +08:00
|
|
|
/// (which may change with attributes such as asm-labels). The key
|
2009-02-19 07:53:56 +08:00
|
|
|
/// to this map should be generated using getMangledName().
|
2009-03-21 17:44:56 +08:00
|
|
|
///
|
|
|
|
/// Note that this map always lines up exactly with the contents of the LLVM
|
|
|
|
/// IR symbol table, but this is quicker to query since it is doing uniqued
|
|
|
|
/// pointer lookups instead of full string lookups.
|
2009-02-19 07:53:56 +08:00
|
|
|
llvm::DenseMap<const char*, llvm::GlobalValue*> GlobalDeclMap;
|
|
|
|
|
|
|
|
/// \brief Contains the strings used for mangled names.
|
|
|
|
///
|
|
|
|
/// FIXME: Eventually, this should map from the semantic/canonical
|
|
|
|
/// declaration for each global entity to its mangled name (if it
|
|
|
|
/// has one).
|
|
|
|
llvm::StringSet<> MangledNames;
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2009-03-21 17:44:56 +08:00
|
|
|
/// DeferredDecls - This contains all the decls which have definitions but
|
|
|
|
/// which are deferred for emission and therefore should only be output if
|
|
|
|
/// they are actually used. If a decl is in this, then it is known to have
|
|
|
|
/// not been referenced yet. The key to this map is a uniqued mangled name.
|
2009-05-05 12:44:02 +08:00
|
|
|
llvm::DenseMap<const char*, GlobalDecl> DeferredDecls;
|
2009-03-21 17:44:56 +08:00
|
|
|
|
|
|
|
/// DeferredDeclsToEmit - This is a list of deferred decls which we have seen
|
|
|
|
/// that *are* actually referenced. These get code generated when the module
|
|
|
|
/// is done.
|
2009-05-05 12:44:02 +08:00
|
|
|
std::vector<GlobalDecl> DeferredDeclsToEmit;
|
2009-04-16 06:08:45 +08:00
|
|
|
|
2009-02-14 04:29:50 +08:00
|
|
|
/// LLVMUsed - List of global values which are required to be
|
|
|
|
/// present in the object file; bitcast to i8*. This is used for
|
|
|
|
/// forcing visibility of symbols which may otherwise be optimized
|
|
|
|
/// out.
|
2009-04-01 06:37:52 +08:00
|
|
|
std::vector<llvm::WeakVH> LLVMUsed;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
|
|
|
/// GlobalCtors - Store the list of global constructors and their respective
|
|
|
|
/// priorities to be emitted when the translation unit is complete.
|
2008-08-01 08:01:51 +08:00
|
|
|
CtorList GlobalCtors;
|
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// GlobalDtors - Store the list of global destructors and their respective
|
|
|
|
/// priorities to be emitted when the translation unit is complete.
|
2008-08-01 08:01:51 +08:00
|
|
|
CtorList GlobalDtors;
|
|
|
|
|
2008-04-19 07:43:57 +08:00
|
|
|
std::vector<llvm::Constant*> Annotations;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2007-08-21 08:21:21 +08:00
|
|
|
llvm::StringMap<llvm::Constant*> CFConstantStringMap;
|
2007-11-28 13:34:05 +08:00
|
|
|
llvm::StringMap<llvm::Constant*> ConstantStringMap;
|
2008-08-24 02:37:06 +08:00
|
|
|
|
2009-08-09 07:24:23 +08:00
|
|
|
/// CXXGlobalInits - Variables with global initializers that need to run
|
|
|
|
/// before main.
|
2010-01-08 08:50:11 +08:00
|
|
|
std::vector<llvm::Constant*> CXXGlobalInits;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// CFConstantStringClassRef - Cached reference to the class for constant
|
|
|
|
/// strings. This value has type int * but is actually an Obj-C class pointer.
|
2007-08-21 08:21:21 +08:00
|
|
|
llvm::Constant *CFConstantStringClassRef;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-01-23 10:40:42 +08:00
|
|
|
/// Lazily create the Objective-C runtime
|
|
|
|
void createObjCRuntime();
|
|
|
|
|
2009-07-15 07:10:40 +08:00
|
|
|
llvm::LLVMContext &VMContext;
|
2007-05-24 14:29:05 +08:00
|
|
|
public:
|
2009-11-13 01:24:48 +08:00
|
|
|
CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
|
2009-03-26 13:00:52 +08:00
|
|
|
llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags);
|
2008-08-06 02:50:11 +08:00
|
|
|
|
2008-03-01 16:45:05 +08:00
|
|
|
~CodeGenModule();
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2008-08-06 02:50:11 +08:00
|
|
|
/// Release - Finalize LLVM code generation.
|
|
|
|
void Release();
|
2008-08-12 02:12:00 +08:00
|
|
|
|
|
|
|
/// getObjCRuntime() - Return a reference to the configured
|
|
|
|
/// Objective-C runtime.
|
2009-02-14 03:12:34 +08:00
|
|
|
CGObjCRuntime &getObjCRuntime() {
|
2010-01-23 10:40:42 +08:00
|
|
|
if (!Runtime) createObjCRuntime();
|
2009-02-14 03:12:34 +08:00
|
|
|
return *Runtime;
|
2008-08-12 02:12:00 +08:00
|
|
|
}
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2008-08-12 02:12:00 +08:00
|
|
|
/// hasObjCRuntime() - Return true iff an Objective-C runtime has
|
|
|
|
/// been configured.
|
|
|
|
bool hasObjCRuntime() { return !!Runtime; }
|
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
CGDebugInfo *getDebugInfo() { return DebugInfo; }
|
2007-05-30 07:17:50 +08:00
|
|
|
ASTContext &getContext() const { return Context; }
|
2009-11-13 01:24:48 +08:00
|
|
|
const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
|
2007-11-28 13:34:05 +08:00
|
|
|
const LangOptions &getLangOptions() const { return Features; }
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::Module &getModule() const { return TheModule; }
|
2007-06-16 08:16:26 +08:00
|
|
|
CodeGenTypes &getTypes() { return Types; }
|
2009-10-07 09:06:45 +08:00
|
|
|
MangleContext &getMangleContext() { return MangleCtx; }
|
2009-10-12 06:13:54 +08:00
|
|
|
CGVtableInfo &getVtableInfo() { return VtableInfo; }
|
2007-12-02 09:40:18 +08:00
|
|
|
Diagnostic &getDiags() const { return Diags; }
|
2008-01-03 14:36:51 +08:00
|
|
|
const llvm::TargetData &getTargetData() const { return TheTargetData; }
|
2009-07-15 07:10:40 +08:00
|
|
|
llvm::LLVMContext &getLLVMContext() { return VMContext; }
|
2010-01-10 20:58:08 +08:00
|
|
|
const TargetCodeGenInfo &getTargetCodeGenInfo() const;
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2009-04-14 14:00:08 +08:00
|
|
|
/// getDeclVisibilityMode - Compute the visibility of the decl \arg D.
|
|
|
|
LangOptions::VisibilityMode getDeclVisibilityMode(const Decl *D) const;
|
|
|
|
|
|
|
|
/// setGlobalVisibility - Set the visibility for the given LLVM
|
|
|
|
/// GlobalValue.
|
|
|
|
void setGlobalVisibility(llvm::GlobalValue *GV, const Decl *D) const;
|
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the
|
2009-03-21 17:16:30 +08:00
|
|
|
/// given global variable. If Ty is non-null and if the global doesn't exist,
|
|
|
|
/// then it will be greated with the specified type instead of whatever the
|
|
|
|
/// normal requested type would be.
|
|
|
|
llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
|
|
|
|
const llvm::Type *Ty = 0);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2009-03-21 16:53:37 +08:00
|
|
|
/// GetAddrOfFunction - Return the address of the given function. If Ty is
|
|
|
|
/// non-null, then this function will use the specified type if it has to
|
|
|
|
/// create it.
|
2009-05-13 05:21:08 +08:00
|
|
|
llvm::Constant *GetAddrOfFunction(GlobalDecl GD,
|
2009-03-21 16:53:37 +08:00
|
|
|
const llvm::Type *Ty = 0);
|
2008-08-14 07:20:05 +08:00
|
|
|
|
2009-12-17 15:09:17 +08:00
|
|
|
/// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor
|
|
|
|
/// for the given type.
|
|
|
|
llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty);
|
2009-12-11 10:46:30 +08:00
|
|
|
|
2009-12-07 06:01:30 +08:00
|
|
|
llvm::Constant *GetAddrOfThunk(GlobalDecl GD,
|
|
|
|
const ThunkAdjustment &ThisAdjustment);
|
|
|
|
llvm::Constant *GetAddrOfCovariantThunk(GlobalDecl GD,
|
|
|
|
const CovariantThunkAdjustment &ThisAdjustment);
|
|
|
|
void BuildThunksForVirtual(GlobalDecl GD);
|
|
|
|
void BuildThunksForVirtualRecursive(GlobalDecl GD, GlobalDecl BaseOGD);
|
|
|
|
|
2009-11-26 10:32:05 +08:00
|
|
|
/// BuildThunk - Build a thunk for the given method.
|
2009-12-03 12:27:05 +08:00
|
|
|
llvm::Constant *BuildThunk(GlobalDecl GD, bool Extern,
|
2009-11-26 10:32:05 +08:00
|
|
|
const ThunkAdjustment &ThisAdjustment);
|
|
|
|
|
2009-09-12 07:25:56 +08:00
|
|
|
/// BuildCoVariantThunk - Build a thunk for the given method
|
2009-11-26 11:09:37 +08:00
|
|
|
llvm::Constant *
|
2009-12-03 11:47:56 +08:00
|
|
|
BuildCovariantThunk(const GlobalDecl &GD, bool Extern,
|
2009-11-26 11:09:37 +08:00
|
|
|
const CovariantThunkAdjustment &Adjustment);
|
2009-09-05 02:27:16 +08:00
|
|
|
|
2009-10-03 22:56:57 +08:00
|
|
|
/// GetCXXBaseClassOffset - Returns the offset from a derived class to its
|
|
|
|
/// base class. Returns null if the offset is 0.
|
|
|
|
llvm::Constant *GetCXXBaseClassOffset(const CXXRecordDecl *ClassDecl,
|
|
|
|
const CXXRecordDecl *BaseClassDecl);
|
|
|
|
|
2009-12-03 11:06:55 +08:00
|
|
|
/// ComputeThunkAdjustment - Returns the two parts required to compute the
|
|
|
|
/// offset for an object.
|
|
|
|
ThunkAdjustment ComputeThunkAdjustment(const CXXRecordDecl *ClassDecl,
|
|
|
|
const CXXRecordDecl *BaseClassDecl);
|
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// GetStringForStringLiteral - Return the appropriate bytes for a string
|
|
|
|
/// literal, properly padded to match the literal type. If only the address of
|
|
|
|
/// a constant is needed consider using GetAddrOfConstantStringLiteral.
|
2008-08-14 07:20:05 +08:00
|
|
|
std::string GetStringForStringLiteral(const StringLiteral *E);
|
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// GetAddrOfConstantCFString - Return a pointer to a constant CFString object
|
|
|
|
/// for the given string.
|
2009-04-01 21:55:36 +08:00
|
|
|
llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
|
2008-02-11 08:02:17 +08:00
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array
|
|
|
|
/// for the given string literal.
|
2008-08-14 07:20:05 +08:00
|
|
|
llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S);
|
2008-08-11 04:25:57 +08:00
|
|
|
|
2009-02-25 06:18:39 +08:00
|
|
|
/// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant
|
|
|
|
/// array for the given ObjCEncodeExpr node.
|
|
|
|
llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-14 07:20:05 +08:00
|
|
|
/// GetAddrOfConstantString - Returns a pointer to a character array
|
2009-02-14 03:12:34 +08:00
|
|
|
/// containing the literal. This contents are exactly that of the given
|
|
|
|
/// string, i.e. it will not be null terminated automatically; see
|
|
|
|
/// GetAddrOfConstantCString. Note that whether the result is actually a
|
|
|
|
/// pointer to an LLVM constant depends on Feature.WriteableStrings.
|
2008-08-14 07:20:05 +08:00
|
|
|
///
|
|
|
|
/// The result has pointer to array type.
|
2008-10-18 05:56:50 +08:00
|
|
|
///
|
|
|
|
/// \param GlobalName If provided, the name to use for the global
|
|
|
|
/// (if one is created).
|
|
|
|
llvm::Constant *GetAddrOfConstantString(const std::string& str,
|
|
|
|
const char *GlobalName=0);
|
2008-08-14 07:20:05 +08:00
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// GetAddrOfConstantCString - Returns a pointer to a character array
|
|
|
|
/// containing the literal and a terminating '\0' character. The result has
|
|
|
|
/// pointer to array type.
|
2008-10-18 05:56:50 +08:00
|
|
|
///
|
2009-02-14 03:12:34 +08:00
|
|
|
/// \param GlobalName If provided, the name to use for the global (if one is
|
|
|
|
/// created).
|
2008-10-18 05:56:50 +08:00
|
|
|
llvm::Constant *GetAddrOfConstantCString(const std::string &str,
|
|
|
|
const char *GlobalName=0);
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2009-04-17 07:57:24 +08:00
|
|
|
/// GetAddrOfCXXConstructor - Return the address of the constructor of the
|
|
|
|
/// given type.
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Function *GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
|
2009-04-17 07:57:24 +08:00
|
|
|
CXXCtorType Type);
|
2009-04-17 09:58:57 +08:00
|
|
|
|
|
|
|
/// GetAddrOfCXXDestructor - Return the address of the constructor of the
|
|
|
|
/// given type.
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Function *GetAddrOfCXXDestructor(const CXXDestructorDecl *D,
|
2009-04-17 09:58:57 +08:00
|
|
|
CXXDtorType Type);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-16 07:26:23 +08:00
|
|
|
/// getBuiltinLibFunction - Given a builtin id for a function like
|
|
|
|
/// "__builtin_fabsf", return a Function* for "fabsf".
|
2009-09-14 12:33:21 +08:00
|
|
|
llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
|
|
|
|
unsigned BuiltinID);
|
2008-08-14 07:20:05 +08:00
|
|
|
|
2007-06-23 02:48:09 +08:00
|
|
|
llvm::Function *getMemCpyFn();
|
2008-05-26 20:59:39 +08:00
|
|
|
llvm::Function *getMemMoveFn();
|
2008-02-20 06:01:01 +08:00
|
|
|
llvm::Function *getMemSetFn();
|
2009-02-14 03:12:34 +08:00
|
|
|
llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
|
2007-12-18 08:25:38 +08:00
|
|
|
unsigned NumTys = 0);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2008-08-16 07:26:23 +08:00
|
|
|
/// EmitTopLevelDecl - Emit code for a single top level declaration.
|
|
|
|
void EmitTopLevelDecl(Decl *D);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2009-02-14 04:29:50 +08:00
|
|
|
/// AddUsedGlobal - Add a global which should be forced to be
|
|
|
|
/// present in the object file; these are emitted to the llvm.used
|
|
|
|
/// metadata global.
|
|
|
|
void AddUsedGlobal(llvm::GlobalValue *GV);
|
|
|
|
|
2008-07-30 07:18:29 +08:00
|
|
|
void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); }
|
|
|
|
|
2009-03-23 05:03:39 +08:00
|
|
|
/// CreateRuntimeFunction - Create a new runtime function with the specified
|
|
|
|
/// type and name.
|
|
|
|
llvm::Constant *CreateRuntimeFunction(const llvm::FunctionType *Ty,
|
|
|
|
const char *Name);
|
|
|
|
/// CreateRuntimeVariable - Create a new runtime global variable with the
|
|
|
|
/// specified type and name.
|
|
|
|
llvm::Constant *CreateRuntimeVariable(const llvm::Type *Ty,
|
|
|
|
const char *Name);
|
2008-10-01 08:49:24 +08:00
|
|
|
|
2009-04-01 10:08:13 +08:00
|
|
|
void UpdateCompletedType(const TagDecl *TD) {
|
|
|
|
// Make sure that this type is translated.
|
|
|
|
Types.UpdateCompletedType(TD);
|
|
|
|
}
|
2009-02-18 02:43:32 +08:00
|
|
|
|
|
|
|
/// EmitConstantExpr - Try to emit the given expression as a
|
|
|
|
/// constant; returns 0 if the expression cannot be emitted as a
|
|
|
|
/// constant.
|
2009-04-08 12:48:15 +08:00
|
|
|
llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
|
|
|
|
CodeGenFunction *CGF = 0);
|
2009-02-18 02:43:32 +08:00
|
|
|
|
2009-04-14 05:47:26 +08:00
|
|
|
/// EmitNullConstant - Return the result of value-initializing the given
|
|
|
|
/// type, i.e. a null expression of the given type. This is usually,
|
|
|
|
/// but not always, an LLVM null constant.
|
|
|
|
llvm::Constant *EmitNullConstant(QualType T);
|
|
|
|
|
2008-04-19 12:17:09 +08:00
|
|
|
llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
|
|
|
|
const AnnotateAttr *AA, unsigned LineNo);
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2008-08-16 08:56:44 +08:00
|
|
|
/// ErrorUnsupported - Print out an error that codegen doesn't support the
|
2008-09-04 11:43:08 +08:00
|
|
|
/// specified stmt yet.
|
2009-02-14 03:12:34 +08:00
|
|
|
/// \param OmitOnError - If true, then this error should only be emitted if no
|
|
|
|
/// other errors have been reported.
|
|
|
|
void ErrorUnsupported(const Stmt *S, const char *Type,
|
2008-09-04 11:43:08 +08:00
|
|
|
bool OmitOnError=false);
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2008-08-16 08:56:44 +08:00
|
|
|
/// ErrorUnsupported - Print out an error that codegen doesn't support the
|
2008-01-12 15:05:38 +08:00
|
|
|
/// specified decl yet.
|
2009-02-14 03:12:34 +08:00
|
|
|
/// \param OmitOnError - If true, then this error should only be emitted if no
|
|
|
|
/// other errors have been reported.
|
2008-09-04 11:43:08 +08:00
|
|
|
void ErrorUnsupported(const Decl *D, const char *Type,
|
|
|
|
bool OmitOnError=false);
|
2008-05-22 08:50:06 +08:00
|
|
|
|
2009-04-17 08:48:04 +08:00
|
|
|
/// SetInternalFunctionAttributes - Set the attributes on the LLVM
|
|
|
|
/// function for the given decl and function info. This applies
|
|
|
|
/// attributes necessary for handling the ABI as well as user
|
|
|
|
/// specified attributes like section.
|
|
|
|
void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
|
|
|
|
const CGFunctionInfo &FI);
|
2008-09-05 07:41:35 +08:00
|
|
|
|
2009-04-14 15:08:30 +08:00
|
|
|
/// SetLLVMFunctionAttributes - Set the LLVM function attributes
|
|
|
|
/// (sext, zext, etc).
|
|
|
|
void SetLLVMFunctionAttributes(const Decl *D,
|
|
|
|
const CGFunctionInfo &Info,
|
|
|
|
llvm::Function *F);
|
2008-09-10 08:41:16 +08:00
|
|
|
|
2009-04-14 16:05:55 +08:00
|
|
|
/// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes
|
|
|
|
/// which only apply to a function definintion.
|
|
|
|
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
|
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// ReturnTypeUsesSret - Return true iff the given type uses 'sret' when used
|
|
|
|
/// as a return type.
|
2009-02-03 06:03:45 +08:00
|
|
|
bool ReturnTypeUsesSret(const CGFunctionInfo &FI);
|
2008-09-10 08:41:16 +08:00
|
|
|
|
2009-09-12 08:59:20 +08:00
|
|
|
/// ConstructAttributeList - Get the LLVM attributes and calling convention to
|
|
|
|
/// use for a particular function type.
|
|
|
|
///
|
|
|
|
/// \param Info - The function type information.
|
|
|
|
/// \param TargetDecl - The decl these attributes are being constructed
|
|
|
|
/// for. If supplied the attributes applied to this decl may contribute to the
|
|
|
|
/// function attributes and calling convention.
|
|
|
|
/// \param PAL [out] - On return, the attribute list to use.
|
|
|
|
/// \param CallingConv [out] - On return, the LLVM calling convention to use.
|
2009-02-03 06:03:45 +08:00
|
|
|
void ConstructAttributeList(const CGFunctionInfo &Info,
|
|
|
|
const Decl *TargetDecl,
|
2009-09-12 08:59:20 +08:00
|
|
|
AttributeListType &PAL,
|
|
|
|
unsigned &CallingConv);
|
2008-09-10 08:41:16 +08:00
|
|
|
|
2009-05-05 12:44:02 +08:00
|
|
|
const char *getMangledName(const GlobalDecl &D);
|
|
|
|
|
2009-02-19 07:53:56 +08:00
|
|
|
const char *getMangledName(const NamedDecl *ND);
|
2009-09-09 23:08:12 +08:00
|
|
|
const char *getMangledCXXCtorName(const CXXConstructorDecl *D,
|
2009-04-15 23:55:24 +08:00
|
|
|
CXXCtorType Type);
|
2009-09-09 23:08:12 +08:00
|
|
|
const char *getMangledCXXDtorName(const CXXDestructorDecl *D,
|
2009-04-17 09:58:57 +08:00
|
|
|
CXXDtorType Type);
|
2009-04-22 01:11:58 +08:00
|
|
|
|
|
|
|
void EmitTentativeDefinition(const VarDecl *D);
|
2009-08-01 02:25:34 +08:00
|
|
|
|
2009-04-14 14:04:17 +08:00
|
|
|
enum GVALinkage {
|
|
|
|
GVA_Internal,
|
2009-04-15 00:44:36 +08:00
|
|
|
GVA_C99Inline,
|
|
|
|
GVA_CXXInline,
|
2009-06-30 06:39:32 +08:00
|
|
|
GVA_StrongExternal,
|
|
|
|
GVA_TemplateInstantiation
|
2009-04-14 14:04:17 +08:00
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-01-07 04:27:16 +08:00
|
|
|
/// getVtableLinkage - Return the appropriate linkage for the vtable, VTT,
|
|
|
|
/// and type information of the given class.
|
2010-01-07 06:00:56 +08:00
|
|
|
static llvm::GlobalVariable::LinkageTypes
|
|
|
|
getVtableLinkage(const CXXRecordDecl *RD);
|
2010-01-26 21:48:07 +08:00
|
|
|
|
|
|
|
/// GetTargetTypeStoreSize - Return the store size, in character units, of
|
|
|
|
/// the given LLVM type.
|
|
|
|
CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const;
|
2010-01-07 04:27:16 +08:00
|
|
|
|
2007-12-02 15:09:19 +08:00
|
|
|
private:
|
2009-04-15 23:55:24 +08:00
|
|
|
/// UniqueMangledName - Unique a name by (if necessary) inserting it into the
|
|
|
|
/// MangledNames string map.
|
|
|
|
const char *UniqueMangledName(const char *NameStart, const char *NameEnd);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-23 05:03:39 +08:00
|
|
|
llvm::Constant *GetOrCreateLLVMFunction(const char *MangledName,
|
|
|
|
const llvm::Type *Ty,
|
2009-05-13 05:21:08 +08:00
|
|
|
GlobalDecl D);
|
2009-03-23 05:03:39 +08:00
|
|
|
llvm::Constant *GetOrCreateLLVMGlobal(const char *MangledName,
|
|
|
|
const llvm::PointerType *PTy,
|
|
|
|
const VarDecl *D);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-14 16:05:55 +08:00
|
|
|
/// SetCommonAttributes - Set attributes which are common to any
|
|
|
|
/// form of a global definition (alias, Objective-C method,
|
|
|
|
/// function, global variable).
|
2009-04-14 15:08:30 +08:00
|
|
|
///
|
2009-04-14 16:05:55 +08:00
|
|
|
/// NOTE: This should only be called for definitions.
|
|
|
|
void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
|
2008-09-05 07:41:35 +08:00
|
|
|
|
2009-04-14 16:05:55 +08:00
|
|
|
/// SetFunctionDefinitionAttributes - Set attributes for a global definition.
|
2009-09-09 23:08:12 +08:00
|
|
|
void SetFunctionDefinitionAttributes(const FunctionDecl *D,
|
2009-05-26 09:22:57 +08:00
|
|
|
llvm::GlobalValue *GV);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-14 15:08:30 +08:00
|
|
|
/// SetFunctionAttributes - Set function attributes for a function
|
|
|
|
/// declaration.
|
2008-06-01 23:54:49 +08:00
|
|
|
void SetFunctionAttributes(const FunctionDecl *FD,
|
2009-05-26 09:22:57 +08:00
|
|
|
llvm::Function *F,
|
|
|
|
bool IsIncompleteFunction);
|
2008-06-08 23:45:52 +08:00
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// EmitGlobal - Emit code for a singal global function or var decl. Forward
|
|
|
|
/// declarations are emitted lazily.
|
2009-05-13 05:21:08 +08:00
|
|
|
void EmitGlobal(GlobalDecl D);
|
2008-08-16 07:26:23 +08:00
|
|
|
|
2009-05-13 05:21:08 +08:00
|
|
|
void EmitGlobalDefinition(GlobalDecl D);
|
2009-02-19 15:15:39 +08:00
|
|
|
|
2009-05-13 05:21:08 +08:00
|
|
|
void EmitGlobalFunctionDefinition(GlobalDecl GD);
|
2008-07-30 07:18:29 +08:00
|
|
|
void EmitGlobalVarDefinition(const VarDecl *D);
|
2009-03-23 05:47:11 +08:00
|
|
|
void EmitAliasDefinition(const ValueDecl *D);
|
2008-08-26 16:29:31 +08:00
|
|
|
void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
|
2009-04-15 23:55:24 +08:00
|
|
|
|
|
|
|
// C++ related functions.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-01 08:58:25 +08:00
|
|
|
void EmitNamespace(const NamespaceDecl *D);
|
2009-04-02 13:55:18 +08:00
|
|
|
void EmitLinkageSpec(const LinkageSpecDecl *D);
|
2009-04-15 23:55:24 +08:00
|
|
|
|
|
|
|
/// EmitCXXConstructors - Emit constructors (base, complete) from a
|
|
|
|
/// C++ constructor Decl.
|
|
|
|
void EmitCXXConstructors(const CXXConstructorDecl *D);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-15 23:55:24 +08:00
|
|
|
/// EmitCXXConstructor - Emit a single constructor with the given type from
|
|
|
|
/// a C++ constructor Decl.
|
|
|
|
void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
/// EmitCXXDestructors - Emit destructors (base, complete) from a
|
2009-04-17 09:58:57 +08:00
|
|
|
/// C++ destructor Decl.
|
|
|
|
void EmitCXXDestructors(const CXXDestructorDecl *D);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-17 09:58:57 +08:00
|
|
|
/// EmitCXXDestructor - Emit a single destructor with the given type from
|
|
|
|
/// a C++ destructor Decl.
|
|
|
|
void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-09 07:24:23 +08:00
|
|
|
/// EmitCXXGlobalInitFunc - Emit a function that initializes C++ globals.
|
|
|
|
void EmitCXXGlobalInitFunc();
|
2010-01-08 08:50:11 +08:00
|
|
|
|
|
|
|
void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D);
|
|
|
|
|
2008-08-01 08:01:51 +08:00
|
|
|
// FIXME: Hardcoding priority here is gross.
|
2009-05-13 05:21:08 +08:00
|
|
|
void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535);
|
|
|
|
void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535);
|
2008-08-01 08:01:51 +08:00
|
|
|
|
2009-02-14 03:12:34 +08:00
|
|
|
/// EmitCtorList - Generates a global array of functions and priorities using
|
|
|
|
/// the given list and name. This array will have appending linkage and is
|
|
|
|
/// suitable for use as a LLVM constructor or destructor array.
|
2008-08-01 08:01:51 +08:00
|
|
|
void EmitCtorList(const CtorList &Fns, const char *GlobalName);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
|
|
|
void EmitAnnotations(void);
|
2009-02-14 04:29:50 +08:00
|
|
|
|
2009-03-10 07:53:08 +08:00
|
|
|
/// EmitDeferred - Emit any needed decls for which code generation
|
|
|
|
/// was deferred.
|
2009-02-14 04:29:50 +08:00
|
|
|
void EmitDeferred(void);
|
|
|
|
|
2009-03-10 07:53:08 +08:00
|
|
|
/// EmitLLVMUsed - Emit the llvm.used metadata used to force
|
|
|
|
/// references to global which may otherwise be optimized out.
|
2009-02-14 04:29:50 +08:00
|
|
|
void EmitLLVMUsed(void);
|
2008-10-01 08:49:24 +08:00
|
|
|
|
2009-03-10 07:53:08 +08:00
|
|
|
/// MayDeferGeneration - Determine if the given decl can be emitted
|
|
|
|
/// lazily; this is only relevant for definitions. The given decl
|
|
|
|
/// must be either a function or var decl.
|
2009-02-14 05:18:01 +08:00
|
|
|
bool MayDeferGeneration(const ValueDecl *D);
|
2007-05-24 14:29:05 +08:00
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|