Trace.cpp 1.8 KB

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