blob: 22c9de4fe94d954e69cfb747e99e9af6f9db705c [file] [log] [blame]
Matthew Simpson0a543332017-10-13 17:53:44 +00001//===-- ValueLatticeUtils.cpp - Utils for solving lattices ------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements common functions useful for performing data-flow
11// analyses that propagate values across function boundaries.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/Analysis/ValueLatticeUtils.h"
16#include "llvm/IR/GlobalVariable.h"
17#include "llvm/IR/Instructions.h"
18using namespace llvm;
19
20bool llvm::canTrackArgumentsInterprocedurally(Function *F) {
21 return F->hasLocalLinkage() && !F->hasAddressTaken();
22}
23
24bool llvm::canTrackReturnsInterprocedurally(Function *F) {
25 return F->hasExactDefinition() && !F->hasFnAttribute(Attribute::Naked);
26}
27
28bool llvm::canTrackGlobalVariableInterprocedurally(GlobalVariable *GV) {
29 if (GV->isConstant() || !GV->hasLocalLinkage() ||
30 !GV->hasDefinitiveInitializer())
31 return false;
32 return !any_of(GV->users(), [&](User *U) {
33 if (auto *Store = dyn_cast<StoreInst>(U)) {
34 if (Store->getValueOperand() == GV || Store->isVolatile())
35 return true;
36 } else if (auto *Load = dyn_cast<LoadInst>(U)) {
37 if (Load->isVolatile())
38 return true;
39 } else {
40 return true;
41 }
42 return false;
43 });
44}