1 //===-- ValueLatticeUtils.cpp - Utils for solving lattices ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements common functions useful for performing data-flow
11 // analyses that propagate values across function boundaries.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Analysis/ValueLatticeUtils.h"
16 #include "llvm/IR/GlobalVariable.h"
17 #include "llvm/IR/Instructions.h"
20 bool llvm::canTrackArgumentsInterprocedurally(Function
*F
) {
21 return F
->hasLocalLinkage() && !F
->hasAddressTaken();
24 bool llvm::canTrackReturnsInterprocedurally(Function
*F
) {
25 return F
->hasExactDefinition() && !F
->hasFnAttribute(Attribute::Naked
);
28 bool llvm::canTrackGlobalVariableInterprocedurally(GlobalVariable
*GV
) {
29 if (GV
->isConstant() || !GV
->hasLocalLinkage() ||
30 !GV
->hasDefinitiveInitializer())
32 return !any_of(GV
->users(), [&](User
*U
) {
33 if (auto *Store
= dyn_cast
<StoreInst
>(U
)) {
34 if (Store
->getValueOperand() == GV
|| Store
->isVolatile())
36 } else if (auto *Load
= dyn_cast
<LoadInst
>(U
)) {
37 if (Load
->isVolatile())