LLVM  15.0.0git
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/Argument.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/ValueHandle.h"
20 
21 namespace llvm {
22 
23 namespace cflaa {
24 
25 template <typename AAResult> struct FunctionHandle final : public CallbackVH {
26  FunctionHandle(Function *Fn, AAResult *Result)
27  : CallbackVH(Fn), Result(Result) {
28  assert(Fn != nullptr);
29  assert(Result != nullptr);
30  }
31 
32  void deleted() override { removeSelfFromCache(); }
33  void allUsesReplacedWith(Value *) override { removeSelfFromCache(); }
34 
35 private:
36  AAResult *Result;
37 
38  void removeSelfFromCache() {
39  assert(Result != nullptr);
40  auto *Val = getValPtr();
41  Result->evict(cast<Function>(Val));
42  setValPtr(nullptr);
43  }
44 };
45 
46 static inline const Function *parentFunctionOfValue(const Value *Val) {
47  if (auto *Inst = dyn_cast<Instruction>(Val)) {
48  auto *Bb = Inst->getParent();
49  return Bb->getParent();
50  }
51 
52  if (auto *Arg = dyn_cast<Argument>(Val))
53  return Arg->getParent();
54  return nullptr;
55 }
56 } // namespace cflaa
57 } // namespace llvm
58 
59 #endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::Function
Definition: Function.h:60
llvm::cflaa::FunctionHandle
Definition: CFLAliasAnalysisUtils.h:25
llvm::ValueHandleBase::getValPtr
Value * getValPtr() const
Definition: ValueHandle.h:99
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
llvm::cflaa::FunctionHandle::FunctionHandle
FunctionHandle(Function *Fn, AAResult *Result)
Definition: CFLAliasAnalysisUtils.h:26
llvm::cflaa::FunctionHandle::allUsesReplacedWith
void allUsesReplacedWith(Value *) override
Callback for Value RAUW.
Definition: CFLAliasAnalysisUtils.h:33
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:577
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::cflaa::FunctionHandle::deleted
void deleted() override
Callback for Value destruction.
Definition: CFLAliasAnalysisUtils.h:32
ValueHandle.h
llvm::cflaa::parentFunctionOfValue
static const Function * parentFunctionOfValue(const Value *Val)
Definition: CFLAliasAnalysisUtils.h:46
Argument.h
Function.h
llvm::CallbackVH
Value handle with callbacks on RAUW and destruction.
Definition: ValueHandle.h:383
llvm::CallbackVH::setValPtr
void setValPtr(Value *P)
Definition: ValueHandle.h:390
llvm::Value
LLVM Value Representation.
Definition: Value.h:74