Hi All, Here is the llvm-gcc patch for PR1373. It makes llvm-gcc to emit noalias parameter attribute as well as noalias intrinsic. Note this patch is just for review. Please give me some suggestion to improve it. Thanks.
Sheng.
Index: gcc/llvm-convert.cpp =================================================================== --- gcc/llvm-convert.cpp (revision 359) +++ gcc/llvm-convert.cpp (working copy) @@ -1400,6 +1400,20 @@ BranchFixups.push_back(BranchFixup(BI, isExceptionEdge)); } +// Emits noalias intrinsic if the decl has the restrict qualifier. +Value *TreeToLLVM::EmitNoAliasIntrinsic(Value *V) { + Function *noAliasFun = Intrinsic::getDeclaration(TheModule, + Intrinsic::noalias); + PointerType *PT = PointerType::get(IntegerType::Int8Ty); + const Type *VTy = V->getType(); + if (VTy != PT) { + V = Builder.CreateBitCast(V, PT, "tmp.be"); + V = Builder.CreateCall(noAliasFun, V, "tmp.noalias"); + return Builder.CreateBitCast(V, VTy, "tmp.af.noalias"); + } + return Builder.CreateCall(noAliasFun, V, "tmp.noalias"); +} + // Emits annotate intrinsic if the decl has the annotate attribute set. void TreeToLLVM::EmitAnnotateIntrinsic(Value *V, tree decl) { @@ -1561,7 +1575,7 @@ // Handle annotate attributes if (DECL_ATTRIBUTES(decl)) EmitAnnotateIntrinsic(AI, decl); - + if (TheDebugInfo) { if (DECL_NAME(decl)) { TheDebugInfo->EmitDeclare(decl, llvm::dwarf::DW_TAG_auto_variable, @@ -2425,7 +2439,10 @@ // Scalar value: emit a load. Value *Ptr = CastToType(Instruction::BitCast, LV.Ptr, PointerType::get(Ty)); - return Builder.CreateLoad(Ptr, isVolatile, "tmp"); + Value *Tmp = Builder.CreateLoad(Ptr, isVolatile, "tmp"); + if (isa<PointerType>(Tmp->getType()) && TYPE_RESTRICT(TREE_TYPE(exp))) + Tmp = EmitNoAliasIntrinsic(Tmp); + return Tmp; } else { EmitAggregateCopy(DestLoc, LV.Ptr, TREE_TYPE(exp), false, isVolatile); return 0; Index: gcc/llvm-internal.h =================================================================== --- gcc/llvm-internal.h (revision 359) +++ gcc/llvm-internal.h (working copy) @@ -453,6 +453,9 @@ /// EmitAnnotateIntrinsic - Emits call to annotate attr intrinsic void EmitAnnotateIntrinsic(Value *V, tree_node *decl); + + /// EmitNoAliasIntrinsic - Emits call to noalias intrinsic + Value *EmitNoAliasIntrinsic(Value *V); private: /// GatherTypeInfo - Walk through the expression gathering all the Index: gcc/llvm-types.cpp =================================================================== --- gcc/llvm-types.cpp (revision 359) +++ gcc/llvm-types.cpp (working copy) @@ -1006,6 +1006,11 @@ else Attributes |= ParamAttr::SExt; } + + // Compute noalias attributes. + if (TREE_CODE(ArgTy) == POINTER_TYPE) + if (TYPE_RESTRICT(ArgTy)) + Attributes |= ParamAttr::NoAlias; #ifdef LLVM_TARGET_ENABLE_REGPARM // Allow the target to mark this as inreg.
_______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits