MipsABIFlagsSection.h [plain text]
#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
#include "llvm/MC/MCStreamer.h"
namespace llvm {
class MCStreamer;
struct MipsABIFlagsSection {
enum AFL_REG {
AFL_REG_NONE = 0x00, AFL_REG_32 = 0x01, AFL_REG_64 = 0x02, AFL_REG_128 = 0x03 };
enum AFL_ASE {
AFL_ASE_DSP = 0x00000001, AFL_ASE_DSPR2 = 0x00000002, AFL_ASE_EVA = 0x00000004, AFL_ASE_MCU = 0x00000008, AFL_ASE_MDMX = 0x00000010, AFL_ASE_MIPS3D = 0x00000020, AFL_ASE_MT = 0x00000040, AFL_ASE_SMARTMIPS = 0x00000080, AFL_ASE_VIRT = 0x00000100, AFL_ASE_MSA = 0x00000200, AFL_ASE_MIPS16 = 0x00000400, AFL_ASE_MICROMIPS = 0x00000800, AFL_ASE_XPA = 0x00001000 };
enum AFL_EXT {
AFL_EXT_XLR = 1, AFL_EXT_OCTEON2 = 2, AFL_EXT_OCTEONP = 3, AFL_EXT_LOONGSON_3A = 4, AFL_EXT_OCTEON = 5, AFL_EXT_5900 = 6, AFL_EXT_4650 = 7, AFL_EXT_4010 = 8, AFL_EXT_4100 = 9, AFL_EXT_3900 = 10, AFL_EXT_10000 = 11, AFL_EXT_SB1 = 12, AFL_EXT_4111 = 13, AFL_EXT_4120 = 14, AFL_EXT_5400 = 15, AFL_EXT_5500 = 16, AFL_EXT_LOONGSON_2E = 17, AFL_EXT_LOONGSON_2F = 18 };
enum Val_GNU_MIPS_ABI {
Val_GNU_MIPS_ABI_FP_ANY = 0,
Val_GNU_MIPS_ABI_FP_DOUBLE = 1,
Val_GNU_MIPS_ABI_FP_XX = 5,
Val_GNU_MIPS_ABI_FP_64 = 6,
Val_GNU_MIPS_ABI_FP_64A = 7
};
enum AFL_FLAGS1 {
AFL_FLAGS1_ODDSPREG = 1
};
enum class FpABIKind { ANY, XX, S32, S64 };
uint16_t Version;
uint8_t ISALevel;
uint8_t ISARevision;
AFL_REG GPRSize;
AFL_REG CPR1Size;
AFL_REG CPR2Size;
uint32_t ISAExtensionSet;
uint32_t ASESet;
bool OddSPReg;
bool Is32BitABI;
protected:
FpABIKind FpABI;
public:
MipsABIFlagsSection()
: Version(0), ISALevel(0), ISARevision(0), GPRSize(AFL_REG_NONE),
CPR1Size(AFL_REG_NONE), CPR2Size(AFL_REG_NONE), ISAExtensionSet(0),
ASESet(0), OddSPReg(false), Is32BitABI(false), FpABI(FpABIKind::ANY) {}
uint16_t getVersionValue() { return (uint16_t)Version; }
uint8_t getISALevelValue() { return (uint8_t)ISALevel; }
uint8_t getISARevisionValue() { return (uint8_t)ISARevision; }
uint8_t getGPRSizeValue() { return (uint8_t)GPRSize; }
uint8_t getCPR1SizeValue();
uint8_t getCPR2SizeValue() { return (uint8_t)CPR2Size; }
uint8_t getFpABIValue();
uint32_t getISAExtensionSetValue() { return (uint32_t)ISAExtensionSet; }
uint32_t getASESetValue() { return (uint32_t)ASESet; }
uint32_t getFlags1Value() {
uint32_t Value = 0;
if (OddSPReg)
Value |= (uint32_t)AFL_FLAGS1_ODDSPREG;
return Value;
}
uint32_t getFlags2Value() { return 0; }
FpABIKind getFpABI() { return FpABI; }
void setFpABI(FpABIKind Value, bool IsABI32Bit) {
FpABI = Value;
Is32BitABI = IsABI32Bit;
}
StringRef getFpABIString(FpABIKind Value);
template <class PredicateLibrary>
void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
if (P.hasMips64()) {
ISALevel = 64;
if (P.hasMips64r6())
ISARevision = 6;
else if (P.hasMips64r2())
ISARevision = 2;
else
ISARevision = 1;
} else if (P.hasMips32()) {
ISALevel = 32;
if (P.hasMips32r6())
ISARevision = 6;
else if (P.hasMips32r2())
ISARevision = 2;
else
ISARevision = 1;
} else {
ISARevision = 0;
if (P.hasMips5())
ISALevel = 5;
else if (P.hasMips4())
ISALevel = 4;
else if (P.hasMips3())
ISALevel = 3;
else if (P.hasMips2())
ISALevel = 2;
else if (P.hasMips1())
ISALevel = 1;
else
llvm_unreachable("Unknown ISA level!");
}
}
template <class PredicateLibrary>
void setGPRSizeFromPredicates(const PredicateLibrary &P) {
GPRSize = P.isGP64bit() ? AFL_REG_64 : AFL_REG_32;
}
template <class PredicateLibrary>
void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
if (P.abiUsesSoftFloat())
CPR1Size = AFL_REG_NONE;
else if (P.hasMSA())
CPR1Size = AFL_REG_128;
else
CPR1Size = P.isFP64bit() ? AFL_REG_64 : AFL_REG_32;
}
template <class PredicateLibrary>
void setASESetFromPredicates(const PredicateLibrary &P) {
ASESet = 0;
if (P.hasDSP())
ASESet |= AFL_ASE_DSP;
if (P.hasDSPR2())
ASESet |= AFL_ASE_DSPR2;
if (P.hasMSA())
ASESet |= AFL_ASE_MSA;
if (P.inMicroMipsMode())
ASESet |= AFL_ASE_MICROMIPS;
if (P.inMips16Mode())
ASESet |= AFL_ASE_MIPS16;
}
template <class PredicateLibrary>
void setFpAbiFromPredicates(const PredicateLibrary &P) {
Is32BitABI = P.isABI_O32();
FpABI = FpABIKind::ANY;
if (P.isABI_N32() || P.isABI_N64())
FpABI = FpABIKind::S64;
else if (P.isABI_O32()) {
if (P.isABI_FPXX())
FpABI = FpABIKind::XX;
else if (P.isFP64bit())
FpABI = FpABIKind::S64;
else
FpABI = FpABIKind::S32;
}
}
template <class PredicateLibrary>
void setAllFromPredicates(const PredicateLibrary &P) {
setISALevelAndRevisionFromPredicates(P);
setGPRSizeFromPredicates(P);
setCPR1SizeFromPredicates(P);
setASESetFromPredicates(P);
setFpAbiFromPredicates(P);
OddSPReg = P.useOddSPReg();
}
};
MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);
}
#endif