LLVM API Documentation

Defines | Functions | Variables
ScalarReplAggregates.cpp File Reference
#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AssumptionTracker.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/Pass.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/Utils/Local.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
Include dependency graph for ScalarReplAggregates.cpp:

Go to the source code of this file.

Defines

#define DEBUG_TYPE   "scalarrepl"

Functions

 STATISTIC (NumReplaced,"Number of allocas broken up")
 STATISTIC (NumPromoted,"Number of allocas promoted")
 STATISTIC (NumAdjusted,"Number of scalar allocas adjusted to allow promotion")
 STATISTIC (NumConverted,"Number of aggregates converted to scalar")
 INITIALIZE_PASS_BEGIN (SROA_DT,"scalarrepl","Scalar Replacement of Aggregates (DT)", false, false) INITIALIZE_PASS_END(SROA_DT
Scalar Replacement of Aggregates (DT)"
Scalar Replacement of false INITIALIZE_PASS_BEGIN (SROA_SSAUp,"scalarrepl-ssa","Scalar Replacement of Aggregates (SSAUp)", false, false) INITIALIZE_PASS_END(SROA_SSAUp
Scalar Replacement of false
scalarrepl Scalar Replacement
of 
Aggregates (SSAUp)"
static bool isSafeSelectToSpeculate (SelectInst *SI, const DataLayout *DL)
static bool isSafePHIToSpeculate (PHINode *PN, const DataLayout *DL)
static bool tryToMakeAllocaBePromotable (AllocaInst *AI, const DataLayout *DL)
static bool isHomogeneousAggregate (Type *T, unsigned &NumElts, Type *&EltTy)
static bool isCompatibleAggregate (Type *T1, Type *T2)
static bool HasPadding (Type *Ty, const DataLayout &DL)

Variables

 scalarrepl
Scalar Replacement of false
Scalar Replacement of false
scalarrepl 
ssa

Define Documentation

#define DEBUG_TYPE   "scalarrepl"

Definition at line 55 of file ScalarReplAggregates.cpp.


Function Documentation

Scalar Replacement of Aggregates ( DT  )
Scalar Replacement of false scalarrepl Scalar Replacement of Aggregates ( SSAUp  )
static bool HasPadding ( Type Ty,
const DataLayout DL 
) [static]

HasPadding - Return true if the specified type has any structure or alignment padding in between the elements that would be split apart by SROA; return false otherwise.

Definition at line 2542 of file ScalarReplAggregates.cpp.

References llvm::StructLayout::getElementOffsetInBits(), llvm::StructType::getElementType(), llvm::SequentialType::getElementType(), llvm::StructType::getNumElements(), llvm::DataLayout::getStructLayout(), llvm::DataLayout::getTypeAllocSizeInBits(), and llvm::DataLayout::getTypeSizeInBits().

INITIALIZE_PASS_BEGIN ( SROA_DT  ,
"scalarrepl"  ,
"Scalar Replacement of Aggregates (DT)"  ,
false  ,
false   
)
Scalar Replacement of false INITIALIZE_PASS_BEGIN ( SROA_SSAUp  ,
"scalarrepl-ssa ,
"Scalar Replacement of Aggregates (SSAUp)"  ,
false  ,
false   
)
static bool isCompatibleAggregate ( Type T1,
Type T2 
) [static]

isCompatibleAggregate - Check if T1 and T2 are either the same type or are "homogeneous" aggregates with the same element type and number of elements.

Definition at line 1777 of file ScalarReplAggregates.cpp.

References isHomogeneousAggregate().

static bool isHomogeneousAggregate ( Type T,
unsigned NumElts,
Type *&  EltTy 
) [static]

isHomogeneousAggregate - Check if type T is a struct or array containing elements of the same type (which is always true for arrays). If so, return true with NumElts and EltTy set to the number of elements and the element type, respectively.

Definition at line 1756 of file ScalarReplAggregates.cpp.

References llvm::SequentialType::getElementType(), and llvm::ArrayType::getNumElements().

Referenced by isCompatibleAggregate().

static bool isSafePHIToSpeculate ( PHINode PN,
const DataLayout DL 
) [static]

isSafePHIToSpeculate - PHI instructions that use an alloca and are subsequently loaded can be rewritten to load both input pointers in the pred blocks and then PHI the results, allowing the load of the alloca to be promoted. From this: P2 = phi [i32* Alloca, i32* Other] V = load i32* P2 to: V1 = load i32* Alloca -> will be mem2reg'd ... V2 = load i32* Other ... V = phi [i32 V1, i32 V2]

We can do this to a select if its only uses are loads and if the operand to the select can be loaded unconditionally.

Definition at line 1186 of file ScalarReplAggregates.cpp.

References llvm::dyn_cast(), llvm::LoadInst::getAlignment(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::TerminatorInst::getNumSuccessors(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::isDereferenceablePointer(), llvm::isSafeToLoadUnconditionally(), llvm::LoadInst::isSimple(), LI, llvm::Instruction::mayHaveSideEffects(), and llvm::Value::users().

Referenced by tryToMakeAllocaBePromotable().

static bool isSafeSelectToSpeculate ( SelectInst SI,
const DataLayout DL 
) [static]

isSafeSelectToSpeculate - Select instructions that use an alloca and are subsequently loaded can be rewritten to load both input pointers and then select between the result, allowing the load of the alloca to be promoted. From this: P2 = select i1 cond, i32* Alloca, i32* Other V = load i32* P2 to: V1 = load i32* Alloca -> will be mem2reg'd V2 = load i32* Other V = select i1 cond, i32 V1, i32 V2

We can do this to a select if its only uses are loads and if the operand to the select can be loaded unconditionally.

Definition at line 1149 of file ScalarReplAggregates.cpp.

References llvm::dyn_cast(), llvm::LoadInst::getAlignment(), llvm::SelectInst::getFalseValue(), llvm::SelectInst::getTrueValue(), llvm::Value::isDereferenceablePointer(), llvm::isSafeToLoadUnconditionally(), llvm::LoadInst::isSimple(), LI, and llvm::Value::users().

Referenced by tryToMakeAllocaBePromotable().

STATISTIC ( NumReplaced  ,
"Number of allocas broken up"   
)
STATISTIC ( NumPromoted  ,
"Number of allocas promoted"   
)
STATISTIC ( NumAdjusted  ,
"Number of scalar allocas adjusted to allow promotion  
)
STATISTIC ( NumConverted  ,
"Number of aggregates converted to scalar"   
)
static bool tryToMakeAllocaBePromotable ( AllocaInst AI,
const DataLayout DL 
) [static]

Variable Documentation

Scalar Replacement of false scalarrepl Scalar Replacement of false

Definition at line 234 of file ScalarReplAggregates.cpp.

Definition at line 233 of file ScalarReplAggregates.cpp.

Scalar Replacement of false scalarrepl ssa

Definition at line 239 of file ScalarReplAggregates.cpp.