@@ -1433,88 +1433,58 @@ class CastInst : public Instruction {
1433
1433
#endif
1434
1434
};
1435
1435
1436
- class SIToFPInst final : public CastInst {
1436
+ // Helper class to simplify stamping out CastInst subclasses.
1437
+ template <Instruction::Opcode Op> class CastInstImpl : public CastInst {
1437
1438
public:
1438
1439
static Value *create (Value *Src, Type *DestTy, BBIterator WhereIt,
1439
1440
BasicBlock *WhereBB, Context &Ctx,
1440
- const Twine &Name = " " );
1441
- static Value *create (Value *Src, Type *DestTy, Instruction *InsertBefore,
1442
- Context &Ctx, const Twine &Name = " " );
1443
- static Value *create (Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
1444
- Context &Ctx, const Twine &Name = " " );
1445
-
1446
- static bool classof (const Value *From) {
1447
- if (auto *I = dyn_cast<Instruction>(From))
1448
- return I->getOpcode () == Opcode::SIToFP;
1449
- return false ;
1441
+ const Twine &Name = " " ) {
1442
+ return CastInst::create (DestTy, Op, Src, WhereIt, WhereBB, Ctx, Name);
1450
1443
}
1451
- #ifndef NDEBUG
1452
- void dump (raw_ostream &OS) const final ;
1453
- LLVM_DUMP_METHOD void dump () const final ;
1454
- #endif // NDEBUG
1455
- };
1456
-
1457
- class FPToUIInst final : public CastInst {
1458
- public:
1459
- static Value *create (Value *Src, Type *DestTy, BBIterator WhereIt,
1460
- BasicBlock *WhereBB, Context &Ctx,
1461
- const Twine &Name = " " );
1462
1444
static Value *create (Value *Src, Type *DestTy, Instruction *InsertBefore,
1463
- Context &Ctx, const Twine &Name = " " );
1464
- static Value *create (Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
1465
- Context &Ctx, const Twine &Name = " " );
1466
-
1467
- static bool classof (const Value *From) {
1468
- if (auto *I = dyn_cast<Instruction>(From))
1469
- return I->getOpcode () == Opcode::FPToUI;
1470
- return false ;
1445
+ Context &Ctx, const Twine &Name = " " ) {
1446
+ return create (Src, DestTy, InsertBefore->getIterator (),
1447
+ InsertBefore->getParent (), Ctx, Name);
1471
1448
}
1472
- #ifndef NDEBUG
1473
- void dump (raw_ostream &OS) const final ;
1474
- LLVM_DUMP_METHOD void dump () const final ;
1475
- #endif // NDEBUG
1476
- };
1477
-
1478
- class FPToSIInst final : public CastInst {
1479
- public:
1480
- static Value *create (Value *Src, Type *DestTy, BBIterator WhereIt,
1481
- BasicBlock *WhereBB, Context &Ctx,
1482
- const Twine &Name = " " );
1483
- static Value *create (Value *Src, Type *DestTy, Instruction *InsertBefore,
1484
- Context &Ctx, const Twine &Name = " " );
1485
1449
static Value *create (Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
1486
- Context &Ctx, const Twine &Name = " " );
1450
+ Context &Ctx, const Twine &Name = " " ) {
1451
+ return create (Src, DestTy, InsertAtEnd->end (), InsertAtEnd, Ctx, Name);
1452
+ }
1487
1453
1488
1454
static bool classof (const Value *From) {
1489
1455
if (auto *I = dyn_cast<Instruction>(From))
1490
- return I->getOpcode () == Opcode::FPToSI ;
1456
+ return I->getOpcode () == Op ;
1491
1457
return false ;
1492
1458
}
1493
- #ifndef NDEBUG
1494
- void dump (raw_ostream &OS) const final ;
1495
- LLVM_DUMP_METHOD void dump () const final ;
1496
- #endif // NDEBUG
1497
1459
};
1498
1460
1499
- class IntToPtrInst final : public CastInst {
1461
+ class SIToFPInst final : public CastInstImpl<Instruction::Opcode::SIToFP> {};
1462
+ class FPToUIInst final : public CastInstImpl<Instruction::Opcode::FPToUI> {};
1463
+ class FPToSIInst final : public CastInstImpl<Instruction::Opcode::FPToSI> {};
1464
+ class IntToPtrInst final : public CastInstImpl<Instruction::Opcode::IntToPtr> {
1465
+ };
1466
+ class PtrToIntInst final : public CastInstImpl<Instruction::Opcode::PtrToInt> {
1467
+ };
1468
+ class BitCastInst final : public CastInstImpl<Instruction::Opcode::BitCast> {};
1469
+ class AddrSpaceCastInst final
1470
+ : public CastInstImpl<Instruction::Opcode::AddrSpaceCast> {
1500
1471
public:
1501
- static Value *create (Value *Src, Type *DestTy, BBIterator WhereIt,
1502
- BasicBlock *WhereBB, Context &Ctx,
1503
- const Twine &Name = " " );
1504
- static Value *create (Value *Src, Type *DestTy, Instruction *InsertBefore,
1505
- Context &Ctx, const Twine &Name = " " );
1506
- static Value *create (Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
1507
- Context &Ctx, const Twine &Name = " " );
1508
-
1509
- static bool classof (const Value *From) {
1510
- if (auto *I = dyn_cast<Instruction>(From))
1511
- return I->getOpcode () == Opcode::IntToPtr;
1512
- return false ;
1472
+ // / \Returns the pointer operand.
1473
+ Value *getPointerOperand () { return getOperand (0 ); }
1474
+ // / \Returns the pointer operand.
1475
+ const Value *getPointerOperand () const {
1476
+ return const_cast <AddrSpaceCastInst *>(this )->getPointerOperand ();
1477
+ }
1478
+ // / \Returns the operand index of the pointer operand.
1479
+ static unsigned getPointerOperandIndex () { return 0u ; }
1480
+ // / \Returns the address space of the pointer operand.
1481
+ unsigned getSrcAddressSpace () const {
1482
+ return getPointerOperand ()->getType ()->getPointerAddressSpace ();
1483
+ }
1484
+ // / \Returns the address space of the result.
1485
+ unsigned getDestAddressSpace () const {
1486
+ return getType ()->getPointerAddressSpace ();
1513
1487
}
1514
- #ifndef NDEBUG
1515
- void dump (raw_ostream &OS) const final ;
1516
- LLVM_DUMP_METHOD void dump () const final ;
1517
- #endif // NDEBUG
1518
1488
};
1519
1489
1520
1490
class PHINode final : public Instruction {
@@ -1611,83 +1581,6 @@ class PHINode final : public Instruction {
1611
1581
LLVM_DUMP_METHOD void dump () const override ;
1612
1582
#endif
1613
1583
};
1614
- class PtrToIntInst final : public CastInst {
1615
- public:
1616
- static Value *create (Value *Src, Type *DestTy, BBIterator WhereIt,
1617
- BasicBlock *WhereBB, Context &Ctx,
1618
- const Twine &Name = " " );
1619
- static Value *create (Value *Src, Type *DestTy, Instruction *InsertBefore,
1620
- Context &Ctx, const Twine &Name = " " );
1621
- static Value *create (Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
1622
- Context &Ctx, const Twine &Name = " " );
1623
-
1624
- static bool classof (const Value *From) {
1625
- return isa<Instruction>(From) &&
1626
- cast<Instruction>(From)->getOpcode () == Opcode::PtrToInt;
1627
- }
1628
- #ifndef NDEBUG
1629
- void dump (raw_ostream &OS) const final ;
1630
- LLVM_DUMP_METHOD void dump () const final ;
1631
- #endif // NDEBUG
1632
- };
1633
-
1634
- class BitCastInst : public CastInst {
1635
- public:
1636
- static Value *create (Value *Src, Type *DestTy, BBIterator WhereIt,
1637
- BasicBlock *WhereBB, Context &Ctx,
1638
- const Twine &Name = " " );
1639
- static Value *create (Value *Src, Type *DestTy, Instruction *InsertBefore,
1640
- Context &Ctx, const Twine &Name = " " );
1641
- static Value *create (Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
1642
- Context &Ctx, const Twine &Name = " " );
1643
-
1644
- static bool classof (const Value *From) {
1645
- if (auto *I = dyn_cast<Instruction>(From))
1646
- return I->getOpcode () == Instruction::Opcode::BitCast;
1647
- return false ;
1648
- }
1649
- #ifndef NDEBUG
1650
- void dump (raw_ostream &OS) const override ;
1651
- LLVM_DUMP_METHOD void dump () const override ;
1652
- #endif
1653
- };
1654
-
1655
- class AddrSpaceCastInst : public CastInst {
1656
- public:
1657
- static Value *create (Value *Src, Type *DestTy, BBIterator WhereIt,
1658
- BasicBlock *WhereBB, Context &Ctx,
1659
- const Twine &Name = " " );
1660
- static Value *create (Value *Src, Type *DestTy, Instruction *InsertBefore,
1661
- Context &Ctx, const Twine &Name = " " );
1662
- static Value *create (Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
1663
- Context &Ctx, const Twine &Name = " " );
1664
-
1665
- static bool classof (const Value *From) {
1666
- if (auto *I = dyn_cast<Instruction>(From))
1667
- return I->getOpcode () == Opcode::AddrSpaceCast;
1668
- return false ;
1669
- }
1670
- // / \Returns the pointer operand.
1671
- Value *getPointerOperand () { return getOperand (0 ); }
1672
- // / \Returns the pointer operand.
1673
- const Value *getPointerOperand () const {
1674
- return const_cast <AddrSpaceCastInst *>(this )->getPointerOperand ();
1675
- }
1676
- // / \Returns the operand index of the pointer operand.
1677
- static unsigned getPointerOperandIndex () { return 0u ; }
1678
- // / \Returns the address space of the pointer operand.
1679
- unsigned getSrcAddressSpace () const {
1680
- return getPointerOperand ()->getType ()->getPointerAddressSpace ();
1681
- }
1682
- // / \Returns the address space of the result.
1683
- unsigned getDestAddressSpace () const {
1684
- return getType ()->getPointerAddressSpace ();
1685
- }
1686
- #ifndef NDEBUG
1687
- void dump (raw_ostream &OS) const override ;
1688
- LLVM_DUMP_METHOD void dump () const override ;
1689
- #endif
1690
- };
1691
1584
1692
1585
// / An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to
1693
1586
// / an OpaqueInstr.
0 commit comments