|
| 1 | +// RUN: llvm-tblgen -gen-dag-isel -I %p/../../include %s 2>&1 | FileCheck %s |
| 2 | + |
| 3 | +include "llvm/Target/Target.td" |
| 4 | + |
| 5 | +// Minimal Target definition |
| 6 | +def DemoInstrInfo : InstrInfo; |
| 7 | +def Demo : Target { |
| 8 | + let InstructionSet = DemoInstrInfo; |
| 9 | +} |
| 10 | + |
| 11 | +// Some registers which can hold ints or floats |
| 12 | +foreach i = 0-7 in |
| 13 | + def "R" # i: Register<"r" # i>; |
| 14 | +def GPR : RegisterClass<"Demo", [i32, f32], 32, (sequence "R%u", 0, 7)>; |
| 15 | + |
| 16 | +// Instruction to convert an int to a float |
| 17 | +def i2f : Instruction { |
| 18 | + let Size = 2; |
| 19 | + let OutOperandList = (outs GPR:$dst); |
| 20 | + let InOperandList = (ins GPR:$src); |
| 21 | + let AsmString = "i2f $dst, $src"; |
| 22 | +} |
| 23 | + |
| 24 | +// Some kind of special type-conversion node supported by this target |
| 25 | +def specialconvert : SDNode<"TEST_TARGET_ISD::SPECIAL_CONVERT", SDTUnaryOp>; |
| 26 | + |
| 27 | +// A PatFrags that matches either bitconvert or the special version |
| 28 | +def anyconvert : PatFrags<(ops node:$src), |
| 29 | + [(bitconvert node:$src), |
| 30 | + (specialconvert node:$src)]>; |
| 31 | + |
| 32 | +// And a rule that matches that PatFrag and turns it into i2f |
| 33 | +def : Pat<(f32 (anyconvert (i32 GPR:$val))), (i2f GPR:$val)>; |
| 34 | + |
| 35 | +// CHECK: SwitchOpcode{{.*}}ISD::BITCAST |
| 36 | +// CHECK: MorphNodeTo1{{.*}}i2f |
| 37 | +// CHECK: SwitchOpcode{{.*}}TEST_TARGET_ISD::SPECIAL_CONVERT |
| 38 | +// CHECK: MorphNodeTo1{{.*}}i2f |
0 commit comments