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/Pass.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Compiler.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.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")
FunctionPassllvm::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 bool MergeInType (const Type *In, const Type *&Accum, const TargetData &TD)
const TypegetIntAtLeastAsBigAs (unsigned NumBits)
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 461 of file ScalarReplAggregates.cpp.

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

const Type* getIntAtLeastAsBigAs ( unsigned  NumBits  ) 

getIntAtLeastAsBigAs - Return an integer type that is at least as big as the specified type. If there is no suitable type, this returns null.

Definition at line 1108 of file ScalarReplAggregates.cpp.

static uint64_t getNumSAElements ( const Type T  )  [static]

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

Definition at line 193 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 908 of file ScalarReplAggregates.cpp.

References llvm::TargetData::getABITypeSizeInBits(), llvm::StructLayout::getElementOffsetInBits(), llvm::SequentialType::getElementType(), llvm::TargetData::getStructLayout(), 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 1545 of file ScalarReplAggregates.cpp.

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

static bool MergeInType ( const Type In,
const Type *&  Accum,
const TargetData TD 
) [static]

MergeInType - Add the 'In' type to the accumulated type so far. If the types are incompatible, return true, otherwise update Accum and return false.

There are three cases we handle here: 1) An effectively-integer union, where the pieces are stored into as smaller integers (common with byte swap and other idioms). 2) A union of vector types of the same size and potentially its elements. Here we turn element accesses into insert/extract element operations. 3) A union of scalar types, such as int/float or int/pointer. Here we merge together into integers, allowing the xform to work with #1 as well.

Definition at line 1045 of file ScalarReplAggregates.cpp.

References llvm::VectorType::getBitWidth(), llvm::SequentialType::getElementType(), llvm::TargetData::getIntPtrType(), llvm::Type::getTypeID(), and llvm::Type::isInteger().

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 1528 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 50 of file ScalarReplAggregates.cpp.

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

Definition at line 90 of file ScalarReplAggregates.cpp.

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

Definition at line 87 of file ScalarReplAggregates.cpp.

bool isUnsafe

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

Definition at line 80 of file ScalarReplAggregates.cpp.

bool needsCanon

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

Definition at line 84 of file ScalarReplAggregates.cpp.

Definition at line 97 of file ScalarReplAggregates.cpp.

Definition at line 73 of file ScalarReplAggregates.cpp.

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




This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.