LLVM API Documentation
#include "llvm/Transforms/IPO.h"#include "llvm/CallingConv.h"#include "llvm/Constants.h"#include "llvm/DerivedTypes.h"#include "llvm/Instructions.h"#include "llvm/IntrinsicInst.h"#include "llvm/LLVMContext.h"#include "llvm/Module.h"#include "llvm/Pass.h"#include "llvm/Analysis/ConstantFolding.h"#include "llvm/Target/TargetData.h"#include "llvm/Support/CallSite.h"#include "llvm/Support/Compiler.h"#include "llvm/Support/Debug.h"#include "llvm/Support/ErrorHandling.h"#include "llvm/Support/GetElementPtrTypeIterator.h"#include "llvm/Support/MathExtras.h"#include "llvm/Support/raw_ostream.h"#include "llvm/ADT/DenseMap.h"#include "llvm/ADT/SmallPtrSet.h"#include "llvm/ADT/SmallVector.h"#include "llvm/ADT/Statistic.h"#include "llvm/ADT/STLExtras.h"#include <algorithm>
Go to the source code of this file.
| #define DEBUG_TYPE "globalopt" |
Definition at line 16 of file GlobalOpt.cpp.
| static bool AllGlobalLoadUsesSimpleEnoughForHeapSRA | ( | GlobalVariable * | GV, | |
| MallocInst * | MI | |||
| ) | [static] |
AllGlobalLoadUsesSimpleEnoughForHeapSRA - If all users of values loaded from GV are simple enough to perform HeapSRA, return true.
Definition at line 1088 of file GlobalOpt.cpp.
References llvm::SmallPtrSet< PtrType, SmallSize >::begin(), llvm::SmallPtrSetImpl::clear(), llvm::SmallPtrSet< PtrType, SmallSize >::count(), E, llvm::SmallPtrSet< PtrType, SmallSize >::end(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), LI, LoadUsesSimpleEnoughForHeapSRA(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by TryToOptimizeStoreOfMallocToGlobal().
| static bool AllUsesOfLoadedValueWillTrapIfNull | ( | GlobalVariable * | GV | ) | [static] |
AllUsesOfLoadedValueWillTrapIfNull - 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 664 of file GlobalOpt.cpp.
References AllUsesOfValueWillTrapIfNull(), E, LI, llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by TryToOptimizeStoreOfMallocToGlobal().
| static bool AllUsesOfValueWillTrapIfNull | ( | Value * | V, | |
| SmallPtrSet< PHINode *, 8 > & | PHIs | |||
| ) | [static] |
AllUsesOfValueWillTrapIfNull - 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 622 of file GlobalOpt.cpp.
References E, II, llvm::SmallPtrSet< PtrType, SmallSize >::insert(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by AllUsesOfLoadedValueWillTrapIfNull().
| static bool AnalyzeGlobal | ( | Value * | V, | |
| GlobalStatus & | GS, | |||
| SmallPtrSet< PHINode *, 16 > & | PHIUsers | |||
| ) | [static] |
AnalyzeGlobal - Look at all uses of the global and fill in the GlobalStatus structure. If the global has its address taken, return true to indicate we can't do anything with it.
Definition at line 160 of file GlobalOpt.cpp.
References llvm::CallingConv::C, E, F, llvm::Constant::getOperand(), GV, if(), llvm::SmallPtrSet< PtrType, SmallSize >::insert(), LI, SafeToDestroyConstant(), llvm::Value::use_begin(), and llvm::Value::use_end().
| static void ChangeCalleesToFastCall | ( | Function * | F | ) | [static] |
ChangeCalleesToFastCall - Walk all of the direct calls of the specified function, changing them to FastCC.
Definition at line 1815 of file GlobalOpt.cpp.
References E, llvm::CallingConv::Fast, llvm::CallSite::setCallingConv(), llvm::Value::use_begin(), llvm::Value::use_end(), and User.
| static bool CleanupConstantGlobalUsers | ( | Value * | V, | |
| Constant * | Init, | |||
| LLVMContext & | Context | |||
| ) | [static] |
CleanupConstantGlobalUsers - 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 285 of file GlobalOpt.cpp.
References BitCast, llvm::CallingConv::C, Changed, llvm::ConstantFoldInstruction(), llvm::ConstantFoldLoadThroughGEPConstantExpr(), E, llvm::MachineInstr::eraseFromParent(), llvm::ConstantExpr::getOpcode(), LI, MI, SafeToDestroyConstant(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by OptimizeAwayTrappingUsesOfLoads().
| static void CommitValueTo | ( | Constant * | Val, | |
| Constant * | Addr, | |||
| LLVMContext & | Context | |||
| ) | [static] |
CommitValueTo - We have decided that Addr (which satisfies the predicate isSimpleEnoughPointerToCommit) should get Val as its value. Make it happen.
Definition at line 2113 of file GlobalOpt.cpp.
References EvaluateStoreInto(), llvm::GlobalVariable::getInitializer(), llvm::Constant::getOperand(), llvm::GlobalVariable::hasInitializer(), and llvm::GlobalVariable::setInitializer().
Referenced by EvaluateStaticConstructor().
| static Constant* ComputeLoadResult | ( | Constant * | P, | |
| const DenseMap< Constant *, Constant * > & | Memory, | |||
| LLVMContext & | Context | |||
| ) | [static] |
ComputeLoadResult - Return the value that would be computed by a load from P after the stores reflected by 'memory' have been performed. If we can't decide, return null.
Definition at line 2132 of file GlobalOpt.cpp.
References llvm::ConstantFoldLoadThroughGEPConstantExpr(), llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::end(), llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::find(), llvm::GlobalVariable::getInitializer(), llvm::GlobalVariable::hasDefinitiveInitializer(), and if().
Referenced by EvaluateFunction().
| static void ConstantPropUsersOf | ( | Value * | V, | |
| LLVMContext & | Context | |||
| ) | [static] |
ConstantPropUsersOf - Walk the use list of V, constant folding all of the instructions that are foldable.
Definition at line 804 of file GlobalOpt.cpp.
References llvm::ConstantFoldInstruction(), E, llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by OptimizeGlobalAddressOfMalloc().
| static bool EvaluateFunction | ( | Function * | F, | |
| Constant *& | RetVal, | |||
| const SmallVectorImpl< Constant * > & | ActualArgs, | |||
| std::vector< Function * > & | CallStack, | |||
| DenseMap< Constant *, Constant * > & | MutatedMemory, | |||
| std::vector< GlobalVariable * > & | AllocaTmps | |||
| ) | [static] |
EvaluateFunction - Evaluate a call to function F, returning true if successful, false if we can't evaluate it. ActualArgs contains the formal arguments for the function.
Values - As we compute SSA register values, we store their contents here.
ExecutedBlocks - We only handle non-looping, non-recursive code. As such, we can only evaluate any one basic block at most once. This set keeps track of what we have executed so we can detect recursive cases etc.
Definition at line 2163 of file GlobalOpt.cpp.
References AI, llvm::Function::arg_begin(), llvm::Function::arg_end(), llvm::Function::begin(), llvm::BasicBlock::begin(), llvm::CallingConv::C, ComputeLoadResult(), llvm::ConstantFoldCall(), Context, llvm::SmallVectorImpl< T >::data(), llvm::dyn_cast(), E, llvm::Function::getContext(), llvm::SequentialType::getElementType(), llvm::Function::getFunctionType(), llvm::PHINode::getIncomingValueForBlock(), llvm::Value::getName(), llvm::Value::getType(), llvm::AllocationInst::getType(), getVal(), llvm::ConstantInt::getZExtValue(), llvm::SmallPtrSet< PtrType, SmallSize >::insert(), llvm::AllocationInst::isArrayAllocation(), llvm::Function::isDeclaration(), isSimpleEnoughPointerToCommit(), llvm::FunctionType::isVarArg(), LI, llvm::SmallVectorImpl< T >::push_back(), llvm::SmallVectorImpl< T >::size(), Ty, Val, and Values.
Referenced by EvaluateStaticConstructor().
EvaluateStaticConstructor - Evaluate static constructors in the function, if we can. Return true if we can, false otherwise.
MutatedMemory - For each store we execute, we update this map. Loads check this to get the most up-to-date value. If evaluation is successful, this state is committed to the process.
AllocaTmps - To 'execute' an alloca, we create a temporary global variable to represent its body. This vector is needed so we can delete the temporary globals when we are done.
CallStack - This is used to detect recursion. In pathological situations we could hit exponential behavior, but at least there is nothing unbounded.
Definition at line 2343 of file GlobalOpt.cpp.
References llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::begin(), CommitValueTo(), DEBUG, E, llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::end(), llvm::errs(), EvaluateFunction(), llvm::Function::getContext(), llvm::Value::getName(), llvm::GlobalValue::getType(), llvm::Value::replaceAllUsesWith(), llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::size(), and llvm::Value::use_empty().
| static Constant* EvaluateStoreInto | ( | Constant * | Init, | |
| Constant * | Val, | |||
| ConstantExpr * | Addr, | |||
| unsigned | OpNo, | |||
| LLVMContext & | Context | |||
| ) | [static] |
EvaluateStoreInto - 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 2049 of file GlobalOpt.cpp.
References llvm::StructType::getElementType(), llvm::StructType::getNumElements(), llvm::User::getNumOperands(), llvm::Constant::getOperand(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), Idx, llvm::StructType::isPacked(), llvm_unreachable, llvm::User::op_begin(), and llvm::User::op_end().
Referenced by CommitValueTo().
| static Constant* getAggregateConstantElement | ( | Constant * | Agg, | |
| Constant * | Idx, | |||
| LLVMContext & | Context | |||
| ) | [static] |
Definition at line 248 of file GlobalOpt.cpp.
References CA, CP, llvm::dyn_cast(), llvm::UndefValue::get(), llvm::Constant::getNullValue(), llvm::Constant::getOperand(), llvm::Value::getType(), and llvm::ConstantInt::getZExtValue().
Referenced by SRAGlobal().
| static Value* GetHeapSROAValue | ( | Value * | V, | |
| unsigned | FieldNo, | |||
| DenseMap< Value *, std::vector< Value * > > & | InsertedScalarizedValues, | |||
| std::vector< std::pair< PHINode *, unsigned > > & | PHIsToRewrite, | |||
| LLVMContext & | Context | |||
| ) | [static] |
Definition at line 1137 of file GlobalOpt.cpp.
References llvm::PHINode::Create(), llvm::StructType::getElementType(), llvm::PointerType::getUnqual(), LI, and llvm_unreachable.
Referenced by PerformHeapAllocSRoA(), and RewriteHeapSROALoadUser().
| static bool GlobalUsersSafeToSRA | ( | GlobalValue * | GV | ) | [static] |
GlobalUsersSafeToSRA - Look at all uses of the global and decide whether it is safe for us to perform this transformation.
Definition at line 457 of file GlobalOpt.cpp.
References E, IsUserOfGlobalSafeForSRA(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by SRAGlobal().
| static GlobalVariable* InstallGlobalCtors | ( | GlobalVariable * | GCL, | |
| const std::vector< Function * > & | Ctors, | |||
| LLVMContext & | Context | |||
| ) | [static] |
InstallGlobalCtors - Given a specified llvm.global_ctors list, install the specified array, returning the new global to use.
Definition at line 1956 of file GlobalOpt.cpp.
References llvm::GlobalVariable::eraseFromParent(), llvm::SequentialType::getElementType(), llvm::Module::getGlobalList(), llvm::GlobalVariable::getInitializer(), llvm::GlobalValue::getLinkage(), llvm::GlobalValue::getParent(), llvm::Value::getType(), llvm::GlobalValue::getType(), llvm::GlobalVariable::isConstant(), llvm::GlobalVariable::isThreadLocal(), llvm::Value::replaceAllUsesWith(), llvm::GlobalVariable::setInitializer(), llvm::Value::takeName(), llvm::Value::use_empty(), and V.
isSafeSROAElementUse - 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 357 of file GlobalOpt.cpp.
References llvm::CallingConv::C, llvm::dyn_cast(), E, llvm::User::getNumOperands(), llvm::User::getOperand(), SafeToDestroyConstant(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by IsUserOfGlobalSafeForSRA().
| static bool isSimpleEnoughPointerToCommit | ( | Constant * | C, | |
| LLVMContext & | Context | |||
| ) | [static] |
isSimpleEnoughPointerToCommit - Return true if this constant is simple enough for us to understand. In particular, if it is a cast of something, we punt. We basically just support direct accesses to globals and GEP's of globals. This should be kept up to date with CommitValueTo.
Definition at line 2026 of file GlobalOpt.cpp.
References llvm::ConstantFoldLoadThroughGEPConstantExpr(), llvm::GlobalVariable::getInitializer(), llvm::GlobalValue::hasExternalLinkage(), llvm::GlobalVariable::hasInitializer(), llvm::GlobalValue::hasLocalLinkage(), and llvm::GlobalVariable::isDeclaration().
Referenced by EvaluateFunction().
| static bool IsUserOfGlobalSafeForSRA | ( | User * | U, | |
| GlobalValue * | GV | |||
| ) | [static] |
IsUserOfGlobalSafeForSRA - U is a direct user of the specified global value. Look at it and its uses and decide whether it is safe to SROA this global.
Definition at line 391 of file GlobalOpt.cpp.
References llvm::dyn_cast(), E, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::generic_gep_type_iterator< ItTy >::getOperand(), llvm::ConstantInt::getZExtValue(), Idx, isSafeSROAElementUse(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by GlobalUsersSafeToSRA().
| static bool LoadUsesSimpleEnoughForHeapSRA | ( | Value * | V, | |
| SmallPtrSet< PHINode *, 32 > & | LoadUsingPHIs, | |||
| SmallPtrSet< PHINode *, 32 > & | LoadUsingPHIsPerLoad | |||
| ) | [static] |
LoadUsesSimpleEnoughForHeapSRA - 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 1036 of file GlobalOpt.cpp.
References E, llvm::SmallPtrSet< PtrType, SmallSize >::insert(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by AllGlobalLoadUsesSimpleEnoughForHeapSRA().
| static bool OptimizeAwayTrappingUsesOfLoads | ( | GlobalVariable * | GV, | |
| Constant * | LV, | |||
| LLVMContext & | Context | |||
| ) | [static] |
OptimizeAwayTrappingUsesOfLoads - 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 749 of file GlobalOpt.cpp.
References Changed, CleanupConstantGlobalUsers(), DOUT, E, llvm::GlobalVariable::eraseFromParent(), llvm::User::getOperand(), LI, OptimizeAwayTrappingUsesOfValue(), llvm::Value::use_begin(), llvm::Value::use_empty(), and llvm::Value::use_end().
Referenced by OptimizeOnceStoredGlobal().
| static bool OptimizeAwayTrappingUsesOfValue | ( | Value * | V, | |
| Constant * | NewV, | |||
| LLVMContext & | Context | |||
| ) | [static] |
Definition at line 681 of file GlobalOpt.cpp.
References llvm::CallingConv::C, Changed, E, llvm::ConstantExpr::getCast(), llvm::ConstantExpr::getGetElementPtr(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Value::getType(), LI, llvm::SmallVectorImpl< T >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::User::setOperand(), llvm::SmallVectorImpl< T >::size(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by OptimizeAwayTrappingUsesOfLoads().
| static GlobalVariable* OptimizeGlobalAddressOfMalloc | ( | GlobalVariable * | GV, | |
| MallocInst * | MI, | |||
| LLVMContext & | Context | |||
| ) | [static] |
OptimizeGlobalAddressOfMalloc - 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 823 of file GlobalOpt.cpp.
References ConstantPropUsersOf(), llvm::GetElementPtrInst::Create(), llvm::BinaryOperator::CreateNot(), DOUT, llvm::GlobalVariable::eraseFromParent(), llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::ArrayType::get(), llvm::ConstantExpr::getBitCast(), llvm::SequentialType::getElementType(), llvm::ConstantInt::getFalse(), llvm::Module::getGlobalList(), llvm::Type::getInt1Ty(), llvm::Type::getInt32Ty(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::GlobalValue::getParent(), llvm::CmpInst::getPredicate(), llvm::ConstantInt::getTrue(), llvm::GlobalValue::getType(), llvm::Use::getUser(), 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::GlobalValue::InternalLinkage, llvm::GlobalVariable::isThreadLocal(), LI, llvm_unreachable, LV, llvm::Value::replaceAllUsesWith(), llvm::Value::use_back(), and llvm::Value::use_empty().
Referenced by TryToOptimizeStoreOfMallocToGlobal().
| static bool OptimizeOnceStoredGlobal | ( | GlobalVariable * | GV, | |
| Value * | StoredOnceVal, | |||
| Module::global_iterator & | GVI, | |||
| TargetData * | TD, | |||
| LLVMContext & | Context | |||
| ) | [static] |
Definition at line 1538 of file GlobalOpt.cpp.
References llvm::ConstantExpr::getBitCast(), llvm::GlobalVariable::getInitializer(), llvm::Value::getType(), llvm::Constant::isNullValue(), MI, OptimizeAwayTrappingUsesOfLoads(), llvm::Value::stripPointerCasts(), and TryToOptimizeStoreOfMallocToGlobal().
| static std::vector<Function*> ParseGlobalCtors | ( | GlobalVariable * | GV | ) | [static] |
ParseGlobalCtors - Given a llvm.global_ctors list that we can understand, return a list of the functions and null terminator as a vector.
Definition at line 1943 of file GlobalOpt.cpp.
References llvm::GlobalVariable::getInitializer(), llvm::User::getNumOperands(), llvm::Constant::getOperand(), llvm::User::op_begin(), and llvm::User::op_end().
| static GlobalVariable* PerformHeapAllocSRoA | ( | GlobalVariable * | GV, | |
| MallocInst * | MI, | |||
| LLVMContext & | Context | |||
| ) | [static] |
PerformHeapAllocSRoA - MI is an allocation of an array of structures. Break it up into multiple allocations of arrays of the fields.
InsertedScalarizedLoads - 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 1270 of file GlobalOpt.cpp.
References llvm::PHINode::addIncoming(), llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::begin(), llvm::BasicBlock::Create(), llvm::BranchInst::Create(), DOUT, E, llvm::DenseMap< KeyT, ValueT, KeyInfoT, ValueInfoT >::end(), llvm::GlobalVariable::eraseFromParent(), llvm::Instruction::eraseFromParent(), llvm::SequentialType::getElementType(), llvm::StructType::getElementType(), GetHeapSROAValue(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::StructType::getNumElements(), llvm::PHINode::getNumIncomingValues(), llvm::User::getOperand(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::Intrinsic::getType(), llvm::PointerType::getUnqual(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::GlobalValue::InternalLinkage, llvm::GlobalVariable::isThreadLocal(), LI, ReplaceUsesOfMallocWithGlobal(), RewriteUsesOfLoadForHeapSRoA(), llvm::BasicBlock::splitBasicBlock(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by TryToOptimizeStoreOfMallocToGlobal().
| static void RemoveNestAttribute | ( | Function * | F | ) | [static] |
Definition at line 1834 of file GlobalOpt.cpp.
References E, llvm::Function::getAttributes(), llvm::CallSite::getAttributes(), llvm::Function::setAttributes(), llvm::CallSite::setAttributes(), StripNest(), llvm::Value::use_begin(), llvm::Value::use_end(), and User.
| static void ReplaceUsesOfMallocWithGlobal | ( | Instruction * | Alloc, | |
| GlobalVariable * | GV | |||
| ) | [static] |
ReplaceUsesOfMallocWithGlobal - 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 993 of file GlobalOpt.cpp.
References llvm::Instruction::eraseFromParent(), llvm::Value::getName(), llvm::SystemZCC::NL, llvm::User::replaceUsesOfWith(), llvm::Value::use_begin(), and llvm::Value::use_empty().
Referenced by PerformHeapAllocSRoA().
| static void RewriteHeapSROALoadUser | ( | Instruction * | LoadUser, | |
| DenseMap< Value *, std::vector< Value * > > & | InsertedScalarizedValues, | |||
| std::vector< std::pair< PHINode *, unsigned > > & | PHIsToRewrite, | |||
| LLVMContext & | Context | |||
| ) | [static] |
RewriteHeapSROALoadUser - Given a load instruction and a value derived from the load, rewrite the derived value to use the HeapSRoA'd load.
Definition at line 1180 of file GlobalOpt.cpp.
References llvm::GetElementPtrInst::Create(), E, GetHeapSROAValue(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::Value::getType(), InsertPos, llvm::Value::replaceAllUsesWith(), llvm::tie(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by RewriteUsesOfLoadForHeapSRoA().
| static void RewriteUsesOfLoadForHeapSRoA | ( | LoadInst * | Load, | |
| DenseMap< Value *, std::vector< Value * > > & | InsertedScalarizedValues, | |||
| std::vector< std::pair< PHINode *, unsigned > > & | PHIsToRewrite, | |||
| LLVMContext & | Context | |||
| ) | [static] |
RewriteUsesOfLoadForHeapSRoA - 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 1251 of file GlobalOpt.cpp.
References E, llvm::Instruction::eraseFromParent(), RewriteHeapSROALoadUser(), llvm::Value::use_begin(), llvm::Value::use_empty(), and llvm::Value::use_end().
Referenced by PerformHeapAllocSRoA().
Definition at line 144 of file GlobalOpt.cpp.
References E, llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by AnalyzeGlobal(), CleanupConstantGlobalUsers(), and isSafeSROAElementUse().
| static GlobalVariable* SRAGlobal | ( | GlobalVariable * | GV, | |
| const TargetData & | TD, | |||
| LLVMContext & | Context | |||
| ) | [static] |
SRAGlobal - 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 472 of file GlobalOpt.cpp.
References llvm::GetElementPtrInst::Create(), DOUT, llvm::ConstantInt::get(), llvm::TargetData::getABITypeAlignment(), llvm::PointerType::getAddressSpace(), getAggregateConstantElement(), llvm::GlobalValue::getAlignment(), llvm::StructLayout::getElementOffset(), llvm::ConstantExpr::getGetElementPtr(), llvm::Module::getGlobalList(), llvm::GlobalVariable::getInitializer(), llvm::Type::getInt32Ty(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::GlobalValue::getParent(), llvm::TargetData::getStructLayout(), llvm::GlobalValue::getType(), llvm::TargetData::getTypeAllocSize(), GlobalUsersSafeToSRA(), llvm::GlobalValue::hasLocalLinkage(), llvm::Value::hasNUsesOrMore(), llvm::GlobalValue::InternalLinkage, llvm::GlobalVariable::isConstant(), llvm::GlobalVariable::isThreadLocal(), llvm::MinAlign(), llvm::SmallVectorImpl< T >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::GlobalValue::setAlignment(), llvm::SmallVectorImpl< T >::size(), Ty, and Val.
| STATISTIC | ( | NumAliasesRemoved | , | |
| "Number of global aliases eliminated" | ||||
| ) |
| STATISTIC | ( | NumAliasesResolved | , | |
| "Number of global aliases resolved" | ||||
| ) |
| STATISTIC | ( | NumNestRemoved | , | |
| "Number of nest attributes removed" | ||||
| ) |
| STATISTIC | ( | NumCtorsEvaluated | , | |
| "Number of static ctors evaluated" | ||||
| ) |
| STATISTIC | ( | NumFastCallFns | , | |
| "Number of functions converted to fastcc" | ||||
| ) |
| STATISTIC | ( | NumShrunkToBool | , | |
| "Number of global vars shrunk to booleans" | ||||
| ) |
| STATISTIC | ( | NumLocalized | , | |
| "Number of globals localized" | ||||
| ) |
| STATISTIC | ( | NumGlobUses | , | |
| "Number of global uses devirtualized" | ||||
| ) |
| STATISTIC | ( | NumFnDeleted | , | |
| "Number of functions deleted" | ||||
| ) |
| STATISTIC | ( | NumDeleted | , | |
| "Number of globals deleted" | ||||
| ) |
| STATISTIC | ( | NumSubstitute | , | |
| "Number of globals with initializers stored into them" | ||||
| ) |
| STATISTIC | ( | NumHeapSRA | , | |
| "Number of heap objects SRA'd" | ||||
| ) |
| STATISTIC | ( | NumSRA | , | |
| "Number of aggregate globals broken into scalars" | ||||
| ) |
| STATISTIC | ( | NumMarked | , | |
| "Number of globals marked constant" | ||||
| ) |
| static AttrListPtr StripNest | ( | const AttrListPtr & | Attrs | ) | [static] |
Definition at line 1822 of file GlobalOpt.cpp.
References llvm::AttributeWithIndex::Attrs, llvm::AttrListPtr::getNumSlots(), llvm::AttrListPtr::getSlot(), llvm::AttributeWithIndex::Index, llvm::Attribute::Nest, and llvm::AttrListPtr::removeAttr().
Referenced by RemoveNestAttribute().
| static bool TryToOptimizeStoreOfMallocToGlobal | ( | GlobalVariable * | GV, | |
| MallocInst * | MI, | |||
| Module::global_iterator & | GVI, | |||
| TargetData * | TD, | |||
| LLVMContext & | Context | |||
| ) | [static] |
TryToOptimizeStoreOfMallocToGlobal - 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 1450 of file GlobalOpt.cpp.
References AllGlobalLoadUsesSimpleEnoughForHeapSRA(), AllUsesOfLoadedValueWillTrapIfNull(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::AllocationInst::getAllocatedType(), llvm::AllocationInst::getArraySize(), llvm::Type::getInt32Ty(), llvm::AllocationInst::getType(), llvm::TargetData::getTypeAllocSize(), llvm::AllocationInst::isArrayAllocation(), llvm::Type::isSized(), OptimizeGlobalAddressOfMalloc(), PerformHeapAllocSRoA(), llvm::Value::replaceAllUsesWith(), llvm::Value::takeName(), and ValueIsOnlyUsedLocallyOrStoredToOneGlobal().
Referenced by OptimizeOnceStoredGlobal().
| static bool TryToShrinkGlobalToBoolean | ( | GlobalVariable * | GV, | |
| Constant * | OtherVal, | |||
| LLVMContext & | Context | |||
| ) | [static] |
TryToShrinkGlobalToBoolean - 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 1571 of file GlobalOpt.cpp.
References llvm::SelectInst::Create(), DOUT, E, llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::SequentialType::getElementType(), llvm::ConstantInt::getFalse(), llvm::Module::getGlobalList(), llvm::Type::getInt1Ty(), llvm::Value::getName(), llvm::User::getOperand(), llvm::GlobalValue::getParent(), llvm::Value::getType(), llvm::GlobalValue::getType(), llvm::GlobalValue::InternalLinkage, llvm::Type::isFloatingPoint(), llvm::Constant::isNullValue(), LI, llvm::Value::replaceAllUsesWith(), llvm::Value::takeName(), llvm::Value::use_begin(), and llvm::Value::use_end().
| static bool ValueIsOnlyUsedLocallyOrStoredToOneGlobal | ( | Instruction * | V, | |
| GlobalVariable * | GV, | |||
| SmallPtrSet< PHINode *, 8 > & | PHIs | |||
| ) | [static] |
ValueIsOnlyUsedLocallyOrStoredToOneGlobal - 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 946 of file GlobalOpt.cpp.
References E, llvm::User::getOperand(), llvm::SmallPtrSet< PtrType, SmallSize >::insert(), Inst, llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by TryToOptimizeStoreOfMallocToGlobal().
AccessingFunction/HasMultipleAccessingFunctions - These start out null/false. When the first accessing function is noticed, it is recorded. When a second different accessing function is noticed, HasMultipleAccessingFunctions is set to true.
Definition at line 123 of file GlobalOpt.cpp.
Definition at line 124 of file GlobalOpt.cpp.
HasNonInstructionUser - Set to true if this global has a user that is not an instruction (e.g. a constant expr or GV initializer).
Definition at line 128 of file GlobalOpt.cpp.
HasPHIUser - Set to true if this global has a user that is a PHI node.
Definition at line 131 of file GlobalOpt.cpp.
char ID [static] |
Definition at line 62 of file GlobalOpt.cpp.
isLoaded - True if the global is ever loaded. If the global isn't ever loaded it can be deleted.
Definition at line 90 of file GlobalOpt.cpp.
StoredOnceValue - If only one value (besides the initializer constant) is ever stored to this global, keep track of what value it is.
Definition at line 117 of file GlobalOpt.cpp.
| enum { ... } GlobalStatus::StoredType StoredType |
StoredType - Keep track of what stores to the global look like.
RegisterPass<GlobalOpt> X("globalopt","Global Variable Optimizer") [static] |