2013-07-11 02:49:00 +08:00
|
|
|
//===- ObjCARC.h - ObjC ARC Optimization --------------*- C++ -*-----------===//
|
2013-01-28 11:28:38 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This file defines common definitions/declarations used by the ObjC ARC
|
|
|
|
/// Optimizer. ARC stands for Automatic Reference Counting and is a system for
|
|
|
|
/// managing reference counts for objects in Objective C.
|
|
|
|
///
|
|
|
|
/// WARNING: This file knows about certain library functions. It recognizes them
|
|
|
|
/// by name, and hardwires knowledge of their semantics.
|
|
|
|
///
|
|
|
|
/// WARNING: This file knows about how certain Objective-C library functions are
|
|
|
|
/// used. Naive LLVM IR transformations which would otherwise be
|
|
|
|
/// behavior-preserving may break these assumptions.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARC_H
|
|
|
|
#define LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARC_H
|
2013-01-28 11:28:38 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2015-08-20 16:06:03 +08:00
|
|
|
#include "llvm/Analysis/ObjCARCAnalysisUtils.h"
|
|
|
|
#include "llvm/Analysis/ObjCARCInstKind.h"
|
2013-01-28 11:28:38 +08:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
2013-01-28 13:51:54 +08:00
|
|
|
#include "llvm/Analysis/ValueTracking.h"
|
2014-03-04 19:01:28 +08:00
|
|
|
#include "llvm/IR/CallSite.h"
|
2014-03-04 18:30:26 +08:00
|
|
|
#include "llvm/IR/InstIterator.h"
|
2013-01-28 11:28:38 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Transforms/ObjCARC.h"
|
2013-01-29 11:03:03 +08:00
|
|
|
#include "llvm/Transforms/Utils/Local.h"
|
2013-01-28 11:28:38 +08:00
|
|
|
|
2013-01-29 12:51:59 +08:00
|
|
|
namespace llvm {
|
|
|
|
class raw_ostream;
|
|
|
|
}
|
|
|
|
|
2013-01-28 11:28:38 +08:00
|
|
|
namespace llvm {
|
|
|
|
namespace objcarc {
|
|
|
|
|
2013-01-29 11:03:03 +08:00
|
|
|
/// \brief Erase the given instruction.
|
|
|
|
///
|
|
|
|
/// Many ObjC calls return their argument verbatim,
|
|
|
|
/// so if it's such a call and the return value has users, replace them with the
|
|
|
|
/// argument value.
|
|
|
|
///
|
|
|
|
static inline void EraseInstruction(Instruction *CI) {
|
|
|
|
Value *OldArg = cast<CallInst>(CI)->getArgOperand(0);
|
|
|
|
|
|
|
|
bool Unused = CI->use_empty();
|
|
|
|
|
|
|
|
if (!Unused) {
|
|
|
|
// Replace the return value with the argument.
|
2015-02-20 03:51:32 +08:00
|
|
|
assert((IsForwarding(GetBasicARCInstKind(CI)) ||
|
|
|
|
(IsNoopOnNull(GetBasicARCInstKind(CI)) &&
|
2013-07-09 07:30:23 +08:00
|
|
|
isa<ConstantPointerNull>(OldArg))) &&
|
2013-01-29 11:03:03 +08:00
|
|
|
"Can't delete non-forwarding instruction with users!");
|
|
|
|
CI->replaceAllUsesWith(OldArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
CI->eraseFromParent();
|
|
|
|
|
|
|
|
if (Unused)
|
|
|
|
RecursivelyDeleteTriviallyDeadInstructions(OldArg);
|
|
|
|
}
|
|
|
|
|
2013-01-28 11:28:38 +08:00
|
|
|
} // end namespace objcarc
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#endif
|