2008-07-30 03:18:29 +04:00
|
|
|
//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
|
2007-07-11 21:01:13 +04:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 22:59:25 +03:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-07-11 21:01:13 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-02-13 22:12:34 +03:00
|
|
|
// This is the internal per-translation-unit state used for llvm translation.
|
2007-07-11 21:01:13 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-29 20:10:38 +03:00
|
|
|
#ifndef CLANG_CODEGEN_CODEGENMODULE_H
|
|
|
|
#define CLANG_CODEGEN_CODEGENMODULE_H
|
2007-07-11 21:01:13 +04:00
|
|
|
|
2009-04-14 10:00:08 +04:00
|
|
|
#include "clang/Basic/LangOptions.h"
|
2008-05-22 04:50:06 +04:00
|
|
|
#include "clang/AST/Attr.h"
|
2009-05-05 08:44:02 +04:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-09-11 04:07:24 +04:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2009-03-26 08:00:52 +03:00
|
|
|
#include "CGBlocks.h"
|
|
|
|
#include "CGCall.h"
|
2009-04-15 19:55:24 +04:00
|
|
|
#include "CGCXX.h"
|
2009-10-12 02:13:54 +04:00
|
|
|
#include "CGVtable.h"
|
2009-03-26 08:00:52 +03:00
|
|
|
#include "CodeGenTypes.h"
|
2009-11-13 07:25:07 +03:00
|
|
|
#include "GlobalDecl.h"
|
2009-10-07 05:06:45 +04:00
|
|
|
#include "Mangle.h"
|
2009-07-13 08:10:07 +04:00
|
|
|
#include "llvm/Module.h"
|
2007-07-11 21:01:13 +04:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-08-21 04:21:21 +04:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2009-02-19 02:53:56 +03:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2009-04-01 02:37:52 +04:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2009-01-04 05:08:04 +03:00
|
|
|
#include <list>
|
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
namespace llvm {
|
|
|
|
class Module;
|
|
|
|
class Constant;
|
|
|
|
class Function;
|
2008-04-19 08:17:09 +04:00
|
|
|
class GlobalValue;
|
2007-10-31 23:01:01 +03:00
|
|
|
class TargetData;
|
2008-06-01 19:54:49 +04:00
|
|
|
class FunctionType;
|
2009-08-11 21:46:57 +04:00
|
|
|
class LLVMContext;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
2010-01-10 15:58:08 +03:00
|
|
|
class TargetCodeGenInfo;
|
2007-07-11 21:01:13 +04:00
|
|
|
class ASTContext;
|
|
|
|
class FunctionDecl;
|
2008-08-25 10:18:57 +04:00
|
|
|
class IdentifierInfo;
|
2008-03-31 03:03:07 +04:00
|
|
|
class ObjCMethodDecl;
|
2008-06-01 18:13:53 +04:00
|
|
|
class ObjCImplementationDecl;
|
|
|
|
class ObjCCategoryImplDecl;
|
|
|
|
class ObjCProtocolDecl;
|
2009-02-25 01:18:39 +03:00
|
|
|
class ObjCEncodeExpr;
|
2009-02-12 20:55:02 +03:00
|
|
|
class BlockExpr;
|
2010-01-26 16:48:07 +03:00
|
|
|
class CharUnits;
|
2007-07-11 21:01:13 +04:00
|
|
|
class Decl;
|
2007-12-02 03:11:25 +03:00
|
|
|
class Expr;
|
2007-12-02 10:19:18 +03:00
|
|
|
class Stmt;
|
2008-08-11 00:25:57 +04:00
|
|
|
class StringLiteral;
|
2008-04-21 00:38:08 +04:00
|
|
|
class NamedDecl;
|
2008-07-30 03:18:29 +04:00
|
|
|
class ValueDecl;
|
2007-12-18 11:16:44 +03:00
|
|
|
class VarDecl;
|
2009-03-07 15:16:37 +03:00
|
|
|
class LangOptions;
|
2009-11-12 20:24:48 +03:00
|
|
|
class CodeGenOptions;
|
2007-12-02 04:40:18 +03:00
|
|
|
class Diagnostic;
|
2008-04-19 08:17:09 +04:00
|
|
|
class AnnotateAttr;
|
2009-04-17 05:58:57 +04:00
|
|
|
class CXXDestructorDecl;
|
2009-02-13 22:12:34 +03:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
namespace CodeGen {
|
|
|
|
|
2008-02-27 00:41:45 +03:00
|
|
|
class CodeGenFunction;
|
2008-05-08 12:54:20 +04:00
|
|
|
class CGDebugInfo;
|
2008-08-13 04:59:25 +04:00
|
|
|
class CGObjCRuntime;
|
2009-02-13 22:12:34 +03:00
|
|
|
|
2009-09-11 03:38:47 +04:00
|
|
|
|
2009-02-13 22:12:34 +03:00
|
|
|
/// CodeGenModule - This class organizes the cross-function state that is used
|
|
|
|
/// while generating LLVM code.
|
2009-03-04 21:17:45 +03:00
|
|
|
class CodeGenModule : public BlockModule {
|
2009-02-24 07:21:31 +03:00
|
|
|
CodeGenModule(const CodeGenModule&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const CodeGenModule&); // DO NOT IMPLEMENT
|
|
|
|
|
2009-09-13 02:45:21 +04:00
|
|
|
typedef std::vector<std::pair<llvm::Constant*, int> > CtorList;
|
2008-08-01 04:01:51 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
ASTContext &Context;
|
2007-11-28 08:34:05 +03:00
|
|
|
const LangOptions &Features;
|
2009-11-12 20:24:48 +03:00
|
|
|
const CodeGenOptions &CodeGenOpts;
|
2007-07-11 21:01:13 +04:00
|
|
|
llvm::Module &TheModule;
|
2007-10-31 23:01:01 +03:00
|
|
|
const llvm::TargetData &TheTargetData;
|
2010-01-10 15:58:08 +03:00
|
|
|
mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
|
2007-12-02 04:40:18 +03:00
|
|
|
Diagnostic &Diags;
|
2007-07-11 21:01:13 +04:00
|
|
|
CodeGenTypes Types;
|
2009-10-07 05:06:45 +04:00
|
|
|
MangleContext MangleCtx;
|
|
|
|
|
2009-10-12 02:13:54 +04:00
|
|
|
/// VtableInfo - Holds information about C++ vtables.
|
|
|
|
CGVtableInfo VtableInfo;
|
|
|
|
|
2008-08-05 22:50:11 +04:00
|
|
|
CGObjCRuntime* Runtime;
|
|
|
|
CGDebugInfo* DebugInfo;
|
2009-10-07 05:06:45 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
llvm::Function *MemCpyFn;
|
2008-05-26 16:59:39 +04:00
|
|
|
llvm::Function *MemMoveFn;
|
2008-02-20 01:01:01 +03:00
|
|
|
llvm::Function *MemSetFn;
|
2008-07-30 20:32:24 +04:00
|
|
|
|
2009-02-19 02:53:56 +03: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 10:48:31 +03:00
|
|
|
/// globals are keyed on their source mangled name, not the global name
|
2009-03-21 12:44:56 +03:00
|
|
|
/// (which may change with attributes such as asm-labels). The key
|
2009-02-19 02:53:56 +03:00
|
|
|
/// to this map should be generated using getMangledName().
|
2009-03-21 12:44:56 +03: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 02:53:56 +03: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 03:18:29 +04:00
|
|
|
|
2009-03-21 12:44:56 +03: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 08:44:02 +04:00
|
|
|
llvm::DenseMap<const char*, GlobalDecl> DeferredDecls;
|
2009-03-21 12:44:56 +03: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 08:44:02 +04:00
|
|
|
std::vector<GlobalDecl> DeferredDeclsToEmit;
|
2009-04-16 02:08:45 +04:00
|
|
|
|
2009-02-13 23:29:50 +03: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 02:37:52 +04:00
|
|
|
std::vector<llvm::WeakVH> LLVMUsed;
|
2009-02-13 22:12:34 +03:00
|
|
|
|
|
|
|
/// GlobalCtors - Store the list of global constructors and their respective
|
|
|
|
/// priorities to be emitted when the translation unit is complete.
|
2008-08-01 04:01:51 +04:00
|
|
|
CtorList GlobalCtors;
|
|
|
|
|
2009-02-13 22:12:34 +03:00
|
|
|
/// GlobalDtors - Store the list of global destructors and their respective
|
|
|
|
/// priorities to be emitted when the translation unit is complete.
|
2008-08-01 04:01:51 +04:00
|
|
|
CtorList GlobalDtors;
|
|
|
|
|
2008-04-19 03:43:57 +04:00
|
|
|
std::vector<llvm::Constant*> Annotations;
|
2009-02-13 22:12:34 +03:00
|
|
|
|
2007-08-21 04:21:21 +04:00
|
|
|
llvm::StringMap<llvm::Constant*> CFConstantStringMap;
|
2007-11-28 08:34:05 +03:00
|
|
|
llvm::StringMap<llvm::Constant*> ConstantStringMap;
|
2008-08-23 22:37:06 +04:00
|
|
|
|
2009-08-09 03:24:23 +04:00
|
|
|
/// CXXGlobalInits - Variables with global initializers that need to run
|
|
|
|
/// before main.
|
2010-01-08 03:50:11 +03:00
|
|
|
std::vector<llvm::Constant*> CXXGlobalInits;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:12:34 +03: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 04:21:21 +04:00
|
|
|
llvm::Constant *CFConstantStringClassRef;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-01-23 05:40:42 +03:00
|
|
|
/// Lazily create the Objective-C runtime
|
|
|
|
void createObjCRuntime();
|
|
|
|
|
2009-07-15 03:10:40 +04:00
|
|
|
llvm::LLVMContext &VMContext;
|
2007-07-11 21:01:13 +04:00
|
|
|
public:
|
2009-11-12 20:24:48 +03:00
|
|
|
CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
|
2010-03-04 07:29:44 +03:00
|
|
|
llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags);
|
2008-08-05 22:50:11 +04:00
|
|
|
|
2008-03-01 11:45:05 +03:00
|
|
|
~CodeGenModule();
|
2009-02-13 22:12:34 +03:00
|
|
|
|
2008-08-05 22:50:11 +04:00
|
|
|
/// Release - Finalize LLVM code generation.
|
|
|
|
void Release();
|
2008-08-11 22:12:00 +04:00
|
|
|
|
|
|
|
/// getObjCRuntime() - Return a reference to the configured
|
|
|
|
/// Objective-C runtime.
|
2009-02-13 22:12:34 +03:00
|
|
|
CGObjCRuntime &getObjCRuntime() {
|
2010-01-23 05:40:42 +03:00
|
|
|
if (!Runtime) createObjCRuntime();
|
2009-02-13 22:12:34 +03:00
|
|
|
return *Runtime;
|
2008-08-11 22:12:00 +04:00
|
|
|
}
|
2009-02-13 22:12:34 +03:00
|
|
|
|
2008-08-11 22:12:00 +04:00
|
|
|
/// hasObjCRuntime() - Return true iff an Objective-C runtime has
|
|
|
|
/// been configured.
|
|
|
|
bool hasObjCRuntime() { return !!Runtime; }
|
|
|
|
|
2008-05-08 12:54:20 +04:00
|
|
|
CGDebugInfo *getDebugInfo() { return DebugInfo; }
|
2007-07-11 21:01:13 +04:00
|
|
|
ASTContext &getContext() const { return Context; }
|
2009-11-12 20:24:48 +03:00
|
|
|
const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
|
2007-11-28 08:34:05 +03:00
|
|
|
const LangOptions &getLangOptions() const { return Features; }
|
2007-07-11 21:01:13 +04:00
|
|
|
llvm::Module &getModule() const { return TheModule; }
|
|
|
|
CodeGenTypes &getTypes() { return Types; }
|
2009-10-07 05:06:45 +04:00
|
|
|
MangleContext &getMangleContext() { return MangleCtx; }
|
2009-10-12 02:13:54 +04:00
|
|
|
CGVtableInfo &getVtableInfo() { return VtableInfo; }
|
2007-12-02 04:40:18 +03:00
|
|
|
Diagnostic &getDiags() const { return Diags; }
|
2008-01-03 09:36:51 +03:00
|
|
|
const llvm::TargetData &getTargetData() const { return TheTargetData; }
|
2009-07-15 03:10:40 +04:00
|
|
|
llvm::LLVMContext &getLLVMContext() { return VMContext; }
|
2010-01-10 15:58:08 +03:00
|
|
|
const TargetCodeGenInfo &getTargetCodeGenInfo() const;
|
2008-07-30 03:18:29 +04:00
|
|
|
|
2009-04-14 10:00:08 +04: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;
|
|
|
|
|
2010-02-19 04:32:20 +03:00
|
|
|
llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
|
|
|
|
if (isa<CXXConstructorDecl>(GD.getDecl()))
|
|
|
|
return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()),
|
|
|
|
GD.getCtorType());
|
|
|
|
else if (isa<CXXDestructorDecl>(GD.getDecl()))
|
|
|
|
return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()),
|
|
|
|
GD.getDtorType());
|
|
|
|
else if (isa<FunctionDecl>(GD.getDecl()))
|
|
|
|
return GetAddrOfFunction(GD);
|
|
|
|
else
|
|
|
|
return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
|
|
|
|
}
|
|
|
|
|
2009-02-13 22:12:34 +03:00
|
|
|
/// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the
|
2009-03-21 12:16:30 +03: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 03:18:29 +04:00
|
|
|
|
2009-03-21 11:53:37 +03: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 01:21:08 +04:00
|
|
|
llvm::Constant *GetAddrOfFunction(GlobalDecl GD,
|
2009-03-21 11:53:37 +03:00
|
|
|
const llvm::Type *Ty = 0);
|
2008-08-14 03:20:05 +04:00
|
|
|
|
2009-12-17 10:09:17 +03:00
|
|
|
/// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor
|
|
|
|
/// for the given type.
|
|
|
|
llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty);
|
2009-12-11 05:46:30 +03:00
|
|
|
|
2009-12-07 01:01:30 +03: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 05:32:05 +03:00
|
|
|
/// BuildThunk - Build a thunk for the given method.
|
2009-12-03 07:27:05 +03:00
|
|
|
llvm::Constant *BuildThunk(GlobalDecl GD, bool Extern,
|
2009-11-26 05:32:05 +03:00
|
|
|
const ThunkAdjustment &ThisAdjustment);
|
|
|
|
|
2009-09-12 03:25:56 +04:00
|
|
|
/// BuildCoVariantThunk - Build a thunk for the given method
|
2009-11-26 06:09:37 +03:00
|
|
|
llvm::Constant *
|
2009-12-03 06:47:56 +03:00
|
|
|
BuildCovariantThunk(const GlobalDecl &GD, bool Extern,
|
2009-11-26 06:09:37 +03:00
|
|
|
const CovariantThunkAdjustment &Adjustment);
|
2009-09-04 22:27:16 +04:00
|
|
|
|
2010-01-31 04:36:53 +03:00
|
|
|
/// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to
|
|
|
|
/// its base class. Returns null if the offset is 0.
|
|
|
|
llvm::Constant *
|
|
|
|
GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
|
|
|
|
const CXXRecordDecl *BaseClassDecl);
|
2009-10-03 18:56:57 +04:00
|
|
|
|
2009-12-03 06:06:55 +03:00
|
|
|
/// ComputeThunkAdjustment - Returns the two parts required to compute the
|
|
|
|
/// offset for an object.
|
|
|
|
ThunkAdjustment ComputeThunkAdjustment(const CXXRecordDecl *ClassDecl,
|
|
|
|
const CXXRecordDecl *BaseClassDecl);
|
|
|
|
|
2009-02-13 22:12:34 +03: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 03:20:05 +04:00
|
|
|
std::string GetStringForStringLiteral(const StringLiteral *E);
|
|
|
|
|
2009-02-13 22:12:34 +03:00
|
|
|
/// GetAddrOfConstantCFString - Return a pointer to a constant CFString object
|
|
|
|
/// for the given string.
|
2009-04-01 17:55:36 +04:00
|
|
|
llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
|
2008-02-11 03:02:17 +03:00
|
|
|
|
2009-02-13 22:12:34 +03:00
|
|
|
/// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array
|
|
|
|
/// for the given string literal.
|
2008-08-14 03:20:05 +04:00
|
|
|
llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S);
|
2008-08-11 00:25:57 +04:00
|
|
|
|
2009-02-25 01:18:39 +03:00
|
|
|
/// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant
|
|
|
|
/// array for the given ObjCEncodeExpr node.
|
|
|
|
llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-08-14 03:20:05 +04:00
|
|
|
/// GetAddrOfConstantString - Returns a pointer to a character array
|
2009-02-13 22:12:34 +03: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 03:20:05 +04:00
|
|
|
///
|
|
|
|
/// The result has pointer to array type.
|
2008-10-18 01:56:50 +04: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 03:20:05 +04:00
|
|
|
|
2009-02-13 22:12:34 +03: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 01:56:50 +04:00
|
|
|
///
|
2009-02-13 22:12:34 +03:00
|
|
|
/// \param GlobalName If provided, the name to use for the global (if one is
|
|
|
|
/// created).
|
2008-10-18 01:56:50 +04:00
|
|
|
llvm::Constant *GetAddrOfConstantCString(const std::string &str,
|
|
|
|
const char *GlobalName=0);
|
2009-02-13 22:12:34 +03:00
|
|
|
|
2009-04-17 03:57:24 +04:00
|
|
|
/// GetAddrOfCXXConstructor - Return the address of the constructor of the
|
|
|
|
/// given type.
|
2010-02-19 04:32:20 +03:00
|
|
|
llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
|
|
|
|
CXXCtorType Type);
|
2009-04-17 05:58:57 +04:00
|
|
|
|
|
|
|
/// GetAddrOfCXXDestructor - Return the address of the constructor of the
|
|
|
|
/// given type.
|
2010-02-19 04:32:20 +03:00
|
|
|
llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *D,
|
|
|
|
CXXDtorType Type);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-08-16 03:26:23 +04:00
|
|
|
/// getBuiltinLibFunction - Given a builtin id for a function like
|
|
|
|
/// "__builtin_fabsf", return a Function* for "fabsf".
|
2009-09-14 08:33:21 +04:00
|
|
|
llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
|
|
|
|
unsigned BuiltinID);
|
2008-08-14 03:20:05 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
llvm::Function *getMemCpyFn();
|
2008-05-26 16:59:39 +04:00
|
|
|
llvm::Function *getMemMoveFn();
|
2008-02-20 01:01:01 +03:00
|
|
|
llvm::Function *getMemSetFn();
|
2009-02-13 22:12:34 +03:00
|
|
|
llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
|
2007-12-18 03:25:38 +03:00
|
|
|
unsigned NumTys = 0);
|
2008-07-30 03:18:29 +04:00
|
|
|
|
2008-08-16 03:26:23 +04:00
|
|
|
/// EmitTopLevelDecl - Emit code for a single top level declaration.
|
|
|
|
void EmitTopLevelDecl(Decl *D);
|
2008-07-30 03:18:29 +04:00
|
|
|
|
2009-02-13 23:29:50 +03: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 03:18:29 +04:00
|
|
|
void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); }
|
|
|
|
|
2009-03-23 00:03:39 +03: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 04:49:24 +04:00
|
|
|
|
2009-04-01 06:08:13 +04:00
|
|
|
void UpdateCompletedType(const TagDecl *TD) {
|
|
|
|
// Make sure that this type is translated.
|
|
|
|
Types.UpdateCompletedType(TD);
|
|
|
|
}
|
2009-02-17 21:43:32 +03: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 08:48:15 +04:00
|
|
|
llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
|
|
|
|
CodeGenFunction *CGF = 0);
|
2009-02-17 21:43:32 +03:00
|
|
|
|
2009-04-14 01:47:26 +04: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 08:17:09 +04:00
|
|
|
llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
|
|
|
|
const AnnotateAttr *AA, unsigned LineNo);
|
2009-02-13 22:12:34 +03:00
|
|
|
|
2010-02-02 06:37:46 +03:00
|
|
|
llvm::Constant *EmitPointerToDataMember(const FieldDecl *FD);
|
|
|
|
|
2008-08-16 04:56:44 +04:00
|
|
|
/// ErrorUnsupported - Print out an error that codegen doesn't support the
|
2008-09-04 07:43:08 +04:00
|
|
|
/// specified stmt yet.
|
2009-02-13 22:12:34 +03: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 07:43:08 +04:00
|
|
|
bool OmitOnError=false);
|
2009-02-13 22:12:34 +03:00
|
|
|
|
2008-08-16 04:56:44 +04:00
|
|
|
/// ErrorUnsupported - Print out an error that codegen doesn't support the
|
2008-01-12 10:05:38 +03:00
|
|
|
/// specified decl yet.
|
2009-02-13 22:12:34 +03:00
|
|
|
/// \param OmitOnError - If true, then this error should only be emitted if no
|
|
|
|
/// other errors have been reported.
|
2008-09-04 07:43:08 +04:00
|
|
|
void ErrorUnsupported(const Decl *D, const char *Type,
|
|
|
|
bool OmitOnError=false);
|
2008-05-22 04:50:06 +04:00
|
|
|
|
2009-04-17 04:48:04 +04: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 03:41:35 +04:00
|
|
|
|
2009-04-14 11:08:30 +04:00
|
|
|
/// SetLLVMFunctionAttributes - Set the LLVM function attributes
|
|
|
|
/// (sext, zext, etc).
|
|
|
|
void SetLLVMFunctionAttributes(const Decl *D,
|
|
|
|
const CGFunctionInfo &Info,
|
|
|
|
llvm::Function *F);
|
2008-09-10 04:41:16 +04:00
|
|
|
|
2009-04-14 12:05:55 +04:00
|
|
|
/// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes
|
|
|
|
/// which only apply to a function definintion.
|
|
|
|
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
|
|
|
|
|
2009-02-13 22:12:34 +03:00
|
|
|
/// ReturnTypeUsesSret - Return true iff the given type uses 'sret' when used
|
|
|
|
/// as a return type.
|
2009-02-03 01:03:45 +03:00
|
|
|
bool ReturnTypeUsesSret(const CGFunctionInfo &FI);
|
2008-09-10 04:41:16 +04:00
|
|
|
|
2009-09-12 04:59:20 +04: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 01:03:45 +03:00
|
|
|
void ConstructAttributeList(const CGFunctionInfo &Info,
|
|
|
|
const Decl *TargetDecl,
|
2009-09-12 04:59:20 +04:00
|
|
|
AttributeListType &PAL,
|
|
|
|
unsigned &CallingConv);
|
2008-09-10 04:41:16 +04:00
|
|
|
|
2009-05-05 08:44:02 +04:00
|
|
|
const char *getMangledName(const GlobalDecl &D);
|
|
|
|
|
2009-02-19 02:53:56 +03:00
|
|
|
const char *getMangledName(const NamedDecl *ND);
|
2009-09-09 19:08:12 +04:00
|
|
|
const char *getMangledCXXCtorName(const CXXConstructorDecl *D,
|
2009-04-15 19:55:24 +04:00
|
|
|
CXXCtorType Type);
|
2009-09-09 19:08:12 +04:00
|
|
|
const char *getMangledCXXDtorName(const CXXDestructorDecl *D,
|
2009-04-17 05:58:57 +04:00
|
|
|
CXXDtorType Type);
|
2009-04-21 21:11:58 +04:00
|
|
|
|
|
|
|
void EmitTentativeDefinition(const VarDecl *D);
|
2009-07-31 22:25:34 +04:00
|
|
|
|
2009-04-14 10:04:17 +04:00
|
|
|
enum GVALinkage {
|
|
|
|
GVA_Internal,
|
2009-04-14 20:44:36 +04:00
|
|
|
GVA_C99Inline,
|
|
|
|
GVA_CXXInline,
|
2009-06-30 02:39:32 +04:00
|
|
|
GVA_StrongExternal,
|
|
|
|
GVA_TemplateInstantiation
|
2009-04-14 10:04:17 +04:00
|
|
|
};
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-02-19 04:32:20 +03:00
|
|
|
llvm::GlobalVariable::LinkageTypes
|
|
|
|
getFunctionLinkage(const FunctionDecl *FD);
|
|
|
|
|
2010-01-06 23:27:16 +03:00
|
|
|
/// getVtableLinkage - Return the appropriate linkage for the vtable, VTT,
|
|
|
|
/// and type information of the given class.
|
2010-01-07 01:00:56 +03:00
|
|
|
static llvm::GlobalVariable::LinkageTypes
|
|
|
|
getVtableLinkage(const CXXRecordDecl *RD);
|
2010-01-26 16:48:07 +03:00
|
|
|
|
|
|
|
/// GetTargetTypeStoreSize - Return the store size, in character units, of
|
|
|
|
/// the given LLVM type.
|
|
|
|
CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const;
|
2010-01-06 23:27:16 +03:00
|
|
|
|
2007-12-02 10:09:19 +03:00
|
|
|
private:
|
2009-04-15 19:55:24 +04: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 19:08:12 +04:00
|
|
|
|
2009-03-23 00:03:39 +03:00
|
|
|
llvm::Constant *GetOrCreateLLVMFunction(const char *MangledName,
|
|
|
|
const llvm::Type *Ty,
|
2009-05-13 01:21:08 +04:00
|
|
|
GlobalDecl D);
|
2009-03-23 00:03:39 +03:00
|
|
|
llvm::Constant *GetOrCreateLLVMGlobal(const char *MangledName,
|
|
|
|
const llvm::PointerType *PTy,
|
|
|
|
const VarDecl *D);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-04-14 12:05:55 +04:00
|
|
|
/// SetCommonAttributes - Set attributes which are common to any
|
|
|
|
/// form of a global definition (alias, Objective-C method,
|
|
|
|
/// function, global variable).
|
2009-04-14 11:08:30 +04:00
|
|
|
///
|
2009-04-14 12:05:55 +04:00
|
|
|
/// NOTE: This should only be called for definitions.
|
|
|
|
void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
|
2008-09-05 03:41:35 +04:00
|
|
|
|
2009-04-14 12:05:55 +04:00
|
|
|
/// SetFunctionDefinitionAttributes - Set attributes for a global definition.
|
2009-09-09 19:08:12 +04:00
|
|
|
void SetFunctionDefinitionAttributes(const FunctionDecl *D,
|
2009-05-26 05:22:57 +04:00
|
|
|
llvm::GlobalValue *GV);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-04-14 11:08:30 +04:00
|
|
|
/// SetFunctionAttributes - Set function attributes for a function
|
|
|
|
/// declaration.
|
2010-02-06 05:44:09 +03:00
|
|
|
void SetFunctionAttributes(GlobalDecl GD,
|
2009-05-26 05:22:57 +04:00
|
|
|
llvm::Function *F,
|
|
|
|
bool IsIncompleteFunction);
|
2008-06-08 19:45:52 +04:00
|
|
|
|
2009-02-13 22:12:34 +03:00
|
|
|
/// EmitGlobal - Emit code for a singal global function or var decl. Forward
|
|
|
|
/// declarations are emitted lazily.
|
2009-05-13 01:21:08 +04:00
|
|
|
void EmitGlobal(GlobalDecl D);
|
2008-08-16 03:26:23 +04:00
|
|
|
|
2009-05-13 01:21:08 +04:00
|
|
|
void EmitGlobalDefinition(GlobalDecl D);
|
2009-02-19 10:15:39 +03:00
|
|
|
|
2009-05-13 01:21:08 +04:00
|
|
|
void EmitGlobalFunctionDefinition(GlobalDecl GD);
|
2008-07-30 03:18:29 +04:00
|
|
|
void EmitGlobalVarDefinition(const VarDecl *D);
|
2009-03-23 00:47:11 +03:00
|
|
|
void EmitAliasDefinition(const ValueDecl *D);
|
2008-08-26 12:29:31 +04:00
|
|
|
void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
|
2009-04-15 19:55:24 +04:00
|
|
|
|
|
|
|
// C++ related functions.
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-02-19 04:32:20 +03:00
|
|
|
bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target);
|
2010-02-23 03:48:20 +03:00
|
|
|
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
|
2010-02-19 04:32:20 +03:00
|
|
|
|
2009-04-01 04:58:25 +04:00
|
|
|
void EmitNamespace(const NamespaceDecl *D);
|
2009-04-02 09:55:18 +04:00
|
|
|
void EmitLinkageSpec(const LinkageSpecDecl *D);
|
2009-04-15 19:55:24 +04:00
|
|
|
|
|
|
|
/// EmitCXXConstructors - Emit constructors (base, complete) from a
|
|
|
|
/// C++ constructor Decl.
|
|
|
|
void EmitCXXConstructors(const CXXConstructorDecl *D);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-04-15 19:55:24 +04: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 19:08:12 +04:00
|
|
|
|
|
|
|
/// EmitCXXDestructors - Emit destructors (base, complete) from a
|
2009-04-17 05:58:57 +04:00
|
|
|
/// C++ destructor Decl.
|
|
|
|
void EmitCXXDestructors(const CXXDestructorDecl *D);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-04-17 05:58:57 +04: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 19:08:12 +04:00
|
|
|
|
2009-08-09 03:24:23 +04:00
|
|
|
/// EmitCXXGlobalInitFunc - Emit a function that initializes C++ globals.
|
|
|
|
void EmitCXXGlobalInitFunc();
|
2010-01-08 03:50:11 +03:00
|
|
|
|
|
|
|
void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D);
|
|
|
|
|
2008-08-01 04:01:51 +04:00
|
|
|
// FIXME: Hardcoding priority here is gross.
|
2009-05-13 01:21:08 +04:00
|
|
|
void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535);
|
|
|
|
void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535);
|
2008-08-01 04:01:51 +04:00
|
|
|
|
2009-02-13 22:12:34 +03: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 04:01:51 +04:00
|
|
|
void EmitCtorList(const CtorList &Fns, const char *GlobalName);
|
2008-07-30 03:18:29 +04:00
|
|
|
|
|
|
|
void EmitAnnotations(void);
|
2009-02-13 23:29:50 +03:00
|
|
|
|
2009-03-10 02:53:08 +03:00
|
|
|
/// EmitDeferred - Emit any needed decls for which code generation
|
|
|
|
/// was deferred.
|
2009-02-13 23:29:50 +03:00
|
|
|
void EmitDeferred(void);
|
|
|
|
|
2009-03-10 02:53:08 +03:00
|
|
|
/// EmitLLVMUsed - Emit the llvm.used metadata used to force
|
|
|
|
/// references to global which may otherwise be optimized out.
|
2009-02-13 23:29:50 +03:00
|
|
|
void EmitLLVMUsed(void);
|
2008-10-01 04:49:24 +04:00
|
|
|
|
2009-03-10 02:53:08 +03: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 00:18:01 +03:00
|
|
|
bool MayDeferGeneration(const ValueDecl *D);
|
2007-07-11 21:01:13 +04:00
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|