[llvm-commits] [llvm] r172957 - /llvm/trunk/include/llvm/IR/IRBuilder.h
Michael Gottesman
mgottesman at apple.com
Sat Jan 19 19:56:31 PST 2013
Author: mgottesman
Date: Sat Jan 19 21:56:31 2013
New Revision: 172957
URL: http://llvm.org/viewvc/llvm-project?rev=172957&view=rev
Log:
Added IRBuilder::CreateFPExtOrFPTrunc.
This method serves an analogous purpose to CreateZExtOrTrunc/CreateSExtOrTrunc
but for floating point types.
In detail, it provides a manner when one is handling conversions of floating
point types of automatically selecting fpext, fptrunc, or identity depending on
the relative bitsize of the source and destination types.
Modified:
llvm/trunk/include/llvm/IR/IRBuilder.h
Modified: llvm/trunk/include/llvm/IR/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/IRBuilder.h?rev=172957&r1=172956&r2=172957&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/IR/IRBuilder.h Sat Jan 19 21:56:31 2013
@@ -1048,6 +1048,20 @@
return CreateTrunc(V, DestTy, Name);
return V;
}
+ /// CreateFPExtOrFPTrunc - Create a FPExt or FPTrunc from the float value V to
+ /// DestTy. Return the value untouched if the type of V is already DestTy.
+ Value *CreateFPExtOrFPTrunc(Value *V, Type *DestTy,
+ const Twine &Name = "") {
+ assert(V->getType()->isFPOrFPVectorTy() &&
+ DestTy->isFPOrFPVectorTy() &&
+ "Can only FPExt/FPTrunc floating point types!");
+ Type *Ty = V->getType();
+ if (Ty->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
+ return CreateFPExt(V, DestTy, Name);
+ if (Ty->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
+ return CreateFPTrunc(V, DestTy, Name);
+ return V;
+ }
Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
return CreateCast(Instruction::FPToUI, V, DestTy, Name);
}
More information about the llvm-commits
mailing list