1193323Sed//===- Trace.cpp - Implementation of Trace class --------------------------===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This class represents a single trace of LLVM basic blocks. A trace is a 11193323Sed// single entry, multiple exit, region of code that is often hot. Trace-based 12193323Sed// optimizations treat traces almost like they are a large, strange, basic 13193323Sed// block: because the trace path is assumed to be hot, optimizations for the 14193323Sed// fall-through path are made at the expense of the non-fall-through paths. 15193323Sed// 16193323Sed//===----------------------------------------------------------------------===// 17193323Sed 18193323Sed#include "llvm/Analysis/Trace.h" 19193323Sed#include "llvm/Assembly/Writer.h" 20249423Sdim#include "llvm/IR/Function.h" 21201360Srdivacky#include "llvm/Support/Debug.h" 22198090Srdivacky#include "llvm/Support/raw_ostream.h" 23193323Sedusing namespace llvm; 24193323Sed 25193323SedFunction *Trace::getFunction() const { 26193323Sed return getEntryBasicBlock()->getParent(); 27193323Sed} 28193323Sed 29193323SedModule *Trace::getModule() const { 30193323Sed return getFunction()->getParent(); 31193323Sed} 32193323Sed 33193323Sed/// print - Write trace to output stream. 34193323Sed/// 35198090Srdivackyvoid Trace::print(raw_ostream &O) const { 36198090Srdivacky Function *F = getFunction(); 37234353Sdim O << "; Trace from function " << F->getName() << ", blocks:\n"; 38193323Sed for (const_iterator i = begin(), e = end(); i != e; ++i) { 39193323Sed O << "; "; 40193323Sed WriteAsOperand(O, *i, true, getModule()); 41193323Sed O << "\n"; 42193323Sed } 43193323Sed O << "; Trace parent function: \n" << *F; 44193323Sed} 45193323Sed 46243830Sdim#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 47193323Sed/// dump - Debugger convenience method; writes trace to standard error 48193323Sed/// output stream. 49193323Sed/// 50193323Sedvoid Trace::dump() const { 51201360Srdivacky print(dbgs()); 52193323Sed} 53243830Sdim#endif 54