163b49d05SChris Lattner //===- Trace.cpp - Implementation of Trace class --------------------------===//
263b49d05SChris Lattner //
3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
663b49d05SChris Lattner //
763b49d05SChris Lattner //===----------------------------------------------------------------------===//
863b49d05SChris Lattner //
963b49d05SChris Lattner // This class represents a single trace of LLVM basic blocks. A trace is a
1063b49d05SChris Lattner // single entry, multiple exit, region of code that is often hot. Trace-based
1163b49d05SChris Lattner // optimizations treat traces almost like they are a large, strange, basic
1263b49d05SChris Lattner // block: because the trace path is assumed to be hot, optimizations for the
1363b49d05SChris Lattner // fall-through path are made at the expense of the non-fall-through paths.
1463b49d05SChris Lattner //
1563b49d05SChris Lattner //===----------------------------------------------------------------------===//
1663b49d05SChris Lattner
1763b49d05SChris Lattner #include "llvm/Analysis/Trace.h"
18432a3883SNico Weber #include "llvm/Config/llvm-config.h"
1938c02bc7SEugene Zelenko #include "llvm/IR/BasicBlock.h"
209fb823bbSChandler Carruth #include "llvm/IR/Function.h"
2138c02bc7SEugene Zelenko #include "llvm/Support/Compiler.h"
22452fc61aSDavid Greene #include "llvm/Support/Debug.h"
23b25de3ffSChris Lattner #include "llvm/Support/raw_ostream.h"
2438c02bc7SEugene Zelenko
2563b49d05SChris Lattner using namespace llvm;
2663b49d05SChris Lattner
getFunction() const2763b49d05SChris Lattner Function *Trace::getFunction() const {
2863b49d05SChris Lattner return getEntryBasicBlock()->getParent();
2963b49d05SChris Lattner }
3063b49d05SChris Lattner
getModule() const3163b49d05SChris Lattner Module *Trace::getModule() const {
3263b49d05SChris Lattner return getFunction()->getParent();
3363b49d05SChris Lattner }
3463b49d05SChris Lattner
3563b49d05SChris Lattner /// print - Write trace to output stream.
print(raw_ostream & O) const36b25de3ffSChris Lattner void Trace::print(raw_ostream &O) const {
3763b49d05SChris Lattner Function *F = getFunction();
381f97a5a6SBenjamin Kramer O << "; Trace from function " << F->getName() << ", blocks:\n";
3963b49d05SChris Lattner for (const_iterator i = begin(), e = end(); i != e; ++i) {
4063b49d05SChris Lattner O << "; ";
41d48cdbf0SChandler Carruth (*i)->printAsOperand(O, true, getModule());
4263b49d05SChris Lattner O << "\n";
4363b49d05SChris Lattner }
4463b49d05SChris Lattner O << "; Trace parent function: \n" << *F;
4563b49d05SChris Lattner }
4663b49d05SChris Lattner
47615eb470SAaron Ballman #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4863b49d05SChris Lattner /// dump - Debugger convenience method; writes trace to standard error
4963b49d05SChris Lattner /// output stream.
dump() const50eb2a2546SYaron Keren LLVM_DUMP_METHOD void Trace::dump() const {
51452fc61aSDavid Greene print(dbgs());
5263b49d05SChris Lattner }
53c3366cceSManman Ren #endif
54