LLVM
8.0.1
|
#include "llvm/Transforms/IPO/GlobalOpt.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Pass.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Utils/CtorUtils.h"
#include "llvm/Transforms/Utils/Evaluator.h"
#include "llvm/Transforms/Utils/GlobalStatus.h"
#include <cassert>
#include <cstdint>
#include <utility>
#include <vector>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "globalopt" |
Functions | |
STATISTIC (NumMarked, "Number of globals marked constant") | |
STATISTIC (NumUnnamed, "Number of globals marked unnamed_addr") | |
STATISTIC (NumSRA, "Number of aggregate globals broken into scalars") | |
STATISTIC (NumHeapSRA, "Number of heap objects SRA'd") | |
STATISTIC (NumSubstitute,"Number of globals with initializers stored into them") | |
STATISTIC (NumDeleted, "Number of globals deleted") | |
STATISTIC (NumGlobUses, "Number of global uses devirtualized") | |
STATISTIC (NumLocalized, "Number of globals localized") | |
STATISTIC (NumShrunkToBool, "Number of global vars shrunk to booleans") | |
STATISTIC (NumFastCallFns, "Number of functions converted to fastcc") | |
STATISTIC (NumCtorsEvaluated, "Number of static ctors evaluated") | |
STATISTIC (NumNestRemoved, "Number of nest attributes removed") | |
STATISTIC (NumAliasesResolved, "Number of global aliases resolved") | |
STATISTIC (NumAliasesRemoved, "Number of global aliases eliminated") | |
STATISTIC (NumCXXDtorsRemoved, "Number of global C++ destructors removed") | |
STATISTIC (NumInternalFunc, "Number of internal functions") | |
STATISTIC (NumColdCC, "Number of functions marked coldcc") | |
static bool | isLeakCheckerRoot (GlobalVariable *GV) |
Is this global variable possibly used by a leak checker as a root? If so, we might not really want to eliminate the stores to it. More... | |
static bool | IsSafeComputationToRemove (Value *V, const TargetLibraryInfo *TLI) |
Given a value that is stored to a global but never read, determine whether it's safe to remove the store and the chain of computation that feeds the store. More... | |
static bool | CleanupPointerRootUsers (GlobalVariable *GV, const TargetLibraryInfo *TLI) |
This GV is a pointer root. More... | |
static bool | CleanupConstantGlobalUsers (Value *V, Constant *Init, const DataLayout &DL, TargetLibraryInfo *TLI) |
We just marked GV constant. More... | |
static bool | isSafeSROAElementUse (Value *V) |
Return true if the specified instruction is a safe user of a derived expression from a global that we want to SROA. More... | |
static bool | isSafeSROAGEP (User *U) |
Return true if the specified GEP is a safe user of a derived expression from a global that we want to SROA. More... | |
static bool | GlobalUsersSafeToSRA (GlobalValue *GV) |
Look at all uses of the global and decide whether it is safe for us to perform this transformation. More... | |
static void | transferSRADebugInfo (GlobalVariable *GV, GlobalVariable *NGV, uint64_t FragmentOffsetInBits, uint64_t FragmentSizeInBits, unsigned NumElements) |
Copy over the debug info for a variable to its SRA replacements. More... | |
static GlobalVariable * | SRAGlobal (GlobalVariable *GV, const DataLayout &DL) |
Perform scalar replacement of aggregates on the specified global variable. More... | |
static bool | AllUsesOfValueWillTrapIfNull (const Value *V, SmallPtrSetImpl< const PHINode *> &PHIs) |
Return true if all users of the specified value will trap if the value is dynamically null. More... | |
static bool | AllUsesOfLoadedValueWillTrapIfNull (const GlobalVariable *GV) |
Return true if all uses of any loads from GV will trap if the loaded value is null. More... | |
static bool | OptimizeAwayTrappingUsesOfValue (Value *V, Constant *NewV) |
static bool | OptimizeAwayTrappingUsesOfLoads (GlobalVariable *GV, Constant *LV, const DataLayout &DL, TargetLibraryInfo *TLI) |
The specified global has only one non-null value stored into it. More... | |
static void | ConstantPropUsersOf (Value *V, const DataLayout &DL, TargetLibraryInfo *TLI) |
Walk the use list of V, constant folding all of the instructions that are foldable. More... | |
static GlobalVariable * | OptimizeGlobalAddressOfMalloc (GlobalVariable *GV, CallInst *CI, Type *AllocTy, ConstantInt *NElements, const DataLayout &DL, TargetLibraryInfo *TLI) |
This function takes the specified global variable, and transforms the program as if it always contained the result of the specified malloc. More... | |
static bool | ValueIsOnlyUsedLocallyOrStoredToOneGlobal (const Instruction *V, const GlobalVariable *GV, SmallPtrSetImpl< const PHINode *> &PHIs) |
Scan the use-list of V checking to make sure that there are no complex uses of V. More... | |
static void | ReplaceUsesOfMallocWithGlobal (Instruction *Alloc, GlobalVariable *GV) |
The Alloc pointer is stored into GV somewhere. More... | |
static bool | LoadUsesSimpleEnoughForHeapSRA (const Value *V, SmallPtrSetImpl< const PHINode *> &LoadUsingPHIs, SmallPtrSetImpl< const PHINode *> &LoadUsingPHIsPerLoad) |
Verify that all uses of V (a load, or a phi of a load) are simple enough to perform heap SRA on. More... | |
static bool | AllGlobalLoadUsesSimpleEnoughForHeapSRA (const GlobalVariable *GV, Instruction *StoredVal) |
If all users of values loaded from GV are simple enough to perform HeapSRA, return true. More... | |
static Value * | GetHeapSROAValue (Value *V, unsigned FieldNo, DenseMap< Value *, std::vector< Value *>> &InsertedScalarizedValues, std::vector< std::pair< PHINode *, unsigned >> &PHIsToRewrite) |
static void | RewriteHeapSROALoadUser (Instruction *LoadUser, DenseMap< Value *, std::vector< Value *>> &InsertedScalarizedValues, std::vector< std::pair< PHINode *, unsigned >> &PHIsToRewrite) |
Given a load instruction and a value derived from the load, rewrite the derived value to use the HeapSRoA'd load. More... | |
static void | RewriteUsesOfLoadForHeapSRoA (LoadInst *Load, DenseMap< Value *, std::vector< Value *>> &InsertedScalarizedValues, std::vector< std::pair< PHINode *, unsigned > > &PHIsToRewrite) |
We are performing Heap SRoA on a global. More... | |
static GlobalVariable * | PerformHeapAllocSRoA (GlobalVariable *GV, CallInst *CI, Value *NElems, const DataLayout &DL, const TargetLibraryInfo *TLI) |
CI is an allocation of an array of structures. More... | |
static bool | tryToOptimizeStoreOfMallocToGlobal (GlobalVariable *GV, CallInst *CI, Type *AllocTy, AtomicOrdering Ordering, const DataLayout &DL, TargetLibraryInfo *TLI) |
This function is called when we see a pointer global variable with a single value stored it that is a malloc or cast of malloc. More... | |
static bool | optimizeOnceStoredGlobal (GlobalVariable *GV, Value *StoredOnceVal, AtomicOrdering Ordering, const DataLayout &DL, TargetLibraryInfo *TLI) |
static bool | TryToShrinkGlobalToBoolean (GlobalVariable *GV, Constant *OtherVal) |
At this point, we have learned that the only two values ever stored into GV are its initializer and OtherVal. More... | |
static bool | deleteIfDead (GlobalValue &GV, SmallPtrSetImpl< const Comdat *> &NotDiscardableComdats) |
static bool | isPointerValueDeadOnEntryToFunction (const Function *F, GlobalValue *GV, function_ref< DominatorTree &(Function &)> LookupDomTree) |
static bool | allNonInstructionUsersCanBeMadeInstructions (Constant *C) |
C may have non-instruction users. More... | |
static void | makeAllConstantUsesInstructions (Constant *C) |
C may have non-instruction users, and allNonInstructionUsersCanBeMadeInstructions has returned true. More... | |
static bool | processInternalGlobal (GlobalVariable *GV, const GlobalStatus &GS, TargetLibraryInfo *TLI, function_ref< DominatorTree &(Function &)> LookupDomTree) |
Analyze the specified global variable and optimize it if possible. More... | |
static bool | processGlobal (GlobalValue &GV, TargetLibraryInfo *TLI, function_ref< DominatorTree &(Function &)> LookupDomTree) |
Analyze the specified global variable and optimize it if possible. More... | |
static void | ChangeCalleesToFastCall (Function *F) |
Walk all of the direct calls of the specified function, changing them to FastCC. More... | |
static AttributeList | StripNest (LLVMContext &C, AttributeList Attrs) |
static void | RemoveNestAttribute (Function *F) |
static bool | hasChangeableCC (Function *F) |
Return true if this is a calling convention that we'd like to change. More... | |
static bool | isColdCallSite (CallSite CS, BlockFrequencyInfo &CallerBFI) |
Return true if the block containing the call site has a BlockFrequency of less than ColdCCRelFreq% of the entry block. More... | |
static bool | isValidCandidateForColdCC (Function &F, function_ref< BlockFrequencyInfo &(Function &)> GetBFI, const std::vector< Function *> &AllCallsCold) |
static void | changeCallSitesToColdCC (Function *F) |
static bool | hasOnlyColdCalls (Function &F, function_ref< BlockFrequencyInfo &(Function &)> GetBFI) |
static bool | OptimizeFunctions (Module &M, TargetLibraryInfo *TLI, function_ref< TargetTransformInfo &(Function &)> GetTTI, function_ref< BlockFrequencyInfo &(Function &)> GetBFI, function_ref< DominatorTree &(Function &)> LookupDomTree, SmallPtrSetImpl< const Comdat *> &NotDiscardableComdats) |
static bool | OptimizeGlobalVars (Module &M, TargetLibraryInfo *TLI, function_ref< DominatorTree &(Function &)> LookupDomTree, SmallPtrSetImpl< const Comdat *> &NotDiscardableComdats) |
static Constant * | EvaluateStoreInto (Constant *Init, Constant *Val, ConstantExpr *Addr, unsigned OpNo) |
Evaluate a piece of a constantexpr store into a global initializer. More... | |
static void | CommitValueTo (Constant *Val, Constant *Addr) |
We have decided that Addr (which satisfies the predicate isSimpleEnoughPointerToCommit) should get Val as its value. More... | |
static void | BatchCommitValueTo (const DenseMap< Constant *, Constant *> &Mem) |
Given a map of address -> value, where addresses are expected to be some form of either a global or a constant GEP, set the initializer for the address to be the value. More... | |
static bool | EvaluateStaticConstructor (Function *F, const DataLayout &DL, TargetLibraryInfo *TLI) |
Evaluate static constructors in the function, if we can. More... | |
static int | compareNames (Constant *const *A, Constant *const *B) |
static void | setUsedInitializer (GlobalVariable &V, const SmallPtrSetImpl< GlobalValue *> &Init) |
static bool | hasUseOtherThanLLVMUsed (GlobalAlias &GA, const LLVMUsed &U) |
static bool | hasMoreThanOneUseOtherThanLLVMUsed (GlobalValue &V, const LLVMUsed &U) |
static bool | mayHaveOtherReferences (GlobalAlias &GA, const LLVMUsed &U) |
static bool | hasUsesToReplace (GlobalAlias &GA, const LLVMUsed &U, bool &RenameTarget) |
static bool | OptimizeGlobalAliases (Module &M, SmallPtrSetImpl< const Comdat *> &NotDiscardableComdats) |
static Function * | FindCXAAtExit (Module &M, TargetLibraryInfo *TLI) |
static bool | cxxDtorIsEmpty (const Function &Fn, SmallPtrSet< const Function *, 8 > &CalledFunctions) |
Returns whether the given function is an empty C++ destructor and can therefore be eliminated. More... | |
static bool | OptimizeEmptyGlobalCXXDtors (Function *CXAAtExitFn) |
static bool | optimizeGlobalsInModule (Module &M, const DataLayout &DL, TargetLibraryInfo *TLI, function_ref< TargetTransformInfo &(Function &)> GetTTI, function_ref< BlockFrequencyInfo &(Function &)> GetBFI, function_ref< DominatorTree &(Function &)> LookupDomTree) |
INITIALIZE_PASS_BEGIN (GlobalOptLegacyPass, "globalopt", "Global Variable Optimizer", false, false) INITIALIZE_PASS_END(GlobalOptLegacyPass | |
Variables | |
static cl::opt< bool > | EnableColdCCStressTest ("enable-coldcc-stress-test", cl::desc("Enable stress test of coldcc by adding " "calling conv to all internal functions."), cl::init(false), cl::Hidden) |
static cl::opt< int > | ColdCCRelFreq ("coldcc-rel-freq", cl::Hidden, cl::init(2), cl::ZeroOrMore, cl::desc("Maximum block frequency, expressed as a percentage of caller's " "entry frequency, for a call site to be considered cold for enabling" "coldcc")) |
globalopt | |
Global Variable | Optimizer |
Global Variable | false |
#define DEBUG_TYPE "globalopt" |
Definition at line 76 of file GlobalOpt.cpp.
|
static |
If all users of values loaded from GV are simple enough to perform HeapSRA, return true.
Definition at line 1103 of file GlobalOpt.cpp.
References llvm::SmallPtrSetImplBase::clear(), LoadUsesSimpleEnoughForHeapSRA(), op, and llvm::Value::users().
Referenced by tryToOptimizeStoreOfMallocToGlobal().
C may have non-instruction users.
Can all of those users be turned into instructions?
Definition at line 1848 of file GlobalOpt.cpp.
References llvm::Value::users().
Referenced by processInternalGlobal().
|
static |
Return true if all uses of any loads from GV will trap if the loaded value is null.
Note that this also permits comparisons of the loaded value against null, as a special case.
Definition at line 662 of file GlobalOpt.cpp.
References AllUsesOfValueWillTrapIfNull(), and llvm::Value::users().
Referenced by tryToOptimizeStoreOfMallocToGlobal().
|
static |
Return true if all users of the specified value will trap if the value is dynamically null.
PHIs keeps track of any phi nodes we've seen to avoid reprocessing them.
Definition at line 613 of file GlobalOpt.cpp.
References I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::NullPointerIsDefined(), SI, and llvm::Value::users().
Referenced by AllUsesOfLoadedValueWillTrapIfNull().
Given a map of address -> value, where addresses are expected to be some form of either a global or a constant GEP, set the initializer for the address to be the value.
This performs mostly the same function as CommitValueTo() and EvaluateStoreInto() but is optimized to be more efficient for the common case where the set of addresses are GEPs sharing the same underlying global, processing the GEPs in batches rather than individually.
To give an example, consider the following C++ code adapted from the clang regression tests: struct S { int n = 10; int m = 2 * n; S(int a) : n(a) {} };
template<typename T> struct U { T *r = T q = 42; U *p = this; };
U<S> e;
The global static constructor for 'e' will need to initialize 'r' and 'p' of the outer struct, while also initializing the inner 'q' structs 'n' and 'm' members. This batch algorithm will simply use general CommitValueTo() method to handle the complex nested S struct initialization of 'q', before processing the outermost members in a single batch. Using CommitValueTo() to handle member in the outer struct is inefficient when the struct/array is very large as we end up creating and destroy constant arrays for each initialization. For the above case, we expect the following IR to be generated:
struct.U = type { struct.S*, struct.S, struct.U* } struct.S = type { i32, i32 } = global struct.U { struct.S* gep inbounds (struct.U, struct.U* , i64 0, i32 1), struct.S { i32 42, i32 84 }, struct.U* } The struct.S { i32 42, i32 84 } inner initializer is treated as a complex constant expression, while the other two elements of are "simple".
Definition at line 2454 of file GlobalOpt.cpp.
References assert(), llvm::SmallVectorImpl< T >::clear(), CommitValueTo(), llvm::SmallVectorBase::empty(), GEP, llvm::ConstantArray::get(), llvm::ConstantStruct::get(), llvm::ConstantVector::get(), llvm::Constant::getAggregateElement(), llvm::GlobalVariable::getInitializer(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), I, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::GlobalVariable::setInitializer(), llvm::SmallVectorBase::size(), and llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::size().
Referenced by EvaluateStaticConstructor().
|
static |
Walk all of the direct calls of the specified function, changing them to FastCC.
Definition at line 2078 of file GlobalOpt.cpp.
References llvm::CallingConv::Fast, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setCallingConv(), and llvm::Value::users().
Referenced by OptimizeFunctions().
|
static |
Definition at line 2184 of file GlobalOpt.cpp.
References llvm::CallingConv::Cold, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setCallingConv(), and llvm::Value::users().
Referenced by OptimizeFunctions().
|
static |
We just marked GV constant.
Loop over all users of the global, cleaning up the obvious ones. This is largely just a quick scan over the use list to clean up the easy and obvious cruft. This returns true if it made a change.
Definition at line 274 of file GlobalOpt.cpp.
References C, llvm::ConstantFoldInstruction(), llvm::ConstantFoldLoadThroughGEPConstantExpr(), GEP, llvm::Constant::getNullValue(), llvm::ConstantExpr::getOpcode(), isSafeSROAElementUse(), llvm::isSafeToDestroyConstant(), MI, llvm::Value::replaceAllUsesWith(), SI, llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by OptimizeAwayTrappingUsesOfLoads(), and processInternalGlobal().
|
static |
This GV is a pointer root.
Loop over all users of the global and clean up any that obviously don't assign the global a value that isn't dynamically allocated.
Definition at line 188 of file GlobalOpt.cpp.
References C, llvm::SmallVectorImpl< T >::clear(), llvm::RegState::Dead, llvm::dyn_cast(), E, llvm::Instruction::eraseFromParent(), first, llvm::User::getOperand(), I, llvm::isAllocationFn(), llvm::GlobalVariable::isConstant(), IsSafeComputationToRemove(), llvm::isSafeToDestroyConstant(), llvm::SmallVectorTemplateBase< T >::push_back(), SI, llvm::SmallVectorBase::size(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by OptimizeAwayTrappingUsesOfLoads(), and processInternalGlobal().
We have decided that Addr (which satisfies the predicate isSimpleEnoughPointerToCommit) should get Val as its value.
Make it happen.
Definition at line 2401 of file GlobalOpt.cpp.
References assert(), EvaluateStoreInto(), and llvm::User::getOperand().
Referenced by BatchCommitValueTo().
Definition at line 2563 of file GlobalOpt.cpp.
References llvm::StringRef::compare(), llvm::Value::getName(), and llvm::Value::stripPointerCastsNoFollowAliases().
Referenced by setUsedInitializer().
|
static |
Walk the use list of V, constant folding all of the instructions that are foldable.
Definition at line 813 of file GlobalOpt.cpp.
References llvm::ConstantFoldInstruction(), E, I, llvm::isInstructionTriviallyDead(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by OptimizeGlobalAddressOfMalloc().
|
static |
Returns whether the given function is an empty C++ destructor and can therefore be eliminated.
Note that we assume that other optimization passes have already simplified the code so we only look for a function with a single basic block, where the only allowed instructions are 'ret', 'call' to an empty C++ dtor and other side-effect free instructions.
Definition at line 2814 of file GlobalOpt.cpp.
References llvm::BasicBlock::begin(), llvm::Function::begin(), E, llvm::BasicBlock::end(), llvm::Function::end(), llvm::Function::getEntryBlock(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), and llvm::GlobalValue::isDeclaration().
Referenced by OptimizeEmptyGlobalCXXDtors().
|
static |
Definition at line 1744 of file GlobalOpt.cpp.
References C, llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), llvm::RegState::Dead, llvm::GlobalValue::eraseFromParent(), F(), llvm::GlobalValue::getComdat(), llvm::GlobalValue::hasLocalLinkage(), llvm::GlobalValue::isDeclaration(), llvm::GlobalValue::isDiscardableIfUnused(), LLVM_DEBUG, llvm::Constant::removeDeadConstantUsers(), and llvm::Value::use_empty().
Referenced by OptimizeFunctions(), OptimizeGlobalAliases(), and OptimizeGlobalVars().
|
static |
Evaluate static constructors in the function, if we can.
Return true if we can, false otherwise.
Definition at line 2540 of file GlobalOpt.cpp.
References BatchCommitValueTo(), llvm::dbgs(), llvm::Evaluator::EvaluateFunction(), llvm::Evaluator::getInvariants(), llvm::Evaluator::getMutatedMemory(), llvm::Value::getName(), and LLVM_DEBUG.
Referenced by optimizeGlobalsInModule().
|
static |
Evaluate a piece of a constantexpr store into a global initializer.
This returns 'Init' modified to reflect 'Val' stored into it. At this point, the GEP operands of Addr [0, OpNo) have been stepped into.
Definition at line 2358 of file GlobalOpt.cpp.
References assert(), llvm::ConstantArray::get(), llvm::ConstantStruct::get(), llvm::ConstantVector::get(), llvm::Constant::getAggregateElement(), llvm::SequentialType::getNumElements(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), llvm::Type::isArrayTy(), and llvm::SmallVectorTemplateBase< T >::push_back().
Referenced by CommitValueTo().
|
static |
Definition at line 2792 of file GlobalOpt.cpp.
References llvm::Module::getFunction(), llvm::TargetLibraryInfo::getLibFunc(), llvm::TargetLibraryInfo::getName(), and llvm::TargetLibraryInfo::has().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 1149 of file GlobalOpt.cpp.
References llvm::PHINode::Create(), llvm::PointerType::get(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::Value::getType(), and llvm::ARM_MB::ST.
Referenced by PerformHeapAllocSRoA(), and RewriteHeapSROALoadUser().
|
static |
Look at all uses of the global and decide whether it is safe for us to perform this transformation.
Definition at line 418 of file GlobalOpt.cpp.
References isSafeSROAGEP(), and llvm::Value::users().
Referenced by SRAGlobal().
Return true if this is a calling convention that we'd like to change.
The idea here is that we don't want to mess with the convention if the user explicitly requested something with performance implications like coldcc, GHC, or anyregcc.
Definition at line 2109 of file GlobalOpt.cpp.
References llvm::CallingConv::C, llvm::dyn_cast(), llvm::Function::getAttributes(), llvm::Function::getCallingConv(), llvm::AttributeList::hasAttrSomewhere(), llvm::Attribute::InAlloca, llvm::CallInst::isMustTailCall(), llvm::Value::users(), and llvm::CallingConv::X86_ThisCall.
Referenced by hasOnlyColdCalls(), and OptimizeFunctions().
|
static |
Definition at line 2671 of file GlobalOpt.cpp.
References assert(), llvm::Value::hasNUsesOrMore(), and N.
Referenced by hasUsesToReplace().
|
static |
Definition at line 2197 of file GlobalOpt.cpp.
References llvm::Function::getIntrinsicID(), llvm::Function::hasAddressTaken(), hasChangeableCC(), llvm::GlobalValue::hasLocalLinkage(), I, isColdCallSite(), llvm::Function::isVarArg(), and llvm::Intrinsic::not_intrinsic.
Referenced by OptimizeFunctions().
|
static |
Definition at line 2655 of file GlobalOpt.cpp.
References assert(), llvm::Value::hasOneUse(), and llvm::Value::use_empty().
Referenced by hasUsesToReplace().
|
static |
Definition at line 2689 of file GlobalOpt.cpp.
References llvm::GlobalAlias::getAliasee(), llvm::GlobalValue::hasLocalLinkage(), hasMoreThanOneUseOtherThanLLVMUsed(), hasUseOtherThanLLVMUsed(), mayHaveOtherReferences(), llvm::MipsISD::Ret, and llvm::Constant::stripPointerCasts().
Referenced by OptimizeGlobalAliases().
INITIALIZE_PASS_BEGIN | ( | GlobalOptLegacyPass | , |
"globalopt" | , | ||
"Global Variable Optimizer" | , | ||
false | , | ||
false | |||
) |
Referenced by llvm::GlobalOptPass::run().
|
static |
Return true if the block containing the call site has a BlockFrequency of less than ColdCCRelFreq% of the entry block.
Definition at line 2147 of file GlobalOpt.cpp.
References ColdCCRelFreq, llvm::BlockFrequencyInfo::getBlockFreq(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCaller(), llvm::Function::getEntryBlock(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), and llvm::Instruction::getParent().
Referenced by hasOnlyColdCalls(), and isValidCandidateForColdCC().
|
static |
Is this global variable possibly used by a leak checker as a root? If so, we might not really want to eliminate the stores to it.
Definition at line 111 of file GlobalOpt.cpp.
References llvm::Type::ArrayTyID, E, llvm::StructType::element_begin(), llvm::StructType::element_end(), llvm::SmallVectorBase::empty(), llvm::SequentialType::getElementType(), llvm::Type::getTypeID(), llvm::GlobalValue::getValueType(), llvm::GlobalValue::hasPrivateLinkage(), I, llvm::StructType::isOpaque(), llvm::Type::PointerTyID, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::Type::StructTyID, and llvm::Type::VectorTyID.
Referenced by OptimizeAwayTrappingUsesOfLoads(), and processInternalGlobal().
|
static |
Definition at line 1769 of file GlobalOpt.cpp.
References assert(), llvm::dyn_cast(), F(), llvm::Module::getDataLayout(), llvm::Operator::getOpcode(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::Value::getType(), llvm::DataLayout::getTypeStoreSize(), llvm::StoreInst::getValueOperand(), I, llvm::none_of(), llvm::SmallVectorTemplateBase< T >::push_back(), SI, llvm::SmallVectorBase::size(), Threshold, and llvm::Value::users().
Referenced by processInternalGlobal().
|
static |
Given a value that is stored to a global but never read, determine whether it's safe to remove the store and the chain of computation that feeds the store.
Definition at line 159 of file GlobalOpt.cpp.
References GEP, llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Value::hasOneUse(), I, llvm::isAllocationFn(), and llvm::Instruction::mayHaveSideEffects().
Referenced by CleanupPointerRootUsers().
Return true if the specified instruction is a safe user of a derived expression from a global that we want to SROA.
Definition at line 397 of file GlobalOpt.cpp.
References C, llvm::dyn_cast(), I, isSafeSROAGEP(), llvm::isSafeToDestroyConstant(), and SI.
Referenced by CleanupConstantGlobalUsers(), and isSafeSROAGEP().
Return true if the specified GEP is a safe user of a derived expression from a global that we want to SROA.
Definition at line 364 of file GlobalOpt.cpp.
References llvm::all_of(), llvm::dyn_cast(), E, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::User::getNumOperands(), llvm::generic_gep_type_iterator< ItTy >::getOperand(), llvm::User::getOperand(), llvm::generic_gep_type_iterator< ItTy >::getSequentialNumElements(), llvm::ConstantInt::getZExtValue(), llvm::generic_gep_type_iterator< ItTy >::isBoundedSequential(), isSafeSROAElementUse(), llvm::generic_gep_type_iterator< ItTy >::isStruct(), and llvm::Value::users().
Referenced by GlobalUsersSafeToSRA(), and isSafeSROAElementUse().
|
static |
Definition at line 2161 of file GlobalOpt.cpp.
References llvm::find(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), isColdCallSite(), llvm::Value::user_empty(), and llvm::Value::users().
Referenced by OptimizeFunctions().
|
static |
Verify that all uses of V (a load, or a phi of a load) are simple enough to perform heap SRA on.
This permits GEP's that index through the array and struct field, icmps of null, and PHIs.
Definition at line 1052 of file GlobalOpt.cpp.
References llvm::SmallPtrSetImpl< PtrType >::insert(), and llvm::Value::users().
Referenced by AllGlobalLoadUsesSimpleEnoughForHeapSRA().
|
static |
C may have non-instruction users, and allNonInstructionUsersCanBeMadeInstructions has returned true.
Convert the non-instruction users to instructions.
Definition at line 1874 of file GlobalOpt.cpp.
References assert(), llvm::SmallVectorImpl< T >::clear(), llvm::Instruction::insertBefore(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::User::replaceUsesOfWith(), Users, and llvm::Value::users().
Referenced by processInternalGlobal().
|
static |
Definition at line 2682 of file GlobalOpt.cpp.
References llvm::GlobalValue::hasLocalLinkage().
Referenced by hasUsesToReplace(), and OptimizeGlobalAliases().
|
static |
The specified global has only one non-null value stored into it.
If there are uses of the loaded value that would trap if the loaded value is dynamically null, then we know that they cannot be reachable with a null optimize away the load.
Definition at line 748 of file GlobalOpt.cpp.
References assert(), CleanupConstantGlobalUsers(), CleanupPointerRootUsers(), llvm::dbgs(), E, llvm::GlobalVariable::eraseFromParent(), llvm::User::getOperand(), isLeakCheckerRoot(), LLVM_DEBUG, OptimizeAwayTrappingUsesOfValue(), llvm::Value::use_empty(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by optimizeOnceStoredGlobal().
Definition at line 678 of file GlobalOpt.cpp.
References llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_size(), C, E, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getArgument(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledValue(), llvm::ConstantExpr::getCast(), llvm::Instruction::getFunction(), llvm::ConstantExpr::getGetElementPtr(), llvm::Value::getType(), I, llvm::NullPointerIsDefined(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setArgument(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setCalledFunction(), SI, llvm::SmallVectorBase::size(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by OptimizeAwayTrappingUsesOfLoads().
Itanium C++ ABI p3.3.5:
After constructing a global (or local static) object, that will require destruction on exit, a termination function is registered as follows:
extern "C" int __cxa_atexit ( void (*f)(void *), void *p, void *d );
This registration, e.g. __cxa_atexit(f,p,d), is intended to cause the call f(p) when DSO d is unloaded, before all such termination calls registered before this one. It returns zero if registration is successful, nonzero on failure.
Definition at line 2854 of file GlobalOpt.cpp.
References cxxDtorIsEmpty(), llvm::dyn_cast(), E, llvm::Instruction::eraseFromParent(), llvm::CallBase::getArgOperand(), llvm::Constant::getNullValue(), llvm::Value::getType(), I, llvm::Value::replaceAllUsesWith(), llvm::Value::stripPointerCasts(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 2228 of file GlobalOpt.cpp.
References llvm::Module::begin(), ChangeCalleesToFastCall(), changeCallSitesToColdCC(), llvm::CallingConv::Cold, deleteIfDead(), E, EnableColdCCStressTest, llvm::Module::end(), llvm::CallingConv::Fast, llvm::Function::getAttributes(), llvm::Function::hasAddressTaken(), llvm::AttributeList::hasAttrSomewhere(), hasChangeableCC(), llvm::Function::hasFnAttribute(), llvm::GlobalValue::hasLocalLinkage(), llvm::Value::hasName(), hasOnlyColdCalls(), llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::isDeclaration(), isValidCandidateForColdCC(), llvm::Function::isVarArg(), llvm::Attribute::Naked, llvm::Attribute::Nest, processGlobal(), RemoveNestAttribute(), llvm::removeUnreachableBlocks(), llvm::Function::setCallingConv(), llvm::GlobalValue::setLinkage(), and llvm::TargetTransformInfo::useColdCCForColdCall().
Referenced by optimizeGlobalsInModule().
|
static |
This function takes the specified global variable, and transforms the program as if it always contained the result of the specified malloc.
Because it is always the result of the specified malloc, there is no reason to actually DO the malloc. Instead, turn the malloc into a global, and any loads of GV as uses of the new global.
Definition at line 835 of file GlobalOpt.cpp.
References ConstantPropUsersOf(), llvm::BinaryOperator::CreateNot(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::GlobalVariable::eraseFromParent(), llvm::errs(), llvm::ArrayType::get(), llvm::UndefValue::get(), llvm::ConstantExpr::getBitCast(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), llvm::Module::getGlobalList(), llvm::Type::getInt1Ty(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::LoadInst::getOrdering(), llvm::GlobalValue::getParent(), llvm::CmpInst::getPredicate(), llvm::LoadInst::getSyncScopeID(), llvm::GlobalValue::getThreadLocalMode(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::Use::getUser(), llvm::GlobalValue::getValueType(), llvm::ConstantInt::getZExtValue(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::iplist_impl< IntrusiveListT, TraitsT >::insert(), llvm::GlobalValue::InternalLinkage, llvm::LoadInst::isUnordered(), LLVM_DEBUG, llvm_unreachable, llvm::Value::replaceAllUsesWith(), llvm::User::replaceUsesOfWith(), SI, llvm::Value::use_begin(), llvm::Value::use_empty(), llvm::Instruction::user_back(), and llvm::Value::user_back().
Referenced by tryToOptimizeStoreOfMallocToGlobal().
|
static |
Definition at line 2722 of file GlobalOpt.cpp.
References llvm::Module::alias_begin(), llvm::Module::alias_end(), deleteIfDead(), llvm::dyn_cast(), E, llvm::iplist_impl< IntrusiveListT, TraitsT >::erase(), llvm::GlobalAlias::getAliasee(), llvm::Module::getAliasList(), llvm::ConstantExpr::getBitCast(), llvm::GlobalValue::getDLLStorageClass(), llvm::GlobalValue::getLinkage(), llvm::GlobalValue::getType(), llvm::GlobalValue::getVisibility(), llvm::GlobalValue::hasLocalLinkage(), llvm::Value::hasName(), hasUsesToReplace(), I, llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::isDeclaration(), llvm::GlobalValue::isDSOLocal(), llvm::GlobalValue::isInterposable(), mayHaveOtherReferences(), llvm::Constant::removeDeadConstantUsers(), llvm::Value::replaceAllUsesWith(), llvm::GlobalValue::setDLLStorageClass(), llvm::GlobalValue::setDSOLocal(), llvm::GlobalValue::setLinkage(), llvm::GlobalValue::setVisibility(), llvm::Constant::stripPointerCasts(), and llvm::Value::takeName().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 2901 of file GlobalOpt.cpp.
References C, llvm::SmallPtrSetImplBase::clear(), EvaluateStaticConstructor(), FindCXAAtExit(), llvm::GlobalObject::getComdat(), llvm::GlobalValue::getComdat(), llvm::Module::globals(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Function::isDefTriviallyDead(), llvm::GlobalValue::isDiscardableIfUnused(), OptimizeEmptyGlobalCXXDtors(), OptimizeFunctions(), OptimizeGlobalAliases(), llvm::optimizeGlobalCtorsList(), OptimizeGlobalVars(), and llvm::Value::use_empty().
Referenced by llvm::GlobalOptPass::run().
|
static |
Definition at line 2325 of file GlobalOpt.cpp.
References C, llvm::ConstantFoldConstant(), deleteIfDead(), E, llvm::Module::getDataLayout(), llvm::GlobalVariable::getInitializer(), llvm::Module::global_begin(), llvm::Module::global_end(), llvm::GlobalVariable::hasInitializer(), llvm::GlobalValue::hasLocalLinkage(), llvm::Value::hasName(), llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::isDeclaration(), processGlobal(), llvm::GlobalVariable::setInitializer(), and llvm::GlobalValue::setLinkage().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 1561 of file GlobalOpt.cpp.
References llvm::extractMallocCall(), llvm::ConstantExpr::getBitCast(), llvm::GlobalVariable::getInitializer(), llvm::getMallocAllocatedType(), llvm::Type::getPointerAddressSpace(), llvm::Value::getType(), llvm::Constant::isNullValue(), llvm::Type::isPointerTy(), llvm::NullPointerIsDefined(), OptimizeAwayTrappingUsesOfLoads(), llvm::Value::stripPointerCasts(), and tryToOptimizeStoreOfMallocToGlobal().
Referenced by processInternalGlobal().
|
static |
CI is an allocation of an array of structures.
Break it up into multiple allocations of arrays of the fields.
As we process loads, if we can't immediately update all uses of the load, keep track of what scalarized loads are inserted for a given load.
Definition at line 1272 of file GlobalOpt.cpp.
References llvm::PHINode::addIncoming(), assert(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::begin(), llvm::GlobalVariable::copyAttributesFrom(), llvm::BasicBlock::Create(), llvm::BranchInst::Create(), llvm::CallInst::CreateFree(), llvm::CallInst::CreateMalloc(), llvm::dbgs(), E, llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::Instruction::eraseFromParent(), llvm::GlobalVariable::eraseFromParent(), llvm::ConstantInt::get(), llvm::PointerType::get(), llvm::CallBase::getArgOperand(), llvm::BasicBlock::getContext(), llvm::Value::getContext(), llvm::StructType::getElementType(), GetHeapSROAValue(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::DataLayout::getIntPtrType(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::getMallocAllocatedType(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::StructType::getNumElements(), llvm::PHINode::getNumIncomingValues(), llvm::User::getOperand(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::Type::getPointerAddressSpace(), llvm::StructLayout::getSizeInBytes(), llvm::DataLayout::getStructLayout(), llvm::BasicBlock::getTerminator(), llvm::GlobalValue::getThreadLocalMode(), getType(), llvm::Value::getType(), llvm::GlobalValue::getType(), llvm::DataLayout::getTypeAllocSize(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SLT, llvm::GlobalValue::InternalLinkage, LLVM_DEBUG, ReplaceUsesOfMallocWithGlobal(), RewriteUsesOfLoadForHeapSRoA(), SI, llvm::BasicBlock::splitBasicBlock(), llvm::ARM_MB::ST, llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by tryToOptimizeStoreOfMallocToGlobal().
|
static |
Analyze the specified global variable and optimize it if possible.
If we make a change, return true.
Definition at line 2041 of file GlobalOpt.cpp.
References llvm::GlobalStatus::analyzeGlobal(), llvm::dyn_cast(), llvm::Value::getName(), llvm::GlobalValue::getUnnamedAddr(), llvm::GlobalValue::Global, llvm::GlobalValue::hasGlobalUnnamedAddr(), llvm::GlobalValue::hasLocalLinkage(), llvm::GlobalStatus::IsCompared, llvm::GlobalValue::Local, processInternalGlobal(), llvm::GlobalValue::setUnnamedAddr(), and llvm::StringRef::startswith().
Referenced by OptimizeFunctions(), and OptimizeGlobalVars().
|
static |
Analyze the specified global variable and optimize it if possible.
If we make a change, return true.
Definition at line 1906 of file GlobalOpt.cpp.
References llvm::GlobalStatus::AccessingFunction, allNonInstructionUsersCanBeMadeInstructions(), llvm::BasicBlock::begin(), CleanupConstantGlobalUsers(), CleanupPointerRootUsers(), llvm::dbgs(), llvm::Function::doesNotRecurse(), llvm::GlobalVariable::eraseFromParent(), llvm::PointerType::getAddressSpace(), llvm::DataLayout::getAllocaAddrSpace(), llvm::Module::getDataLayout(), llvm::Function::getEntryBlock(), llvm::GlobalVariable::getInitializer(), llvm::Value::getName(), llvm::GlobalValue::getParent(), llvm::Value::getType(), llvm::GlobalValue::getType(), llvm::GlobalValue::getValueType(), llvm::GlobalStatus::HasMultipleAccessingFunctions, llvm::GlobalStatus::InitializerStored, llvm::GlobalVariable::isExternallyInitialized(), isLeakCheckerRoot(), llvm::GlobalStatus::IsLoaded, isPointerValueDeadOnEntryToFunction(), llvm::Type::isSingleValueType(), LLVM_DEBUG, makeAllConstantUsesInstructions(), llvm::NotAtomic, optimizeOnceStoredGlobal(), llvm::GlobalStatus::Ordering, llvm::Value::replaceAllUsesWith(), llvm::GlobalVariable::setConstant(), llvm::GlobalVariable::setInitializer(), SRAGlobal(), llvm::GlobalStatus::StoredOnce, llvm::GlobalStatus::StoredOnceValue, TryToShrinkGlobalToBoolean(), and llvm::Value::use_empty().
Referenced by processGlobal().
|
static |
Definition at line 2095 of file GlobalOpt.cpp.
References llvm::Function::getAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getAttributes(), llvm::Function::getContext(), llvm::Function::setAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setAttributes(), StripNest(), and llvm::Value::users().
Referenced by OptimizeFunctions().
|
static |
The Alloc pointer is stored into GV somewhere.
Transform all uses of the allocation into loads from the global and uses of the resultant pointer. Further, delete the store into GV. This assumes that these value pass the 'ValueIsOnlyUsedLocallyOrStoredToOneGlobal' predicate.
Definition at line 1009 of file GlobalOpt.cpp.
Referenced by PerformHeapAllocSRoA().
|
static |
Given a load instruction and a value derived from the load, rewrite the derived value to use the HeapSRoA'd load.
Definition at line 1193 of file GlobalOpt.cpp.
References assert(), llvm::GetElementPtrInst::Create(), E, GetHeapSROAValue(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by RewriteUsesOfLoadForHeapSRoA().
|
static |
We are performing Heap SRoA on a global.
Ptr is a value loaded from the global. Eliminate all uses of Ptr, making them use FieldGlobals instead. All uses of loaded values satisfy AllGlobalLoadUsesSimpleEnoughForHeapSRA.
Definition at line 1256 of file GlobalOpt.cpp.
References E, llvm::iplist_impl< IntrusiveListT, TraitsT >::erase(), llvm::Instruction::eraseFromParent(), RewriteHeapSROALoadUser(), llvm::Value::use_empty(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by PerformHeapAllocSRoA().
|
static |
Definition at line 2569 of file GlobalOpt.cpp.
References llvm::GlobalValue::AppendingLinkage, llvm::array_pod_sort(), llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::collectUsedGlobalVariables(), compareNames(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::SmallPtrSetImplBase::empty(), llvm::SmallPtrSetImpl< PtrType >::end(), llvm::SmallPtrSetImpl< PtrType >::erase(), llvm::GlobalVariable::eraseFromParent(), llvm::ArrayType::get(), llvm::ConstantArray::get(), llvm::Value::getContext(), llvm::Type::getInt8PtrTy(), llvm::GlobalValue::getParent(), llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::GlobalVariable::removeFromParent(), llvm::GlobalObject::setSection(), and llvm::Value::takeName().
|
static |
Perform scalar replacement of aggregates on the specified global variable.
This opens the door for other optimizations by exposing the behavior of the program in a more fine-grained way. We have determined that this transformation is safe already. We return the first global variable we insert so that the caller can reprocess it.
Definition at line 461 of file GlobalOpt.cpp.
References assert(), llvm::GlobalVariable::copyAttributesFrom(), llvm::GetElementPtrInst::Create(), llvm::dbgs(), llvm::iplist_impl< IntrusiveListT, TraitsT >::erase(), GEP, llvm::DataLayout::getABITypeAlignment(), llvm::PointerType::getAddressSpace(), llvm::GlobalObject::getAlignment(), llvm::Value::getContext(), llvm::StructLayout::getElementOffset(), llvm::StructLayout::getElementOffsetInBits(), llvm::ConstantExpr::getGetElementPtr(), llvm::Module::getGlobalList(), llvm::GlobalVariable::getInitializer(), llvm::Type::getInt32Ty(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::User::getNumOperands(), getOpcode(), llvm::User::getOperand(), llvm::GlobalValue::getParent(), llvm::DataLayout::getStructLayout(), llvm::GlobalValue::getThreadLocalMode(), llvm::GlobalValue::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::DataLayout::getTypeAllocSizeInBits(), llvm::GlobalValue::getValueType(), GlobalUsersSafeToSRA(), llvm::GlobalValue::hasLocalLinkage(), llvm::Value::hasNUsesOrMore(), llvm::tgtok::In, llvm::GlobalValue::InternalLinkage, llvm::GlobalVariable::isExternallyInitialized(), LLVM_DEBUG, llvm::MinAlign(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::iplist_impl< IntrusiveListT, TraitsT >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::GlobalObject::setAlignment(), llvm::GlobalVariable::setExternallyInitialized(), Size, transferSRADebugInfo(), llvm::Value::use_empty(), and llvm::Value::user_back().
Referenced by processInternalGlobal().
STATISTIC | ( | NumMarked | , |
"Number of globals marked constant" | |||
) |
STATISTIC | ( | NumUnnamed | , |
"Number of globals marked unnamed_addr" | |||
) |
STATISTIC | ( | NumHeapSRA | , |
"Number of heap objects SRA'd" | |||
) |
STATISTIC | ( | NumSubstitute | , |
"Number of globals with initializers stored into them" | |||
) |
STATISTIC | ( | NumDeleted | , |
"Number of globals deleted" | |||
) |
STATISTIC | ( | NumGlobUses | , |
"Number of global uses devirtualized" | |||
) |
STATISTIC | ( | NumLocalized | , |
"Number of globals localized" | |||
) |
STATISTIC | ( | NumShrunkToBool | , |
"Number of global vars shrunk to booleans" | |||
) |
STATISTIC | ( | NumFastCallFns | , |
"Number of functions converted to fastcc" | |||
) |
STATISTIC | ( | NumCtorsEvaluated | , |
"Number of static ctors evaluated" | |||
) |
STATISTIC | ( | NumNestRemoved | , |
"Number of nest attributes removed" | |||
) |
STATISTIC | ( | NumAliasesResolved | , |
"Number of global aliases resolved" | |||
) |
STATISTIC | ( | NumAliasesRemoved | , |
"Number of global aliases eliminated" | |||
) |
STATISTIC | ( | NumCXXDtorsRemoved | , |
"Number of global C++ destructors removed" | |||
) |
STATISTIC | ( | NumInternalFunc | , |
"Number of internal functions" | |||
) |
STATISTIC | ( | NumColdCC | , |
"Number of functions marked coldcc" | |||
) |
|
static |
Definition at line 2087 of file GlobalOpt.cpp.
References llvm::AMDGPU::HSAMD::Kernel::Key::Attrs, llvm::AttributeList::hasAttrSomewhere(), llvm::Attribute::Nest, and llvm::AttributeList::removeAttribute().
Referenced by RemoveNestAttribute().
|
static |
Copy over the debug info for a variable to its SRA replacements.
Definition at line 435 of file GlobalOpt.cpp.
References llvm::GlobalVariable::addDebugInfo(), llvm::DIExpression::createFragmentExpression(), E, llvm::MDNode::get(), and llvm::GlobalVariable::getDebugInfo().
Referenced by SRAGlobal().
|
static |
This function is called when we see a pointer global variable with a single value stored it that is a malloc or cast of malloc.
Definition at line 1463 of file GlobalOpt.cpp.
References AllGlobalLoadUsesSimpleEnoughForHeapSRA(), AllUsesOfLoadedValueWillTrapIfNull(), llvm::CallInst::CreateMalloc(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::CallBase::getArgOperand(), llvm::DataLayout::getIntPtrType(), llvm::getMallocAllocatedType(), llvm::getMallocArraySize(), llvm::Value::getName(), llvm::StructType::getNumElements(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::StructLayout::getSizeInBytes(), llvm::DataLayout::getStructLayout(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::Type::isSized(), llvm::NotAtomic, OptimizeGlobalAddressOfMalloc(), PerformHeapAllocSRoA(), llvm::Value::replaceAllUsesWith(), and ValueIsOnlyUsedLocallyOrStoredToOneGlobal().
Referenced by optimizeOnceStoredGlobal().
|
static |
At this point, we have learned that the only two values ever stored into GV are its initializer and OtherVal.
See if we can shrink the global into a boolean and select between the two values whenever it is used. This exposes the values to other scalar optimizations.
Definition at line 1599 of file GlobalOpt.cpp.
References llvm::GlobalVariable::addDebugInfo(), assert(), llvm::GlobalVariable::copyAttributesFrom(), llvm::SelectInst::Create(), llvm::dbgs(), E, llvm::Instruction::eraseFromParent(), llvm::GlobalVariable::eraseFromParent(), llvm::ConstantInt::get(), llvm::MDNode::get(), llvm::PointerType::getAddressSpace(), llvm::Value::getContext(), llvm::GlobalVariable::getDebugInfo(), llvm::Instruction::getDebugLoc(), llvm::ConstantInt::getFalse(), llvm::Module::getGlobalList(), llvm::GlobalVariable::getInitializer(), llvm::Type::getInt1Ty(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::User::getOperand(), llvm::LoadInst::getOrdering(), llvm::GlobalValue::getParent(), llvm::LoadInst::getSyncScopeID(), llvm::GlobalValue::getThreadLocalMode(), llvm::Value::getType(), llvm::GlobalValue::getType(), llvm::GlobalValue::getValueType(), llvm::iplist_impl< IntrusiveListT, TraitsT >::insert(), llvm::GlobalValue::InternalLinkage, llvm::Type::isFloatingPointTy(), llvm::Constant::isNullValue(), llvm::Type::isPointerTy(), llvm::Type::isVectorTy(), LLVM_DEBUG, llvm::DIExpression::prependOpcodes(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setDebugLoc(), SI, llvm::Value::takeName(), llvm::Value::use_empty(), llvm::Value::user_back(), llvm::Value::users(), and llvm::DIExpression::WithStackValue.
Referenced by processInternalGlobal().
|
static |
Scan the use-list of V checking to make sure that there are no complex uses of V.
We permit simple things like dereferencing the pointer, but not storing through the address, unless it is to the specified global.
Definition at line 962 of file GlobalOpt.cpp.
References llvm::User::getNumOperands(), llvm::SmallPtrSetImpl< PtrType >::insert(), SI, and llvm::Value::users().
Referenced by tryToOptimizeStoreOfMallocToGlobal().
|
static |
Referenced by isColdCallSite().
|
static |
Referenced by OptimizeFunctions().
Global Variable false |
Definition at line 3025 of file GlobalOpt.cpp.
globalopt |
Definition at line 3025 of file GlobalOpt.cpp.
Global Variable Optimizer |
Definition at line 3025 of file GlobalOpt.cpp.