summaryrefslogtreecommitdiffstats
path: root/llvm/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
commit5c14088844effd2a9ec483cc4b71be4dbacdaa57 (patch)
tree1d2f5cfd6fe7a19406980148ab11e9908daffe1a /llvm/lib/VMCore/Instructions.cpp
parent332109374a628563c43036561c49a0cee0447237 (diff)
downloadbcm5719-llvm-5c14088844effd2a9ec483cc4b71be4dbacdaa57.tar.gz
bcm5719-llvm-5c14088844effd2a9ec483cc4b71be4dbacdaa57.zip
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. llvm-svn: 32191
Diffstat (limited to 'llvm/lib/VMCore/Instructions.cpp')
-rw-r--r--llvm/lib/VMCore/Instructions.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index de1ebced7bc..8c1f47d8afb 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/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:
OpenPOWER on IntegriCloud