mirror of
https://github.com/intel/llvm.git
synced 2026-01-25 10:55:58 +08:00
Move GlobalDecl to its own file. Also add DenseMapInfo traits.
llvm-svn: 87081
This commit is contained in:
@@ -365,6 +365,7 @@
|
||||
1A2A54B30FD1DD1C00F4CE45 /* StmtXML.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StmtXML.cpp; path = lib/Frontend/StmtXML.cpp; sourceTree = "<group>"; };
|
||||
1A2A54B40FD1DD1C00F4CE45 /* Warnings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Warnings.cpp; path = lib/Frontend/Warnings.cpp; sourceTree = "<group>"; };
|
||||
1A30A9E80B93A4C800201A91 /* ExprCXX.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = ExprCXX.h; path = clang/AST/ExprCXX.h; sourceTree = "<group>"; tabWidth = 2; };
|
||||
1A31B27210ACE6DA009E0C8B /* GlobalDecl.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = GlobalDecl.h; path = lib/CodeGen/GlobalDecl.h; sourceTree = "<group>"; tabWidth = 2; };
|
||||
1A32C17E0E1C87AD00A6B483 /* ExprConstant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = ExprConstant.cpp; path = lib/AST/ExprConstant.cpp; sourceTree = "<group>"; tabWidth = 2; };
|
||||
1A376A2C0D4AED9B002A1C52 /* CGExprConstant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGExprConstant.cpp; path = lib/CodeGen/CGExprConstant.cpp; sourceTree = "<group>"; tabWidth = 2; };
|
||||
1A471AB40F437BC500753CE8 /* CGBlocks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGBlocks.cpp; path = lib/CodeGen/CGBlocks.cpp; sourceTree = "<group>"; tabWidth = 2; };
|
||||
@@ -1295,6 +1296,7 @@
|
||||
DE928B7E0C0A615600231DA4 /* CodeGenModule.cpp */,
|
||||
DEEBC3BB0C2363BC00A9FE82 /* CodeGenTypes.cpp */,
|
||||
DEEBC3B90C2363B800A9FE82 /* CodeGenTypes.h */,
|
||||
1A31B27210ACE6DA009E0C8B /* GlobalDecl.h */,
|
||||
1A2193CC0F45EEB700C0713D /* Mangle.cpp */,
|
||||
1A2193CD0F45EEB700C0713D /* Mangle.h */,
|
||||
DE928B120C05659200231DA4 /* ModuleBuilder.cpp */,
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "CGCXX.h"
|
||||
#include "CGVtable.h"
|
||||
#include "CodeGenTypes.h"
|
||||
#include "GlobalDecl.h"
|
||||
#include "Mangle.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
@@ -70,46 +71,7 @@ namespace CodeGen {
|
||||
class CGDebugInfo;
|
||||
class CGObjCRuntime;
|
||||
|
||||
/// GlobalDecl - represents a global declaration. This can either be a
|
||||
/// CXXConstructorDecl and the constructor type (Base, Complete).
|
||||
/// a CXXDestructorDecl and the destructor type (Base, Complete) or
|
||||
/// a VarDecl, a FunctionDecl or a BlockDecl.
|
||||
class GlobalDecl {
|
||||
llvm::PointerIntPair<const Decl*, 2> Value;
|
||||
|
||||
void Init(const Decl *D) {
|
||||
assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
|
||||
assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
|
||||
|
||||
Value.setPointer(D);
|
||||
}
|
||||
|
||||
public:
|
||||
GlobalDecl() {}
|
||||
|
||||
GlobalDecl(const VarDecl *D) { Init(D);}
|
||||
GlobalDecl(const FunctionDecl *D) { Init(D); }
|
||||
GlobalDecl(const BlockDecl *D) { Init(D); }
|
||||
GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
|
||||
|
||||
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
|
||||
: Value(D, Type) {}
|
||||
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
|
||||
: Value(D, Type) {}
|
||||
|
||||
const Decl *getDecl() const { return Value.getPointer(); }
|
||||
|
||||
CXXCtorType getCtorType() const {
|
||||
assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
|
||||
return static_cast<CXXCtorType>(Value.getInt());
|
||||
}
|
||||
|
||||
CXXDtorType getDtorType() const {
|
||||
assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
|
||||
return static_cast<CXXDtorType>(Value.getInt());
|
||||
}
|
||||
};
|
||||
|
||||
/// CodeGenModule - This class organizes the cross-function state that is used
|
||||
/// while generating LLVM code.
|
||||
class CodeGenModule : public BlockModule {
|
||||
|
||||
110
clang/lib/CodeGen/GlobalDecl.h
Normal file
110
clang/lib/CodeGen/GlobalDecl.h
Normal file
@@ -0,0 +1,110 @@
|
||||
//===--- GlobalDecl.h - Global declaration holder ---------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// A GlobalDecl can hold either a regular variable/function or a C++ ctor/dtor
|
||||
// together with its type.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef CLANG_CODEGEN_GLOBALDECL_H
|
||||
#define CLANG_CODEGEN_GLOBALDECL_H
|
||||
|
||||
namespace clang {
|
||||
|
||||
namespace CodeGen {
|
||||
|
||||
/// GlobalDecl - represents a global declaration. This can either be a
|
||||
/// CXXConstructorDecl and the constructor type (Base, Complete).
|
||||
/// a CXXDestructorDecl and the destructor type (Base, Complete) or
|
||||
/// a VarDecl, a FunctionDecl or a BlockDecl.
|
||||
class GlobalDecl {
|
||||
llvm::PointerIntPair<const Decl*, 2> Value;
|
||||
|
||||
void Init(const Decl *D) {
|
||||
assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
|
||||
assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
|
||||
|
||||
Value.setPointer(D);
|
||||
}
|
||||
|
||||
public:
|
||||
GlobalDecl() {}
|
||||
|
||||
GlobalDecl(const VarDecl *D) { Init(D);}
|
||||
GlobalDecl(const FunctionDecl *D) { Init(D); }
|
||||
GlobalDecl(const BlockDecl *D) { Init(D); }
|
||||
GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
|
||||
|
||||
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
|
||||
: Value(D, Type) {}
|
||||
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
|
||||
: Value(D, Type) {}
|
||||
|
||||
const Decl *getDecl() const { return Value.getPointer(); }
|
||||
|
||||
CXXCtorType getCtorType() const {
|
||||
assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
|
||||
return static_cast<CXXCtorType>(Value.getInt());
|
||||
}
|
||||
|
||||
CXXDtorType getDtorType() const {
|
||||
assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
|
||||
return static_cast<CXXDtorType>(Value.getInt());
|
||||
}
|
||||
|
||||
friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
|
||||
return LHS.Value == RHS.Value;
|
||||
}
|
||||
|
||||
void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
|
||||
|
||||
static GlobalDecl getFromOpaquePtr(void *P) {
|
||||
GlobalDecl GD;
|
||||
GD.Value.setFromOpaqueValue(P);
|
||||
return GD;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace CodeGen
|
||||
} // end namespace clang
|
||||
|
||||
namespace llvm {
|
||||
template<class> struct DenseMapInfo;
|
||||
|
||||
template<> struct DenseMapInfo<clang::CodeGen::GlobalDecl> {
|
||||
static inline clang::CodeGen::GlobalDecl getEmptyKey() {
|
||||
return clang::CodeGen::GlobalDecl();
|
||||
}
|
||||
|
||||
static inline clang::CodeGen::GlobalDecl getTombstoneKey() {
|
||||
return clang::CodeGen::GlobalDecl::
|
||||
getFromOpaquePtr(reinterpret_cast<void*>(-1));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(clang::CodeGen::GlobalDecl GD) {
|
||||
return DenseMapInfo<void*>::getHashValue(GD.getAsOpaquePtr());
|
||||
}
|
||||
|
||||
static bool isEqual(clang::CodeGen::GlobalDecl LHS,
|
||||
clang::CodeGen::GlobalDecl RHS) {
|
||||
return LHS == RHS;
|
||||
}
|
||||
|
||||
static bool isPod() {
|
||||
// GlobalDecl isn't *technically* a POD type. However, we can get
|
||||
// away with calling it a POD type since its copy constructor,
|
||||
// copy assignment operator, and destructor are all trivial.
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user