LLVM  10.0.0svn
GlobalStatus.h
Go to the documentation of this file.
1 //===- GlobalStatus.h - Compute status info for globals ---------*- 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 
9 #ifndef LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
10 #define LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
11 
13 
14 namespace llvm {
15 
16 class Constant;
17 class Function;
18 class Value;
19 
20 /// It is safe to destroy a constant iff it is only used by constants itself.
21 /// Note that constants cannot be cyclic, so this test is pretty easy to
22 /// implement recursively.
23 ///
25 
26 /// As we analyze each global, keep track of some information about it. If we
27 /// find out that the address of the global is taken, none of this info will be
28 /// accurate.
29 struct GlobalStatus {
30  /// True if the global's address is used in a comparison.
31  bool IsCompared = false;
32 
33  /// True if the global is ever loaded. If the global isn't ever loaded it
34  /// can be deleted.
35  bool IsLoaded = false;
36 
37  /// Keep track of what stores to the global look like.
38  enum StoredType {
39  /// There is no store to this global. It can thus be marked constant.
41 
42  /// This global is stored to, but the only thing stored is the constant it
43  /// was initialized with. This is only tracked for scalar globals.
45 
46  /// This global is stored to, but only its initializer and one other value
47  /// is ever stored to it. If this global isStoredOnce, we track the value
48  /// stored to it in StoredOnceValue below. This is only tracked for scalar
49  /// globals.
51 
52  /// This global is stored to by multiple values or something else that we
53  /// cannot track.
56 
57  /// If only one value (besides the initializer constant) is ever stored to
58  /// this global, keep track of what value it is.
59  Value *StoredOnceValue = nullptr;
60 
61  /// These start out null/false. When the first accessing function is noticed,
62  /// it is recorded. When a second different accessing function is noticed,
63  /// HasMultipleAccessingFunctions is set to true.
64  const Function *AccessingFunction = nullptr;
66 
67  /// Set to true if this global has a user that is not an instruction (e.g. a
68  /// constant expr or GV initializer).
69  bool HasNonInstructionUser = false;
70 
71  /// Set to the strongest atomic ordering requirement.
73 
74  GlobalStatus();
75 
76  /// Look at all uses of the global and fill in the GlobalStatus structure. If
77  /// the global has its address taken, return true to indicate we can't do
78  /// anything with it.
79  static bool analyzeGlobal(const Value *V, GlobalStatus &GS);
80 };
81 
82 } // end namespace llvm
83 
84 #endif // LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
uint64_t CallInst * C
bool IsLoaded
True if the global is ever loaded.
Definition: GlobalStatus.h:35
Value * StoredOnceValue
If only one value (besides the initializer constant) is ever stored to this global, keep track of what value it is.
Definition: GlobalStatus.h:59
const Function * AccessingFunction
These start out null/false.
Definition: GlobalStatus.h:64
Atomic ordering constants.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool HasMultipleAccessingFunctions
Definition: GlobalStatus.h:65
This global is stored to, but the only thing stored is the constant it was initialized with...
Definition: GlobalStatus.h:44
StoredType
Keep track of what stores to the global look like.
Definition: GlobalStatus.h:38
bool HasNonInstructionUser
Set to true if this global has a user that is not an instruction (e.g.
Definition: GlobalStatus.h:69
AtomicOrdering
Atomic ordering for LLVM's memory model.
This global is stored to, but only its initializer and one other value is ever stored to it...
Definition: GlobalStatus.h:50
As we analyze each global, keep track of some information about it.
Definition: GlobalStatus.h:29
static bool analyzeGlobal(const Value *V, GlobalStatus &GS)
Look at all uses of the global and fill in the GlobalStatus structure.
bool isSafeToDestroyConstant(const Constant *C)
It is safe to destroy a constant iff it is only used by constants itself.
This global is stored to by multiple values or something else that we cannot track.
Definition: GlobalStatus.h:54
bool IsCompared
True if the global's address is used in a comparison.
Definition: GlobalStatus.h:31
AtomicOrdering Ordering
Set to the strongest atomic ordering requirement.
Definition: GlobalStatus.h:72
LLVM Value Representation.
Definition: Value.h:73
There is no store to this global. It can thus be marked constant.
Definition: GlobalStatus.h:40