summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Instructions.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2014-03-06 17:33:55 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2014-03-06 17:33:55 +0000
commita236ea551ccf97911bb566850a09c1c72d412152 (patch)
treea4103d4ad4bdc6384e9a5246f58afd7cdbdd0036 /llvm/lib/IR/Instructions.cpp
parent9c86656d62eedb7c88c16421680d2be23f72e3d6 (diff)
downloadbcm5719-llvm-a236ea551ccf97911bb566850a09c1c72d412152.tar.gz
bcm5719-llvm-a236ea551ccf97911bb566850a09c1c72d412152.zip
Teach lint about address spaces
llvm-svn: 203132
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r--llvm/lib/IR/Instructions.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index c89365fcda6..c3a34a2ccd7 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -2115,8 +2115,27 @@ bool CastInst::isNoopCast(Type *IntPtrTy) const {
return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), IntPtrTy);
}
-/// This function determines if a pair of casts can be eliminated and what
-/// opcode should be used in the elimination. This assumes that there are two
+bool CastInst::isNoopCast(const DataLayout *DL) const {
+ if (!DL) {
+ // Assume maximum pointer size.
+ return isNoopCast(Type::getInt64Ty(getContext()));
+ }
+
+ Type *PtrOpTy = 0;
+ if (getOpcode() == Instruction::PtrToInt)
+ PtrOpTy = getOperand(0)->getType();
+ else if (getOpcode() == Instruction::IntToPtr)
+ PtrOpTy = getType();
+
+ Type *IntPtrTy = PtrOpTy
+ ? DL->getIntPtrType(PtrOpTy)
+ : DL->getIntPtrType(getContext(), 0);
+
+ return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), IntPtrTy);
+}
+
+/// This function determines if a pair of casts can be eliminated and what
+/// opcode should be used in the elimination. This assumes that there are two
/// instructions like this:
/// * %F = firstOpcode SrcTy %x to MidTy
/// * %S = secondOpcode MidTy %F to DstTy
OpenPOWER on IntegriCloud