mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
Use llvm.global_ctors to locate global constructors instead
of recognizing them by name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148416 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
785a7a97da
commit
1dae3e965c
@ -887,6 +887,8 @@ bool ObjCARCExpand::runOnFunction(Function &F) {
|
|||||||
// ARC autorelease pool elimination.
|
// ARC autorelease pool elimination.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/Constants.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/// ObjCARCAPElim - Autorelease pool elimination.
|
/// ObjCARCAPElim - Autorelease pool elimination.
|
||||||
class ObjCARCAPElim : public ModulePass {
|
class ObjCARCAPElim : public ModulePass {
|
||||||
@ -978,17 +980,28 @@ bool ObjCARCAPElim::runOnModule(Module &M) {
|
|||||||
if (!ModuleHasARC(M))
|
if (!ModuleHasARC(M))
|
||||||
return false;
|
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;
|
bool Changed = false;
|
||||||
|
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
// Dig the constructor functions out of GV's initializer.
|
||||||
Function *F = I;
|
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.
|
// Only look at function definitions.
|
||||||
if (F->isDeclaration())
|
if (F->isDeclaration())
|
||||||
continue;
|
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.
|
// Only look at functions with one basic block.
|
||||||
if (llvm::next(F->begin()) != F->end())
|
if (llvm::next(F->begin()) != F->end())
|
||||||
continue;
|
continue;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
; RUN: opt -S -objc-arc-apelim < %s | FileCheck %s
|
; RUN: opt -S -objc-arc-apelim < %s | FileCheck %s
|
||||||
; rdar://10227311
|
; rdar://10227311
|
||||||
|
|
||||||
|
@llvm.global_ctors = appending global [2 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_x }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_y }]
|
||||||
|
|
||||||
@x = global i32 0
|
@x = global i32 0
|
||||||
|
|
||||||
declare i32 @bar() nounwind
|
declare i32 @bar() nounwind
|
||||||
|
Loading…
x
Reference in New Issue
Block a user