[Alignment][NFC] Support compile time constants
[llvm-core.git] / include / llvm / Analysis / CFLAliasAnalysisUtils.h
blob02f999a5b913d6ea3597358429b63a293baa96d9
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'.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
15 #define LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/ValueHandle.h"
20 namespace llvm {
21 namespace cflaa {
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);
30 void deleted() override { removeSelfFromCache(); }
31 void allUsesReplacedWith(Value *) override { removeSelfFromCache(); }
33 private:
34 AAResult *Result;
36 void removeSelfFromCache() {
37 assert(Result != nullptr);
38 auto *Val = getValPtr();
39 Result->evict(cast<Function>(Val));
40 setValPtr(nullptr);
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();
50 if (auto *Arg = dyn_cast<Argument>(Val))
51 return Arg->getParent();
52 return nullptr;
53 } // namespace cflaa
54 } // namespace llvm
57 #endif // LLVM_ANALYSIS_CFLALIASANALYSISUTILS_H