|
LLVM 24.0.0git
|
#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/Analysis/ValueTracking.h"#include "llvm/BinaryFormat/Dwarf.h"#include "llvm/IR/Attributes.h"#include "llvm/IR/BasicBlock.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/GlobalAlias.h"#include "llvm/IR/GlobalValue.h"#include "llvm/IR/GlobalVariable.h"#include "llvm/IR/IRBuilder.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/ProfDataUtils.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/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/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 "llvm/Transforms/Utils/Local.h"#include <cassert>#include <cstdint>#include <optional>#include <utility>#include <vector>Go to the source code of this file.
Classes | |
| struct | GlobalPart |
| Part of the global at a specific offset, which is only accessed through loads and stores with the given type. More... | |
Macros | |
| #define | DEBUG_TYPE "globalopt" |
Typedefs | |
| using | ChangeableCCCacheTy = SmallDenseMap<Function *, bool, 8> |
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 (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 (NumAtExitRemoved, "Number of atexit handlers removed") | |
| STATISTIC (NumInternalFunc, "Number of internal functions") | |
| STATISTIC (NumColdCC, "Number of functions marked coldcc") | |
| STATISTIC (NumIFuncsResolved, "Number of statically resolved IFuncs") | |
| STATISTIC (NumIFuncsDeleted, "Number of IFuncs removed") | |
| static bool | isLeakCheckerRoot (GlobalVariable *GV) |
| Is this global variable possibly used by a leak checker as a root? | |
| static bool | IsSafeComputationToRemove (Value *V, function_ref< TargetLibraryInfo &(Function &)> GetTLI) |
| 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. | |
| static bool | CleanupPointerRootUsers (GlobalVariable *GV, function_ref< TargetLibraryInfo &(Function &)> GetTLI) |
| This GV is a pointer root. | |
| static bool | CleanupConstantGlobalUsers (GlobalVariable *GV, const DataLayout &DL) |
| We just marked GV constant. | |
| static bool | collectSRATypes (DenseMap< uint64_t, GlobalPart > &Parts, GlobalVariable *GV, const DataLayout &DL) |
| Look at all uses of the global and determine which (offset, type) pairs it can be split into. | |
| static void | transferSRADebugInfo (GlobalVariable *GV, GlobalVariable *NGV, uint64_t FragmentOffsetInBits, uint64_t FragmentSizeInBits, uint64_t VarSize) |
| Copy over the debug info for a variable to its SRA replacements. | |
| static GlobalVariable * | SRAGlobal (GlobalVariable *GV, const DataLayout &DL) |
| Perform scalar replacement of aggregates on the specified global variable. | |
| static bool | OptimizeAwayTrappingUsesOfValue (Instruction *V, Constant *NewV) |
| static bool | OptimizeAwayTrappingUsesOfLoads (GlobalVariable *GV, Constant *LV, const DataLayout &DL, function_ref< TargetLibraryInfo &(Function &)> GetTLI) |
| The specified global has only one non-null value stored into it. | |
| static bool | optimizeOnceStoredGlobal (GlobalVariable *GV, Value *StoredOnceVal, const DataLayout &DL, function_ref< TargetLibraryInfo &(Function &)> GetTLI) |
| 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. | |
| static bool | deleteIfDead (GlobalValue &GV, SmallPtrSetImpl< const Comdat * > &NotDiscardableComdats, function_ref< void(Function &)> DeleteFnCallback=nullptr) |
| static bool | isPointerValueDeadOnEntryToFunction (const Function *F, GlobalValue *GV, function_ref< DominatorTree &(Function &)> LookupDomTree) |
| static bool | forwardStoredOnceStore (GlobalVariable *GV, const StoreInst *StoredOnceStore, function_ref< DominatorTree &(Function &)> LookupDomTree) |
| static bool | processInternalGlobal (GlobalVariable *GV, const GlobalStatus &GS, function_ref< TargetTransformInfo &(Function &)> GetTTI, function_ref< TargetLibraryInfo &(Function &)> GetTLI, function_ref< DominatorTree &(Function &)> LookupDomTree) |
| Analyze the specified global variable and optimize it if possible. | |
| static bool | processGlobal (GlobalValue &GV, function_ref< TargetTransformInfo &(Function &)> GetTTI, function_ref< TargetLibraryInfo &(Function &)> GetTLI, function_ref< DominatorTree &(Function &)> LookupDomTree) |
| Analyze the specified global variable and optimize it if possible. | |
| static void | ChangeCalleesToFastCall (Function *F) |
| Walk all of the direct calls of the specified function, changing them to FastCC. | |
| static AttributeList | StripAttr (LLVMContext &C, AttributeList Attrs, Attribute::AttrKind A) |
| static void | RemoveAttribute (Function *F, Attribute::AttrKind A) |
| static bool | hasChangeableCCImpl (Function *F) |
| Return true if this is a calling convention that we'd like to change. | |
| static bool | hasChangeableCC (Function *F, ChangeableCCCacheTy &ChangeableCCCache) |
| static bool | isColdCallSite (CallBase &CB, BlockFrequencyInfo &CallerBFI) |
| Return true if the block containing the call site has a BlockFrequency of less than ColdCCRelFreq% of the entry block. | |
| static bool | isValidCandidateForColdCC (Function &F, function_ref< BlockFrequencyInfo &(Function &)> GetBFI, function_ref< bool(Function &)> HasOnlyColdCalls) |
| static void | changeCallSitesToColdCC (Function *F) |
| static bool | hasOnlyColdCalls (Function &F, function_ref< BlockFrequencyInfo &(Function &)> GetBFI, ChangeableCCCacheTy &ChangeableCCCache) |
| static bool | hasMustTailCallers (Function *F) |
| static bool | hasInvokeCallers (Function *F) |
| static void | RemovePreallocated (Function *F) |
| static bool | OptimizeFunctions (Module &M, function_ref< TargetLibraryInfo &(Function &)> GetTLI, function_ref< TargetTransformInfo &(Function &)> GetTTI, function_ref< BlockFrequencyInfo &(Function &)> GetBFI, function_ref< DominatorTree &(Function &)> LookupDomTree, SmallPtrSetImpl< const Comdat * > &NotDiscardableComdats, function_ref< void(Function &F)> ChangedCFGCallback, function_ref< void(Function &F)> DeleteFnCallback) |
| static bool | OptimizeGlobalVars (Module &M, function_ref< TargetTransformInfo &(Function &)> GetTTI, function_ref< TargetLibraryInfo &(Function &)> GetTLI, function_ref< DominatorTree &(Function &)> LookupDomTree, SmallPtrSetImpl< const Comdat * > &NotDiscardableComdats) |
| static bool | EvaluateStaticConstructor (Function *F, const DataLayout &DL, TargetLibraryInfo *TLI) |
| Evaluate static constructors in the function, if we can. | |
| 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 | mayHaveOtherReferences (GlobalValue &GV, const LLVMUsed &U) |
| static bool | hasUsesToReplace (GlobalAlias &GA, const LLVMUsed &U, bool &RenameTarget) |
| static bool | OptimizeGlobalAliases (Module &M, SmallPtrSetImpl< const Comdat * > &NotDiscardableComdats) |
| static Function * | FindAtExitLibFunc (Module &M, function_ref< TargetLibraryInfo &(Function &)> GetTLI, LibFunc Func) |
| static bool | IsEmptyAtExitFunction (const Function &Fn) |
| Returns whether the given function is an empty C++ destructor or atexit handler and can therefore be eliminated. | |
| static bool | OptimizeEmptyGlobalAtExitDtors (Function *CXAAtExitFn, bool isCXX) |
| static Function * | hasSideeffectFreeStaticResolution (GlobalIFunc &IF) |
| static bool | OptimizeStaticIFuncs (Module &M) |
| Find IFuncs that have resolvers that always point at the same statically known callee, and replace their callers with a direct call. | |
| static bool | DeleteDeadIFuncs (Module &M, SmallPtrSetImpl< const Comdat * > &NotDiscardableComdats) |
| static bool | collectVersions (Value *V, SmallVectorImpl< Function * > &Versions, function_ref< TargetTransformInfo &(Function &)> GetTTI) |
| static bool | OptimizeNonTrivialIFuncs (Module &M, function_ref< TargetTransformInfo &(Function &)> GetTTI) |
| static bool | optimizeGlobalsInModule (Module &M, const DataLayout &DL, function_ref< TargetLibraryInfo &(Function &)> GetTLI, function_ref< TargetTransformInfo &(Function &)> GetTTI, function_ref< BlockFrequencyInfo &(Function &)> GetBFI, function_ref< DominatorTree &(Function &)> LookupDomTree, function_ref< void(Function &F)> ChangedCFGCallback, function_ref< void(Function &F)> DeleteFnCallback) |
Variables | |
| static cl::opt< bool > | OptimizeNonFMVCallers ("optimize-non-fmv-callers", cl::desc("Statically resolve calls to versioned " "functions from non-versioned callers."), cl::init(true), cl::Hidden) |
| static cl::opt< unsigned > | MaxIFuncVersions ("max-ifunc-versions", cl::Hidden, cl::init(5), cl::desc("Maximum number of caller/callee versions that is allowed for " "using the expensive (cubic) static resolution algorithm.")) |
| 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::desc("Maximum block frequency, expressed as a percentage of caller's " "entry frequency, for a call site to be considered cold for enabling " "coldcc")) |
| #define DEBUG_TYPE "globalopt" |
Definition at line 75 of file GlobalOpt.cpp.
| using ChangeableCCCacheTy = SmallDenseMap<Function *, bool, 8> |
Definition at line 1393 of file GlobalOpt.cpp.
|
static |
Walk all of the direct calls of the specified function, changing them to FastCC.
Definition at line 1333 of file GlobalOpt.cpp.
References Call, llvm::dyn_cast(), F, and llvm::CallingConv::Fast.
Referenced by OptimizeFunctions().
|
static |
Definition at line 1439 of file GlobalOpt.cpp.
References Call, llvm::CallingConv::Cold, llvm::dyn_cast(), and F.
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 282 of file GlobalOpt.cpp.
References llvm::append_range(), Changed, llvm::ConstantFoldLoadFromConst(), llvm::ConstantFoldLoadFromUniformValue(), DL, llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), GEP, llvm::GlobalVariable::getInitializer(), llvm::Value::getType(), llvm::getUnderlyingObject(), I, II, llvm::SmallPtrSetImpl< PtrType >::insert(), MI, llvm::Offset, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::RecursivelyDeleteTriviallyDeadInstructionsPermissive(), llvm::Constant::removeDeadConstantUsers(), llvm::Value::stripAndAccumulateConstantOffsets(), and llvm::Value::users().
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 204 of file GlobalOpt.cpp.
References llvm::append_range(), Changed, llvm::Dead, llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), I, llvm::isa(), llvm::isAllocationFn(), llvm::GlobalVariable::isConstant(), IsSafeComputationToRemove(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::Constant::removeDeadConstantUsers(), llvm::Store, and llvm::Value::users().
Referenced by OptimizeAwayTrappingUsesOfLoads(), and processInternalGlobal().
|
static |
Look at all uses of the global and determine which (offset, type) pairs it can be split into.
Definition at line 361 of file GlobalOpt.cpp.
References C(), llvm::ConstantFoldLoadFromConst(), llvm::dbgs(), DL, llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), GEP, llvm::GlobalVariable::getInitializer(), llvm::getLoadStorePointerOperand(), llvm::getLoadStoreType(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::isa(), llvm::isSafeToDestroyConstant(), LLVM_DEBUG, llvm::Offset, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace(), and llvm::Value::uses().
Referenced by SRAGlobal().
|
static |
Definition at line 2155 of file GlobalOpt.cpp.
References collectVersions(), llvm::dyn_cast(), E(), F, I, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by collectVersions(), and OptimizeNonTrivialIFuncs().
Definition at line 1768 of file GlobalOpt.cpp.
References A(), B(), llvm::StringRef::compare(), llvm::Value::getName(), and llvm::Value::stripPointerCasts().
Referenced by setUsedInitializer().
|
static |
Definition at line 2140 of file GlobalOpt.cpp.
References Changed, deleteIfDead(), and llvm::make_early_inc_range().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 971 of file GlobalOpt.cpp.
References C(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), llvm::Dead, llvm::dyn_cast(), llvm::GlobalValue::eraseFromParent(), F, llvm::GlobalValue::getComdat(), llvm::GlobalValue::hasLocalLinkage(), llvm::GlobalValue::isDeclaration(), llvm::GlobalValue::isDiscardableIfUnused(), LLVM_DEBUG, llvm::Constant::removeDeadConstantUsers(), llvm::ReplaceableUses::SalvageDebugInfo(), and llvm::Value::use_empty().
Referenced by DeleteDeadIFuncs(), OptimizeFunctions(), OptimizeGlobalAliases(), and OptimizeGlobalVars().
|
static |
Evaluate static constructors in the function, if we can.
Return true if we can, false otherwise.
Definition at line 1740 of file GlobalOpt.cpp.
References llvm::dbgs(), DL, llvm::Evaluator::EvaluateFunction(), F, llvm::Evaluator::getInvariants(), llvm::Evaluator::getMutatedInitializers(), and LLVM_DEBUG.
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 2004 of file GlobalOpt.cpp.
References llvm::Function::begin(), and llvm::Function::getFunction().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 1071 of file GlobalOpt.cpp.
References llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), F, llvm::Instruction::getFunction(), llvm::Value::getType(), llvm::StoreInst::getValueOperand(), llvm::isa(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::Value::users().
Referenced by processInternalGlobal().
|
static |
Definition at line 1394 of file GlobalOpt.cpp.
References F, hasChangeableCCImpl(), and llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().
Referenced by hasOnlyColdCalls(), and OptimizeFunctions().
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 1360 of file GlobalOpt.cpp.
References llvm::CallingConv::C, CC, llvm::dyn_cast(), F, llvm::CallInst::isMustTailCall(), and llvm::CallingConv::X86_ThisCall.
Referenced by hasChangeableCC().
Definition at line 1491 of file GlobalOpt.cpp.
References F, and llvm::isa().
Referenced by OptimizeFunctions().
Definition at line 1482 of file GlobalOpt.cpp.
References llvm::cast(), F, and llvm::CallBase::isMustTailCall().
Referenced by OptimizeFunctions().
|
static |
Definition at line 1450 of file GlobalOpt.cpp.
References llvm::dyn_cast(), F, llvm::Function::getIntrinsicID(), hasChangeableCC(), llvm::GlobalValue::hasLocalLinkage(), I, isColdCallSite(), and llvm::Intrinsic::not_intrinsic.
Referenced by OptimizeFunctions().
|
static |
Definition at line 2095 of file GlobalOpt.cpp.
References llvm::any_of(), llvm::dyn_cast(), llvm::GlobalIFunc::getResolverFunction(), llvm::BasicBlock::getTerminator(), I, and llvm::GlobalValue::isInterposable().
Referenced by OptimizeStaticIFuncs().
|
static |
Definition at line 1871 of file GlobalOpt.cpp.
References assert(), llvm::Value::hasOneUse(), and llvm::Value::use_empty().
Referenced by hasUsesToReplace().
|
static |
Definition at line 1894 of file GlobalOpt.cpp.
References llvm::cast(), llvm::GlobalAlias::getAliasee(), hasUseOtherThanLLVMUsed(), llvm::GlobalValue::isWeakForLinker(), mayHaveOtherReferences(), and llvm::Constant::stripPointerCasts().
Referenced by OptimizeGlobalAliases().
|
static |
Return true if the block containing the call site has a BlockFrequency of less than ColdCCRelFreq% of the entry block.
Definition at line 1404 of file GlobalOpt.cpp.
References ColdCCRelFreq, llvm::BlockFrequencyInfo::getBlockFreq(), llvm::CallBase::getCaller(), llvm::Function::getEntryBlock(), and llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent().
Referenced by hasOnlyColdCalls(), and isValidCandidateForColdCC().
Returns whether the given function is an empty C++ destructor or atexit handler and can therefore be eliminated.
Note that we assume that other optimization passes have already simplified the code so we simply check for 'ret'.
Definition at line 2034 of file GlobalOpt.cpp.
References llvm::Function::getEntryBlock(), I, llvm::isa(), and llvm::GlobalValue::isDeclaration().
Referenced by OptimizeEmptyGlobalAtExitDtors().
|
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 123 of file GlobalOpt.cpp.
References llvm::Type::ArrayTyID, llvm::cast(), llvm::StructType::elements(), llvm::Type::FixedVectorTyID, llvm::GlobalValue::getValueType(), llvm::GlobalValue::hasPrivateLinkage(), llvm::isa(), llvm::StructType::isOpaque(), llvm::isPointerTy(), llvm::Type::PointerTyID, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Type::ScalableVectorTyID, and llvm::Type::StructTyID.
Referenced by OptimizeAwayTrappingUsesOfLoads(), and processInternalGlobal().
|
static |
Definition at line 1002 of file GlobalOpt.cpp.
References assert(), DL, llvm::dyn_cast(), F, llvm::GlobalValue::getDataLayout(), llvm::Value::getType(), llvm::StoreInst::getValueOperand(), I, llvm::none_of(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateCommon< T, typename >::size(), 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 173 of file GlobalOpt.cpp.
References llvm::cast(), llvm::dyn_cast(), GEP, I, llvm::isa(), and llvm::isAllocationFn().
Referenced by CleanupPointerRootUsers().
|
static |
Definition at line 1418 of file GlobalOpt.cpp.
References llvm::dyn_cast(), F, llvm::CallBase::getCalledOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), and isColdCallSite().
Referenced by OptimizeFunctions().
|
static |
Definition at line 1887 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 726 of file GlobalOpt.cpp.
References assert(), Changed, CleanupConstantGlobalUsers(), CleanupPointerRootUsers(), llvm::dbgs(), DL, llvm::dyn_cast(), llvm::GlobalVariable::eraseFromParent(), llvm::isa(), isLeakCheckerRoot(), LLVM_DEBUG, llvm::make_early_inc_range(), OptimizeAwayTrappingUsesOfValue(), llvm::Value::use_empty(), and llvm::Value::users().
Referenced by optimizeOnceStoredGlobal().
|
static |
Definition at line 662 of file GlobalOpt.cpp.
References llvm::CallBase::arg_size(), C(), llvm::cast(), Changed, llvm::dyn_cast(), llvm::ConstantExpr::getAddrSpaceCast(), llvm::CallBase::getArgOperand(), llvm::CallBase::getCalledOperand(), llvm::ConstantExpr::getGetElementPtr(), llvm::Value::getType(), I, llvm::isa(), llvm::NullPointerIsDefined(), OptimizeAwayTrappingUsesOfValue(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::CallBase::setArgOperand(), llvm::CallBase::setCalledOperand(), llvm::SmallVectorTemplateCommon< T, typename >::size(), and Users.
Referenced by OptimizeAwayTrappingUsesOfLoads(), and OptimizeAwayTrappingUsesOfValue().
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 2050 of file GlobalOpt.cpp.
References Changed, llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::CallBase::getArgOperand(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::CallBase::isCallee(), IsEmptyAtExitFunction(), llvm::make_early_inc_range(), llvm::Value::replaceAllUsesWith(), llvm::Value::stripPointerCasts(), and llvm::Value::uses().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 1576 of file GlobalOpt.cpp.
References ChangeCalleesToFastCall(), changeCallSitesToColdCC(), Changed, llvm::CallingConv::Cold, deleteIfDead(), EnableColdCCStressTest, llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::erase(), F, llvm::CallingConv::Fast, hasChangeableCC(), hasInvokeCallers(), hasMustTailCallers(), hasOnlyColdCalls(), llvm::GlobalValue::InternalLinkage, isValidCandidateForColdCC(), llvm::make_early_inc_range(), processGlobal(), RemoveAttribute(), RemovePreallocated(), llvm::removeUnreachableBlocks(), and llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 1925 of file GlobalOpt.cpp.
References Changed, deleteIfDead(), llvm::dyn_cast(), llvm::GlobalValue::getLinkage(), hasUsesToReplace(), llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::isDSOLocal(), llvm::GlobalValue::isImplicitDSOLocal(), llvm::GlobalValue::isInterposableLinkage(), llvm::make_early_inc_range(), mayHaveOtherReferences(), and llvm::Constant::stripPointerCasts().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 2401 of file GlobalOpt.cpp.
References C(), Changed, llvm::SmallPtrSetImplBase::clear(), DeleteDeadIFuncs(), DL, EvaluateStaticConstructor(), F, FindAtExitLibFunc(), llvm::GlobalValue::getComdat(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::GlobalValue::isDiscardableIfUnused(), OptimizeEmptyGlobalAtExitDtors(), OptimizeFunctions(), OptimizeGlobalAliases(), llvm::optimizeGlobalCtorsList(), OptimizeGlobalVars(), OptimizeNonTrivialIFuncs(), OptimizeStaticIFuncs(), and llvm::Value::use_empty().
Referenced by llvm::GlobalOptPass::run().
|
static |
Definition at line 1705 of file GlobalOpt.cpp.
References C(), Changed, llvm::ConstantFoldConstant(), deleteIfDead(), DL, llvm::GlobalValue::hasLocalLinkage(), llvm::Value::hasName(), llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::isDeclaration(), llvm::make_early_inc_range(), processGlobal(), and llvm::GlobalValue::setLinkage().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 2198 of file GlobalOpt.cpp.
References llvm::all_of(), llvm::any_of(), Changed, collectVersions(), llvm::dbgs(), llvm::dyn_cast(), E(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::BasicBlock::getTerminator(), I, llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::detail::DenseSetImpl< ValueT, MapTy >::insert(), llvm::APInt::isSubsetOf(), LHS, LLVM_DEBUG, MaxIFuncVersions, OptimizeNonFMVCallers, llvm::SmallVectorTemplateBase< T, bool >::push_back(), RHS, llvm::CallBase::setCalledOperand(), llvm::ArrayRef< T >::size(), llvm::sort(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace(), and llvm::Value::users().
Referenced by optimizeGlobalsInModule().
|
static |
Definition at line 783 of file GlobalOpt.cpp.
References DL, llvm::dyn_cast(), llvm::GlobalVariable::getInitializer(), llvm::Type::getPointerAddressSpace(), llvm::Value::getType(), llvm::Constant::isNullValue(), llvm::Type::isPointerTy(), llvm::NullPointerIsDefined(), and OptimizeAwayTrappingUsesOfLoads().
Referenced by processInternalGlobal().
Find IFuncs that have resolvers that always point at the same statically known callee, and replace their callers with a direct call.
Definition at line 2125 of file GlobalOpt.cpp.
References Changed, hasSideeffectFreeStaticResolution(), and llvm::none_of().
Referenced by optimizeGlobalsInModule().
|
static |
Analyze the specified global variable and optimize it if possible.
If we make a change, return true.
Definition at line 1286 of file GlobalOpt.cpp.
References llvm::GlobalStatus::analyzeGlobal(), Changed, llvm::dyn_cast(), llvm::Value::getName(), llvm::GlobalValue::getUnnamedAddr(), llvm::GlobalValue::Global, llvm::GlobalValue::hasAtLeastLocalUnnamedAddr(), llvm::GlobalValue::hasGlobalUnnamedAddr(), llvm::GlobalValue::hasLocalLinkage(), llvm::isa(), llvm::GlobalValue::Local, processInternalGlobal(), llvm::GlobalValue::setUnnamedAddr(), and llvm::StringRef::starts_with().
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 1107 of file GlobalOpt.cpp.
References assert(), Changed, CleanupConstantGlobalUsers(), CleanupPointerRootUsers(), llvm::dbgs(), DL, llvm::dyn_cast(), llvm::GlobalVariable::eraseFromParent(), forwardStoredOnceStore(), llvm::GlobalValue::getAddressSpace(), llvm::PointerType::getAddressSpace(), llvm::DebugLoc::getCompilerGenerated(), llvm::GlobalValue::getDataLayout(), llvm::GlobalVariable::getGlobalSize(), llvm::GlobalVariable::getInitializer(), llvm::GlobalValue::getLinkage(), llvm::Value::getName(), llvm::GlobalValue::getParent(), llvm::GlobalValue::getThreadLocalMode(), llvm::GlobalValue::getType(), llvm::Value::getType(), llvm::GlobalValue::getValueType(), llvm::GlobalStatus::InitializerStored, llvm::isa(), llvm::GlobalVariable::isConstant(), llvm::GlobalVariable::isExternallyInitialized(), isLeakCheckerRoot(), isPointerValueDeadOnEntryToFunction(), llvm::Type::isSingleValueType(), LLVM_DEBUG, llvm::NotAtomic, optimizeOnceStoredGlobal(), llvm::Value::replaceAllUsesWith(), llvm::GlobalVariable::setConstant(), llvm::Instruction::setDebugLoc(), llvm::GlobalVariable::setInitializer(), SRAGlobal(), llvm::GlobalStatus::StoredOnce, TryToShrinkGlobalToBoolean(), and llvm::Value::use_empty().
Referenced by processGlobal().
|
static |
Definition at line 1348 of file GlobalOpt.cpp.
References A(), llvm::cast(), F, llvm::CallBase::getAttributes(), llvm::CallBase::setAttributes(), and StripAttr().
Referenced by OptimizeFunctions(), and RemovePreallocated().
|
static |
Definition at line 1498 of file GlobalOpt.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::cast(), llvm::CallBase::Create(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::SmallVectorImpl< T >::erase(), F, llvm::CallBase::getArgOperand(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::isa(), llvm::make_isa_range(), RemoveAttribute(), llvm::Value::takeName(), uint64_t, and llvm::Instruction::users().
Referenced by OptimizeFunctions().
|
static |
Definition at line 1774 of file GlobalOpt.cpp.
References llvm::GlobalValue::AppendingLinkage, llvm::array_pod_sort(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::cast(), compareNames(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::ArrayType::get(), llvm::ConstantArray::get(), llvm::PointerType::get(), llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(), llvm::GlobalValue::NotThreadLocal, llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::SmallVectorTemplateCommon< T, typename >::size().
|
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 530 of file GlobalOpt.cpp.
References _, assert(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::begin(), llvm::cast(), collectSRATypes(), llvm::commonAlignment(), llvm::GlobalVariable::copyAttributesFrom(), llvm::count_if(), llvm::dbgs(), DL, llvm::dyn_cast(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::GlobalVariable::eraseFromParent(), llvm::GlobalValue::getAddressSpace(), llvm::GlobalVariable::getAlign(), llvm::GlobalVariable::getGlobalSize(), llvm::getLoadStorePointerOperand(), llvm::getLoadStoreType(), llvm::Value::getName(), llvm::getOrEnforceKnownAlignment(), llvm::GlobalValue::getParent(), llvm::GlobalValue::getThreadLocalMode(), llvm::GlobalValue::getValueType(), llvm::GlobalValue::hasLocalLinkage(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::GlobalValue::InternalLinkage, llvm::isa(), llvm::isSafeToDestroyConstant(), LLVM_DEBUG, llvm::Offset, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::RecursivelyDeleteTriviallyDeadInstructions(), llvm::Constant::removeDeadConstantUsers(), llvm::GlobalVariable::setAlignment(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::size(), llvm::sort(), transferSRADebugInfo(), uint64_t, and llvm::Value::users().
Referenced by processInternalGlobal().
| STATISTIC | ( | NumAliasesRemoved | , |
| "Number of global aliases eliminated" | ) |
| STATISTIC | ( | NumAliasesResolved | , |
| "Number of global aliases resolved" | ) |
| STATISTIC | ( | NumAtExitRemoved | , |
| "Number of atexit handlers removed" | ) |
| STATISTIC | ( | NumColdCC | , |
| "Number of functions marked coldcc" | ) |
| STATISTIC | ( | NumCtorsEvaluated | , |
| "Number of static ctors evaluated" | ) |
| STATISTIC | ( | NumCXXDtorsRemoved | , |
| "Number of global C++ destructors removed" | ) |
| STATISTIC | ( | NumDeleted | , |
| "Number of globals deleted" | ) |
| STATISTIC | ( | NumFastCallFns | , |
| "Number of functions converted to fastcc" | ) |
| STATISTIC | ( | NumGlobUses | , |
| "Number of global uses devirtualized" | ) |
| STATISTIC | ( | NumIFuncsDeleted | , |
| "Number of IFuncs removed" | ) |
| STATISTIC | ( | NumIFuncsResolved | , |
| "Number of statically resolved IFuncs" | ) |
| STATISTIC | ( | NumInternalFunc | , |
| "Number of internal functions" | ) |
| STATISTIC | ( | NumLocalized | , |
| "Number of globals localized" | ) |
| STATISTIC | ( | NumMarked | , |
| "Number of globals marked constant" | ) |
| STATISTIC | ( | NumNestRemoved | , |
| "Number of nest attributes removed" | ) |
| STATISTIC | ( | NumShrunkToBool | , |
| "Number of global vars shrunk to booleans" | ) |
| STATISTIC | ( | NumSRA | , |
| "Number of aggregate globals broken into scalars" | ) |
| STATISTIC | ( | NumSubstitute | , |
| "Number of globals with initializers stored into them" | ) |
| STATISTIC | ( | NumUnnamed | , |
| "Number of globals marked unnamed_addr" | ) |
|
static |
Definition at line 1340 of file GlobalOpt.cpp.
Referenced by RemoveAttribute().
|
static |
Copy over the debug info for a variable to its SRA replacements.
Definition at line 450 of file GlobalOpt.cpp.
References llvm::GlobalVariable::addDebugInfo(), llvm::DIExpression::createFragmentExpression(), E(), llvm::DIExpression::extractIfOffset(), llvm::MDNode::get(), llvm::MDNode::getContext(), llvm::GlobalVariable::getDebugInfo(), llvm::DIType::getSizeInBits(), llvm::DIVariable::getType(), and uint64_t.
Referenced by SRAGlobal().
|
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 810 of file GlobalOpt.cpp.
References AbstractManglingParser< Derived, Alloc >::Ops, llvm::GlobalVariable::addDebugInfo(), assert(), llvm::cast(), llvm::GlobalVariable::copyAttributesFrom(), llvm::SelectInst::Create(), llvm::dbgs(), DEBUG_TYPE, DL, llvm::dyn_cast(), E(), llvm::GlobalVariable::eraseFromParent(), llvm::Instruction::eraseFromParent(), llvm::MDNode::get(), llvm::PointerType::getAddressSpace(), llvm::Value::getContext(), llvm::GlobalValue::getDataLayout(), llvm::GlobalVariable::getDebugInfo(), llvm::Instruction::getDebugLoc(), llvm::ConstantInt::getFalse(), llvm::GlobalVariable::getGlobalSize(), llvm::GlobalVariable::getInitializer(), llvm::Type::getInt1Ty(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::getLoadStoreType(), llvm::Value::getName(), llvm::User::getOperand(), llvm::LoadInst::getOrdering(), llvm::GlobalValue::getParent(), llvm::LoadInst::getSyncScopeID(), llvm::GlobalValue::getThreadLocalMode(), llvm::GlobalValue::getType(), llvm::Value::getType(), llvm::GlobalValue::getValueType(), llvm::Module::insertGlobalVariable(), llvm::GlobalValue::InternalLinkage, llvm::isa(), llvm::Type::isFloatingPointTy(), llvm::Constant::isNullValue(), llvm::Type::isPointerTy(), llvm::Type::isVectorTy(), LLVM_DEBUG, llvm::DIExpression::prependOpcodes(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setDebugLoc(), llvm::setExplicitlyUnknownBranchWeightsIfProfiled(), llvm::Value::takeName(), uint64_t, llvm::Value::use_empty(), llvm::Value::user_back(), and llvm::Value::users().
Referenced by processInternalGlobal().
|
static |
Referenced by isColdCallSite().
|
static |
Referenced by OptimizeFunctions().
|
static |
Referenced by OptimizeNonTrivialIFuncs().
|
static |
Referenced by OptimizeNonTrivialIFuncs().