Switch the asmprinter (.ll) and all the stuff it requires over to

use raw_ostream instead of std::ostream.  Among other goodness,
this speeds up llvm-dis of kc++ with a release build from 0.85s
to 0.49s (88% faster).

Other interesting changes:
 1) This makes Value::print be non-virtual.
 2) AP[S]Int and ConstantRange can no longer print to ostream directly, 
    use raw_ostream instead.
 3) This fixes a bug in raw_os_ostream where it didn't flush itself 
    when destroyed.
 4) This adds a new SDNode::print method, instead of only allowing "dump".


A lot of APIs have both std::ostream and raw_ostream versions, it would
be useful to go through and systematically anihilate the std::ostream 
versions.

This passes dejagnu, but there may be minor fallout, plz let me know if
so and I'll fix it.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55263 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2008-08-23 22:23:09 +00:00
parent ef5dc366e7
commit 944fac71e0
36 changed files with 270 additions and 251 deletions

View File

@ -32,7 +32,7 @@
#include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/JIT.h"
#include "llvm/ExecutionEngine/Interpreter.h" #include "llvm/ExecutionEngine/Interpreter.h"
#include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/ExecutionEngine/GenericValue.h"
#include <iostream> #include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
static Function *CreateFibFunction(Module *M) { static Function *CreateFibFunction(Module *M) {
@ -100,15 +100,15 @@ int main(int argc, char **argv) {
ExistingModuleProvider *MP = new ExistingModuleProvider(M); ExistingModuleProvider *MP = new ExistingModuleProvider(M);
ExecutionEngine *EE = ExecutionEngine::create(MP, false); ExecutionEngine *EE = ExecutionEngine::create(MP, false);
std::cerr << "verifying... "; errs() << "verifying... ";
if (verifyModule(*M)) { if (verifyModule(*M)) {
std::cerr << argv[0] << ": Error constructing function!\n"; errs() << argv[0] << ": Error constructing function!\n";
return 1; return 1;
} }
std::cerr << "OK\n"; errs() << "OK\n";
std::cerr << "We just constructed this LLVM module:\n\n---------\n" << *M; errs() << "We just constructed this LLVM module:\n\n---------\n" << *M;
std::cerr << "---------\nstarting fibonacci(" << n << ") with JIT...\n"; errs() << "---------\nstarting fibonacci(" << n << ") with JIT...\n";
// Call the Fibonacci function with argument n: // Call the Fibonacci function with argument n:
std::vector<GenericValue> Args(1); std::vector<GenericValue> Args(1);
@ -116,6 +116,6 @@ int main(int argc, char **argv) {
GenericValue GV = EE->runFunction(FibF, Args); GenericValue GV = EE->runFunction(FibF, Args);
// import result of execution // import result of execution
std::cout << "Result: " << GV.IntVal << "\n"; outs() << "Result: " << GV.IntVal << "\n";
return 0; return 0;
} }

View File

@ -42,7 +42,7 @@
#include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/JIT.h"
#include "llvm/ExecutionEngine/Interpreter.h" #include "llvm/ExecutionEngine/Interpreter.h"
#include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/ExecutionEngine/GenericValue.h"
#include <iostream> #include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
int main() { int main() {
@ -99,14 +99,15 @@ int main() {
ExistingModuleProvider* MP = new ExistingModuleProvider(M); ExistingModuleProvider* MP = new ExistingModuleProvider(M);
ExecutionEngine* EE = ExecutionEngine::create(MP, false); ExecutionEngine* EE = ExecutionEngine::create(MP, false);
std::cout << "We just constructed this LLVM module:\n\n" << *M; outs() << "We just constructed this LLVM module:\n\n" << *M;
std::cout << "\n\nRunning foo: " << std::flush; outs() << "\n\nRunning foo: ";
outs().flush();
// Call the `foo' function with no arguments: // Call the `foo' function with no arguments:
std::vector<GenericValue> noargs; std::vector<GenericValue> noargs;
GenericValue gv = EE->runFunction(FooF, noargs); GenericValue gv = EE->runFunction(FooF, noargs);
// Import result of execution: // Import result of execution:
std::cout << "Result: " << gv.IntVal << "\n"; outs() << "Result: " << gv.IntVal << "\n";
return 0; return 0;
} }

View File

@ -19,13 +19,13 @@
#include "llvm/Support/MathExtras.h" #include "llvm/Support/MathExtras.h"
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <iosfwd>
#include <string> #include <string>
namespace llvm { namespace llvm {
class Serializer; class Serializer;
class Deserializer; class Deserializer;
class FoldingSetNodeID; class FoldingSetNodeID;
class raw_ostream;
template<typename T> template<typename T>
class SmallVectorImpl; class SmallVectorImpl;
@ -1115,8 +1115,7 @@ public:
/// @} /// @}
/// @name Conversion Functions /// @name Conversion Functions
/// @{ /// @{
void print(raw_ostream &OS, bool isSigned) const;
void print(std::ostream &OS, bool isSigned) const;
/// toString - Converts an APInt to a string and append it to Str. Str is /// toString - Converts an APInt to a string and append it to Str. Str is
/// commonly a SmallString. /// commonly a SmallString.
@ -1385,7 +1384,7 @@ inline bool operator!=(uint64_t V1, const APInt& V2) {
return V2 != V1; return V2 != V1;
} }
inline std::ostream &operator<<(std::ostream &OS, const APInt &I) { inline raw_ostream &operator<<(raw_ostream &OS, const APInt &I) {
I.print(OS, true); I.print(OS, true);
return OS; return OS;
} }

View File

@ -239,7 +239,7 @@ public:
void Profile(FoldingSetNodeID& ID) const; void Profile(FoldingSetNodeID& ID) const;
}; };
inline std::ostream &operator<<(std::ostream &OS, const APSInt &I) { inline raw_ostream &operator<<(raw_ostream &OS, const APSInt &I) {
I.print(OS, I.isSigned()); I.print(OS, I.isSigned());
return OS; return OS;
} }

View File

@ -65,11 +65,6 @@ public:
/// removeAttr - Remove a ParamAttr from an argument /// removeAttr - Remove a ParamAttr from an argument
void removeAttr(ParameterAttributes); void removeAttr(ParameterAttributes);
virtual void print(std::ostream &OS) const;
void print(std::ostream *OS) const {
if (OS) print(*OS);
}
/// classof - Methods for support type inquiry through isa, cast, and /// classof - Methods for support type inquiry through isa, cast, and
/// dyn_cast: /// dyn_cast:
/// ///

View File

@ -17,13 +17,12 @@
#ifndef LLVM_ASSEMBLY_ASMANNOTATIONWRITER_H #ifndef LLVM_ASSEMBLY_ASMANNOTATIONWRITER_H
#define LLVM_ASSEMBLY_ASMANNOTATIONWRITER_H #define LLVM_ASSEMBLY_ASMANNOTATIONWRITER_H
#include <iosfwd>
namespace llvm { namespace llvm {
class Function; class Function;
class BasicBlock; class BasicBlock;
class Instruction; class Instruction;
class raw_ostream;
struct AssemblyAnnotationWriter { struct AssemblyAnnotationWriter {
@ -31,21 +30,21 @@ struct AssemblyAnnotationWriter {
// emitFunctionAnnot - This may be implemented to emit a string right before // emitFunctionAnnot - This may be implemented to emit a string right before
// the start of a function. // the start of a function.
virtual void emitFunctionAnnot(const Function *F, std::ostream &OS) {} virtual void emitFunctionAnnot(const Function *F, raw_ostream &OS) {}
// emitBasicBlockStartAnnot - This may be implemented to emit a string right // emitBasicBlockStartAnnot - This may be implemented to emit a string right
// after the basic block label, but before the first instruction in the block. // after the basic block label, but before the first instruction in the block.
virtual void emitBasicBlockStartAnnot(const BasicBlock *BB, std::ostream &OS){ virtual void emitBasicBlockStartAnnot(const BasicBlock *BB, raw_ostream &OS){
} }
// emitBasicBlockEndAnnot - This may be implemented to emit a string right // emitBasicBlockEndAnnot - This may be implemented to emit a string right
// after the basic block. // after the basic block.
virtual void emitBasicBlockEndAnnot(const BasicBlock *BB, std::ostream &OS){ virtual void emitBasicBlockEndAnnot(const BasicBlock *BB, raw_ostream &OS){
} }
// emitInstructionAnnot - This may be implemented to emit a string right // emitInstructionAnnot - This may be implemented to emit a string right
// before an instruction is emitted. // before an instruction is emitted.
virtual void emitInstructionAnnot(const Instruction *I, std::ostream &OS) {} virtual void emitInstructionAnnot(const Instruction *I, raw_ostream &OS) {}
}; };
} // End llvm namespace } // End llvm namespace

View File

@ -24,12 +24,14 @@ namespace llvm {
class Type; class Type;
class Module; class Module;
class Value; class Value;
class raw_ostream;
// WriteTypeSymbolic - This attempts to write the specified type as a symbolic // WriteTypeSymbolic - This attempts to write the specified type as a symbolic
// type, iff there is an entry in the Module's symbol table for the specified // type, iff there is an entry in the Module's symbol table for the specified
// type or one of its component types. This is slower than a simple x << Type; // type or one of its component types. This is slower than a simple x << Type;
// //
void WriteTypeSymbolic(std::ostream &, const Type *, const Module *M); void WriteTypeSymbolic(std::ostream &, const Type *, const Module *M);
void WriteTypeSymbolic(raw_ostream &, const Type *, const Module *M);
// WriteAsOperand - Write the name of the specified value out to the specified // WriteAsOperand - Write the name of the specified value out to the specified
// ostream. This can be useful when you just want to print int %reg126, not the // ostream. This can be useful when you just want to print int %reg126, not the
@ -39,6 +41,8 @@ void WriteTypeSymbolic(std::ostream &, const Type *, const Module *M);
// //
void WriteAsOperand(std::ostream &, const Value *, bool PrintTy = true, void WriteAsOperand(std::ostream &, const Value *, bool PrintTy = true,
const Module *Context = 0); const Module *Context = 0);
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy = true,
const Module *Context = 0);
} // End llvm namespace } // End llvm namespace

View File

@ -157,10 +157,6 @@ public:
const InstListType &getInstList() const { return InstList; } const InstListType &getInstList() const { return InstList; }
InstListType &getInstList() { return InstList; } InstListType &getInstList() { return InstList; }
virtual void print(std::ostream &OS) const { print(OS, 0); }
void print(std::ostream *OS) const { if (OS) print(*OS); }
void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast: /// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const BasicBlock *) { return true; } static inline bool classof(const BasicBlock *) { return true; }
static inline bool classof(const Value *V) { static inline bool classof(const Value *V) {

View File

@ -29,6 +29,7 @@ class TargetData;
class TargetMachine; class TargetMachine;
class Type; class Type;
class MachineConstantPool; class MachineConstantPool;
class raw_ostream;
/// Abstract base class for all machine specific constantpool value subclasses. /// Abstract base class for all machine specific constantpool value subclasses.
/// ///
@ -50,8 +51,9 @@ public:
/// print - Implement operator<<... /// print - Implement operator<<...
/// ///
virtual void print(std::ostream &O) const = 0; void print(std::ostream &O) const;
void print(std::ostream *O) const { if (O) print(*O); } void print(std::ostream *O) const { if (O) print(*O); }
virtual void print(raw_ostream &O) const = 0;
}; };
inline std::ostream &operator<<(std::ostream &OS, inline std::ostream &operator<<(std::ostream &OS,
@ -59,6 +61,13 @@ inline std::ostream &operator<<(std::ostream &OS,
V.print(OS); V.print(OS);
return OS; return OS;
} }
inline raw_ostream &operator<<(raw_ostream &OS,
const MachineConstantPoolValue &V) {
V.print(OS);
return OS;
}
/// This class is a data container for one entry in a MachineConstantPool. /// This class is a data container for one entry in a MachineConstantPool.
/// It contains a pointer to the value and an offset from the start of /// It contains a pointer to the value and an offset from the start of

View File

@ -1260,6 +1260,7 @@ public:
/// ///
std::string getOperationName(const SelectionDAG *G = 0) const; std::string getOperationName(const SelectionDAG *G = 0) const;
static const char* getIndexedModeName(ISD::MemIndexedMode AM); static const char* getIndexedModeName(ISD::MemIndexedMode AM);
void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
void dump() const; void dump() const;
void dump(const SelectionDAG *G) const; void dump(const SelectionDAG *G) const;

View File

@ -58,9 +58,6 @@ public:
/// getNullValue. /// getNullValue.
virtual bool isNullValue() const = 0; virtual bool isNullValue() const = 0;
virtual void print(std::ostream &O) const;
void print(std::ostream *O) const { if (O) print(*O); }
/// canTrap - Return true if evaluation of this constant could trap. This is /// canTrap - Return true if evaluation of this constant could trap. This is
/// true for things like constant expressions that could divide by zero. /// true for things like constant expressions that could divide by zero.
bool canTrap() const; bool canTrap() const;

View File

@ -301,10 +301,6 @@ public:
size_t arg_size() const; size_t arg_size() const;
bool arg_empty() const; bool arg_empty() const;
virtual void print(std::ostream &OS) const { print(OS, 0); }
void print(std::ostream *OS) const { if (OS) print(*OS); }
void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
/// viewCFG - This function is meant for use from the debugger. You can just /// viewCFG - This function is meant for use from the debugger. You can just
/// say 'call F->viewCFG()' and a ghostview window should pop up from the /// say 'call F->viewCFG()' and a ghostview window should pop up from the
/// program, displaying the CFG of the current function with the code for each /// program, displaying the CFG of the current function with the code for each

View File

@ -62,9 +62,6 @@ public:
/// ///
void eraseFromParent(); void eraseFromParent();
virtual void print(std::ostream &OS) const;
void print(std::ostream *OS) const { if (OS) print(*OS); }
/// set/getAliasee - These methods retrive and set alias target. /// set/getAliasee - These methods retrive and set alias target.
void setAliasee(Constant* GV); void setAliasee(Constant* GV);
const Constant* getAliasee() const { const Constant* getAliasee() const {

View File

@ -133,9 +133,6 @@ public:
/// replace constant initializers. /// replace constant initializers.
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
virtual void print(std::ostream &OS) const;
void print(std::ostream *OS) const { if (OS) print(*OS); }
// Methods for support type inquiry through isa, cast, and dyn_cast: // Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const GlobalVariable *) { return true; } static inline bool classof(const GlobalVariable *) { return true; }
static inline bool classof(const Value *V) { static inline bool classof(const Value *V) {

View File

@ -21,7 +21,6 @@
namespace llvm { namespace llvm {
struct AssemblyAnnotationWriter;
class PointerType; class PointerType;
class FunctionType; class FunctionType;
class Module; class Module;
@ -58,10 +57,6 @@ public:
const std::string &getAsmString() const { return AsmString; } const std::string &getAsmString() const { return AsmString; }
const std::string &getConstraintString() const { return Constraints; } const std::string &getConstraintString() const { return Constraints; }
virtual void print(std::ostream &O) const { print(O, 0); }
void print(std::ostream *O) const { if (O) print(*O); }
void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
/// Verify - This static method can be used by the parser to check to see if /// Verify - This static method can be used by the parser to check to see if
/// the specified constraint string is legal for the type. This returns true /// the specified constraint string is legal for the type. This returns true
/// if legal, false if not. /// if legal, false if not.

View File

@ -20,8 +20,6 @@
namespace llvm { namespace llvm {
struct AssemblyAnnotationWriter;
template<typename ValueSubClass, typename ItemParentClass> template<typename ValueSubClass, typename ItemParentClass>
class SymbolTableListTraits; class SymbolTableListTraits;
@ -180,10 +178,6 @@ public:
} }
static bool isTrapping(unsigned op); static bool isTrapping(unsigned op);
virtual void print(std::ostream &OS) const { print(OS, 0); }
void print(std::ostream *OS) const { if (OS) print(*OS); }
void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast: /// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *) { return true; } static inline bool classof(const Instruction *) { return true; }
static inline bool classof(const Value *V) { static inline bool classof(const Value *V) {

View File

@ -350,15 +350,11 @@ public:
/// @name Utility functions for printing and dumping Module objects /// @name Utility functions for printing and dumping Module objects
/// @{ /// @{
public: public:
/// Print the module to an output stream
void print(std::ostream &OS) const { print(OS, 0); }
void print(std::ostream *OS) const { if (OS) print(*OS); }
/// Print the module to an output stream with AssemblyAnnotationWriter. /// Print the module to an output stream with AssemblyAnnotationWriter.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const;
void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const; void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
void print(std::ostream *OS, AssemblyAnnotationWriter *AAW) const {
if (OS) print(*OS, AAW); /// Dump the module to stderr (for debugging).
}
/// Dump the module to std::cerr (for debugging).
void dump() const; void dump() const;
/// This function causes all the subinstructions to "let go" of all references /// This function causes all the subinstructions to "let go" of all references
/// that they are maintaining. This allows one to 'delete' a whole class at /// that they are maintaining. This allows one to 'delete' a whole class at
@ -385,9 +381,14 @@ public:
/// An iostream inserter for modules. /// An iostream inserter for modules.
inline std::ostream &operator<<(std::ostream &O, const Module &M) { inline std::ostream &operator<<(std::ostream &O, const Module &M) {
M.print(O); M.print(O, 0);
return O; return O;
} }
inline raw_ostream &operator<<(raw_ostream &O, const Module &M) {
M.print(O, 0);
return O;
}
inline ValueSymbolTable * inline ValueSymbolTable *
ilist_traits<Function>::getSymTab(Module *M) { ilist_traits<Function>::getSymTab(Module *M) {

View File

@ -32,8 +32,6 @@
#include "llvm/ADT/APInt.h" #include "llvm/ADT/APInt.h"
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
#include "llvm/Support/Streams.h"
#include <iosfwd>
namespace llvm { namespace llvm {
@ -180,15 +178,14 @@ class ConstantRange {
/// print - Print out the bounds to a stream... /// print - Print out the bounds to a stream...
/// ///
void print(std::ostream &OS) const; void print(raw_ostream &OS) const;
void print(std::ostream *OS) const { if (OS) print(*OS); }
/// dump - Allow printing from a debugger easily... /// dump - Allow printing from a debugger easily...
/// ///
void dump() const; void dump() const;
}; };
inline std::ostream &operator<<(std::ostream &OS, const ConstantRange &CR) { inline raw_ostream &operator<<(raw_ostream &OS, const ConstantRange &CR) {
CR.print(OS); CR.print(OS);
return OS; return OS;
} }

View File

@ -96,7 +96,7 @@ public:
raw_ostream &operator<<(long N); raw_ostream &operator<<(long N);
raw_ostream &operator<<(unsigned long long N); raw_ostream &operator<<(unsigned long long N);
raw_ostream &operator<<(long long N); raw_ostream &operator<<(long long N);
raw_ostream &operator<<(const void *P);
raw_ostream &operator<<(unsigned int N) { raw_ostream &operator<<(unsigned int N) {
return this->operator<<(static_cast<unsigned long>(N)); return this->operator<<(static_cast<unsigned long>(N));
} }
@ -201,7 +201,8 @@ class raw_os_ostream : public raw_ostream {
std::ostream &OS; std::ostream &OS;
public: public:
raw_os_ostream(std::ostream &O) : OS(O) {} raw_os_ostream(std::ostream &O) : OS(O) {}
~raw_os_ostream();
/// flush_impl - The is the piece of the class that is implemented by /// flush_impl - The is the piece of the class that is implemented by
/// subclasses. This outputs the currently buffered data and resets the /// subclasses. This outputs the currently buffered data and resets the
/// buffer to empty. /// buffer to empty.

View File

@ -14,7 +14,6 @@
#include "llvm/AbstractTypeUser.h" #include "llvm/AbstractTypeUser.h"
#include "llvm/Support/Casting.h" #include "llvm/Support/Casting.h"
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
#include "llvm/Support/Streams.h"
#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/iterator.h" #include "llvm/ADT/iterator.h"
#include <string> #include <string>
@ -26,6 +25,7 @@ class DerivedType;
class PointerType; class PointerType;
class IntegerType; class IntegerType;
class TypeMapBase; class TypeMapBase;
class raw_ostream;
/// This file contains the declaration of the Type class. For more "Type" type /// This file contains the declaration of the Type class. For more "Type" type
/// stuff, look in DerivedTypes.h. /// stuff, look in DerivedTypes.h.
@ -156,6 +156,7 @@ protected:
PATypeHandle *ContainedTys; PATypeHandle *ContainedTys;
public: public:
void print(raw_ostream &O) const;
void print(std::ostream &O) const; void print(std::ostream &O) const;
void print(std::ostream *O) const { if (O) print(*O); } void print(std::ostream *O) const { if (O) print(*O); }
@ -450,6 +451,7 @@ template <> inline bool isa_impl<PointerType, Type>(const Type &Ty) {
} }
std::ostream &operator<<(std::ostream &OS, const Type &T); std::ostream &operator<<(std::ostream &OS, const Type &T);
raw_ostream &operator<<(raw_ostream &OS, const Type &T);
} // End llvm namespace } // End llvm namespace

View File

@ -35,6 +35,8 @@ class ValueSymbolTable;
class TypeSymbolTable; class TypeSymbolTable;
template<typename ValueTy> class StringMapEntry; template<typename ValueTy> class StringMapEntry;
typedef StringMapEntry<Value*> ValueName; typedef StringMapEntry<Value*> ValueName;
class raw_ostream;
class AssemblyAnnotationWriter;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Value Class // Value Class
@ -76,10 +78,10 @@ public:
// //
virtual void dump() const; virtual void dump() const;
/// print - Implement operator<< on Value... /// print - Implement operator<< on Value.
/// ///
virtual void print(std::ostream &O) const = 0; void print(std::ostream &O, AssemblyAnnotationWriter *AAW = 0) const;
void print(std::ostream *O) const { if (O) print(*O); } void print(raw_ostream &O, AssemblyAnnotationWriter *AAW = 0) const;
/// All values are typed, get the type of this value. /// All values are typed, get the type of this value.
/// ///
@ -237,7 +239,11 @@ inline std::ostream &operator<<(std::ostream &OS, const Value &V) {
V.print(OS); V.print(OS);
return OS; return OS;
} }
inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
V.print(OS);
return OS;
}
void Use::init(Value *V, User *) { void Use::init(Value *V, User *) {
Val = V; Val = V;
if (V) V->addUse(*this); if (V) V->addUse(*this);

View File

@ -6,6 +6,10 @@
// License. See LICENSE.TXT for details. // License. See LICENSE.TXT for details.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
//
// FIXME: What does this do?
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "loopvr" #define DEBUG_TYPE "loopvr"
#include "llvm/Analysis/LoopVR.h" #include "llvm/Analysis/LoopVR.h"
@ -15,13 +19,11 @@
#include "llvm/Assembly/Writer.h" #include "llvm/Assembly/Writer.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/Streams.h" #include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
char LoopVR::ID = 0; char LoopVR::ID = 0;
namespace {
static RegisterPass<LoopVR> X("loopvr", "Loop Value Ranges", true, true); static RegisterPass<LoopVR> X("loopvr", "Loop Value Ranges", true, true);
}
/// getRange - determine the range for a particular SCEV within a given Loop /// getRange - determine the range for a particular SCEV within a given Loop
ConstantRange LoopVR::getRange(SCEVHandle S, Loop *L, ScalarEvolution &SE) { ConstantRange LoopVR::getRange(SCEVHandle S, Loop *L, ScalarEvolution &SE) {
@ -220,11 +222,10 @@ ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){
bool LoopVR::runOnFunction(Function &F) { Map.clear(); return false; } bool LoopVR::runOnFunction(Function &F) { Map.clear(); return false; }
void LoopVR::print(std::ostream &os, const Module *) const { void LoopVR::print(std::ostream &os, const Module *) const {
raw_os_ostream OS(os);
for (std::map<Value *, ConstantRange *>::const_iterator I = Map.begin(), for (std::map<Value *, ConstantRange *>::const_iterator I = Map.begin(),
E = Map.end(); I != E; ++I) { E = Map.end(); I != E; ++I) {
os << *I->first << ": "; OS << *I->first << ": " << *I->second << '\n';
I->second->print(os);
os << "\n";
} }
} }

View File

@ -28,6 +28,7 @@
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/GraphWriter.h" #include "llvm/Support/GraphWriter.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/Config/config.h" #include "llvm/Config/config.h"
#include <fstream> #include <fstream>
@ -525,6 +526,10 @@ unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V,
return Constants.size()-1; return Constants.size()-1;
} }
void MachineConstantPoolValue::print(std::ostream &o) const {
raw_os_ostream OS(o);
print(OS);
}
void MachineConstantPool::print(std::ostream &OS) const { void MachineConstantPool::print(std::ostream &OS) const {
for (unsigned i = 0, e = Constants.size(); i != e; ++i) { for (unsigned i = 0, e = Constants.size(); i != e; ++i) {

View File

@ -24,12 +24,13 @@
#include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/PseudoSourceValue.h" #include "llvm/CodeGen/PseudoSourceValue.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallSet.h"
@ -4980,169 +4981,166 @@ std::string ISD::ArgFlagsTy::getArgFlagsString() {
void SDNode::dump() const { dump(0); } void SDNode::dump() const { dump(0); }
void SDNode::dump(const SelectionDAG *G) const { void SDNode::dump(const SelectionDAG *G) const {
cerr << (void*)this << ": "; print(errs(), G);
}
void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
OS << (void*)this << ": ";
for (unsigned i = 0, e = getNumValues(); i != e; ++i) { for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
if (i) cerr << ","; if (i) OS << ",";
if (getValueType(i) == MVT::Other) if (getValueType(i) == MVT::Other)
cerr << "ch"; OS << "ch";
else else
cerr << getValueType(i).getMVTString(); OS << getValueType(i).getMVTString();
} }
cerr << " = " << getOperationName(G); OS << " = " << getOperationName(G);
cerr << " "; OS << " ";
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
if (i) cerr << ", "; if (i) OS << ", ";
cerr << (void*)getOperand(i).Val; OS << (void*)getOperand(i).Val;
if (unsigned RN = getOperand(i).ResNo) if (unsigned RN = getOperand(i).ResNo)
cerr << ":" << RN; OS << ":" << RN;
} }
if (!isTargetOpcode() && getOpcode() == ISD::VECTOR_SHUFFLE) { if (!isTargetOpcode() && getOpcode() == ISD::VECTOR_SHUFFLE) {
SDNode *Mask = getOperand(2).Val; SDNode *Mask = getOperand(2).Val;
cerr << "<"; OS << "<";
for (unsigned i = 0, e = Mask->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = Mask->getNumOperands(); i != e; ++i) {
if (i) cerr << ","; if (i) OS << ",";
if (Mask->getOperand(i).getOpcode() == ISD::UNDEF) if (Mask->getOperand(i).getOpcode() == ISD::UNDEF)
cerr << "u"; OS << "u";
else else
cerr << cast<ConstantSDNode>(Mask->getOperand(i))->getValue(); OS << cast<ConstantSDNode>(Mask->getOperand(i))->getValue();
} }
cerr << ">"; OS << ">";
} }
if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) { if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
cerr << '<' << CSDN->getAPIntValue() << '>'; OS << '<' << CSDN->getAPIntValue() << '>';
} else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) { } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle) if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
cerr << '<' << CSDN->getValueAPF().convertToFloat() << '>'; OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble) else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble)
cerr << '<' << CSDN->getValueAPF().convertToDouble() << '>'; OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
else { else {
cerr << "<APFloat("; OS << "<APFloat(";
CSDN->getValueAPF().convertToAPInt().dump(); CSDN->getValueAPF().convertToAPInt().dump();
cerr << ")>"; OS << ")>";
} }
} else if (const GlobalAddressSDNode *GADN = } else if (const GlobalAddressSDNode *GADN =
dyn_cast<GlobalAddressSDNode>(this)) { dyn_cast<GlobalAddressSDNode>(this)) {
int offset = GADN->getOffset(); int offset = GADN->getOffset();
cerr << '<'; OS << '<';
WriteAsOperand(*cerr.stream(), GADN->getGlobal()); WriteAsOperand(OS, GADN->getGlobal());
cerr << '>'; OS << '>';
if (offset > 0) if (offset > 0)
cerr << " + " << offset; OS << " + " << offset;
else else
cerr << " " << offset; OS << " " << offset;
} else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) { } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
cerr << "<" << FIDN->getIndex() << ">"; OS << "<" << FIDN->getIndex() << ">";
} else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) { } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
cerr << "<" << JTDN->getIndex() << ">"; OS << "<" << JTDN->getIndex() << ">";
} else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){ } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
int offset = CP->getOffset(); int offset = CP->getOffset();
if (CP->isMachineConstantPoolEntry()) if (CP->isMachineConstantPoolEntry())
cerr << "<" << *CP->getMachineCPVal() << ">"; OS << "<" << *CP->getMachineCPVal() << ">";
else else
cerr << "<" << *CP->getConstVal() << ">"; OS << "<" << *CP->getConstVal() << ">";
if (offset > 0) if (offset > 0)
cerr << " + " << offset; OS << " + " << offset;
else else
cerr << " " << offset; OS << " " << offset;
} else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) { } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
cerr << "<"; OS << "<";
const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
if (LBB) if (LBB)
cerr << LBB->getName() << " "; OS << LBB->getName() << " ";
cerr << (const void*)BBDN->getBasicBlock() << ">"; OS << (const void*)BBDN->getBasicBlock() << ">";
} else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) { } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
if (G && R->getReg() && if (G && R->getReg() &&
TargetRegisterInfo::isPhysicalRegister(R->getReg())) { TargetRegisterInfo::isPhysicalRegister(R->getReg())) {
cerr << " " << G->getTarget().getRegisterInfo()->getName(R->getReg()); OS << " " << G->getTarget().getRegisterInfo()->getName(R->getReg());
} else { } else {
cerr << " #" << R->getReg(); OS << " #" << R->getReg();
} }
} else if (const ExternalSymbolSDNode *ES = } else if (const ExternalSymbolSDNode *ES =
dyn_cast<ExternalSymbolSDNode>(this)) { dyn_cast<ExternalSymbolSDNode>(this)) {
cerr << "'" << ES->getSymbol() << "'"; OS << "'" << ES->getSymbol() << "'";
} else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) { } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
if (M->getValue()) if (M->getValue())
cerr << "<" << M->getValue() << ">"; OS << "<" << M->getValue() << ">";
else else
cerr << "<null>"; OS << "<null>";
} else if (const MemOperandSDNode *M = dyn_cast<MemOperandSDNode>(this)) { } else if (const MemOperandSDNode *M = dyn_cast<MemOperandSDNode>(this)) {
if (M->MO.getValue()) if (M->MO.getValue())
cerr << "<" << M->MO.getValue() << ":" << M->MO.getOffset() << ">"; OS << "<" << M->MO.getValue() << ":" << M->MO.getOffset() << ">";
else else
cerr << "<null:" << M->MO.getOffset() << ">"; OS << "<null:" << M->MO.getOffset() << ">";
} else if (const ARG_FLAGSSDNode *N = dyn_cast<ARG_FLAGSSDNode>(this)) { } else if (const ARG_FLAGSSDNode *N = dyn_cast<ARG_FLAGSSDNode>(this)) {
cerr << N->getArgFlags().getArgFlagsString(); OS << N->getArgFlags().getArgFlagsString();
} else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) { } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
cerr << ":" << N->getVT().getMVTString(); OS << ":" << N->getVT().getMVTString();
} }
else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) { else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
const Value *SrcValue = LD->getSrcValue(); const Value *SrcValue = LD->getSrcValue();
int SrcOffset = LD->getSrcValueOffset(); int SrcOffset = LD->getSrcValueOffset();
cerr << " <"; OS << " <";
if (SrcValue) if (SrcValue)
cerr << SrcValue; OS << SrcValue;
else else
cerr << "null"; OS << "null";
cerr << ":" << SrcOffset << ">"; OS << ":" << SrcOffset << ">";
bool doExt = true; bool doExt = true;
switch (LD->getExtensionType()) { switch (LD->getExtensionType()) {
default: doExt = false; break; default: doExt = false; break;
case ISD::EXTLOAD: case ISD::EXTLOAD: OS << " <anyext "; break;
cerr << " <anyext "; case ISD::SEXTLOAD: OS << " <sext "; break;
break; case ISD::ZEXTLOAD: OS << " <zext "; break;
case ISD::SEXTLOAD:
cerr << " <sext ";
break;
case ISD::ZEXTLOAD:
cerr << " <zext ";
break;
} }
if (doExt) if (doExt)
cerr << LD->getMemoryVT().getMVTString() << ">"; OS << LD->getMemoryVT().getMVTString() << ">";
const char *AM = getIndexedModeName(LD->getAddressingMode()); const char *AM = getIndexedModeName(LD->getAddressingMode());
if (*AM) if (*AM)
cerr << " " << AM; OS << " " << AM;
if (LD->isVolatile()) if (LD->isVolatile())
cerr << " <volatile>"; OS << " <volatile>";
cerr << " alignment=" << LD->getAlignment(); OS << " alignment=" << LD->getAlignment();
} else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) { } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
const Value *SrcValue = ST->getSrcValue(); const Value *SrcValue = ST->getSrcValue();
int SrcOffset = ST->getSrcValueOffset(); int SrcOffset = ST->getSrcValueOffset();
cerr << " <"; OS << " <";
if (SrcValue) if (SrcValue)
cerr << SrcValue; OS << SrcValue;
else else
cerr << "null"; OS << "null";
cerr << ":" << SrcOffset << ">"; OS << ":" << SrcOffset << ">";
if (ST->isTruncatingStore()) if (ST->isTruncatingStore())
cerr << " <trunc " OS << " <trunc " << ST->getMemoryVT().getMVTString() << ">";
<< ST->getMemoryVT().getMVTString() << ">";
const char *AM = getIndexedModeName(ST->getAddressingMode()); const char *AM = getIndexedModeName(ST->getAddressingMode());
if (*AM) if (*AM)
cerr << " " << AM; OS << " " << AM;
if (ST->isVolatile()) if (ST->isVolatile())
cerr << " <volatile>"; OS << " <volatile>";
cerr << " alignment=" << ST->getAlignment(); OS << " alignment=" << ST->getAlignment();
} else if (const AtomicSDNode* AT = dyn_cast<AtomicSDNode>(this)) { } else if (const AtomicSDNode* AT = dyn_cast<AtomicSDNode>(this)) {
const Value *SrcValue = AT->getSrcValue(); const Value *SrcValue = AT->getSrcValue();
int SrcOffset = AT->getSrcValueOffset(); int SrcOffset = AT->getSrcValueOffset();
cerr << " <"; OS << " <";
if (SrcValue) if (SrcValue)
cerr << SrcValue; OS << SrcValue;
else else
cerr << "null"; OS << "null";
cerr << ":" << SrcOffset << ">"; OS << ":" << SrcOffset << ">";
if (AT->isVolatile()) if (AT->isVolatile())
cerr << " <volatile>"; OS << " <volatile>";
cerr << " alignment=" << AT->getAlignment(); OS << " alignment=" << AT->getAlignment();
} }
} }

View File

@ -18,6 +18,7 @@
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h" #include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cmath> #include <cmath>
#include <limits> #include <limits>
#include <cstring> #include <cstring>
@ -41,8 +42,7 @@ inline static uint64_t* getMemory(uint32_t numWords) {
return result; return result;
} }
void APInt::initSlowCase(uint32_t numBits, uint64_t val, bool isSigned) void APInt::initSlowCase(uint32_t numBits, uint64_t val, bool isSigned) {
{
pVal = getClearedMemory(getNumWords()); pVal = getClearedMemory(getNumWords());
pVal[0] = val; pVal[0] = val;
if (isSigned && int64_t(val) < 0) if (isSigned && int64_t(val) < 0)
@ -51,7 +51,7 @@ void APInt::initSlowCase(uint32_t numBits, uint64_t val, bool isSigned)
} }
APInt::APInt(uint32_t numBits, uint32_t numWords, const uint64_t bigVal[]) APInt::APInt(uint32_t numBits, uint32_t numWords, const uint64_t bigVal[])
: BitWidth(numBits), VAL(0) { : BitWidth(numBits), VAL(0) {
assert(BitWidth && "bitwidth too small"); assert(BitWidth && "bitwidth too small");
assert(bigVal && "Null pointer detected!"); assert(bigVal && "Null pointer detected!");
if (isSingleWord()) if (isSingleWord())
@ -1995,13 +1995,12 @@ void APInt::dump() const {
fprintf(stderr, "APInt(%db, %su %ss)", BitWidth, U.c_str(), S.c_str()); fprintf(stderr, "APInt(%db, %su %ss)", BitWidth, U.c_str(), S.c_str());
} }
void APInt::print(std::ostream &OS, bool isSigned) const { void APInt::print(raw_ostream &OS, bool isSigned) const {
SmallString<40> S; SmallString<40> S;
this->toString(S, 10, isSigned); this->toString(S, 10, isSigned);
OS << S.c_str(); OS << S.c_str();
} }
// This implements a variety of operations on a representation of // This implements a variety of operations on a representation of
// arbitrary precision, two's-complement, bignum integer values. // arbitrary precision, two's-complement, bignum integer values.

View File

@ -22,8 +22,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Support/ConstantRange.h" #include "llvm/Support/ConstantRange.h"
#include "llvm/Support/Streams.h" #include "llvm/Support/raw_ostream.h"
#include <ostream>
using namespace llvm; using namespace llvm;
/// Initialize a full (the default) or empty set for the specified type. /// Initialize a full (the default) or empty set for the specified type.
@ -462,12 +461,12 @@ ConstantRange ConstantRange::truncate(uint32_t DstTySize) const {
/// print - Print out the bounds to a stream... /// print - Print out the bounds to a stream...
/// ///
void ConstantRange::print(std::ostream &OS) const { void ConstantRange::print(raw_ostream &OS) const {
OS << "[" << Lower << "," << Upper << ")"; OS << "[" << Lower << "," << Upper << ")";
} }
/// dump - Allow printing from a debugger easily... /// dump - Allow printing from a debugger easily...
/// ///
void ConstantRange::dump() const { void ConstantRange::dump() const {
print(cerr); print(errs());
} }

View File

@ -99,6 +99,12 @@ raw_ostream &raw_ostream::operator<<(long long N) {
return this->operator<<(static_cast<unsigned long long>(N)); return this->operator<<(static_cast<unsigned long long>(N));
} }
raw_ostream &raw_ostream::operator<<(const void *P) {
// FIXME: This could be much faster if it matters.
return *this << format("%p", P);
}
raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) { raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
if (OutBufCur+Size > OutBufEnd) if (OutBufCur+Size > OutBufEnd)
flush_impl(); flush_impl();
@ -250,6 +256,10 @@ raw_ostream &llvm::errs() {
// raw_os_ostream // raw_os_ostream
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
raw_os_ostream::~raw_os_ostream() {
flush();
}
/// flush_impl - The is the piece of the class that is implemented by /// flush_impl - The is the piece of the class that is implemented by
/// subclasses. This outputs the currently buffered data and resets the /// subclasses. This outputs the currently buffered data and resets the
/// buffer to empty. /// buffer to empty.

View File

@ -15,6 +15,7 @@
#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/FoldingSet.h"
#include "llvm/GlobalValue.h" #include "llvm/GlobalValue.h"
#include "llvm/Type.h" #include "llvm/Type.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id, ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
@ -72,7 +73,7 @@ ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
ID.AddInteger(PCAdjust); ID.AddInteger(PCAdjust);
} }
void ARMConstantPoolValue::print(std::ostream &O) const { void ARMConstantPoolValue::print(raw_ostream &O) const {
if (GV) if (GV)
O << GV->getName(); O << GV->getName();
else else

View File

@ -69,7 +69,7 @@ public:
virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID); virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
virtual void print(std::ostream &O) const; virtual void print(raw_ostream &O) const;
}; };
} }

View File

@ -15,6 +15,7 @@
#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/FoldingSet.h"
#include "llvm/GlobalValue.h" #include "llvm/GlobalValue.h"
#include "llvm/Type.h" #include "llvm/Type.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
PIC16ConstantPoolValue::PIC16ConstantPoolValue(GlobalValue *gv, unsigned id, PIC16ConstantPoolValue::PIC16ConstantPoolValue(GlobalValue *gv, unsigned id,
@ -70,7 +71,7 @@ PIC16ConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
ID.AddInteger(PCAdjust); ID.AddInteger(PCAdjust);
} }
void PIC16ConstantPoolValue::print(std::ostream &O) const { void PIC16ConstantPoolValue::print(raw_ostream &O) const {
if (GV) if (GV)
O << GV->getName(); O << GV->getName();
else else

View File

@ -69,7 +69,7 @@ public:
virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID); virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
virtual void print(std::ostream &O) const; virtual void print(raw_ostream &O) const;
}; };
} }

View File

@ -922,7 +922,7 @@ namespace {
void dump(std::ostream &os) const { void dump(std::ostream &os) const {
os << "{"; os << "{";
for (const_iterator I = begin(), E = end(); I != E; ++I) { for (const_iterator I = begin(), E = end(); I != E; ++I) {
os << I->second << " (" << I->first->getDFSNumIn() << "), "; os << &I->second << " (" << I->first->getDFSNumIn() << "), ";
} }
os << "}"; os << "}";
} }

View File

@ -22,6 +22,7 @@
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm> #include <algorithm>
using namespace llvm; using namespace llvm;
@ -144,9 +145,10 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
DOUT << "RHS: " << RHS << "\n"; DOUT << "RHS: " << RHS << "\n";
CaseRange& Pivot = *(Begin + Mid); CaseRange& Pivot = *(Begin + Mid);
DEBUG(cerr << "Pivot ==> " DEBUG(errs() << "Pivot ==> "
<< cast<ConstantInt>(Pivot.Low)->getValue() << " -" << cast<ConstantInt>(Pivot.Low)->getValue() << " -"
<< cast<ConstantInt>(Pivot.High)->getValue() << "\n"); << cast<ConstantInt>(Pivot.High)->getValue() << "\n";
errs().flush());
BasicBlock* LBranch = switchConvert(LHS.begin(), LHS.end(), Val, BasicBlock* LBranch = switchConvert(LHS.begin(), LHS.end(), Val,
OrigBlock, Default); OrigBlock, Default);

View File

@ -31,7 +31,6 @@
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "llvm/Support/MathExtras.h" #include "llvm/Support/MathExtras.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
@ -126,7 +125,7 @@ enum PrefixType {
/// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
/// prefixed with % (if the string only contains simple characters) or is /// prefixed with % (if the string only contains simple characters) or is
/// surrounded with ""'s (if it has special chars in it). Print it out. /// surrounded with ""'s (if it has special chars in it). Print it out.
static void PrintLLVMName(std::ostream &OS, const char *NameStr, static void PrintLLVMName(raw_ostream &OS, const char *NameStr,
unsigned NameLen, PrefixType Prefix) { unsigned NameLen, PrefixType Prefix) {
assert(NameStr && "Cannot get empty name!"); assert(NameStr && "Cannot get empty name!");
switch (Prefix) { switch (Prefix) {
@ -184,7 +183,7 @@ static void PrintLLVMName(std::ostream &OS, const char *NameStr,
/// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
/// prefixed with % (if the string only contains simple characters) or is /// prefixed with % (if the string only contains simple characters) or is
/// surrounded with ""'s (if it has special chars in it). Print it out. /// surrounded with ""'s (if it has special chars in it). Print it out.
static void PrintLLVMName(std::ostream &OS, const Value *V) { static void PrintLLVMName(raw_ostream &OS, const Value *V) {
PrintLLVMName(OS, V->getNameStart(), V->getNameLen(), PrintLLVMName(OS, V->getNameStart(), V->getNameLen(),
isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix); isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix);
} }
@ -439,7 +438,7 @@ void SlotTracker::CreateFunctionSlot(const Value *V) {
// AsmWriter Implementation // AsmWriter Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
static void WriteAsOperandInternal(std::ostream &Out, const Value *V, static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
std::map<const Type *, std::string> &TypeTable, std::map<const Type *, std::string> &TypeTable,
SlotTracker *Machine); SlotTracker *Machine);
@ -579,7 +578,7 @@ static void calcTypeName(const Type *Ty,
/// printTypeInt - The internal guts of printing out a type that has a /// printTypeInt - The internal guts of printing out a type that has a
/// potentially named portion. /// potentially named portion.
/// ///
static void printTypeInt(std::ostream &Out, const Type *Ty, static void printTypeInt(raw_ostream &Out, const Type *Ty,
std::map<const Type *, std::string> &TypeNames) { std::map<const Type *, std::string> &TypeNames) {
// Primitive types always print out their description, regardless of whether // Primitive types always print out their description, regardless of whether
// they have been named or not. // they have been named or not.
@ -614,6 +613,11 @@ static void printTypeInt(std::ostream &Out, const Type *Ty,
/// ///
void llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty, void llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty,
const Module *M) { const Module *M) {
raw_os_ostream RO(Out);
WriteTypeSymbolic(RO, Ty, M);
}
void llvm::WriteTypeSymbolic(raw_ostream &Out, const Type *Ty, const Module *M){
Out << ' '; Out << ' ';
// If they want us to print out a type, but there is no context, we can't // If they want us to print out a type, but there is no context, we can't
@ -629,7 +633,7 @@ void llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty,
// PrintEscapedString - Print each character of the specified string, escaping // PrintEscapedString - Print each character of the specified string, escaping
// it if it is not printable or if it is an escape char. // it if it is not printable or if it is an escape char.
static void PrintEscapedString(const std::string &Str, std::ostream &Out) { static void PrintEscapedString(const std::string &Str, raw_ostream &Out) {
for (unsigned i = 0, e = Str.size(); i != e; ++i) { for (unsigned i = 0, e = Str.size(); i != e; ++i) {
unsigned char C = Str[i]; unsigned char C = Str[i];
if (isprint(C) && C != '"' && C != '\\') { if (isprint(C) && C != '"' && C != '\\') {
@ -675,7 +679,7 @@ static const char *getPredicateText(unsigned predicate) {
return pred; return pred;
} }
static void WriteConstantInt(std::ostream &Out, const Constant *CV, static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
std::map<const Type *, std::string> &TypeTable, std::map<const Type *, std::string> &TypeTable,
SlotTracker *Machine) { SlotTracker *Machine) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
@ -873,7 +877,7 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
/// ostream. This can be useful when you just want to print int %reg126, not /// ostream. This can be useful when you just want to print int %reg126, not
/// the whole instruction that generated it. /// the whole instruction that generated it.
/// ///
static void WriteAsOperandInternal(std::ostream &Out, const Value *V, static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
std::map<const Type*, std::string> &TypeTable, std::map<const Type*, std::string> &TypeTable,
SlotTracker *Machine) { SlotTracker *Machine) {
Out << ' '; Out << ' ';
@ -936,6 +940,12 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
/// ///
void llvm::WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType, void llvm::WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType,
const Module *Context) { const Module *Context) {
raw_os_ostream OS(Out);
WriteAsOperand(OS, V, PrintType, Context);
}
void llvm::WriteAsOperand(raw_ostream &Out, const Value *V, bool PrintType,
const Module *Context) {
std::map<const Type *, std::string> TypeNames; std::map<const Type *, std::string> TypeNames;
if (Context == 0) Context = getModuleFromVal(V); if (Context == 0) Context = getModuleFromVal(V);
@ -952,13 +962,13 @@ void llvm::WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType,
namespace { namespace {
class AssemblyWriter { class AssemblyWriter {
std::ostream &Out; raw_ostream &Out;
SlotTracker &Machine; SlotTracker &Machine;
const Module *TheModule; const Module *TheModule;
std::map<const Type *, std::string> TypeNames; std::map<const Type *, std::string> TypeNames;
AssemblyAnnotationWriter *AnnotationWriter; AssemblyAnnotationWriter *AnnotationWriter;
public: public:
inline AssemblyWriter(std::ostream &o, SlotTracker &Mac, const Module *M, inline AssemblyWriter(raw_ostream &o, SlotTracker &Mac, const Module *M,
AssemblyAnnotationWriter *AAW) AssemblyAnnotationWriter *AAW)
: Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) { : Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) {
@ -968,10 +978,19 @@ public:
fillTypeNameTable(M, TypeNames); fillTypeNameTable(M, TypeNames);
} }
void write(const Module *M) { printModule(M); } void write(const Module *M) { printModule(M); }
void write(const GlobalVariable *G) { printGlobal(G); }
void write(const GlobalAlias *G) { printAlias(G); } void write(const GlobalValue *G) {
void write(const Function *F) { printFunction(F); } if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(G))
printGlobal(GV);
else if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(G))
printAlias(GA);
else if (const Function *F = dyn_cast<Function>(G))
printFunction(F);
else
assert(0 && "Unknown global");
}
void write(const BasicBlock *BB) { printBasicBlock(BB); } void write(const BasicBlock *BB) { printBasicBlock(BB); }
void write(const Instruction *I) { printInstruction(*I); } void write(const Instruction *I) { printInstruction(*I); }
void write(const Type *Ty) { printType(Ty); } void write(const Type *Ty) { printType(Ty); }
@ -1176,7 +1195,7 @@ void AssemblyWriter::printModule(const Module *M) {
printFunction(I); printFunction(I);
} }
static void PrintLinkage(GlobalValue::LinkageTypes LT, std::ostream &Out) { static void PrintLinkage(GlobalValue::LinkageTypes LT, raw_ostream &Out) {
switch (LT) { switch (LT) {
case GlobalValue::InternalLinkage: Out << "internal "; break; case GlobalValue::InternalLinkage: Out << "internal "; break;
case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break; case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break;
@ -1195,7 +1214,7 @@ static void PrintLinkage(GlobalValue::LinkageTypes LT, std::ostream &Out) {
static void PrintVisibility(GlobalValue::VisibilityTypes Vis, static void PrintVisibility(GlobalValue::VisibilityTypes Vis,
std::ostream &Out) { raw_ostream &Out) {
switch (Vis) { switch (Vis) {
default: assert(0 && "Invalid visibility style!"); default: assert(0 && "Invalid visibility style!");
case GlobalValue::DefaultVisibility: break; case GlobalValue::DefaultVisibility: break;
@ -1705,74 +1724,75 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void Module::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { void Module::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
raw_os_ostream OS(o);
print(OS, AAW);
}
void Module::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const {
SlotTracker SlotTable(this); SlotTracker SlotTable(this);
AssemblyWriter W(o, SlotTable, this, AAW); AssemblyWriter W(OS, SlotTable, this, AAW);
W.write(this); W.write(this);
} }
void GlobalVariable::print(std::ostream &o) const {
SlotTracker SlotTable(getParent());
AssemblyWriter W(o, SlotTable, getParent(), 0);
W.write(this);
}
void GlobalAlias::print(std::ostream &o) const {
SlotTracker SlotTable(getParent());
AssemblyWriter W(o, SlotTable, getParent(), 0);
W.write(this);
}
void Function::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
SlotTracker SlotTable(getParent());
AssemblyWriter W(o, SlotTable, getParent(), AAW);
W.write(this);
}
void InlineAsm::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
WriteAsOperand(o, this, true, 0);
}
void BasicBlock::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
SlotTracker SlotTable(getParent());
AssemblyWriter W(o, SlotTable,
getParent() ? getParent()->getParent() : 0, AAW);
W.write(this);
}
void Instruction::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
const Function *F = getParent() ? getParent()->getParent() : 0;
SlotTracker SlotTable(F);
AssemblyWriter W(o, SlotTable, F ? F->getParent() : 0, AAW);
W.write(this);
}
void Constant::print(std::ostream &o) const {
if (this == 0) { o << "<null> constant value\n"; return; }
o << ' ' << getType()->getDescription() << ' ';
std::map<const Type *, std::string> TypeTable;
WriteConstantInt(o, this, TypeTable, 0);
}
void Type::print(std::ostream &o) const { void Type::print(std::ostream &o) const {
raw_os_ostream OS(o);
print(OS);
}
void Type::print(raw_ostream &o) const {
if (this == 0) if (this == 0)
o << "<null Type>"; o << "<null Type>";
else else
o << getDescription(); o << getDescription();
} }
void Argument::print(std::ostream &o) const { void Value::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const {
WriteAsOperand(o, this, true, getParent() ? getParent()->getParent() : 0); if (this == 0) {
OS << "printing a <null> value\n";
return;
}
if (const Instruction *I = dyn_cast<Instruction>(this)) {
const Function *F = I->getParent() ? I->getParent()->getParent() : 0;
SlotTracker SlotTable(F);
AssemblyWriter W(OS, SlotTable, F ? F->getParent() : 0, AAW);
W.write(I);
} else if (const BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
SlotTracker SlotTable(BB->getParent());
AssemblyWriter W(OS, SlotTable,
BB->getParent() ? BB->getParent()->getParent() : 0, AAW);
W.write(BB);
} else if (const GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
SlotTracker SlotTable(GV->getParent());
AssemblyWriter W(OS, SlotTable, GV->getParent(), 0);
W.write(GV);
} else if (const Constant *C = dyn_cast<Constant>(this)) {
OS << ' ' << C->getType()->getDescription() << ' ';
std::map<const Type *, std::string> TypeTable;
WriteConstantInt(OS, C, TypeTable, 0);
} else if (const Argument *A = dyn_cast<Argument>(this)) {
WriteAsOperand(OS, this, true,
A->getParent() ? A->getParent()->getParent() : 0);
} else if (isa<InlineAsm>(this)) {
WriteAsOperand(OS, this, true, 0);
} else {
assert(0 && "Unknown value to print out!");
}
}
void Value::print(std::ostream &O, AssemblyAnnotationWriter *AAW) const {
raw_os_ostream OS(O);
print(OS, AAW);
} }
// Value::dump - allow easy printing of Values from the debugger. // Value::dump - allow easy printing of Values from the debugger.
// Located here because so much of the needed functionality is here. // Located here because so much of the needed functionality is here.
void Value::dump() const { print(*cerr.stream()); cerr << '\n'; } void Value::dump() const { print(errs()); errs() << '\n'; }
// Type::dump - allow easy printing of Values from the debugger. // Type::dump - allow easy printing of Values from the debugger.
// Located here because so much of the needed functionality is here. // Located here because so much of the needed functionality is here.
void Type::dump() const { print(*cerr.stream()); cerr << '\n'; } void Type::dump() const { print(errs()); errs() << '\n'; }
// Module::dump() - Allow printing from debugger
void Module::dump() const { print(errs(), 0); }

View File

@ -88,11 +88,6 @@ Module::~Module() {
delete TypeSymTab; delete TypeSymTab;
} }
// Module::dump() - Allow printing from debugger
void Module::dump() const {
print(*cerr.stream());
}
/// Target endian information... /// Target endian information...
Module::Endianness Module::getEndianness() const { Module::Endianness Module::getEndianness() const {
std::string temp = DataLayout; std::string temp = DataLayout;

View File

@ -21,6 +21,7 @@
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h" #include "llvm/System/Signals.h"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
@ -71,12 +72,12 @@ namespace {
std::map<ProfileInfoLoader::Edge, unsigned> &EF) std::map<ProfileInfoLoader::Edge, unsigned> &EF)
: FuncFreqs(FF), BlockFreqs(BF), EdgeFreqs(EF) {} : FuncFreqs(FF), BlockFreqs(BF), EdgeFreqs(EF) {}
virtual void emitFunctionAnnot(const Function *F, std::ostream &OS) { virtual void emitFunctionAnnot(const Function *F, raw_ostream &OS) {
OS << ";;; %" << F->getName() << " called " << FuncFreqs[F] OS << ";;; %" << F->getName() << " called " << FuncFreqs[F]
<< " times.\n;;;\n"; << " times.\n;;;\n";
} }
virtual void emitBasicBlockStartAnnot(const BasicBlock *BB, virtual void emitBasicBlockStartAnnot(const BasicBlock *BB,
std::ostream &OS) { raw_ostream &OS) {
if (BlockFreqs.empty()) return; if (BlockFreqs.empty()) return;
if (unsigned Count = BlockFreqs[BB]) if (unsigned Count = BlockFreqs[BB])
OS << "\t;;; Basic block executed " << Count << " times.\n"; OS << "\t;;; Basic block executed " << Count << " times.\n";
@ -84,7 +85,7 @@ namespace {
OS << "\t;;; Never executed!\n"; OS << "\t;;; Never executed!\n";
} }
virtual void emitBasicBlockEndAnnot(const BasicBlock *BB, std::ostream &OS){ virtual void emitBasicBlockEndAnnot(const BasicBlock *BB, raw_ostream &OS) {
if (EdgeFreqs.empty()) return; if (EdgeFreqs.empty()) return;
// Figure out how many times each successor executed. // Figure out how many times each successor executed.
@ -235,7 +236,7 @@ int main(int argc, char **argv) {
if (FunctionsToPrint.empty() || PrintAllCode) if (FunctionsToPrint.empty() || PrintAllCode)
M->print(std::cout, &PA); M->print(std::cout, &PA);
else else
// Print just a subset of the functions... // Print just a subset of the functions.
for (std::set<Function*>::iterator I = FunctionsToPrint.begin(), for (std::set<Function*>::iterator I = FunctionsToPrint.begin(),
E = FunctionsToPrint.end(); I != E; ++I) E = FunctionsToPrint.end(); I != E; ++I)
(*I)->print(std::cout, &PA); (*I)->print(std::cout, &PA);