2017-02-14 08:33:36 +08:00
|
|
|
//===- MipsOptionRecord.cpp - Abstraction for storing information ---------===//
|
2014-07-21 21:30:55 +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-07-21 21:30:55 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "MipsOptionRecord.h"
|
2017-02-14 08:33:36 +08:00
|
|
|
#include "MipsABIInfo.h"
|
2014-07-21 21:30:55 +08:00
|
|
|
#include "MipsELFStreamer.h"
|
2015-02-13 17:09:03 +08:00
|
|
|
#include "MipsTargetStreamer.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
2017-02-14 08:33:36 +08:00
|
|
|
#include "llvm/MC/MCAssembler.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2014-07-21 21:30:55 +08:00
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
2017-02-14 08:33:36 +08:00
|
|
|
#include <cassert>
|
2014-07-21 21:30:55 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
void MipsRegInfoRecord::EmitMipsOptionRecord() {
|
|
|
|
MCAssembler &MCA = Streamer->getAssembler();
|
2015-01-27 01:33:46 +08:00
|
|
|
MipsTargetStreamer *MTS =
|
|
|
|
static_cast<MipsTargetStreamer *>(Streamer->getTargetStreamer());
|
2014-07-21 21:30:55 +08:00
|
|
|
|
|
|
|
Streamer->PushSection();
|
|
|
|
|
|
|
|
// We need to distinguish between N64 and the rest because at the moment
|
|
|
|
// we don't emit .Mips.options for other ELFs other than N64.
|
|
|
|
// Since .reginfo has the same information as .Mips.options (ODK_REGINFO),
|
|
|
|
// we can use the same abstraction (MipsRegInfoRecord class) to handle both.
|
2015-01-27 01:33:46 +08:00
|
|
|
if (MTS->getABI().IsN64()) {
|
2014-07-21 21:30:55 +08:00
|
|
|
// The EntrySize value of 1 seems strange since the records are neither
|
|
|
|
// 1-byte long nor fixed length but it matches the value GAS emits.
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSectionELF *Sec =
|
2014-07-21 21:30:55 +08:00
|
|
|
Context.getELFSection(".MIPS.options", ELF::SHT_MIPS_OPTIONS,
|
2015-01-30 01:33:21 +08:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_MIPS_NOSTRIP, 1, "");
|
2015-05-26 23:07:25 +08:00
|
|
|
MCA.registerSection(*Sec);
|
2019-09-27 20:54:21 +08:00
|
|
|
Sec->setAlignment(Align(8));
|
2014-07-21 21:30:55 +08:00
|
|
|
Streamer->SwitchSection(Sec);
|
|
|
|
|
2015-02-17 06:59:29 +08:00
|
|
|
Streamer->EmitIntValue(ELF::ODK_REGINFO, 1); // kind
|
2014-07-21 21:30:55 +08:00
|
|
|
Streamer->EmitIntValue(40, 1); // size
|
|
|
|
Streamer->EmitIntValue(0, 2); // section
|
|
|
|
Streamer->EmitIntValue(0, 4); // info
|
|
|
|
Streamer->EmitIntValue(ri_gprmask, 4);
|
|
|
|
Streamer->EmitIntValue(0, 4); // pad
|
|
|
|
Streamer->EmitIntValue(ri_cprmask[0], 4);
|
|
|
|
Streamer->EmitIntValue(ri_cprmask[1], 4);
|
|
|
|
Streamer->EmitIntValue(ri_cprmask[2], 4);
|
|
|
|
Streamer->EmitIntValue(ri_cprmask[3], 4);
|
|
|
|
Streamer->EmitIntValue(ri_gp_value, 8);
|
|
|
|
} else {
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSectionELF *Sec = Context.getELFSection(".reginfo", ELF::SHT_MIPS_REGINFO,
|
|
|
|
ELF::SHF_ALLOC, 24, "");
|
2015-05-26 23:07:25 +08:00
|
|
|
MCA.registerSection(*Sec);
|
2019-09-27 20:54:21 +08:00
|
|
|
Sec->setAlignment(MTS->getABI().IsN32() ? Align(8) : Align(4));
|
2014-07-21 21:30:55 +08:00
|
|
|
Streamer->SwitchSection(Sec);
|
|
|
|
|
|
|
|
Streamer->EmitIntValue(ri_gprmask, 4);
|
|
|
|
Streamer->EmitIntValue(ri_cprmask[0], 4);
|
|
|
|
Streamer->EmitIntValue(ri_cprmask[1], 4);
|
|
|
|
Streamer->EmitIntValue(ri_cprmask[2], 4);
|
|
|
|
Streamer->EmitIntValue(ri_cprmask[3], 4);
|
|
|
|
assert((ri_gp_value & 0xffffffff) == ri_gp_value);
|
|
|
|
Streamer->EmitIntValue(ri_gp_value, 4);
|
|
|
|
}
|
2014-08-12 20:41:44 +08:00
|
|
|
|
2014-07-21 21:30:55 +08:00
|
|
|
Streamer->PopSection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsRegInfoRecord::SetPhysRegUsed(unsigned Reg,
|
|
|
|
const MCRegisterInfo *MCRegInfo) {
|
|
|
|
unsigned Value = 0;
|
|
|
|
|
2019-12-05 17:16:08 +08:00
|
|
|
for (const MCPhysReg &SubReg : MCRegInfo->subregs_inclusive(Reg)) {
|
|
|
|
unsigned EncVal = MCRegInfo->getEncodingValue(SubReg);
|
2014-07-21 21:30:55 +08:00
|
|
|
Value |= 1 << EncVal;
|
|
|
|
|
2019-12-05 17:16:08 +08:00
|
|
|
if (GPR32RegClass->contains(SubReg) || GPR64RegClass->contains(SubReg))
|
2014-07-21 21:30:55 +08:00
|
|
|
ri_gprmask |= Value;
|
2019-12-05 17:16:08 +08:00
|
|
|
else if (COP0RegClass->contains(SubReg))
|
2015-06-27 23:39:19 +08:00
|
|
|
ri_cprmask[0] |= Value;
|
|
|
|
// MIPS COP1 is the FPU.
|
2019-12-05 17:16:08 +08:00
|
|
|
else if (FGR32RegClass->contains(SubReg) ||
|
|
|
|
FGR64RegClass->contains(SubReg) ||
|
|
|
|
AFGR64RegClass->contains(SubReg) ||
|
|
|
|
MSA128BRegClass->contains(SubReg))
|
2014-07-21 21:30:55 +08:00
|
|
|
ri_cprmask[1] |= Value;
|
2019-12-05 17:16:08 +08:00
|
|
|
else if (COP2RegClass->contains(SubReg))
|
2014-07-21 21:30:55 +08:00
|
|
|
ri_cprmask[2] |= Value;
|
2019-12-05 17:16:08 +08:00
|
|
|
else if (COP3RegClass->contains(SubReg))
|
2014-07-21 21:30:55 +08:00
|
|
|
ri_cprmask[3] |= Value;
|
|
|
|
}
|
|
|
|
}
|