|
LLVM 24.0.0git
|
#include "llvm/Transforms/IPO/MergeFunctions.h"#include "llvm/ADT/ArrayRef.h"#include "llvm/ADT/DenseMap.h"#include "llvm/ADT/DenseSet.h"#include "llvm/ADT/PostOrderIterator.h"#include "llvm/ADT/STLExtras.h"#include "llvm/ADT/SmallVector.h"#include "llvm/ADT/Statistic.h"#include "llvm/Analysis/BlockFrequencyInfo.h"#include "llvm/Analysis/BranchProbabilityInfo.h"#include "llvm/IR/Argument.h"#include "llvm/IR/BasicBlock.h"#include "llvm/IR/DebugInfoMetadata.h"#include "llvm/IR/DebugLoc.h"#include "llvm/IR/DerivedTypes.h"#include "llvm/IR/Function.h"#include "llvm/IR/GlobalValue.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/Metadata.h"#include "llvm/IR/Module.h"#include "llvm/IR/PassManager.h"#include "llvm/IR/ProfDataUtils.h"#include "llvm/IR/StructuralHash.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/ProfileData/InstrProf.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/FunctionComparator.h"#include "llvm/Transforms/Utils/ModuleUtils.h"#include <algorithm>#include <cassert>#include <cstddef>#include <cstdint>#include <iterator>#include <optional>#include <set>#include <utility>#include <vector>Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "mergefunc" |
Functions | |
| STATISTIC (NumFunctionsMerged, "Number of functions merged") | |
| STATISTIC (NumThunksWritten, "Number of thunks generated") | |
| STATISTIC (NumAliasesWritten, "Number of aliases generated") | |
| STATISTIC (NumDoubleWeak, "Number of new functions created") | |
| static bool | hasDistinctMetadataIntrinsic (const Function &F) |
Check whether F has an intrinsic which references distinct metadata as an operand. | |
| static bool | isEligibleForMerging (Function &F) |
Check whether F is eligible for function merging. | |
| Function * | asPtr (Function *Fn) |
| Function * | asPtr (Function &Fn) |
| static void | addMissingCallLocations (Function *Old, Function *New) |
| static bool | canCreateThunkFor (Function *F) |
| Whether this function may be replaced by a forwarding thunk. | |
| static void | copyMetadataIfPresent (Function *From, Function *To, StringRef Kind) |
| Copy all metadata of a specific kind from one function to another. | |
| static bool | canCreateAliasFor (Function *F) |
| static bool | hasNonLocalAlias (const Function *F) |
| static bool | canBeAliasee (const Function *F) |
| A COFF weak external must name its target, and a local symbol has no name the linker can agree on across objects (LNK1227). | |
| static DenseSet< GlobalValue::GUID > | unionImportGUIDs (const Function &F, const Function &G) |
| static void | mergeEntryCountsAndImportsInto (Function &F, Function &G) |
| static bool | isODR (const Function *F) |
Returns true if F is either weak_odr or linkonce_odr. | |
| static uint64_t | getBlockCountForMerging (const BlockFrequencyInfo &BFI, const BasicBlock *BB) |
| static void | mergeBranchWeightsOnInstructions (Instruction *DstI, const Instruction *SrcI, const BlockFrequencyInfo &DstBFI, const BlockFrequencyInfo &SrcBFI) |
| static void | addValueProfile (const Instruction &I, InstrProfValueKind Kind, DenseMap< uint64_t, uint64_t > &Merged) |
| static void | mergeValueProfileOnInstructions (Instruction *DstI, const Instruction *SrcI) |
| static bool | isFuncOrderCorrect (const Function *F, const Function *G) |
Variables | |
| static cl::opt< unsigned > | NumFunctionsForVerificationCheck ("mergefunc-verify", cl::desc("How many functions in a module could be used for " "MergeFunctions to pass a basic correctness check. " "'0' disables this check. Works only with '-debug' key."), cl::init(0), cl::Hidden) |
| static cl::opt< bool > | MergeFunctionsPDI ("mergefunc-preserve-debug-info", cl::Hidden, cl::init(false), cl::desc("Preserve debug info in thunk when mergefunc " "transformations are made.")) |
| static cl::opt< bool > | MergeFunctionsAliases ("mergefunc-use-aliases", cl::Hidden, cl::init(false), cl::desc("Allow mergefunc to create aliases")) |
| #define DEBUG_TYPE "mergefunc" |
Definition at line 145 of file MergeFunctions.cpp.
Definition at line 535 of file MergeFunctions.cpp.
References llvm::dyn_cast(), llvm::MDNode::get(), llvm::DILocalScope::getSubprogram(), and llvm::Value::uses().
|
static |
Definition at line 1029 of file MergeFunctions.cpp.
References llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::getValueProfDataFromInst(), I, llvm::SaturatingAdd(), llvm::Total, and uint64_t.
Referenced by mergeValueProfileOnInstructions().
Definition at line 467 of file MergeFunctions.cpp.
Definition at line 466 of file MergeFunctions.cpp.
A COFF weak external must name its target, and a local symbol has no name the linker can agree on across objects (LNK1227).
Definition at line 889 of file MergeFunctions.cpp.
References F.
Definition at line 870 of file MergeFunctions.cpp.
References assert(), F, and MergeFunctionsAliases.
Whether this function may be replaced by a forwarding thunk.
Definition at line 746 of file MergeFunctions.cpp.
References llvm::dbgs(), F, and LLVM_DEBUG.
Copy all metadata of a specific kind from one function to another.
Definition at line 766 of file MergeFunctions.cpp.
References llvm::GlobalObject::addMetadata(), and llvm::GlobalObject::getMetadata().
|
static |
Definition at line 976 of file MergeFunctions.cpp.
References llvm::Count, llvm::BlockFrequencyInfo::getBlockProfileCount(), and uint64_t.
Referenced by mergeBranchWeightsOnInstructions().
Check whether F has an intrinsic which references distinct metadata as an operand.
The most common instance of this would be CFI checks for function-local types.
Definition at line 439 of file MergeFunctions.cpp.
References llvm::dyn_cast(), F, I, llvm::isa(), llvm::make_isa_range(), and N.
Referenced by isEligibleForMerging().
Definition at line 880 of file MergeFunctions.cpp.
References F.
Check whether F is eligible for function merging.
Definition at line 457 of file MergeFunctions.cpp.
References F, and hasDistinctMetadataIntrinsic().
Definition at line 1258 of file MergeFunctions.cpp.
Returns true if F is either weak_odr or linkonce_odr.
Definition at line 972 of file MergeFunctions.cpp.
References F.
Referenced by isFuncOrderCorrect().
|
static |
Definition at line 984 of file MergeFunctions.cpp.
References assert(), llvm::extractBranchWeights(), llvm::extractProfTotalWeight(), getBlockCountForMerging(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::hasBranchWeightOrigin(), I, llvm::mulDivNearest(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::SaturatingAdd(), llvm::setFittedBranchWeights(), llvm::SmallVectorTemplateCommon< T, typename >::size(), and uint64_t.
Definition at line 928 of file MergeFunctions.cpp.
References llvm::detail::DenseSetImpl< ValueT, MapTy >::empty(), F, G, llvm::SaturatingAdd(), uint64_t, and unionImportGUIDs().
|
static |
Definition at line 1041 of file MergeFunctions.cpp.
References A(), addValueProfile(), llvm::annotateValueSite(), B(), llvm::Count, llvm::mdconst::dyn_extract(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::Instruction::getFunction(), llvm::Instruction::getMetadata(), llvm::MDNode::getOperand(), llvm::GlobalValue::getParent(), llvm::ConstantInt::getZExtValue(), llvm::isValueProfileMD(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::SaturatingAdd(), llvm::Instruction::setMetadata(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::size(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::sort(), and uint64_t.
| STATISTIC | ( | NumAliasesWritten | , |
| "Number of aliases generated" | ) |
| STATISTIC | ( | NumDoubleWeak | , |
| "Number of new functions created" | ) |
| STATISTIC | ( | NumFunctionsMerged | , |
| "Number of functions merged" | ) |
| STATISTIC | ( | NumThunksWritten | , |
| "Number of thunks generated" | ) |
Definition at line 920 of file MergeFunctions.cpp.
References llvm::detail::DenseSetImpl< ValueT, MapTy >::begin(), llvm::detail::DenseSetImpl< ValueT, MapTy >::end(), F, G, and llvm::detail::DenseSetImpl< ValueT, MapTy >::insert().
Referenced by mergeEntryCountsAndImportsInto().
|
static |
Referenced by canCreateAliasFor().
|
static |
|
static |