@@ -434,12 +434,7 @@ static std::string getAttributeMaskString(const SmallVector<Record *> Recs) {
434
434
// / \param Output stream
435
435
static void emitDXILEnums (std::vector<DXILOperationDesc> &Ops,
436
436
raw_ostream &OS) {
437
- // Sort by OpCode
438
- llvm::sort (Ops, [](DXILOperationDesc &A, DXILOperationDesc &B) {
439
- return A.OpCode < B.OpCode ;
440
- });
441
-
442
- OS << " #ifdef DXIL_OP_ENUM\n " ;
437
+ OS << " #ifdef DXIL_OP_ENUM\n\n " ;
443
438
OS << " // Enumeration for operations specified by DXIL\n " ;
444
439
OS << " enum class OpCode : unsigned {\n " ;
445
440
@@ -461,40 +456,33 @@ static void emitDXILEnums(std::vector<DXILOperationDesc> &Ops,
461
456
OS << C << " ,\n " ;
462
457
}
463
458
OS << " \n };\n\n " ;
464
- OS << " #endif // DXIL_OP_ENUM\n " ;
459
+ OS << " #undef DXIL_OP_ENUM\n " ;
460
+ OS << " #endif\n\n " ;
465
461
}
466
462
467
463
// / Emit map of DXIL operation to LLVM or DirectX intrinsic
468
464
// / \param A vector of DXIL Ops
469
465
// / \param Output stream
470
466
static void emitDXILIntrinsicMap (std::vector<DXILOperationDesc> &Ops,
471
467
raw_ostream &OS) {
472
- OS << " \n #ifdef DXIL_OP_INTRINSIC_MAP\n " ;
473
-
474
- // FIXME: use array instead of SmallDenseMap.
475
- OS << " static const SmallDenseMap<Intrinsic::ID, dxil::OpCode> LowerMap = "
476
- " {\n " ;
477
- for (auto &Op : Ops) {
468
+ OS << " #ifdef DXIL_OP_INTRINSIC\n " ;
469
+ OS << " \n " ;
470
+ for (const auto &Op : Ops) {
478
471
if (Op.Intrinsic .empty ())
479
472
continue ;
480
- // {Intrinsic::sin, dxil::OpCode::Sin},
481
- OS << " { Intrinsic::" << Op.Intrinsic << " , dxil::OpCode::" << Op.OpName
482
- << " },\n " ;
473
+ OS << " DXIL_OP_INTRINSIC(dxil::OpCode::" << Op.OpName
474
+ << " , Intrinsic::" << Op.Intrinsic << " )\n " ;
483
475
}
484
- OS << " };\n\n " ;
485
- OS << " #endif // DXIL_OP_INTRINSIC_MAP\n " ;
476
+ OS << " \n " ;
477
+ OS << " #undef DXIL_OP_INTRINSIC\n " ;
478
+ OS << " #endif\n\n " ;
486
479
}
487
480
488
481
// / Emit DXIL operation table
489
482
// / \param A vector of DXIL Ops
490
483
// / \param Output stream
491
484
static void emitDXILOperationTable (std::vector<DXILOperationDesc> &Ops,
492
485
raw_ostream &OS) {
493
- // Sort by OpCode.
494
- llvm::sort (Ops, [](DXILOperationDesc &A, DXILOperationDesc &B) {
495
- return A.OpCode < B.OpCode ;
496
- });
497
-
498
486
// Collect Names.
499
487
SequenceToOffsetTable<std::string> OpClassStrings;
500
488
SequenceToOffsetTable<std::string> OpStrings;
@@ -601,7 +589,7 @@ static void emitDXILOperationTable(std::vector<DXILOperationDesc> &Ops,
601
589
OS << " };\n\n " ;
602
590
OS << " unsigned Index = Prop.ParameterTableOffset;\n " ;
603
591
OS << " return DXILOpParameterKindTable + Index;\n " ;
604
- OS << " }\n " ;
592
+ OS << " }\n\n " ;
605
593
}
606
594
607
595
static void emitDXILOperationTableDataStructs (RecordKeeper &Records,
@@ -653,12 +641,24 @@ static void EmitDXILOperation(RecordKeeper &Records, raw_ostream &OS) {
653
641
for (auto *Record : OpIntrProps) {
654
642
DXILOps.emplace_back (DXILOperationDesc (Record));
655
643
}
644
+ // Sort by opcode.
645
+ llvm::sort (DXILOps, [](DXILOperationDesc &A, DXILOperationDesc &B) {
646
+ return A.OpCode < B.OpCode ;
647
+ });
648
+ int PrevOp = -1 ;
649
+ for (DXILOperationDesc &Desc : DXILOps) {
650
+ if (Desc.OpCode == PrevOp)
651
+ PrintFatalError (Twine (" Duplicate opcode: " ) + Twine (Desc.OpCode ));
652
+ PrevOp = Desc.OpCode ;
653
+ }
654
+
656
655
emitDXILEnums (DXILOps, OS);
657
656
emitDXILIntrinsicMap (DXILOps, OS);
658
- OS << " #ifdef DXIL_OP_OPERATION_TABLE\n " ;
657
+ OS << " #ifdef DXIL_OP_OPERATION_TABLE\n\n " ;
659
658
emitDXILOperationTableDataStructs (Records, OS);
660
659
emitDXILOperationTable (DXILOps, OS);
661
- OS << " #endif // DXIL_OP_OPERATION_TABLE\n " ;
660
+ OS << " #undef DXIL_OP_OPERATION_TABLE\n " ;
661
+ OS << " #endif\n\n " ;
662
662
}
663
663
664
664
static TableGen::Emitter::Opt X (" gen-dxil-operation" , EmitDXILOperation,
0 commit comments