MipsOptionRecord.cpp revision 274955
119370Spst//===-- MipsOptionRecord.cpp - Abstraction for storing information --------===// 219370Spst// 319370Spst// The LLVM Compiler Infrastructure 419370Spst// 546283Sdfr// This file is distributed under the University of Illinois Open Source 619370Spst// License. See LICENSE.TXT for details. 719370Spst// 819370Spst//===----------------------------------------------------------------------===// 919370Spst 1019370Spst#include "MipsOptionRecord.h" 1119370Spst#include "MipsELFStreamer.h" 1219370Spst#include "llvm/MC/MCSectionELF.h" 1319370Spst 1419370Spstusing namespace llvm; 1519370Spst 1619370Spstvoid MipsRegInfoRecord::EmitMipsOptionRecord() { 1719370Spst MCAssembler &MCA = Streamer->getAssembler(); 1819370Spst Triple T(STI.getTargetTriple()); 1919370Spst uint64_t Features = STI.getFeatureBits(); 2019370Spst 2119370Spst Streamer->PushSection(); 2219370Spst 2319370Spst // We need to distinguish between N64 and the rest because at the moment 2419370Spst // we don't emit .Mips.options for other ELFs other than N64. 2519370Spst // Since .reginfo has the same information as .Mips.options (ODK_REGINFO), 2619370Spst // we can use the same abstraction (MipsRegInfoRecord class) to handle both. 2719370Spst if (Features & Mips::FeatureN64) { 2819370Spst // The EntrySize value of 1 seems strange since the records are neither 2919370Spst // 1-byte long nor fixed length but it matches the value GAS emits. 3019370Spst const MCSectionELF *Sec = 3119370Spst Context.getELFSection(".MIPS.options", ELF::SHT_MIPS_OPTIONS, 3219370Spst ELF::SHF_ALLOC | ELF::SHF_MIPS_NOSTRIP, 3319370Spst SectionKind::getMetadata(), 1, ""); 3419370Spst MCA.getOrCreateSectionData(*Sec).setAlignment(8); 3519370Spst Streamer->SwitchSection(Sec); 3619370Spst 3719370Spst Streamer->EmitIntValue(1, 1); // kind 3819370Spst Streamer->EmitIntValue(40, 1); // size 3919370Spst Streamer->EmitIntValue(0, 2); // section 4019370Spst Streamer->EmitIntValue(0, 4); // info 4119370Spst Streamer->EmitIntValue(ri_gprmask, 4); 4219370Spst Streamer->EmitIntValue(0, 4); // pad 4319370Spst Streamer->EmitIntValue(ri_cprmask[0], 4); 4419370Spst Streamer->EmitIntValue(ri_cprmask[1], 4); 4519370Spst Streamer->EmitIntValue(ri_cprmask[2], 4); 4619370Spst Streamer->EmitIntValue(ri_cprmask[3], 4); 4719370Spst Streamer->EmitIntValue(ri_gp_value, 8); 4819370Spst } else { 4919370Spst const MCSectionELF *Sec = 5019370Spst Context.getELFSection(".reginfo", ELF::SHT_MIPS_REGINFO, ELF::SHF_ALLOC, 5119370Spst SectionKind::getMetadata(), 24, ""); 5219370Spst MCA.getOrCreateSectionData(*Sec) 5319370Spst .setAlignment(Features & Mips::FeatureN32 ? 8 : 4); 5419370Spst Streamer->SwitchSection(Sec); 5519370Spst 5619370Spst Streamer->EmitIntValue(ri_gprmask, 4); 5719370Spst Streamer->EmitIntValue(ri_cprmask[0], 4); 5819370Spst Streamer->EmitIntValue(ri_cprmask[1], 4); 5919370Spst Streamer->EmitIntValue(ri_cprmask[2], 4); 6019370Spst Streamer->EmitIntValue(ri_cprmask[3], 4); 6119370Spst assert((ri_gp_value & 0xffffffff) == ri_gp_value); 6219370Spst Streamer->EmitIntValue(ri_gp_value, 4); 6319370Spst } 6419370Spst 6519370Spst Streamer->PopSection(); 6619370Spst} 6719370Spst 6819370Spstvoid MipsRegInfoRecord::SetPhysRegUsed(unsigned Reg, 6919370Spst const MCRegisterInfo *MCRegInfo) { 7019370Spst unsigned Value = 0; 7119370Spst 7219370Spst for (MCSubRegIterator SubRegIt(Reg, MCRegInfo, true); SubRegIt.isValid(); 7319370Spst ++SubRegIt) { 7419370Spst unsigned CurrentSubReg = *SubRegIt; 7519370Spst 7619370Spst unsigned EncVal = MCRegInfo->getEncodingValue(CurrentSubReg); 7719370Spst Value |= 1 << EncVal; 7819370Spst 7919370Spst if (GPR32RegClass->contains(CurrentSubReg) || 8019370Spst GPR64RegClass->contains(CurrentSubReg)) 8119370Spst ri_gprmask |= Value; 8219370Spst else if (FGR32RegClass->contains(CurrentSubReg) || 8319370Spst FGR64RegClass->contains(CurrentSubReg) || 8419370Spst AFGR64RegClass->contains(CurrentSubReg) || 8519370Spst MSA128BRegClass->contains(CurrentSubReg)) 8619370Spst ri_cprmask[1] |= Value; 8719370Spst else if (COP2RegClass->contains(CurrentSubReg)) 8819370Spst ri_cprmask[2] |= Value; 8919370Spst else if (COP3RegClass->contains(CurrentSubReg)) 9019370Spst ri_cprmask[3] |= Value; 9119370Spst } 9219370Spst} 9319370Spst