Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 1 | //===-- Uops.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 "Uops.h" |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 11 | |
| 12 | #include "Assembler.h" |
| 13 | #include "BenchmarkRunner.h" |
| 14 | #include "MCInstrDescView.h" |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 15 | #include "PerfHelper.h" |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 16 | #include "Target.h" |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 17 | |
| 18 | // FIXME: Load constants into registers (e.g. with fld1) to not break |
| 19 | // instructions like x87. |
| 20 | |
| 21 | // Ideally we would like the only limitation on executing uops to be the issue |
| 22 | // ports. Maximizing port pressure increases the likelihood that the load is |
| 23 | // distributed evenly across possible ports. |
| 24 | |
| 25 | // To achieve that, one approach is to generate instructions that do not have |
| 26 | // data dependencies between them. |
| 27 | // |
| 28 | // For some instructions, this is trivial: |
| 29 | // mov rax, qword ptr [rsi] |
| 30 | // mov rax, qword ptr [rsi] |
| 31 | // mov rax, qword ptr [rsi] |
| 32 | // mov rax, qword ptr [rsi] |
| 33 | // For the above snippet, haswell just renames rax four times and executes the |
| 34 | // four instructions two at a time on P23 and P0126. |
| 35 | // |
| 36 | // For some instructions, we just need to make sure that the source is |
| 37 | // different from the destination. For example, IDIV8r reads from GPR and |
| 38 | // writes to AX. We just need to ensure that the Var is assigned a |
| 39 | // register which is different from AX: |
| 40 | // idiv bx |
| 41 | // idiv bx |
| 42 | // idiv bx |
| 43 | // idiv bx |
| 44 | // The above snippet will be able to fully saturate the ports, while the same |
| 45 | // with ax would issue one uop every `latency(IDIV8r)` cycles. |
| 46 | // |
| 47 | // Some instructions make this harder because they both read and write from |
| 48 | // the same register: |
| 49 | // inc rax |
| 50 | // inc rax |
| 51 | // inc rax |
| 52 | // inc rax |
| 53 | // This has a data dependency from each instruction to the next, limit the |
| 54 | // number of instructions that can be issued in parallel. |
| 55 | // It turns out that this is not a big issue on recent Intel CPUs because they |
| 56 | // have heuristics to balance port pressure. In the snippet above, subsequent |
| 57 | // instructions will end up evenly distributed on {P0,P1,P5,P6}, but some CPUs |
| 58 | // might end up executing them all on P0 (just because they can), or try |
| 59 | // avoiding P5 because it's usually under high pressure from vector |
| 60 | // instructions. |
| 61 | // This issue is even more important for high-latency instructions because |
| 62 | // they increase the idle time of the CPU, e.g. : |
| 63 | // imul rax, rbx |
| 64 | // imul rax, rbx |
| 65 | // imul rax, rbx |
| 66 | // imul rax, rbx |
| 67 | // |
| 68 | // To avoid that, we do the renaming statically by generating as many |
| 69 | // independent exclusive assignments as possible (until all possible registers |
| 70 | // are exhausted) e.g.: |
| 71 | // imul rax, rbx |
| 72 | // imul rcx, rbx |
| 73 | // imul rdx, rbx |
| 74 | // imul r8, rbx |
| 75 | // |
| 76 | // Some instruction even make the above static renaming impossible because |
| 77 | // they implicitly read and write from the same operand, e.g. ADC16rr reads |
| 78 | // and writes from EFLAGS. |
| 79 | // In that case we just use a greedy register assignment and hope for the |
| 80 | // best. |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 81 | |
| 82 | namespace exegesis { |
| 83 | |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 84 | static bool hasUnknownOperand(const llvm::MCOperandInfo &OpInfo) { |
| 85 | return OpInfo.OperandType == llvm::MCOI::OPERAND_UNKNOWN; |
| 86 | } |
| 87 | |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 88 | llvm::Error |
| 89 | UopsBenchmarkRunner::isInfeasible(const llvm::MCInstrDesc &MCInstrDesc) const { |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 90 | if (llvm::any_of(MCInstrDesc.operands(), hasUnknownOperand)) |
| 91 | return llvm::make_error<BenchmarkFailure>( |
| 92 | "Infeasible : has unknown operands"); |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 93 | return llvm::Error::success(); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | // Returns whether this Variable ties Use and Def operands together. |
Guillaume Chatelet | ef6cef5 | 2018-06-20 08:52:30 +0000 | [diff] [blame] | 97 | static bool hasTiedOperands(const Instruction &Instr, const Variable &Var) { |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 98 | bool HasUse = false; |
| 99 | bool HasDef = false; |
Guillaume Chatelet | ef6cef5 | 2018-06-20 08:52:30 +0000 | [diff] [blame] | 100 | for (const unsigned OpIndex : Var.TiedOperands) { |
| 101 | const Operand &Op = Instr.Operands[OpIndex]; |
| 102 | if (Op.IsDef) |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 103 | HasDef = true; |
| 104 | else |
| 105 | HasUse = true; |
| 106 | } |
| 107 | return HasUse && HasDef; |
| 108 | } |
| 109 | |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 110 | static llvm::SmallVector<const Variable *, 8> |
| 111 | getTiedVariables(const Instruction &Instr) { |
| 112 | llvm::SmallVector<const Variable *, 8> Result; |
| 113 | for (const auto &Var : Instr.Variables) |
Guillaume Chatelet | ef6cef5 | 2018-06-20 08:52:30 +0000 | [diff] [blame] | 114 | if (hasTiedOperands(Instr, Var)) |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 115 | Result.push_back(&Var); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 116 | return Result; |
| 117 | } |
| 118 | |
| 119 | static void remove(llvm::BitVector &a, const llvm::BitVector &b) { |
| 120 | assert(a.size() == b.size()); |
| 121 | for (auto I : b.set_bits()) |
| 122 | a.reset(I); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 125 | UopsBenchmarkRunner::~UopsBenchmarkRunner() = default; |
| 126 | |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 127 | void UopsBenchmarkRunner::instantiateMemoryOperands( |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 128 | const unsigned ScratchSpacePointerInReg, |
| 129 | std::vector<InstructionBuilder> &Instructions) const { |
| 130 | if (ScratchSpacePointerInReg == 0) |
Guillaume Chatelet | 171f3f4 | 2018-08-02 11:12:02 +0000 | [diff] [blame] | 131 | return; // no memory operands. |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 132 | const auto &ET = State.getExegesisTarget(); |
| 133 | const unsigned MemStep = ET.getMaxMemoryAccessSize(); |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 134 | const size_t OriginalInstructionsSize = Instructions.size(); |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 135 | size_t I = 0; |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 136 | for (InstructionBuilder &IB : Instructions) { |
| 137 | ET.fillMemoryOperands(IB, ScratchSpacePointerInReg, I * MemStep); |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 138 | ++I; |
| 139 | } |
| 140 | |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 141 | while (Instructions.size() < kMinNumDifferentAddresses) { |
| 142 | InstructionBuilder IB = Instructions[I % OriginalInstructionsSize]; |
| 143 | ET.fillMemoryOperands(IB, ScratchSpacePointerInReg, I * MemStep); |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 144 | ++I; |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 145 | Instructions.push_back(std::move(IB)); |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 146 | } |
| 147 | assert(I * MemStep < ScratchSpace::kSize && "not enough scratch space"); |
| 148 | } |
| 149 | |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 150 | llvm::Expected<CodeTemplate> |
| 151 | UopsBenchmarkRunner::generateCodeTemplate(unsigned Opcode) const { |
Clement Courbet | 0e8bf4e | 2018-06-25 13:44:27 +0000 | [diff] [blame] | 152 | const auto &InstrDesc = State.getInstrInfo().get(Opcode); |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 153 | if (auto E = isInfeasible(InstrDesc)) |
| 154 | return std::move(E); |
| 155 | const Instruction Instr(InstrDesc, RATC); |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 156 | const auto &ET = State.getExegesisTarget(); |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 157 | CodeTemplate CT; |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 158 | |
| 159 | const llvm::BitVector *ScratchSpaceAliasedRegs = nullptr; |
| 160 | if (Instr.hasMemoryOperands()) { |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 161 | CT.ScratchSpacePointerInReg = |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 162 | ET.getScratchMemoryRegister(State.getTargetMachine().getTargetTriple()); |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 163 | if (CT.ScratchSpacePointerInReg == 0) |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 164 | return llvm::make_error<BenchmarkFailure>( |
| 165 | "Infeasible : target does not support memory instructions"); |
| 166 | ScratchSpaceAliasedRegs = |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 167 | &RATC.getRegister(CT.ScratchSpacePointerInReg).aliasedBits(); |
| 168 | // If the instruction implicitly writes to ScratchSpacePointerInReg , abort. |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 169 | // FIXME: We could make a copy of the scratch register. |
| 170 | for (const auto &Op : Instr.Operands) { |
| 171 | if (Op.IsDef && Op.ImplicitReg && |
| 172 | ScratchSpaceAliasedRegs->test(*Op.ImplicitReg)) |
| 173 | return llvm::make_error<BenchmarkFailure>( |
| 174 | "Infeasible : memory instruction uses scratch memory register"); |
| 175 | } |
| 176 | } |
| 177 | |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 178 | const AliasingConfigurations SelfAliasing(Instr, Instr); |
Guillaume Chatelet | 171f3f4 | 2018-08-02 11:12:02 +0000 | [diff] [blame] | 179 | InstructionBuilder IB(Instr); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 180 | if (SelfAliasing.empty()) { |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 181 | CT.Info = "instruction is parallel, repeating a random one."; |
| 182 | CT.Instructions.push_back(std::move(IB)); |
| 183 | instantiateMemoryOperands(CT.ScratchSpacePointerInReg, CT.Instructions); |
| 184 | return std::move(CT); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 185 | } |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 186 | if (SelfAliasing.hasImplicitAliasing()) { |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 187 | CT.Info = "instruction is serial, repeating a random one."; |
| 188 | CT.Instructions.push_back(std::move(IB)); |
| 189 | instantiateMemoryOperands(CT.ScratchSpacePointerInReg, CT.Instructions); |
| 190 | return std::move(CT); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 191 | } |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 192 | const auto TiedVariables = getTiedVariables(Instr); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 193 | if (!TiedVariables.empty()) { |
Guillaume Chatelet | b4f1582 | 2018-06-07 14:00:29 +0000 | [diff] [blame] | 194 | if (TiedVariables.size() > 1) |
| 195 | return llvm::make_error<llvm::StringError>( |
| 196 | "Infeasible : don't know how to handle several tied variables", |
| 197 | llvm::inconvertibleErrorCode()); |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 198 | const Variable *Var = TiedVariables.front(); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 199 | assert(Var); |
| 200 | assert(!Var->TiedOperands.empty()); |
Guillaume Chatelet | ef6cef5 | 2018-06-20 08:52:30 +0000 | [diff] [blame] | 201 | const Operand &Op = Instr.Operands[Var->TiedOperands.front()]; |
| 202 | assert(Op.Tracker); |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 203 | CT.Info = "instruction has tied variables using static renaming."; |
Guillaume Chatelet | ef6cef5 | 2018-06-20 08:52:30 +0000 | [diff] [blame] | 204 | for (const llvm::MCPhysReg Reg : Op.Tracker->sourceBits().set_bits()) { |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 205 | if (ScratchSpaceAliasedRegs && ScratchSpaceAliasedRegs->test(Reg)) |
| 206 | continue; // Do not use the scratch memory address register. |
Guillaume Chatelet | 171f3f4 | 2018-08-02 11:12:02 +0000 | [diff] [blame] | 207 | InstructionBuilder TmpIB = IB; |
| 208 | TmpIB.getValueFor(*Var) = llvm::MCOperand::createReg(Reg); |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 209 | CT.Instructions.push_back(std::move(TmpIB)); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 210 | } |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 211 | instantiateMemoryOperands(CT.ScratchSpacePointerInReg, CT.Instructions); |
| 212 | return std::move(CT); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 213 | } |
| 214 | // No tied variables, we pick random values for defs. |
Clement Courbet | 0e8bf4e | 2018-06-25 13:44:27 +0000 | [diff] [blame] | 215 | llvm::BitVector Defs(State.getRegInfo().getNumRegs()); |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 216 | for (const auto &Op : Instr.Operands) { |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 217 | if (Op.Tracker && Op.IsExplicit && Op.IsDef && !Op.IsMem) { |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 218 | auto PossibleRegisters = Op.Tracker->sourceBits(); |
| 219 | remove(PossibleRegisters, RATC.reservedRegisters()); |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 220 | // Do not use the scratch memory address register. |
| 221 | if (ScratchSpaceAliasedRegs) |
| 222 | remove(PossibleRegisters, *ScratchSpaceAliasedRegs); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 223 | assert(PossibleRegisters.any() && "No register left to choose from"); |
| 224 | const auto RandomReg = randomBit(PossibleRegisters); |
| 225 | Defs.set(RandomReg); |
Guillaume Chatelet | 171f3f4 | 2018-08-02 11:12:02 +0000 | [diff] [blame] | 226 | IB.getValueFor(Op) = llvm::MCOperand::createReg(RandomReg); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | // And pick random use values that are not reserved and don't alias with defs. |
Clement Courbet | 0e8bf4e | 2018-06-25 13:44:27 +0000 | [diff] [blame] | 230 | const auto DefAliases = getAliasedBits(State.getRegInfo(), Defs); |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 231 | for (const auto &Op : Instr.Operands) { |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 232 | if (Op.Tracker && Op.IsExplicit && !Op.IsDef && !Op.IsMem) { |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 233 | auto PossibleRegisters = Op.Tracker->sourceBits(); |
| 234 | remove(PossibleRegisters, RATC.reservedRegisters()); |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 235 | // Do not use the scratch memory address register. |
| 236 | if (ScratchSpaceAliasedRegs) |
| 237 | remove(PossibleRegisters, *ScratchSpaceAliasedRegs); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 238 | remove(PossibleRegisters, DefAliases); |
| 239 | assert(PossibleRegisters.any() && "No register left to choose from"); |
| 240 | const auto RandomReg = randomBit(PossibleRegisters); |
Guillaume Chatelet | 171f3f4 | 2018-08-02 11:12:02 +0000 | [diff] [blame] | 241 | IB.getValueFor(Op) = llvm::MCOperand::createReg(RandomReg); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 242 | } |
| 243 | } |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 244 | CT.Info = |
Guillaume Chatelet | b4f1582 | 2018-06-07 14:00:29 +0000 | [diff] [blame] | 245 | "instruction has no tied variables picking Uses different from defs"; |
Guillaume Chatelet | e60866a | 2018-08-03 09:29:38 +0000 | [diff] [blame] | 246 | CT.Instructions.push_back(std::move(IB)); |
| 247 | instantiateMemoryOperands(CT.ScratchSpacePointerInReg, CT.Instructions); |
| 248 | return std::move(CT); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | std::vector<BenchmarkMeasure> |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 252 | UopsBenchmarkRunner::runMeasurements(const ExecutableFunction &Function, |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 253 | ScratchSpace &Scratch, |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 254 | const unsigned NumRepetitions) const { |
| 255 | const auto &SchedModel = State.getSubtargetInfo().getSchedModel(); |
| 256 | |
| 257 | std::vector<BenchmarkMeasure> Result; |
| 258 | for (unsigned ProcResIdx = 1; |
| 259 | ProcResIdx < SchedModel.getNumProcResourceKinds(); ++ProcResIdx) { |
Clement Courbet | b449379 | 2018-04-10 08:16:37 +0000 | [diff] [blame] | 260 | const char *const PfmCounters = SchedModel.getExtraProcessorInfo() |
| 261 | .PfmCounters.IssueCounters[ProcResIdx]; |
| 262 | if (!PfmCounters) |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 263 | continue; |
Clement Courbet | 3827537 | 2018-06-12 13:28:37 +0000 | [diff] [blame] | 264 | // We sum counts when there are several counters for a single ProcRes |
Clement Courbet | b449379 | 2018-04-10 08:16:37 +0000 | [diff] [blame] | 265 | // (e.g. P23 on SandyBridge). |
Clement Courbet | 3827537 | 2018-06-12 13:28:37 +0000 | [diff] [blame] | 266 | int64_t CounterValue = 0; |
| 267 | llvm::SmallVector<llvm::StringRef, 2> CounterNames; |
| 268 | llvm::StringRef(PfmCounters).split(CounterNames, ','); |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 269 | for (const auto &CounterName : CounterNames) { |
Clement Courbet | 3827537 | 2018-06-12 13:28:37 +0000 | [diff] [blame] | 270 | pfm::PerfEvent UopPerfEvent(CounterName); |
| 271 | if (!UopPerfEvent.valid()) |
| 272 | llvm::report_fatal_error( |
| 273 | llvm::Twine("invalid perf event ").concat(PfmCounters)); |
| 274 | pfm::Counter Counter(UopPerfEvent); |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 275 | Scratch.clear(); |
Clement Courbet | 3827537 | 2018-06-12 13:28:37 +0000 | [diff] [blame] | 276 | Counter.start(); |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 277 | Function(Scratch.ptr()); |
Clement Courbet | 3827537 | 2018-06-12 13:28:37 +0000 | [diff] [blame] | 278 | Counter.stop(); |
| 279 | CounterValue += Counter.read(); |
| 280 | } |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 281 | Result.push_back({llvm::itostr(ProcResIdx), |
Clement Courbet | 3827537 | 2018-06-12 13:28:37 +0000 | [diff] [blame] | 282 | static_cast<double>(CounterValue) / NumRepetitions, |
Clement Courbet | b449379 | 2018-04-10 08:16:37 +0000 | [diff] [blame] | 283 | SchedModel.getProcResource(ProcResIdx)->Name}); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 284 | } |
| 285 | return Result; |
| 286 | } |
| 287 | |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 288 | constexpr const size_t UopsBenchmarkRunner::kMinNumDifferentAddresses; |
| 289 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 290 | } // namespace exegesis |