LLVM 20.0.0git
CodeEmitter.h
Go to the documentation of this file.
1//===--------------------- CodeEmitter.h ------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// A utility class used to compute instruction encodings. It buffers encodings
11/// for later usage. It exposes a simple API to compute and get the encodings as
12/// StringRef.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_MCA_CODEEMITTER_H
17#define LLVM_MCA_CODEEMITTER_H
18
19#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/StringRef.h"
24#include "llvm/MC/MCInst.h"
26
27namespace llvm {
28namespace mca {
29
30/// A utility class used to compute instruction encodings for a code region.
31///
32/// It provides a simple API to compute and return instruction encodings as
33/// strings. Encodings are cached internally for later usage.
35 const MCSubtargetInfo &STI;
36 const MCAsmBackend &MAB;
37 const MCCodeEmitter &MCE;
38
40 ArrayRef<MCInst> Sequence;
41
42 // An EncodingInfo pair stores <base, length> information. Base (i.e. first)
43 // is an index to the `Code`. Length (i.e. second) is the encoding size.
44 using EncodingInfo = std::pair<unsigned, unsigned>;
45
46 // A cache of encodings.
48
49 EncodingInfo getOrCreateEncodingInfo(unsigned MCID);
50
51public:
54 : STI(ST), MAB(AB), MCE(CE), Sequence(S), Encodings(S.size()) {}
55
56 StringRef getEncoding(unsigned MCID) {
57 EncodingInfo EI = getOrCreateEncodingInfo(MCID);
58 return StringRef(&Code[EI.first], EI.second);
59 }
60};
61
62} // namespace mca
63} // namespace llvm
64
65#endif // LLVM_MCA_CODEEMITTER_H
This file defines the SmallString class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
Generic base class for all target subtargets.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
A utility class used to compute instruction encodings for a code region.
Definition: CodeEmitter.h:34
CodeEmitter(const MCSubtargetInfo &ST, const MCAsmBackend &AB, const MCCodeEmitter &CE, ArrayRef< MCInst > S)
Definition: CodeEmitter.h:52
StringRef getEncoding(unsigned MCID)
Definition: CodeEmitter.h:56
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1697