Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,18 @@
add_llvm_library(LLVMHexagonDesc
HexagonAsmBackend.cpp
HexagonELFObjectWriter.cpp
HexagonInstPrinter.cpp
HexagonMCAsmInfo.cpp
HexagonMCChecker.cpp
HexagonMCCodeEmitter.cpp
HexagonMCCompound.cpp
HexagonMCDuplexInfo.cpp
HexagonMCELFStreamer.cpp
HexagonMCExpr.cpp
HexagonMCInstrInfo.cpp
HexagonMCShuffler.cpp
HexagonMCTargetDesc.cpp
HexagonShuffler.cpp
)
add_dependencies(LLVMHexagonDesc HexagonCommonTableGen)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,288 @@
//===- HexagonBaseInfo.h - Top level definitions for Hexagon ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains small standalone helper functions and enum definitions for
// the Hexagon target useful for the compiler back-end and the MC libraries.
// As such, it deliberately does not include references to LLVM core
// code gen types, passes, etc..
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONBASEINFO_H
#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONBASEINFO_H
#include "HexagonDepITypes.h"
#include "MCTargetDesc/HexagonMCTargetDesc.h"
namespace llvm {
/// HexagonII - This namespace holds all of the target specific flags that
/// instruction info tracks.
namespace HexagonII {
unsigned const TypeCVI_FIRST = TypeCVI_HIST;
unsigned const TypeCVI_LAST = TypeCVI_VX_LATE;
enum SubTarget {
HasV4SubT = 0x3f,
HasV5SubT = 0x3e,
HasV55SubT = 0x3c,
HasV60SubT = 0x38,
};
enum AddrMode {
NoAddrMode = 0, // No addressing mode
Absolute = 1, // Absolute addressing mode
AbsoluteSet = 2, // Absolute set addressing mode
BaseImmOffset = 3, // Indirect with offset
BaseLongOffset = 4, // Indirect with long offset
BaseRegOffset = 5, // Indirect with register offset
PostInc = 6 // Post increment addressing mode
};
enum MemAccessSize {
NoMemAccess = 0,
ByteAccess,
HalfWordAccess,
WordAccess,
DoubleWordAccess,
HVXVectorAccess
};
// MCInstrDesc TSFlags
// *** Must match HexagonInstrFormat*.td ***
enum {
// This 5-bit field describes the insn type.
TypePos = 0,
TypeMask = 0x3f,
// Solo instructions.
SoloPos = 6,
SoloMask = 0x1,
// Packed only with A or X-type instructions.
SoloAXPos = 7,
SoloAXMask = 0x1,
// Only A-type instruction in first slot or nothing.
RestrictSlot1AOKPos = 8,
RestrictSlot1AOKMask = 0x1,
// Predicated instructions.
PredicatedPos = 9,
PredicatedMask = 0x1,
PredicatedFalsePos = 10,
PredicatedFalseMask = 0x1,
PredicatedNewPos = 11,
PredicatedNewMask = 0x1,
PredicateLatePos = 12,
PredicateLateMask = 0x1,
// New-Value consumer instructions.
NewValuePos = 13,
NewValueMask = 0x1,
// New-Value producer instructions.
hasNewValuePos = 14,
hasNewValueMask = 0x1,
// Which operand consumes or produces a new value.
NewValueOpPos = 15,
NewValueOpMask = 0x7,
// Stores that can become new-value stores.
mayNVStorePos = 18,
mayNVStoreMask = 0x1,
// New-value store instructions.
NVStorePos = 19,
NVStoreMask = 0x1,
// Loads that can become current-value loads.
mayCVLoadPos = 20,
mayCVLoadMask = 0x1,
// Current-value load instructions.
CVLoadPos = 21,
CVLoadMask = 0x1,
// Extendable insns.
ExtendablePos = 22,
ExtendableMask = 0x1,
// Insns must be extended.
ExtendedPos = 23,
ExtendedMask = 0x1,
// Which operand may be extended.
ExtendableOpPos = 24,
ExtendableOpMask = 0x7,
// Signed or unsigned range.
ExtentSignedPos = 27,
ExtentSignedMask = 0x1,
// Number of bits of range before extending operand.
ExtentBitsPos = 28,
ExtentBitsMask = 0x1f,
// Alignment power-of-two before extending operand.
ExtentAlignPos = 33,
ExtentAlignMask = 0x3,
CofMax1Pos = 35,
CofMax1Mask = 0x1,
CofRelax1Pos = 36,
CofRelax1Mask = 0x1,
CofRelax2Pos = 37,
CofRelax2Mask = 0x1,
RestrictNoSlot1StorePos = 38,
RestrictNoSlot1StoreMask = 0x1,
// Addressing mode for load/store instructions.
AddrModePos = 41,
AddrModeMask = 0x7,
// Access size for load/store instructions.
MemAccessSizePos = 44,
MemAccesSizeMask = 0xf,
// Branch predicted taken.
TakenPos = 48,
TakenMask = 0x1,
// Floating-point instructions.
FPPos = 49,
FPMask = 0x1,
// New-Value producer-2 instructions.
hasNewValuePos2 = 51,
hasNewValueMask2 = 0x1,
// Which operand consumes or produces a new value.
NewValueOpPos2 = 52,
NewValueOpMask2 = 0x7,
// Accumulator instructions.
AccumulatorPos = 55,
AccumulatorMask = 0x1,
// Complex XU, prevent xu competition by preferring slot3
PrefersSlot3Pos = 56,
PrefersSlot3Mask = 0x1,
// v65
HasTmpDstPos = 59,
HasTmpDstMask = 0x1,
CVINewPos = 61,
CVINewMask = 0x1
};
// *** The code above must match HexagonInstrFormat*.td *** //
// Hexagon specific MO operand flag mask.
enum HexagonMOTargetFlagVal {
// Hexagon-specific MachineOperand target flags.
//
// When chaning these, make sure to update
// getSerializableDirectMachineOperandTargetFlags and
// getSerializableBitmaskMachineOperandTargetFlags if needed.
MO_NO_FLAG,
/// MO_PCREL - On a symbol operand, indicates a PC-relative relocation
/// Used for computing a global address for PIC compilations
MO_PCREL,
/// MO_GOT - Indicates a GOT-relative relocation
MO_GOT,
// Low or high part of a symbol.
MO_LO16, MO_HI16,
// Offset from the base of the SDA.
MO_GPREL,
// MO_GDGOT - indicates GOT relative relocation for TLS
// GeneralDynamic method
MO_GDGOT,
// MO_GDPLT - indicates PLT relative relocation for TLS
// GeneralDynamic method
MO_GDPLT,
// MO_IE - indicates non PIC relocation for TLS
// Initial Executable method
MO_IE,
// MO_IEGOT - indicates PIC relocation for TLS
// Initial Executable method
MO_IEGOT,
// MO_TPREL - indicates relocation for TLS
// local Executable method
MO_TPREL,
// HMOTF_ConstExtended
// Addendum to above, indicates a const extended op
// Can be used as a mask.
HMOTF_ConstExtended = 0x80,
// Union of all bitmasks (currently only HMOTF_ConstExtended).
MO_Bitmasks = HMOTF_ConstExtended
};
// Hexagon Sub-instruction classes.
enum SubInstructionGroup {
HSIG_None = 0,
HSIG_L1,
HSIG_L2,
HSIG_S1,
HSIG_S2,
HSIG_A,
HSIG_Compound
};
// Hexagon Compound classes.
enum CompoundGroup {
HCG_None = 0,
HCG_A,
HCG_B,
HCG_C
};
enum InstParseBits {
INST_PARSE_MASK = 0x0000c000,
INST_PARSE_PACKET_END = 0x0000c000,
INST_PARSE_LOOP_END = 0x00008000,
INST_PARSE_NOT_END = 0x00004000,
INST_PARSE_DUPLEX = 0x00000000,
INST_PARSE_EXTENDER = 0x00000000
};
enum InstIClassBits : unsigned {
INST_ICLASS_MASK = 0xf0000000,
INST_ICLASS_EXTENDER = 0x00000000,
INST_ICLASS_J_1 = 0x10000000,
INST_ICLASS_J_2 = 0x20000000,
INST_ICLASS_LD_ST_1 = 0x30000000,
INST_ICLASS_LD_ST_2 = 0x40000000,
INST_ICLASS_J_3 = 0x50000000,
INST_ICLASS_CR = 0x60000000,
INST_ICLASS_ALU32_1 = 0x70000000,
INST_ICLASS_XTYPE_1 = 0x80000000,
INST_ICLASS_LD = 0x90000000,
INST_ICLASS_ST = 0xa0000000,
INST_ICLASS_ALU32_2 = 0xb0000000,
INST_ICLASS_XTYPE_2 = 0xc0000000,
INST_ICLASS_XTYPE_3 = 0xd0000000,
INST_ICLASS_XTYPE_4 = 0xe0000000,
INST_ICLASS_ALU32_3 = 0xf0000000
};
LLVM_ATTRIBUTE_UNUSED
static unsigned getMemAccessSizeInBytes(MemAccessSize S) {
switch (S) {
case ByteAccess: return 1;
case HalfWordAccess: return 2;
case WordAccess: return 4;
case DoubleWordAccess: return 8;
default: return 0;
}
}
} // end namespace HexagonII
} // end namespace llvm
#endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONBASEINFO_H

View File

@ -0,0 +1,306 @@
//===-- HexagonELFObjectWriter.cpp - Hexagon Target Descriptions ----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Hexagon.h"
#include "MCTargetDesc/HexagonFixupKinds.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCELFObjectWriter.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#define DEBUG_TYPE "hexagon-elf-writer"
using namespace llvm;
using namespace Hexagon;
namespace {
class HexagonELFObjectWriter : public MCELFObjectTargetWriter {
private:
StringRef CPU;
public:
HexagonELFObjectWriter(uint8_t OSABI, StringRef C);
unsigned getRelocType(MCContext &Ctx, MCValue const &Target,
MCFixup const &Fixup, bool IsPCRel) const override;
};
}
HexagonELFObjectWriter::HexagonELFObjectWriter(uint8_t OSABI, StringRef C)
: MCELFObjectTargetWriter(/*Is64bit*/ false, OSABI, ELF::EM_HEXAGON,
/*HasRelocationAddend*/ true),
CPU(C) {}
unsigned HexagonELFObjectWriter::getRelocType(MCContext &Ctx,
MCValue const &Target,
MCFixup const &Fixup,
bool IsPCRel) const {
MCSymbolRefExpr::VariantKind Variant = Target.getAccessVariant();
switch ((unsigned)Fixup.getKind()) {
default:
report_fatal_error("Unrecognized relocation type");
break;
case FK_Data_4:
switch(Variant) {
case MCSymbolRefExpr::VariantKind::VK_DTPREL:
return ELF::R_HEX_DTPREL_32;
case MCSymbolRefExpr::VariantKind::VK_GOT:
return ELF::R_HEX_GOT_32;
case MCSymbolRefExpr::VariantKind::VK_GOTREL:
return ELF::R_HEX_GOTREL_32;
case MCSymbolRefExpr::VariantKind::VK_Hexagon_GD_GOT:
return ELF::R_HEX_GD_GOT_32;
case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE:
return ELF::R_HEX_IE_32;
case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE_GOT:
return ELF::R_HEX_IE_GOT_32;
case MCSymbolRefExpr::VariantKind::VK_Hexagon_LD_GOT:
return ELF::R_HEX_LD_GOT_32;
case MCSymbolRefExpr::VariantKind::VK_Hexagon_PCREL:
return ELF::R_HEX_32_PCREL;
case MCSymbolRefExpr::VariantKind::VK_TPREL:
return ELF::R_HEX_TPREL_32;
case MCSymbolRefExpr::VariantKind::VK_None:
return IsPCRel ? ELF::R_HEX_32_PCREL : ELF::R_HEX_32;
default:
report_fatal_error("Unrecognized variant type");
};
case FK_PCRel_4:
return ELF::R_HEX_32_PCREL;
case FK_Data_2:
switch(Variant) {
case MCSymbolRefExpr::VariantKind::VK_DTPREL:
return ELF::R_HEX_DTPREL_16;
case MCSymbolRefExpr::VariantKind::VK_GOT:
return ELF::R_HEX_GOT_16;
case MCSymbolRefExpr::VariantKind::VK_Hexagon_GD_GOT:
return ELF::R_HEX_GD_GOT_16;
case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE_GOT:
return ELF::R_HEX_IE_GOT_16;
case MCSymbolRefExpr::VariantKind::VK_Hexagon_LD_GOT:
return ELF::R_HEX_LD_GOT_16;
case MCSymbolRefExpr::VariantKind::VK_TPREL:
return ELF::R_HEX_TPREL_16;
case MCSymbolRefExpr::VariantKind::VK_None:
return ELF::R_HEX_16;
default:
report_fatal_error("Unrecognized variant type");
};
case FK_Data_1:
return ELF::R_HEX_8;
case fixup_Hexagon_B22_PCREL:
return ELF::R_HEX_B22_PCREL;
case fixup_Hexagon_B15_PCREL:
return ELF::R_HEX_B15_PCREL;
case fixup_Hexagon_B7_PCREL:
return ELF::R_HEX_B7_PCREL;
case fixup_Hexagon_LO16:
return ELF::R_HEX_LO16;
case fixup_Hexagon_HI16:
return ELF::R_HEX_HI16;
case fixup_Hexagon_32:
return ELF::R_HEX_32;
case fixup_Hexagon_16:
return ELF::R_HEX_16;
case fixup_Hexagon_8:
return ELF::R_HEX_8;
case fixup_Hexagon_GPREL16_0:
return ELF::R_HEX_GPREL16_0;
case fixup_Hexagon_GPREL16_1:
return ELF::R_HEX_GPREL16_1;
case fixup_Hexagon_GPREL16_2:
return ELF::R_HEX_GPREL16_2;
case fixup_Hexagon_GPREL16_3:
return ELF::R_HEX_GPREL16_3;
case fixup_Hexagon_HL16:
return ELF::R_HEX_HL16;
case fixup_Hexagon_B13_PCREL:
return ELF::R_HEX_B13_PCREL;
case fixup_Hexagon_B9_PCREL:
return ELF::R_HEX_B9_PCREL;
case fixup_Hexagon_B32_PCREL_X:
return ELF::R_HEX_B32_PCREL_X;
case fixup_Hexagon_32_6_X:
return ELF::R_HEX_32_6_X;
case fixup_Hexagon_B22_PCREL_X:
return ELF::R_HEX_B22_PCREL_X;
case fixup_Hexagon_B15_PCREL_X:
return ELF::R_HEX_B15_PCREL_X;
case fixup_Hexagon_B13_PCREL_X:
return ELF::R_HEX_B13_PCREL_X;
case fixup_Hexagon_B9_PCREL_X:
return ELF::R_HEX_B9_PCREL_X;
case fixup_Hexagon_B7_PCREL_X:
return ELF::R_HEX_B7_PCREL_X;
case fixup_Hexagon_16_X:
return ELF::R_HEX_16_X;
case fixup_Hexagon_12_X:
return ELF::R_HEX_12_X;
case fixup_Hexagon_11_X:
return ELF::R_HEX_11_X;
case fixup_Hexagon_10_X:
return ELF::R_HEX_10_X;
case fixup_Hexagon_9_X:
return ELF::R_HEX_9_X;
case fixup_Hexagon_8_X:
return ELF::R_HEX_8_X;
case fixup_Hexagon_7_X:
return ELF::R_HEX_7_X;
case fixup_Hexagon_6_X:
return ELF::R_HEX_6_X;
case fixup_Hexagon_32_PCREL:
return ELF::R_HEX_32_PCREL;
case fixup_Hexagon_COPY:
return ELF::R_HEX_COPY;
case fixup_Hexagon_GLOB_DAT:
return ELF::R_HEX_GLOB_DAT;
case fixup_Hexagon_JMP_SLOT:
return ELF::R_HEX_JMP_SLOT;
case fixup_Hexagon_RELATIVE:
return ELF::R_HEX_RELATIVE;
case fixup_Hexagon_PLT_B22_PCREL:
return ELF::R_HEX_PLT_B22_PCREL;
case fixup_Hexagon_GOTREL_LO16:
return ELF::R_HEX_GOTREL_LO16;
case fixup_Hexagon_GOTREL_HI16:
return ELF::R_HEX_GOTREL_HI16;
case fixup_Hexagon_GOTREL_32:
return ELF::R_HEX_GOTREL_32;
case fixup_Hexagon_GOT_LO16:
return ELF::R_HEX_GOT_LO16;
case fixup_Hexagon_GOT_HI16:
return ELF::R_HEX_GOT_HI16;
case fixup_Hexagon_GOT_32:
return ELF::R_HEX_GOT_32;
case fixup_Hexagon_GOT_16:
return ELF::R_HEX_GOT_16;
case fixup_Hexagon_DTPMOD_32:
return ELF::R_HEX_DTPMOD_32;
case fixup_Hexagon_DTPREL_LO16:
return ELF::R_HEX_DTPREL_LO16;
case fixup_Hexagon_DTPREL_HI16:
return ELF::R_HEX_DTPREL_HI16;
case fixup_Hexagon_DTPREL_32:
return ELF::R_HEX_DTPREL_32;
case fixup_Hexagon_DTPREL_16:
return ELF::R_HEX_DTPREL_16;
case fixup_Hexagon_GD_PLT_B22_PCREL:
return ELF::R_HEX_GD_PLT_B22_PCREL;
case fixup_Hexagon_LD_PLT_B22_PCREL:
return ELF::R_HEX_LD_PLT_B22_PCREL;
case fixup_Hexagon_GD_GOT_LO16:
return ELF::R_HEX_GD_GOT_LO16;
case fixup_Hexagon_GD_GOT_HI16:
return ELF::R_HEX_GD_GOT_HI16;
case fixup_Hexagon_GD_GOT_32:
return ELF::R_HEX_GD_GOT_32;
case fixup_Hexagon_GD_GOT_16:
return ELF::R_HEX_GD_GOT_16;
case fixup_Hexagon_LD_GOT_LO16:
return ELF::R_HEX_LD_GOT_LO16;
case fixup_Hexagon_LD_GOT_HI16:
return ELF::R_HEX_LD_GOT_HI16;
case fixup_Hexagon_LD_GOT_32:
return ELF::R_HEX_LD_GOT_32;
case fixup_Hexagon_LD_GOT_16:
return ELF::R_HEX_LD_GOT_16;
case fixup_Hexagon_IE_LO16:
return ELF::R_HEX_IE_LO16;
case fixup_Hexagon_IE_HI16:
return ELF::R_HEX_IE_HI16;
case fixup_Hexagon_IE_32:
return ELF::R_HEX_IE_32;
case fixup_Hexagon_IE_GOT_LO16:
return ELF::R_HEX_IE_GOT_LO16;
case fixup_Hexagon_IE_GOT_HI16:
return ELF::R_HEX_IE_GOT_HI16;
case fixup_Hexagon_IE_GOT_32:
return ELF::R_HEX_IE_GOT_32;
case fixup_Hexagon_IE_GOT_16:
return ELF::R_HEX_IE_GOT_16;
case fixup_Hexagon_TPREL_LO16:
return ELF::R_HEX_TPREL_LO16;
case fixup_Hexagon_TPREL_HI16:
return ELF::R_HEX_TPREL_HI16;
case fixup_Hexagon_TPREL_32:
return ELF::R_HEX_TPREL_32;
case fixup_Hexagon_TPREL_16:
return ELF::R_HEX_TPREL_16;
case fixup_Hexagon_6_PCREL_X:
return ELF::R_HEX_6_PCREL_X;
case fixup_Hexagon_GOTREL_32_6_X:
return ELF::R_HEX_GOTREL_32_6_X;
case fixup_Hexagon_GOTREL_16_X:
return ELF::R_HEX_GOTREL_16_X;
case fixup_Hexagon_GOTREL_11_X:
return ELF::R_HEX_GOTREL_11_X;
case fixup_Hexagon_GOT_32_6_X:
return ELF::R_HEX_GOT_32_6_X;
case fixup_Hexagon_GOT_16_X:
return ELF::R_HEX_GOT_16_X;
case fixup_Hexagon_GOT_11_X:
return ELF::R_HEX_GOT_11_X;
case fixup_Hexagon_DTPREL_32_6_X:
return ELF::R_HEX_DTPREL_32_6_X;
case fixup_Hexagon_DTPREL_16_X:
return ELF::R_HEX_DTPREL_16_X;
case fixup_Hexagon_DTPREL_11_X:
return ELF::R_HEX_DTPREL_11_X;
case fixup_Hexagon_GD_GOT_32_6_X:
return ELF::R_HEX_GD_GOT_32_6_X;
case fixup_Hexagon_GD_GOT_16_X:
return ELF::R_HEX_GD_GOT_16_X;
case fixup_Hexagon_GD_GOT_11_X:
return ELF::R_HEX_GD_GOT_11_X;
case fixup_Hexagon_LD_GOT_32_6_X:
return ELF::R_HEX_LD_GOT_32_6_X;
case fixup_Hexagon_LD_GOT_16_X:
return ELF::R_HEX_LD_GOT_16_X;
case fixup_Hexagon_LD_GOT_11_X:
return ELF::R_HEX_LD_GOT_11_X;
case fixup_Hexagon_IE_32_6_X:
return ELF::R_HEX_IE_32_6_X;
case fixup_Hexagon_IE_16_X:
return ELF::R_HEX_IE_16_X;
case fixup_Hexagon_IE_GOT_32_6_X:
return ELF::R_HEX_IE_GOT_32_6_X;
case fixup_Hexagon_IE_GOT_16_X:
return ELF::R_HEX_IE_GOT_16_X;
case fixup_Hexagon_IE_GOT_11_X:
return ELF::R_HEX_IE_GOT_11_X;
case fixup_Hexagon_TPREL_32_6_X:
return ELF::R_HEX_TPREL_32_6_X;
case fixup_Hexagon_TPREL_16_X:
return ELF::R_HEX_TPREL_16_X;
case fixup_Hexagon_TPREL_11_X:
return ELF::R_HEX_TPREL_11_X;
case fixup_Hexagon_23_REG:
return ELF::R_HEX_23_REG;
case fixup_Hexagon_27_REG:
return ELF::R_HEX_27_REG;
case fixup_Hexagon_GD_PLT_B22_PCREL_X:
return ELF::R_HEX_GD_PLT_B22_PCREL_X;
case fixup_Hexagon_GD_PLT_B32_PCREL_X:
return ELF::R_HEX_GD_PLT_B32_PCREL_X;
case fixup_Hexagon_LD_PLT_B22_PCREL_X:
return ELF::R_HEX_LD_PLT_B22_PCREL_X;
case fixup_Hexagon_LD_PLT_B32_PCREL_X:
return ELF::R_HEX_LD_PLT_B32_PCREL_X;
}
}
std::unique_ptr<MCObjectWriter>
llvm::createHexagonELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI,
StringRef CPU) {
auto MOTW = llvm::make_unique<HexagonELFObjectWriter>(OSABI, CPU);
return createELFObjectWriter(std::move(MOTW), OS, /*IsLittleEndian*/ true);
}

View File

@ -0,0 +1,143 @@
//===-- HexagonFixupKinds.h - Hexagon Specific Fixup Entries --------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_HEXAGON_HEXAGONFIXUPKINDS_H
#define LLVM_HEXAGON_HEXAGONFIXUPKINDS_H
#include "llvm/MC/MCFixup.h"
namespace llvm {
namespace Hexagon {
enum Fixups {
// Branch fixups for R_HEX_B{22,15,7}_PCREL.
fixup_Hexagon_B22_PCREL = FirstTargetFixupKind,
fixup_Hexagon_B15_PCREL,
fixup_Hexagon_B7_PCREL,
fixup_Hexagon_LO16,
fixup_Hexagon_HI16,
fixup_Hexagon_32,
fixup_Hexagon_16,
fixup_Hexagon_8,
fixup_Hexagon_GPREL16_0,
fixup_Hexagon_GPREL16_1,
fixup_Hexagon_GPREL16_2,
fixup_Hexagon_GPREL16_3,
fixup_Hexagon_HL16,
fixup_Hexagon_B13_PCREL,
fixup_Hexagon_B9_PCREL,
fixup_Hexagon_B32_PCREL_X,
fixup_Hexagon_32_6_X,
fixup_Hexagon_B22_PCREL_X,
fixup_Hexagon_B15_PCREL_X,
fixup_Hexagon_B13_PCREL_X,
fixup_Hexagon_B9_PCREL_X,
fixup_Hexagon_B7_PCREL_X,
fixup_Hexagon_16_X,
fixup_Hexagon_12_X,
fixup_Hexagon_11_X,
fixup_Hexagon_10_X,
fixup_Hexagon_9_X,
fixup_Hexagon_8_X,
fixup_Hexagon_7_X,
fixup_Hexagon_6_X,
fixup_Hexagon_32_PCREL,
fixup_Hexagon_COPY,
fixup_Hexagon_GLOB_DAT,
fixup_Hexagon_JMP_SLOT,
fixup_Hexagon_RELATIVE,
fixup_Hexagon_PLT_B22_PCREL,
fixup_Hexagon_GOTREL_LO16,
fixup_Hexagon_GOTREL_HI16,
fixup_Hexagon_GOTREL_32,
fixup_Hexagon_GOT_LO16,
fixup_Hexagon_GOT_HI16,
fixup_Hexagon_GOT_32,
fixup_Hexagon_GOT_16,
fixup_Hexagon_DTPMOD_32,
fixup_Hexagon_DTPREL_LO16,
fixup_Hexagon_DTPREL_HI16,
fixup_Hexagon_DTPREL_32,
fixup_Hexagon_DTPREL_16,
fixup_Hexagon_GD_PLT_B22_PCREL,
fixup_Hexagon_LD_PLT_B22_PCREL,
fixup_Hexagon_GD_GOT_LO16,
fixup_Hexagon_GD_GOT_HI16,
fixup_Hexagon_GD_GOT_32,
fixup_Hexagon_GD_GOT_16,
fixup_Hexagon_LD_GOT_LO16,
fixup_Hexagon_LD_GOT_HI16,
fixup_Hexagon_LD_GOT_32,
fixup_Hexagon_LD_GOT_16,
fixup_Hexagon_IE_LO16,
fixup_Hexagon_IE_HI16,
fixup_Hexagon_IE_32,
fixup_Hexagon_IE_16,
fixup_Hexagon_IE_GOT_LO16,
fixup_Hexagon_IE_GOT_HI16,
fixup_Hexagon_IE_GOT_32,
fixup_Hexagon_IE_GOT_16,
fixup_Hexagon_TPREL_LO16,
fixup_Hexagon_TPREL_HI16,
fixup_Hexagon_TPREL_32,
fixup_Hexagon_TPREL_16,
fixup_Hexagon_6_PCREL_X,
fixup_Hexagon_GOTREL_32_6_X,
fixup_Hexagon_GOTREL_16_X,
fixup_Hexagon_GOTREL_11_X,
fixup_Hexagon_GOT_32_6_X,
fixup_Hexagon_GOT_16_X,
fixup_Hexagon_GOT_11_X,
fixup_Hexagon_DTPREL_32_6_X,
fixup_Hexagon_DTPREL_16_X,
fixup_Hexagon_DTPREL_11_X,
fixup_Hexagon_GD_GOT_32_6_X,
fixup_Hexagon_GD_GOT_16_X,
fixup_Hexagon_GD_GOT_11_X,
fixup_Hexagon_LD_GOT_32_6_X,
fixup_Hexagon_LD_GOT_16_X,
fixup_Hexagon_LD_GOT_11_X,
fixup_Hexagon_IE_32_6_X,
fixup_Hexagon_IE_16_X,
fixup_Hexagon_IE_GOT_32_6_X,
fixup_Hexagon_IE_GOT_16_X,
fixup_Hexagon_IE_GOT_11_X,
fixup_Hexagon_TPREL_32_6_X,
fixup_Hexagon_TPREL_16_X,
fixup_Hexagon_TPREL_11_X,
fixup_Hexagon_23_REG,
fixup_Hexagon_27_REG,
fixup_Hexagon_GD_PLT_B22_PCREL_X,
fixup_Hexagon_GD_PLT_B32_PCREL_X,
fixup_Hexagon_LD_PLT_B22_PCREL_X,
fixup_Hexagon_LD_PLT_B32_PCREL_X,
LastTargetFixupKind,
NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind
};
enum FixupBitmaps : unsigned {
Word8 = 0xff,
Word16 = 0xffff,
Word32 = 0xffffffff,
Word32_LO = 0x00c03fff,
Word32_HL = 0x0, // Not Implemented
Word32_GP = 0x0, // Not Implemented
Word32_B7 = 0x00001f18,
Word32_B9 = 0x003000fe,
Word32_B13 = 0x00202ffe,
Word32_B15 = 0x00df20fe,
Word32_B22 = 0x01ff3ffe,
Word32_R6 = 0x000007e0,
Word32_U6 = 0x0, // Not Implemented
Word32_U16 = 0x0, // Not Implemented
Word32_X26 = 0x0fff3fff
};
} // namespace Hexagon
} // namespace llvm
#endif // LLVM_HEXAGON_HEXAGONFIXUPKINDS_H

View File

@ -0,0 +1,187 @@
//===- HexagonInstPrinter.cpp - Convert Hexagon MCInst to assembly syntax -===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class prints an Hexagon MCInst to a .s file.
//
//===----------------------------------------------------------------------===//
#include "HexagonInstPrinter.h"
#include "HexagonAsmPrinter.h"
#include "MCTargetDesc/HexagonBaseInfo.h"
#include "MCTargetDesc/HexagonMCInstrInfo.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
#define DEBUG_TYPE "asm-printer"
#define GET_INSTRUCTION_NAME
#include "HexagonGenAsmWriter.inc"
HexagonInstPrinter::HexagonInstPrinter(MCAsmInfo const &MAI,
MCInstrInfo const &MII,
MCRegisterInfo const &MRI)
: MCInstPrinter(MAI, MII, MRI), MII(MII), HasExtender(false) {
}
StringRef HexagonInstPrinter::getOpcodeName(unsigned Opcode) const {
return MII.getName(Opcode);
}
void HexagonInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
O << getRegName(RegNo);
}
StringRef HexagonInstPrinter::getRegName(unsigned RegNo) const {
return getRegisterName(RegNo);
}
void HexagonInstPrinter::setExtender(MCInst const &MCI) {
HasExtender = HexagonMCInstrInfo::isImmext(MCI);
}
void HexagonInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
StringRef Annot, const MCSubtargetInfo &STI) {
assert(HexagonMCInstrInfo::isBundle(*MI));
assert(HexagonMCInstrInfo::bundleSize(*MI) <= HEXAGON_PACKET_SIZE);
assert(HexagonMCInstrInfo::bundleSize(*MI) > 0);
HasExtender = false;
for (auto const &I : HexagonMCInstrInfo::bundleInstructions(*MI)) {
MCInst const &MCI = *I.getInst();
if (HexagonMCInstrInfo::isDuplex(MII, MCI)) {
printInstruction(MCI.getOperand(1).getInst(), OS);
OS << '\v';
HasExtender = false;
printInstruction(MCI.getOperand(0).getInst(), OS);
} else
printInstruction(&MCI, OS);
setExtender(MCI);
OS << "\n";
}
auto Separator = "";
if (HexagonMCInstrInfo::isInnerLoop(*MI)) {
OS << Separator;
Separator = " ";
MCInst ME;
ME.setOpcode(Hexagon::ENDLOOP0);
printInstruction(&ME, OS);
}
if (HexagonMCInstrInfo::isOuterLoop(*MI)) {
OS << Separator;
MCInst ME;
ME.setOpcode(Hexagon::ENDLOOP1);
printInstruction(&ME, OS);
}
}
void HexagonInstPrinter::printOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {
if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo &&
(HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI)))
O << "#";
MCOperand const &MO = MI->getOperand(OpNo);
if (MO.isReg()) {
O << getRegisterName(MO.getReg());
} else if (MO.isExpr()) {
int64_t Value;
if (MO.getExpr()->evaluateAsAbsolute(Value))
O << formatImm(Value);
else
O << *MO.getExpr();
} else {
llvm_unreachable("Unknown operand");
}
}
void HexagonInstPrinter::printExtOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {
printOperand(MI, OpNo, O);
}
void HexagonInstPrinter::printUnsignedImmOperand(MCInst const *MI,
unsigned OpNo,
raw_ostream &O) const {
O << MI->getOperand(OpNo).getImm();
}
void HexagonInstPrinter::printNegImmOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {
O << -MI->getOperand(OpNo).getImm();
}
void HexagonInstPrinter::printNOneImmOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {
O << -1;
}
void HexagonInstPrinter::printGlobalOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {
printOperand(MI, OpNo, O);
}
void HexagonInstPrinter::printJumpTable(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {
assert(MI->getOperand(OpNo).isExpr() && "Expecting expression");
printOperand(MI, OpNo, O);
}
void HexagonInstPrinter::printConstantPool(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {
assert(MI->getOperand(OpNo).isExpr() && "Expecting expression");
printOperand(MI, OpNo, O);
}
void HexagonInstPrinter::printBranchOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {
// Branches can take an immediate operand. This is used by the branch
// selection pass to print $+8, an eight byte displacement from the PC.
llvm_unreachable("Unknown branch operand.");
}
void HexagonInstPrinter::printCallOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {}
void HexagonInstPrinter::printAbsAddrOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {}
void HexagonInstPrinter::printPredicateOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {}
void HexagonInstPrinter::printSymbol(MCInst const *MI, unsigned OpNo,
raw_ostream &O, bool hi) const {
assert(MI->getOperand(OpNo).isImm() && "Unknown symbol operand");
O << '#' << (hi ? "HI" : "LO") << '(';
O << '#';
printOperand(MI, OpNo, O);
O << ')';
}
void HexagonInstPrinter::printBrtarget(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const {
MCOperand const &MO = MI->getOperand(OpNo);
assert (MO.isExpr());
MCExpr const &Expr = *MO.getExpr();
int64_t Value;
if (Expr.evaluateAsAbsolute(Value))
O << format("0x%" PRIx64, Value);
else {
if (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI))
if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo)
O << "##";
O << Expr;
}
}

View File

@ -0,0 +1,84 @@
//===-- HexagonInstPrinter.h - Convert Hexagon MCInst to assembly syntax --===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_HEXAGON_INSTPRINTER_HEXAGONINSTPRINTER_H
#define LLVM_LIB_TARGET_HEXAGON_INSTPRINTER_HEXAGONINSTPRINTER_H
#include "llvm/MC/MCInstPrinter.h"
namespace llvm {
/// Prints bundles as a newline separated list of individual instructions
/// Duplexes are separated by a vertical tab \v character
/// A trailing line includes bundle properties such as endloop0/1
///
/// r0 = add(r1, r2)
/// r0 = #0 \v jump 0x0
/// :endloop0 :endloop1
class HexagonInstPrinter : public MCInstPrinter {
public:
explicit HexagonInstPrinter(MCAsmInfo const &MAI, MCInstrInfo const &MII,
MCRegisterInfo const &MRI);
void printInst(MCInst const *MI, raw_ostream &O, StringRef Annot,
const MCSubtargetInfo &STI) override;
virtual StringRef getOpcodeName(unsigned Opcode) const;
void printInstruction(MCInst const *MI, raw_ostream &O);
StringRef getRegName(unsigned RegNo) const;
static char const *getRegisterName(unsigned RegNo);
void printRegName(raw_ostream &O, unsigned RegNo) const override;
void printOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const;
void printExtOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const;
void printUnsignedImmOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const;
void printNegImmOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const;
void printNOneImmOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const;
void printBranchOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const;
void printCallOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const;
void printAbsAddrOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const;
void printPredicateOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const;
void printGlobalOperand(MCInst const *MI, unsigned OpNo,
raw_ostream &O) const;
void printJumpTable(MCInst const *MI, unsigned OpNo, raw_ostream &O) const;
void printBrtarget(MCInst const *MI, unsigned OpNo, raw_ostream &O) const;
void printConstantPool(MCInst const *MI, unsigned OpNo, raw_ostream &O) const;
void printSymbolHi(MCInst const *MI, unsigned OpNo, raw_ostream &O) const {
printSymbol(MI, OpNo, O, true);
}
void printSymbolLo(MCInst const *MI, unsigned OpNo, raw_ostream &O) const {
printSymbol(MI, OpNo, O, false);
}
MCAsmInfo const &getMAI() const { return MAI; }
MCInstrInfo const &getMII() const { return MII; }
protected:
void printSymbol(MCInst const *MI, unsigned OpNo, raw_ostream &O,
bool hi) const;
private:
MCInstrInfo const &MII;
bool HasExtender;
void setExtender(MCInst const &MCI);
};
} // end namespace llvm
#endif

View File

@ -0,0 +1,38 @@
//===-- HexagonMCAsmInfo.cpp - Hexagon asm properties ---------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the declarations of the HexagonMCAsmInfo properties.
//
//===----------------------------------------------------------------------===//
#include "HexagonMCAsmInfo.h"
using namespace llvm;
// Pin the vtable to this file.
void HexagonMCAsmInfo::anchor() {}
HexagonMCAsmInfo::HexagonMCAsmInfo(const Triple &TT) {
Data16bitsDirective = "\t.half\t";
Data32bitsDirective = "\t.word\t";
Data64bitsDirective = nullptr; // .xword is only supported by V9.
CommentString = "//";
SupportsDebugInformation = true;
LCOMMDirectiveAlignmentType = LCOMM::ByteAlignment;
InlineAsmStart = "# InlineAsm Start";
InlineAsmEnd = "# InlineAsm End";
ZeroDirective = "\t.space\t";
AscizDirective = "\t.string\t";
MinInstAlignment = 4;
UsesELFSectionDirectiveForBSS = true;
ExceptionsType = ExceptionHandling::DwarfCFI;
UseLogicalShr = false;
}

View File

@ -0,0 +1,31 @@
//===-- HexagonTargetAsmInfo.h - Hexagon asm properties --------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the declaration of the HexagonMCAsmInfo class.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCASMINFO_H
#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCASMINFO_H
#include "llvm/MC/MCAsmInfoELF.h"
namespace llvm {
class Triple;
class HexagonMCAsmInfo : public MCAsmInfoELF {
void anchor() override;
public:
explicit HexagonMCAsmInfo(const Triple &TT);
};
} // namespace llvm
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,130 @@
//===- HexagonMCChecker.h - Instruction bundle checking ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This implements the checking of insns inside a bundle according to the
// packet constraint rules of the Hexagon ISA.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCHECKER_H
#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCHECKER_H
#include "MCTargetDesc/HexagonMCInstrInfo.h"
#include "MCTargetDesc/HexagonMCTargetDesc.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/SMLoc.h"
#include <set>
#include <utility>
namespace llvm {
class MCContext;
class MCInst;
class MCInstrInfo;
class MCRegisterInfo;
class MCSubtargetInfo;
/// Check for a valid bundle.
class HexagonMCChecker {
MCContext &Context;
MCInst &MCB;
const MCRegisterInfo &RI;
MCInstrInfo const &MCII;
MCSubtargetInfo const &STI;
bool ReportErrors;
/// Set of definitions: register #, if predicated, if predicated true.
using PredSense = std::pair<unsigned, bool>;
static const PredSense Unconditional;
using PredSet = std::multiset<PredSense>;
using PredSetIterator = std::multiset<PredSense>::iterator;
using DefsIterator = DenseMap<unsigned, PredSet>::iterator;
DenseMap<unsigned, PredSet> Defs;
/// Set of weak definitions whose clashes should be enforced selectively.
using SoftDefsIterator = std::set<unsigned>::iterator;
std::set<unsigned> SoftDefs;
/// Set of temporary definitions not committed to the register file.
using TmpDefsIterator = std::set<unsigned>::iterator;
std::set<unsigned> TmpDefs;
/// Set of new predicates used.
using NewPredsIterator = std::set<unsigned>::iterator;
std::set<unsigned> NewPreds;
/// Set of predicates defined late.
using LatePredsIterator = std::multiset<unsigned>::iterator;
std::multiset<unsigned> LatePreds;
/// Set of uses.
using UsesIterator = std::set<unsigned>::iterator;
std::set<unsigned> Uses;
/// Pre-defined set of read-only registers.
using ReadOnlyIterator = std::set<unsigned>::iterator;
std::set<unsigned> ReadOnly;
void init();
void init(MCInst const &);
void initReg(MCInst const &, unsigned, unsigned &PredReg, bool &isTrue);
bool registerUsed(unsigned Register);
std::tuple<MCInst const *, unsigned, HexagonMCInstrInfo::PredicateInfo>
registerProducer(unsigned Register,
HexagonMCInstrInfo::PredicateInfo Predicated);
// Checks performed.
bool checkBranches();
bool checkPredicates();
bool checkNewValues();
bool checkRegisters();
bool checkRegistersReadOnly();
void checkRegisterCurDefs();
bool checkSolo();
bool checkShuffle();
bool checkSlots();
bool checkAXOK();
bool checkHWLoop();
bool checkCOFMax1();
static void compoundRegisterMap(unsigned &);
bool isPredicateRegister(unsigned R) const {
return (Hexagon::P0 == R || Hexagon::P1 == R || Hexagon::P2 == R ||
Hexagon::P3 == R);
}
bool isLoopRegister(unsigned R) const {
return (Hexagon::SA0 == R || Hexagon::LC0 == R || Hexagon::SA1 == R ||
Hexagon::LC1 == R);
}
public:
explicit HexagonMCChecker(MCContext &Context, MCInstrInfo const &MCII,
MCSubtargetInfo const &STI, MCInst &mcb,
const MCRegisterInfo &ri, bool ReportErrors = true);
explicit HexagonMCChecker(HexagonMCChecker const &Check,
MCSubtargetInfo const &STI, bool CopyReportErrors);
bool check(bool FullCheck = true);
void reportErrorRegisters(unsigned Register);
void reportErrorNewValue(unsigned Register);
void reportError(SMLoc Loc, Twine const &Msg);
void reportNote(SMLoc Loc, Twine const &Msg);
void reportError(Twine const &Msg);
void reportWarning(Twine const &Msg);
void reportBranchErrors();
};
} // end namespace llvm
#endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCHECKER_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,86 @@
//===- HexagonMCCodeEmitter.h - Hexagon Target Descriptions -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief Definition for classes that emit Hexagon machine code from MCInsts
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCODEEMITTER_H
#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCODEEMITTER_H
#include "MCTargetDesc/HexagonFixupKinds.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/SubtargetFeature.h"
#include <cstddef>
#include <cstdint>
#include <memory>
namespace llvm {
class MCContext;
class MCInst;
class MCInstrInfo;
class MCOperand;
class MCSubtargetInfo;
class raw_ostream;
class HexagonMCCodeEmitter : public MCCodeEmitter {
MCContext &MCT;
MCInstrInfo const &MCII;
std::unique_ptr<unsigned> Addend;
std::unique_ptr<bool> Extended;
std::unique_ptr<MCInst const *> CurrentBundle;
std::unique_ptr<size_t> CurrentIndex;
// 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;
public:
HexagonMCCodeEmitter(MCInstrInfo const &aMII, MCContext &aMCT);
// Return parse bits for instruction `MCI' inside bundle `MCB'
uint32_t parseBits(size_t Last, MCInst const &MCB, MCInst const &MCI) const;
void encodeInstruction(MCInst const &MI, raw_ostream &OS,
SmallVectorImpl<MCFixup> &Fixups,
MCSubtargetInfo const &STI) const override;
void EncodeSingleInstruction(const MCInst &MI, raw_ostream &OS,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI,
uint32_t Parse) const;
// \brief TableGen'erated function for getting the
// binary encoding for an instruction.
uint64_t getBinaryCodeForInstr(MCInst const &MI,
SmallVectorImpl<MCFixup> &Fixups,
MCSubtargetInfo const &STI) const;
/// \brief Return binary encoding of operand.
unsigned getMachineOpValue(MCInst const &MI, MCOperand const &MO,
SmallVectorImpl<MCFixup> &Fixups,
MCSubtargetInfo const &STI) const;
private:
uint64_t computeAvailableFeatures(const FeatureBitset &FB) const;
void verifyInstructionPredicates(const MCInst &MI,
uint64_t AvailableFeatures) const;
};
} // end namespace llvm
#endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCODEEMITTER_H

View File

@ -0,0 +1,429 @@
//=== HexagonMCCompound.cpp - Hexagon Compound checker -------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is looks at a packet and tries to form compound insns
//
//===----------------------------------------------------------------------===//
#include "Hexagon.h"
#include "MCTargetDesc/HexagonBaseInfo.h"
#include "MCTargetDesc/HexagonMCInstrInfo.h"
#include "MCTargetDesc/HexagonMCShuffler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInst.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
using namespace llvm;
using namespace Hexagon;
#define DEBUG_TYPE "hexagon-mccompound"
enum OpcodeIndex {
fp0_jump_nt = 0,
fp0_jump_t,
fp1_jump_nt,
fp1_jump_t,
tp0_jump_nt,
tp0_jump_t,
tp1_jump_nt,
tp1_jump_t
};
static const unsigned tstBitOpcode[8] = {
J4_tstbit0_fp0_jump_nt, J4_tstbit0_fp0_jump_t, J4_tstbit0_fp1_jump_nt,
J4_tstbit0_fp1_jump_t, J4_tstbit0_tp0_jump_nt, J4_tstbit0_tp0_jump_t,
J4_tstbit0_tp1_jump_nt, J4_tstbit0_tp1_jump_t};
static const unsigned cmpeqBitOpcode[8] = {
J4_cmpeq_fp0_jump_nt, J4_cmpeq_fp0_jump_t, J4_cmpeq_fp1_jump_nt,
J4_cmpeq_fp1_jump_t, J4_cmpeq_tp0_jump_nt, J4_cmpeq_tp0_jump_t,
J4_cmpeq_tp1_jump_nt, J4_cmpeq_tp1_jump_t};
static const unsigned cmpgtBitOpcode[8] = {
J4_cmpgt_fp0_jump_nt, J4_cmpgt_fp0_jump_t, J4_cmpgt_fp1_jump_nt,
J4_cmpgt_fp1_jump_t, J4_cmpgt_tp0_jump_nt, J4_cmpgt_tp0_jump_t,
J4_cmpgt_tp1_jump_nt, J4_cmpgt_tp1_jump_t};
static const unsigned cmpgtuBitOpcode[8] = {
J4_cmpgtu_fp0_jump_nt, J4_cmpgtu_fp0_jump_t, J4_cmpgtu_fp1_jump_nt,
J4_cmpgtu_fp1_jump_t, J4_cmpgtu_tp0_jump_nt, J4_cmpgtu_tp0_jump_t,
J4_cmpgtu_tp1_jump_nt, J4_cmpgtu_tp1_jump_t};
static const unsigned cmpeqiBitOpcode[8] = {
J4_cmpeqi_fp0_jump_nt, J4_cmpeqi_fp0_jump_t, J4_cmpeqi_fp1_jump_nt,
J4_cmpeqi_fp1_jump_t, J4_cmpeqi_tp0_jump_nt, J4_cmpeqi_tp0_jump_t,
J4_cmpeqi_tp1_jump_nt, J4_cmpeqi_tp1_jump_t};
static const unsigned cmpgtiBitOpcode[8] = {
J4_cmpgti_fp0_jump_nt, J4_cmpgti_fp0_jump_t, J4_cmpgti_fp1_jump_nt,
J4_cmpgti_fp1_jump_t, J4_cmpgti_tp0_jump_nt, J4_cmpgti_tp0_jump_t,
J4_cmpgti_tp1_jump_nt, J4_cmpgti_tp1_jump_t};
static const unsigned cmpgtuiBitOpcode[8] = {
J4_cmpgtui_fp0_jump_nt, J4_cmpgtui_fp0_jump_t, J4_cmpgtui_fp1_jump_nt,
J4_cmpgtui_fp1_jump_t, J4_cmpgtui_tp0_jump_nt, J4_cmpgtui_tp0_jump_t,
J4_cmpgtui_tp1_jump_nt, J4_cmpgtui_tp1_jump_t};
static const unsigned cmpeqn1BitOpcode[8] = {
J4_cmpeqn1_fp0_jump_nt, J4_cmpeqn1_fp0_jump_t, J4_cmpeqn1_fp1_jump_nt,
J4_cmpeqn1_fp1_jump_t, J4_cmpeqn1_tp0_jump_nt, J4_cmpeqn1_tp0_jump_t,
J4_cmpeqn1_tp1_jump_nt, J4_cmpeqn1_tp1_jump_t};
static const unsigned cmpgtn1BitOpcode[8] = {
J4_cmpgtn1_fp0_jump_nt, J4_cmpgtn1_fp0_jump_t, J4_cmpgtn1_fp1_jump_nt,
J4_cmpgtn1_fp1_jump_t, J4_cmpgtn1_tp0_jump_nt, J4_cmpgtn1_tp0_jump_t,
J4_cmpgtn1_tp1_jump_nt, J4_cmpgtn1_tp1_jump_t,
};
// enum HexagonII::CompoundGroup
static unsigned getCompoundCandidateGroup(MCInst const &MI, bool IsExtended) {
unsigned DstReg, SrcReg, Src1Reg, Src2Reg;
switch (MI.getOpcode()) {
default:
return HexagonII::HCG_None;
//
// Compound pairs.
// "p0=cmp.eq(Rs16,Rt16); if (p0.new) jump:nt #r9:2"
// "Rd16=#U6 ; jump #r9:2"
// "Rd16=Rs16 ; jump #r9:2"
//
case Hexagon::C2_cmpeq:
case Hexagon::C2_cmpgt:
case Hexagon::C2_cmpgtu:
if (IsExtended)
return false;
DstReg = MI.getOperand(0).getReg();
Src1Reg = MI.getOperand(1).getReg();
Src2Reg = MI.getOperand(2).getReg();
if ((Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(Src1Reg) &&
HexagonMCInstrInfo::isIntRegForSubInst(Src2Reg))
return HexagonII::HCG_A;
break;
case Hexagon::C2_cmpeqi:
case Hexagon::C2_cmpgti:
case Hexagon::C2_cmpgtui:
if (IsExtended)
return false;
// P0 = cmp.eq(Rs,#u2)
DstReg = MI.getOperand(0).getReg();
SrcReg = MI.getOperand(1).getReg();
if ((Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
(HexagonMCInstrInfo::inRange<5>(MI, 2) ||
HexagonMCInstrInfo::minConstant(MI, 2) == -1))
return HexagonII::HCG_A;
break;
case Hexagon::A2_tfr:
if (IsExtended)
return false;
// Rd = Rs
DstReg = MI.getOperand(0).getReg();
SrcReg = MI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg))
return HexagonII::HCG_A;
break;
case Hexagon::A2_tfrsi:
if (IsExtended)
return false;
// Rd = #u6
DstReg = MI.getOperand(0).getReg();
if (HexagonMCInstrInfo::minConstant(MI, 1) <= 63 &&
HexagonMCInstrInfo::minConstant(MI, 1) >= 0 &&
HexagonMCInstrInfo::isIntRegForSubInst(DstReg))
return HexagonII::HCG_A;
break;
case Hexagon::S2_tstbit_i:
if (IsExtended)
return false;
DstReg = MI.getOperand(0).getReg();
Src1Reg = MI.getOperand(1).getReg();
if ((Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(Src1Reg) &&
HexagonMCInstrInfo::minConstant(MI, 2) == 0)
return HexagonII::HCG_A;
break;
// The fact that .new form is used pretty much guarantees
// that predicate register will match. Nevertheless,
// there could be some false positives without additional
// checking.
case Hexagon::J2_jumptnew:
case Hexagon::J2_jumpfnew:
case Hexagon::J2_jumptnewpt:
case Hexagon::J2_jumpfnewpt:
Src1Reg = MI.getOperand(0).getReg();
if (Hexagon::P0 == Src1Reg || Hexagon::P1 == Src1Reg)
return HexagonII::HCG_B;
break;
// Transfer and jump:
// Rd=#U6 ; jump #r9:2
// Rd=Rs ; jump #r9:2
// Do not test for jump range here.
case Hexagon::J2_jump:
case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
return HexagonII::HCG_C;
break;
}
return HexagonII::HCG_None;
}
/// getCompoundOp - Return the index from 0-7 into the above opcode lists.
static unsigned getCompoundOp(MCInst const &HMCI) {
const MCOperand &Predicate = HMCI.getOperand(0);
unsigned PredReg = Predicate.getReg();
assert((PredReg == Hexagon::P0) || (PredReg == Hexagon::P1) ||
(PredReg == Hexagon::P2) || (PredReg == Hexagon::P3));
switch (HMCI.getOpcode()) {
default:
llvm_unreachable("Expected match not found.\n");
break;
case Hexagon::J2_jumpfnew:
return (PredReg == Hexagon::P0) ? fp0_jump_nt : fp1_jump_nt;
case Hexagon::J2_jumpfnewpt:
return (PredReg == Hexagon::P0) ? fp0_jump_t : fp1_jump_t;
case Hexagon::J2_jumptnew:
return (PredReg == Hexagon::P0) ? tp0_jump_nt : tp1_jump_nt;
case Hexagon::J2_jumptnewpt:
return (PredReg == Hexagon::P0) ? tp0_jump_t : tp1_jump_t;
}
}
static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
MCInst const &R) {
MCInst *CompoundInsn = nullptr;
unsigned compoundOpcode;
MCOperand Rs, Rt;
int64_t Value;
bool Success;
switch (L.getOpcode()) {
default:
DEBUG(dbgs() << "Possible compound ignored\n");
return CompoundInsn;
case Hexagon::A2_tfrsi:
Rt = L.getOperand(0);
compoundOpcode = J4_jumpseti;
CompoundInsn = new (Context) MCInst;
CompoundInsn->setOpcode(compoundOpcode);
CompoundInsn->addOperand(Rt);
CompoundInsn->addOperand(L.getOperand(1)); // Immediate
CompoundInsn->addOperand(R.getOperand(0)); // Jump target
break;
case Hexagon::A2_tfr:
Rt = L.getOperand(0);
Rs = L.getOperand(1);
compoundOpcode = J4_jumpsetr;
CompoundInsn = new (Context) MCInst;
CompoundInsn->setOpcode(compoundOpcode);
CompoundInsn->addOperand(Rt);
CompoundInsn->addOperand(Rs);
CompoundInsn->addOperand(R.getOperand(0)); // Jump target.
break;
case Hexagon::C2_cmpeq:
DEBUG(dbgs() << "CX: C2_cmpeq\n");
Rs = L.getOperand(1);
Rt = L.getOperand(2);
compoundOpcode = cmpeqBitOpcode[getCompoundOp(R)];
CompoundInsn = new (Context) MCInst;
CompoundInsn->setOpcode(compoundOpcode);
CompoundInsn->addOperand(Rs);
CompoundInsn->addOperand(Rt);
CompoundInsn->addOperand(R.getOperand(1));
break;
case Hexagon::C2_cmpgt:
DEBUG(dbgs() << "CX: C2_cmpgt\n");
Rs = L.getOperand(1);
Rt = L.getOperand(2);
compoundOpcode = cmpgtBitOpcode[getCompoundOp(R)];
CompoundInsn = new (Context) MCInst;
CompoundInsn->setOpcode(compoundOpcode);
CompoundInsn->addOperand(Rs);
CompoundInsn->addOperand(Rt);
CompoundInsn->addOperand(R.getOperand(1));
break;
case Hexagon::C2_cmpgtu:
DEBUG(dbgs() << "CX: C2_cmpgtu\n");
Rs = L.getOperand(1);
Rt = L.getOperand(2);
compoundOpcode = cmpgtuBitOpcode[getCompoundOp(R)];
CompoundInsn = new (Context) MCInst;
CompoundInsn->setOpcode(compoundOpcode);
CompoundInsn->addOperand(Rs);
CompoundInsn->addOperand(Rt);
CompoundInsn->addOperand(R.getOperand(1));
break;
case Hexagon::C2_cmpeqi:
DEBUG(dbgs() << "CX: C2_cmpeqi\n");
Success = L.getOperand(2).getExpr()->evaluateAsAbsolute(Value);
(void)Success;
assert(Success);
if (Value == -1)
compoundOpcode = cmpeqn1BitOpcode[getCompoundOp(R)];
else
compoundOpcode = cmpeqiBitOpcode[getCompoundOp(R)];
Rs = L.getOperand(1);
CompoundInsn = new (Context) MCInst;
CompoundInsn->setOpcode(compoundOpcode);
CompoundInsn->addOperand(Rs);
CompoundInsn->addOperand(L.getOperand(2));
CompoundInsn->addOperand(R.getOperand(1));
break;
case Hexagon::C2_cmpgti:
DEBUG(dbgs() << "CX: C2_cmpgti\n");
Success = L.getOperand(2).getExpr()->evaluateAsAbsolute(Value);
(void)Success;
assert(Success);
if (Value == -1)
compoundOpcode = cmpgtn1BitOpcode[getCompoundOp(R)];
else
compoundOpcode = cmpgtiBitOpcode[getCompoundOp(R)];
Rs = L.getOperand(1);
CompoundInsn = new (Context) MCInst;
CompoundInsn->setOpcode(compoundOpcode);
CompoundInsn->addOperand(Rs);
CompoundInsn->addOperand(L.getOperand(2));
CompoundInsn->addOperand(R.getOperand(1));
break;
case Hexagon::C2_cmpgtui:
DEBUG(dbgs() << "CX: C2_cmpgtui\n");
Rs = L.getOperand(1);
compoundOpcode = cmpgtuiBitOpcode[getCompoundOp(R)];
CompoundInsn = new (Context) MCInst;
CompoundInsn->setOpcode(compoundOpcode);
CompoundInsn->addOperand(Rs);
CompoundInsn->addOperand(L.getOperand(2));
CompoundInsn->addOperand(R.getOperand(1));
break;
case Hexagon::S2_tstbit_i:
DEBUG(dbgs() << "CX: S2_tstbit_i\n");
Rs = L.getOperand(1);
compoundOpcode = tstBitOpcode[getCompoundOp(R)];
CompoundInsn = new (Context) MCInst;
CompoundInsn->setOpcode(compoundOpcode);
CompoundInsn->addOperand(Rs);
CompoundInsn->addOperand(R.getOperand(1));
break;
}
return CompoundInsn;
}
/// Non-Symmetrical. See if these two instructions are fit for compound pair.
static bool isOrderedCompoundPair(MCInst const &MIa, bool IsExtendedA,
MCInst const &MIb, bool IsExtendedB) {
unsigned MIaG = getCompoundCandidateGroup(MIa, IsExtendedA);
unsigned MIbG = getCompoundCandidateGroup(MIb, IsExtendedB);
// We have two candidates - check that this is the same register
// we are talking about.
unsigned Opca = MIa.getOpcode();
if (MIaG == HexagonII::HCG_A && MIbG == HexagonII::HCG_C &&
(Opca == Hexagon::A2_tfr || Opca == Hexagon::A2_tfrsi))
return true;
return ((MIaG == HexagonII::HCG_A && MIbG == HexagonII::HCG_B) &&
(MIa.getOperand(0).getReg() == MIb.getOperand(0).getReg()));
}
static bool lookForCompound(MCInstrInfo const &MCII, MCContext &Context,
MCInst &MCI) {
assert(HexagonMCInstrInfo::isBundle(MCI));
bool JExtended = false;
for (MCInst::iterator J =
MCI.begin() + HexagonMCInstrInfo::bundleInstructionsOffset;
J != MCI.end(); ++J) {
MCInst const *JumpInst = J->getInst();
if (HexagonMCInstrInfo::isImmext(*JumpInst)) {
JExtended = true;
continue;
}
if (HexagonMCInstrInfo::getType(MCII, *JumpInst) == HexagonII::TypeJ) {
// Try to pair with another insn (B)undled with jump.
bool BExtended = false;
for (MCInst::iterator B =
MCI.begin() + HexagonMCInstrInfo::bundleInstructionsOffset;
B != MCI.end(); ++B) {
MCInst const *Inst = B->getInst();
if (JumpInst == Inst)
continue;
if (HexagonMCInstrInfo::isImmext(*Inst)) {
BExtended = true;
continue;
}
DEBUG(dbgs() << "J,B: " << JumpInst->getOpcode() << ","
<< Inst->getOpcode() << "\n");
if (isOrderedCompoundPair(*Inst, BExtended, *JumpInst, JExtended)) {
MCInst *CompoundInsn = getCompoundInsn(Context, *Inst, *JumpInst);
if (CompoundInsn) {
DEBUG(dbgs() << "B: " << Inst->getOpcode() << ","
<< JumpInst->getOpcode() << " Compounds to "
<< CompoundInsn->getOpcode() << "\n");
J->setInst(CompoundInsn);
MCI.erase(B);
return true;
}
}
BExtended = false;
}
}
JExtended = false;
}
return false;
}
/// tryCompound - Given a bundle check for compound insns when one
/// is found update the contents fo the bundle with the compound insn.
/// If a compound instruction is found then the bundle will have one
/// additional slot.
void HexagonMCInstrInfo::tryCompound(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
MCContext &Context, MCInst &MCI) {
assert(HexagonMCInstrInfo::isBundle(MCI) &&
"Non-Bundle where Bundle expected");
// By definition a compound must have 2 insn.
if (MCI.size() < 2)
return;
bool StartedValid = llvm::HexagonMCShuffle(Context, false, MCII, STI, MCI);
// Create a vector, needed to keep the order of jump instructions.
MCInst CheckList(MCI);
// Look for compounds until none are found, only update the bundle when
// a compound is found.
while (lookForCompound(MCII, Context, CheckList)) {
// Keep the original bundle around in case the shuffle fails.
MCInst OriginalBundle(MCI);
// Need to update the bundle.
MCI = CheckList;
if (StartedValid &&
!llvm::HexagonMCShuffle(Context, false, MCII, STI, MCI)) {
DEBUG(dbgs() << "Found ERROR\n");
MCI = OriginalBundle;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,174 @@
//=== HexagonMCELFStreamer.cpp - Hexagon subclass of MCELFStreamer -------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a stub that parses a MCInst bundle and passes the
// instructions on to the real streamer.
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "hexagonmcelfstreamer"
#include "MCTargetDesc/HexagonMCELFStreamer.h"
#include "MCTargetDesc/HexagonMCInstrInfo.h"
#include "MCTargetDesc/HexagonMCShuffler.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
#include <cstdint>
using namespace llvm;
static cl::opt<unsigned> GPSize
("gpsize", cl::NotHidden,
cl::desc("Global Pointer Addressing Size. The default size is 8."),
cl::Prefix,
cl::init(8));
HexagonMCELFStreamer::HexagonMCELFStreamer(
MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
raw_pwrite_stream &OS, std::unique_ptr<MCCodeEmitter> Emitter)
: MCELFStreamer(Context, std::move(TAB), OS, std::move(Emitter)),
MCII(createHexagonMCInstrInfo()) {}
HexagonMCELFStreamer::HexagonMCELFStreamer(
MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
raw_pwrite_stream &OS, std::unique_ptr<MCCodeEmitter> Emitter,
MCAssembler *Assembler)
: MCELFStreamer(Context, std::move(TAB), OS, std::move(Emitter)),
MCII(createHexagonMCInstrInfo()) {}
void HexagonMCELFStreamer::EmitInstruction(const MCInst &MCB,
const MCSubtargetInfo &STI, bool) {
assert(MCB.getOpcode() == Hexagon::BUNDLE);
assert(HexagonMCInstrInfo::bundleSize(MCB) <= HEXAGON_PACKET_SIZE);
assert(HexagonMCInstrInfo::bundleSize(MCB) > 0);
bool Extended = false;
for (auto &I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
MCInst *MCI = const_cast<MCInst *>(I.getInst());
if (Extended) {
if (HexagonMCInstrInfo::isDuplex(*MCII, *MCI)) {
MCInst *SubInst = const_cast<MCInst *>(MCI->getOperand(1).getInst());
HexagonMCInstrInfo::clampExtended(*MCII, getContext(), *SubInst);
} else {
HexagonMCInstrInfo::clampExtended(*MCII, getContext(), *MCI);
}
Extended = false;
} else {
Extended = HexagonMCInstrInfo::isImmext(*MCI);
}
}
// At this point, MCB is a bundle
// Iterate through the bundle and assign addends for the instructions
for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
MCInst *MCI = const_cast<MCInst *>(I.getInst());
EmitSymbol(*MCI);
}
MCObjectStreamer::EmitInstruction(MCB, STI);
}
void HexagonMCELFStreamer::EmitSymbol(const MCInst &Inst) {
// Scan for values.
for (unsigned i = Inst.getNumOperands(); i--;)
if (Inst.getOperand(i).isExpr())
visitUsedExpr(*Inst.getOperand(i).getExpr());
}
// EmitCommonSymbol and EmitLocalCommonSymbol are extended versions of the
// functions found in MCELFStreamer.cpp taking AccessSize as an additional
// parameter.
void HexagonMCELFStreamer::HexagonMCEmitCommonSymbol(MCSymbol *Symbol,
uint64_t Size,
unsigned ByteAlignment,
unsigned AccessSize) {
getAssembler().registerSymbol(*Symbol);
StringRef sbss[4] = {".sbss.1", ".sbss.2", ".sbss.4", ".sbss.8"};
auto ELFSymbol = cast<MCSymbolELF>(Symbol);
if (!ELFSymbol->isBindingSet()) {
ELFSymbol->setBinding(ELF::STB_GLOBAL);
ELFSymbol->setExternal(true);
}
ELFSymbol->setType(ELF::STT_OBJECT);
if (ELFSymbol->getBinding() == ELF::STB_LOCAL) {
StringRef SectionName =
((AccessSize == 0) || (Size == 0) || (Size > GPSize))
? ".bss"
: sbss[(Log2_64(AccessSize))];
MCSection &Section = *getAssembler().getContext().getELFSection(
SectionName, ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
MCSectionSubPair P = getCurrentSection();
SwitchSection(&Section);
if (ELFSymbol->isUndefined(false)) {
EmitValueToAlignment(ByteAlignment, 0, 1, 0);
EmitLabel(Symbol);
EmitZeros(Size);
}
// Update the maximum alignment of the section if necessary.
if (ByteAlignment > Section.getAlignment())
Section.setAlignment(ByteAlignment);
SwitchSection(P.first, P.second);
} else {
if (ELFSymbol->declareCommon(Size, ByteAlignment))
report_fatal_error("Symbol: " + Symbol->getName() +
" redeclared as different type");
if ((AccessSize) && (Size <= GPSize)) {
uint64_t SectionIndex =
(AccessSize <= GPSize)
? ELF::SHN_HEXAGON_SCOMMON + (Log2_64(AccessSize) + 1)
: (unsigned)ELF::SHN_HEXAGON_SCOMMON;
ELFSymbol->setIndex(SectionIndex);
}
}
ELFSymbol->setSize(MCConstantExpr::create(Size, getContext()));
}
void HexagonMCELFStreamer::HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol,
uint64_t Size,
unsigned ByteAlignment,
unsigned AccessSize) {
getAssembler().registerSymbol(*Symbol);
auto ELFSymbol = cast<MCSymbolELF>(Symbol);
ELFSymbol->setBinding(ELF::STB_LOCAL);
ELFSymbol->setExternal(false);
HexagonMCEmitCommonSymbol(Symbol, Size, ByteAlignment, AccessSize);
}
namespace llvm {
MCStreamer *createHexagonELFStreamer(Triple const &TT, MCContext &Context,
std::unique_ptr<MCAsmBackend> MAB,
raw_pwrite_stream &OS,
std::unique_ptr<MCCodeEmitter> CE) {
return new HexagonMCELFStreamer(Context, std::move(MAB), OS, std::move(CE));
}
} // end namespace llvm

View File

@ -0,0 +1,51 @@
//===- HexagonMCELFStreamer.h - Hexagon subclass of MCElfStreamer ---------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCELFSTREAMER_H
#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCELFSTREAMER_H
#include "MCTargetDesc/HexagonMCTargetDesc.h"
#include "llvm/MC/MCELFStreamer.h"
#include "llvm/MC/MCInstrInfo.h"
#include <cstdint>
#include <memory>
namespace llvm {
class HexagonMCELFStreamer : public MCELFStreamer {
std::unique_ptr<MCInstrInfo> MCII;
public:
HexagonMCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
raw_pwrite_stream &OS,
std::unique_ptr<MCCodeEmitter> Emitter);
HexagonMCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
raw_pwrite_stream &OS,
std::unique_ptr<MCCodeEmitter> Emitter,
MCAssembler *Assembler);
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
bool) override;
void EmitSymbol(const MCInst &Inst);
void HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment,
unsigned AccessSize);
void HexagonMCEmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment, unsigned AccessSize);
};
MCStreamer *createHexagonELFStreamer(Triple const &TT, MCContext &Context,
std::unique_ptr<MCAsmBackend> MAB,
raw_pwrite_stream &OS,
std::unique_ptr<MCCodeEmitter> CE);
} // end namespace llvm
#endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCELFSTREAMER_H

View File

@ -0,0 +1,120 @@
//===-- HexagonMCExpr.cpp - Hexagon specific MC expression classes
//----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "HexagonMCExpr.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
#define DEBUG_TYPE "hexagon-mcexpr"
HexagonMCExpr *HexagonMCExpr::create(MCExpr const *Expr, MCContext &Ctx) {
return new (Ctx) HexagonMCExpr(Expr);
}
bool HexagonMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
MCAsmLayout const *Layout,
MCFixup const *Fixup) const {
return Expr->evaluateAsRelocatable(Res, Layout, Fixup);
}
void HexagonMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
Streamer.visitUsedExpr(*Expr);
}
MCFragment *llvm::HexagonMCExpr::findAssociatedFragment() const {
return Expr->findAssociatedFragment();
}
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
switch (Expr->getKind()) {
case MCExpr::Target:
llvm_unreachable("Cannot handle nested target MCExpr");
break;
case MCExpr::Constant:
break;
case MCExpr::Binary: {
const MCBinaryExpr *be = cast<MCBinaryExpr>(Expr);
fixELFSymbolsInTLSFixupsImpl(be->getLHS(), Asm);
fixELFSymbolsInTLSFixupsImpl(be->getRHS(), Asm);
break;
}
case MCExpr::SymbolRef: {
const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(Expr);
switch (symRef.getKind()) {
default:
return;
case MCSymbolRefExpr::VK_Hexagon_GD_GOT:
case MCSymbolRefExpr::VK_Hexagon_LD_GOT:
case MCSymbolRefExpr::VK_Hexagon_GD_PLT:
case MCSymbolRefExpr::VK_Hexagon_LD_PLT:
case MCSymbolRefExpr::VK_Hexagon_IE:
case MCSymbolRefExpr::VK_Hexagon_IE_GOT:
case MCSymbolRefExpr::VK_TPREL:
break;
}
cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
break;
}
case MCExpr::Unary:
fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
break;
}
}
void HexagonMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
auto expr = getExpr();
fixELFSymbolsInTLSFixupsImpl(expr, Asm);
}
MCExpr const *HexagonMCExpr::getExpr() const { return Expr; }
void HexagonMCExpr::setMustExtend(bool Val) {
assert((!Val || !MustNotExtend) && "Extension contradiction");
MustExtend = Val;
}
bool HexagonMCExpr::mustExtend() const { return MustExtend; }
void HexagonMCExpr::setMustNotExtend(bool Val) {
assert((!Val || !MustExtend) && "Extension contradiction");
MustNotExtend = Val;
}
bool HexagonMCExpr::mustNotExtend() const { return MustNotExtend; }
bool HexagonMCExpr::s27_2_reloc() const { return S27_2_reloc; }
void HexagonMCExpr::setS27_2_reloc(bool Val) {
S27_2_reloc = Val;
}
bool HexagonMCExpr::classof(MCExpr const *E) {
return E->getKind() == MCExpr::Target;
}
HexagonMCExpr::HexagonMCExpr(MCExpr const *Expr)
: Expr(Expr), MustNotExtend(false), MustExtend(false), S27_2_reloc(false),
SignMismatch(false) {}
void HexagonMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
Expr->print(OS, MAI);
}
void HexagonMCExpr::setSignMismatch(bool Val) {
SignMismatch = Val;
}
bool HexagonMCExpr::signMismatch() const {
return SignMismatch;
}

View File

@ -0,0 +1,47 @@
//==- HexagonMCExpr.h - Hexagon specific MC expression classes --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONMCEXPR_H
#define LLVM_LIB_TARGET_HEXAGON_HEXAGONMCEXPR_H
#include "llvm/MC/MCExpr.h"
namespace llvm {
class MCInst;
class HexagonMCExpr : public MCTargetExpr {
public:
static HexagonMCExpr *create(MCExpr const *Expr, MCContext &Ctx);
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
const MCFixup *Fixup) const override;
void visitUsedExpr(MCStreamer &Streamer) const override;
MCFragment *findAssociatedFragment() const override;
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
static bool classof(MCExpr const *E);
MCExpr const *getExpr() const;
void setMustExtend(bool Val = true);
bool mustExtend() const;
void setMustNotExtend(bool Val = true);
bool mustNotExtend() const;
void setS27_2_reloc(bool Val = true);
bool s27_2_reloc() const;
void setSignMismatch(bool Val = true);
bool signMismatch() const;
private:
HexagonMCExpr(MCExpr const *Expr);
MCExpr const *Expr;
bool MustNotExtend;
bool MustExtend;
bool S27_2_reloc;
bool SignMismatch;
};
} // end namespace llvm
#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONMCEXPR_H

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More