|
LLVM 24.0.0git
|
#include "llvm/Transforms/IPO/LowerTypeTests.h"#include "llvm/ADT/APInt.h"#include "llvm/ADT/ArrayRef.h"#include "llvm/ADT/DenseMap.h"#include "llvm/ADT/EquivalenceClasses.h"#include "llvm/ADT/FunctionExtras.h"#include "llvm/ADT/MapVector.h"#include "llvm/ADT/PointerUnion.h"#include "llvm/ADT/STLExtras.h"#include "llvm/ADT/SetVector.h"#include "llvm/ADT/SmallVector.h"#include "llvm/ADT/Statistic.h"#include "llvm/ADT/StringMap.h"#include "llvm/ADT/StringRef.h"#include "llvm/ADT/TinyPtrVector.h"#include "llvm/Analysis/BlockFrequencyInfo.h"#include "llvm/Analysis/LoopInfo.h"#include "llvm/Analysis/PostDominators.h"#include "llvm/Analysis/ProfileSummaryInfo.h"#include "llvm/Analysis/TargetTransformInfo.h"#include "llvm/Analysis/TypeMetadataUtils.h"#include "llvm/Analysis/ValueTracking.h"#include "llvm/AsmParser/Parser.h"#include "llvm/BinaryFormat/ELF.h"#include "llvm/IR/Attributes.h"#include "llvm/IR/BasicBlock.h"#include "llvm/IR/Constant.h"#include "llvm/IR/Constants.h"#include "llvm/IR/DIBuilder.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/DerivedTypes.h"#include "llvm/IR/Function.h"#include "llvm/IR/GlobalAlias.h"#include "llvm/IR/GlobalObject.h"#include "llvm/IR/GlobalValue.h"#include "llvm/IR/GlobalVariable.h"#include "llvm/IR/IRBuilder.h"#include "llvm/IR/InlineAsm.h"#include "llvm/IR/Instruction.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/Intrinsics.h"#include "llvm/IR/LLVMContext.h"#include "llvm/IR/MDBuilder.h"#include "llvm/IR/Metadata.h"#include "llvm/IR/Module.h"#include "llvm/IR/ModuleSummaryIndex.h"#include "llvm/IR/ModuleSummaryIndexYAML.h"#include "llvm/IR/Operator.h"#include "llvm/IR/PassManager.h"#include "llvm/IR/ProfDataUtils.h"#include "llvm/IR/ReplaceConstant.h"#include "llvm/IR/Type.h"#include "llvm/IR/Use.h"#include "llvm/IR/User.h"#include "llvm/IR/Value.h"#include "llvm/Object/ModuleSymbolTable.h"#include "llvm/Support/Allocator.h"#include "llvm/Support/Casting.h"#include "llvm/Support/CommandLine.h"#include "llvm/Support/Debug.h"#include "llvm/Support/Error.h"#include "llvm/Support/ErrorHandling.h"#include "llvm/Support/FileSystem.h"#include "llvm/Support/MathExtras.h"#include "llvm/Support/MemoryBuffer.h"#include "llvm/Support/SourceMgr.h"#include "llvm/Support/TrailingObjects.h"#include "llvm/Support/YAMLTraits.h"#include "llvm/Support/raw_ostream.h"#include "llvm/TargetParser/Triple.h"#include "llvm/Transforms/IPO.h"#include "llvm/Transforms/Utils/BasicBlockUtils.h"#include "llvm/Transforms/Utils/ModuleUtils.h"#include <algorithm>#include <cassert>#include <cstdint>#include <set>#include <string>#include <system_error>#include <utility>#include <vector>Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "lowertypetests" |
Functions | |
| STATISTIC (ByteArraySizeBits, "Byte array size in bits") | |
| STATISTIC (ByteArraySizeBytes, "Byte array size in bytes") | |
| STATISTIC (NumByteArraysCreated, "Number of byte arrays created") | |
| STATISTIC (NumTypeTestCallsLowered, "Number of type test calls lowered") | |
| STATISTIC (NumTypeIdDisjointSets, "Number of disjoint sets of type identifiers") | |
| static ConstantInt * | extractNumericTypeId (MDNode &MD) |
| Extracts a numeric type identifier from an MDNode containing type metadata. | |
| static CfiFunctionLinkage | decodeCfiFunctionLinkage (uint8_t Encoded) |
| static CfiFunctionHotness | decodeCfiFunctionHotness (uint8_t Encoded) |
| static uint8_t | encodeCfiFunctionLinkage (CfiFunctionLinkage Linkage, CfiFunctionHotness Hotness) |
| static void | createCfiFunctionsMetadata (Module &DestM, ArrayRef< GlobalValue * > CfiFunctions, ProfileSummaryInfo &PSI, function_ref< const BlockFrequencyInfo &(Function &)> BFIGetter) |
| static void | createCfiAliasesMetadata (Module &DestM, const Module &SrcM) |
| static void | createCfiSymversMetadata (Module &DestM, const Module &SrcM) |
| static BitSetInfo | buildBitSet (ArrayRef< uint64_t > Offsets) |
| Build a bit set for list of offsets. | |
| static Value * | createMaskedBitTest (IRBuilder<> &B, Value *Bits, Value *BitOffset) |
| Build a test that bit BitOffset mod sizeof(Bits)*8 is set in Bits. | |
| static bool | isKnownTypeIdMember (Metadata *TypeId, const DataLayout &DL, Value *V, uint64_t COffset) |
| static auto | buildBitSets (ArrayRef< Metadata * > TypeIds, const DenseMap< GlobalTypeMember *, uint64_t > &GlobalLayout) |
| static bool | isThumbFunction (Function *F, Triple::ArchType ModuleArch) |
| static SmallVector< DILocation * > | createJumpTableDebugInfo (Function *F, ArrayRef< GlobalTypeMember * > Functions) |
| static bool | isDirectCall (Use &U) |
| static void | dropTypeTests (Module &M, Function &TypeTestFunc, bool ShouldDropAll) |
| static bool | dropTypeTests (Module &M, bool ShouldDropAll) |
Variables | |
| static cl::opt< bool > | AvoidReuse ("lowertypetests-avoid-reuse", cl::desc("Try to avoid reuse of byte array addresses using aliases"), cl::Hidden, cl::init(true)) |
| static cl::opt< PassSummaryAction > | ClSummaryAction ("lowertypetests-summary-action", cl::desc("What to do with the summary when running this pass"), cl::values(clEnumValN(PassSummaryAction::None, "none", "Do nothing"), clEnumValN(PassSummaryAction::Import, "import", "Import typeid resolutions from summary and globals"), clEnumValN(PassSummaryAction::Export, "export", "Export typeid resolutions to summary and globals")), cl::Hidden) |
| static cl::opt< std::string > | ClReadSummary ("lowertypetests-read-summary", cl::desc("Read summary from given textual assembly or YAML " "file before running pass"), cl::Hidden) |
| static cl::opt< std::string > | ClWriteSummary ("lowertypetests-write-summary", cl::desc("Write summary to given YAML file after running pass"), cl::Hidden) |
| static cl::opt< bool > | EnableJumpTableDebugInfo ("lowertypetests-jump-table-debug-info", cl::init(true), cl::Hidden, cl::desc("Enable debug info generation for jump tables")) |
| static cl::opt< bool > | ReorderCfiJumpTablesProfiles ("reorder-cfi-jump-tables-profiles", cl::init(true), cl::Hidden, cl::desc("Reorder CFI jump tables using profile information")) |
| static const unsigned | kX86JumpTableEntrySize = 8 |
| static const unsigned | kX86IBTJumpTableEntrySize = 16 |
| static const unsigned | kARMJumpTableEntrySize = 4 |
| static const unsigned | kARMBTIJumpTableEntrySize = 8 |
| static const unsigned | kARMv6MJumpTableEntrySize = 16 |
| static const unsigned | kRISCVJumpTableEntrySize = 8 |
| static const unsigned | kLOONGARCH64JumpTableEntrySize = 8 |
| static const unsigned | kHexagonJumpTableEntrySize = 4 |
| #define DEBUG_TYPE "lowertypetests" |
Definition at line 102 of file LowerTypeTests.cpp.
|
static |
Build a bit set for list of offsets.
Definition at line 870 of file LowerTypeTests.cpp.
References llvm::lowertypetests::BitSetBuilder::build().
Referenced by buildBitSets().
|
static |
Definition at line 1455 of file LowerTypeTests.cpp.
References llvm::SmallVectorTemplateCommon< T, typename >::back(), buildBitSet(), llvm::cast(), llvm::dbgs(), llvm::dyn_cast(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), LLVM_DEBUG, llvm::Offset, llvm::SmallVectorImpl< T >::reserve(), llvm::ArrayRef< T >::size(), and uint64_t.
Definition at line 502 of file LowerTypeTests.cpp.
References A(), llvm::NamedMDNode::addOperand(), llvm::Module::aliases(), llvm::cast(), llvm::MapVector< KeyT, ValueT, MapType, VectorType, N >::empty(), F, llvm::MDString::get(), llvm::MDTuple::get(), llvm::Module::getContext(), llvm::Module::getOrInsertNamedMetadata(), llvm::isa(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::lowertypetests::createCfiMetadata().
|
static |
Definition at line 460 of file LowerTypeTests.cpp.
References llvm::NamedMDNode::addOperand(), llvm::append_range(), llvm::cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), encodeCfiFunctionLinkage(), F, llvm::ConstantAsMetadata::get(), llvm::MDString::get(), llvm::MDTuple::get(), llvm::Module::getContext(), llvm::Type::getInt64Ty(), llvm::Type::getInt8Ty(), llvm::Module::getOrInsertNamedMetadata(), llvm::lowertypetests::isJumpTableCanonical(), Linkage, llvm::SmallVectorTemplateBase< T, bool >::push_back(), and ReorderCfiJumpTablesProfiles.
Referenced by llvm::lowertypetests::createCfiMetadata().
Definition at line 525 of file LowerTypeTests.cpp.
References llvm::NamedMDNode::addOperand(), llvm::ModuleSymbolTable::CollectAsmSymvers(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), F, llvm::MDString::get(), llvm::MDTuple::get(), llvm::Module::getContext(), llvm::Module::getFunction(), llvm::Module::getOrInsertNamedMetadata(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::lowertypetests::createCfiMetadata().
|
static |
Definition at line 1849 of file LowerTypeTests.cpp.
References llvm::StringRef::consume_back(), llvm::DIBuilder::createCompileUnit(), llvm::DIBuilder::createFile(), llvm::DIBuilder::createFunction(), llvm::DIBuilder::createSubroutineType(), F, llvm::DIBuilder::finalize(), llvm::MDNode::get(), llvm::DICompileUnit::LineTablesOnly, and llvm::SmallVectorImpl< T >::reserve().
Build a test that bit BitOffset mod sizeof(Bits)*8 is set in Bits.
This pattern matches to the bt instruction on x86.
Definition at line 878 of file LowerTypeTests.cpp.
References B(), llvm::BitWidth, and llvm::cast().
|
static |
Definition at line 447 of file LowerTypeTests.cpp.
Referenced by encodeCfiFunctionLinkage().
|
static |
Definition at line 443 of file LowerTypeTests.cpp.
Referenced by encodeCfiFunctionLinkage().
Definition at line 2442 of file LowerTypeTests.cpp.
References dropTypeTests(), llvm::GlobalObject::eraseMetadata(), and llvm::Intrinsic::getDeclarationIfExists().
Definition at line 2418 of file LowerTypeTests.cpp.
References llvm::all_of(), assert(), llvm::lowertypetests::Assume, llvm::cast(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::getTrue(), llvm::make_early_inc_range(), llvm::Value::replaceAllUsesWith(), llvm::Value::use_empty(), llvm::Instruction::users(), and llvm::Value::uses().
Referenced by dropTypeTests(), and llvm::DropTypeTestsPass::run().
|
static |
Definition at line 451 of file LowerTypeTests.cpp.
References assert(), decodeCfiFunctionHotness(), decodeCfiFunctionLinkage(), and Linkage.
Referenced by createCfiFunctionsMetadata().
|
static |
Extracts a numeric type identifier from an MDNode containing type metadata.
Definition at line 329 of file LowerTypeTests.cpp.
References C(), llvm::dyn_cast(), llvm::dyn_cast_or_null(), and llvm::MDNode::getOperand().
Referenced by llvm::lowertypetests::findCfiTypeIds().
Definition at line 2373 of file LowerTypeTests.cpp.
References llvm::dyn_cast().
|
static |
Definition at line 986 of file LowerTypeTests.cpp.
References llvm::cast(), DL, llvm::dyn_cast(), GEP, llvm::APInt::getZExtValue(), isKnownTypeIdMember(), llvm::Offset, and uint64_t.
Referenced by isKnownTypeIdMember(), and llvm::SimplifyTypeTestsPass::run().
|
static |
Definition at line 1797 of file LowerTypeTests.cpp.
References F, llvm::Attribute::getValueAsString(), llvm::Attribute::isValid(), llvm::StringRef::split(), and llvm::Triple::thumb.
| STATISTIC | ( | ByteArraySizeBits | , |
| "Byte array size in bits" | ) |
| STATISTIC | ( | ByteArraySizeBytes | , |
| "Byte array size in bytes" | ) |
| STATISTIC | ( | NumByteArraysCreated | , |
| "Number of byte arrays created" | ) |
| STATISTIC | ( | NumTypeIdDisjointSets | , |
| "Number of disjoint sets of type identifiers" | ) |
| STATISTIC | ( | NumTypeTestCallsLowered | , |
| "Number of type test calls lowered" | ) |
|
static |
|
static |
|
static |
Referenced by checkCombinedSummaryForTesting().
|
static |
|
static |
Definition at line 1570 of file LowerTypeTests.cpp.
Definition at line 1569 of file LowerTypeTests.cpp.
Definition at line 1571 of file LowerTypeTests.cpp.
Definition at line 1574 of file LowerTypeTests.cpp.
Definition at line 1573 of file LowerTypeTests.cpp.
Definition at line 1572 of file LowerTypeTests.cpp.
Definition at line 1568 of file LowerTypeTests.cpp.
Definition at line 1567 of file LowerTypeTests.cpp.
|
static |
Referenced by createCfiFunctionsMetadata().