<div dir="ltr">Hi Quentin,<div><br></div><div>Just one other thing I noticed on my way through this - would it be possible to separate the new opcodes you're adding for global isel to another .td file that's then included? Keep the separation of concerns/code out?</div><div><br></div><div>Thoughts?</div><div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 20, 2016 at 11:18 AM Quentin Colombet via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: qcolombet<br>
Date: Wed Jan 20 13:14:55 2016<br>
New Revision: 258333<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=258333&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=258333&view=rev</a><br>
Log:<br>
[GlobalISel] Add a generic machine opcode for ADD.<br>
The selection process being split into separate passes, we need generic opcodes<br>
to translate the LLVM IR to target independent code.<br>
<br>
This patch adds an opcode for addition: G_ADD.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D15472" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15472</a><br>
<br>
Modified:<br>
llvm/trunk/include/llvm/Target/Target.td<br>
llvm/trunk/include/llvm/Target/TargetOpcodes.h<br>
llvm/trunk/test/TableGen/<a href="http://trydecode-emission.td" rel="noreferrer" target="_blank">trydecode-emission.td</a><br>
llvm/trunk/test/TableGen/<a href="http://trydecode-emission2.td" rel="noreferrer" target="_blank">trydecode-emission2.td</a><br>
llvm/trunk/test/TableGen/<a href="http://trydecode-emission3.td" rel="noreferrer" target="_blank">trydecode-emission3.td</a><br>
llvm/trunk/utils/TableGen/CodeGenTarget.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Target/Target.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/Target.td?rev=258333&r1=258332&r2=258333&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/Target.td?rev=258333&r1=258332&r2=258333&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Target/Target.td (original)<br>
+++ llvm/trunk/include/llvm/Target/Target.td Wed Jan 20 13:14:55 2016<br>
@@ -913,6 +913,17 @@ def FAULTING_LOAD_OP : Instruction {<br>
let usesCustomInserter = 1;<br>
let mayLoad = 1;<br>
}<br>
+<br>
+// Generic opcode used by the IRTranslator.<br>
+// After ISel, this opcode should not appear.<br>
+def G_ADD : Instruction {<br>
+ let OutOperandList = (outs unknown:$dst);<br>
+ let InOperandList = (ins unknown:$src1, unknown:$src2);<br>
+ let AsmString = "";<br>
+ let hasSideEffects = 0;<br>
+ let isCommutable = 1;<br>
+}<br>
+// TODO: Add the other generic opcodes.<br>
}<br>
<br>
//===----------------------------------------------------------------------===//<br>
<br>
Modified: llvm/trunk/include/llvm/Target/TargetOpcodes.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOpcodes.h?rev=258333&r1=258332&r2=258333&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOpcodes.h?rev=258333&r1=258332&r2=258333&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Target/TargetOpcodes.h (original)<br>
+++ llvm/trunk/include/llvm/Target/TargetOpcodes.h Wed Jan 20 13:14:55 2016<br>
@@ -129,9 +129,27 @@ enum {<br>
/// comparisons into existing memory operations.<br>
FAULTING_LOAD_OP = 22,<br>
<br>
+ /// The following generic opcodes are not supposed to appear after ISel.<br>
+ /// This is something we might want to relax, but for now, this is convenient<br>
+ /// to produce diagnostic.<br>
+ PRE_ISEL_GENERIC_OPCODE_START,<br>
+ // Generic opcodes used before ISel are here.<br>
+<br>
+ /// Generic ADD instruction. This is an integer add.<br>
+ G_ADD = PRE_ISEL_GENERIC_OPCODE_START,<br>
+ // TODO: Add more generic opcodes as we move along.<br>
+ // FIXME: Right now, we have to manually add any new opcode in<br>
+ // CodeGenTarget.cpp for TableGen to pick them up.<br>
+ // Moreover the order must match.<br>
+<br>
+ /// Marker for the end of the generic opcode.<br>
+ /// This is used to check if an opcode is in the range of the<br>
+ /// generic opcodes.<br>
+ PRE_ISEL_GENERIC_OPCODE_END,<br>
+<br>
/// BUILTIN_OP_END - This must be the last enum value in this list.<br>
/// The target-specific post-isel opcode values start here.<br>
- GENERIC_OP_END = FAULTING_LOAD_OP,<br>
+ GENERIC_OP_END = PRE_ISEL_GENERIC_OPCODE_END,<br>
};<br>
} // end namespace TargetOpcode<br>
} // end namespace llvm<br>
<br>
Modified: llvm/trunk/test/TableGen/<a href="http://trydecode-emission.td" rel="noreferrer" target="_blank">trydecode-emission.td</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/trydecode-emission.td?rev=258333&r1=258332&r2=258333&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/trydecode-emission.td?rev=258333&r1=258332&r2=258333&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/TableGen/<a href="http://trydecode-emission.td" rel="noreferrer" target="_blank">trydecode-emission.td</a> (original)<br>
+++ llvm/trunk/test/TableGen/<a href="http://trydecode-emission.td" rel="noreferrer" target="_blank">trydecode-emission.td</a> Wed Jan 20 13:14:55 2016<br>
@@ -36,8 +36,8 @@ def InstB : TestInstruction {<br>
// CHECK: /* 0 */ MCD::OPC_ExtractField, 4, 4, // Inst{7-4} ...<br>
// CHECK-NEXT: /* 3 */ MCD::OPC_FilterValue, 0, 14, 0, // Skip to: 21<br>
// CHECK-NEXT: /* 7 */ MCD::OPC_CheckField, 2, 2, 0, 5, 0, // Skip to: 18<br>
-// CHECK-NEXT: /* 13 */ MCD::OPC_TryDecode, 24, 0, 0, 0, // Opcode: InstB, skip to: 18<br>
-// CHECK-NEXT: /* 18 */ MCD::OPC_Decode, 23, 1, // Opcode: InstA<br>
+// CHECK-NEXT: /* 13 */ MCD::OPC_TryDecode, 25, 0, 0, 0, // Opcode: InstB, skip to: 18<br>
+// CHECK-NEXT: /* 18 */ MCD::OPC_Decode, 24, 1, // Opcode: InstA<br>
// CHECK-NEXT: /* 21 */ MCD::OPC_Fail,<br>
<br>
// CHECK: if (DecodeInstB(MI, insn, Address, Decoder) == MCDisassembler::Fail) { DecodeComplete = false; return MCDisassembler::Fail; }<br>
<br>
Modified: llvm/trunk/test/TableGen/<a href="http://trydecode-emission2.td" rel="noreferrer" target="_blank">trydecode-emission2.td</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/trydecode-emission2.td?rev=258333&r1=258332&r2=258333&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/trydecode-emission2.td?rev=258333&r1=258332&r2=258333&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/TableGen/<a href="http://trydecode-emission2.td" rel="noreferrer" target="_blank">trydecode-emission2.td</a> (original)<br>
+++ llvm/trunk/test/TableGen/<a href="http://trydecode-emission2.td" rel="noreferrer" target="_blank">trydecode-emission2.td</a> Wed Jan 20 13:14:55 2016<br>
@@ -35,9 +35,9 @@ def InstB : TestInstruction {<br>
// CHECK-NEXT: /* 7 */ MCD::OPC_ExtractField, 5, 3, // Inst{7-5} ...<br>
// CHECK-NEXT: /* 10 */ MCD::OPC_FilterValue, 0, 22, 0, // Skip to: 36<br>
// CHECK-NEXT: /* 14 */ MCD::OPC_CheckField, 0, 2, 3, 5, 0, // Skip to: 25<br>
-// CHECK-NEXT: /* 20 */ MCD::OPC_TryDecode, 24, 0, 0, 0, // Opcode: InstB, skip to: 25<br>
+// CHECK-NEXT: /* 20 */ MCD::OPC_TryDecode, 25, 0, 0, 0, // Opcode: InstB, skip to: 25<br>
// CHECK-NEXT: /* 25 */ MCD::OPC_CheckField, 3, 2, 0, 5, 0, // Skip to: 36<br>
-// CHECK-NEXT: /* 31 */ MCD::OPC_TryDecode, 23, 1, 0, 0, // Opcode: InstA, skip to: 36<br>
+// CHECK-NEXT: /* 31 */ MCD::OPC_TryDecode, 24, 1, 0, 0, // Opcode: InstA, skip to: 36<br>
// CHECK-NEXT: /* 36 */ MCD::OPC_Fail,<br>
<br>
// CHECK: if (DecodeInstB(MI, insn, Address, Decoder) == MCDisassembler::Fail) { DecodeComplete = false; return MCDisassembler::Fail; }<br>
<br>
Modified: llvm/trunk/test/TableGen/<a href="http://trydecode-emission3.td" rel="noreferrer" target="_blank">trydecode-emission3.td</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/trydecode-emission3.td?rev=258333&r1=258332&r2=258333&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/trydecode-emission3.td?rev=258333&r1=258332&r2=258333&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/TableGen/<a href="http://trydecode-emission3.td" rel="noreferrer" target="_blank">trydecode-emission3.td</a> (original)<br>
+++ llvm/trunk/test/TableGen/<a href="http://trydecode-emission3.td" rel="noreferrer" target="_blank">trydecode-emission3.td</a> Wed Jan 20 13:14:55 2016<br>
@@ -37,8 +37,8 @@ def InstB : TestInstruction {<br>
// CHECK: /* 0 */ MCD::OPC_ExtractField, 4, 4, // Inst{7-4} ...<br>
// CHECK-NEXT: /* 3 */ MCD::OPC_FilterValue, 0, 14, 0, // Skip to: 21<br>
// CHECK-NEXT: /* 7 */ MCD::OPC_CheckField, 2, 2, 0, 5, 0, // Skip to: 18<br>
-// CHECK-NEXT: /* 13 */ MCD::OPC_TryDecode, 24, 0, 0, 0, // Opcode: InstB, skip to: 18<br>
-// CHECK-NEXT: /* 18 */ MCD::OPC_Decode, 23, 1, // Opcode: InstA<br>
+// CHECK-NEXT: /* 13 */ MCD::OPC_TryDecode, 25, 0, 0, 0, // Opcode: InstB, skip to: 18<br>
+// CHECK-NEXT: /* 18 */ MCD::OPC_Decode, 24, 1, // Opcode: InstA<br>
// CHECK-NEXT: /* 21 */ MCD::OPC_Fail,<br>
<br>
// CHECK: if (DecodeInstBOp(MI, tmp, Address, Decoder) == MCDisassembler::Fail) { DecodeComplete = false; return MCDisassembler::Fail; }<br>
<br>
Modified: llvm/trunk/utils/TableGen/CodeGenTarget.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.cpp?rev=258333&r1=258332&r2=258333&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.cpp?rev=258333&r1=258332&r2=258333&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/utils/TableGen/CodeGenTarget.cpp (original)<br>
+++ llvm/trunk/utils/TableGen/CodeGenTarget.cpp Wed Jan 20 13:14:55 2016<br>
@@ -301,6 +301,9 @@ GetInstByName(const char *Name,<br>
/// their enum value.<br>
void CodeGenTarget::ComputeInstrsByEnum() const {<br>
// The ordering here must match the ordering in TargetOpcodes.h.<br>
+ // FIXME: It would be nice to have the opcode directly extracted<br>
+ // to avoid potential errors. At the very, least a compile time<br>
+ // error would be appreciated if the order does not match.<br>
static const char *const FixedInstrs[] = {<br>
"PHI", "INLINEASM", "CFI_INSTRUCTION", "EH_LABEL",<br>
"GC_LABEL", "KILL", "EXTRACT_SUBREG", "INSERT_SUBREG",<br>
@@ -308,6 +311,8 @@ void CodeGenTarget::ComputeInstrsByEnum(<br>
"REG_SEQUENCE", "COPY", "BUNDLE", "LIFETIME_START",<br>
"LIFETIME_END", "STACKMAP", "PATCHPOINT", "LOAD_STACK_GUARD",<br>
"STATEPOINT", "LOCAL_ESCAPE", "FAULTING_LOAD_OP",<br>
+ // Generic opcodes for GlobalISel start here.<br>
+ "G_ADD",<br>
nullptr};<br>
const auto &Insts = getInstructions();<br>
for (const char *const *p = FixedInstrs; *p; ++p) {<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>