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

View File

@ -25,17 +25,11 @@
#include "llvm/Argument.h" #include "llvm/Argument.h"
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "Support/STLExtras.h" #include "Support/STLExtras.h"
#include "Support/StatisticReporter.h"
#include <algorithm> #include <algorithm>
using std::map; using std::map;
using std::vector; 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 // ValuePlaceHolder - A stupid little marker value. It appears as an
// instruction of type Instruction::UserOp1. // instruction of type Instruction::UserOp1.
// //
@ -174,7 +168,7 @@ Value *MutateStructTypes::ConvertValue(const Value *V) {
return LocalValueMap[V] = new BasicBlock(BB->getName()); 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 // Otherwise make a constant to represent it
return LocalValueMap[V] = new ValuePlaceHolder(ConvertType(V->getType())); return LocalValueMap[V] = new ValuePlaceHolder(ConvertType(V->getType()));
@ -233,7 +227,7 @@ void MutateStructTypes::setTransforms(const TransformsType &XForm) {
Transforms.insert(std::make_pair(OldTy, Transforms.insert(std::make_pair(OldTy,
std::make_pair(cast<StructType>(NSTy.get()), InVec))); 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"); 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) \ #define PRINT_PEEPHOLE(ID, NUM, I) \
std::cerr << "Inst P/H " << ID << "[" << NUM << "] " << I; DEBUG(std::cerr << "Inst P/H " << ID << "[" << NUM << "] " << I)
#else
#define PRINT_PEEPHOLE(ID, NUM, I)
#endif
#define PRINT_PEEPHOLE1(ID, I1) do { PRINT_PEEPHOLE(ID, 0, I1); } while (0) #define PRINT_PEEPHOLE1(ID, I1) do { PRINT_PEEPHOLE(ID, 0, I1); } while (0)
#define PRINT_PEEPHOLE2(ID, I1, I2) \ #define PRINT_PEEPHOLE2(ID, I1, I2) \
@ -217,9 +211,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
if (ExpressionConvertableToType(Src, DestTy, ConvertedTypes)) { if (ExpressionConvertableToType(Src, DestTy, ConvertedTypes)) {
PRINT_PEEPHOLE3("CAST-SRC-EXPR-CONV:in ", Src, CI, BB->getParent()); PRINT_PEEPHOLE3("CAST-SRC-EXPR-CONV:in ", Src, CI, BB->getParent());
#ifdef DEBUG_PEEPHOLE_INSTS DEBUG(cerr << "\nCONVERTING SRC EXPR TYPE:\n");
cerr << "\nCONVERTING SRC EXPR TYPE:\n";
#endif
ValueMapCache ValueMap; ValueMapCache ValueMap;
Value *E = ConvertExpressionToType(Src, DestTy, ValueMap); Value *E = ConvertExpressionToType(Src, DestTy, ValueMap);
if (Constant *CPV = dyn_cast<Constant>(E)) 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. BI = BB->begin(); // Rescan basic block. BI might be invalidated.
PRINT_PEEPHOLE1("CAST-SRC-EXPR-CONV:out", E); PRINT_PEEPHOLE1("CAST-SRC-EXPR-CONV:out", E);
#ifdef DEBUG_PEEPHOLE_INSTS DEBUG(cerr << "DONE CONVERTING SRC EXPR TYPE: \n" << BB->getParent());
cerr << "DONE CONVERTING SRC EXPR TYPE: \n" << BB->getParent();
#endif
++NumExprTreesConv; ++NumExprTreesConv;
return true; return true;
} }
@ -241,17 +231,13 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
if (ValueConvertableToType(CI, Src->getType(), ConvertedTypes)) { if (ValueConvertableToType(CI, Src->getType(), ConvertedTypes)) {
PRINT_PEEPHOLE3("CAST-DEST-EXPR-CONV:in ", Src, CI, BB->getParent()); PRINT_PEEPHOLE3("CAST-DEST-EXPR-CONV:in ", Src, CI, BB->getParent());
#ifdef DEBUG_PEEPHOLE_INSTS DEBUG(cerr << "\nCONVERTING EXPR TYPE:\n");
cerr << "\nCONVERTING EXPR TYPE:\n";
#endif
ValueMapCache ValueMap; ValueMapCache ValueMap;
ConvertValueToNewType(CI, Src, ValueMap); // This will delete CI! ConvertValueToNewType(CI, Src, ValueMap); // This will delete CI!
BI = BB->begin(); // Rescan basic block. BI might be invalidated. BI = BB->begin(); // Rescan basic block. BI might be invalidated.
PRINT_PEEPHOLE1("CAST-DEST-EXPR-CONV:out", Src); PRINT_PEEPHOLE1("CAST-DEST-EXPR-CONV:out", Src);
#ifdef DEBUG_PEEPHOLE_INSTS DEBUG(cerr << "DONE CONVERTING EXPR TYPE: \n\n" << BB->getParent());
cerr << "DONE CONVERTING EXPR TYPE: \n\n" << BB->getParent();
#endif
++NumExprTreesConv; ++NumExprTreesConv;
return true; return true;
} }
@ -279,7 +265,6 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
// Into: %t2 = getelementptr {<...>} * %StructPtr, <0, 0, 0, ...> // Into: %t2 = getelementptr {<...>} * %StructPtr, <0, 0, 0, ...>
// %t1 = cast <eltype> * %t1 to <ty> * // %t1 = cast <eltype> * %t1 to <ty> *
// //
#if 1
if (const CompositeType *CTy = getPointedToComposite(Src->getType())) if (const CompositeType *CTy = getPointedToComposite(Src->getType()))
if (const PointerType *DestPTy = dyn_cast<PointerType>(DestTy)) { 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)) { } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
Value *Val = SI->getOperand(0); Value *Val = SI->getOperand(0);
@ -458,15 +442,11 @@ static bool DoRaisePass(Function *F) {
BasicBlock::InstListType &BIL = BB->getInstList(); BasicBlock::InstListType &BIL = BB->getInstList();
for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) { for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) {
#if DEBUG_PEEPHOLE_INSTS DEBUG(cerr << "Processing: " << *BI);
cerr << "Processing: " << *BI;
#endif
if (dceInstruction(BIL, BI) || doConstantPropogation(BB, BI)) { if (dceInstruction(BIL, BI) || doConstantPropogation(BB, BI)) {
Changed = true; Changed = true;
++NumDCEorCP; ++NumDCEorCP;
#ifdef DEBUG_PEEPHOLE_INSTS DEBUG(cerr << "***\t\t^^-- DeadCode Elinated!\n");
cerr << "***\t\t^^-- DeadCode Elinated!\n";
#endif
} else if (PeepholeOptimize(BB, BI)) } else if (PeepholeOptimize(BB, BI))
Changed = true; Changed = true;
else else
@ -481,9 +461,7 @@ static bool DoRaisePass(Function *F) {
// level. // level.
// //
static bool doRPR(Function *F) { static bool doRPR(Function *F) {
#ifdef DEBUG_PEEPHOLE_INSTS DEBUG(cerr << "\n\n\nStarting to work on Function '" << F->getName()<< "'\n");
cerr << "\n\n\nStarting to work on Function '" << F->getName() << "'\n";
#endif
// Insert casts for all incoming pointer pointer values that are treated as // Insert casts for all incoming pointer pointer values that are treated as
// arrays... // arrays...
@ -491,9 +469,7 @@ static bool doRPR(Function *F) {
bool Changed = false, LocalChange; bool Changed = false, LocalChange;
do { do {
#ifdef DEBUG_PEEPHOLE_INSTS DEBUG(cerr << "Looping: \n" << F);
cerr << "Looping: \n" << F;
#endif
// Iterate over the function, refining it, until it converges on a stable // Iterate over the function, refining it, until it converges on a stable
// state // state