1*9880d681SAndroid Build Coastguard Worker //===- Trace.cpp - Implementation of Trace class --------------------------===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This class represents a single trace of LLVM basic blocks. A trace is a 11*9880d681SAndroid Build Coastguard Worker // single entry, multiple exit, region of code that is often hot. Trace-based 12*9880d681SAndroid Build Coastguard Worker // optimizations treat traces almost like they are a large, strange, basic 13*9880d681SAndroid Build Coastguard Worker // block: because the trace path is assumed to be hot, optimizations for the 14*9880d681SAndroid Build Coastguard Worker // fall-through path are made at the expense of the non-fall-through paths. 15*9880d681SAndroid Build Coastguard Worker // 16*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/Trace.h" 19*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Function.h" 20*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Debug.h" 21*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h" 22*9880d681SAndroid Build Coastguard Worker using namespace llvm; 23*9880d681SAndroid Build Coastguard Worker getFunction() const24*9880d681SAndroid Build Coastguard WorkerFunction *Trace::getFunction() const { 25*9880d681SAndroid Build Coastguard Worker return getEntryBasicBlock()->getParent(); 26*9880d681SAndroid Build Coastguard Worker } 27*9880d681SAndroid Build Coastguard Worker getModule() const28*9880d681SAndroid Build Coastguard WorkerModule *Trace::getModule() const { 29*9880d681SAndroid Build Coastguard Worker return getFunction()->getParent(); 30*9880d681SAndroid Build Coastguard Worker } 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard Worker /// print - Write trace to output stream. 33*9880d681SAndroid Build Coastguard Worker /// print(raw_ostream & O) const34*9880d681SAndroid Build Coastguard Workervoid Trace::print(raw_ostream &O) const { 35*9880d681SAndroid Build Coastguard Worker Function *F = getFunction(); 36*9880d681SAndroid Build Coastguard Worker O << "; Trace from function " << F->getName() << ", blocks:\n"; 37*9880d681SAndroid Build Coastguard Worker for (const_iterator i = begin(), e = end(); i != e; ++i) { 38*9880d681SAndroid Build Coastguard Worker O << "; "; 39*9880d681SAndroid Build Coastguard Worker (*i)->printAsOperand(O, true, getModule()); 40*9880d681SAndroid Build Coastguard Worker O << "\n"; 41*9880d681SAndroid Build Coastguard Worker } 42*9880d681SAndroid Build Coastguard Worker O << "; Trace parent function: \n" << *F; 43*9880d681SAndroid Build Coastguard Worker } 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 46*9880d681SAndroid Build Coastguard Worker /// dump - Debugger convenience method; writes trace to standard error 47*9880d681SAndroid Build Coastguard Worker /// output stream. 48*9880d681SAndroid Build Coastguard Worker /// dump() const49*9880d681SAndroid Build Coastguard WorkerLLVM_DUMP_METHOD void Trace::dump() const { 50*9880d681SAndroid Build Coastguard Worker print(dbgs()); 51*9880d681SAndroid Build Coastguard Worker } 52*9880d681SAndroid Build Coastguard Worker #endif 53