LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GlobalStatus.h
Go to the documentation of this file.
1 //===- GlobalStatus.h - Compute status info for globals ---------*- 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 #ifndef LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
11 #define LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
12 
13 #include "llvm/IR/Instructions.h"
14 
15 namespace llvm {
16 class Value;
17 class Function;
18 
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.
22 ///
24 
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
27 /// accurate.
28 struct GlobalStatus {
29  /// True if the global's address is used in a comparison.
30  bool IsCompared;
31 
32  /// True if the global is ever loaded. If the global isn't ever loaded it
33  /// can be deleted.
34  bool IsLoaded;
35 
36  /// Keep track of what stores to the global look like.
37  enum StoredType {
38  /// There is no store to this global. It can thus be marked constant.
40 
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.
44 
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
48  /// globals.
50 
51  /// This global is stored to by multiple values or something else that we
52  /// cannot track.
54  } StoredType;
55 
56  /// If only one value (besides the initializer constant) is ever stored to
57  /// this global, keep track of what value it is.
59 
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.
65 
66  /// Set to true if this global has a user that is not an instruction (e.g. a
67  /// constant expr or GV initializer).
69 
70  /// Set to the strongest atomic ordering requirement.
72 
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
75  /// anything with it.
76  static bool analyzeGlobal(const Value *V, GlobalStatus &GS);
77 
78  GlobalStatus();
79 };
80 }
81 
82 #endif
Value * StoredOnceValue
Definition: GlobalStatus.h:58
const Function * AccessingFunction
Definition: GlobalStatus.h:63
bool HasMultipleAccessingFunctions
Definition: GlobalStatus.h:64
StoredType
Keep track of what stores to the global look like.
Definition: GlobalStatus.h:37
AtomicOrdering
Definition: Instructions.h:36
static bool analyzeGlobal(const Value *V, GlobalStatus &GS)
bool isSafeToDestroyConstant(const Constant *C)
bool IsCompared
True if the global's address is used in a comparison.
Definition: GlobalStatus.h:30
AtomicOrdering Ordering
Set to the strongest atomic ordering requirement.
Definition: GlobalStatus.h:71
LLVM Value Representation.
Definition: Value.h:66
There is no store to this global. It can thus be marked constant.
Definition: GlobalStatus.h:39