mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
Implement createIntegerCast and createFPCast factory methods for handling
integer and floating point cast creation. createIntegerCast generates ZExt/SExt, BitCast or Trunc. createFPCast generates FPExt, Bitcast, or FPTrunc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32456 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4fbcdf61e8
commit
6d81a7d2ae
@ -339,6 +339,40 @@ public:
|
|||||||
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
|
||||||
|
static CastInst *createIntegerCast(
|
||||||
|
Value *S, ///< The pointer value to be casted (operand 0)
|
||||||
|
const Type *Ty, ///< The type to which cast should be made
|
||||||
|
bool isSigned, ///< Whether to regard S as signed or not
|
||||||
|
const std::string &Name = "", ///< Name for the instruction
|
||||||
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
||||||
|
);
|
||||||
|
|
||||||
|
/// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
|
||||||
|
static CastInst *createIntegerCast(
|
||||||
|
Value *S, ///< The integer value to be casted (operand 0)
|
||||||
|
const Type *Ty, ///< The integer type to which operand is casted
|
||||||
|
bool isSigned, ///< Whether to regard S as signed or not
|
||||||
|
const std::string &Name, ///< The name for the instruction
|
||||||
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
||||||
|
);
|
||||||
|
|
||||||
|
/// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
|
||||||
|
static CastInst *createFPCast(
|
||||||
|
Value *S, ///< The floating point value to be casted
|
||||||
|
const Type *Ty, ///< The floating point type to cast to
|
||||||
|
const std::string &Name = "", ///< Name for the instruction
|
||||||
|
Instruction *InsertBefore = 0 ///< Place to insert the instruction
|
||||||
|
);
|
||||||
|
|
||||||
|
/// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
|
||||||
|
static CastInst *createFPCast(
|
||||||
|
Value *S, ///< The floating point value to be casted
|
||||||
|
const Type *Ty, ///< The floating point type to cast to
|
||||||
|
const std::string &Name, ///< The name for the instruction
|
||||||
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
||||||
|
);
|
||||||
|
|
||||||
/// @brief Create a SExt or BitCast cast instruction
|
/// @brief Create a SExt or BitCast cast instruction
|
||||||
static CastInst *createSExtOrBitCast(
|
static CastInst *createSExtOrBitCast(
|
||||||
Value *S, ///< The value to be casted (operand 0)
|
Value *S, ///< The value to be casted (operand 0)
|
||||||
|
@ -1580,6 +1580,58 @@ CastInst *CastInst::createPointerCast(Value *S, const Type *Ty,
|
|||||||
return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
|
return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty,
|
||||||
|
bool isSigned, const std::string &Name,
|
||||||
|
Instruction *InsertBefore) {
|
||||||
|
assert(C->getType()->isIntegral() && Ty->isIntegral() && "Invalid cast");
|
||||||
|
unsigned SrcBits = C->getType()->getPrimitiveSizeInBits();
|
||||||
|
unsigned DstBits = Ty->getPrimitiveSizeInBits();
|
||||||
|
Instruction::CastOps opcode =
|
||||||
|
(SrcBits == DstBits ? Instruction::BitCast :
|
||||||
|
(SrcBits > DstBits ? Instruction::Trunc :
|
||||||
|
(isSigned ? Instruction::SExt : Instruction::ZExt)));
|
||||||
|
return create(opcode, C, Ty, Name, InsertBefore);
|
||||||
|
}
|
||||||
|
|
||||||
|
CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty,
|
||||||
|
bool isSigned, const std::string &Name,
|
||||||
|
BasicBlock *InsertAtEnd) {
|
||||||
|
assert(C->getType()->isIntegral() && Ty->isIntegral() && "Invalid cast");
|
||||||
|
unsigned SrcBits = C->getType()->getPrimitiveSizeInBits();
|
||||||
|
unsigned DstBits = Ty->getPrimitiveSizeInBits();
|
||||||
|
Instruction::CastOps opcode =
|
||||||
|
(SrcBits == DstBits ? Instruction::BitCast :
|
||||||
|
(SrcBits > DstBits ? Instruction::Trunc :
|
||||||
|
(isSigned ? Instruction::SExt : Instruction::ZExt)));
|
||||||
|
return create(opcode, C, Ty, Name, InsertAtEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
CastInst *CastInst::createFPCast(Value *C, const Type *Ty,
|
||||||
|
const std::string &Name,
|
||||||
|
Instruction *InsertBefore) {
|
||||||
|
assert(C->getType()->isFloatingPoint() && Ty->isFloatingPoint() &&
|
||||||
|
"Invalid cast");
|
||||||
|
unsigned SrcBits = C->getType()->getPrimitiveSizeInBits();
|
||||||
|
unsigned DstBits = Ty->getPrimitiveSizeInBits();
|
||||||
|
Instruction::CastOps opcode =
|
||||||
|
(SrcBits == DstBits ? Instruction::BitCast :
|
||||||
|
(SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
|
||||||
|
return create(opcode, C, Ty, Name, InsertBefore);
|
||||||
|
}
|
||||||
|
|
||||||
|
CastInst *CastInst::createFPCast(Value *C, const Type *Ty,
|
||||||
|
const std::string &Name,
|
||||||
|
BasicBlock *InsertAtEnd) {
|
||||||
|
assert(C->getType()->isFloatingPoint() && Ty->isFloatingPoint() &&
|
||||||
|
"Invalid cast");
|
||||||
|
unsigned SrcBits = C->getType()->getPrimitiveSizeInBits();
|
||||||
|
unsigned DstBits = Ty->getPrimitiveSizeInBits();
|
||||||
|
Instruction::CastOps opcode =
|
||||||
|
(SrcBits == DstBits ? Instruction::BitCast :
|
||||||
|
(SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
|
||||||
|
return create(opcode, C, Ty, Name, InsertAtEnd);
|
||||||
|
}
|
||||||
|
|
||||||
// Provide a way to get a "cast" where the cast opcode is inferred from the
|
// Provide a way to get a "cast" where the cast opcode is inferred from the
|
||||||
// types and size of the operand. This, basically, is a parallel of the
|
// types and size of the operand. This, basically, is a parallel of the
|
||||||
// logic in the checkCast function below. This axiom should hold:
|
// logic in the checkCast function below. This axiom should hold:
|
||||||
|
Loading…
Reference in New Issue
Block a user