summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2012-01-18 21:19:38 +0000
committerDan Gohman <gohman@apple.com>2012-01-18 21:19:38 +0000
commit82041c2e608de80b38c6feb2fcc300eb3ab8cce4 (patch)
tree50cbc4454bf4ac22f32632f3ea16cdd226f20a2a /llvm/lib
parent632a355a01122b72f0fbaaa1538d18a42389c023 (diff)
downloadbcm5719-llvm-82041c2e608de80b38c6feb2fcc300eb3ab8cce4.tar.gz
bcm5719-llvm-82041c2e608de80b38c6feb2fcc300eb3ab8cce4.zip
Use llvm.global_ctors to locate global constructors instead
of recognizing them by name. llvm-svn: 148416
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/ObjCARC.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/ObjCARC.cpp b/llvm/lib/Transforms/Scalar/ObjCARC.cpp
index 87df83857b1..a01676ab65b 100644
--- a/llvm/lib/Transforms/Scalar/ObjCARC.cpp
+++ b/llvm/lib/Transforms/Scalar/ObjCARC.cpp
@@ -887,6 +887,8 @@ bool ObjCARCExpand::runOnFunction(Function &F) {
// ARC autorelease pool elimination.
//===----------------------------------------------------------------------===//
+#include "llvm/Constants.h"
+
namespace {
/// ObjCARCAPElim - Autorelease pool elimination.
class ObjCARCAPElim : public ModulePass {
@@ -978,17 +980,28 @@ bool ObjCARCAPElim::runOnModule(Module &M) {
if (!ModuleHasARC(M))
return false;
+ // Find the llvm.global_ctors variable, as the first step in
+ // identifying the global constructors.
+ GlobalVariable *GV = M.getGlobalVariable("llvm.global_ctors");
+ if (!GV)
+ return false;
+
+ assert(GV->hasDefinitiveInitializer() &&
+ "llvm.global_ctors is uncooperative!");
+
bool Changed = false;
- for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
- Function *F = I;
+ // Dig the constructor functions out of GV's initializer.
+ ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
+ for (User::op_iterator OI = Init->op_begin(), OE = Init->op_end();
+ OI != OE; ++OI) {
+ Value *Op = *OI;
+ // llvm.global_ctors is an array of pairs where the second members
+ // are constructor functions.
+ Function *F = cast<Function>(cast<ConstantStruct>(Op)->getOperand(1));
// Only look at function definitions.
if (F->isDeclaration())
continue;
- // Only look at global constructor functions. Unfortunately,
- // the name is the most convenient way to recognize them.
- if (!F->getName().startswith("_GLOBAL__I_"))
- continue;
// Only look at functions with one basic block.
if (llvm::next(F->begin()) != F->end())
continue;
OpenPOWER on IntegriCloud