2009-06-02 17:52:33 +00:00
|
|
|
//===- Trace.cpp - Implementation of Trace class --------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class represents a single trace of LLVM basic blocks. A trace is a
|
|
|
|
// single entry, multiple exit, region of code that is often hot. Trace-based
|
|
|
|
// optimizations treat traces almost like they are a large, strange, basic
|
|
|
|
// block: because the trace path is assumed to be hot, optimizations for the
|
|
|
|
// fall-through path are made at the expense of the non-fall-through paths.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/Trace.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
2010-01-01 10:31:22 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-10-14 17:57:32 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
Function *Trace::getFunction() const {
|
|
|
|
return getEntryBasicBlock()->getParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
Module *Trace::getModule() const {
|
|
|
|
return getFunction()->getParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// print - Write trace to output stream.
|
|
|
|
///
|
2009-10-14 17:57:32 +00:00
|
|
|
void Trace::print(raw_ostream &O) const {
|
|
|
|
Function *F = getFunction();
|
2012-04-14 13:54:10 +00:00
|
|
|
O << "; Trace from function " << F->getName() << ", blocks:\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
for (const_iterator i = begin(), e = end(); i != e; ++i) {
|
|
|
|
O << "; ";
|
2014-11-24 09:08:18 +00:00
|
|
|
(*i)->printAsOperand(O, true, getModule());
|
2009-06-02 17:52:33 +00:00
|
|
|
O << "\n";
|
|
|
|
}
|
|
|
|
O << "; Trace parent function: \n" << *F;
|
|
|
|
}
|
|
|
|
|
2012-12-02 13:10:19 +00:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2009-06-02 17:52:33 +00:00
|
|
|
/// dump - Debugger convenience method; writes trace to standard error
|
|
|
|
/// output stream.
|
|
|
|
///
|
2016-07-23 20:41:05 +00:00
|
|
|
LLVM_DUMP_METHOD void Trace::dump() const {
|
2010-01-01 10:31:22 +00:00
|
|
|
print(dbgs());
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2012-12-02 13:10:19 +00:00
|
|
|
#endif
|