brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.5 KiB · 36c6521 Raw
265 lines · plain
1// RUN: llvm-tblgen -gen-emitter -I %p/../../include %s | \2// RUN:     FileCheck %s --check-prefix=ENCODER3// RUN: llvm-tblgen -gen-disassembler -I %p/../../include %s | \4// RUN:     FileCheck %s --check-prefix=DECODER5// RUN: llvm-tblgen -gen-disassembler --suppress-per-hwmode-duplicates=O1 -I \6// RUN:     %p/../../include %s | FileCheck %s --check-prefix=DECODER-SUPPRESS-O17// RUN: llvm-tblgen -gen-disassembler --suppress-per-hwmode-duplicates=O2 -I \8// RUN:     %p/../../include %s | FileCheck %s --check-prefix=DECODER-SUPPRESS-O29 10include "llvm/Target/Target.td"11 12def archInstrInfo : InstrInfo { }13 14def arch : Target {15  let InstructionSet = archInstrInfo;16}17 18def Myi32 : Operand<i32> {19  let DecoderMethod = "DecodeMyi32";20}21 22def HasA : Predicate<"Subtarget->hasA()">;23def HasB : Predicate<"Subtarget->hasB()">;24 25def ModeA : HwMode<[HasA]>; // Mode 126def ModeB : HwMode<[HasB]>; // Mode 227def ModeC : HwMode<[]>;     // Mode 328 29 30def fooTypeEncDefault : InstructionEncoding {31  let Size = 8;32  field bits<64> SoftFail = 0;33  bits<64> Inst;34  bits<8> factor;35  let Inst{7...0} = factor;36  let Inst{3...2} = 0b10;37  let Inst{1...0} = 0b00;38}39 40def fooTypeEncA : InstructionEncoding {41  let Size = 4;42  field bits<32> SoftFail = 0;43  bits<32> Inst;44  bits<8> factor;45  let Inst{7...0} = factor;46  let Inst{3...2} = 0b11;47  let Inst{1...0} = 0b00;48}49 50def fooTypeEncB : InstructionEncoding {51  let Size = 4;52  field bits<32> SoftFail = 0;53  bits<32> Inst;54  bits<8> factor;55  let Inst{15...8} = factor;56  let Inst{1...0} = 0b11;57}58 59def fooTypeEncC : InstructionEncoding {60  let Size = 4;61  field bits<32> SoftFail = 0;62  bits<32> Inst;63  bits<8> factor;64  let Inst{31...24} = factor;65  let Inst{23...21} = 0b110;66  let Inst{1...0} = 0b11;67}68 69// Test for DefaultMode as a selector.70def foo : Instruction {71  let OutOperandList = (outs);72  let InOperandList = (ins i32imm:$factor);73  let EncodingInfos = EncodingByHwMode<74  [ModeC, ModeA, ModeB, DefaultMode],75  [fooTypeEncC, fooTypeEncA, fooTypeEncB, fooTypeEncDefault]>;76  let AsmString = "foo  $factor";77}78 79def bar: Instruction {80  let OutOperandList = (outs);81  let InOperandList = (ins i32imm:$factor);82  let Size = 4;83  bits<32> Inst;84  bits<32> SoftFail;85  bits<8> factor;86  let Inst{31...24} = factor;87  let Inst{1...0} = 0b10;88  let AsmString = "bar  $factor";89}90 91def baz : Instruction {92  let OutOperandList = (outs);93  let InOperandList = (ins i32imm:$factor);94  bits<32> Inst;95  let EncodingInfos = EncodingByHwMode<96    [ModeB], [fooTypeEncA]97  >;98  let AsmString = "foo  $factor";99}100 101def unrelated: Instruction {102  let OutOperandList = (outs);103  let DecoderNamespace = "Alt";104  let InOperandList = (ins i32imm:$factor);105  let Size = 4;106  bits<32> Inst;107  bits<32> SoftFail;108  bits<8> factor;109  let Inst{31...24} = factor;110  let Inst{1...0} = 0b10;111  let AsmString = "unrelated  $factor";112}113 114 115// Under default settings, using 'HwMode' to dictate instruction encodings results in116// significant duplication of DecoderTables. The four tables ‘DecoderTableAlt32’,117// ‘DecoderTableAlt_ModeA32’, ‘DecoderTableAlt_ModeB32’ and 'DecoderTable_ModeC32' are118// exact duplicates and could effectively be merged into one.119// DECODER-LABEL: DecoderTable32120// DECODER-DAG: decode to bar121// DECODER-LABEL: DecoderTable_ModeA32122// DECODER-DAG: decode to fooTypeEncA:foo123// DECODER-DAG: decode to bar124// DECODER-LABEL: DecoderTable_ModeB32125// DECODER-DAG: decode to fooTypeEncB:foo126// DECODER-DAG: decode to fooTypeEncA:baz127// DECODER-DAG: decode to bar128// DECODER-LABEL: DecoderTable_ModeC32129// DECODER-DAG: decode to fooTypeEncC:foo130// DECODER-DAG: decode to bar131// DECODER-LABEL: DecoderTableAlt32132// DECODER-DAG: decode to unrelated133// DECODER-LABEL: DecoderTableAlt_ModeA32134// DECODER-DAG: decode to unrelated135// DECODER-LABEL: DecoderTableAlt_ModeB32136// DECODER-DAG: decode to unrelated137// DECODER-LABEL: DecoderTableAlt_ModeC32138// DECODER-DAG: decode to unrelated139// DECODER-LABEL: DecoderTable64140// DECODER-DAG: decode to fooTypeEncDefault:foo141 142// Under the 'O1' optimization level, unnecessary duplicate tables will be eliminated,143// reducing the four ‘Alt’ tables down to just one.144// DECODER-SUPPRESS-O1-LABEL: DecoderTable32145// DECODER-SUPPRESS-O1-DAG: decode to bar146// DECODER-SUPPRESS-O1-LABEL: DecoderTable_ModeA32147// DECODER-SUPPRESS-O1-DAG: decode to fooTypeEncA:foo148// DECODER-SUPPRESS-O1-DAG: decode to bar149// DECODER-SUPPRESS-O1-LABEL: DecoderTable_ModeB32150// DECODER-SUPPRESS-O1-DAG: decode to fooTypeEncB:foo151// DECODER-SUPPRESS-O1-DAG: decode to fooTypeEncA:baz152// DECODER-SUPPRESS-O1-DAG: decode to bar153// DECODER-SUPPRESS-O1-LABEL: DecoderTable_ModeC32154// DECODER-SUPPRESS-O1-DAG: decode to fooTypeEncC:foo155// DECODER-SUPPRESS-O1-DAG: decode to bar156// DECODER-SUPPRESS-O1-LABEL: DecoderTableAlt32157// DECODER-SUPPRESS-O1-DAG: decode to unrelated158// DECODER-SUPPRESS-O1-LABEL: DecoderTable64159// DECODER-SUPPRESS-O1-DAG: decode to fooTypeEncDefault:foo160 161// Under the 'O2' optimization condition, instructions possessing the 'EncodingByHwMode'162// attribute will be extracted from their original DecoderNamespace and placed into their163// respective HwMode tables. Meanwhile, other instructions that do not have the 'EncodingByHwMode'164// attribute but are within the same DecoderNamespace will be stored in the 'Default' table. This165// approach will significantly reduce instruction redundancy, but it necessitates users to thoroughly166// consider the interplay between HwMode and DecoderNamespace for their instructions.167// DECODER-SUPPRESS-O2-LABEL: DecoderTable32168// DECODER-SUPPRESS-O2-DAG: decode to bar169// DECODER-SUPPRESS-O2-LABEL: DecoderTable_ModeA32170// DECODER-SUPPRESS-O2-DAG: decode to fooTypeEncA:foo171// DECODER-SUPPRESS-O2-NOT: decode to bar172// DECODER-SUPPRESS-O2-LABEL: DecoderTable_ModeB32173// DECODER-SUPPRESS-O2-DAG: decode to fooTypeEncB:foo174// DECODER-SUPPRESS-O2-DAG: decode to fooTypeEncA:baz175// DECODER-SUPPRESS-O2-NOT: decode to bar176// DECODER-SUPPRESS-O2-LABEL: DecoderTable_ModeC32177// DECODER-SUPPRESS-O2-DAG: decode to fooTypeEncC:foo178// DECODER-SUPPRESS-O2-NOT: decode to bar179// DECODER-SUPPRESS-O2-LABEL: DecoderTableAlt32180// DECODER-SUPPRESS-O2-DAG: decode to unrelated181// DECODER-SUPPRESS-O2-LABEL: DecoderTable64182// DECODER-SUPPRESS-O2-NOT: decode to bar183// DECODER-SUPPRESS-O2-DAG: decode to fooTypeEncDefault:foo184 185// For 'bar' and 'unrelated', we didn't assign any HwModes for them,186// they should keep the same in the following four tables.187// For 'foo' we assigned four HwModes( includes 'DefaultMode' ),188// it's encodings should be different in the following four tables.189// For 'baz' we only assigned ModeB for it, so it will be presented190// as '0' in the tables of ModeA, ModeC and Default Mode.191// ENCODER-LABEL:   static const uint64_t InstBits[] = {192// ENCODER-NEXT:    UINT64_C(2),        // bar193// ENCODER-NEXT:    UINT64_C(0),        // baz194// ENCODER-NEXT:    UINT64_C(8),        // foo195// ENCODER-NEXT:    UINT64_C(2),        // unrelated196// ENCODER-NEXT:    };197// ENCODER-LABEL:   static const uint64_t InstBits_ModeA[] = {198// ENCODER-NEXT:    UINT64_C(2),        // bar199// ENCODER-NEXT:    UINT64_C(0),        // baz200// ENCODER-NEXT:    UINT64_C(12),       // foo201// ENCODER-NEXT:    UINT64_C(2),        // unrelated202// ENCODER-NEXT:    };203// ENCODER-LABEL:   static const uint64_t InstBits_ModeB[] = {204// ENCODER-NEXT:    UINT64_C(2),        // bar205// ENCODER-NEXT:    UINT64_C(12),       // baz206// ENCODER-NEXT:    UINT64_C(3),        // foo207// ENCODER-NEXT:    UINT64_C(2),        // unrelated208// ENCODER-NEXT:    };209// ENCODER-LABEL:   static const uint64_t InstBits_ModeC[] = {210// ENCODER-NEXT:    UINT64_C(2),        // bar211// ENCODER-NEXT:    UINT64_C(0),        // baz212// ENCODER-NEXT:    UINT64_C(12582915), // foo213// ENCODER-NEXT:    UINT64_C(2),        // unrelated214// ENCODER-NEXT:    };215 216// ENCODER-LABEL: case ::bar:217// ENCODER-LABEL: case ::unrelated:218// ENCODER-NOT: getHwMode219// ENCODER-LABEL: case ::foo: {220// ENCODER: unsigned HwMode = STI.getHwMode(MCSubtargetInfo::HwMode_EncodingInfo);221// ENCODER: switch (HwMode) {222// ENCODER: default: llvm_unreachable("Unknown hardware mode!"); break;223// ENCODER: case 0: InstBitsByHw = InstBits; break;224// ENCODER: case 1: InstBitsByHw = InstBits_ModeA; break;225// ENCODER: case 2: InstBitsByHw = InstBits_ModeB; break;226// ENCODER: case 3: InstBitsByHw = InstBits_ModeC; break;227// ENCODER: };228// ENCODER: Value = InstBitsByHw[TableIndex];229// ENCODER: switch (HwMode) {230// ENCODER: default: llvm_unreachable("Unhandled HwMode");231// ENCODER: case 0: {232// ENCODER: op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);233// ENCODER: Value |= (op & 0xf0);234// ENCODER: break;235// ENCODER: }236// ENCODER: case 1: {237// ENCODER: op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);238// ENCODER: Value |= (op & 0xf0);239// ENCODER: break;240// ENCODER: }241// ENCODER: case 2: {242// ENCODER: op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);243// ENCODER: Value |= (op & 0xff) << 8;244// ENCODER: break;245// ENCODER: }246// ENCODER: case 3: {247// ENCODER: op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);248// ENCODER: Value |= (op & 0xff) << 24;249// ENCODER: break;250// ENCODER: }251// ENCODER-LABEL: case ::baz: {252// ENCODER: unsigned HwMode = STI.getHwMode(MCSubtargetInfo::HwMode_EncodingInfo);253// ENCODER: switch (HwMode) {254// ENCODER: default: llvm_unreachable("Unknown hardware mode!"); break;255// ENCODER: case 2: InstBitsByHw = InstBits_ModeB; break;256// ENCODER: };257// ENCODER: Value = InstBitsByHw[TableIndex];258// ENCODER: switch (HwMode) {259// ENCODER: default: llvm_unreachable("Unhandled HwMode");260// ENCODER: case 2: {261// ENCODER: op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);262// ENCODER: Value |= (op & 0xf0);263// ENCODER: break;264// ENCODER: }265