LLVM API Documentation
00001 //===- GlobalStatus.h - Compute status info for globals ---------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H 00011 #define LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H 00012 00013 #include "llvm/IR/Instructions.h" 00014 00015 namespace llvm { 00016 class Value; 00017 class Function; 00018 00019 /// It is safe to destroy a constant iff it is only used by constants itself. 00020 /// Note that constants cannot be cyclic, so this test is pretty easy to 00021 /// implement recursively. 00022 /// 00023 bool isSafeToDestroyConstant(const Constant *C); 00024 00025 /// As we analyze each global, keep track of some information about it. If we 00026 /// find out that the address of the global is taken, none of this info will be 00027 /// accurate. 00028 struct GlobalStatus { 00029 /// True if the global's address is used in a comparison. 00030 bool IsCompared; 00031 00032 /// True if the global is ever loaded. If the global isn't ever loaded it 00033 /// can be deleted. 00034 bool IsLoaded; 00035 00036 /// Keep track of what stores to the global look like. 00037 enum StoredType { 00038 /// There is no store to this global. It can thus be marked constant. 00039 NotStored, 00040 00041 /// This global is stored to, but the only thing stored is the constant it 00042 /// was initialized with. This is only tracked for scalar globals. 00043 InitializerStored, 00044 00045 /// This global is stored to, but only its initializer and one other value 00046 /// is ever stored to it. If this global isStoredOnce, we track the value 00047 /// stored to it in StoredOnceValue below. This is only tracked for scalar 00048 /// globals. 00049 StoredOnce, 00050 00051 /// This global is stored to by multiple values or something else that we 00052 /// cannot track. 00053 Stored 00054 } StoredType; 00055 00056 /// If only one value (besides the initializer constant) is ever stored to 00057 /// this global, keep track of what value it is. 00058 Value *StoredOnceValue; 00059 00060 /// These start out null/false. When the first accessing function is noticed, 00061 /// it is recorded. When a second different accessing function is noticed, 00062 /// HasMultipleAccessingFunctions is set to true. 00063 const Function *AccessingFunction; 00064 bool HasMultipleAccessingFunctions; 00065 00066 /// Set to true if this global has a user that is not an instruction (e.g. a 00067 /// constant expr or GV initializer). 00068 bool HasNonInstructionUser; 00069 00070 /// Set to the strongest atomic ordering requirement. 00071 AtomicOrdering Ordering; 00072 00073 /// Look at all uses of the global and fill in the GlobalStatus structure. If 00074 /// the global has its address taken, return true to indicate we can't do 00075 /// anything with it. 00076 static bool analyzeGlobal(const Value *V, GlobalStatus &GS); 00077 00078 GlobalStatus(); 00079 }; 00080 } 00081 00082 #endif