forked from OSchip/llvm-project
parent
0c5e3132aa
commit
3bfce1887f
|
@ -535,11 +535,12 @@ bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) {
|
||||||
if (FD->getAttr<ConstructorAttr>() || FD->getAttr<DestructorAttr>())
|
if (FD->getAttr<ConstructorAttr>() || FD->getAttr<DestructorAttr>())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// FIXME: What about inline, and/or extern inline?
|
||||||
if (FD->getStorageClass() != FunctionDecl::Static)
|
if (FD->getStorageClass() != FunctionDecl::Static)
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
const VarDecl *VD = cast<VarDecl>(Global);
|
const VarDecl *VD = cast<VarDecl>(Global);
|
||||||
assert(VD->isFileVarDecl() && "Invalid decl.");
|
assert(VD->isFileVarDecl() && "Invalid decl");
|
||||||
|
|
||||||
if (VD->getStorageClass() != VarDecl::Static)
|
if (VD->getStorageClass() != VarDecl::Static)
|
||||||
return false;
|
return false;
|
||||||
|
@ -594,42 +595,46 @@ void CodeGenModule::EmitGlobalDefinition(const ValueDecl *D) {
|
||||||
|
|
||||||
QualType ASTTy = D->getType();
|
QualType ASTTy = D->getType();
|
||||||
const llvm::Type *Ty = getTypes().ConvertTypeForMem(ASTTy);
|
const llvm::Type *Ty = getTypes().ConvertTypeForMem(ASTTy);
|
||||||
const llvm::Type *PTy = llvm::PointerType::get(Ty, ASTTy.getAddressSpace());
|
|
||||||
|
|
||||||
// Lookup the entry, lazily creating it if necessary.
|
// Lookup the entry, lazily creating it if necessary.
|
||||||
llvm::GlobalValue *&Entry = GlobalDeclMap[getMangledName(D)];
|
llvm::GlobalValue *&Entry = GlobalDeclMap[getMangledName(D)];
|
||||||
if (!Entry) {
|
if (Entry) {
|
||||||
llvm::GlobalVariable *GV =
|
const llvm::Type *PTy = llvm::PointerType::get(Ty, ASTTy.getAddressSpace());
|
||||||
new llvm::GlobalVariable(Ty, false,
|
|
||||||
llvm::GlobalValue::ExternalLinkage,
|
// Make sure the result is of the correct type.
|
||||||
0, getMangledName(D), &getModule(),
|
if (Entry->getType() != PTy)
|
||||||
0, ASTTy.getAddressSpace());
|
return llvm::ConstantExpr::getBitCast(Entry, PTy);
|
||||||
Entry = GV;
|
return Entry;
|
||||||
|
|
||||||
// Handle things which are present even on external declarations.
|
|
||||||
|
|
||||||
// FIXME: This code is overly simple and should be merged with
|
|
||||||
// other global handling.
|
|
||||||
|
|
||||||
GV->setConstant(D->getType().isConstant(Context));
|
|
||||||
|
|
||||||
// FIXME: Merge with other attribute handling code.
|
|
||||||
|
|
||||||
if (D->getStorageClass() == VarDecl::PrivateExtern)
|
|
||||||
setGlobalVisibility(GV, VisibilityAttr::HiddenVisibility);
|
|
||||||
|
|
||||||
if (D->getAttr<WeakAttr>() || D->getAttr<WeakImportAttr>())
|
|
||||||
GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
|
|
||||||
|
|
||||||
if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
|
|
||||||
// Prefaced with special LLVM marker to indicate that the name
|
|
||||||
// should not be munged.
|
|
||||||
GV->setName("\01" + ALA->getLabel());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the result is of the correct type.
|
llvm::GlobalVariable *GV =
|
||||||
return llvm::ConstantExpr::getBitCast(Entry, PTy);
|
new llvm::GlobalVariable(Ty, false,
|
||||||
|
llvm::GlobalValue::ExternalLinkage,
|
||||||
|
0, getMangledName(D), &getModule(),
|
||||||
|
0, ASTTy.getAddressSpace());
|
||||||
|
|
||||||
|
// Handle things which are present even on external declarations.
|
||||||
|
|
||||||
|
// FIXME: This code is overly simple and should be merged with
|
||||||
|
// other global handling.
|
||||||
|
|
||||||
|
GV->setConstant(D->getType().isConstant(Context));
|
||||||
|
|
||||||
|
// FIXME: Merge with other attribute handling code.
|
||||||
|
|
||||||
|
if (D->getStorageClass() == VarDecl::PrivateExtern)
|
||||||
|
setGlobalVisibility(GV, VisibilityAttr::HiddenVisibility);
|
||||||
|
|
||||||
|
if (D->getAttr<WeakAttr>() || D->getAttr<WeakImportAttr>())
|
||||||
|
GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
|
||||||
|
|
||||||
|
// FIXME: This should be handled by the mangler!
|
||||||
|
if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
|
||||||
|
// Prefaced with special LLVM marker to indicate that the name
|
||||||
|
// should not be munged.
|
||||||
|
GV->setName("\01" + ALA->getLabel());
|
||||||
|
}
|
||||||
|
return Entry = GV;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
|
void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
|
||||||
|
@ -826,7 +831,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(const FunctionDecl *D) {
|
||||||
// Lookup the entry, lazily creating it if necessary.
|
// Lookup the entry, lazily creating it if necessary.
|
||||||
llvm::GlobalValue *&Entry = GlobalDeclMap[getMangledName(D)];
|
llvm::GlobalValue *&Entry = GlobalDeclMap[getMangledName(D)];
|
||||||
if (!Entry)
|
if (!Entry)
|
||||||
Entry = EmitForwardFunctionDefinition(D, 0);
|
return Entry = EmitForwardFunctionDefinition(D, 0);
|
||||||
|
|
||||||
if (Entry->getType() != PTy)
|
if (Entry->getType() != PTy)
|
||||||
return llvm::ConstantExpr::getBitCast(Entry, PTy);
|
return llvm::ConstantExpr::getBitCast(Entry, PTy);
|
||||||
|
|
|
@ -86,7 +86,7 @@ class CodeGenModule : public BlockModule {
|
||||||
/// protected from introducing conflicts. These globals should be
|
/// protected from introducing conflicts. These globals should be
|
||||||
/// created unnamed, we will name them and patch up conflicts when
|
/// created unnamed, we will name them and patch up conflicts when
|
||||||
/// we release the module.
|
/// we release the module.
|
||||||
std::vector< std::pair<llvm::GlobalValue*, std::string> > RuntimeGlobals;
|
std::vector<std::pair<llvm::GlobalValue*, std::string> > RuntimeGlobals;
|
||||||
|
|
||||||
/// GlobalDeclMap - Mapping of decl names (represented as unique
|
/// GlobalDeclMap - Mapping of decl names (represented as unique
|
||||||
/// character pointers from either the identifier table or the set
|
/// character pointers from either the identifier table or the set
|
||||||
|
|
Loading…
Reference in New Issue