[cfe-commits] r64492 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/CodeGen/attr-used.c
Daniel Dunbar
daniel at zuster.org
Fri Feb 13 14:08:43 PST 2009
Author: ddunbar
Date: Fri Feb 13 16:08:43 2009
New Revision: 64492
URL: http://llvm.org/viewvc/llvm-project?rev=64492&view=rev
Log:
IRgen support for attribute used.
- PR3566
Added:
cfe/trunk/test/CodeGen/attr-used.c
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=64492&r1=64491&r2=64492&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Feb 13 16:08:43 2009
@@ -138,6 +138,9 @@
if (const SectionAttr *SA = D.getAttr<SectionAttr>())
GV->setSection(SA->getName());
+ if (D.getAttr<UsedAttr>())
+ CGM.AddUsedGlobal(GV);
+
const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType());
const llvm::Type *LPtrTy =
llvm::PointerType::get(LTy, D.getType().getAddressSpace());
@@ -149,7 +152,6 @@
DI->setLocation(D.getLocation());
DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(GV), &D);
}
-
}
/// EmitLocalBlockVarDecl - Emit code and set up an entry in LocalDeclMap for a
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=64492&r1=64491&r2=64492&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Feb 13 16:08:43 2009
@@ -238,11 +238,11 @@
gv->setSection("llvm.metadata");
}
-static void SetGlobalValueAttributes(const Decl *D,
- bool IsInternal,
- bool IsInline,
- llvm::GlobalValue *GV,
- bool ForDefinition) {
+void CodeGenModule::SetGlobalValueAttributes(const Decl *D,
+ bool IsInternal,
+ bool IsInline,
+ llvm::GlobalValue *GV,
+ bool ForDefinition) {
// FIXME: Set up linkage and many other things. Note, this is a simple
// approximation of what we really want.
if (!ForDefinition) {
@@ -290,6 +290,14 @@
if (const SectionAttr *SA = D->getAttr<SectionAttr>())
GV->setSection(SA->getName());
+
+ // Only add to llvm.used when we see a definition, otherwise we
+ // might add multiple times or risk the value being replaced by a
+ // subsequent RAUW.
+ if (ForDefinition) {
+ if (D->getAttr<UsedAttr>())
+ AddUsedGlobal(GV);
+ }
}
void CodeGenModule::SetFunctionAttributes(const Decl *D,
@@ -492,8 +500,9 @@
}
bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) {
- // Never defer when EmitAllDecls is specified.
- if (Features.EmitAllDecls)
+ // Never defer when EmitAllDecls is specified or the decl has
+ // attribute used.
+ if (Features.EmitAllDecls || Global->getAttr<UsedAttr>())
return false;
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Global)) {
@@ -728,6 +737,9 @@
if (const SectionAttr *SA = D->getAttr<SectionAttr>())
GV->setSection(SA->getName());
+ if (D->getAttr<UsedAttr>())
+ AddUsedGlobal(GV);
+
// Emit global variable debug information.
CGDebugInfo *DI = getDebugInfo();
if(DI) {
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=64492&r1=64491&r2=64492&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Fri Feb 13 16:08:43 2009
@@ -284,6 +284,13 @@
private:
+ /// SetGlobalValueAttributes - Set attributes for a global decl.
+ void SetGlobalValueAttributes(const Decl *D,
+ bool IsInternal,
+ bool IsInline,
+ llvm::GlobalValue *GV,
+ bool ForDefinition);
+
/// SetFunctionAttributesForDefinition - Set function attributes specific to a
/// function definition.
/// \param D - The ObjCMethodDecl or FunctionDecl defining \arg F.
Added: cfe/trunk/test/CodeGen/attr-used.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-used.c?rev=64492&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/attr-used.c (added)
+++ cfe/trunk/test/CodeGen/attr-used.c Fri Feb 13 16:08:43 2009
@@ -0,0 +1,14 @@
+// RUN: clang -emit-llvm -o %t %s &&
+// RUN: grep '@llvm.used = .*@g0' %t &&
+// RUN: grep '@llvm.used = .*@f0' %t &&
+// RUN: grep '@llvm.used = .*@f1.l0' %t
+
+
+int g0 __attribute__((used));
+
+static void __attribute__((used)) f0(void) {
+}
+
+void f1() {
+ static int l0 __attribute__((used)) = 5225;
+}
More information about the cfe-commits
mailing list