2
0

Trace.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===- Trace.cpp - Implementation of Trace class --------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This class represents a single trace of LLVM basic blocks. A trace is a
  11. // single entry, multiple exit, region of code that is often hot. Trace-based
  12. // optimizations treat traces almost like they are a large, strange, basic
  13. // block: because the trace path is assumed to be hot, optimizations for the
  14. // fall-through path are made at the expense of the non-fall-through paths.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #include "llvm/Analysis/Trace.h"
  18. #include "llvm/IR/Function.h"
  19. #include "llvm/Support/Debug.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. using namespace llvm;
  22. Function *Trace::getFunction() const {
  23. return getEntryBasicBlock()->getParent();
  24. }
  25. Module *Trace::getModule() const {
  26. return getFunction()->getParent();
  27. }
  28. /// print - Write trace to output stream.
  29. ///
  30. void Trace::print(raw_ostream &O) const {
  31. Function *F = getFunction();
  32. O << "; Trace from function " << F->getName() << ", blocks:\n";
  33. for (const_iterator i = begin(), e = end(); i != e; ++i) {
  34. O << "; ";
  35. (*i)->printAsOperand(O, true, getModule());
  36. O << "\n";
  37. }
  38. O << "; Trace parent function: \n" << *F;
  39. }
  40. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  41. /// dump - Debugger convenience method; writes trace to standard error
  42. /// output stream.
  43. ///
  44. void Trace::dump() const {
  45. print(dbgs());
  46. }
  47. #endif