[llvm] r221742 - Extend intrinsic name mangling to support arrays, named structs, and function types.

Philip Reames listmail at philipreames.com
Mon Nov 24 15:25:19 PST 2014


I finally closed the loop on the requested changes in 222707.  Sorry for 
the delay.

Philip

On 11/11/2014 04:44 PM, Sean Silva wrote:
>
>
> On Tue, Nov 11, 2014 at 4:42 PM, Philip Reames 
> <listmail at philipreames.com <mailto:listmail at philipreames.com>> wrote:
>
>
>     On 11/11/2014 04:33 PM, Sean Silva wrote:
>>     Can you please beef up the comment to give a
>>     declarative/human-readable description of the mangling scheme?
>     Sure.  Will address in a follow up commit.  (Without further
>     review unless you object.)
>
>
> Go for it.
>
>
>>
>>     Also, would it make sense to document this mangling in LangRef?
>     It is currently not documented.   I don't have a strong opinion,
>     but would lean towards not documenting it.  It's arguably an
>     internal implementation detail.   There's enough rough edges
>     around this mechanism that I'm really reluctant to encourage it's
>     use, except through the programmatic APIs.  (For example, if you
>     get the naming wrong, it's a silent codegen problem.  This is not
>     new.)
>
>
> Makes sense.
>
> -- Sean Silva
>
>
>     For context, there's discussion of removing this mechanism
>     entirely since it makes the code much harder to read.  That change
>     (which might include special casing type rules around intrinsics)
>     will definitely need broader review and documentation.
>>
>>
>>     One nit:
>>
>>     +    Result += "f"; //ensure distinguishable
>>
>>     "... use proper capitalization, punctuation, etc ...."
>>     http://llvm.org/docs/CodingStandards.html#commenting
>     Will fix in follow up.
>
>>
>>     -- Sean Silva
>>
>>     On Tue, Nov 11, 2014 at 4:21 PM, Philip Reames
>>     <listmail at philipreames.com <mailto:listmail at philipreames.com>> wrote:
>>
>>         Author: reames
>>         Date: Tue Nov 11 18:21:51 2014
>>         New Revision: 221742
>>
>>         URL: http://llvm.org/viewvc/llvm-project?rev=221742&view=rev
>>         Log:
>>         Extend intrinsic name mangling to support arrays, named
>>         structs, and function types.
>>
>>         Currently, we have a type parameter mechanism for intrinsics.
>>         Rather than having to specify a separate intrinsic for each
>>         combination of argument and return types, we can specify a
>>         single intrinsic with one or more type parameters. These type
>>         parameters are passed explicitly to Intrinsic::getDeclaration
>>         or can be specified implicitly in the naming of the intrinsic
>>         function in an LL file.
>>
>>         Today, the types are limited to integer, floating point, and
>>         pointer types. With a goal of supporting symbolic targets for
>>         patchpoints and statepoints, this change adds support for
>>         function types.  The change also includes support for first
>>         class aggregate types (named structures and arrays) since
>>         these appear in function types we've encountered.
>>
>>         Reviewed by: atrick, ributzka
>>         Differential Revision: http://reviews.llvm.org/D4608
>>
>>
>>         Modified:
>>             llvm/trunk/lib/IR/Function.cpp
>>
>>         Modified: llvm/trunk/lib/IR/Function.cpp
>>         URL:
>>         http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Function.cpp?rev=221742&r1=221741&r2=221742&view=diff
>>         ==============================================================================
>>         --- llvm/trunk/lib/IR/Function.cpp (original)
>>         +++ llvm/trunk/lib/IR/Function.cpp Tue Nov 11 18:21:51 2014
>>         @@ -455,6 +455,33 @@ unsigned Function::lookupIntrinsicID() c
>>            return 0;
>>          }
>>
>>         +/// Returns a stable mangling for the type specified for use
>>         in the name
>>         +/// mangling scheme used by 'any' types in intrinsic signatures.
>>         +static std::string getMangledTypeStr(Type* Ty) {
>>         +  std::string Result;
>>         +  if (PointerType* PTyp = dyn_cast<PointerType>(Ty)) {
>>         +    Result += "p" + llvm::utostr(PTyp->getAddressSpace()) +
>>         + getMangledTypeStr(PTyp->getElementType());
>>         +  } else if (ArrayType* ATyp = dyn_cast<ArrayType>(Ty)) {
>>         +    Result += "a" + llvm::utostr(ATyp->getNumElements()) +
>>         + getMangledTypeStr(ATyp->getElementType());
>>         +  } else if (StructType* STyp = dyn_cast<StructType>(Ty)) {
>>         +    if (!STyp->isLiteral())
>>         +      Result += STyp->getName();
>>         +    else
>>         +      llvm_unreachable("TODO: implement literal types");
>>         +  } else if (FunctionType* FT = dyn_cast<FunctionType>(Ty)) {
>>         +    Result += "f_" + getMangledTypeStr(FT->getReturnType());
>>         +    for (size_t i = 0; i < FT->getNumParams(); i++)
>>         +      Result += getMangledTypeStr(FT->getParamType(i));
>>         +    if (FT->isVarArg())
>>         +      Result += "vararg";
>>         +    Result += "f"; //ensure distinguishable
>>         +  } else if (Ty)
>>         +    Result += EVT::getEVT(Ty).getEVTString();
>>         +  return Result;
>>         +}
>>         +
>>          std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
>>            assert(id < num_intrinsics && "Invalid intrinsic ID!");
>>            static const char * const Table[] = {
>>         @@ -467,12 +494,7 @@ std::string Intrinsic::getName(ID id, Ar
>>              return Table[id];
>>            std::string Result(Table[id]);
>>            for (unsigned i = 0; i < Tys.size(); ++i) {
>>         -    if (PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) {
>>         -      Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
>>         - EVT::getEVT(PTyp->getElementType()).getEVTString();
>>         -    }
>>         -    else if (Tys[i])
>>         -      Result += "." + EVT::getEVT(Tys[i]).getEVTString();
>>         +    Result += "." + getMangledTypeStr(Tys[i]);
>>            }
>>            return Result;
>>          }
>>
>>
>>         _______________________________________________
>>         llvm-commits mailing list
>>         llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
>>         http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141124/35159e88/attachment.html>


More information about the llvm-commits mailing list