LLVM  9.0.0svn
CFLAliasAnalysisUtils.h
Go to the documentation of this file.
1 //=- CFLAliasAnalysisUtils.h - Utilities for CFL Alias Analysis ----*- C++-*-=//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // \file
9 // These are the utilities/helpers used by the CFL Alias Analyses available in
10 // tree, i.e. Steensgaard's and Andersens'.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
15 #define LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
16 
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/ValueHandle.h"
19 
20 namespace llvm {
21 namespace cflaa {
22 
23 template <typename AAResult> struct FunctionHandle final : public CallbackVH {
24  FunctionHandle(Function *Fn, AAResult *Result)
25  : CallbackVH(Fn), Result(Result) {
26  assert(Fn != nullptr);
27  assert(Result != nullptr);
28  }
29 
30  void deleted() override { removeSelfFromCache(); }
31  void allUsesReplacedWith(Value *) override { removeSelfFromCache(); }
32 
33 private:
34  AAResult *Result;
35 
36  void removeSelfFromCache() {
37  assert(Result != nullptr);
38  auto *Val = getValPtr();
39  Result->evict(cast<Function>(Val));
40  setValPtr(nullptr);
41  }
42 };
43 
44 static inline const Function *parentFunctionOfValue(const Value *Val) {
45  if (auto *Inst = dyn_cast<Instruction>(Val)) {
46  auto *Bb = Inst->getParent();
47  return Bb->getParent();
48  }
49 
50  if (auto *Arg = dyn_cast<Argument>(Val))
51  return Arg->getParent();
52  return nullptr;
53 } // namespace cflaa
54 } // namespace llvm
55 }
56 
57 #endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void setValPtr(Value *P)
Definition: ValueHandle.h:386
FunctionHandle(Function *Fn, AAResult *Result)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const Function * parentFunctionOfValue(const Value *Val)
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:72
Value handle with callbacks on RAUW and destruction.
Definition: ValueHandle.h:379
void deleted() override
Callback for Value destruction.
void allUsesReplacedWith(Value *) override
Callback for Value RAUW.
Value * getValPtr() const
Definition: ValueHandle.h:95