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 is distributed under the University of Illinois Open Source
00006 // 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/Assembly/Writer.h"
00020 #include "llvm/IR/Function.h"
00021 #include "llvm/Support/Debug.h"
00022 #include "llvm/Support/raw_ostream.h"
00023 using namespace llvm;
00024 
00025 Function *Trace::getFunction() const {
00026   return getEntryBasicBlock()->getParent();
00027 }
00028 
00029 Module *Trace::getModule() const {
00030   return getFunction()->getParent();
00031 }
00032 
00033 /// print - Write trace to output stream.
00034 ///
00035 void Trace::print(raw_ostream &O) const {
00036   Function *F = getFunction();
00037   O << "; Trace from function " << F->getName() << ", blocks:\n";
00038   for (const_iterator i = begin(), e = end(); i != e; ++i) {
00039     O << "; ";
00040     WriteAsOperand(O, *i, true, getModule());
00041     O << "\n";
00042   }
00043   O << "; Trace parent function: \n" << *F;
00044 }
00045 
00046 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
00047 /// dump - Debugger convenience method; writes trace to standard error
00048 /// output stream.
00049 ///
00050 void Trace::dump() const {
00051   print(dbgs());
00052 }
00053 #endif