Skip to content

Commit 4c7f52d

Browse files
committed
[CodeGen][NFC] Add laneBitmask as new MachineOperand Type
This patch adds a new MachineOperand type to represent the laneBitmask as MO_LaneMask that can be used in the instructions to represent the relevant information associated with the register operands of the same such as liveness.
1 parent 1862e3c commit 4c7f52d

File tree

12 files changed

+94
-5
lines changed

12 files changed

+94
-5
lines changed

llvm/docs/MIRLangRef.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ For an int eq predicate ``ICMP_EQ``, the syntax is:
819819
.. TODO: Describe the syntax of the metadata machine operands, and the
820820
instructions debug location attribute.
821821
.. TODO: Describe the syntax of the register live out machine operands.
822+
.. TODO: Describe the syntax of the lanemask machine operands.
822823
.. TODO: Describe the syntax of the machine memory operands.
823824
824825
Comments

llvm/include/llvm/CodeGen/MachineInstrBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ class MachineInstrBuilder {
292292
return *this;
293293
}
294294

295+
const MachineInstrBuilder &addLaneMask(LaneBitmask LaneMask) const {
296+
MI->addOperand(*MF, MachineOperand::CreateLaneMask(LaneMask));
297+
return *this;
298+
}
299+
295300
const MachineInstrBuilder &addSym(MCSymbol *Sym,
296301
unsigned char TargetFlags = 0) const {
297302
MI->addOperand(*MF, MachineOperand::CreateMCSymbol(Sym, TargetFlags));

llvm/include/llvm/CodeGen/MachineOperand.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/DenseMapInfo.h"
1717
#include "llvm/CodeGen/Register.h"
1818
#include "llvm/IR/Intrinsics.h"
19+
#include "llvm/MC/LaneBitmask.h"
1920
#include "llvm/Support/Compiler.h"
2021
#include <cassert>
2122

@@ -69,7 +70,8 @@ class MachineOperand {
6970
MO_Predicate, ///< Generic predicate for ISel
7071
MO_ShuffleMask, ///< Other IR Constant for ISel (shuffle masks)
7172
MO_DbgInstrRef, ///< Integer indices referring to an instruction+operand
72-
MO_Last = MO_DbgInstrRef
73+
MO_LaneMask, ///< Mask to represent active parts of registers
74+
MO_Last = MO_LaneMask
7375
};
7476

7577
private:
@@ -178,6 +180,7 @@ class MachineOperand {
178180
Intrinsic::ID IntrinsicID; // For MO_IntrinsicID.
179181
unsigned Pred; // For MO_Predicate
180182
ArrayRef<int> ShuffleMask; // For MO_ShuffleMask
183+
LaneBitmask LaneMask; // For MO_LaneMask
181184

182185
struct { // For MO_Register.
183186
// Register number is in SmallContents.RegNo.
@@ -360,6 +363,7 @@ class MachineOperand {
360363
bool isIntrinsicID() const { return OpKind == MO_IntrinsicID; }
361364
bool isPredicate() const { return OpKind == MO_Predicate; }
362365
bool isShuffleMask() const { return OpKind == MO_ShuffleMask; }
366+
bool isLaneMask() const { return OpKind == MO_LaneMask; }
363367
//===--------------------------------------------------------------------===//
364368
// Accessors for Register Operands
365369
//===--------------------------------------------------------------------===//
@@ -624,6 +628,11 @@ class MachineOperand {
624628
return Contents.ShuffleMask;
625629
}
626630

631+
LaneBitmask getLaneMask() const {
632+
assert(isLaneMask() && "Wrong MachineOperand accessor");
633+
return Contents.LaneMask;
634+
}
635+
627636
/// Return the offset from the symbol in this operand. This always returns 0
628637
/// for ExternalSymbol operands.
629638
int64_t getOffset() const {
@@ -989,6 +998,12 @@ class MachineOperand {
989998
return Op;
990999
}
9911000

1001+
static MachineOperand CreateLaneMask(LaneBitmask LaneMask) {
1002+
MachineOperand Op(MachineOperand::MO_LaneMask);
1003+
Op.Contents.LaneMask = LaneMask;
1004+
return Op;
1005+
}
1006+
9921007
friend class MachineInstr;
9931008
friend class MachineRegisterInfo;
9941009

llvm/lib/CodeGen/MIRParser/MILexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
266266
.Case("constant-pool", MIToken::kw_constant_pool)
267267
.Case("call-entry", MIToken::kw_call_entry)
268268
.Case("custom", MIToken::kw_custom)
269+
.Case("lanemask", MIToken::kw_lanemask)
269270
.Case("liveout", MIToken::kw_liveout)
270271
.Case("landing-pad", MIToken::kw_landing_pad)
271272
.Case("inlineasm-br-indirect-target",

llvm/lib/CodeGen/MIRParser/MILexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct MIToken {
122122
kw_constant_pool,
123123
kw_call_entry,
124124
kw_custom,
125+
kw_lanemask,
125126
kw_liveout,
126127
kw_landing_pad,
127128
kw_inlineasm_br_indirect_target,

llvm/lib/CodeGen/MIRParser/MIParser.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ class MIParser {
496496
bool parseTargetIndexOperand(MachineOperand &Dest);
497497
bool parseDbgInstrRefOperand(MachineOperand &Dest);
498498
bool parseCustomRegisterMaskOperand(MachineOperand &Dest);
499+
bool parseLaneMaskOperand(MachineOperand &Dest);
499500
bool parseLiveoutRegisterMaskOperand(MachineOperand &Dest);
500501
bool parseMachineOperand(const unsigned OpCode, const unsigned OpIdx,
501502
MachineOperand &Dest,
@@ -2870,6 +2871,32 @@ bool MIParser::parseCustomRegisterMaskOperand(MachineOperand &Dest) {
28702871
return false;
28712872
}
28722873

2874+
bool MIParser::parseLaneMaskOperand(MachineOperand &Dest) {
2875+
assert(Token.is(MIToken::kw_lanemask));
2876+
2877+
lex();
2878+
if (expectAndConsume(MIToken::lparen))
2879+
return error("expected syntax lanemask(...)");
2880+
2881+
LaneBitmask LaneMask = LaneBitmask::getAll();
2882+
// Parse lanemask.
2883+
if (Token.isNot(MIToken::IntegerLiteral) && Token.isNot(MIToken::HexLiteral))
2884+
return error("expected a lane mask");
2885+
static_assert(sizeof(LaneBitmask::Type) == sizeof(uint64_t),
2886+
"Use correct get-function for lane mask");
2887+
LaneBitmask::Type V;
2888+
if (getUint64(V))
2889+
return error("invalid lanemask value");
2890+
LaneMask = LaneBitmask(V);
2891+
lex();
2892+
2893+
if (expectAndConsume(MIToken::rparen))
2894+
return error("lanemask should be terminated by ')'.");
2895+
2896+
Dest = MachineOperand::CreateLaneMask(LaneMask);
2897+
return false;
2898+
}
2899+
28732900
bool MIParser::parseLiveoutRegisterMaskOperand(MachineOperand &Dest) {
28742901
assert(Token.is(MIToken::kw_liveout));
28752902
uint32_t *Mask = MF.allocateRegMask();
@@ -2970,6 +2997,8 @@ bool MIParser::parseMachineOperand(const unsigned OpCode, const unsigned OpIdx,
29702997
return parseIntrinsicOperand(Dest);
29712998
case MIToken::kw_target_index:
29722999
return parseTargetIndexOperand(Dest);
3000+
case MIToken::kw_lanemask:
3001+
return parseLaneMaskOperand(Dest);
29733002
case MIToken::kw_liveout:
29743003
return parseLiveoutRegisterMaskOperand(Dest);
29753004
case MIToken::kw_floatpred:

llvm/lib/CodeGen/MIRPrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,8 @@ static void printMIOperand(raw_ostream &OS, MFPrintState &State,
928928
case MachineOperand::MO_Predicate:
929929
case MachineOperand::MO_BlockAddress:
930930
case MachineOperand::MO_DbgInstrRef:
931-
case MachineOperand::MO_ShuffleMask: {
931+
case MachineOperand::MO_ShuffleMask:
932+
case MachineOperand::MO_LaneMask: {
932933
unsigned TiedOperandIdx = 0;
933934
if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
934935
TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);

llvm/lib/CodeGen/MIRVRegNamerUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ std::string VRegRenamer::getInstructionOpcodeHash(MachineInstr &MI) {
106106
case MachineOperand::MO_ExternalSymbol:
107107
case MachineOperand::MO_GlobalAddress:
108108
case MachineOperand::MO_BlockAddress:
109+
case MachineOperand::MO_LaneMask:
109110
case MachineOperand::MO_RegisterMask:
110111
case MachineOperand::MO_RegisterLiveOut:
111112
case MachineOperand::MO_Metadata:

llvm/lib/CodeGen/MachineOperand.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
380380
return getPredicate() == Other.getPredicate();
381381
case MachineOperand::MO_ShuffleMask:
382382
return getShuffleMask() == Other.getShuffleMask();
383+
case MachineOperand::MO_LaneMask:
384+
return getLaneMask() == Other.getLaneMask();
383385
}
384386
llvm_unreachable("Invalid machine operand type");
385387
}
@@ -445,6 +447,9 @@ hash_code llvm::hash_value(const MachineOperand &MO) {
445447
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getPredicate());
446448
case MachineOperand::MO_ShuffleMask:
447449
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getShuffleMask());
450+
case MachineOperand::MO_LaneMask:
451+
return hash_combine(MO.getType(), MO.getTargetFlags(),
452+
MO.getLaneMask().getAsInteger());
448453
}
449454
llvm_unreachable("Invalid machine operand type");
450455
}
@@ -1004,11 +1009,11 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
10041009
}
10051010
case MachineOperand::MO_Predicate: {
10061011
auto Pred = static_cast<CmpInst::Predicate>(getPredicate());
1007-
OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred("
1008-
<< Pred << ')';
1012+
OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred(" << Pred
1013+
<< ')';
10091014
break;
10101015
}
1011-
case MachineOperand::MO_ShuffleMask:
1016+
case MachineOperand::MO_ShuffleMask: {
10121017
OS << "shufflemask(";
10131018
ArrayRef<int> Mask = getShuffleMask();
10141019
StringRef Separator;
@@ -1023,6 +1028,14 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
10231028
OS << ')';
10241029
break;
10251030
}
1031+
case MachineOperand::MO_LaneMask: {
1032+
OS << "lanemask(";
1033+
LaneBitmask LaneMask = getLaneMask();
1034+
OS << "0x" << PrintLaneMask(LaneMask);
1035+
OS << ')';
1036+
break;
1037+
}
1038+
}
10261039
}
10271040

10281041
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

llvm/lib/CodeGen/MachineStableHash.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ stable_hash llvm::stableHashValue(const MachineOperand &MO) {
164164
return stable_hash_combine(MO.getType(), MO.getTargetFlags(),
165165
stable_hash_name(SymbolName));
166166
}
167+
case MachineOperand::MO_LaneMask: {
168+
return stable_hash_combine(MO.getType(), MO.getTargetFlags(),
169+
MO.getLaneMask().getAsInteger());
170+
}
167171
case MachineOperand::MO_CFIIndex:
168172
return stable_hash_combine(MO.getType(), MO.getTargetFlags(),
169173
MO.getCFIIndex());

0 commit comments

Comments
 (0)