[llvm-commits] [llvm] r85189 - in /llvm/trunk: include/llvm/Intrinsics.td lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp lib/Transforms/Scalar/SimplifyLibCalls.cpp
Nick Lewycky
nicholas at mxc.ca
Mon Oct 26 21:43:56 PDT 2009
Eric Christopher wrote:
> Author: echristo
> Date: Mon Oct 26 19:52:25 2009
> New Revision: 85189
>
> URL: http://llvm.org/viewvc/llvm-project?rev=85189&view=rev
> Log:
> Add objectsize intrinsic and hook it up through codegen. Doesn't
> do anything than return "I don't know" at the moment.
Please document this in the LangRef.
Nick
> Modified:
> llvm/trunk/include/llvm/Intrinsics.td
> llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
> llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
>
> Modified: llvm/trunk/include/llvm/Intrinsics.td
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Intrinsics.td?rev=85189&r1=85188&r2=85189&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Intrinsics.td (original)
> +++ llvm/trunk/include/llvm/Intrinsics.td Mon Oct 26 19:52:25 2009
> @@ -259,6 +259,11 @@
> def int_sigsetjmp : Intrinsic<[llvm_i32_ty] , [llvm_ptr_ty, llvm_i32_ty]>;
> def int_siglongjmp : Intrinsic<[llvm_void_ty], [llvm_ptr_ty, llvm_i32_ty]>;
>
> +// Internal interface for object size checking
> +def int_objectsize : Intrinsic<[llvm_anyint_ty], [llvm_ptr_ty, llvm_i32_ty],
> + [IntrReadArgMem]>,
> + GCCBuiltin<"__builtin_object_size">;
> +
> //===-------------------- Bit Manipulation Intrinsics ---------------------===//
> //
>
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=85189&r1=85188&r2=85189&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Mon Oct 26 19:52:25 2009
> @@ -4204,6 +4204,18 @@
> DAG.setRoot(Result);
> return 0;
> }
> + case Intrinsic::objectsize: {
> + // If we don't know by now, we're never going to know.
> + ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand(2));
> +
> + assert(CI && "Non-constant type in __builtin_object_size?");
> +
> + if (CI->getZExtValue() < 2)
> + setValue(&I, DAG.getConstant(-1, MVT::i32));
> + else
> + setValue(&I, DAG.getConstant(0, MVT::i32));
> + return 0;
> + }
> case Intrinsic::var_annotation:
> // Discard annotate attributes
> return 0;
>
> Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=85189&r1=85188&r2=85189&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Mon Oct 26 19:52:25 2009
> @@ -509,6 +509,27 @@
> }
>
> //===----------------------------------------------------------------------===//
> +// Miscellaneous LibCall/Intrinsic Optimizations
> +//===----------------------------------------------------------------------===//
> +
> +namespace {
> +struct SizeOpt : public LibCallOptimization {
> + virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
> + // TODO: We can do more with this, but delaying to here should be no change
> + // in behavior.
> + ConstantInt *Const = dyn_cast<ConstantInt>(CI->getOperand(2));
> +
> + if (!Const) return 0;
> +
> + if (Const->getZExtValue() < 2)
> + return Constant::getAllOnesValue(Const->getType());
> + else
> + return ConstantInt::get(Const->getType(), 0);
> + }
> +};
> +}
> +
> +//===----------------------------------------------------------------------===//
> // String and Memory LibCall Optimizations
> //===----------------------------------------------------------------------===//
>
> @@ -1548,6 +1569,7 @@
> // Formatting and IO Optimizations
> SPrintFOpt SPrintF; PrintFOpt PrintF;
> FWriteOpt FWrite; FPutsOpt FPuts; FPrintFOpt FPrintF;
> + SizeOpt ObjectSize;
>
> bool Modified; // This is only used by doInitialization.
> public:
> @@ -1653,6 +1675,9 @@
> Optimizations["fwrite"] = &FWrite;
> Optimizations["fputs"] = &FPuts;
> Optimizations["fprintf"] = &FPrintF;
> +
> + // Miscellaneous
> + Optimizations["llvm.objectsize"] = &ObjectSize;
> }
>
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list