blob: 4dec53151ed629c173c33c1d78b72e43d6c59476 [file] [log] [blame]
Chris Lattner6ba89722004-03-08 20:57:27 +00001//===- Trace.cpp - Implementation of Trace class --------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner6ba89722004-03-08 20:57:27 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This class represents a single trace of LLVM basic blocks. A trace is a
11// single entry, multiple exit, region of code that is often hot. Trace-based
12// optimizations treat traces almost like they are a large, strange, basic
13// block: because the trace path is assumed to be hot, optimizations for the
14// fall-through path are made at the expense of the non-fall-through paths.
15//
16//===----------------------------------------------------------------------===//
17
18#include "llvm/Analysis/Trace.h"
Nico Weber0f38c602018-04-30 14:59:11 +000019#include "llvm/Config/llvm-config.h"
Eugene Zelenko15a56d42017-07-21 21:37:46 +000020#include "llvm/IR/BasicBlock.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000021#include "llvm/IR/Function.h"
Eugene Zelenko15a56d42017-07-21 21:37:46 +000022#include "llvm/Support/Compiler.h"
David Greenec48e3d12009-12-23 22:35:10 +000023#include "llvm/Support/Debug.h"
Chris Lattnerbdff5482009-08-23 04:37:46 +000024#include "llvm/Support/raw_ostream.h"
Eugene Zelenko15a56d42017-07-21 21:37:46 +000025
Chris Lattner6ba89722004-03-08 20:57:27 +000026using namespace llvm;
27
28Function *Trace::getFunction() const {
29 return getEntryBasicBlock()->getParent();
30}
31
Chris Lattner6ba89722004-03-08 20:57:27 +000032Module *Trace::getModule() const {
33 return getFunction()->getParent();
34}
35
36/// print - Write trace to output stream.
Chris Lattnerbdff5482009-08-23 04:37:46 +000037void Trace::print(raw_ostream &O) const {
38 Function *F = getFunction();
Benjamin Kramera7b0cb72011-11-15 16:27:03 +000039 O << "; Trace from function " << F->getName() << ", blocks:\n";
Bill Wendling6f81b512006-11-28 22:46:12 +000040 for (const_iterator i = begin(), e = end(); i != e; ++i) {
Chris Lattner6ba89722004-03-08 20:57:27 +000041 O << "; ";
Chandler Carruth560e3952014-01-09 02:29:41 +000042 (*i)->printAsOperand(O, true, getModule());
Chris Lattner6ba89722004-03-08 20:57:27 +000043 O << "\n";
44 }
45 O << "; Trace parent function: \n" << *F;
46}
47
Aaron Ballman1d03d382017-10-15 14:32:27 +000048#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Chris Lattner6ba89722004-03-08 20:57:27 +000049/// dump - Debugger convenience method; writes trace to standard error
50/// output stream.
Yaron Keren55307982016-01-29 20:50:44 +000051LLVM_DUMP_METHOD void Trace::dump() const {
David Greenec48e3d12009-12-23 22:35:10 +000052 print(dbgs());
Chris Lattner6ba89722004-03-08 20:57:27 +000053}
Manman Rencc77eec2012-09-06 19:55:56 +000054#endif