[CFLAA] Move a common function to the header to reduce duplication.

Differential Revision:  https://reviews.llvm.org/D34660

llvm-svn: 306354
This commit is contained in:
Davide Italiano 2017-06-27 02:25:06 +00:00
parent 3b978394ba
commit 31d4c1bbbc
3 changed files with 17 additions and 24 deletions

View File

@ -41,4 +41,19 @@ private:
}
};
namespace llvm {
namespace cflaa {
static inline const Function *parentFunctionOfValue(const Value *Val) {
if (auto *Inst = dyn_cast<Instruction>(Val)) {
auto *Bb = Inst->getParent();
return Bb->getParent();
}
if (auto *Arg = dyn_cast<Argument>(Val))
return Arg->getParent();
return nullptr;
} // namespace cflaa
} // namespace llvm
}
#endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H

View File

@ -68,17 +68,6 @@ CFLAndersAAResult::CFLAndersAAResult(CFLAndersAAResult &&RHS)
: AAResultBase(std::move(RHS)), TLI(RHS.TLI) {}
CFLAndersAAResult::~CFLAndersAAResult() {}
static const Function *parentFunctionOfValue(const Value *Val) {
if (auto *Inst = dyn_cast<Instruction>(Val)) {
auto *Bb = Inst->getParent();
return Bb->getParent();
}
if (auto *Arg = dyn_cast<Argument>(Val))
return Arg->getParent();
return nullptr;
}
namespace {
enum class MatchState : uint8_t {

View File

@ -90,17 +90,6 @@ const StratifiedIndex StratifiedLink::SetSentinel =
/// Determines whether it would be pointless to add the given Value to our sets.
static bool canSkipAddingToSets(Value *Val);
static Function *parentFunctionOfValue(Value *Val) {
if (auto *Inst = dyn_cast<Instruction>(Val)) {
auto *Bb = Inst->getParent();
return Bb->getParent();
}
if (auto *Arg = dyn_cast<Argument>(Val))
return Arg->getParent();
return nullptr;
}
static bool canSkipAddingToSets(Value *Val) {
// Constants can share instances, which may falsely unify multiple
// sets, e.g. in
@ -281,8 +270,8 @@ AliasResult CFLSteensAAResult::query(const MemoryLocation &LocA,
return NoAlias;
Function *Fn = nullptr;
Function *MaybeFnA = parentFunctionOfValue(ValA);
Function *MaybeFnB = parentFunctionOfValue(ValB);
Function *MaybeFnA = const_cast<Function *>(parentFunctionOfValue(ValA));
Function *MaybeFnB = const_cast<Function *>(parentFunctionOfValue(ValB));
if (!MaybeFnA && !MaybeFnB) {
// The only times this is known to happen are when globals + InlineAsm are
// involved