2017-08-02 05:20:10 +08:00
|
|
|
//===- HexagonMCCodeEmitter.h - Hexagon Target Descriptions -----*- C++ -*-===//
|
2014-10-03 21:18:11 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2014-10-03 21:18:11 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Definition for classes that emit Hexagon machine code from MCInsts
|
2014-10-03 21:18:11 +08:00
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCODEEMITTER_H
|
|
|
|
#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCODEEMITTER_H
|
2014-10-03 21:18:11 +08:00
|
|
|
|
2017-02-03 03:58:22 +08:00
|
|
|
#include "MCTargetDesc/HexagonFixupKinds.h"
|
2014-10-03 21:18:11 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
2017-08-02 05:20:10 +08:00
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
2014-10-03 21:18:11 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
class MCContext;
|
|
|
|
class MCInst;
|
|
|
|
class MCInstrInfo;
|
|
|
|
class MCOperand;
|
|
|
|
class MCSubtargetInfo;
|
|
|
|
class raw_ostream;
|
|
|
|
|
2014-10-03 21:18:11 +08:00
|
|
|
class HexagonMCCodeEmitter : public MCCodeEmitter {
|
|
|
|
MCContext &MCT;
|
2015-02-20 03:00:00 +08:00
|
|
|
MCInstrInfo const &MCII;
|
2015-05-02 05:14:21 +08:00
|
|
|
|
2018-05-09 23:02:04 +08:00
|
|
|
// A mutable state of the emitter when encoding bundles and duplexes.
|
|
|
|
struct EmitterState {
|
|
|
|
unsigned Addend = 0;
|
|
|
|
bool Extended = false;
|
|
|
|
bool SubInst1 = false;
|
|
|
|
const MCInst *Bundle = nullptr;
|
|
|
|
size_t Index = 0;
|
|
|
|
};
|
|
|
|
mutable EmitterState State;
|
2017-02-03 03:58:22 +08:00
|
|
|
|
2014-10-03 21:18:11 +08:00
|
|
|
public:
|
2018-05-09 23:02:04 +08:00
|
|
|
HexagonMCCodeEmitter(MCInstrInfo const &MII, MCContext &MCT)
|
|
|
|
: MCT(MCT), MCII(MII) {}
|
2015-05-29 22:44:13 +08:00
|
|
|
|
2015-05-16 03:13:16 +08:00
|
|
|
void encodeInstruction(MCInst const &MI, raw_ostream &OS,
|
2014-10-03 21:18:11 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
MCSubtargetInfo const &STI) const override;
|
|
|
|
|
2015-05-29 22:44:13 +08:00
|
|
|
void EncodeSingleInstruction(const MCInst &MI, raw_ostream &OS,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI,
|
2017-02-02 23:32:26 +08:00
|
|
|
uint32_t Parse) const;
|
2015-05-29 22:44:13 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
// TableGen'erated function for getting the
|
2014-10-03 21:18:11 +08:00
|
|
|
// binary encoding for an instruction.
|
|
|
|
uint64_t getBinaryCodeForInstr(MCInst const &MI,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
MCSubtargetInfo const &STI) const;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Return binary encoding of operand.
|
2014-10-03 21:18:11 +08:00
|
|
|
unsigned getMachineOpValue(MCInst const &MI, MCOperand const &MO,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
MCSubtargetInfo const &STI) const;
|
Check that emitted instructions meet their predicates on all targets except ARM, Mips, and X86.
Summary:
* ARM is omitted from this patch because this check appears to expose bugs in this target.
* Mips is omitted from this patch because this check either detects bugs or deliberate
emission of instructions that don't satisfy their predicates. One deliberate
use is the SYNC instruction where the version with an operand is correctly
defined as requiring MIPS32 while the version without an operand is defined
as an alias of 'SYNC 0' and requires MIPS2.
* X86 is omitted from this patch because it doesn't use the tablegen-erated
MCCodeEmitter infrastructure.
Patches for ARM and Mips will follow.
Depends on D25617
Reviewers: tstellarAMD, jmolloy
Subscribers: wdng, jmolloy, aemerson, rengolin, arsenm, jyknight, nemanjai, nhaehnle, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D25618
llvm-svn: 287439
2016-11-19 21:05:44 +08:00
|
|
|
|
|
|
|
private:
|
2018-05-09 23:02:04 +08:00
|
|
|
// helper routine for getMachineOpValue()
|
|
|
|
unsigned getExprOpValue(const MCInst &MI, const MCOperand &MO,
|
|
|
|
const MCExpr *ME, SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
|
|
|
|
|
|
|
Hexagon::Fixups getFixupNoBits(MCInstrInfo const &MCII, const MCInst &MI,
|
|
|
|
const MCOperand &MO,
|
|
|
|
const MCSymbolRefExpr::VariantKind Kind) const;
|
|
|
|
|
|
|
|
// Return parse bits for instruction `MCI' inside bundle `MCB'
|
|
|
|
uint32_t parseBits(size_t Last, MCInst const &MCB, MCInst const &MCI) const;
|
|
|
|
|
2019-03-12 01:04:35 +08:00
|
|
|
FeatureBitset computeAvailableFeatures(const FeatureBitset &FB) const;
|
|
|
|
void
|
|
|
|
verifyInstructionPredicates(const MCInst &MI,
|
|
|
|
const FeatureBitset &AvailableFeatures) const;
|
2017-08-02 05:20:10 +08:00
|
|
|
};
|
2014-10-03 21:18:11 +08:00
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
} // end namespace llvm
|
2014-10-03 21:18:11 +08:00
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
#endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCODEEMITTER_H
|