LLVM API Documentation

Trace.cpp

Go to the documentation of this file.
00001 //===- Trace.cpp - Implementation of Trace class --------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This class represents a single trace of LLVM basic blocks.  A trace is a
00011 // single entry, multiple exit, region of code that is often hot.  Trace-based
00012 // optimizations treat traces almost like they are a large, strange, basic
00013 // block: because the trace path is assumed to be hot, optimizations for the
00014 // fall-through path are made at the expense of the non-fall-through paths.
00015 //
00016 //===----------------------------------------------------------------------===//
00017 
00018 #include "llvm/Analysis/Trace.h"
00019 #include "llvm/Function.h"
00020 #include "llvm/Assembly/Writer.h"
00021 #include <iostream>
00022 
00023 using namespace llvm;
00024 
00025 Function *Trace::getFunction() const {
00026   return getEntryBasicBlock()->getParent();
00027 }
00028 
00029 
00030 Module *Trace::getModule() const {
00031   return getFunction()->getParent();
00032 }
00033 
00034 /// print - Write trace to output stream.
00035 ///
00036 void Trace::print (std::ostream &O) const {
00037   Function *F = getFunction ();
00038   O << "; Trace from function " << F->getName () << ", blocks:\n";
00039   for (const_iterator i = begin (), e = end (); i != e; ++i) {
00040     O << "; ";
00041     WriteAsOperand (O, *i, true, true, getModule ());
00042     O << "\n";
00043   }
00044   O << "; Trace parent function: \n" << *F;
00045 }
00046 
00047 /// dump - Debugger convenience method; writes trace to standard error
00048 /// output stream.
00049 ///
00050 void Trace::dump () const {
00051   print (std::cerr);
00052 }