2017-02-08 23:23:19 +01:00
|
|
|
//===- llvm/MC/MCAsmBackend.h - MC Asm Backend ------------------*- C++ -*-===//
|
2010-02-21 22:53:53 +01:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-26 01:24:55 +02:00
|
|
|
#ifndef LLVM_MC_MCASMBACKEND_H
|
|
|
|
#define LLVM_MC_MCASMBACKEND_H
|
2010-02-21 22:53:53 +01:00
|
|
|
|
2013-09-09 04:37:14 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2016-01-20 00:05:27 +01:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2017-02-08 23:23:19 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2010-12-08 02:16:55 +01:00
|
|
|
#include "llvm/MC/MCDirectives.h"
|
2010-12-16 04:20:06 +01:00
|
|
|
#include "llvm/MC/MCFixup.h"
|
2017-02-08 23:23:19 +01:00
|
|
|
#include <cstdint>
|
2010-03-19 10:28:12 +01:00
|
|
|
|
2010-02-21 22:53:53 +01:00
|
|
|
namespace llvm {
|
2017-02-08 23:23:19 +01:00
|
|
|
|
2011-12-06 01:47:03 +01:00
|
|
|
class MCAsmLayout;
|
2012-01-18 01:23:57 +01:00
|
|
|
class MCAssembler;
|
2016-07-27 18:03:57 +02:00
|
|
|
class MCCFIInstruction;
|
2012-03-26 08:58:25 +02:00
|
|
|
struct MCFixupKindInfo;
|
2012-01-18 01:23:57 +01:00
|
|
|
class MCFragment;
|
2010-03-23 02:39:09 +01:00
|
|
|
class MCInst;
|
2010-03-19 11:43:26 +01:00
|
|
|
class MCObjectWriter;
|
2017-02-08 23:23:19 +01:00
|
|
|
class MCRelaxableFragment;
|
2016-07-27 18:03:57 +02:00
|
|
|
class MCSubtargetInfo;
|
2012-01-18 01:23:57 +01:00
|
|
|
class MCValue;
|
2016-04-18 11:17:29 +02:00
|
|
|
class raw_pwrite_stream;
|
2010-02-21 22:53:53 +01:00
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Generic interface to target specific assembler backends.
|
2011-07-26 01:24:55 +02:00
|
|
|
class MCAsmBackend {
|
2010-02-21 22:53:53 +01:00
|
|
|
protected: // Can only create subclasses.
|
2011-07-26 01:24:55 +02:00
|
|
|
MCAsmBackend();
|
2010-02-21 22:53:53 +01:00
|
|
|
|
|
|
|
public:
|
2017-02-08 23:23:19 +01:00
|
|
|
MCAsmBackend(const MCAsmBackend &) = delete;
|
|
|
|
MCAsmBackend &operator=(const MCAsmBackend &) = delete;
|
2011-07-26 01:24:55 +02:00
|
|
|
virtual ~MCAsmBackend();
|
2010-02-21 22:53:53 +01:00
|
|
|
|
2012-12-14 19:52:11 +01:00
|
|
|
/// lifetime management
|
2013-09-07 13:55:36 +02:00
|
|
|
virtual void reset() {}
|
2012-12-14 19:52:11 +01:00
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Create a new MCObjectWriter instance for use by the assembler backend to
|
|
|
|
/// emit the final object file.
|
2015-04-15 00:14:34 +02:00
|
|
|
virtual MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const = 0;
|
2010-03-19 11:43:26 +01:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \name Target Fixup Interfaces
|
2010-12-16 04:20:06 +01:00
|
|
|
/// @{
|
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Get the number of target specific fixup kinds.
|
2010-12-16 04:20:06 +01:00
|
|
|
virtual unsigned getNumFixupKinds() const = 0;
|
|
|
|
|
2015-11-12 14:33:00 +01:00
|
|
|
/// Map a relocation name used in .reloc to a fixup kind.
|
2016-01-20 00:05:27 +01:00
|
|
|
virtual Optional<MCFixupKind> getFixupKind(StringRef Name) const;
|
2015-11-12 14:33:00 +01:00
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Get information on a fixup kind.
|
2010-12-16 04:20:06 +01:00
|
|
|
virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
|
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Target hook to adjust the literal value of a fixup if necessary.
|
|
|
|
/// IsResolved signals whether the caller believes a relocation is needed; the
|
|
|
|
/// target can modify the value. The default does nothing.
|
2012-01-18 01:23:57 +01:00
|
|
|
virtual void processFixupValue(const MCAssembler &Asm,
|
|
|
|
const MCAsmLayout &Layout,
|
|
|
|
const MCFixup &Fixup, const MCFragment *DF,
|
2014-03-28 17:06:09 +01:00
|
|
|
const MCValue &Target, uint64_t &Value,
|
2012-02-27 22:36:23 +01:00
|
|
|
bool &IsResolved) {}
|
2012-01-18 01:23:57 +01:00
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Apply the \p Value for given \p Fixup into the provided data fragment, at
|
|
|
|
/// the offset specified by the fixup and following the fixup kind as
|
2017-04-05 12:16:14 +02:00
|
|
|
/// appropriate. Errors (such as an out of range fixup value) should be
|
|
|
|
/// reported via \p Ctx.
|
2012-01-18 19:52:16 +01:00
|
|
|
virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
2017-04-05 12:16:14 +02:00
|
|
|
uint64_t Value, bool IsPCRel,
|
|
|
|
MCContext &Ctx) const = 0;
|
2010-03-23 02:39:09 +01:00
|
|
|
|
2010-12-16 04:20:06 +01:00
|
|
|
/// @}
|
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \name Target Relaxation Interfaces
|
2010-12-16 04:20:06 +01:00
|
|
|
/// @{
|
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Check whether the given instruction may need relaxation.
|
2010-03-23 04:13:05 +01:00
|
|
|
///
|
2010-05-26 20:15:06 +02:00
|
|
|
/// \param Inst - The instruction to test.
|
2012-01-18 19:52:16 +01:00
|
|
|
virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
|
2010-03-23 04:13:05 +01:00
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Target specific predicate for whether a given fixup requires the
|
|
|
|
/// associated instruction to be relaxed.
|
2015-05-30 20:42:22 +02:00
|
|
|
virtual bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved,
|
|
|
|
uint64_t Value,
|
|
|
|
const MCRelaxableFragment *DF,
|
|
|
|
const MCAsmLayout &Layout) const;
|
|
|
|
|
|
|
|
/// Simple predicate for targets where !Resolved implies requiring relaxation
|
2013-09-07 13:55:36 +02:00
|
|
|
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
|
2013-01-08 01:22:56 +01:00
|
|
|
const MCRelaxableFragment *DF,
|
2011-12-06 01:47:03 +01:00
|
|
|
const MCAsmLayout &Layout) const = 0;
|
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Relax the instruction in the given fragment to the next wider instruction.
|
2010-05-26 20:15:06 +02:00
|
|
|
///
|
2012-09-12 18:59:47 +02:00
|
|
|
/// \param Inst The instruction to relax, which may be the same as the
|
2010-05-26 20:15:06 +02:00
|
|
|
/// output.
|
2016-07-11 16:23:53 +02:00
|
|
|
/// \param STI the subtarget information for the associated instruction.
|
2012-09-12 18:59:47 +02:00
|
|
|
/// \param [out] Res On return, the relaxed instruction.
|
2016-07-11 16:23:53 +02:00
|
|
|
virtual void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
|
|
|
|
MCInst &Res) const = 0;
|
2010-03-23 03:36:58 +01:00
|
|
|
|
2010-12-16 04:20:06 +01:00
|
|
|
/// @}
|
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Returns the minimum size of a nop in bytes on this target. The assembler
|
|
|
|
/// will use this to emit excess padding in situations where the padding
|
|
|
|
/// required for simple alignment would be less than the minimum nop size.
|
2012-08-30 00:18:56 +02:00
|
|
|
///
|
|
|
|
virtual unsigned getMinimumNopSize() const { return 1; }
|
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Write an (optimal) nop sequence of Count bytes to the given output. If the
|
|
|
|
/// target cannot generate such a sequence, it should return an error.
|
2010-03-23 03:36:58 +01:00
|
|
|
///
|
|
|
|
/// \return - True on success.
|
2012-01-18 19:52:16 +01:00
|
|
|
virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
|
2010-12-08 02:16:55 +01:00
|
|
|
|
2016-04-27 23:26:13 +02:00
|
|
|
/// Give backend an opportunity to finish layout after relaxation
|
|
|
|
virtual void finishLayout(MCAssembler const &Asm,
|
|
|
|
MCAsmLayout &Layout) const {}
|
|
|
|
|
2015-04-09 18:06:26 +02:00
|
|
|
/// Handle any target-specific assembler flags. By default, do nothing.
|
2012-01-18 19:52:16 +01:00
|
|
|
virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
|
2013-09-09 04:37:14 +02:00
|
|
|
|
|
|
|
/// \brief Generate the compact unwind encoding for the CFI instructions.
|
2013-09-11 23:47:57 +02:00
|
|
|
virtual uint32_t
|
2014-09-16 11:18:23 +02:00
|
|
|
generateCompactUnwindEncoding(ArrayRef<MCCFIInstruction>) const {
|
2013-09-09 04:37:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-02-21 22:53:53 +01:00
|
|
|
};
|
|
|
|
|
2017-02-08 23:23:19 +01:00
|
|
|
} // end namespace llvm
|
2010-02-21 22:53:53 +01:00
|
|
|
|
2017-02-08 23:23:19 +01:00
|
|
|
#endif // LLVM_MC_MCASMBACKEND_H
|