Skip to content

Commit a4d3f5e

Browse files
committed
[TableGen] Add InstrInfoEmitter options for operand type/size mappings
- It seems operand type and operand size mappings are only used by a few backends. So disable their emission by default and have the backends that use these opt-in.
1 parent 19a4135 commit a4d3f5e

File tree

6 files changed

+32
-14
lines changed

6 files changed

+32
-14
lines changed

llvm/lib/Target/AVR/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tablegen(LLVM AVRGenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM AVRGenCallingConv.inc -gen-callingconv)
88
tablegen(LLVM AVRGenDAGISel.inc -gen-dag-isel)
99
tablegen(LLVM AVRGenDisassemblerTables.inc -gen-disassembler)
10-
tablegen(LLVM AVRGenInstrInfo.inc -gen-instr-info)
10+
tablegen(LLVM AVRGenInstrInfo.inc -gen-instr-info -emit-operand-types)
1111
tablegen(LLVM AVRGenMCCodeEmitter.inc -gen-emitter)
1212
tablegen(LLVM AVRGenRegisterInfo.inc -gen-register-info)
1313
tablegen(LLVM AVRGenSubtargetInfo.inc -gen-subtarget)

llvm/lib/Target/M68k/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ set(LLVM_TARGET_DEFINITIONS M68k.td)
55
tablegen(LLVM M68kGenGlobalISel.inc -gen-global-isel)
66
tablegen(LLVM M68kGenRegisterInfo.inc -gen-register-info)
77
tablegen(LLVM M68kGenRegisterBank.inc -gen-register-bank)
8-
tablegen(LLVM M68kGenInstrInfo.inc -gen-instr-info)
8+
tablegen(LLVM M68kGenInstrInfo.inc -gen-instr-info
9+
-emit-operand-types
10+
-emit-logical-operand-size)
911
tablegen(LLVM M68kGenSubtargetInfo.inc -gen-subtarget)
1012
tablegen(LLVM M68kGenMCCodeEmitter.inc -gen-emitter)
1113
tablegen(LLVM M68kGenMCPseudoLowering.inc -gen-pseudo-lowering)

llvm/lib/Target/X86/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ tablegen(LLVM X86GenExegesis.inc -gen-exegesis)
1313
tablegen(LLVM X86GenFastISel.inc -gen-fast-isel)
1414
tablegen(LLVM X86GenGlobalISel.inc -gen-global-isel)
1515
tablegen(LLVM X86GenInstrInfo.inc -gen-instr-info
16-
-instr-info-expand-mi-operand-info=0)
16+
-instr-info-expand-mi-operand-info=0
17+
-emit-operand-types)
1718
tablegen(LLVM X86GenMnemonicTables.inc -gen-x86-mnemonic-tables -asmwriternum=1)
1819
tablegen(LLVM X86GenRegisterBank.inc -gen-register-bank)
1920
tablegen(LLVM X86GenRegisterInfo.inc -gen-register-info)

llvm/test/TableGen/get-operand-type-no-expand.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def InstA : Instruction {
3030
}
3131

3232
// RUN: llvm-tblgen -gen-instr-info -I %p/../../include %s \
33-
// RUN: -instr-info-expand-mi-operand-info=1 \
33+
// RUN: -emit-operand-types -instr-info-expand-mi-operand-info=1 \
3434
// RUN: | FileCheck %s --check-prefix=CHECK-EXPAND
3535
// CHECK-EXPAND: #ifdef GET_INSTRINFO_OPERAND_TYPE
3636
// CHECK-EXPAND: OpcodeOperandTypes[] = {
@@ -39,7 +39,7 @@ def InstA : Instruction {
3939
// CHECK-EXPAND: #endif // GET_INSTRINFO_OPERAND_TYPE
4040

4141
// RUN: llvm-tblgen -gen-instr-info -I %p/../../include %s \
42-
// RUN: -instr-info-expand-mi-operand-info=0 \
42+
// RUN: -emit-operand-types -instr-info-expand-mi-operand-info=0 \
4343
// RUN: | FileCheck %s --check-prefix=CHECK-NOEXPAND
4444
// CHECK-NOEXPAND: #ifdef GET_INSTRINFO_OPERAND_TYPE
4545
// CHECK-NOEXPAND: OpcodeOperandTypes[] = {

llvm/test/TableGen/get-operand-type.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: llvm-tblgen -gen-instr-info -I %p/../../include %s | FileCheck %s
1+
// RUN: llvm-tblgen -gen-instr-info -emit-operand-types \
2+
// RUN: -I %p/../../include %s | FileCheck %s
23

34
// Check that getOperandType has the expected info in it
45

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
using namespace llvm;
4242

4343
static cl::OptionCategory InstrInfoEmitterCat("Options for -gen-instr-info");
44+
45+
static cl::opt<bool>
46+
EnableOperandTypeMappings("emit-operand-types",
47+
cl::desc("Emit operand type mappings"),
48+
cl::cat(InstrInfoEmitterCat), cl::init(false));
49+
50+
static cl::opt<bool> EnableLogicalOperandSizeMappings(
51+
"emit-logical-operand-size", cl::desc("Emit logical operand size mappings"),
52+
cl::cat(InstrInfoEmitterCat), cl::init(false));
53+
4454
static cl::opt<bool> ExpandMIOperandInfo(
4555
"instr-info-expand-mi-operand-info",
4656
cl::desc("Expand operand's MIOperandInfo DAG into suboperands"),
@@ -338,8 +348,8 @@ void InstrInfoEmitter::emitOperandNameMappings(
338348
void InstrInfoEmitter::emitOperandTypeMappings(
339349
raw_ostream &OS, const CodeGenTarget &Target,
340350
ArrayRef<const CodeGenInstruction *> NumberedInstructions) {
341-
342351
StringRef Namespace = Target.getInstNamespace();
352+
343353
ArrayRef<const Record *> Operands =
344354
Records.getAllDerivedDefinitions("Operand");
345355
ArrayRef<const Record *> RegisterOperands =
@@ -461,10 +471,10 @@ void InstrInfoEmitter::emitOperandTypeMappings(
461471
SizeToOperandName[Size].push_back(Op->getName());
462472
}
463473
OS << " default: return 0;\n";
464-
for (const auto &KV : SizeToOperandName) {
465-
for (const StringRef &OperandName : KV.second)
474+
for (const auto &[Size, Names] : SizeToOperandName) {
475+
for (const StringRef &OperandName : Names)
466476
OS << " case OpTypes::" << OperandName << ":\n";
467-
OS << " return " << KV.first << ";\n\n";
477+
OS << " return " << Size << ";\n\n";
468478
}
469479
OS << " }\n}\n";
470480
OS << "} // end namespace llvm::" << Namespace << "\n";
@@ -1124,11 +1134,15 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
11241134
Timer.startTimer("Emit operand name mappings");
11251135
emitOperandNameMappings(OS, Target, NumberedInstructions);
11261136

1127-
Timer.startTimer("Emit operand type mappings");
1128-
emitOperandTypeMappings(OS, Target, NumberedInstructions);
1137+
if (EnableOperandTypeMappings) {
1138+
Timer.startTimer("Emit operand type mappings");
1139+
emitOperandTypeMappings(OS, Target, NumberedInstructions);
1140+
}
11291141

1130-
Timer.startTimer("Emit logical operand size mappings");
1131-
emitLogicalOperandSizeMappings(OS, TargetName, NumberedInstructions);
1142+
if (EnableLogicalOperandSizeMappings) {
1143+
Timer.startTimer("Emit logical operand size mappings");
1144+
emitLogicalOperandSizeMappings(OS, TargetName, NumberedInstructions);
1145+
}
11321146

11331147
Timer.startTimer("Emit logical operand type mappings");
11341148
emitLogicalOperandTypeMappings(OS, TargetName, NumberedInstructions);

0 commit comments

Comments
 (0)