forked from OSchip/llvm-project
don't repeat function names in comments; NFC
llvm-svn: 235531
This commit is contained in:
parent
67e82482c0
commit
c96ee08016
|
|
@ -59,7 +59,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
/// PrintOps - Print out the expression identified in the Ops list.
|
/// Print out the expression identified in the Ops list.
|
||||||
///
|
///
|
||||||
static void PrintOps(Instruction *I, const SmallVectorImpl<ValueEntry> &Ops) {
|
static void PrintOps(Instruction *I, const SmallVectorImpl<ValueEntry> &Ops) {
|
||||||
Module *M = I->getParent()->getParent()->getParent();
|
Module *M = I->getParent()->getParent()->getParent();
|
||||||
|
|
@ -233,8 +233,8 @@ INITIALIZE_PASS(Reassociate, "reassociate",
|
||||||
// Public interface to the Reassociate pass
|
// Public interface to the Reassociate pass
|
||||||
FunctionPass *llvm::createReassociatePass() { return new Reassociate(); }
|
FunctionPass *llvm::createReassociatePass() { return new Reassociate(); }
|
||||||
|
|
||||||
/// isReassociableOp - Return true if V is an instruction of the specified
|
/// Return true if V is an instruction of the specified opcode and if it
|
||||||
/// opcode and if it only has one use.
|
/// only has one use.
|
||||||
static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) {
|
static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) {
|
||||||
if (V->hasOneUse() && isa<Instruction>(V) &&
|
if (V->hasOneUse() && isa<Instruction>(V) &&
|
||||||
cast<Instruction>(V)->getOpcode() == Opcode &&
|
cast<Instruction>(V)->getOpcode() == Opcode &&
|
||||||
|
|
@ -382,8 +382,7 @@ static BinaryOperator *CreateNeg(Value *S1, const Twine &Name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// LowerNegateToMultiply - Replace 0-X with X*-1.
|
/// Replace 0-X with X*-1.
|
||||||
///
|
|
||||||
static BinaryOperator *LowerNegateToMultiply(Instruction *Neg) {
|
static BinaryOperator *LowerNegateToMultiply(Instruction *Neg) {
|
||||||
Type *Ty = Neg->getType();
|
Type *Ty = Neg->getType();
|
||||||
Constant *NegOne = Ty->isIntOrIntVectorTy() ?
|
Constant *NegOne = Ty->isIntOrIntVectorTy() ?
|
||||||
|
|
@ -397,8 +396,8 @@ static BinaryOperator *LowerNegateToMultiply(Instruction *Neg) {
|
||||||
return Res;
|
return Res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CarmichaelShift - Returns k such that lambda(2^Bitwidth) = 2^k, where lambda
|
/// Returns k such that lambda(2^Bitwidth) = 2^k, where lambda is the Carmichael
|
||||||
/// is the Carmichael function. This means that x^(2^k) === 1 mod 2^Bitwidth for
|
/// function. This means that x^(2^k) === 1 mod 2^Bitwidth for
|
||||||
/// every odd x, i.e. x^(2^k) = 1 for every odd x in Bitwidth-bit arithmetic.
|
/// every odd x, i.e. x^(2^k) = 1 for every odd x in Bitwidth-bit arithmetic.
|
||||||
/// Note that 0 <= k < Bitwidth, and if Bitwidth > 3 then x^(2^k) = 0 for every
|
/// Note that 0 <= k < Bitwidth, and if Bitwidth > 3 then x^(2^k) = 0 for every
|
||||||
/// even x in Bitwidth-bit arithmetic.
|
/// even x in Bitwidth-bit arithmetic.
|
||||||
|
|
@ -408,7 +407,7 @@ static unsigned CarmichaelShift(unsigned Bitwidth) {
|
||||||
return Bitwidth - 2;
|
return Bitwidth - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// IncorporateWeight - Add the extra weight 'RHS' to the existing weight 'LHS',
|
/// Add the extra weight 'RHS' to the existing weight 'LHS',
|
||||||
/// reducing the combined weight using any special properties of the operation.
|
/// reducing the combined weight using any special properties of the operation.
|
||||||
/// The existing weight LHS represents the computation X op X op ... op X where
|
/// The existing weight LHS represents the computation X op X op ... op X where
|
||||||
/// X occurs LHS times. The combined weight represents X op X op ... op X with
|
/// X occurs LHS times. The combined weight represents X op X op ... op X with
|
||||||
|
|
@ -490,7 +489,7 @@ static void IncorporateWeight(APInt &LHS, const APInt &RHS, unsigned Opcode) {
|
||||||
|
|
||||||
typedef std::pair<Value*, APInt> RepeatedValue;
|
typedef std::pair<Value*, APInt> RepeatedValue;
|
||||||
|
|
||||||
/// LinearizeExprTree - Given an associative binary expression, return the leaf
|
/// Given an associative binary expression, return the leaf
|
||||||
/// nodes in Ops along with their weights (how many times the leaf occurs). The
|
/// nodes in Ops along with their weights (how many times the leaf occurs). The
|
||||||
/// original expression is the same as
|
/// original expression is the same as
|
||||||
/// (Ops[0].first op Ops[0].first op ... Ops[0].first) <- Ops[0].second times
|
/// (Ops[0].first op Ops[0].first op ... Ops[0].first) <- Ops[0].second times
|
||||||
|
|
@ -740,8 +739,8 @@ static bool LinearizeExprTree(BinaryOperator *I,
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RewriteExprTree - Now that the operands for this expression tree are
|
/// Now that the operands for this expression tree are
|
||||||
// linearized and optimized, emit them in-order.
|
/// linearized and optimized, emit them in-order.
|
||||||
void Reassociate::RewriteExprTree(BinaryOperator *I,
|
void Reassociate::RewriteExprTree(BinaryOperator *I,
|
||||||
SmallVectorImpl<ValueEntry> &Ops) {
|
SmallVectorImpl<ValueEntry> &Ops) {
|
||||||
assert(Ops.size() > 1 && "Single values should be used directly!");
|
assert(Ops.size() > 1 && "Single values should be used directly!");
|
||||||
|
|
@ -910,7 +909,7 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
|
||||||
RedoInsts.insert(NodesToRewrite[i]);
|
RedoInsts.insert(NodesToRewrite[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NegateValue - Insert instructions before the instruction pointed to by BI,
|
/// Insert instructions before the instruction pointed to by BI,
|
||||||
/// that computes the negative version of the value specified. The negative
|
/// that computes the negative version of the value specified. The negative
|
||||||
/// version of the value is returned, and BI is left pointing at the instruction
|
/// version of the value is returned, and BI is left pointing at the instruction
|
||||||
/// that should be processed next by the reassociation pass.
|
/// that should be processed next by the reassociation pass.
|
||||||
|
|
@ -985,8 +984,7 @@ static Value *NegateValue(Value *V, Instruction *BI) {
|
||||||
return CreateNeg(V, V->getName() + ".neg", BI, BI);
|
return CreateNeg(V, V->getName() + ".neg", BI, BI);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ShouldBreakUpSubtract - Return true if we should break up this subtract of
|
/// Return true if we should break up this subtract of X-Y into (X + -Y).
|
||||||
/// X-Y into (X + -Y).
|
|
||||||
static bool ShouldBreakUpSubtract(Instruction *Sub) {
|
static bool ShouldBreakUpSubtract(Instruction *Sub) {
|
||||||
// If this is a negation, we can't split it up!
|
// If this is a negation, we can't split it up!
|
||||||
if (BinaryOperator::isNeg(Sub) || BinaryOperator::isFNeg(Sub))
|
if (BinaryOperator::isNeg(Sub) || BinaryOperator::isFNeg(Sub))
|
||||||
|
|
@ -1015,9 +1013,8 @@ static bool ShouldBreakUpSubtract(Instruction *Sub) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// BreakUpSubtract - If we have (X-Y), and if either X is an add, or if this is
|
/// If we have (X-Y), and if either X is an add, or if this is only used by an
|
||||||
/// only used by an add, transform this into (X+(0-Y)) to promote better
|
/// add, transform this into (X+(0-Y)) to promote better reassociation.
|
||||||
/// reassociation.
|
|
||||||
static BinaryOperator *BreakUpSubtract(Instruction *Sub) {
|
static BinaryOperator *BreakUpSubtract(Instruction *Sub) {
|
||||||
// Convert a subtract into an add and a neg instruction. This allows sub
|
// Convert a subtract into an add and a neg instruction. This allows sub
|
||||||
// instructions to be commuted with other add instructions.
|
// instructions to be commuted with other add instructions.
|
||||||
|
|
@ -1039,9 +1036,8 @@ static BinaryOperator *BreakUpSubtract(Instruction *Sub) {
|
||||||
return New;
|
return New;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ConvertShiftToMul - If this is a shift of a reassociable multiply or is used
|
/// If this is a shift of a reassociable multiply or is used by one, change
|
||||||
/// by one, change this into a multiply by a constant to assist with further
|
/// this into a multiply by a constant to assist with further reassociation.
|
||||||
/// reassociation.
|
|
||||||
static BinaryOperator *ConvertShiftToMul(Instruction *Shl) {
|
static BinaryOperator *ConvertShiftToMul(Instruction *Shl) {
|
||||||
Constant *MulCst = ConstantInt::get(Shl->getType(), 1);
|
Constant *MulCst = ConstantInt::get(Shl->getType(), 1);
|
||||||
MulCst = ConstantExpr::getShl(MulCst, cast<Constant>(Shl->getOperand(1)));
|
MulCst = ConstantExpr::getShl(MulCst, cast<Constant>(Shl->getOperand(1)));
|
||||||
|
|
@ -1066,10 +1062,9 @@ static BinaryOperator *ConvertShiftToMul(Instruction *Shl) {
|
||||||
return Mul;
|
return Mul;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FindInOperandList - Scan backwards and forwards among values with the same
|
/// Scan backwards and forwards among values with the same rank as element i
|
||||||
/// rank as element i to see if X exists. If X does not exist, return i. This
|
/// to see if X exists. If X does not exist, return i. This is useful when
|
||||||
/// is useful when scanning for 'x' when we see '-x' because they both get the
|
/// scanning for 'x' when we see '-x' because they both get the same rank.
|
||||||
/// same rank.
|
|
||||||
static unsigned FindInOperandList(SmallVectorImpl<ValueEntry> &Ops, unsigned i,
|
static unsigned FindInOperandList(SmallVectorImpl<ValueEntry> &Ops, unsigned i,
|
||||||
Value *X) {
|
Value *X) {
|
||||||
unsigned XRank = Ops[i].Rank;
|
unsigned XRank = Ops[i].Rank;
|
||||||
|
|
@ -1094,7 +1089,7 @@ static unsigned FindInOperandList(SmallVectorImpl<ValueEntry> &Ops, unsigned i,
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitAddTreeOfValues - Emit a tree of add instructions, summing Ops together
|
/// Emit a tree of add instructions, summing Ops together
|
||||||
/// and returning the result. Insert the tree before I.
|
/// and returning the result. Insert the tree before I.
|
||||||
static Value *EmitAddTreeOfValues(Instruction *I,
|
static Value *EmitAddTreeOfValues(Instruction *I,
|
||||||
SmallVectorImpl<WeakVH> &Ops){
|
SmallVectorImpl<WeakVH> &Ops){
|
||||||
|
|
@ -1106,8 +1101,8 @@ static Value *EmitAddTreeOfValues(Instruction *I,
|
||||||
return CreateAdd(V2, V1, "tmp", I, I);
|
return CreateAdd(V2, V1, "tmp", I, I);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// RemoveFactorFromExpression - If V is an expression tree that is a
|
/// If V is an expression tree that is a multiplication sequence,
|
||||||
/// multiplication sequence, and if this sequence contains a multiply by Factor,
|
/// and if this sequence contains a multiply by Factor,
|
||||||
/// remove Factor from the tree and return the new tree.
|
/// remove Factor from the tree and return the new tree.
|
||||||
Value *Reassociate::RemoveFactorFromExpression(Value *V, Value *Factor) {
|
Value *Reassociate::RemoveFactorFromExpression(Value *V, Value *Factor) {
|
||||||
BinaryOperator *BO = isReassociableOp(V, Instruction::Mul, Instruction::FMul);
|
BinaryOperator *BO = isReassociableOp(V, Instruction::Mul, Instruction::FMul);
|
||||||
|
|
@ -1179,8 +1174,8 @@ Value *Reassociate::RemoveFactorFromExpression(Value *V, Value *Factor) {
|
||||||
return V;
|
return V;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FindSingleUseMultiplyFactors - If V is a single-use multiply, recursively
|
/// If V is a single-use multiply, recursively add its operands as factors,
|
||||||
/// add its operands as factors, otherwise add V to the list of factors.
|
/// otherwise add V to the list of factors.
|
||||||
///
|
///
|
||||||
/// Ops is the top-level list of add operands we're trying to factor.
|
/// Ops is the top-level list of add operands we're trying to factor.
|
||||||
static void FindSingleUseMultiplyFactors(Value *V,
|
static void FindSingleUseMultiplyFactors(Value *V,
|
||||||
|
|
@ -1197,10 +1192,9 @@ static void FindSingleUseMultiplyFactors(Value *V,
|
||||||
FindSingleUseMultiplyFactors(BO->getOperand(0), Factors, Ops);
|
FindSingleUseMultiplyFactors(BO->getOperand(0), Factors, Ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// OptimizeAndOrXor - Optimize a series of operands to an 'and', 'or', or 'xor'
|
/// Optimize a series of operands to an 'and', 'or', or 'xor' instruction.
|
||||||
/// instruction. This optimizes based on identities. If it can be reduced to
|
/// This optimizes based on identities. If it can be reduced to a single Value,
|
||||||
/// a single Value, it is returned, otherwise the Ops list is mutated as
|
/// it is returned, otherwise the Ops list is mutated as necessary.
|
||||||
/// necessary.
|
|
||||||
static Value *OptimizeAndOrXor(unsigned Opcode,
|
static Value *OptimizeAndOrXor(unsigned Opcode,
|
||||||
SmallVectorImpl<ValueEntry> &Ops) {
|
SmallVectorImpl<ValueEntry> &Ops) {
|
||||||
// Scan the operand lists looking for X and ~X pairs, along with X,X pairs.
|
// Scan the operand lists looking for X and ~X pairs, along with X,X pairs.
|
||||||
|
|
@ -1490,7 +1484,7 @@ Value *Reassociate::OptimizeXor(Instruction *I,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// OptimizeAdd - Optimize a series of operands to an 'add' instruction. This
|
/// Optimize a series of operands to an 'add' instruction. This
|
||||||
/// optimizes based on identities. If it can be reduced to a single Value, it
|
/// optimizes based on identities. If it can be reduced to a single Value, it
|
||||||
/// is returned, otherwise the Ops list is mutated as necessary.
|
/// is returned, otherwise the Ops list is mutated as necessary.
|
||||||
Value *Reassociate::OptimizeAdd(Instruction *I,
|
Value *Reassociate::OptimizeAdd(Instruction *I,
|
||||||
|
|
@ -1943,8 +1937,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EraseInst - Zap the given instruction, adding interesting operands to the
|
/// Zap the given instruction, adding interesting operands to the work list.
|
||||||
/// work list.
|
|
||||||
void Reassociate::EraseInst(Instruction *I) {
|
void Reassociate::EraseInst(Instruction *I) {
|
||||||
assert(isInstructionTriviallyDead(I) && "Trivially dead instructions only!");
|
assert(isInstructionTriviallyDead(I) && "Trivially dead instructions only!");
|
||||||
SmallVector<Value*, 8> Ops(I->op_begin(), I->op_end());
|
SmallVector<Value*, 8> Ops(I->op_begin(), I->op_end());
|
||||||
|
|
@ -2058,7 +2051,7 @@ Instruction *Reassociate::canonicalizeNegConstExpr(Instruction *I) {
|
||||||
return NI;
|
return NI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// OptimizeInst - Inspect and optimize the given instruction. Note that erasing
|
/// Inspect and optimize the given instruction. Note that erasing
|
||||||
/// instructions is not allowed.
|
/// instructions is not allowed.
|
||||||
void Reassociate::OptimizeInst(Instruction *I) {
|
void Reassociate::OptimizeInst(Instruction *I) {
|
||||||
// Only consider operations that we understand.
|
// Only consider operations that we understand.
|
||||||
|
|
@ -2191,7 +2184,7 @@ void Reassociate::ReassociateExpression(BinaryOperator *I) {
|
||||||
// the vector.
|
// the vector.
|
||||||
std::stable_sort(Ops.begin(), Ops.end());
|
std::stable_sort(Ops.begin(), Ops.end());
|
||||||
|
|
||||||
// OptimizeExpression - Now that we have the expression tree in a convenient
|
// Now that we have the expression tree in a convenient
|
||||||
// sorted form, optimize it globally if possible.
|
// sorted form, optimize it globally if possible.
|
||||||
if (Value *V = OptimizeExpression(I, Ops)) {
|
if (Value *V = OptimizeExpression(I, Ops)) {
|
||||||
if (V == I)
|
if (V == I)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue