llvm-project/llvm/lib/MCA/CodeEmitter.cpp
Alexis Engelke 0c049ea60a [MC] Always encode instruction into SmallVector
All users of MCCodeEmitter::encodeInstruction use a raw_svector_ostream
to encode the instruction into a SmallVector. The raw_ostream however
incurs some overhead for the actual encoding.

This change allows an MCCodeEmitter to directly emit an instruction into
a SmallVector without using a raw_ostream and therefore allow for
performance improvments in encoding. A default path that uses existing
raw_ostream implementations is provided.

Reviewed By: MaskRay, Amir

Differential Revision: https://reviews.llvm.org/D145791
2023-04-06 16:21:49 +02:00

37 lines
1.1 KiB
C++

//===--------------------- CodeEmitter.cpp ----------------------*- 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
//
//===----------------------------------------------------------------------===//
//
// This file implements the CodeEmitter API.
//
//===----------------------------------------------------------------------===//
#include "llvm/MCA/CodeEmitter.h"
namespace llvm {
namespace mca {
CodeEmitter::EncodingInfo CodeEmitter::getOrCreateEncodingInfo(unsigned MCID) {
EncodingInfo &EI = Encodings[MCID];
if (EI.second)
return EI;
SmallVector<llvm::MCFixup, 2> Fixups;
const MCInst &Inst = Sequence[MCID];
MCInst Relaxed(Sequence[MCID]);
if (MAB.mayNeedRelaxation(Inst, STI))
MAB.relaxInstruction(Relaxed, STI);
EI.first = Code.size();
MCE.encodeInstruction(Relaxed, Code, Fixups, STI);
EI.second = Code.size() - EI.first;
return EI;
}
} // namespace mca
} // namespace llvm