[cfe-commits] r172341 - in /cfe/trunk: include/clang/Basic/Builtins.def lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtins-multipercision.c

NAKAMURA Takumi geek4civic at gmail.com
Sun Jan 13 03:30:26 PST 2013


2013/1/13 Michael Gottesman <mgottesman at apple.com>:
> Author: mgottesman
> Date: Sat Jan 12 20:22:39 2013
> New Revision: 172341
>
> URL: http://llvm.org/viewvc/llvm-project?rev=172341&view=rev
> Log:
> Added builtins for multiprecision adds.
>
> We lower all of these intrinsics into a 2x chained usage of
> uadd.with.overflow.
>
> Added:
>     cfe/trunk/test/CodeGen/builtins-multipercision.c
> Modified:
>     cfe/trunk/include/clang/Basic/Builtins.def
>     cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Builtins.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=172341&r1=172340&r2=172341&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> +++ cfe/trunk/include/clang/Basic/Builtins.def Sat Jan 12 20:22:39 2013
> @@ -925,5 +925,11 @@
>  // Annotation function
>  BUILTIN(__builtin_annotation, "v.", "tn")
>
> +// Multiprecision Arithmetic Builtins.
> +BUILTIN(__builtin_addcs, "UsUsCUsCUsCUs*", "n")
> +BUILTIN(__builtin_addc, "UiUiCUiCUiCUi*", "n")
> +BUILTIN(__builtin_addcl, "ULiULiCULiCULiCULi*", "n")
> +BUILTIN(__builtin_addcll, "ULLiULLiCULLiCULLiCULLi*", "n")
> +
>  #undef BUILTIN
>  #undef LIBBUILTIN
>
> Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=172341&r1=172340&r2=172341&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sat Jan 12 20:22:39 2013
> @@ -169,6 +169,31 @@
>                        ReturnValueSlot(), E->arg_begin(), E->arg_end(), Fn);
>  }
>
> +/// \brief Emit a call to llvm.{sadd,uadd,ssub,usub,smul,umul}.with.overflow.*
> +/// depending on IntrinsicID.
> +///
> +/// \arg CGF The current codegen function.
> +/// \arg IntrinsicID The ID for the Intrinsic we wish to generate.
> +/// \arg X The first argument to the llvm.*.with.overflow.*.
> +/// \arg Y The second argument to the llvm.*.with.overflow.*.
> +/// \arg Carry The carry returned by the llvm.*.with.overflow.*.
> +/// \returns The result (i.e. sum/product) returned by the intrinsic.
> +static llvm::Value *EmitOverflowIntrinsic(CodeGenFunction &CGF,
> +                                          const llvm::Intrinsic::ID IntrinsicID,
> +                                          llvm::Value *X, llvm::Value *Y,
> +                                          llvm::Value *&Carry) {
> +  // Make sure we have integers of the same width.
> +  assert(X->getType() == Y->getType() &&
> +         "Arguments must be the same type. (Did you forget to make sure both "
> +         "arguments have the same integer width?)");
> +
> +  ArrayRef<llvm::Type *> Type(X->getType());
> +  llvm::Value *Callee = CGF.CGM.getIntrinsic(IntrinsicID, Type);

You should not create ArrayRef with temporary value. Fixed in r172352.

(Although the pointee of Type* is immutable, ArrayRef<Type*> holds "Type**")

...Takumi



More information about the cfe-commits mailing list