From a236ea551ccf97911bb566850a09c1c72d412152 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 6 Mar 2014 17:33:55 +0000 Subject: Teach lint about address spaces llvm-svn: 203132 --- llvm/lib/IR/Instructions.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'llvm/lib/IR/Instructions.cpp') 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 -- cgit v1.2.3