Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TableGen] Better error checking for TIED_TO constraints.
There are quite strong constraints on how you can use the TIED_TO constraint between MC operands, many of which are currently not checked until compiler run time. MachineVerifier enforces that operands can only be tied together in pairs (no three-way ties), and MachineInstr::tieOperands enforces that one of the tied operands must be an output operand (def) and the other must be an input operand (use). Now we check these at TableGen time, so that if you violate any of them in a new instruction definition, you find out immediately, instead of having to wait until you compile something that makes code generation hit one of those assertions. Also in this commit, all the error reports in ParseConstraint now include the name and source location of the def where the problem happened, so that if you do trigger any of these errors, it's easier to find the part of your TableGen input where you made the mistake. The trunk sources already build successfully with this additional error check, so I think no in-tree target has any of these problems. Reviewers: fhahn, lhames, nhaehnle, MatzeB Reviewed By: MatzeB Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D53815 llvm-svn: 347743
- Loading branch information
1 parent
69c6120
commit 3486055
Showing
10 changed files
with
154 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
include "llvm/Target/Target.td" | ||
|
||
def TestTarget : Target; | ||
|
||
class Encoding : Instruction { | ||
field bits<8> Inst; | ||
} | ||
|
||
class TestReg<string name, bits<1> enc> : Register<name, []> { | ||
let HWEncoding{15-1} = 0; | ||
let HWEncoding{0} = enc; | ||
} | ||
|
||
def R0 : TestReg<"R0", 0>; | ||
def R1 : TestReg<"R1", 1>; | ||
def Reg : RegisterClass<"TestTarget", [i32], 32, (sequence "R%d", 0, 1)>; | ||
|
||
class TestInstructionWithConstraints<string cstr> : Encoding { | ||
dag OutOperandList = (outs Reg:$dest1, Reg:$dest2); | ||
dag InOperandList = (ins Reg:$src1, Reg:$src2); | ||
string AsmString = "mnemonic $dest1, $dest2, $src1, $src2"; | ||
string AsmVariantName = ""; | ||
let Constraints = cstr; | ||
field bits<1> dest1; | ||
field bits<1> dest2; | ||
field bits<1> src1; | ||
field bits<1> src2; | ||
let Inst{7-4} = 0b1010; | ||
let Inst{3} = dest1{0}; | ||
let Inst{2} = dest2{0}; | ||
let Inst{1} = src1{0}; | ||
let Inst{0} = src2{0}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: not llvm-tblgen -gen-asm-writer -I %p -I %p/../../include %s 2>&1 | FileCheck %s -DFILE=%s | ||
|
||
include "ConstraintChecking.inc" | ||
|
||
// CHECK: [[FILE]]:[[@LINE+1]]:1: error: Unrecognized constraint '$dest1 ~ $src2' in 'Foo' | ||
def Foo : TestInstructionWithConstraints<"$dest1 ~ $src2">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: not llvm-tblgen -gen-asm-writer -I %p -I %p/../../include %s 2>&1 | FileCheck %s -DFILE=%s | ||
|
||
include "ConstraintChecking.inc" | ||
|
||
// CHECK: [[FILE]]:[[@LINE+1]]:1: error: Illegal format for @earlyclobber constraint in 'Foo' | ||
def Foo : TestInstructionWithConstraints<"@earlyclobber ">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// RUN: not llvm-tblgen -gen-asm-writer -I %p -I %p/../../include %s 2>&1 | FileCheck %s -DFILE=%s | ||
|
||
include "ConstraintChecking.inc" | ||
|
||
// (This is illegal because the '=' has to be surrounded by whitespace) | ||
|
||
// CHECK: [[FILE]]:[[@LINE+1]]:1: error: Illegal format for tied-to constraint in 'Foo' | ||
def Foo : TestInstructionWithConstraints<"$dest1=$dest2">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: not llvm-tblgen -gen-asm-writer -I %p -I %p/../../include %s 2>&1 | FileCheck %s -DFILE=%s | ||
|
||
include "ConstraintChecking.inc" | ||
|
||
// CHECK: [[FILE]]:[[@LINE+1]]:1: error: Output operands '$dest1' and '$dest2' of 'Foo' cannot be tied! | ||
def Foo : TestInstructionWithConstraints<"$dest1 = $dest2">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: not llvm-tblgen -gen-asm-writer -I %p -I %p/../../include %s 2>&1 | FileCheck %s -DFILE=%s | ||
|
||
include "ConstraintChecking.inc" | ||
|
||
// CHECK: [[FILE]]:[[@LINE+1]]:1: error: Input operands '$src1' and '$src2' of 'Foo' cannot be tied! | ||
def Foo : TestInstructionWithConstraints<"$src1 = $src2">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: not llvm-tblgen -gen-asm-writer -I %p -I %p/../../include %s 2>&1 | FileCheck %s -DFILE=%s | ||
|
||
include "ConstraintChecking.inc" | ||
|
||
// CHECK: [[FILE]]:[[@LINE+1]]:1: error: Operand '$dest1' of 'Foo' cannot have multiple operands tied to it! | ||
def Foo : TestInstructionWithConstraints<"$dest1 = $src1, $dest1 = $src2">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: not llvm-tblgen -gen-asm-writer -I %p -I %p/../../include %s 2>&1 | FileCheck %s -DFILE=%s | ||
|
||
include "ConstraintChecking.inc" | ||
|
||
// CHECK: [[FILE]]:[[@LINE+1]]:1: error: Operand '$src1' of 'Foo' cannot have multiple constraints! | ||
def Foo : TestInstructionWithConstraints<"$dest1 = $src1, $dest2 = $src1">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters