1 //===- GlobalStatus.h - Compute status info for globals ---------*- 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 #ifndef LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
11 #define LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
13 #include "llvm/IR/Instructions.h"
19 /// It is safe to destroy a constant iff it is only used by constants itself.
20 /// Note that constants cannot be cyclic, so this test is pretty easy to
21 /// implement recursively.
23 bool isSafeToDestroyConstant(const Constant *C);
25 /// As we analyze each global, keep track of some information about it. If we
26 /// find out that the address of the global is taken, none of this info will be
29 /// True if the global's address is used in a comparison.
32 /// True if the global is ever loaded. If the global isn't ever loaded it
36 /// Keep track of what stores to the global look like.
38 /// There is no store to this global. It can thus be marked constant.
41 /// This global is stored to, but the only thing stored is the constant it
42 /// was initialized with. This is only tracked for scalar globals.
45 /// This global is stored to, but only its initializer and one other value
46 /// is ever stored to it. If this global isStoredOnce, we track the value
47 /// stored to it in StoredOnceValue below. This is only tracked for scalar
51 /// This global is stored to by multiple values or something else that we
56 /// If only one value (besides the initializer constant) is ever stored to
57 /// this global, keep track of what value it is.
58 Value *StoredOnceValue;
60 /// These start out null/false. When the first accessing function is noticed,
61 /// it is recorded. When a second different accessing function is noticed,
62 /// HasMultipleAccessingFunctions is set to true.
63 const Function *AccessingFunction;
64 bool HasMultipleAccessingFunctions;
66 /// Set to true if this global has a user that is not an instruction (e.g. a
67 /// constant expr or GV initializer).
68 bool HasNonInstructionUser;
70 /// Set to the strongest atomic ordering requirement.
71 AtomicOrdering Ordering;
73 /// Look at all uses of the global and fill in the GlobalStatus structure. If
74 /// the global has its address taken, return true to indicate we can't do
76 static bool analyzeGlobal(const Value *V, GlobalStatus &GS);