Convert transforms over to standardize debugging output on -debug option

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2714 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-05-22 17:27:12 +00:00
parent f016ea4ff8
commit b3abf9d0d8
3 changed files with 26 additions and 76 deletions

View File

@ -13,12 +13,11 @@
#include "llvm/ConstantHandling.h"
#include "llvm/Analysis/Expressions.h"
#include "Support/STLExtras.h"
#include "Support/StatisticReporter.h"
#include <algorithm>
#include <iostream>
using std::cerr;
//#define DEBUG_EXPR_CONVERT 1
static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
ValueTypeCache &ConvertedTypes);
@ -190,7 +189,7 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
// We can convert the expr if the cast destination type is losslessly
// convertable to the requested type.
if (!Ty->isLosslesslyConvertableTo(I->getType())) return false;
#if 1
// We also do not allow conversion of a cast that casts from a ptr to array
// of X to a *X. For example: cast [4 x %List *] * %val to %List * *
//
@ -199,7 +198,6 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
if (ArrayType *AT = dyn_cast<ArrayType>(SPT->getElementType()))
if (AT->getElementType() == DPT->getElementType())
return false;
#endif
break;
case Instruction::Add:
@ -242,7 +240,6 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
return false;
break;
#if 1
case Instruction::GetElementPtr: {
// GetElementPtr's are directly convertable to a pointer type if they have
// a number of zeros at the end. Because removing these values does not
@ -321,7 +318,6 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
return false; // No match, maybe next time.
}
#endif
default:
return false;
@ -352,9 +348,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
return VMCI->second;
}
#ifdef DEBUG_EXPR_CONVERT
cerr << "CETT: " << (void*)V << " " << V;
#endif
DEBUG(cerr << "CETT: " << (void*)V << " " << V);
Instruction *I = dyn_cast<Instruction>(V);
if (I == 0)
@ -544,15 +538,11 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
if (NumUses == OldSize) ++It;
}
#ifdef DEBUG_EXPR_CONVERT
cerr << "ExpIn: " << (void*)I << " " << I
<< "ExpOut: " << (void*)Res << " " << Res;
#endif
DEBUG(cerr << "ExpIn: " << (void*)I << " " << I
<< "ExpOut: " << (void*)Res << " " << Res);
if (I->use_empty()) {
#ifdef DEBUG_EXPR_CONVERT
cerr << "EXPR DELETING: " << (void*)I << " " << I;
#endif
DEBUG(cerr << "EXPR DELETING: " << (void*)I << " " << I);
BIL.remove(I);
VMC.OperandsMapped.erase(I);
VMC.ExprMap.erase(I);
@ -625,7 +615,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
I->getOperand(0)->getType()->isSigned() != Ty->isSigned())
return false;
#if 1
// We also do not allow conversion of a cast that casts from a ptr to array
// of X to a *X. For example: cast [4 x %List *] * %val to %List * *
//
@ -634,7 +623,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
if (ArrayType *AT = dyn_cast<ArrayType>(SPT->getElementType()))
if (AT->getElementType() == DPT->getElementType())
return false;
#endif
return true;
case Instruction::Add:
@ -1146,10 +1134,9 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
assert(It != BIL.end() && "Instruction not in own basic block??");
BIL.insert(It, Res); // Keep It pointing to old instruction
#ifdef DEBUG_EXPR_CONVERT
cerr << "COT CREATED: " << (void*)Res << " " << Res;
cerr << "In: " << (void*)I << " " << I << "Out: " << (void*)Res << " " << Res;
#endif
DEBUG(cerr << "COT CREATED: " << (void*)Res << " " << Res
<< "In: " << (void*)I << " " << I << "Out: " << (void*)Res
<< " " << Res);
// Add the instruction to the expression map
VMC.ExprMap[I] = Res;
@ -1170,9 +1157,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// loops. Note that we cannot use DCE because DCE won't remove a store
// instruction, for example.
//
#ifdef DEBUG_EXPR_CONVERT
cerr << "DELETING: " << (void*)I << " " << I;
#endif
DEBUG(cerr << "DELETING: " << (void*)I << " " << I);
BIL.remove(I);
VMC.OperandsMapped.erase(I);
VMC.ExprMap.erase(I);
@ -1188,9 +1173,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
ValueHandle::ValueHandle(ValueMapCache &VMC, Value *V)
: Instruction(Type::VoidTy, UserOp1, ""), Cache(VMC) {
#ifdef DEBUG_EXPR_CONVERT
//cerr << "VH AQUIRING: " << (void*)V << " " << V;
#endif
//DEBUG(cerr << "VH AQUIRING: " << (void*)V << " " << V);
Operands.push_back(Use(V, this));
}
@ -1199,9 +1182,7 @@ static void RecursiveDelete(ValueMapCache &Cache, Instruction *I) {
assert(I->getParent() && "Inst not in basic block!");
#ifdef DEBUG_EXPR_CONVERT
//cerr << "VH DELETING: " << (void*)I << " " << I;
#endif
//DEBUG(cerr << "VH DELETING: " << (void*)I << " " << I);
for (User::op_iterator OI = I->op_begin(), OE = I->op_end();
OI != OE; ++OI)
@ -1228,8 +1209,7 @@ ValueHandle::~ValueHandle() {
//
RecursiveDelete(Cache, dyn_cast<Instruction>(V));
} else {
#ifdef DEBUG_EXPR_CONVERT
//cerr << "VH RELEASING: " << (void*)Operands[0].get() << " " << Operands[0]->use_size() << " " << Operands[0];
#endif
//DEBUG(cerr << "VH RELEASING: " << (void*)Operands[0].get() << " "
// << Operands[0]->use_size() << " " << Operands[0]);
}
}

View File

@ -25,17 +25,11 @@
#include "llvm/Argument.h"
#include "llvm/Constants.h"
#include "Support/STLExtras.h"
#include "Support/StatisticReporter.h"
#include <algorithm>
using std::map;
using std::vector;
// To enable debugging, uncomment this...
//#define DEBUG_MST(x) x
#ifndef DEBUG_MST
#define DEBUG_MST(x) // Disable debug code
#endif
// ValuePlaceHolder - A stupid little marker value. It appears as an
// instruction of type Instruction::UserOp1.
//
@ -174,7 +168,7 @@ Value *MutateStructTypes::ConvertValue(const Value *V) {
return LocalValueMap[V] = new BasicBlock(BB->getName());
}
DEBUG_MST(cerr << "NPH: " << V << endl);
DEBUG(cerr << "NPH: " << V << "\n");
// Otherwise make a constant to represent it
return LocalValueMap[V] = new ValuePlaceHolder(ConvertType(V->getType()));
@ -233,7 +227,7 @@ void MutateStructTypes::setTransforms(const TransformsType &XForm) {
Transforms.insert(std::make_pair(OldTy,
std::make_pair(cast<StructType>(NSTy.get()), InVec)));
DEBUG_MST(cerr << "Mutate " << OldTy << "\nTo " << NSTy << endl);
DEBUG(cerr << "Mutate " << OldTy << "\nTo " << NSTy << "\n");
}
}

View File

@ -26,14 +26,8 @@ static Statistic<> NumCastOfCast("raise\t\t- Number of cast-of-self removed");
static Statistic<> NumDCEorCP("raise\t\t- Number of insts DCE'd or constprop'd");
//#define DEBUG_PEEPHOLE_INSTS 1
#ifdef DEBUG_PEEPHOLE_INSTS
#define PRINT_PEEPHOLE(ID, NUM, I) \
std::cerr << "Inst P/H " << ID << "[" << NUM << "] " << I;
#else
#define PRINT_PEEPHOLE(ID, NUM, I)
#endif
DEBUG(std::cerr << "Inst P/H " << ID << "[" << NUM << "] " << I)
#define PRINT_PEEPHOLE1(ID, I1) do { PRINT_PEEPHOLE(ID, 0, I1); } while (0)
#define PRINT_PEEPHOLE2(ID, I1, I2) \
@ -217,9 +211,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
if (ExpressionConvertableToType(Src, DestTy, ConvertedTypes)) {
PRINT_PEEPHOLE3("CAST-SRC-EXPR-CONV:in ", Src, CI, BB->getParent());
#ifdef DEBUG_PEEPHOLE_INSTS
cerr << "\nCONVERTING SRC EXPR TYPE:\n";
#endif
DEBUG(cerr << "\nCONVERTING SRC EXPR TYPE:\n");
ValueMapCache ValueMap;
Value *E = ConvertExpressionToType(Src, DestTy, ValueMap);
if (Constant *CPV = dyn_cast<Constant>(E))
@ -227,9 +219,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
BI = BB->begin(); // Rescan basic block. BI might be invalidated.
PRINT_PEEPHOLE1("CAST-SRC-EXPR-CONV:out", E);
#ifdef DEBUG_PEEPHOLE_INSTS
cerr << "DONE CONVERTING SRC EXPR TYPE: \n" << BB->getParent();
#endif
DEBUG(cerr << "DONE CONVERTING SRC EXPR TYPE: \n" << BB->getParent());
++NumExprTreesConv;
return true;
}
@ -241,17 +231,13 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
if (ValueConvertableToType(CI, Src->getType(), ConvertedTypes)) {
PRINT_PEEPHOLE3("CAST-DEST-EXPR-CONV:in ", Src, CI, BB->getParent());
#ifdef DEBUG_PEEPHOLE_INSTS
cerr << "\nCONVERTING EXPR TYPE:\n";
#endif
DEBUG(cerr << "\nCONVERTING EXPR TYPE:\n");
ValueMapCache ValueMap;
ConvertValueToNewType(CI, Src, ValueMap); // This will delete CI!
BI = BB->begin(); // Rescan basic block. BI might be invalidated.
PRINT_PEEPHOLE1("CAST-DEST-EXPR-CONV:out", Src);
#ifdef DEBUG_PEEPHOLE_INSTS
cerr << "DONE CONVERTING EXPR TYPE: \n\n" << BB->getParent();
#endif
DEBUG(cerr << "DONE CONVERTING EXPR TYPE: \n\n" << BB->getParent());
++NumExprTreesConv;
return true;
}
@ -279,7 +265,6 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
// Into: %t2 = getelementptr {<...>} * %StructPtr, <0, 0, 0, ...>
// %t1 = cast <eltype> * %t1 to <ty> *
//
#if 1
if (const CompositeType *CTy = getPointedToComposite(Src->getType()))
if (const PointerType *DestPTy = dyn_cast<PointerType>(DestTy)) {
@ -354,7 +339,6 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
}
}
}
#endif
} else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
Value *Val = SI->getOperand(0);
@ -458,15 +442,11 @@ static bool DoRaisePass(Function *F) {
BasicBlock::InstListType &BIL = BB->getInstList();
for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) {
#if DEBUG_PEEPHOLE_INSTS
cerr << "Processing: " << *BI;
#endif
DEBUG(cerr << "Processing: " << *BI);
if (dceInstruction(BIL, BI) || doConstantPropogation(BB, BI)) {
Changed = true;
++NumDCEorCP;
#ifdef DEBUG_PEEPHOLE_INSTS
cerr << "***\t\t^^-- DeadCode Elinated!\n";
#endif
DEBUG(cerr << "***\t\t^^-- DeadCode Elinated!\n");
} else if (PeepholeOptimize(BB, BI))
Changed = true;
else
@ -481,9 +461,7 @@ static bool DoRaisePass(Function *F) {
// level.
//
static bool doRPR(Function *F) {
#ifdef DEBUG_PEEPHOLE_INSTS
cerr << "\n\n\nStarting to work on Function '" << F->getName() << "'\n";
#endif
DEBUG(cerr << "\n\n\nStarting to work on Function '" << F->getName()<< "'\n");
// Insert casts for all incoming pointer pointer values that are treated as
// arrays...
@ -491,9 +469,7 @@ static bool doRPR(Function *F) {
bool Changed = false, LocalChange;
do {
#ifdef DEBUG_PEEPHOLE_INSTS
cerr << "Looping: \n" << F;
#endif
DEBUG(cerr << "Looping: \n" << F);
// Iterate over the function, refining it, until it converges on a stable
// state