LLVM  10.0.0svn
CodeEmitter.cpp
Go to the documentation of this file.
1 //===--------------------- CodeEmitter.cpp ----------------------*- 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 //
9 // This file implements the CodeEmitter API.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/MCA/CodeEmitter.h"
14 
15 namespace llvm {
16 namespace mca {
17 
18 CodeEmitter::EncodingInfo
19 CodeEmitter::getOrCreateEncodingInfo(unsigned MCID) {
20  EncodingInfo &EI = Encodings[MCID];
21  if (EI.second)
22  return EI;
23 
24  SmallVector<llvm::MCFixup, 2> Fixups;
25  const MCInst &Inst = Sequence[MCID];
26  MCInst Relaxed(Sequence[MCID]);
27  if (MAB.mayNeedRelaxation(Inst, STI))
28  MAB.relaxInstruction(Inst, STI, Relaxed);
29 
30  EI.first = Code.size();
31  MCE.encodeInstruction(Relaxed, VecOS, Fixups, STI);
32  EI.second = Code.size() - EI.first;
33  return EI;
34 }
35 
36 } // namespace mca
37 } // namespace llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
virtual bool mayNeedRelaxation(const MCInst &Inst, const MCSubtargetInfo &STI) const =0
Check whether the given instruction may need relaxation.
virtual void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, MCInst &Res) const =0
Relax the instruction in the given fragment to the next wider instruction.
std::pair< UnicodeEncodingForm, unsigned > EncodingInfo
EncodingInfo - Holds the encoding type and length of the byte order mark if it exists.
Definition: YAMLParser.cpp:54
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
A utility class used to compute instruction encodings.
size_t size() const
Definition: SmallVector.h:52