2014-07-08 18:11:38 +08:00
|
|
|
//===-- MipsABIFlagsSection.h - Mips ELF ABI Flags Section -----*- C++ -*--===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
|
|
|
|
#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
|
2014-07-08 18:11:38 +08:00
|
|
|
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2015-05-16 06:19:42 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2015-05-07 22:57:04 +08:00
|
|
|
#include "llvm/Support/MipsABIFlags.h"
|
2014-07-08 18:11:38 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class MCStreamer;
|
|
|
|
|
|
|
|
struct MipsABIFlagsSection {
|
2015-05-07 18:29:52 +08:00
|
|
|
// Internal representation of the fp_abi related values used in .module.
|
|
|
|
enum class FpABIKind { ANY, XX, S32, S64, SOFT };
|
2014-07-10 21:38:23 +08:00
|
|
|
|
2014-07-08 18:11:38 +08:00
|
|
|
// Version of flags structure.
|
|
|
|
uint16_t Version;
|
|
|
|
// The level of the ISA: 1-5, 32, 64.
|
|
|
|
uint8_t ISALevel;
|
|
|
|
// The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
|
|
|
|
uint8_t ISARevision;
|
|
|
|
// The size of general purpose registers.
|
2015-05-07 22:57:04 +08:00
|
|
|
Mips::AFL_REG GPRSize;
|
2014-07-08 18:11:38 +08:00
|
|
|
// The size of co-processor 1 registers.
|
2015-05-07 22:57:04 +08:00
|
|
|
Mips::AFL_REG CPR1Size;
|
2014-07-08 18:11:38 +08:00
|
|
|
// The size of co-processor 2 registers.
|
2015-05-07 22:57:04 +08:00
|
|
|
Mips::AFL_REG CPR2Size;
|
2014-07-08 18:11:38 +08:00
|
|
|
// Processor-specific extension.
|
|
|
|
uint32_t ISAExtensionSet;
|
|
|
|
// Mask of ASEs used.
|
|
|
|
uint32_t ASESet;
|
|
|
|
|
2014-07-10 21:38:23 +08:00
|
|
|
bool OddSPReg;
|
|
|
|
|
|
|
|
bool Is32BitABI;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// The floating-point ABI.
|
|
|
|
FpABIKind FpABI;
|
|
|
|
|
|
|
|
public:
|
2014-07-08 18:11:38 +08:00
|
|
|
MipsABIFlagsSection()
|
2015-05-07 22:57:04 +08:00
|
|
|
: Version(0), ISALevel(0), ISARevision(0), GPRSize(Mips::AFL_REG_NONE),
|
|
|
|
CPR1Size(Mips::AFL_REG_NONE), CPR2Size(Mips::AFL_REG_NONE),
|
|
|
|
ISAExtensionSet(0), ASESet(0), OddSPReg(false), Is32BitABI(false),
|
|
|
|
FpABI(FpABIKind::ANY) {}
|
2014-07-10 21:38:23 +08:00
|
|
|
|
|
|
|
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; }
|
2014-07-17 17:57:23 +08:00
|
|
|
uint8_t getCPR1SizeValue();
|
2014-07-10 21:38:23 +08:00
|
|
|
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)
|
2015-05-07 22:57:04 +08:00
|
|
|
Value |= (uint32_t)Mips::AFL_FLAGS1_ODDSPREG;
|
2014-07-10 21:38:23 +08:00
|
|
|
|
|
|
|
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);
|
2014-07-08 18:11:38 +08:00
|
|
|
|
|
|
|
template <class PredicateLibrary>
|
|
|
|
void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
|
|
|
|
if (P.hasMips64()) {
|
|
|
|
ISALevel = 64;
|
|
|
|
if (P.hasMips64r6())
|
|
|
|
ISARevision = 6;
|
2015-02-19 00:24:50 +08:00
|
|
|
else if (P.hasMips64r5())
|
|
|
|
ISARevision = 5;
|
|
|
|
else if (P.hasMips64r3())
|
|
|
|
ISARevision = 3;
|
2014-07-08 18:11:38 +08:00
|
|
|
else if (P.hasMips64r2())
|
|
|
|
ISARevision = 2;
|
|
|
|
else
|
|
|
|
ISARevision = 1;
|
|
|
|
} else if (P.hasMips32()) {
|
|
|
|
ISALevel = 32;
|
|
|
|
if (P.hasMips32r6())
|
|
|
|
ISARevision = 6;
|
2015-02-19 00:24:50 +08:00
|
|
|
else if (P.hasMips32r5())
|
|
|
|
ISARevision = 5;
|
|
|
|
else if (P.hasMips32r3())
|
|
|
|
ISARevision = 3;
|
2014-07-08 18:11:38 +08:00
|
|
|
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) {
|
2015-05-07 22:57:04 +08:00
|
|
|
GPRSize = P.isGP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
|
2014-07-08 18:11:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class PredicateLibrary>
|
|
|
|
void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
|
2015-05-08 07:10:21 +08:00
|
|
|
if (P.useSoftFloat())
|
2015-05-07 22:57:04 +08:00
|
|
|
CPR1Size = Mips::AFL_REG_NONE;
|
2014-07-08 18:11:38 +08:00
|
|
|
else if (P.hasMSA())
|
2015-05-07 22:57:04 +08:00
|
|
|
CPR1Size = Mips::AFL_REG_128;
|
2014-07-08 18:11:38 +08:00
|
|
|
else
|
2015-05-07 22:57:04 +08:00
|
|
|
CPR1Size = P.isFP64bit() ? Mips::AFL_REG_64 : Mips::AFL_REG_32;
|
2014-07-08 18:11:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class PredicateLibrary>
|
|
|
|
void setASESetFromPredicates(const PredicateLibrary &P) {
|
|
|
|
ASESet = 0;
|
|
|
|
if (P.hasDSP())
|
2015-05-07 22:57:04 +08:00
|
|
|
ASESet |= Mips::AFL_ASE_DSP;
|
2014-07-08 18:11:38 +08:00
|
|
|
if (P.hasDSPR2())
|
2015-05-07 22:57:04 +08:00
|
|
|
ASESet |= Mips::AFL_ASE_DSPR2;
|
2014-07-08 18:11:38 +08:00
|
|
|
if (P.hasMSA())
|
2015-05-07 22:57:04 +08:00
|
|
|
ASESet |= Mips::AFL_ASE_MSA;
|
2014-07-08 18:11:38 +08:00
|
|
|
if (P.inMicroMipsMode())
|
2015-05-07 22:57:04 +08:00
|
|
|
ASESet |= Mips::AFL_ASE_MICROMIPS;
|
2014-07-08 18:11:38 +08:00
|
|
|
if (P.inMips16Mode())
|
2015-05-07 22:57:04 +08:00
|
|
|
ASESet |= Mips::AFL_ASE_MIPS16;
|
2014-07-08 18:11:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class PredicateLibrary>
|
|
|
|
void setFpAbiFromPredicates(const PredicateLibrary &P) {
|
2014-07-10 21:38:23 +08:00
|
|
|
Is32BitABI = P.isABI_O32();
|
|
|
|
|
|
|
|
FpABI = FpABIKind::ANY;
|
2015-05-08 07:10:21 +08:00
|
|
|
if (P.useSoftFloat())
|
2015-05-07 18:29:52 +08:00
|
|
|
FpABI = FpABIKind::SOFT;
|
|
|
|
else if (P.isABI_N32() || P.isABI_N64())
|
2014-07-10 21:38:23 +08:00
|
|
|
FpABI = FpABIKind::S64;
|
2014-07-08 18:11:38 +08:00
|
|
|
else if (P.isABI_O32()) {
|
2014-07-17 17:57:23 +08:00
|
|
|
if (P.isABI_FPXX())
|
2014-07-10 21:38:23 +08:00
|
|
|
FpABI = FpABIKind::XX;
|
2014-07-17 17:57:23 +08:00
|
|
|
else if (P.isFP64bit())
|
|
|
|
FpABI = FpABIKind::S64;
|
2014-07-08 18:11:38 +08:00
|
|
|
else
|
2014-07-10 21:38:23 +08:00
|
|
|
FpABI = FpABIKind::S32;
|
2014-07-08 18:11:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class PredicateLibrary>
|
|
|
|
void setAllFromPredicates(const PredicateLibrary &P) {
|
|
|
|
setISALevelAndRevisionFromPredicates(P);
|
|
|
|
setGPRSizeFromPredicates(P);
|
|
|
|
setCPR1SizeFromPredicates(P);
|
|
|
|
setASESetFromPredicates(P);
|
|
|
|
setFpAbiFromPredicates(P);
|
2014-07-14 18:26:15 +08:00
|
|
|
OddSPReg = P.useOddSPReg();
|
2014-07-08 18:11:38 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2014-07-08 18:11:38 +08:00
|
|
|
|
|
|
|
#endif
|