aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-12-04 20:17:56 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-12-04 20:17:56 +0000
commit848414e49c7600e3002a4366de52d03a9638b327 (patch)
tree66a866cadf9e3a2444544b3db94ed95b17081d5d /lib/VMCore/Instructions.cpp
parent4d42fcebe3818bc7abfcac0507737082c8c1b71e (diff)
downloadexternal_llvm-848414e49c7600e3002a4366de52d03a9638b327.zip
external_llvm-848414e49c7600e3002a4366de52d03a9638b327.tar.gz
external_llvm-848414e49c7600e3002a4366de52d03a9638b327.tar.bz2
Implement new cast creation functions for both instructions and constant
expressions. These will get used to reduce clutter as we replace various calls to createInferredCast and getCast. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32191 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Instructions.cpp')
-rw-r--r--lib/VMCore/Instructions.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index de1ebce..8c1f47d 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -1500,6 +1500,54 @@ CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty,
return 0;
}
+CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ Instruction *InsertBefore) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return create(Instruction::ZExt, S, Ty, Name, InsertBefore);
+}
+
+CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return create(Instruction::ZExt, S, Ty, Name, InsertAtEnd);
+}
+
+CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ Instruction *InsertBefore) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return create(Instruction::SExt, S, Ty, Name, InsertBefore);
+}
+
+CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return create(Instruction::SExt, S, Ty, Name, InsertAtEnd);
+}
+
+CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ Instruction *InsertBefore) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return create(Instruction::Trunc, S, Ty, Name, InsertBefore);
+}
+
+CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return create(Instruction::Trunc, S, Ty, Name, InsertAtEnd);
+}
+
// 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
// logic in the checkCast function below. This axiom should hold: