1// RUN: llvm-tblgen -gen-emitter -I %p/../../include %s | FileCheck %s --check-prefix=ENCODER 2// RUN: llvm-tblgen -gen-disassembler -I %p/../../include %s | FileCheck %s --check-prefix=DECODER 3 4include "llvm/Target/Target.td" 5 6def archInstrInfo : InstrInfo { } 7 8def arch : Target { 9 let InstructionSet = archInstrInfo; 10} 11 12def Myi32 : Operand<i32> { 13 let DecoderMethod = "DecodeMyi32"; 14} 15 16def ModeA : HwMode<"+a">; 17def ModeB : HwMode<"+b">; 18 19 20def fooTypeEncA : InstructionEncoding { 21 let Size = 4; 22 field bits<32> SoftFail = 0; 23 bits<32> Inst; 24 bits<8> factor; 25 let Inst{7...0} = factor; 26 let Inst{3...2} = 0b11; 27 let Inst{1...0} = 0b00; 28} 29 30def fooTypeEncB : InstructionEncoding { 31 let Size = 4; 32 field bits<32> SoftFail = 0; 33 bits<32> Inst; 34 bits<8> factor; 35 let Inst{15...8} = factor; 36 let Inst{1...0} = 0b11; 37} 38 39let OutOperandList = (outs) in { 40def foo : Instruction { 41 let InOperandList = (ins i32imm:$factor); 42 let EncodingInfos = EncodingByHwMode< 43 [ModeA, ModeB], [fooTypeEncA, 44 fooTypeEncB] 45 >; 46 let AsmString = "foo $factor"; 47} 48 49def bar: Instruction { 50 let InOperandList = (ins i32imm:$factor); 51 let Size = 4; 52 bits<32> Inst; 53 bits<32> SoftFail; 54 bits<8> factor; 55 let Inst{31...24} = factor; 56 let Inst{1...0} = 0b10; 57 let AsmString = "bar $factor"; 58} 59 60def baz : Instruction { 61 let InOperandList = (ins i32imm:$factor); 62 bits<32> Inst; 63 let EncodingInfos = EncodingByHwMode< 64 [ModeB], [fooTypeEncA] 65 >; 66 let AsmString = "foo $factor"; 67} 68} 69 70// DECODER-LABEL: DecoderTable_ModeA32[] = 71// DECODER-DAG: Opcode: fooTypeEncA:foo 72// DECODER-DAG: Opcode: bar 73// DECODER-LABEL: DecoderTable_ModeB32[] = 74// Note that the comment says fooTypeEncA but this is actually fooTypeEncB; plumbing 75// the correct comment text through the decoder is nontrivial. 76// DECODER-DAG: Opcode: fooTypeEncA:foo 77// DECODER-DAG: Opcode: bar 78 79// ENCODER-LABEL: static const uint64_t InstBits_ModeA[] = { 80// ENCODER: UINT64_C(2), // bar 81// ENCODER: UINT64_C(12), // foo 82 83// ENCODER-LABEL: static const uint64_t InstBits_ModeB[] = { 84// ENCODER: UINT64_C(2), // bar 85// ENCODER: UINT64_C(3), // foo 86 87// ENCODER: case ::foo: { 88// ENCODER: switch (HwMode) { 89// ENCODER: default: llvm_unreachable("Unhandled HwMode"); 90// ENCODER: case 1: { 91