LLVM API Documentation

ScalarReplAggregates.cpp File Reference

#include "llvm/Transforms/Scalar.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Instructions.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/LLVMContext.h"
#include "llvm/Pass.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/IRBuilder.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Compiler.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.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 (NumConverted,"Number of aggregates converted to scalar")
 STATISTIC (NumGlobals,"Number of allocas copied from constant global")
FunctionPass * llvm::createScalarReplAggregatesPass (signed int Threshold)
static uint64_t getNumSAElements (const Type *T)
static bool AllUsersAreLoads (Value *Ptr)
 AllUsersAreLoads - Return true if all users of this value are loads.
static bool HasPadding (const Type *Ty, const TargetData &TD)
static void MergeInType (const Type *In, uint64_t Offset, const Type *&VecTy, unsigned AllocaSize, const TargetData &TD, LLVMContext &Context)
static bool PointsToConstantGlobal (Value *V)
static bool isOnlyCopiedFromConstantGlobal (Value *V, Instruction *&TheCopy, bool isOffset)

Variables

static RegisterPass< SROA > X ("scalarrepl","Scalar Replacement of Aggregates")


Define Documentation

#define DEBUG_TYPE   "scalarrepl"

Definition at line 22 of file ScalarReplAggregates.cpp.


Function Documentation

static bool AllUsersAreLoads ( Value *  Ptr  )  [static]

AllUsersAreLoads - Return true if all users of this value are loads.

Definition at line 511 of file ScalarReplAggregates.cpp.

References E, Load, llvm::Value::use_begin(), and llvm::Value::use_end().

static uint64_t getNumSAElements ( const Type *  T  )  [static]

getNumSAElements - Return the number of elements in the specific struct or array.

Definition at line 205 of file ScalarReplAggregates.cpp.

static bool HasPadding ( const Type *  Ty,
const TargetData &  TD 
) [static]

HasPadding - Return true if the specified type has any structure or alignment padding, false otherwise.

Definition at line 1119 of file ScalarReplAggregates.cpp.

References llvm::StructLayout::getElementOffsetInBits(), llvm::SequentialType::getElementType(), llvm::TargetData::getStructLayout(), llvm::TargetData::getTypeAllocSizeInBits(), and llvm::TargetData::getTypeSizeInBits().

static bool isOnlyCopiedFromConstantGlobal ( Value *  V,
Instruction *&  TheCopy,
bool  isOffset 
) [static]

isOnlyCopiedFromConstantGlobal - Recursively walk the uses of a (derived) pointer to an alloca. Ignore any reads of the pointer, return false if we see any stores or other unknown uses. If we see pointer arithmetic, keep track of whether it moves the pointer (with isOffset) but otherwise traverse the uses. If we see a memcpy/memmove that targets an unoffseted pointer to the alloca, and if the source pointer is a pointer to a constant global, we can optimize this.

Definition at line 1800 of file ScalarReplAggregates.cpp.

References E, llvm::User::getOperand(), llvm::GetElementPtrInst::hasAllZeroIndices(), llvm::LoadInst::isVolatile(), PointsToConstantGlobal(), llvm::Value::use_begin(), and llvm::Value::use_end().

static void MergeInType ( const Type *  In,
uint64_t  Offset,
const Type *&  VecTy,
unsigned  AllocaSize,
const TargetData &  TD,
LLVMContext &  Context 
) [static]

MergeInType - Add the 'In' type to the accumulated type (Accum) so far at the offset specified by Offset (which is specified in bytes).

There are two cases we handle here: 1) A union of vector types of the same size and potentially its elements. Here we turn element accesses into insert/extract element operations. This promotes a <4 x float> with a store of float to the third element into a <4 x float> that uses insert element. 2) A fully general blob of memory, which we turn into some (potentially large) integer type with extract and insert operations where the loads and stores would mutate the memory.

Definition at line 1279 of file ScalarReplAggregates.cpp.

References llvm::Type::getPrimitiveSizeInBits(), and llvm::isPowerOf2_32().

static bool PointsToConstantGlobal ( Value *  V  )  [static]

PointsToConstantGlobal - Return true if V (possibly indirectly) points to some part of a constant global variable. This intentionally only accepts constant expressions because we don't can't rewrite arbitrary instructions.

Definition at line 1783 of file ScalarReplAggregates.cpp.

References BitCast, llvm::BinaryOperator::getOpcode(), and GV.

Referenced by isOnlyCopiedFromConstantGlobal().

STATISTIC ( NumGlobals  ,
"Number of allocas copied from constant global"   
)

STATISTIC ( NumConverted  ,
"Number of aggregates converted to scalar"   
)

STATISTIC ( NumPromoted  ,
"Number of allocas promoted"   
)

STATISTIC ( NumReplaced  ,
"Number of allocas broken up"   
)


Variable Documentation

char ID [static]

Definition at line 53 of file ScalarReplAggregates.cpp.

isMemCpyDst - This is true if this aggregate is memcpy'd into.

Definition at line 92 of file ScalarReplAggregates.cpp.

isMemCpySrc - This is true if this aggregate is memcpy'd from.

Definition at line 89 of file ScalarReplAggregates.cpp.

isUnsafe - This is set to true if the alloca cannot be SROA'd.

Definition at line 82 of file ScalarReplAggregates.cpp.

needsCleanup - This is set to true if there is some use of the alloca that requires cleanup.

Definition at line 86 of file ScalarReplAggregates.cpp.

Definition at line 99 of file ScalarReplAggregates.cpp.

Definition at line 75 of file ScalarReplAggregates.cpp.

RegisterPass<SROA> X("scalarrepl","Scalar Replacement of Aggregates") [static]