class SROAPass

Declaration

class SROAPass : public PassInfoMixin { /* full declaration omitted */ };

Description

An optimization pass providing Scalar Replacement of Aggregates. This pass takes allocations which can be completely analyzed (that is, they don't escape) and tries to turn them into scalar SSA values. There are a few steps to this process. 1) It takes allocations of aggregates and analyzes the ways in which they are used to try to split them into smaller allocations, ideally of a single scalar data type. It will split up memcpy and memset accesses as necessary and try to isolate individual scalar accesses. 2) It will transform accesses into forms which are suitable for SSA value promotion. This can be replacing a memset with a scalar store of an integer value, or it can involve speculating operations on a PHI or select to be a PHI or select of the results. 3) Finally, this will try to detect a pattern of accesses which map cleanly onto insert and extract operations on a vector value, and convert them to this form. By doing so, it will enable promotion of vector aggregates to SSA vector values.

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:64

Inherits from: PassInfoMixin

Member Variables

private llvm::LLVMContext* C = nullptr
private llvm::DominatorTree* DT = nullptr
private llvm::AssumptionCache* AC = nullptr
private SetVector<llvm::AllocaInst*, SmallVector<llvm::AllocaInst*, 16>> Worklist
Each alloca in the function is added to this. Each new alloca formed gets added to it as well to recursively simplify unless that alloca can be directly promoted. Finally, each time we rewrite a use of an alloca other the one being actively rewritten, we add it back onto the list if not already present to ensure it is re-visited.
private SmallVector<llvm::WeakVH, 8> DeadInsts
A collection of instructions to delete. We try to batch deletions to simplify code and make things a bit more efficient. We also make sure there is no dangling pointers.
private SetVector<llvm::AllocaInst*, SmallVector<llvm::AllocaInst*, 16>> PostPromotionWorklist
Note that we have to be very careful to clear allocas out of this list in the event they are deleted.
private std::vector<AllocaInst*> PromotableAllocas
A collection of alloca instructions we can directly promote.
private SetVector<llvm::PHINode*, SmallVector<llvm::PHINode*, 2>> SpeculatablePHIs
All of these PHIs have been checked for the safety of speculation and by being speculated will allow promoting allocas currently in the promotable queue.
private SetVector<llvm::SelectInst*, SmallVector<llvm::SelectInst*, 2>> SpeculatableSelects
All of these select instructions have been checked for the safety of speculation and by being speculated will allow promoting allocas currently in the promotable queue.

Method Overview

  • public SROAPass()
  • private void clobberUse(llvm::Use & U)
  • private bool deleteDeadInstructions(SmallPtrSetImpl<llvm::AllocaInst *> & DeletedAllocas)
  • private bool presplitLoadsAndStores(llvm::AllocaInst & AI, sroa::AllocaSlices & AS)
  • private bool promoteAllocas(llvm::Function & F)
  • private llvm::AllocaInst * rewritePartition(llvm::AllocaInst & AI, sroa::AllocaSlices & AS, sroa::Partition & P)
  • public llvm::PreservedAnalyses run(llvm::Function & F, llvm::FunctionAnalysisManager & AM)
  • private llvm::PreservedAnalyses runImpl(llvm::Function & F, llvm::DominatorTree & RunDT, llvm::AssumptionCache & RunAC)
  • private bool runOnAlloca(llvm::AllocaInst & AI)
  • private bool splitAlloca(llvm::AllocaInst & AI, sroa::AllocaSlices & AS)

Methods

SROAPass()

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:112

void clobberUse(llvm::Use& U)

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:130

Parameters

llvm::Use& U

bool deleteDeadInstructions(
    SmallPtrSetImpl<llvm::AllocaInst*>&
        DeletedAllocas)

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:131

Parameters

SmallPtrSetImpl<llvm::AllocaInst*>& DeletedAllocas

bool presplitLoadsAndStores(
    llvm::AllocaInst& AI,
    sroa::AllocaSlices& AS)

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:125

Parameters

llvm::AllocaInst& AI
sroa::AllocaSlices& AS

bool promoteAllocas(llvm::Function& F)

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:132

Parameters

llvm::Function& F

llvm::AllocaInst* rewritePartition(
    llvm::AllocaInst& AI,
    sroa::AllocaSlices& AS,
    sroa::Partition& P)

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:126

Parameters

llvm::AllocaInst& AI
sroa::AllocaSlices& AS
sroa::Partition& P

llvm::PreservedAnalyses run(
    llvm::Function& F,
    llvm::FunctionAnalysisManager& AM)

Description

Run the pass over the function.

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:115

Parameters

llvm::Function& F
llvm::FunctionAnalysisManager& AM

llvm::PreservedAnalyses runImpl(
    llvm::Function& F,
    llvm::DominatorTree& RunDT,
    llvm::AssumptionCache& RunAC)

Description

Helper used by both the public run method and by the legacy pass.

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:122

Parameters

llvm::Function& F
llvm::DominatorTree& RunDT
llvm::AssumptionCache& RunAC

bool runOnAlloca(llvm::AllocaInst& AI)

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:129

Parameters

llvm::AllocaInst& AI

bool splitAlloca(llvm::AllocaInst& AI,
                 sroa::AllocaSlices& AS)

Declared at: llvm/include/llvm/Transforms/Scalar/SROA.h:128

Parameters

llvm::AllocaInst& AI
sroa::AllocaSlices& AS