aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/Mips/MCTargetDesc/MipsOptionRecord.cpp
blob: 0ef220821320a61e8b163c9314101db3ee28c373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//===-- MipsOptionRecord.cpp - Abstraction for storing information --------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "MipsOptionRecord.h"
#include "MipsELFStreamer.h"
#include "llvm/MC/MCSectionELF.h"

using namespace llvm;

void MipsRegInfoRecord::EmitMipsOptionRecord() {
  MCAssembler &MCA = Streamer->getAssembler();
  Triple T(STI.getTargetTriple());
  uint64_t Features = STI.getFeatureBits();

  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.
  if (Features & Mips::FeatureN64) {
    // 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.
    const MCSectionELF *Sec =
        Context.getELFSection(".MIPS.options", ELF::SHT_MIPS_OPTIONS,
                              ELF::SHF_ALLOC | ELF::SHF_MIPS_NOSTRIP,
                              SectionKind::getMetadata(), 1, "");
    MCA.getOrCreateSectionData(*Sec).setAlignment(8);
    Streamer->SwitchSection(Sec);

    Streamer->EmitIntValue(1, 1);  // kind
    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 {
    const MCSectionELF *Sec =
        Context.getELFSection(".reginfo", ELF::SHT_MIPS_REGINFO, ELF::SHF_ALLOC,
                              SectionKind::getMetadata(), 24, "");
    MCA.getOrCreateSectionData(*Sec)
        .setAlignment(Features & Mips::FeatureN32 ? 8 : 4);
    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);
  }

  Streamer->PopSection();
}

void MipsRegInfoRecord::SetPhysRegUsed(unsigned Reg,
                                       const MCRegisterInfo *MCRegInfo) {
  unsigned Value = 0;

  for (MCSubRegIterator SubRegIt(Reg, MCRegInfo, true); SubRegIt.isValid();
       ++SubRegIt) {
    unsigned CurrentSubReg = *SubRegIt;

    unsigned EncVal = MCRegInfo->getEncodingValue(CurrentSubReg);
    Value |= 1 << EncVal;

    if (GPR32RegClass->contains(CurrentSubReg) ||
        GPR64RegClass->contains(CurrentSubReg))
      ri_gprmask |= Value;
    else if (FGR32RegClass->contains(CurrentSubReg) ||
             FGR64RegClass->contains(CurrentSubReg) ||
             AFGR64RegClass->contains(CurrentSubReg) ||
             MSA128BRegClass->contains(CurrentSubReg))
      ri_cprmask[1] |= Value;
    else if (COP2RegClass->contains(CurrentSubReg))
      ri_cprmask[2] |= Value;
    else if (COP3RegClass->contains(CurrentSubReg))
      ri_cprmask[3] |= Value;
  }
}