当前位置: 首页>>代码示例>>C++>>正文


C++ AttrBuilder::hasAttributes方法代码示例

本文整理汇总了C++中AttrBuilder::hasAttributes方法的典型用法代码示例。如果您正苦于以下问题:C++ AttrBuilder::hasAttributes方法的具体用法?C++ AttrBuilder::hasAttributes怎么用?C++ AttrBuilder::hasAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AttrBuilder的用法示例。


在下文中一共展示了AttrBuilder::hasAttributes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ArgumentTypes

Function *ABIMethodSignature::createFunction(GenIR &Reader, Module &M) {
  // Compute the function type
  LLVMContext &Context = M.getContext();
  bool HasIndirectResult = Result.getKind() == ABIArgInfo::Indirect;
  uint32_t NumExtraArgs = HasIndirectResult ? 1 : 0;
  const uint32_t NumArgs = Args.size() + NumExtraArgs;
  int32_t ResultIndex = -1;
  SmallVector<Type *, 16> ArgumentTypes(NumArgs);
  SmallVector<AttributeSet, 16> Attrs(NumArgs + 1);

  if (HasIndirectResult) {
    ResultIndex = Signature->hasThis() ? 1 : 0;
    Result.setIndex((uint32_t)ResultIndex);
    ArgumentTypes[ResultIndex] = Reader.getManagedPointerType(Result.getType());
  } else {
    AttrBuilder RetAttrs;

    if (Result.getKind() == ABIArgInfo::ZeroExtend) {
      RetAttrs.addAttribute(Attribute::ZExt);
    } else if (Result.getKind() == ABIArgInfo::SignExtend) {
      RetAttrs.addAttribute(Attribute::SExt);
    }

    if (RetAttrs.hasAttributes()) {
      Attrs.push_back(
          AttributeSet::get(Context, AttributeSet::ReturnIndex, RetAttrs));
    }
  }

  uint32_t I = 0;
  for (auto &Arg : Args) {
    AttrBuilder ArgAttrs;

    if (ResultIndex >= 0 && I == (uint32_t)ResultIndex) {
      I++;
    }

    if (Arg.getKind() == ABIArgInfo::Indirect) {
      // TODO: byval attribute support
      ArgumentTypes[I] = Reader.getManagedPointerType(Arg.getType());
    } else {
      ArgumentTypes[I] = Arg.getType();

      if (Arg.getKind() == ABIArgInfo::ZeroExtend) {
        ArgAttrs.addAttribute(Attribute::ZExt);
      } else if (Arg.getKind() == ABIArgInfo::SignExtend) {
        ArgAttrs.addAttribute(Attribute::SExt);
      }

      if (ArgAttrs.hasAttributes()) {
        const unsigned Idx = I + 1; // Add one to accomodate the return attrs.
        Attrs.push_back(AttributeSet::get(Context, Idx, ArgAttrs));
      }
    }
    Arg.setIndex(I);

    I++;
  }

  const bool IsVarArg = false;
  FunctionType *FunctionTy =
      FunctionType::get(FuncResultType, ArgumentTypes, IsVarArg);
  Function *F = Function::Create(FunctionTy, Function::ExternalLinkage,
                                 M.getModuleIdentifier(), &M);

  // Use "param" for these initial parameter values. Numbering here
  // is strictly positional (hence includes implicit parameters).
  uint32_t N = 0;
  for (Function::arg_iterator Args = F->arg_begin(); Args != F->arg_end();
       Args++) {
    Args->setName(Twine("param") + Twine(N++));
  }

  CallingConv::ID CC;
  if (Signature->hasSecretParameter()) {
    assert((--F->arg_end())->getType()->isIntegerTy());

    AttrBuilder SecretParamAttrs;
    SecretParamAttrs.addAttribute("CLR_SecretParameter");
    Attrs.push_back(
        AttributeSet::get(Context, F->arg_size(), SecretParamAttrs));

    CC = CallingConv::CLR_SecretParameter;
  } else {
    CC = CallingConv::C;
  }
  F->setCallingConv(CC);

  if (Attrs.size() > 0) {
    F->setAttributes(AttributeSet::get(Context, Attrs));
  }

  if (Reader.JitContext->Options->DoInsertStatepoints) {
    F->setGC("coreclr");
  }

  return F;
}
开发者ID:ANDREENKOS,项目名称:llilc,代码行数:98,代码来源:abisignature.cpp

示例2: getNumABIArgs

Function *ABIMethodSignature::createFunction(GenIR &Reader, Module &M) {
  // Compute the function type
  LLVMContext &Context = M.getContext();
  bool HasIndirectResult = Result.getKind() == ABIArgInfo::Indirect;
  uint32_t NumExtraArgs = HasIndirectResult ? 1 : 0;
  const uint32_t NumArgs = getNumABIArgs() + NumExtraArgs;
  int32_t ResultIndex = -1;
  SmallVector<Type *, 16> ArgumentTypes(NumArgs);
  SmallVector<AttributeSet, 16> Attrs(NumArgs + 1);

  if (HasIndirectResult) {
    ResultIndex = Signature->hasThis() ? 1 : 0;
    Result.setIndex((uint32_t)ResultIndex);
    ArgumentTypes[ResultIndex] = Reader.getManagedPointerType(Result.getType());
  } else {
    AttrBuilder RetAttrs;

    if (Result.getKind() == ABIArgInfo::ZeroExtend) {
      RetAttrs.addAttribute(Attribute::ZExt);
    } else if (Result.getKind() == ABIArgInfo::SignExtend) {
      RetAttrs.addAttribute(Attribute::SExt);
    }

    if (RetAttrs.hasAttributes()) {
      Attrs.push_back(
          AttributeSet::get(Context, AttributeSet::ReturnIndex, RetAttrs));
    }
  }

  uint32_t I = 0;
  for (auto &Arg : Args) {
    AttrBuilder ArgAttrs;

    if (ResultIndex >= 0 && I == (uint32_t)ResultIndex) {
      I++;
    }

    switch (Arg.getKind()) {
    case ABIArgInfo::Indirect:
      ArgumentTypes[I] = Reader.getManagedPointerType(Arg.getType());
      break;

    case ABIArgInfo::Expand:
      for (const ABIArgInfo::Expansion &Exp : Arg.getExpansions()) {
        ArgumentTypes[I++] = Exp.TheType;
      }
      I--;
      break;

    case ABIArgInfo::ZeroExtend:
      ArgAttrs.addAttribute(Attribute::ZExt);
      goto direct;

    case ABIArgInfo::SignExtend:
      ArgAttrs.addAttribute(Attribute::SExt);
      goto direct;

    case ABIArgInfo::Direct: {
    direct:
      Type *ArgTy = Arg.getType();
      if (ArgTy->isStructTy()) {
        ArgTy = ArgTy->getPointerTo();
        ArgAttrs.addAttribute(Attribute::ByVal);
      }

      ArgumentTypes[I] = ArgTy;
      if (ArgAttrs.hasAttributes()) {
        const unsigned Idx = I + 1; // Add one to accomodate the return attrs.
        Attrs.push_back(AttributeSet::get(Context, Idx, ArgAttrs));
      }
    }
    }
    Arg.setIndex(I);

    I++;
  }

  const bool IsVarArg = false;
  FunctionType *FunctionTy =
      FunctionType::get(FuncResultType, ArgumentTypes, IsVarArg);
  Function *F = Function::Create(FunctionTy, Function::ExternalLinkage,
                                 M.getModuleIdentifier(), &M);

  // Use "param" for these initial parameter values. Numbering here
  // is strictly positional (hence includes implicit parameters).
  uint32_t N = 0;
  for (Function::arg_iterator Args = F->arg_begin(); Args != F->arg_end();
       Args++) {
    Args->setName(Twine("param") + Twine(N++));
  }

  CallingConv::ID CC = Signature->hasSecretParameter()
                           ? CallingConv::CLR_SecretParameter
                           : CallingConv::C;
  F->setCallingConv(CC);

  if (Attrs.size() > 0) {
    F->setAttributes(AttributeSet::get(Context, Attrs));
  }

//.........这里部分代码省略.........
开发者ID:Anbu2388,项目名称:llilc,代码行数:101,代码来源:abisignature.cpp

示例3: assert

Value *ABICallSignature::emitCall(GenIR &Reader, Value *Target, bool MayThrow,
                                  ArrayRef<Value *> Args,
                                  Value *IndirectionCell,
                                  Value **CallNode) const {
  assert(Target->getType()->isIntegerTy(Reader.TargetPointerSizeInBits));

  LLVMContext &Context = *Reader.JitContext->LLVMContext;

  // Compute the function type
  bool HasIndirectResult = Result.getKind() == ABIArgInfo::Indirect;
  bool HasIndirectionCell = IndirectionCell != nullptr;
  bool IsUnmanagedCall =
      Signature.getCallingConvention() != CORINFO_CALLCONV_DEFAULT;
  assert(((HasIndirectionCell ? 1 : 0) + (IsUnmanagedCall ? 1 : 0)) <= 1);

  uint32_t NumSpecialArgs = 0;
  if (HasIndirectionCell) {
    NumSpecialArgs = 1;
  }

  uint32_t NumExtraArgs = (HasIndirectResult ? 1 : 0) + NumSpecialArgs;
  const uint32_t NumArgs = Args.size() + NumExtraArgs;
  Value *ResultNode = nullptr;
  SmallVector<Type *, 16> ArgumentTypes(NumArgs);
  SmallVector<Value *, 16> Arguments(NumArgs);
  SmallVector<AttributeSet, 16> Attrs(NumArgs + 1);
  IRBuilder<> &Builder = *Reader.LLVMBuilder;

  // Check for calls with special args.
  //
  // Any special arguments are passed immediately preceeding the normal
  // arguments. The backend will place these arguments in the appropriate
  // registers according to the calling convention. Each special argument should
  // be machine-word-sized.
  if (HasIndirectionCell) {
    assert(IndirectionCell->getType()->isIntegerTy(
        Reader.TargetPointerSizeInBits));
    ArgumentTypes[0] = IndirectionCell->getType();
    Arguments[0] = IndirectionCell;
  }

  int32_t ResultIndex = -1;
  if (HasIndirectResult) {
    ResultIndex = (int32_t)NumSpecialArgs + (Signature.hasThis() ? 1 : 0);
    Type *ResultTy = Result.getType();
    ArgumentTypes[ResultIndex] = Reader.getUnmanagedPointerType(ResultTy);
    Arguments[ResultIndex] = ResultNode = Reader.createTemporary(ResultTy);

    if (ResultTy->isStructTy()) {
      Reader.setValueRepresentsStruct(ResultNode);
    }
  } else {
    AttrBuilder RetAttrs;

    if (Result.getKind() == ABIArgInfo::ZeroExtend) {
      RetAttrs.addAttribute(Attribute::ZExt);
    } else if (Result.getKind() == ABIArgInfo::SignExtend) {
      RetAttrs.addAttribute(Attribute::SExt);
    }

    if (RetAttrs.hasAttributes()) {
      Attrs.push_back(
          AttributeSet::get(Context, AttributeSet::ReturnIndex, RetAttrs));
    }
  }

  uint32_t I = NumSpecialArgs, J = 0;
  for (auto Arg : Args) {
    AttrBuilder ArgAttrs;

    if (ResultIndex >= 0 && I == (uint32_t)ResultIndex) {
      I++;
    }

    const ABIArgInfo &ArgInfo = this->Args[J];
    Type *ArgType = Arg->getType();

    if (ArgInfo.getKind() == ABIArgInfo::Indirect) {
      // TODO: byval attribute support
      Value *Temp = nullptr;
      if (Reader.doesValueRepresentStruct(Arg)) {
        StructType *ArgStructTy =
            cast<StructType>(ArgType->getPointerElementType());
        ArgumentTypes[I] = ArgType;
        Temp = Reader.createTemporary(ArgStructTy);
        const bool IsVolatile = false;
        Reader.copyStruct(ArgStructTy, Temp, Arg, IsVolatile);
      } else {
        ArgumentTypes[I] = ArgType->getPointerTo();
        Temp = Reader.createTemporary(ArgType);
        Builder.CreateStore(Arg, Temp);
      }
      Arguments[I] = Temp;
    } else {
      ArgumentTypes[I] = ArgInfo.getType();
      Arguments[I] = coerce(Reader, ArgInfo.getType(), Arg);

      if (ArgInfo.getKind() == ABIArgInfo::ZeroExtend) {
        ArgAttrs.addAttribute(Attribute::ZExt);
      } else if (ArgInfo.getKind() == ABIArgInfo::SignExtend) {
//.........这里部分代码省略.........
开发者ID:ANDREENKOS,项目名称:llilc,代码行数:101,代码来源:abisignature.cpp

示例4: assert

Value *ABICallSignature::emitCall(GenIR &Reader, Value *Target, bool MayThrow,
                                  ArrayRef<Value *> Args,
                                  Value *IndirectionCell, bool IsJmp,
                                  Value **CallNode) const {
  assert(isa<llvm::Function>(Target) ||
         Target->getType()->isIntegerTy(Reader.TargetPointerSizeInBits));

  LLVMContext &Context = *Reader.JitContext->LLVMContext;

  // Compute the function type
  bool HasIndirectResult = Result.getKind() == ABIArgInfo::Indirect;
  bool HasIndirectionCell = IndirectionCell != nullptr;
  bool IsUnmanagedCall =
      Signature.getCallingConvention() != CORINFO_CALLCONV_DEFAULT;
  bool CallerHasSecretParameter = Reader.MethodSignature.hasSecretParameter();
  bool IsJmpWithSecretParam = IsJmp && CallerHasSecretParameter;
  assert(((HasIndirectionCell ? 1 : 0) + (IsUnmanagedCall ? 1 : 0) +
          (IsJmpWithSecretParam ? 1 : 0)) <= 1);

  uint32_t NumSpecialArgs = 0;
  if (HasIndirectionCell || IsJmpWithSecretParam) {
    NumSpecialArgs = 1;
  }

  uint32_t NumExtraArgs = (HasIndirectResult ? 1 : 0) + NumSpecialArgs;
  const uint32_t NumArgs = getNumABIArgs() + NumExtraArgs;
  Value *ResultNode = nullptr;
  SmallVector<Type *, 16> ArgumentTypes(NumArgs);
  SmallVector<Value *, 16> Arguments(NumArgs);
  SmallVector<AttributeSet, 16> Attrs(NumArgs + 1);
  IRBuilder<> &Builder = *Reader.LLVMBuilder;

  // Check for calls with special args.
  //
  // Any special arguments are passed immediately preceeding the normal
  // arguments. The backend will place these arguments in the appropriate
  // registers according to the calling convention. Each special argument should
  // be machine-word-sized.
  if (HasIndirectionCell) {
    assert(IndirectionCell->getType()->isIntegerTy(
        Reader.TargetPointerSizeInBits));
    ArgumentTypes[0] = IndirectionCell->getType();
    Arguments[0] = IndirectionCell;
  } else if (IsJmpWithSecretParam) {
    Arguments[0] = Reader.secretParam();
    ArgumentTypes[0] = Arguments[0]->getType();
  }

  int32_t ResultIndex = -1;
  if (HasIndirectResult) {
    ResultIndex = (int32_t)NumSpecialArgs + (Signature.hasThis() ? 1 : 0);
    Type *ResultTy = Result.getType();
    // Jmp target signature has to match the caller's signature. Since we type
    // the caller's indirect result parameters as managed pointers, jmp target's
    // indirect result parameters also have to be typed as managed pointers.
    ArgumentTypes[ResultIndex] = IsJmp
                                     ? Reader.getManagedPointerType(ResultTy)
                                     : Reader.getUnmanagedPointerType(ResultTy);
    if (IsJmp) {
      // When processing jmp, pass the pointer that we got from the caller
      // rather than a pointer to a copy in the current frame.
      Arguments[ResultIndex] = ResultNode = Reader.IndirectResult;
    } else {
      Arguments[ResultIndex] = ResultNode = Reader.createTemporary(ResultTy);
    }
    if (ResultTy->isStructTy()) {
      Reader.setValueRepresentsStruct(ResultNode);
    }
  } else {
    AttrBuilder RetAttrs;

    if (Result.getKind() == ABIArgInfo::ZeroExtend) {
      RetAttrs.addAttribute(Attribute::ZExt);
    } else if (Result.getKind() == ABIArgInfo::SignExtend) {
      RetAttrs.addAttribute(Attribute::SExt);
    }

    if (RetAttrs.hasAttributes()) {
      Attrs.push_back(
          AttributeSet::get(Context, AttributeSet::ReturnIndex, RetAttrs));
    }
  }

  uint32_t I = NumSpecialArgs, J = 0;
  for (auto Arg : Args) {
    AttrBuilder ArgAttrs;

    if (ResultIndex >= 0 && I == (uint32_t)ResultIndex) {
      I++;
    }

    const ABIArgInfo &ArgInfo = this->Args[J];
    Type *ArgType = Arg->getType();

    switch (ArgInfo.getKind()) {
    case ABIArgInfo::Indirect:
      if (IsJmp) {
        // When processing jmp pass the pointer that we got from the caller
        // rather than a pointer to a copy in the current frame.
        Arguments[I] = Arg;
//.........这里部分代码省略.........
开发者ID:Anbu2388,项目名称:llilc,代码行数:101,代码来源:abisignature.cpp


注:本文中的AttrBuilder::hasAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。