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/Pass.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Debug.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/Statistic.h"
#include <algorithm>
#include <iostream>

Include dependency graph for Reassociate.cpp:

Go to the source code of this file.

Defines

#define DEBUG_TYPE   "reassociate"

Functions

bool operator< (const ValueEntry &LHS, const ValueEntry &RHS)
static void PrintOps (Instruction *I, const std::vector< ValueEntry > &Ops)
FunctionPassllvm::createReassociatePass ()
static bool isUnmovableInstruction (Instruction *I)
static BinaryOperatorisReassociableOp (Value *V, unsigned Opcode)
static InstructionLowerNegateToMultiply (Instruction *Neg)
static ValueNegateValue (Value *V, Instruction *BI)
static InstructionBreakUpSubtract (Instruction *Sub)
static InstructionConvertShiftToMul (Instruction *Shl)
static unsigned FindInOperandList (std::vector< ValueEntry > &Ops, unsigned i, Value *X)
static ValueEmitAddTreeOfValues (Instruction *I, std::vector< Value * > &Ops)
static void FindSingleUseMultiplyFactors (Value *V, std::vector< Value * > &Factors)

Variables

Statistic NumLinear ("reassociate","Number of insts linearized")
Statistic NumChanged ("reassociate","Number of insts reassociated")
Statistic NumSwapped ("reassociate","Number of insts with operands swapped")
Statistic NumAnnihil ("reassociate","Number of expr tree annihilated")
Statistic NumFactor ("reassociate","Number of multiplies factored")
RegisterOpt< Reassociate > X ("reassociate","Reassociate expressions")


Define Documentation

#define DEBUG_TYPE   "reassociate"

Definition at line 23 of file Reassociate.cpp.


Function Documentation

static Instruction* BreakUpSubtract ( Instruction Sub  )  [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 394 of file Reassociate.cpp.

References DEBUG, llvm::Instruction::eraseFromParent(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Value::hasOneUse(), isReassociableOp(), Name, NegateValue(), llvm::Value::replaceAllUsesWith(), llvm::Value::setName(), and llvm::Value::use_back().

static Instruction* ConvertShiftToMul ( Instruction Shl  )  [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 425 of file Reassociate.cpp.

References llvm::Instruction::eraseFromParent(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Value::hasOneUse(), isReassociableOp(), Name, llvm::Value::replaceAllUsesWith(), llvm::Value::setName(), and llvm::Value::use_back().

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 463 of file Reassociate.cpp.

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

Definition at line 447 of file Reassociate.cpp.

References Op, U, and X.

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 503 of file Reassociate.cpp.

References llvm::BinaryOperator::getOpcode(), llvm::BinaryOperator::getOperand(), and V.

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 176 of file Reassociate.cpp.

References V.

Referenced by BreakUpSubtract(), and ConvertShiftToMul().

static bool isUnmovableInstruction ( Instruction I  )  [static]

Definition at line 109 of file Reassociate.cpp.

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

static Instruction* LowerNegateToMultiply ( Instruction Neg  )  [static]

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

Definition at line 185 of file Reassociate.cpp.

References llvm::Instruction::eraseFromParent(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Type::isFloatingPoint(), llvm::Value::replaceAllUsesWith(), and llvm::Value::setName().

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

Definition at line 359 of file Reassociate.cpp.

References llvm::Value::getName(), llvm::BinaryOperator::getOpcode(), llvm::BinaryOperator::getOperand(), llvm::Value::hasOneUse(), llvm::Instruction::moveBefore(), llvm::Value::setName(), llvm::BinaryOperator::setOperand(), and V.

Referenced by BreakUpSubtract().

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

Definition at line 51 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 58 of file Reassociate.cpp.

References llvm::Instruction::getOpcode(), llvm::GlobalValue::getParent(), llvm::BasicBlock::getParent(), llvm::Instruction::getParent(), M, Op, and llvm::WriteAsOperand().


Variable Documentation

bool MadeChange

Definition at line 71 of file Reassociate.cpp.

Statistic NumAnnihil("reassociate","Number of expr tree annihilated") [static]

Statistic NumChanged("reassociate","Number of insts reassociated") [static]

Statistic NumFactor("reassociate","Number of multiplies factored") [static]

Statistic NumLinear("reassociate","Number of insts linearized") [static]

Statistic NumSwapped("reassociate","Number of insts with operands swapped") [static]

Value* Op

Definition at line 48 of file Reassociate.cpp.

unsigned Rank

Definition at line 47 of file Reassociate.cpp.

std::map<BasicBlock*, unsigned> RankMap

Definition at line 69 of file Reassociate.cpp.

std::map<Value*, unsigned> ValueRankMap

Definition at line 70 of file Reassociate.cpp.

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