LLVM API Documentation

Reassociate.cpp File Reference

#include "llvm/Transforms/Scalar.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/LLVMContext.h"
#include "llvm/Pass.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ValueHandle.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/Statistic.h"
#include <algorithm>
#include <map>

Include dependency graph for Reassociate.cpp:

Go to the source code of this file.

Defines

#define DEBUG_TYPE   "reassociate"

Functions

 STATISTIC (NumLinear,"Number of insts linearized")
 STATISTIC (NumChanged,"Number of insts reassociated")
 STATISTIC (NumAnnihil,"Number of expr tree annihilated")
 STATISTIC (NumFactor,"Number of multiplies factored")
bool operator< (const ValueEntry &LHS, const ValueEntry &RHS)
static void PrintOps (Instruction *I, const std::vector< ValueEntry > &Ops)
FunctionPass * llvm::createReassociatePass ()
static bool isUnmovableInstruction (Instruction *I)
static BinaryOperator * isReassociableOp (Value *V, unsigned Opcode)
static Instruction * LowerNegateToMultiply (Instruction *Neg, std::map< AssertingVH<>, unsigned > &ValueRankMap, LLVMContext &Context)
static Value * NegateValue (LLVMContext &Context, Value *V, Instruction *BI)
static bool ShouldBreakUpSubtract (LLVMContext &Context, Instruction *Sub)
static Instruction * BreakUpSubtract (LLVMContext &Context, Instruction *Sub, std::map< AssertingVH<>, unsigned > &ValueRankMap)
static Instruction * ConvertShiftToMul (Instruction *Shl, std::map< AssertingVH<>, unsigned > &ValueRankMap, LLVMContext &Context)
static unsigned FindInOperandList (std::vector< ValueEntry > &Ops, unsigned i, Value *X)
static Value * EmitAddTreeOfValues (Instruction *I, std::vector< Value * > &Ops)
static void FindSingleUseMultiplyFactors (Value *V, std::vector< Value * > &Factors)

Variables

static RegisterPass< Reassociate > X ("reassociate","Reassociate expressions")


Define Documentation

#define DEBUG_TYPE   "reassociate"

Definition at line 23 of file Reassociate.cpp.


Function Documentation

static Instruction* BreakUpSubtract ( LLVMContext &  Context,
Instruction *  Sub,
std::map< AssertingVH<>, unsigned > &  ValueRankMap 
) [static]

BreakUpSubtract - If we have (X-Y), and if either X is an add, or if this is only used by an add, transform this into (X+(0-Y)) to promote better reassociation.

Definition at line 435 of file Reassociate.cpp.

References DOUT, llvm::Instruction::eraseFromParent(), llvm::User::getOperand(), NegateValue(), llvm::Value::replaceAllUsesWith(), llvm::Value::takeName(), and ValueRankMap.

static Instruction* ConvertShiftToMul ( Instruction *  Shl,
std::map< AssertingVH<>, unsigned > &  ValueRankMap,
LLVMContext &  Context 
) [static]

ConvertShiftToMul - If this is a shift of a reassociable multiply or is used by one, change this into a multiply by a constant to assist with further reassociation.

Definition at line 460 of file Reassociate.cpp.

References llvm::Instruction::eraseFromParent(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Value::hasOneUse(), isReassociableOp(), llvm::Value::replaceAllUsesWith(), llvm::Value::takeName(), llvm::Instruction::use_back(), and ValueRankMap.

static Value* EmitAddTreeOfValues ( Instruction *  I,
std::vector< Value * > &  Ops 
) [static]

EmitAddTreeOfValues - Emit a tree of add instructions, summing Ops together and returning the result. Insert the tree before I.

Definition at line 502 of file Reassociate.cpp.

References V1.

static unsigned FindInOperandList ( std::vector< ValueEntry > &  Ops,
unsigned  i,
Value *  X 
) [static]

Definition at line 486 of file Reassociate.cpp.

static void FindSingleUseMultiplyFactors ( Value *  V,
std::vector< Value * > &  Factors 
) [static]

FindSingleUseMultiplyFactors - If V is a single-use multiply, recursively add its operands as factors, otherwise add V to the list of factors.

Definition at line 542 of file Reassociate.cpp.

References llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::hasOneUse(), and llvm::Value::use_empty().

static BinaryOperator* isReassociableOp ( Value *  V,
unsigned  Opcode 
) [static]

isReassociableOp - Return true if V is an instruction of the specified opcode and if it only has one use.

Definition at line 192 of file Reassociate.cpp.

References llvm::Value::hasOneUse(), and llvm::Value::use_empty().

Referenced by ConvertShiftToMul(), and ShouldBreakUpSubtract().

static bool isUnmovableInstruction ( Instruction *  I  )  [static]

Definition at line 120 of file Reassociate.cpp.

References Call, llvm::Instruction::getOpcode(), Load, Malloc, and PHI.

static Instruction* LowerNegateToMultiply ( Instruction *  Neg,
std::map< AssertingVH<>, unsigned > &  ValueRankMap,
LLVMContext &  Context 
) [static]

LowerNegateToMultiply - Replace 0-X with X*-1.

Definition at line 201 of file Reassociate.cpp.

References llvm::Instruction::eraseFromParent(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Value::replaceAllUsesWith(), and ValueRankMap.

static Value* NegateValue ( LLVMContext &  Context,
Value *  V,
Instruction *  BI 
) [static]

Definition at line 377 of file Reassociate.cpp.

References llvm::Value::getName(), and llvm::Value::setName().

Referenced by BreakUpSubtract().

bool @1363::operator< ( const ValueEntry &  LHS,
const ValueEntry &  RHS 
) [inline, static]

Definition at line 54 of file Reassociate.cpp.

static void PrintOps ( Instruction *  I,
const std::vector< ValueEntry > &  Ops 
) [static]

PrintOps - Print out the expression identified in the Ops list.

Definition at line 62 of file Reassociate.cpp.

References llvm::cerr(), and llvm::WriteAsOperand().

static bool ShouldBreakUpSubtract ( LLVMContext &  Context,
Instruction *  Sub 
) [static]

ShouldBreakUpSubtract - Return true if we should break up this subtract of X-Y into (X + -Y).

Definition at line 411 of file Reassociate.cpp.

References llvm::User::getOperand(), llvm::Value::hasOneUse(), isReassociableOp(), and llvm::Instruction::use_back().

STATISTIC ( NumFactor  ,
"Number of multiplies factored"   
)

STATISTIC ( NumAnnihil  ,
"Number of expr tree annihilated"   
)

STATISTIC ( NumChanged  ,
"Number of insts reassociated"   
)

STATISTIC ( NumLinear  ,
"Number of insts linearized"   
)


Variable Documentation

char ID [static]

Definition at line 79 of file Reassociate.cpp.

Definition at line 77 of file Reassociate.cpp.

Definition at line 51 of file Reassociate.cpp.

Definition at line 50 of file Reassociate.cpp.

Definition at line 75 of file Reassociate.cpp.

Definition at line 76 of file Reassociate.cpp.

Referenced by BreakUpSubtract(), ConvertShiftToMul(), and LowerNegateToMultiply().

RegisterPass<Reassociate> X("reassociate","Reassociate expressions") [static]