LLVM 24.0.0git
IndirectBrExpandPass.cpp File Reference

Implements an expansion pass to turn indirectbr instructions in the IR into switch instructions. More...

Go to the source code of this file.

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.

Macros

#define DEBUG_TYPE   "indirectbr-expand"

Functions

static bool runImpl (Function &F, const TargetLowering *TLI, DomTreeUpdater *DTU, function_ref< BlockFrequencyInfo *()> GetBFI, bool PreserveProfile)
 INITIALIZE_PASS_BEGIN (IndirectBrExpandLegacyPass, DEBUG_TYPE, "Expand indirectbr instructions", false, false) INITIALIZE_PASS_END(IndirectBrExpandLegacyPass

Variables

 DEBUG_TYPE
Expand indirectbr instructions
Expand indirectbr false

Detailed Description

Implements an expansion pass to turn indirectbr instructions in the IR into switch instructions.

This works by enumerating the basic blocks in a dense range of integers, replacing each blockaddr constant with the corresponding integer constant, and then building a switch that maps from the integers to the actual blocks. All of the indirectbr instructions in the function are redirected to this common switch.

While this is generically useful if a target is unable to codegen indirectbr natively, it is primarily useful when there is some desire to get the builtin non-jump-table lowering of a switch even when the input source contained an explicit indirect branch construct.

Note that it doesn't make any sense to enable this pass unless a target also disables jump-table lowering of switches. Doing that is likely to pessimize the code.

Definition in file IndirectBrExpandPass.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "indirectbr-expand"

Definition at line 53 of file IndirectBrExpandPass.cpp.

Function Documentation

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( IndirectBrExpandLegacyPass ,
DEBUG_TYPE ,
"Expand indirectbr instructions" ,
false ,
false  )

◆ runImpl()

bool runImpl ( Function & F,
const TargetLowering * TLI,
DomTreeUpdater * DTU,
function_ref< BlockFrequencyInfo *()> GetBFI,
bool PreserveProfile )
static

Definition at line 121 of file IndirectBrExpandPass.cpp.

References llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(), assert(), llvm::cast(), llvm::BasicBlock::Create(), llvm::PHINode::Create(), llvm::SwitchInst::Create(), llvm::UncondBrInst::Create(), llvm::CastInst::CreatePointerCast(), DEBUG_TYPE, llvm::DominatorTreeBase< BasicBlock, false >::Delete, DL, llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::Instruction::eraseFromParent(), llvm::extractBranchWeights(), F, llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::IntegerType::getBitWidth(), llvm::BlockFrequencyInfo::getBlockProfileCount(), llvm::ConstantExpr::getIntToPtr(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::Value::getType(), llvm::DominatorTreeBase< BasicBlock, false >::Insert, llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::BlockAddress::lookup(), llvm::ProfcheckDisableMetadataFixes, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::seq(), llvm::setExplicitlyUnknownBranchWeightsIfProfiled(), llvm::setFittedBranchWeights(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::size(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::IndirectBrInst::successors(), llvm::sum_of(), uint64_t, and llvm::zip_equal().

Variable Documentation

◆ DEBUG_TYPE

DEBUG_TYPE

Definition at line 114 of file IndirectBrExpandPass.cpp.

◆ false

Expand indirectbr false

Definition at line 115 of file IndirectBrExpandPass.cpp.

◆ instructions

Expand indirectbr instructions

Definition at line 115 of file IndirectBrExpandPass.cpp.