summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp')
-rw-r--r--llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp141
1 files changed, 68 insertions, 73 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 790e253709c..5f22e2a998f 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -38,18 +38,18 @@ struct YamlContext {
generateOpcodeNameToOpcodeIdxMapping(State.getInstrInfo())),
RegNameToRegNo(generateRegNameToRegNoMapping(State.getRegInfo())) {}
- static llvm::StringMap<unsigned>
- generateOpcodeNameToOpcodeIdxMapping(const llvm::MCInstrInfo &InstrInfo) {
- llvm::StringMap<unsigned> Map(InstrInfo.getNumOpcodes());
+ static StringMap<unsigned>
+ generateOpcodeNameToOpcodeIdxMapping(const MCInstrInfo &InstrInfo) {
+ StringMap<unsigned> Map(InstrInfo.getNumOpcodes());
for (unsigned I = 0, E = InstrInfo.getNumOpcodes(); I < E; ++I)
Map[InstrInfo.getName(I)] = I;
assert(Map.size() == InstrInfo.getNumOpcodes() && "Size prediction failed");
return Map;
};
- llvm::StringMap<unsigned>
- generateRegNameToRegNoMapping(const llvm::MCRegisterInfo &RegInfo) {
- llvm::StringMap<unsigned> Map(RegInfo.getNumRegs());
+ StringMap<unsigned>
+ generateRegNameToRegNoMapping(const MCRegisterInfo &RegInfo) {
+ StringMap<unsigned> Map(RegInfo.getNumRegs());
// Special-case RegNo 0, which would otherwise be spelled as ''.
Map[kNoRegister] = 0;
for (unsigned I = 1, E = RegInfo.getNumRegs(); I < E; ++I)
@@ -58,7 +58,7 @@ struct YamlContext {
return Map;
};
- void serializeMCInst(const llvm::MCInst &MCInst, llvm::raw_ostream &OS) {
+ void serializeMCInst(const MCInst &MCInst, raw_ostream &OS) {
OS << getInstrName(MCInst.getOpcode());
for (const auto &Op : MCInst) {
OS << ' ';
@@ -66,15 +66,15 @@ struct YamlContext {
}
}
- void deserializeMCInst(llvm::StringRef String, llvm::MCInst &Value) {
- llvm::SmallVector<llvm::StringRef, 16> Pieces;
+ void deserializeMCInst(StringRef String, MCInst &Value) {
+ SmallVector<StringRef, 16> Pieces;
String.split(Pieces, " ", /* MaxSplit */ -1, /* KeepEmpty */ false);
if (Pieces.empty()) {
ErrorStream << "Unknown Instruction: '" << String << "'\n";
return;
}
bool ProcessOpcode = true;
- for (llvm::StringRef Piece : Pieces) {
+ for (StringRef Piece : Pieces) {
if (ProcessOpcode)
Value.setOpcode(getInstrOpcode(Piece));
else
@@ -85,43 +85,43 @@ struct YamlContext {
std::string &getLastError() { return ErrorStream.str(); }
- llvm::raw_string_ostream &getErrorStream() { return ErrorStream; }
+ raw_string_ostream &getErrorStream() { return ErrorStream; }
- llvm::StringRef getRegName(unsigned RegNo) {
+ StringRef getRegName(unsigned RegNo) {
// Special case: RegNo 0 is NoRegister. We have to deal with it explicitly.
if (RegNo == 0)
return kNoRegister;
- const llvm::StringRef RegName = State->getRegInfo().getName(RegNo);
+ const StringRef RegName = State->getRegInfo().getName(RegNo);
if (RegName.empty())
ErrorStream << "No register with enum value '" << RegNo << "'\n";
return RegName;
}
- llvm::Optional<unsigned> getRegNo(llvm::StringRef RegName) {
+ Optional<unsigned> getRegNo(StringRef RegName) {
auto Iter = RegNameToRegNo.find(RegName);
if (Iter != RegNameToRegNo.end())
return Iter->second;
ErrorStream << "No register with name '" << RegName << "'\n";
- return llvm::None;
+ return None;
}
private:
- void serializeIntegerOperand(llvm::raw_ostream &OS, int64_t Value) {
+ void serializeIntegerOperand(raw_ostream &OS, int64_t Value) {
OS << kIntegerPrefix;
- OS.write_hex(llvm::bit_cast<uint64_t>(Value));
+ OS.write_hex(bit_cast<uint64_t>(Value));
}
- bool tryDeserializeIntegerOperand(llvm::StringRef String, int64_t &Value) {
+ bool tryDeserializeIntegerOperand(StringRef String, int64_t &Value) {
if (!String.consume_front(kIntegerPrefix))
return false;
return !String.consumeInteger(16, Value);
}
- void serializeFPOperand(llvm::raw_ostream &OS, double Value) {
- OS << kDoublePrefix << llvm::format("%la", Value);
+ void serializeFPOperand(raw_ostream &OS, double Value) {
+ OS << kDoublePrefix << format("%la", Value);
}
- bool tryDeserializeFPOperand(llvm::StringRef String, double &Value) {
+ bool tryDeserializeFPOperand(StringRef String, double &Value) {
if (!String.consume_front(kDoublePrefix))
return false;
char *EndPointer = nullptr;
@@ -129,8 +129,7 @@ private:
return EndPointer == String.end();
}
- void serializeMCOperand(const llvm::MCOperand &MCOperand,
- llvm::raw_ostream &OS) {
+ void serializeMCOperand(const MCOperand &MCOperand, raw_ostream &OS) {
if (MCOperand.isReg()) {
OS << getRegName(MCOperand.getReg());
} else if (MCOperand.isImm()) {
@@ -142,29 +141,29 @@ private:
}
}
- llvm::MCOperand deserializeMCOperand(llvm::StringRef String) {
+ MCOperand deserializeMCOperand(StringRef String) {
assert(!String.empty());
int64_t IntValue = 0;
double DoubleValue = 0;
if (tryDeserializeIntegerOperand(String, IntValue))
- return llvm::MCOperand::createImm(IntValue);
+ return MCOperand::createImm(IntValue);
if (tryDeserializeFPOperand(String, DoubleValue))
- return llvm::MCOperand::createFPImm(DoubleValue);
+ return MCOperand::createFPImm(DoubleValue);
if (auto RegNo = getRegNo(String))
- return llvm::MCOperand::createReg(*RegNo);
+ return MCOperand::createReg(*RegNo);
if (String != kInvalidOperand)
ErrorStream << "Unknown Operand: '" << String << "'\n";
return {};
}
- llvm::StringRef getInstrName(unsigned InstrNo) {
- const llvm::StringRef InstrName = State->getInstrInfo().getName(InstrNo);
+ StringRef getInstrName(unsigned InstrNo) {
+ const StringRef InstrName = State->getInstrInfo().getName(InstrNo);
if (InstrName.empty())
ErrorStream << "No opcode with enum value '" << InstrNo << "'\n";
return InstrName;
}
- unsigned getInstrOpcode(llvm::StringRef InstrName) {
+ unsigned getInstrOpcode(StringRef InstrName) {
auto Iter = OpcodeNameToOpcodeIdx.find(InstrName);
if (Iter != OpcodeNameToOpcodeIdx.end())
return Iter->second;
@@ -172,11 +171,11 @@ private:
return 0;
}
- const llvm::exegesis::LLVMState *State;
+ const exegesis::LLVMState *State;
std::string LastError;
- llvm::raw_string_ostream ErrorStream;
- const llvm::StringMap<unsigned> OpcodeNameToOpcodeIdx;
- const llvm::StringMap<unsigned> RegNameToRegNo;
+ raw_string_ostream ErrorStream;
+ const StringMap<unsigned> OpcodeNameToOpcodeIdx;
+ const StringMap<unsigned> RegNameToRegNo;
};
} // namespace
@@ -187,19 +186,18 @@ static YamlContext &getTypedContext(void *Ctx) {
return *reinterpret_cast<YamlContext *>(Ctx);
}
-// std::vector<llvm::MCInst> will be rendered as a list.
-template <> struct SequenceElementTraits<llvm::MCInst> {
+// std::vector<MCInst> will be rendered as a list.
+template <> struct SequenceElementTraits<MCInst> {
static const bool flow = false;
};
-template <> struct ScalarTraits<llvm::MCInst> {
+template <> struct ScalarTraits<MCInst> {
- static void output(const llvm::MCInst &Value, void *Ctx,
- llvm::raw_ostream &Out) {
+ static void output(const MCInst &Value, void *Ctx, raw_ostream &Out) {
getTypedContext(Ctx).serializeMCInst(Value, Out);
}
- static StringRef input(StringRef Scalar, void *Ctx, llvm::MCInst &Value) {
+ static StringRef input(StringRef Scalar, void *Ctx, MCInst &Value) {
YamlContext &Context = getTypedContext(Ctx);
Context.deserializeMCInst(Scalar, Value);
return Context.getLastError();
@@ -254,7 +252,7 @@ template <> struct ScalarTraits<exegesis::RegisterValue> {
static constexpr const bool kSigned = false;
static void output(const exegesis::RegisterValue &RV, void *Ctx,
- llvm::raw_ostream &Out) {
+ raw_ostream &Out) {
YamlContext &Context = getTypedContext(Ctx);
Out << Context.getRegName(RV.Register) << "=0x"
<< RV.Value.toString(kRadix, kSigned);
@@ -262,15 +260,15 @@ template <> struct ScalarTraits<exegesis::RegisterValue> {
static StringRef input(StringRef String, void *Ctx,
exegesis::RegisterValue &RV) {
- llvm::SmallVector<llvm::StringRef, 2> Pieces;
+ SmallVector<StringRef, 2> Pieces;
String.split(Pieces, "=0x", /* MaxSplit */ -1,
/* KeepEmpty */ false);
YamlContext &Context = getTypedContext(Ctx);
- llvm::Optional<unsigned> RegNo;
+ Optional<unsigned> RegNo;
if (Pieces.size() == 2 && (RegNo = Context.getRegNo(Pieces[0]))) {
RV.Register = *RegNo;
- const unsigned BitsNeeded = llvm::APInt::getBitsNeeded(Pieces[1], kRadix);
- RV.Value = llvm::APInt(BitsNeeded, Pieces[1], kRadix);
+ const unsigned BitsNeeded = APInt::getBitsNeeded(Pieces[1], kRadix);
+ RV.Value = APInt(BitsNeeded, Pieces[1], kRadix);
} else {
Context.getErrorStream()
<< "Unknown initial register value: '" << String << "'";
@@ -333,16 +331,15 @@ struct MappingContextTraits<exegesis::InstructionBenchmark, YamlContext> {
namespace exegesis {
-llvm::Expected<InstructionBenchmark>
-InstructionBenchmark::readYaml(const LLVMState &State,
- llvm::StringRef Filename) {
+Expected<InstructionBenchmark>
+InstructionBenchmark::readYaml(const LLVMState &State, StringRef Filename) {
if (auto ExpectedMemoryBuffer =
- llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename))) {
- llvm::yaml::Input Yin(*ExpectedMemoryBuffer.get());
+ errorOrToExpected(MemoryBuffer::getFile(Filename))) {
+ yaml::Input Yin(*ExpectedMemoryBuffer.get());
YamlContext Context(State);
InstructionBenchmark Benchmark;
if (Yin.setCurrentDocument())
- llvm::yaml::yamlize(Yin, Benchmark, /*unused*/ true, Context);
+ yaml::yamlize(Yin, Benchmark, /*unused*/ true, Context);
if (!Context.getLastError().empty())
return make_error<Failure>(Context.getLastError());
return Benchmark;
@@ -351,19 +348,18 @@ InstructionBenchmark::readYaml(const LLVMState &State,
}
}
-llvm::Expected<std::vector<InstructionBenchmark>>
-InstructionBenchmark::readYamls(const LLVMState &State,
- llvm::StringRef Filename) {
+Expected<std::vector<InstructionBenchmark>>
+InstructionBenchmark::readYamls(const LLVMState &State, StringRef Filename) {
if (auto ExpectedMemoryBuffer =
- llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename))) {
- llvm::yaml::Input Yin(*ExpectedMemoryBuffer.get());
+ errorOrToExpected(MemoryBuffer::getFile(Filename))) {
+ yaml::Input Yin(*ExpectedMemoryBuffer.get());
YamlContext Context(State);
std::vector<InstructionBenchmark> Benchmarks;
while (Yin.setCurrentDocument()) {
Benchmarks.emplace_back();
yamlize(Yin, Benchmarks.back(), /*unused*/ true, Context);
if (Yin.error())
- return llvm::errorCodeToError(Yin.error());
+ return errorCodeToError(Yin.error());
if (!Context.getLastError().empty())
return make_error<Failure>(Context.getLastError());
Yin.nextDocument();
@@ -374,47 +370,46 @@ InstructionBenchmark::readYamls(const LLVMState &State,
}
}
-llvm::Error InstructionBenchmark::writeYamlTo(const LLVMState &State,
- llvm::raw_ostream &OS) {
+Error InstructionBenchmark::writeYamlTo(const LLVMState &State,
+ raw_ostream &OS) {
auto Cleanup = make_scope_exit([&] { OS.flush(); });
- llvm::yaml::Output Yout(OS, nullptr /*Ctx*/, 200 /*WrapColumn*/);
+ yaml::Output Yout(OS, nullptr /*Ctx*/, 200 /*WrapColumn*/);
YamlContext Context(State);
Yout.beginDocuments();
- llvm::yaml::yamlize(Yout, *this, /*unused*/ true, Context);
+ yaml::yamlize(Yout, *this, /*unused*/ true, Context);
if (!Context.getLastError().empty())
return make_error<Failure>(Context.getLastError());
Yout.endDocuments();
return Error::success();
}
-llvm::Error InstructionBenchmark::readYamlFrom(const LLVMState &State,
- llvm::StringRef InputContent) {
- llvm::yaml::Input Yin(InputContent);
+Error InstructionBenchmark::readYamlFrom(const LLVMState &State,
+ StringRef InputContent) {
+ yaml::Input Yin(InputContent);
YamlContext Context(State);
if (Yin.setCurrentDocument())
- llvm::yaml::yamlize(Yin, *this, /*unused*/ true, Context);
+ yaml::yamlize(Yin, *this, /*unused*/ true, Context);
if (!Context.getLastError().empty())
return make_error<Failure>(Context.getLastError());
return Error::success();
}
-llvm::Error InstructionBenchmark::writeYaml(const LLVMState &State,
- const llvm::StringRef Filename) {
+Error InstructionBenchmark::writeYaml(const LLVMState &State,
+ const StringRef Filename) {
if (Filename == "-") {
- if (auto Err = writeYamlTo(State, llvm::outs()))
+ if (auto Err = writeYamlTo(State, outs()))
return Err;
} else {
int ResultFD = 0;
- if (auto E = llvm::errorCodeToError(
- openFileForWrite(Filename, ResultFD, llvm::sys::fs::CD_CreateAlways,
- llvm::sys::fs::OF_Text))) {
+ if (auto E = errorCodeToError(openFileForWrite(
+ Filename, ResultFD, sys::fs::CD_CreateAlways, sys::fs::OF_Text))) {
return E;
}
- llvm::raw_fd_ostream Ostr(ResultFD, true /*shouldClose*/);
+ raw_fd_ostream Ostr(ResultFD, true /*shouldClose*/);
if (auto Err = writeYamlTo(State, Ostr))
return Err;
}
- return llvm::Error::success();
+ return Error::success();
}
void PerInstructionStats::push(const BenchmarkMeasure &BM) {
OpenPOWER on IntegriCloud