Skip to content

Commit

Permalink
eliminate the Type::getDescription() method, using "<<" instead. This
Browse files Browse the repository at this point in the history
removes some gunk from LLVMContext.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133360 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lattner committed Jun 18, 2011
1 parent 70d0ff1 commit 0cd0d88
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 67 deletions.
10 changes: 3 additions & 7 deletions include/llvm/Type.h
Expand Up @@ -68,7 +68,7 @@ class Type : public AbstractTypeUser {
/// Also update LLVMTypeKind and LLVMGetTypeKind () in the C binding.
///
enum TypeID {
// PrimitiveTypes .. make sure LastPrimitiveTyID stays up to date
// PrimitiveTypes - make sure LastPrimitiveTyID stays up to date.
VoidTyID = 0, ///< 0: type with no size
FloatTyID, ///< 1: 32-bit floating point type
DoubleTyID, ///< 2: 64-bit floating point type
Expand Down Expand Up @@ -178,17 +178,13 @@ class Type : public AbstractTypeUser {
LLVMContext &getContext() const { return Context; }

//===--------------------------------------------------------------------===//
// Property accessors for dealing with types... Some of these virtual methods
// are defined in private classes defined in Type.cpp for primitive types.
// Accessors for working with types.
//

/// getDescription - Return the string representation of the type.
std::string getDescription() const;

/// getTypeID - Return the type id for the type. This will return one
/// of the TypeID enum elements defined above.
///
inline TypeID getTypeID() const { return ID; }
TypeID getTypeID() const { return ID; }

/// isVoidTy - Return true if this is 'void'.
bool isVoidTy() const { return ID == VoidTyID; }
Expand Down
47 changes: 27 additions & 20 deletions lib/AsmParser/LLParser.cpp
Expand Up @@ -26,6 +26,13 @@
#include "llvm/Support/raw_ostream.h"
using namespace llvm;

static std::string getTypeString(const Type *T) {
std::string Result;
raw_string_ostream Tmp(Result);
Tmp << *T;
return Tmp.str();
}

/// Run: module ::= toplevelentity*
bool LLParser::Run() {
// Prime the lexer.
Expand Down Expand Up @@ -360,7 +367,7 @@ bool LLParser::ParseNamedType() {

// Otherwise, this is an attempt to redefine a type, report the error.
return Error(NameLoc, "redefinition of type named '" + Name + "' of type '" +
Ty->getDescription() + "'");
getTypeString(Ty) + "'");
}


Expand Down Expand Up @@ -786,7 +793,7 @@ GlobalValue *LLParser::GetGlobalVal(const std::string &Name, const Type *Ty,
if (Val) {
if (Val->getType() == Ty) return Val;
Error(Loc, "'@" + Name + "' defined with type '" +
Val->getType()->getDescription() + "'");
getTypeString(Val->getType()) + "'");
return 0;
}

Expand Down Expand Up @@ -831,7 +838,7 @@ GlobalValue *LLParser::GetGlobalVal(unsigned ID, const Type *Ty, LocTy Loc) {
if (Val) {
if (Val->getType() == Ty) return Val;
Error(Loc, "'@" + Twine(ID) + "' defined with type '" +
Val->getType()->getDescription() + "'");
getTypeString(Val->getType()) + "'");
return 0;
}

Expand Down Expand Up @@ -1257,7 +1264,7 @@ PATypeHolder LLParser::HandleUpRefs(const Type *ty) {

PATypeHolder Ty(ty);
#if 0
dbgs() << "Type '" << Ty->getDescription()
dbgs() << "Type '" << *Ty
<< "' newly formed. Resolving upreferences.\n"
<< UpRefs.size() << " upreferences active!\n";
#endif
Expand All @@ -1275,8 +1282,8 @@ PATypeHolder LLParser::HandleUpRefs(const Type *ty) {
UpRefs[i].LastContainedTy) != Ty->subtype_end();

#if 0
dbgs() << " UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
<< UpRefs[i].LastContainedTy->getDescription() << ") = "
dbgs() << " UR#" << i << " - TypeContains(" << *Ty << ", "
<< *UpRefs[i].LastContainedTy << ") = "
<< (ContainsType ? "true" : "false")
<< " level=" << UpRefs[i].NestingLevel << "\n";
#endif
Expand Down Expand Up @@ -1765,7 +1772,7 @@ Value *LLParser::PerFunctionState::GetVal(const std::string &Name,
P.Error(Loc, "'%" + Name + "' is not a basic block");
else
P.Error(Loc, "'%" + Name + "' defined with type '" +
Val->getType()->getDescription() + "'");
getTypeString(Val->getType()) + "'");
return 0;
}

Expand Down Expand Up @@ -1807,7 +1814,7 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty,
P.Error(Loc, "'%" + Twine(ID) + "' is not a basic block");
else
P.Error(Loc, "'%" + Twine(ID) + "' defined with type '" +
Val->getType()->getDescription() + "'");
getTypeString(Val->getType()) + "'");
return 0;
}

Expand Down Expand Up @@ -1855,7 +1862,7 @@ bool LLParser::PerFunctionState::SetInstName(int NameID,
if (FI != ForwardRefValIDs.end()) {
if (FI->second.first->getType() != Inst->getType())
return P.Error(NameLoc, "instruction forward referenced with type '" +
FI->second.first->getType()->getDescription() + "'");
getTypeString(FI->second.first->getType()) + "'");
FI->second.first->replaceAllUsesWith(Inst);
delete FI->second.first;
ForwardRefValIDs.erase(FI);
Expand All @@ -1871,7 +1878,7 @@ bool LLParser::PerFunctionState::SetInstName(int NameID,
if (FI != ForwardRefVals.end()) {
if (FI->second.first->getType() != Inst->getType())
return P.Error(NameLoc, "instruction forward referenced with type '" +
FI->second.first->getType()->getDescription() + "'");
getTypeString(FI->second.first->getType()) + "'");
FI->second.first->replaceAllUsesWith(Inst);
delete FI->second.first;
ForwardRefVals.erase(FI);
Expand Down Expand Up @@ -2026,7 +2033,7 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
if (Elts[i]->getType() != Elts[0]->getType())
return Error(FirstEltLoc,
"vector element #" + Twine(i) +
" is not of type '" + Elts[0]->getType()->getDescription());
" is not of type '" + getTypeString(Elts[0]->getType()));

ID.ConstantVal = ConstantVector::get(Elts);
ID.Kind = ValID::t_Constant;
Expand All @@ -2050,7 +2057,7 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {

if (!Elts[0]->getType()->isFirstClassType())
return Error(FirstEltLoc, "invalid array element type: " +
Elts[0]->getType()->getDescription());
getTypeString(Elts[0]->getType()));

ArrayType *ATy = ArrayType::get(Elts[0]->getType(), Elts.size());

Expand All @@ -2059,7 +2066,7 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
if (Elts[i]->getType() != Elts[0]->getType())
return Error(FirstEltLoc,
"array element #" + Twine(i) +
" is not of type '" +Elts[0]->getType()->getDescription());
" is not of type '" + getTypeString(Elts[0]->getType()));
}

ID.ConstantVal = ConstantArray::get(ATy, Elts.data(), Elts.size());
Expand Down Expand Up @@ -2142,8 +2149,8 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
return true;
if (!CastInst::castIsValid((Instruction::CastOps)Opc, SrcVal, DestTy))
return Error(ID.Loc, "invalid cast opcode for cast from '" +
SrcVal->getType()->getDescription() + "' to '" +
DestTy->getDescription() + "'");
getTypeString(SrcVal->getType()) + "' to '" +
getTypeString(DestTy) + "'");
ID.ConstantVal = ConstantExpr::getCast((Instruction::CastOps)Opc,
SrcVal, DestTy);
ID.Kind = ValID::t_Constant;
Expand Down Expand Up @@ -2552,7 +2559,7 @@ bool LLParser::ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V,

if (V->getType() != Ty)
return Error(ID.Loc, "floating point constant does not have type '" +
Ty->getDescription() + "'");
getTypeString(Ty) + "'");

return false;
case ValID::t_Null:
Expand Down Expand Up @@ -3253,7 +3260,7 @@ bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) {

if (ExpectedTy && ExpectedTy != ArgList[i].V->getType())
return Error(ArgList[i].Loc, "argument is not of expected type '" +
ExpectedTy->getDescription() + "'");
getTypeString(ExpectedTy) + "'");
Args.push_back(ArgList[i].V);
if (ArgList[i].Attrs != Attribute::None)
Attrs.push_back(AttributeWithIndex::get(i+1, ArgList[i].Attrs));
Expand Down Expand Up @@ -3379,8 +3386,8 @@ bool LLParser::ParseCast(Instruction *&Inst, PerFunctionState &PFS,
if (!CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy)) {
CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy);
return Error(Loc, "invalid cast opcode for cast from '" +
Op->getType()->getDescription() + "' to '" +
DestTy->getDescription() + "'");
getTypeString(Op->getType()) + "' to '" +
getTypeString(DestTy) + "'");
}
Inst = CastInst::Create((Instruction::CastOps)Opc, Op, DestTy);
return false;
Expand Down Expand Up @@ -3590,7 +3597,7 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,

if (ExpectedTy && ExpectedTy != ArgList[i].V->getType())
return Error(ArgList[i].Loc, "argument is not of expected type '" +
ExpectedTy->getDescription() + "'");
getTypeString(ExpectedTy) + "'");
Args.push_back(ArgList[i].V);
if (ArgList[i].Attrs != Attribute::None)
Attrs.push_back(AttributeWithIndex::get(i+1, ArgList[i].Attrs));
Expand Down
4 changes: 2 additions & 2 deletions lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
Expand Up @@ -282,10 +282,10 @@ GenericValue Interpreter::callExternalFunction(Function *F,

if (F->getName() == "__main")
errs() << "Tried to execute an unknown external function: "
<< F->getType()->getDescription() << " __main\n";
<< *F->getType() << " __main\n";
else
report_fatal_error("Tried to execute an unknown external function: " +
F->getType()->getDescription() + " " +F->getName());
F->getName());
#ifndef USE_LIBFFI
errs() << "Recompiling LLVM with --enable-libffi might help.\n";
#endif
Expand Down
8 changes: 0 additions & 8 deletions lib/VMCore/LLVMContextImpl.h
Expand Up @@ -22,7 +22,6 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Metadata.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/ValueHandle.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
Expand Down Expand Up @@ -182,13 +181,6 @@ class LLVMContextImpl {
const IntegerType Int32Ty;
const IntegerType Int64Ty;

// Concrete/Abstract TypeDescriptions - We lazily calculate type descriptions
// for types as they are needed. Because resolution of types must invalidate
// all of the abstract type descriptions, we keep them in a separate map to
// make this easy.
TypePrinting ConcreteTypeDescriptions;
TypePrinting AbstractTypeDescriptions;

TypeMap<ArrayValType, ArrayType> ArrayTypes;
TypeMap<VectorValType, VectorType> VectorTypes;
TypeMap<PointerValType, PointerType> PointerTypes;
Expand Down
20 changes: 0 additions & 20 deletions lib/VMCore/Type.cpp
Expand Up @@ -286,21 +286,6 @@ void Type::typeBecameConcrete(const DerivedType *AbsTy) {
llvm_unreachable("DerivedType is already a concrete type!");
}


std::string Type::getDescription() const {
LLVMContextImpl *pImpl = getContext().pImpl;
TypePrinting &Map =
isAbstract() ?
pImpl->AbstractTypeDescriptions :
pImpl->ConcreteTypeDescriptions;

std::string DescStr;
raw_string_ostream DescOS(DescStr);
Map.print(this, DescOS);
return DescOS.str();
}


bool StructType::indexValid(const Value *V) const {
// Structure indexes require 32-bit integer constants.
if (V->getType()->isIntegerTy(32))
Expand Down Expand Up @@ -1067,11 +1052,6 @@ void DerivedType::refineAbstractTypeTo(const Type *NewType) {
assert(this != NewType && "Can't refine to myself!");
assert(ForwardType == 0 && "This type has already been refined!");

LLVMContextImpl *pImpl = getContext().pImpl;

// The descriptions may be out of date. Conservatively clear them all!
pImpl->AbstractTypeDescriptions.clear();

#ifdef DEBUG_MERGE_TYPES
DEBUG(dbgs() << "REFINING abstract type [" << (void*)this << " "
<< *this << "] to [" << (void*)NewType << " "
Expand Down
15 changes: 7 additions & 8 deletions lib/VMCore/TypeSymbolTable.cpp
Expand Up @@ -59,7 +59,7 @@ Type* TypeSymbolTable::remove(iterator Entry) {

#if DEBUG_SYMBOL_TABLE
dump();
dbgs() << " Removing Value: " << Result->getDescription() << "\n";
dbgs() << " Removing Value: " << *Result << "\n";
#endif

tmap.erase(Entry);
Expand All @@ -69,8 +69,7 @@ Type* TypeSymbolTable::remove(iterator Entry) {
if (Result->isAbstract()) {
#if DEBUG_ABSTYPE
dbgs() << "Removing abstract type from symtab"
<< Result->getDescription()
<< "\n";
<< *Result << "\n";
#endif
cast<DerivedType>(Result)->removeAbstractTypeUser(this);
}
Expand All @@ -88,7 +87,7 @@ void TypeSymbolTable::insert(StringRef Name, const Type* T) {

#if DEBUG_SYMBOL_TABLE
dump();
dbgs() << " Inserted type: " << Name << ": " << T->getDescription() << "\n";
dbgs() << " Inserted type: " << Name << ": " << *T << "\n";
#endif
} else {
// If there is a name conflict...
Expand All @@ -101,7 +100,7 @@ void TypeSymbolTable::insert(StringRef Name, const Type* T) {
#if DEBUG_SYMBOL_TABLE
dump();
dbgs() << " Inserting type: " << UniqueName << ": "
<< T->getDescription() << "\n";
<< *T << "\n";
#endif

// Insert the tmap entry
Expand All @@ -112,7 +111,7 @@ void TypeSymbolTable::insert(StringRef Name, const Type* T) {
if (T->isAbstract()) {
cast<DerivedType>(T)->addAbstractTypeUser(this);
#if DEBUG_ABSTYPE
dbgs() << "Added abstract type to ST: " << T->getDescription() << "\n";
dbgs() << "Added abstract type to ST: " << *T << "\n";
#endif
}
}
Expand All @@ -129,15 +128,15 @@ void TypeSymbolTable::refineAbstractType(const DerivedType *OldType,
// FIXME when Types aren't const.
if (I->second == const_cast<DerivedType *>(OldType)) {
#if DEBUG_ABSTYPE
dbgs() << "Removing type " << OldType->getDescription() << "\n";
dbgs() << "Removing type " << *OldType << "\n";
#endif
OldType->removeAbstractTypeUser(this);

// TODO FIXME when types aren't const
I->second = const_cast<Type *>(NewType);
if (NewType->isAbstract()) {
#if DEBUG_ABSTYPE
dbgs() << "Added type " << NewType->getDescription() << "\n";
dbgs() << "Added type " << *NewType << "\n";
#endif
cast<DerivedType>(NewType)->addAbstractTypeUser(this);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/VMCore/ValueSymbolTable.cpp
Expand Up @@ -25,7 +25,7 @@ ValueSymbolTable::~ValueSymbolTable() {
#ifndef NDEBUG // Only do this in -g mode...
for (iterator VI = vmap.begin(), VE = vmap.end(); VI != VE; ++VI)
dbgs() << "Value still in symbol table! Type = '"
<< VI->getValue()->getType()->getDescription() << "' Name = '"
<< *VI->getValue()->getType() << "' Name = '"
<< VI->getKeyData() << "'\n";
assert(vmap.empty() && "Values remain in symbol table!");
#endif
Expand Down
2 changes: 1 addition & 1 deletion tools/llvm-dis/llvm-dis.cpp
Expand Up @@ -74,7 +74,7 @@ class CommentWriter : public AssemblyAnnotationWriter {
if (!V.getType()->isVoidTy()) {
OS.PadToColumn(50);
Padded = true;
OS << "; [#uses=" << V.getNumUses() << " type=" << V.getType()->getDescription() << "]"; // Output # uses and type
OS << "; [#uses=" << V.getNumUses() << " type=" << *V.getType() << "]"; // Output # uses and type
}
if (const Instruction *I = dyn_cast<Instruction>(&V)) {
const DebugLoc &DL = I->getDebugLoc();
Expand Down

0 comments on commit 0cd0d88

Please sign in to comment.