LLVM 19.0.0git
LanaiAluCode.h
Go to the documentation of this file.
1//===-- LanaiAluCode.h - ALU operator encoding ----------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// The encoding for ALU operators used in RM and RRM operands
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H
14#define LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H
15
18
19namespace llvm {
20namespace LPAC {
21enum AluCode {
22 ADD = 0x00,
23 ADDC = 0x01,
24 SUB = 0x02,
25 SUBB = 0x03,
26 AND = 0x04,
27 OR = 0x05,
28 XOR = 0x06,
29 SPECIAL = 0x07,
30
31 // Shift instructions are treated as SPECIAL when encoding the machine
32 // instruction, but kept distinct until lowering. The constant values are
33 // chosen to ease lowering.
34 SHL = 0x17,
35 SRL = 0x27,
36 SRA = 0x37,
37
38 // Indicates an unknown/unsupported operator
39 UNKNOWN = 0xFF,
40};
41
42// Bits indicating post- and pre-operators should be tested and set using Is*
43// and Make* utility functions
44const int Lanai_PRE_OP = 0x40;
45const int Lanai_POST_OP = 0x80;
46
47inline static unsigned encodeLanaiAluCode(unsigned AluOp) {
48 unsigned const OP_ENCODING_MASK = 0x07;
49 return AluOp & OP_ENCODING_MASK;
50}
51
52inline static unsigned getAluOp(unsigned AluOp) {
53 unsigned const ALU_MASK = 0x3F;
54 return AluOp & ALU_MASK;
55}
56
57inline static bool isPreOp(unsigned AluOp) { return AluOp & Lanai_PRE_OP; }
58
59inline static bool isPostOp(unsigned AluOp) { return AluOp & Lanai_POST_OP; }
60
61inline static unsigned makePreOp(unsigned AluOp) {
62 assert(!isPostOp(AluOp) && "Operator can't be a post- and pre-op");
63 return AluOp | Lanai_PRE_OP;
64}
65
66inline static unsigned makePostOp(unsigned AluOp) {
67 assert(!isPreOp(AluOp) && "Operator can't be a post- and pre-op");
68 return AluOp | Lanai_POST_OP;
69}
70
71inline static bool modifiesOp(unsigned AluOp) {
72 return isPreOp(AluOp) || isPostOp(AluOp);
73}
74
75inline static const char *lanaiAluCodeToString(unsigned AluOp) {
76 switch (getAluOp(AluOp)) {
77 case ADD:
78 return "add";
79 case ADDC:
80 return "addc";
81 case SUB:
82 return "sub";
83 case SUBB:
84 return "subb";
85 case AND:
86 return "and";
87 case OR:
88 return "or";
89 case XOR:
90 return "xor";
91 case SHL:
92 return "sh";
93 case SRL:
94 return "sh";
95 case SRA:
96 return "sha";
97 default:
98 llvm_unreachable("Invalid ALU code.");
99 }
100}
101
103 return StringSwitch<AluCode>(S)
104 .Case("add", ADD)
105 .Case("addc", ADDC)
106 .Case("sub", SUB)
107 .Case("subb", SUBB)
108 .Case("and", AND)
109 .Case("or", OR)
110 .Case("xor", XOR)
111 .Case("sh", SHL)
112 .Case("srl", SRL)
113 .Case("sha", SRA)
115}
116} // namespace LPAC
117} // namespace llvm
118
119#endif // LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool isPreOp(unsigned AluOp)
Definition: LanaiAluCode.h:57
static unsigned getAluOp(unsigned AluOp)
Definition: LanaiAluCode.h:52
static const char * lanaiAluCodeToString(unsigned AluOp)
Definition: LanaiAluCode.h:75
static unsigned makePostOp(unsigned AluOp)
Definition: LanaiAluCode.h:66
static unsigned makePreOp(unsigned AluOp)
Definition: LanaiAluCode.h:61
static unsigned encodeLanaiAluCode(unsigned AluOp)
Definition: LanaiAluCode.h:47
static AluCode stringToLanaiAluCode(StringRef S)
Definition: LanaiAluCode.h:102
const int Lanai_POST_OP
Definition: LanaiAluCode.h:45
static bool isPostOp(unsigned AluOp)
Definition: LanaiAluCode.h:59
const int Lanai_PRE_OP
Definition: LanaiAluCode.h:44
static bool modifiesOp(unsigned AluOp)
Definition: LanaiAluCode.h:71
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18