2015-10-10 02:21:14 +02:00
|
|
|
//===--- BinaryBasicBlock.cpp - Interface for assembly-level basic block --===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-15 00:35:14 +02:00
|
|
|
#include "BinaryBasicBlock.h"
|
|
|
|
#include "BinaryFunction.h"
|
2015-10-10 02:21:14 +02:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
|
|
|
#include <limits>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#undef DEBUG_TYPE
|
2016-02-05 23:42:04 +01:00
|
|
|
#define DEBUG_TYPE "bolt"
|
2015-10-10 02:21:14 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2016-02-05 23:42:04 +01:00
|
|
|
namespace bolt {
|
2015-10-10 02:21:14 +02:00
|
|
|
|
|
|
|
bool operator<(const BinaryBasicBlock &LHS, const BinaryBasicBlock &RHS) {
|
|
|
|
return LHS.Offset < RHS.Offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinaryBasicBlock::addSuccessor(BinaryBasicBlock *Succ,
|
|
|
|
uint64_t Count,
|
|
|
|
uint64_t MispredictedCount) {
|
|
|
|
Successors.push_back(Succ);
|
2015-10-12 21:30:47 +02:00
|
|
|
BranchInfo.push_back({Count, MispredictedCount});
|
2015-10-10 02:21:14 +02:00
|
|
|
Succ->Predecessors.push_back(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinaryBasicBlock::removeSuccessor(BinaryBasicBlock *Succ) {
|
|
|
|
Succ->removePredecessor(this);
|
2015-10-12 21:30:47 +02:00
|
|
|
auto I = succ_begin();
|
|
|
|
auto BI = BranchInfo.begin();
|
|
|
|
for (; I != succ_end(); ++I) {
|
|
|
|
assert(BI != BranchInfo.end() && "missing BranchInfo entry");
|
|
|
|
if (*I == Succ)
|
|
|
|
break;
|
|
|
|
++BI;
|
|
|
|
}
|
2015-10-10 02:21:14 +02:00
|
|
|
assert(I != succ_end() && "no such successor!");
|
|
|
|
|
|
|
|
Successors.erase(I);
|
2015-10-12 21:30:47 +02:00
|
|
|
BranchInfo.erase(BI);
|
2015-10-10 02:21:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BinaryBasicBlock::addPredecessor(BinaryBasicBlock *Pred) {
|
|
|
|
Predecessors.push_back(Pred);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinaryBasicBlock::removePredecessor(BinaryBasicBlock *Pred) {
|
|
|
|
auto I = std::find(pred_begin(), pred_end(), Pred);
|
|
|
|
assert(I != pred_end() && "Pred is not a predecessor of this block!");
|
|
|
|
Predecessors.erase(I);
|
|
|
|
}
|
|
|
|
|
2016-02-05 23:42:04 +01:00
|
|
|
} // namespace bolt
|
2015-10-10 02:21:14 +02:00
|
|
|
} // namespace llvm
|