2018-03-08 14:05:02 +01:00
|
|
|
//===--------------------- InstrBuilder.h -----------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-03-08 14:05:02 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
///
|
|
|
|
/// A builder class for instructions that are statically analyzed by llvm-mca.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-12-17 09:08:31 +01:00
|
|
|
#ifndef LLVM_MCA_INSTRBUILDER_H
|
|
|
|
#define LLVM_MCA_INSTRBUILDER_H
|
2018-03-08 14:05:02 +01:00
|
|
|
|
2018-06-20 12:08:11 +02:00
|
|
|
#include "llvm/MC/MCInstrAnalysis.h"
|
2018-03-08 14:05:02 +01:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2018-06-20 12:08:11 +02:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2018-03-08 14:05:02 +01:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2018-12-17 09:08:31 +01:00
|
|
|
#include "llvm/MCA/Instruction.h"
|
|
|
|
#include "llvm/MCA/Support.h"
|
2018-08-13 20:11:48 +02:00
|
|
|
#include "llvm/Support/Error.h"
|
2018-03-08 14:05:02 +01:00
|
|
|
|
2018-10-30 16:56:08 +01:00
|
|
|
namespace llvm {
|
2018-03-08 14:05:02 +01:00
|
|
|
namespace mca {
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// A builder class that knows how to construct Instruction objects.
|
2018-03-08 14:05:02 +01:00
|
|
|
///
|
|
|
|
/// Every llvm-mca Instruction is described by an object of class InstrDesc.
|
|
|
|
/// An InstrDesc describes which registers are read/written by the instruction,
|
|
|
|
/// as well as the instruction latency and hardware resources consumed.
|
|
|
|
///
|
|
|
|
/// This class is used by the tool to construct Instructions and instruction
|
|
|
|
/// descriptors (i.e. InstrDesc objects).
|
|
|
|
/// Information from the machine scheduling model is used to identify processor
|
|
|
|
/// resources that are consumed by an instruction.
|
|
|
|
class InstrBuilder {
|
2018-10-31 16:53:28 +01:00
|
|
|
const MCSubtargetInfo &STI;
|
|
|
|
const MCInstrInfo &MCII;
|
|
|
|
const MCRegisterInfo &MRI;
|
2018-12-17 15:00:37 +01:00
|
|
|
const MCInstrAnalysis *MCIA;
|
2018-10-31 16:53:28 +01:00
|
|
|
SmallVector<uint64_t, 8> ProcResourceMasks;
|
2018-03-08 14:05:02 +01:00
|
|
|
|
2018-10-31 16:53:28 +01:00
|
|
|
DenseMap<unsigned short, std::unique_ptr<const InstrDesc>> Descriptors;
|
|
|
|
DenseMap<const MCInst *, std::unique_ptr<const InstrDesc>> VariantDescriptors;
|
2018-03-08 14:05:02 +01:00
|
|
|
|
2018-11-24 19:40:45 +01:00
|
|
|
bool FirstCallInst;
|
|
|
|
bool FirstReturnInst;
|
|
|
|
|
2018-10-31 16:53:28 +01:00
|
|
|
Expected<const InstrDesc &> createInstrDescImpl(const MCInst &MCI);
|
|
|
|
Expected<const InstrDesc &> getOrCreateInstrDesc(const MCInst &MCI);
|
2018-08-10 22:24:27 +02:00
|
|
|
|
2018-05-04 15:10:10 +02:00
|
|
|
InstrBuilder(const InstrBuilder &) = delete;
|
|
|
|
InstrBuilder &operator=(const InstrBuilder &) = delete;
|
2018-03-08 14:05:02 +01:00
|
|
|
|
2018-11-23 21:26:57 +01:00
|
|
|
void populateWrites(InstrDesc &ID, const MCInst &MCI, unsigned SchedClassID);
|
|
|
|
void populateReads(InstrDesc &ID, const MCInst &MCI, unsigned SchedClassID);
|
2018-10-31 16:53:28 +01:00
|
|
|
Error verifyInstrDesc(const InstrDesc &ID, const MCInst &MCI) const;
|
2018-07-09 14:30:55 +02:00
|
|
|
|
2018-03-08 14:05:02 +01:00
|
|
|
public:
|
2018-10-31 16:53:28 +01:00
|
|
|
InstrBuilder(const MCSubtargetInfo &STI, const MCInstrInfo &MCII,
|
2018-12-17 15:00:37 +01:00
|
|
|
const MCRegisterInfo &RI, const MCInstrAnalysis *IA);
|
2018-03-08 14:05:02 +01:00
|
|
|
|
2018-11-24 19:40:45 +01:00
|
|
|
void clear() {
|
2021-05-31 17:39:35 +02:00
|
|
|
Descriptors.clear();
|
|
|
|
VariantDescriptors.clear();
|
2018-11-24 19:40:45 +01:00
|
|
|
FirstCallInst = true;
|
|
|
|
FirstReturnInst = true;
|
|
|
|
}
|
2018-07-02 22:39:57 +02:00
|
|
|
|
2018-10-31 16:53:28 +01:00
|
|
|
Expected<std::unique_ptr<Instruction>> createInstruction(const MCInst &MCI);
|
2018-03-08 14:05:02 +01:00
|
|
|
};
|
|
|
|
} // namespace mca
|
2018-10-30 16:56:08 +01:00
|
|
|
} // namespace llvm
|
2018-03-08 14:05:02 +01:00
|
|
|
|
2018-12-17 09:08:31 +01:00
|
|
|
#endif // LLVM_MCA_INSTRBUILDER_H
|