18bcb0991SDimitry Andric //===--------------------- CodeEmitter.cpp ----------------------*- C++ -*-===// 28bcb0991SDimitry Andric // 38bcb0991SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 48bcb0991SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 58bcb0991SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 68bcb0991SDimitry Andric // 78bcb0991SDimitry Andric //===----------------------------------------------------------------------===// 88bcb0991SDimitry Andric // 98bcb0991SDimitry Andric // This file implements the CodeEmitter API. 108bcb0991SDimitry Andric // 118bcb0991SDimitry Andric //===----------------------------------------------------------------------===// 128bcb0991SDimitry Andric 138bcb0991SDimitry Andric #include "llvm/MCA/CodeEmitter.h" 148bcb0991SDimitry Andric 158bcb0991SDimitry Andric namespace llvm { 168bcb0991SDimitry Andric namespace mca { 178bcb0991SDimitry Andric getOrCreateEncodingInfo(unsigned MCID)18fe6060f1SDimitry AndricCodeEmitter::EncodingInfo CodeEmitter::getOrCreateEncodingInfo(unsigned MCID) { 198bcb0991SDimitry Andric EncodingInfo &EI = Encodings[MCID]; 208bcb0991SDimitry Andric if (EI.second) 218bcb0991SDimitry Andric return EI; 228bcb0991SDimitry Andric 238bcb0991SDimitry Andric SmallVector<llvm::MCFixup, 2> Fixups; 248bcb0991SDimitry Andric const MCInst &Inst = Sequence[MCID]; 258bcb0991SDimitry Andric MCInst Relaxed(Sequence[MCID]); 268bcb0991SDimitry Andric if (MAB.mayNeedRelaxation(Inst, STI)) 275ffd83dbSDimitry Andric MAB.relaxInstruction(Relaxed, STI); 288bcb0991SDimitry Andric 298bcb0991SDimitry Andric EI.first = Code.size(); 30*06c3fb27SDimitry Andric MCE.encodeInstruction(Relaxed, Code, Fixups, STI); 318bcb0991SDimitry Andric EI.second = Code.size() - EI.first; 328bcb0991SDimitry Andric return EI; 338bcb0991SDimitry Andric } 348bcb0991SDimitry Andric 358bcb0991SDimitry Andric } // namespace mca 368bcb0991SDimitry Andric } // namespace llvm 37