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