mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-14 14:24:05 +00:00
Finally change the instruction looking map to be a densemap from
record* -> instrinfo instead of std::string -> instrinfo. This speeds up tblgen on cellcpu from 7.28 -> 5.98s with a debug build (20%). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98916 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -15,14 +15,14 @@
|
|||||||
#ifndef CODEGEN_DAGPATTERNS_H
|
#ifndef CODEGEN_DAGPATTERNS_H
|
||||||
#define CODEGEN_DAGPATTERNS_H
|
#define CODEGEN_DAGPATTERNS_H
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "CodeGenTarget.h"
|
#include "CodeGenTarget.h"
|
||||||
#include "CodeGenIntrinsics.h"
|
#include "CodeGenIntrinsics.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
|
#include <set>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class Record;
|
class Record;
|
||||||
|
@ -135,11 +135,6 @@ Record *CodeGenTarget::getInstructionSet() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CodeGenInstruction &CodeGenTarget::getInstruction(const Record *InstRec) const {
|
|
||||||
return getInstruction(InstRec->getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// getAsmParser - Return the AssemblyParser definition for this target.
|
/// getAsmParser - Return the AssemblyParser definition for this target.
|
||||||
///
|
///
|
||||||
Record *CodeGenTarget::getAsmParser() const {
|
Record *CodeGenTarget::getAsmParser() const {
|
||||||
@ -279,25 +274,37 @@ void CodeGenTarget::ReadInstructions() const {
|
|||||||
|
|
||||||
for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
|
||||||
std::string AsmStr = Insts[i]->getValueAsString(InstFormatName);
|
std::string AsmStr = Insts[i]->getValueAsString(InstFormatName);
|
||||||
Instructions.insert(std::make_pair(Insts[i]->getName(),
|
Instructions[Insts[i]] = new CodeGenInstruction(Insts[i], AsmStr);
|
||||||
CodeGenInstruction(Insts[i], AsmStr)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const CodeGenInstruction *
|
static const CodeGenInstruction *
|
||||||
GetInstByName(const char *Name,
|
GetInstByName(const char *Name,
|
||||||
const std::map<std::string, CodeGenInstruction> &Insts) {
|
const DenseMap<const Record*, CodeGenInstruction*> &Insts) {
|
||||||
std::map<std::string, CodeGenInstruction>::const_iterator
|
const Record *Rec = Records.getDef(Name);
|
||||||
I = Insts.find(Name);
|
|
||||||
if (I == Insts.end())
|
DenseMap<const Record*, CodeGenInstruction*>::const_iterator
|
||||||
|
I = Insts.find(Rec);
|
||||||
|
if (Rec == 0 || I == Insts.end())
|
||||||
throw std::string("Could not find '") + Name + "' instruction!";
|
throw std::string("Could not find '") + Name + "' instruction!";
|
||||||
return &I->second;
|
return I->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
/// SortInstByName - Sorting predicate to sort instructions by name.
|
||||||
|
///
|
||||||
|
struct SortInstByName {
|
||||||
|
bool operator()(const CodeGenInstruction *Rec1,
|
||||||
|
const CodeGenInstruction *Rec2) const {
|
||||||
|
return Rec1->TheDef->getName() < Rec2->TheDef->getName();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getInstructionsByEnumValue - Return all of the instructions defined by the
|
/// getInstructionsByEnumValue - Return all of the instructions defined by the
|
||||||
/// target, ordered by their enum value.
|
/// target, ordered by their enum value.
|
||||||
void CodeGenTarget::ComputeInstrsByEnum() const {
|
void CodeGenTarget::ComputeInstrsByEnum() const {
|
||||||
const std::map<std::string, CodeGenInstruction> &Insts = getInstructions();
|
const DenseMap<const Record*, CodeGenInstruction*> &Insts = getInstructions();
|
||||||
const CodeGenInstruction *PHI = GetInstByName("PHI", Insts);
|
const CodeGenInstruction *PHI = GetInstByName("PHI", Insts);
|
||||||
const CodeGenInstruction *INLINEASM = GetInstByName("INLINEASM", Insts);
|
const CodeGenInstruction *INLINEASM = GetInstByName("INLINEASM", Insts);
|
||||||
const CodeGenInstruction *DBG_LABEL = GetInstByName("DBG_LABEL", Insts);
|
const CodeGenInstruction *DBG_LABEL = GetInstByName("DBG_LABEL", Insts);
|
||||||
@ -329,10 +336,11 @@ void CodeGenTarget::ComputeInstrsByEnum() const {
|
|||||||
InstrsByEnum.push_back(COPY_TO_REGCLASS);
|
InstrsByEnum.push_back(COPY_TO_REGCLASS);
|
||||||
InstrsByEnum.push_back(DBG_VALUE);
|
InstrsByEnum.push_back(DBG_VALUE);
|
||||||
|
|
||||||
for (std::map<std::string, CodeGenInstruction>::const_iterator
|
unsigned EndOfPredefines = InstrsByEnum.size();
|
||||||
I = Insts.begin(), E = Insts.end(); I != E; ++I) {
|
|
||||||
const CodeGenInstruction *CGI = &I->second;
|
|
||||||
|
|
||||||
|
for (DenseMap<const Record*, CodeGenInstruction*>::const_iterator
|
||||||
|
I = Insts.begin(), E = Insts.end(); I != E; ++I) {
|
||||||
|
const CodeGenInstruction *CGI = I->second;
|
||||||
if (CGI != PHI &&
|
if (CGI != PHI &&
|
||||||
CGI != INLINEASM &&
|
CGI != INLINEASM &&
|
||||||
CGI != DBG_LABEL &&
|
CGI != DBG_LABEL &&
|
||||||
@ -347,6 +355,11 @@ void CodeGenTarget::ComputeInstrsByEnum() const {
|
|||||||
CGI != DBG_VALUE)
|
CGI != DBG_VALUE)
|
||||||
InstrsByEnum.push_back(CGI);
|
InstrsByEnum.push_back(CGI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All of the instructions are now in random order based on the map iteration.
|
||||||
|
// Sort them by name.
|
||||||
|
std::sort(InstrsByEnum.begin()+EndOfPredefines, InstrsByEnum.end(),
|
||||||
|
SortInstByName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
#ifndef CODEGEN_TARGET_H
|
#ifndef CODEGEN_TARGET_H
|
||||||
#define CODEGEN_TARGET_H
|
#define CODEGEN_TARGET_H
|
||||||
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include "CodeGenRegisters.h"
|
#include "CodeGenRegisters.h"
|
||||||
#include "CodeGenInstruction.h"
|
#include "CodeGenInstruction.h"
|
||||||
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ std::string getQualifiedName(const Record *R);
|
|||||||
class CodeGenTarget {
|
class CodeGenTarget {
|
||||||
Record *TargetRec;
|
Record *TargetRec;
|
||||||
|
|
||||||
mutable std::map<std::string, CodeGenInstruction> Instructions;
|
mutable DenseMap<const Record*, CodeGenInstruction*> Instructions;
|
||||||
mutable std::vector<CodeGenRegister> Registers;
|
mutable std::vector<CodeGenRegister> Registers;
|
||||||
mutable std::vector<CodeGenRegisterClass> RegisterClasses;
|
mutable std::vector<CodeGenRegisterClass> RegisterClasses;
|
||||||
mutable std::vector<MVT::SimpleValueType> LegalValueTypes;
|
mutable std::vector<MVT::SimpleValueType> LegalValueTypes;
|
||||||
@ -185,25 +185,20 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getInstructions - Return all of the instructions defined for this target.
|
|
||||||
///
|
|
||||||
private:
|
private:
|
||||||
const std::map<std::string, CodeGenInstruction> &getInstructions() const {
|
DenseMap<const Record*, CodeGenInstruction*> &getInstructions() const {
|
||||||
if (Instructions.empty()) ReadInstructions();
|
if (Instructions.empty()) ReadInstructions();
|
||||||
return Instructions;
|
return Instructions;
|
||||||
}
|
}
|
||||||
std::map<std::string, CodeGenInstruction> &getInstructions() {
|
|
||||||
if (Instructions.empty()) ReadInstructions();
|
|
||||||
return Instructions;
|
|
||||||
}
|
|
||||||
CodeGenInstruction &getInstruction(const std::string &Name) const {
|
|
||||||
const std::map<std::string, CodeGenInstruction> &Insts = getInstructions();
|
|
||||||
assert(Insts.count(Name) && "Not an instruction!");
|
|
||||||
return const_cast<CodeGenInstruction&>(Insts.find(Name)->second);
|
|
||||||
}
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CodeGenInstruction &getInstruction(const Record *InstRec) const;
|
CodeGenInstruction &getInstruction(const Record *InstRec) const {
|
||||||
|
if (Instructions.empty()) ReadInstructions();
|
||||||
|
DenseMap<const Record*, CodeGenInstruction*>::iterator I =
|
||||||
|
Instructions.find(InstRec);
|
||||||
|
assert(I != Instructions.end() && "Not an instruction");
|
||||||
|
return *I->second;
|
||||||
|
}
|
||||||
|
|
||||||
/// getInstructionsByEnumValue - Return all of the instructions defined by the
|
/// getInstructionsByEnumValue - Return all of the instructions defined by the
|
||||||
/// target, ordered by their enum value.
|
/// target, ordered by their enum value.
|
||||||
|
@ -39,16 +39,10 @@ static void PrintBarriers(std::vector<Record*> &Barriers,
|
|||||||
// Instruction Itinerary Information.
|
// Instruction Itinerary Information.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
struct RecordNameComparator {
|
|
||||||
bool operator()(const Record *Rec1, const Record *Rec2) const {
|
|
||||||
return Rec1->getName() < Rec2->getName();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void InstrInfoEmitter::GatherItinClasses() {
|
void InstrInfoEmitter::GatherItinClasses() {
|
||||||
std::vector<Record*> DefList =
|
std::vector<Record*> DefList =
|
||||||
Records.getAllDerivedDefinitions("InstrItinClass");
|
Records.getAllDerivedDefinitions("InstrItinClass");
|
||||||
std::sort(DefList.begin(), DefList.end(), RecordNameComparator());
|
std::sort(DefList.begin(), DefList.end(), LessRecord());
|
||||||
|
|
||||||
for (unsigned i = 0, N = DefList.size(); i < N; i++)
|
for (unsigned i = 0, N = DefList.size(); i < N; i++)
|
||||||
ItinClassMap[DefList[i]->getName()] = i;
|
ItinClassMap[DefList[i]->getName()] = i;
|
||||||
|
Reference in New Issue
Block a user