mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 18:24:00 +00:00
MC CFG: Use data structures more appropriate than std::set.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188888 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -8,8 +8,8 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/MC/MCObjectDisassembler.h"
|
#include "llvm/MC/MCObjectDisassembler.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/SetVector.h"
|
#include "llvm/ADT/SetVector.h"
|
||||||
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/ADT/StringExtras.h"
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/ADT/Twine.h"
|
#include "llvm/ADT/Twine.h"
|
||||||
@ -27,7 +27,7 @@
|
|||||||
#include "llvm/Support/StringRefMemoryObject.h"
|
#include "llvm/Support/StringRefMemoryObject.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <vector>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace object;
|
using namespace object;
|
||||||
@ -149,7 +149,7 @@ void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct BBInfo;
|
struct BBInfo;
|
||||||
typedef std::set<BBInfo*> BBInfoSetTy;
|
typedef SmallPtrSet<BBInfo*, 2> BBInfoSetTy;
|
||||||
|
|
||||||
struct BBInfo {
|
struct BBInfo {
|
||||||
MCTextAtom *Atom;
|
MCTextAtom *Atom;
|
||||||
@ -169,7 +169,7 @@ namespace {
|
|||||||
void MCObjectDisassembler::buildCFG(MCModule *Module) {
|
void MCObjectDisassembler::buildCFG(MCModule *Module) {
|
||||||
typedef std::map<uint64_t, BBInfo> BBInfoByAddrTy;
|
typedef std::map<uint64_t, BBInfo> BBInfoByAddrTy;
|
||||||
BBInfoByAddrTy BBInfos;
|
BBInfoByAddrTy BBInfos;
|
||||||
typedef std::set<uint64_t> AddressSetTy;
|
typedef std::vector<uint64_t> AddressSetTy;
|
||||||
AddressSetTy Splits;
|
AddressSetTy Splits;
|
||||||
AddressSetTy Calls;
|
AddressSetTy Calls;
|
||||||
|
|
||||||
@ -184,8 +184,8 @@ void MCObjectDisassembler::buildCFG(MCModule *Module) {
|
|||||||
uint64_t SymAddr;
|
uint64_t SymAddr;
|
||||||
SI->getAddress(SymAddr);
|
SI->getAddress(SymAddr);
|
||||||
SymAddr = getEffectiveLoadAddr(SymAddr);
|
SymAddr = getEffectiveLoadAddr(SymAddr);
|
||||||
Calls.insert(SymAddr);
|
Calls.push_back(SymAddr);
|
||||||
Splits.insert(SymAddr);
|
Splits.push_back(SymAddr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,21 +198,27 @@ void MCObjectDisassembler::buildCFG(MCModule *Module) {
|
|||||||
AI != AE; ++AI) {
|
AI != AE; ++AI) {
|
||||||
MCTextAtom *TA = dyn_cast<MCTextAtom>(*AI);
|
MCTextAtom *TA = dyn_cast<MCTextAtom>(*AI);
|
||||||
if (!TA) continue;
|
if (!TA) continue;
|
||||||
Calls.insert(TA->getBeginAddr());
|
Calls.push_back(TA->getBeginAddr());
|
||||||
BBInfos[TA->getBeginAddr()].Atom = TA;
|
BBInfos[TA->getBeginAddr()].Atom = TA;
|
||||||
for (MCTextAtom::const_iterator II = TA->begin(), IE = TA->end();
|
for (MCTextAtom::const_iterator II = TA->begin(), IE = TA->end();
|
||||||
II != IE; ++II) {
|
II != IE; ++II) {
|
||||||
if (MIA.isTerminator(II->Inst))
|
if (MIA.isTerminator(II->Inst))
|
||||||
Splits.insert(II->Address + II->Size);
|
Splits.push_back(II->Address + II->Size);
|
||||||
uint64_t Target;
|
uint64_t Target;
|
||||||
if (MIA.evaluateBranch(II->Inst, II->Address, II->Size, Target)) {
|
if (MIA.evaluateBranch(II->Inst, II->Address, II->Size, Target)) {
|
||||||
if (MIA.isCall(II->Inst))
|
if (MIA.isCall(II->Inst))
|
||||||
Calls.insert(Target);
|
Calls.push_back(Target);
|
||||||
Splits.insert(Target);
|
Splits.push_back(Target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::sort(Splits.begin(), Splits.end());
|
||||||
|
Splits.erase(std::unique(Splits.begin(), Splits.end()), Splits.end());
|
||||||
|
|
||||||
|
std::sort(Calls.begin(), Calls.end());
|
||||||
|
Calls.erase(std::unique(Calls.begin(), Calls.end()), Calls.end());
|
||||||
|
|
||||||
// Split text atoms into basic block atoms.
|
// Split text atoms into basic block atoms.
|
||||||
for (AddressSetTy::const_iterator SI = Splits.begin(), SE = Splits.end();
|
for (AddressSetTy::const_iterator SI = Splits.begin(), SE = Splits.end();
|
||||||
SI != SE; ++SI) {
|
SI != SE; ++SI) {
|
||||||
|
Reference in New Issue
Block a user