summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2008-06-08 15:45:52 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2008-06-08 15:45:52 +0000
commitb6f79538182462413595f9f0990b292fd9b21a41 (patch)
tree68bdf1169c4059d60ffa321cf97098cf7d35dc9e /clang/lib/CodeGen/CodeGenModule.cpp
parent486c7d3fa50c1f1e7a3d2f5bbca29bc28b588f32 (diff)
downloadbcm5719-llvm-b6f79538182462413595f9f0990b292fd9b21a41.tar.gz
bcm5719-llvm-b6f79538182462413595f9f0990b292fd9b21a41.zip
implement the alias attirbute (in both Sema and Codegen)
llvm-svn: 52092
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp56
1 files changed, 39 insertions, 17 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index b802ce7d97c..1d0001c607a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -188,6 +188,24 @@ bool hasAggregateLLVMType(QualType T) {
!T->isVoidType() && !T->isVectorType() && !T->isFunctionType();
}
+void CodeGenModule::SetGlobalValueAttributes(const FunctionDecl *FD,
+ llvm::GlobalValue *GV) {
+ // TODO: Set up linkage and many other things. Note, this is a simple
+ // approximation of what we really want.
+ if (FD->getStorageClass() == FunctionDecl::Static)
+ GV->setLinkage(llvm::Function::InternalLinkage);
+ else if (FD->getAttr<DLLImportAttr>())
+ GV->setLinkage(llvm::Function::DLLImportLinkage);
+ else if (FD->getAttr<DLLExportAttr>())
+ GV->setLinkage(llvm::Function::DLLExportLinkage);
+ else if (FD->getAttr<WeakAttr>() || FD->isInline())
+ GV->setLinkage(llvm::Function::WeakLinkage);
+
+ if (const VisibilityAttr *attr = FD->getAttr<VisibilityAttr>())
+ CodeGenModule::setVisibility(GV, attr->getVisibility());
+ // FIXME: else handle -fvisibility
+}
+
void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD,
llvm::Function *F,
const llvm::FunctionType *FTy) {
@@ -230,20 +248,7 @@ void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD,
if (FD->getAttr<FastCallAttr>())
F->setCallingConv(llvm::CallingConv::Fast);
- // TODO: Set up linkage and many other things. Note, this is a simple
- // approximation of what we really want.
- if (FD->getStorageClass() == FunctionDecl::Static)
- F->setLinkage(llvm::Function::InternalLinkage);
- else if (FD->getAttr<DLLImportAttr>())
- F->setLinkage(llvm::Function::DLLImportLinkage);
- else if (FD->getAttr<DLLExportAttr>())
- F->setLinkage(llvm::Function::DLLExportLinkage);
- else if (FD->getAttr<WeakAttr>() || FD->isInline())
- F->setLinkage(llvm::Function::WeakLinkage);
-
- if (const VisibilityAttr *attr = FD->getAttr<VisibilityAttr>())
- CodeGenModule::setVisibility(F, attr->getVisibility());
- // FIXME: else handle -fvisibility
+ SetGlobalValueAttributes(FD, F);
}
@@ -263,8 +268,20 @@ llvm::Constant *CodeGenModule::GetAddrOfFunctionDecl(const FunctionDecl *D,
// If it doesn't already exist, just create and return an entry.
if (F == 0) {
// FIXME: param attributes for sext/zext etc.
- F = llvm::Function::Create(FTy, llvm::Function::ExternalLinkage,
- D->getName(), &getModule());
+ if (D->getBody() || !D->getAttr<AliasAttr>())
+ F = llvm::Function::Create(FTy, llvm::Function::ExternalLinkage,
+ D->getName(), &getModule());
+ else {
+ const std::string& aliaseeName = D->getAttr<AliasAttr>()->getAliasee();
+ llvm::Function *aliasee = getModule().getFunction(aliaseeName);
+ llvm::GlobalValue *alias = new llvm::GlobalAlias(aliasee->getType(),
+ llvm::Function::ExternalLinkage,
+ D->getName(),
+ aliasee,
+ &getModule());
+ SetGlobalValueAttributes(D, alias);
+ return Entry = alias;
+ }
SetFunctionAttributes(D, F, FTy);
return Entry = F;
@@ -494,8 +511,11 @@ void CodeGenModule::EmitObjCClassImplementation(
void CodeGenModule::EmitFunction(const FunctionDecl *FD) {
// If this is not a prototype, emit the body.
- if (!FD->isThisDeclarationADefinition())
+ if (!FD->isThisDeclarationADefinition()) {
+ if (FD->getAttr<AliasAttr>())
+ GetAddrOfFunctionDecl(FD, true);
return;
+ }
// If the function is a static, defer code generation until later so we can
// easily omit unused statics.
@@ -534,6 +554,8 @@ void CodeGenModule::EmitStatics() {
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
if (FD->getBody())
CodeGenFunction(*this).GenerateCode(FD);
+ else if (FD->getAttr<AliasAttr>())
+ GetAddrOfFunctionDecl(FD, true);
} else {
EmitGlobalVarInit(cast<VarDecl>(D));
}
OpenPOWER on IntegriCloud