Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 1 | //===-- BenchmarkResult.cpp -------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "BenchmarkResult.h" |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 11 | #include "BenchmarkRunner.h" |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/STLExtras.h" |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/StringRef.h" |
Clement Courbet | 4273e1e | 2018-06-15 07:30:45 +0000 | [diff] [blame] | 14 | #include "llvm/ObjectYAML/YAML.h" |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 15 | #include "llvm/Support/FileOutputBuffer.h" |
| 16 | #include "llvm/Support/FileSystem.h" |
| 17 | #include "llvm/Support/Format.h" |
| 18 | #include "llvm/Support/raw_ostream.h" |
| 19 | |
Guillaume Chatelet | 083a0c16 | 2018-06-07 07:40:40 +0000 | [diff] [blame] | 20 | static constexpr const char kIntegerFormat[] = "i_0x%" PRId64 "x"; |
| 21 | static constexpr const char kDoubleFormat[] = "f_%la"; |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 22 | static constexpr const char kInvalidOperand[] = "INVALID"; |
Guillaume Chatelet | 083a0c16 | 2018-06-07 07:40:40 +0000 | [diff] [blame] | 23 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 24 | // A mutable struct holding an LLVMState that can be passed through the |
| 25 | // serialization process to encode/decode registers and instructions. |
| 26 | struct YamlContext { |
| 27 | YamlContext(const exegesis::LLVMState &State) |
| 28 | : State(&State), ErrorStream(LastError) {} |
Guillaume Chatelet | 083a0c16 | 2018-06-07 07:40:40 +0000 | [diff] [blame] | 29 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 30 | void serializeMCInst(const llvm::MCInst &MCInst, llvm::raw_ostream &OS) { |
| 31 | OS << getInstrName(MCInst.getOpcode()); |
| 32 | for (const auto &Op : MCInst) { |
| 33 | OS << ' '; |
| 34 | serializeMCOperand(Op, OS); |
Guillaume Chatelet | 083a0c16 | 2018-06-07 07:40:40 +0000 | [diff] [blame] | 35 | } |
| 36 | } |
Guillaume Chatelet | 083a0c16 | 2018-06-07 07:40:40 +0000 | [diff] [blame] | 37 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 38 | void deserializeMCInst(llvm::StringRef String, llvm::MCInst &Value) { |
| 39 | llvm::SmallVector<llvm::StringRef, 8> Pieces; |
| 40 | String.split(Pieces, " ", /* MaxSplit */ -1, /* KeepEmpty */ false); |
| 41 | if (Pieces.empty()) { |
| 42 | ErrorStream << "Unknown Instruction: '" << String << "'"; |
| 43 | return; |
| 44 | } |
| 45 | bool ProcessOpcode = true; |
| 46 | for (llvm::StringRef Piece : Pieces) { |
| 47 | if (ProcessOpcode) |
| 48 | Value.setOpcode(getInstrOpcode(Piece)); |
| 49 | else |
| 50 | Value.addOperand(deserializeMCOperand(Piece)); |
| 51 | ProcessOpcode = false; |
| 52 | } |
| 53 | } |
Guillaume Chatelet | 083a0c16 | 2018-06-07 07:40:40 +0000 | [diff] [blame] | 54 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 55 | std::string &getLastError() { return ErrorStream.str(); } |
| 56 | |
Guillaume Chatelet | 345fae5 | 2018-09-25 15:15:54 +0000 | [diff] [blame^] | 57 | llvm::raw_string_ostream &getErrorStream() { return ErrorStream; } |
| 58 | |
| 59 | llvm::StringRef getRegName(unsigned RegNo) { |
| 60 | const llvm::StringRef RegName = State->getRegInfo().getName(RegNo); |
| 61 | if (RegName.empty()) |
| 62 | ErrorStream << "No register with enum value" << RegNo; |
| 63 | return RegName; |
| 64 | } |
| 65 | |
| 66 | unsigned getRegNo(llvm::StringRef RegName) { |
| 67 | const llvm::MCRegisterInfo &RegInfo = State->getRegInfo(); |
| 68 | for (unsigned E = RegInfo.getNumRegs(), I = 0; I < E; ++I) |
| 69 | if (RegInfo.getName(I) == RegName) |
| 70 | return I; |
| 71 | ErrorStream << "No register with name " << RegName; |
| 72 | return 0; |
| 73 | } |
| 74 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 75 | private: |
| 76 | void serializeMCOperand(const llvm::MCOperand &MCOperand, |
| 77 | llvm::raw_ostream &OS) { |
| 78 | if (MCOperand.isReg()) { |
| 79 | OS << getRegName(MCOperand.getReg()); |
| 80 | } else if (MCOperand.isImm()) { |
| 81 | OS << llvm::format(kIntegerFormat, MCOperand.getImm()); |
| 82 | } else if (MCOperand.isFPImm()) { |
| 83 | OS << llvm::format(kDoubleFormat, MCOperand.getFPImm()); |
| 84 | } else { |
| 85 | OS << kInvalidOperand; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | llvm::MCOperand deserializeMCOperand(llvm::StringRef String) { |
| 90 | assert(!String.empty()); |
| 91 | int64_t IntValue = 0; |
| 92 | double DoubleValue = 0; |
| 93 | if (sscanf(String.data(), kIntegerFormat, &IntValue) == 1) |
| 94 | return llvm::MCOperand::createImm(IntValue); |
| 95 | if (sscanf(String.data(), kDoubleFormat, &DoubleValue) == 1) |
| 96 | return llvm::MCOperand::createFPImm(DoubleValue); |
| 97 | if (unsigned RegNo = getRegNo(String)) |
| 98 | return llvm::MCOperand::createReg(RegNo); |
| 99 | if (String != kInvalidOperand) |
| 100 | ErrorStream << "Unknown Operand: '" << String << "'"; |
| 101 | return {}; |
| 102 | } |
| 103 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 104 | llvm::StringRef getInstrName(unsigned InstrNo) { |
| 105 | const llvm::StringRef InstrName = State->getInstrInfo().getName(InstrNo); |
| 106 | if (InstrName.empty()) |
| 107 | ErrorStream << "No opcode with enum value" << InstrNo; |
| 108 | return InstrName; |
| 109 | } |
| 110 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 111 | unsigned getInstrOpcode(llvm::StringRef InstrName) { |
| 112 | const llvm::MCInstrInfo &InstrInfo = State->getInstrInfo(); |
| 113 | for (unsigned E = InstrInfo.getNumOpcodes(), I = 0; I < E; ++I) |
| 114 | if (InstrInfo.getName(I) == InstrName) |
| 115 | return I; |
| 116 | ErrorStream << "No opcode with name " << InstrName; |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | const exegesis::LLVMState *State; |
| 121 | std::string LastError; |
| 122 | llvm::raw_string_ostream ErrorStream; |
| 123 | }; |
Guillaume Chatelet | 083a0c16 | 2018-06-07 07:40:40 +0000 | [diff] [blame] | 124 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 125 | // Defining YAML traits for IO. |
| 126 | namespace llvm { |
| 127 | namespace yaml { |
| 128 | |
Guillaume Chatelet | 345fae5 | 2018-09-25 15:15:54 +0000 | [diff] [blame^] | 129 | static YamlContext &getTypedContext(void *Ctx) { |
| 130 | return *reinterpret_cast<YamlContext *>(Ctx); |
| 131 | } |
| 132 | |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 133 | // std::vector<llvm::MCInst> will be rendered as a list. |
| 134 | template <> struct SequenceElementTraits<llvm::MCInst> { |
| 135 | static const bool flow = false; |
| 136 | }; |
| 137 | |
| 138 | template <> struct ScalarTraits<llvm::MCInst> { |
| 139 | |
| 140 | static void output(const llvm::MCInst &Value, void *Ctx, |
| 141 | llvm::raw_ostream &Out) { |
Guillaume Chatelet | 345fae5 | 2018-09-25 15:15:54 +0000 | [diff] [blame^] | 142 | getTypedContext(Ctx).serializeMCInst(Value, Out); |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static StringRef input(StringRef Scalar, void *Ctx, llvm::MCInst &Value) { |
Guillaume Chatelet | 345fae5 | 2018-09-25 15:15:54 +0000 | [diff] [blame^] | 146 | YamlContext &Context = getTypedContext(Ctx); |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 147 | Context.deserializeMCInst(Scalar, Value); |
| 148 | return Context.getLastError(); |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Guillaume Chatelet | 345fae5 | 2018-09-25 15:15:54 +0000 | [diff] [blame^] | 151 | // By default strings are quoted only when necessary. |
| 152 | // We force the use of single quotes for uniformity. |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 153 | static QuotingType mustQuote(StringRef) { return QuotingType::Single; } |
| 154 | |
| 155 | static const bool flow = true; |
| 156 | }; |
| 157 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 158 | // std::vector<exegesis::Measure> will be rendered as a list. |
| 159 | template <> struct SequenceElementTraits<exegesis::BenchmarkMeasure> { |
| 160 | static const bool flow = false; |
| 161 | }; |
| 162 | |
| 163 | // exegesis::Measure is rendererd as a flow instead of a list. |
| 164 | // e.g. { "key": "the key", "value": 0123 } |
| 165 | template <> struct MappingTraits<exegesis::BenchmarkMeasure> { |
| 166 | static void mapping(IO &Io, exegesis::BenchmarkMeasure &Obj) { |
| 167 | Io.mapRequired("key", Obj.Key); |
| 168 | Io.mapRequired("value", Obj.Value); |
| 169 | Io.mapOptional("debug_string", Obj.DebugString); |
| 170 | } |
| 171 | static const bool flow = true; |
| 172 | }; |
| 173 | |
Clement Courbet | 2cb97b9 | 2018-06-04 11:43:40 +0000 | [diff] [blame] | 174 | template <> |
Clement Courbet | 62b34fa | 2018-06-06 09:42:36 +0000 | [diff] [blame] | 175 | struct ScalarEnumerationTraits<exegesis::InstructionBenchmark::ModeE> { |
Clement Courbet | 2cb97b9 | 2018-06-04 11:43:40 +0000 | [diff] [blame] | 176 | static void enumeration(IO &Io, |
Clement Courbet | 62b34fa | 2018-06-06 09:42:36 +0000 | [diff] [blame] | 177 | exegesis::InstructionBenchmark::ModeE &Value) { |
| 178 | Io.enumCase(Value, "", exegesis::InstructionBenchmark::Unknown); |
| 179 | Io.enumCase(Value, "latency", exegesis::InstructionBenchmark::Latency); |
| 180 | Io.enumCase(Value, "uops", exegesis::InstructionBenchmark::Uops); |
Clement Courbet | 2cb97b9 | 2018-06-04 11:43:40 +0000 | [diff] [blame] | 181 | } |
| 182 | }; |
| 183 | |
Guillaume Chatelet | 345fae5 | 2018-09-25 15:15:54 +0000 | [diff] [blame^] | 184 | // std::vector<exegesis::RegisterValue> will be rendered as a list. |
| 185 | template <> struct SequenceElementTraits<exegesis::RegisterValue> { |
| 186 | static const bool flow = false; |
| 187 | }; |
| 188 | |
| 189 | template <> struct ScalarTraits<exegesis::RegisterValue> { |
| 190 | static constexpr const unsigned kRadix = 16; |
| 191 | static constexpr const bool kSigned = false; |
| 192 | |
| 193 | static void output(const exegesis::RegisterValue &RV, void *Ctx, |
| 194 | llvm::raw_ostream &Out) { |
| 195 | YamlContext &Context = getTypedContext(Ctx); |
| 196 | Out << Context.getRegName(RV.Register) << "=0x" |
| 197 | << RV.Value.toString(kRadix, kSigned); |
| 198 | } |
| 199 | |
| 200 | static StringRef input(StringRef String, void *Ctx, |
| 201 | exegesis::RegisterValue &RV) { |
| 202 | llvm::SmallVector<llvm::StringRef, 2> Pieces; |
| 203 | String.split(Pieces, "=0x", /* MaxSplit */ -1, |
| 204 | /* KeepEmpty */ false); |
| 205 | YamlContext &Context = getTypedContext(Ctx); |
| 206 | if (Pieces.size() == 2) { |
| 207 | RV.Register = Context.getRegNo(Pieces[0]); |
| 208 | const unsigned BitsNeeded = llvm::APInt::getBitsNeeded(Pieces[1], kRadix); |
| 209 | RV.Value = llvm::APInt(BitsNeeded, Pieces[1], kRadix); |
| 210 | } else { |
| 211 | Context.getErrorStream() |
| 212 | << "Unknown initial register value: '" << String << "'"; |
| 213 | } |
| 214 | return Context.getLastError(); |
| 215 | } |
| 216 | |
| 217 | static QuotingType mustQuote(StringRef) { return QuotingType::Single; } |
| 218 | |
| 219 | static const bool flow = true; |
| 220 | }; |
| 221 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 222 | template <> |
| 223 | struct MappingContextTraits<exegesis::InstructionBenchmarkKey, YamlContext> { |
| 224 | static void mapping(IO &Io, exegesis::InstructionBenchmarkKey &Obj, |
| 225 | YamlContext &Context) { |
| 226 | Io.setContext(&Context); |
Clement Courbet | 49fad1c | 2018-06-14 06:57:52 +0000 | [diff] [blame] | 227 | Io.mapRequired("instructions", Obj.Instructions); |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 228 | Io.mapOptional("config", Obj.Config); |
Guillaume Chatelet | 345fae5 | 2018-09-25 15:15:54 +0000 | [diff] [blame^] | 229 | Io.mapRequired("register_initial_values", Obj.RegisterInitialValues); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 230 | } |
| 231 | }; |
| 232 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 233 | template <> |
| 234 | struct MappingContextTraits<exegesis::InstructionBenchmark, YamlContext> { |
Guillaume Chatelet | 345fae5 | 2018-09-25 15:15:54 +0000 | [diff] [blame^] | 235 | struct NormalizedBinary { |
Clement Courbet | 4273e1e | 2018-06-15 07:30:45 +0000 | [diff] [blame] | 236 | NormalizedBinary(IO &io) {} |
| 237 | NormalizedBinary(IO &, std::vector<uint8_t> &Data) : Binary(Data) {} |
| 238 | std::vector<uint8_t> denormalize(IO &) { |
| 239 | std::vector<uint8_t> Data; |
| 240 | std::string Str; |
| 241 | raw_string_ostream OSS(Str); |
| 242 | Binary.writeAsBinary(OSS); |
| 243 | OSS.flush(); |
| 244 | Data.assign(Str.begin(), Str.end()); |
| 245 | return Data; |
| 246 | } |
| 247 | |
| 248 | BinaryRef Binary; |
| 249 | }; |
| 250 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 251 | static void mapping(IO &Io, exegesis::InstructionBenchmark &Obj, |
| 252 | YamlContext &Context) { |
Clement Courbet | 62b34fa | 2018-06-06 09:42:36 +0000 | [diff] [blame] | 253 | Io.mapRequired("mode", Obj.Mode); |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 254 | Io.mapRequired("key", Obj.Key, Context); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 255 | Io.mapRequired("cpu_name", Obj.CpuName); |
| 256 | Io.mapRequired("llvm_triple", Obj.LLVMTriple); |
| 257 | Io.mapRequired("num_repetitions", Obj.NumRepetitions); |
| 258 | Io.mapRequired("measurements", Obj.Measurements); |
| 259 | Io.mapRequired("error", Obj.Error); |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 260 | Io.mapOptional("info", Obj.Info); |
Clement Courbet | 4273e1e | 2018-06-15 07:30:45 +0000 | [diff] [blame] | 261 | // AssembledSnippet |
| 262 | MappingNormalization<NormalizedBinary, std::vector<uint8_t>> BinaryString( |
| 263 | Io, Obj.AssembledSnippet); |
| 264 | Io.mapOptional("assembled_snippet", BinaryString->Binary); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 265 | } |
| 266 | }; |
| 267 | |
| 268 | } // namespace yaml |
| 269 | } // namespace llvm |
| 270 | |
| 271 | namespace exegesis { |
| 272 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 273 | llvm::Expected<InstructionBenchmark> |
| 274 | InstructionBenchmark::readYaml(const LLVMState &State, |
| 275 | llvm::StringRef Filename) { |
Guillaume Chatelet | 8c91d4c | 2018-06-07 07:51:16 +0000 | [diff] [blame] | 276 | if (auto ExpectedMemoryBuffer = |
| 277 | llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename))) { |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 278 | llvm::yaml::Input Yin(*ExpectedMemoryBuffer.get()); |
| 279 | YamlContext Context(State); |
| 280 | InstructionBenchmark Benchmark; |
| 281 | if (Yin.setCurrentDocument()) |
| 282 | llvm::yaml::yamlize(Yin, Benchmark, /*unused*/ true, Context); |
| 283 | if (!Context.getLastError().empty()) |
| 284 | return llvm::make_error<BenchmarkFailure>(Context.getLastError()); |
Guillaume Chatelet | 8c91d4c | 2018-06-07 07:51:16 +0000 | [diff] [blame] | 285 | return Benchmark; |
| 286 | } else { |
| 287 | return ExpectedMemoryBuffer.takeError(); |
| 288 | } |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Guillaume Chatelet | 8c91d4c | 2018-06-07 07:51:16 +0000 | [diff] [blame] | 291 | llvm::Expected<std::vector<InstructionBenchmark>> |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 292 | InstructionBenchmark::readYamls(const LLVMState &State, |
Guillaume Chatelet | 8c91d4c | 2018-06-07 07:51:16 +0000 | [diff] [blame] | 293 | llvm::StringRef Filename) { |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 294 | if (auto ExpectedMemoryBuffer = |
| 295 | llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename))) { |
| 296 | llvm::yaml::Input Yin(*ExpectedMemoryBuffer.get()); |
| 297 | YamlContext Context(State); |
| 298 | std::vector<InstructionBenchmark> Benchmarks; |
| 299 | while (Yin.setCurrentDocument()) { |
| 300 | Benchmarks.emplace_back(); |
| 301 | yamlize(Yin, Benchmarks.back(), /*unused*/ true, Context); |
| 302 | if (Yin.error()) |
| 303 | return llvm::errorCodeToError(Yin.error()); |
| 304 | if (!Context.getLastError().empty()) |
| 305 | return llvm::make_error<BenchmarkFailure>(Context.getLastError()); |
| 306 | Yin.nextDocument(); |
| 307 | } |
| 308 | return Benchmarks; |
| 309 | } else { |
| 310 | return ExpectedMemoryBuffer.takeError(); |
| 311 | } |
Clement Courbet | 7b7c27a | 2018-05-14 09:01:22 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 314 | void InstructionBenchmark::writeYamlTo(const LLVMState &State, |
Guillaume Chatelet | 083a0c16 | 2018-06-07 07:40:40 +0000 | [diff] [blame] | 315 | llvm::raw_ostream &OS) { |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 316 | llvm::yaml::Output Yout(OS); |
| 317 | YamlContext Context(State); |
Guillaume Chatelet | 6078f82 | 2018-09-25 14:48:24 +0000 | [diff] [blame] | 318 | Yout.beginDocuments(); |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 319 | llvm::yaml::yamlize(Yout, *this, /*unused*/ true, Context); |
Guillaume Chatelet | 6078f82 | 2018-09-25 14:48:24 +0000 | [diff] [blame] | 320 | Yout.endDocuments(); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 323 | void InstructionBenchmark::readYamlFrom(const LLVMState &State, |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 324 | llvm::StringRef InputContent) { |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 325 | llvm::yaml::Input Yin(InputContent); |
| 326 | YamlContext Context(State); |
| 327 | if (Yin.setCurrentDocument()) |
| 328 | llvm::yaml::yamlize(Yin, *this, /*unused*/ true, Context); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 331 | llvm::Error InstructionBenchmark::writeYaml(const LLVMState &State, |
| 332 | const llvm::StringRef Filename) { |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 333 | if (Filename == "-") { |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 334 | writeYamlTo(State, llvm::outs()); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 335 | } else { |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 336 | int ResultFD = 0; |
Guillaume Chatelet | 8c91d4c | 2018-06-07 07:51:16 +0000 | [diff] [blame] | 337 | if (auto E = llvm::errorCodeToError( |
Zachary Turner | 1f67a3c | 2018-06-07 19:58:58 +0000 | [diff] [blame] | 338 | openFileForWrite(Filename, ResultFD, llvm::sys::fs::CD_CreateAlways, |
| 339 | llvm::sys::fs::F_Text))) { |
Guillaume Chatelet | 8c91d4c | 2018-06-07 07:51:16 +0000 | [diff] [blame] | 340 | return E; |
| 341 | } |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 342 | llvm::raw_fd_ostream Ostr(ResultFD, true /*shouldClose*/); |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame] | 343 | writeYamlTo(State, Ostr); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 344 | } |
Guillaume Chatelet | 8c91d4c | 2018-06-07 07:51:16 +0000 | [diff] [blame] | 345 | return llvm::Error::success(); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Clement Courbet | ae8ae5dc | 2018-05-24 12:41:02 +0000 | [diff] [blame] | 348 | void BenchmarkMeasureStats::push(const BenchmarkMeasure &BM) { |
| 349 | if (Key.empty()) |
| 350 | Key = BM.Key; |
| 351 | assert(Key == BM.Key); |
| 352 | ++NumValues; |
| 353 | SumValues += BM.Value; |
| 354 | MaxValue = std::max(MaxValue, BM.Value); |
| 355 | MinValue = std::min(MinValue, BM.Value); |
| 356 | } |
| 357 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 358 | } // namespace exegesis |