mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
9bbf3a5aeb
Flag -show-encoding enables the printing of instruction encodings as part of the the instruction info view. Example (with flags -mtriple=x86_64-- -mcpu=btver2): Instruction Info: [1]: #uOps [2]: Latency [3]: RThroughput [4]: MayLoad [5]: MayStore [6]: HasSideEffects (U) [7]: Encoding Size [1] [2] [3] [4] [5] [6] [7] Encodings: Instructions: 1 2 1.00 4 c5 f0 59 d0 vmulps %xmm0, %xmm1, %xmm2 1 4 1.00 4 c5 eb 7c da vhaddps %xmm2, %xmm2, %xmm3 1 4 1.00 4 c5 e3 7c e3 vhaddps %xmm3, %xmm3, %xmm4 In this example, column Encoding Size is the size in bytes of the instruction encoding. Column Encodings reports the actual instruction encodings as byte sequences in hex (objdump style). The computation of encodings is done by a utility class named mca::CodeEmitter. In future, I plan to expose the CodeEmitter to the instruction builder, so that information about instruction encoding sizes can be used by the simulator. That would be a first step towards simulating the throughput from the decoders in the hardware frontend. Differential Revision: https://reviews.llvm.org/D65948 llvm-svn: 368432
73 lines
2.2 KiB
C++
73 lines
2.2 KiB
C++
//===--------------------- CodeEmitter.h ------------------------*- C++ -*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
/// \file
|
|
///
|
|
/// A utility class used to compute instruction encodings. It buffers encodings
|
|
/// for later usage. It exposes a simple API to compute and get the encodings as
|
|
/// StringRef.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_MCA_CODEEMITTER_H
|
|
#define LLVM_MCA_CODEEMITTER_H
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/MC/MCAsmBackend.h"
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
|
#include "llvm/MC/MCFixup.h"
|
|
#include "llvm/MC/MCInst.h"
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
#include "llvm/MCA/Instruction.h"
|
|
#include "llvm/MCA/Support.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <string>
|
|
|
|
namespace llvm {
|
|
namespace mca {
|
|
|
|
/// A utility class used to compute instruction encodings for a code region.
|
|
///
|
|
/// It provides a simple API to compute and return instruction encodings as
|
|
/// strings. Encodings are cached internally for later usage.
|
|
class CodeEmitter {
|
|
const MCSubtargetInfo &STI;
|
|
const MCAsmBackend &MAB;
|
|
const MCCodeEmitter &MCE;
|
|
|
|
SmallString<256> Code;
|
|
raw_svector_ostream VecOS;
|
|
ArrayRef<MCInst> Sequence;
|
|
|
|
// An EncodingInfo pair stores <base, length> information. Base (i.e. first)
|
|
// is an index to the `Code`. Length (i.e. second) is the encoding size.
|
|
using EncodingInfo = std::pair<unsigned, unsigned>;
|
|
|
|
// A cache of encodings.
|
|
SmallVector<EncodingInfo, 16> Encodings;
|
|
|
|
EncodingInfo getOrCreateEncodingInfo(unsigned MCID);
|
|
|
|
public:
|
|
CodeEmitter(const MCSubtargetInfo &ST, const MCAsmBackend &AB,
|
|
const MCCodeEmitter &CE, ArrayRef<MCInst> S)
|
|
: STI(ST), MAB(AB), MCE(CE), VecOS(Code), Sequence(S),
|
|
Encodings(S.size()) {}
|
|
|
|
StringRef getEncoding(unsigned MCID) {
|
|
EncodingInfo EI = getOrCreateEncodingInfo(MCID);
|
|
return StringRef(&Code[EI.first], EI.second);
|
|
}
|
|
};
|
|
|
|
} // namespace mca
|
|
} // namespace llvm
|
|
|
|
#endif // LLVM_MCA_CODEEMITTER_H
|