Skip to content

Commit ba4162c

Browse files
kaz7Simon Moll
authored andcommitted
[VE] Add alternative names to registers
Summary: VE uses identical names "%s0-63" to all generic registers. Change to use alternative name mechanism among all generic registers instead of hard- coding them. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D78174
1 parent 05a1197 commit ba4162c

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ using namespace VE;
3636
#include "VEGenAsmWriter.inc"
3737

3838
void VEInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
39-
OS << '%' << StringRef(getRegisterName(RegNo)).lower();
39+
// Generic registers have identical register name among register classes.
40+
unsigned AltIdx = VE::AsmName;
41+
OS << '%' << getRegisterName(RegNo, AltIdx);
4042
}
4143

4244
void VEInstPrinter::printInst(const MCInst *MI, uint64_t Address,

llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_LIB_TARGET_VE_INSTPRINTER_VEINSTPRINTER_H
1414
#define LLVM_LIB_TARGET_VE_INSTPRINTER_VEINSTPRINTER_H
1515

16+
#include "VEMCTargetDesc.h"
1617
#include "llvm/MC/MCInstPrinter.h"
1718

1819
namespace llvm {
@@ -32,7 +33,8 @@ class VEInstPrinter : public MCInstPrinter {
3233
const MCSubtargetInfo &, raw_ostream &);
3334
void printInstruction(const MCInst *, uint64_t, const MCSubtargetInfo &,
3435
raw_ostream &);
35-
static const char *getRegisterName(unsigned RegNo);
36+
static const char *getRegisterName(unsigned RegNo,
37+
unsigned AltIdx = VE::NoRegAltName);
3638

3739
void printOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI,
3840
raw_ostream &OS);

llvm/lib/Target/VE/VERegisterInfo.td

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,60 @@
1010
// Declarations that describe the VE register file
1111
//===----------------------------------------------------------------------===//
1212

13-
class VEReg<bits<7> Enc, string n> : Register<n> {
13+
class VEReg<bits<7> enc, string n, list<Register> subregs = [],
14+
list<string> altNames = [], list<Register> aliases = []>
15+
: Register<n, altNames> {
1416
let HWEncoding{15-7} = 0;
15-
let HWEncoding{6-0} = Enc;
17+
let HWEncoding{6-0} = enc;
1618
let Namespace = "VE";
19+
let SubRegs = subregs;
20+
let Aliases = aliases;
1721
}
1822

1923
let Namespace = "VE" in {
2024
def sub_i8 : SubRegIndex<8, 56>; // Low 8 bit (56..63)
2125
def sub_i16 : SubRegIndex<16, 48>; // Low 16 bit (48..63)
2226
def sub_i32 : SubRegIndex<32, 32>; // Low 32 bit (32..63)
2327
def sub_f32 : SubRegIndex<32>; // High 32 bit (0..31)
28+
def AsmName : RegAltNameIndex;
2429
}
2530

26-
// Registers are identified with 7-bit ID numbers.
27-
// R - 64-bit integer or floating-point registers
28-
class R<bits<7> Enc, string n, list<Register> subregs = [],
29-
list<Register> aliases = []>: VEReg<Enc, n> {
30-
let SubRegs = subregs;
31-
let Aliases = aliases;
32-
}
31+
//-----------------------------------------------------------------------------
32+
// Gneric Registers
33+
//-----------------------------------------------------------------------------
34+
35+
let RegAltNameIndices = [AsmName] in {
3336

3437
// Generic integer registers - 8 bits wide
3538
foreach I = 0-63 in
36-
def SB#I : R<I, "S"#I>, DwarfRegNum<[I]>;
39+
def SB#I : VEReg<I, "sb"#I, [], ["s"#I]>, DwarfRegNum<[I]>;
3740

3841
// Generic integer registers - 16 bits wide
3942
let SubRegIndices = [sub_i8] in
4043
foreach I = 0-63 in
41-
def SH#I : R<I, "S"#I, [!cast<R>("SB"#I)]>, DwarfRegNum<[I]>;
44+
def SH#I : VEReg<I, "sh"#I, [!cast<VEReg>("SB"#I)], ["s"#I]>,
45+
DwarfRegNum<[I]>;
4246

4347
// Generic integer registers - 32 bits wide
4448
let SubRegIndices = [sub_i16] in
4549
foreach I = 0-63 in
46-
def SW#I : R<I, "S"#I, [!cast<R>("SH"#I)]>, DwarfRegNum<[I]>;
50+
def SW#I : VEReg<I, "sw"#I, [!cast<VEReg>("SH"#I)], ["s"#I]>,
51+
DwarfRegNum<[I]>;
4752

4853
// Generic floating point registers - 32 bits wide
4954
// NOTE: Mark SF#I as alias of SW#I temporary to avoid register allocation
5055
// problem.
5156
foreach I = 0-63 in
52-
def SF#I : R<I, "S"#I, [], [!cast<R>("SW"#I)]>, DwarfRegNum<[I]>;
57+
def SF#I : VEReg<I, "sf"#I, [], ["s"#I], [!cast<VEReg>("SW"#I)]>,
58+
DwarfRegNum<[I]>;
5359

5460
// Generic integer registers - 64 bits wide
5561
let SubRegIndices = [sub_i32, sub_f32], CoveredBySubRegs = 1 in
5662
foreach I = 0-63 in
57-
def SX#I : R<I, "S"#I, [!cast<R>("SW"#I), !cast<R>("SF"#I)]>,
58-
DwarfRegNum<[I]>;
63+
def SX#I : VEReg<I, "s"#I, [!cast<VEReg>("SW"#I), !cast<VEReg>("SF"#I)],
64+
["s"#I]>, DwarfRegNum<[I]>;
65+
66+
} // RegAltNameIndices = [AsmName]
5967

6068
// Register classes.
6169
//

0 commit comments

Comments
 (0)