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


C++ AttributeSet::addAttribute方法代码示例

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


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

示例1: whichFPReturnVariant

//
// Returns of float, double and complex need to be handled with a helper
// function.
//
static bool fixupFPReturnAndCall
  (Function &F, Module *M,  const MipsSubtarget &Subtarget) {
  bool Modified = false;
  LLVMContext &C = M->getContext();
  Type *MyVoid = Type::getVoidTy(C);
  for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
    for (BasicBlock::iterator I = BB->begin(), E = BB->end();
         I != E; ++I) {
      Instruction &Inst = *I;
      if (const ReturnInst *RI = dyn_cast<ReturnInst>(I)) {
        Value *RVal = RI->getReturnValue();
        if (!RVal) continue;
        //
        // If there is a return value and it needs a helper function,
        // figure out which one and add a call before the actual
        // return to this helper. The purpose of the helper is to move
        // floating point values from their soft float return mapping to
        // where they would have been mapped to in floating point registers.
        //
        Type *T = RVal->getType();
        FPReturnVariant RV = whichFPReturnVariant(T);
        if (RV == NoFPRet) continue;
        static const char* Helper[NoFPRet] =
          {"__mips16_ret_sf", "__mips16_ret_df", "__mips16_ret_sc",
           "__mips16_ret_dc"};
        const char *Name = Helper[RV];
        AttributeSet A;
        Value *Params[] = {RVal};
        Modified = true;
        //
        // These helper functions have a different calling ABI so
        // this __Mips16RetHelper indicates that so that later
        // during call setup, the proper call lowering to the helper
        // functions will take place.
        //
        A = A.addAttribute(C, AttributeSet::FunctionIndex,
                           "__Mips16RetHelper");
        A = A.addAttribute(C, AttributeSet::FunctionIndex,
                           Attribute::ReadNone);
        A = A.addAttribute(C, AttributeSet::FunctionIndex,
                           Attribute::NoInline);
        Value *F = (M->getOrInsertFunction(Name, A, MyVoid, T, NULL));
        CallInst::Create(F, Params, "", &Inst );
      } else if (const CallInst *CI = dyn_cast<CallInst>(I)) {
          // pic mode calls are handled by already defined
          // helper functions
          if (Subtarget.getRelocationModel() != Reloc::PIC_ ) {
            Function *F_ =  CI->getCalledFunction();
            if (F_ && !isIntrinsicInline(F_) && needsFPHelperFromSig(*F_)) {
              assureFPCallStub(*F_, M, Subtarget);
              Modified=true;
            }
          }
      }
    }
  return Modified;
}
开发者ID:benlangmuir,项目名称:llvm,代码行数:61,代码来源:Mips16HardFloat.cpp

示例2: visitCALL

Value* ARMIREmitter::visitCALL(const SDNode *N) {
  const ConstantSDNode *DestNode = dyn_cast<ConstantSDNode>(N->getOperand(0));
  if (!DestNode) {
    printError("visitCALL: Not a constant integer for call!");
    return NULL;
  }

  int64_t DestInt = DestNode->getSExtValue();
  int64_t PC = Dec->getDisassembler()->getDebugOffset(N->getDebugLoc());
  unsigned InstrSize = 8;   // Note: ARM defaults to 4; should be 8.
  int64_t Tgt = PC + InstrSize + DestInt;

  // TODO: Look up address in symbol table.
  std::string FName = Dec->getDisassembler()->getFunctionName(Tgt);

  Module *Mod = IRB->GetInsertBlock()->getParent()->getParent();

  FunctionType *FT =
      FunctionType::get(Type::getPrimitiveType(Mod->getContext(),
          Type::VoidTyID), false);

  Twine TgtAddr(Tgt);

  AttributeSet AS;
  AS = AS.addAttribute(Mod->getContext(), AttributeSet::FunctionIndex,
      "Address", TgtAddr.str());
  Value* Proto = Mod->getOrInsertFunction(FName, FT, AS);

  // CallInst* Call =
  IRB->CreateCall(dyn_cast<Value>(Proto));

  // TODO: Technically visitCall sets the LR to IP+8. We should return that.
  VisitMap[N] = NULL;
  return NULL;
}
开发者ID:AmesianX,项目名称:fracture,代码行数:35,代码来源:ARMIREmitter.cpp

示例3: processCallSite

/// Infer nonnull attributes for the arguments at the specified callsite.
static bool processCallSite(CallSite CS, LazyValueInfo *LVI) {
  SmallVector<unsigned, 4> Indices;
  unsigned ArgNo = 0;

  for (Value *V : CS.args()) {
    PointerType *Type = dyn_cast<PointerType>(V->getType());
    // Try to mark pointer typed parameters as non-null.  We skip the
    // relatively expensive analysis for constants which are obviously either
    // null or non-null to start with.
    if (Type && !CS.paramHasAttr(ArgNo + 1, Attribute::NonNull) &&
        !isa<Constant>(V) && 
        LVI->getPredicateAt(ICmpInst::ICMP_EQ, V,
                            ConstantPointerNull::get(Type),
                            CS.getInstruction()) == LazyValueInfo::False)
      Indices.push_back(ArgNo + 1);
    ArgNo++;
  }

  assert(ArgNo == CS.arg_size() && "sanity check");

  if (Indices.empty())
    return false;

  AttributeSet AS = CS.getAttributes();
  LLVMContext &Ctx = CS.getInstruction()->getContext();
  AS = AS.addAttribute(Ctx, Indices, Attribute::get(Ctx, Attribute::NonNull));
  CS.setAttributes(AS);

  return true;
}
开发者ID:sanjoy,项目名称:llvm,代码行数:31,代码来源:CorrelatedValuePropagation.cpp

示例4: removeUseSoftFloat

//
// remove the use-soft-float attribute
//
static void removeUseSoftFloat(Function &F) {
  AttributeSet A;
  DEBUG(errs() << "removing -use-soft-float\n");
  A = A.addAttribute(F.getContext(), AttributeSet::FunctionIndex,
                     "use-soft-float", "false");
  F.removeAttributes(AttributeSet::FunctionIndex, A);
  if (F.hasFnAttribute("use-soft-float")) {
    DEBUG(errs() << "still has -use-soft-float\n");
  }
  F.addAttributes(AttributeSet::FunctionIndex, A);
}
开发者ID:benlangmuir,项目名称:llvm,代码行数:14,代码来源:Mips16HardFloat.cpp

示例5: validateMissingAttributes

//==============================================================================
// ElementType::validateMissingAttributes
//
// Test if all required attributes have been specified and add attributes
// that have a default value
//
//==============================================================================
void ElementType::validateMissingAttributes(AttributeSet& attSet, bool bValidate, ParserImpl& parser) const
{
	AttributeTypeMap::const_iterator iter;
	for(iter=m_attributeTypeMap.begin(); iter!=m_attributeTypeMap.end(); ++iter)
	{
		const AutoPtr<AttributeType>& rpAttrType = (*iter).second;
		if(rpAttrType->getDefaultType() == AttributeType::REQUIRED)
		{
			if(bValidate && !attSet.getAttribute(rpAttrType->getName().getRawName()))
			{
				const String& errMsg = MessageFormatter::Format(
					System::GetSysMessage(sXML, EXML_ATTRREQUIRED,
					"required attribute '{0}' has not been supplied for element '{1}'"),
					rpAttrType->getName().getRawName(),
					getName().getRawName());

				parser.errorDetected(Parser::Error, errMsg, EXML_ATTRREQUIRED);
			}
		}
		else if(rpAttrType->getDefaultType() != AttributeType::IMPLIED)
		{
			// XML 1.0 says that attributes with default value
			// that are not present should be created
			if(!attSet.getAttribute(rpAttrType->getName().getRawName()))
			{
				AutoPtr<Attribute> rpAttr = new Attribute(rpAttrType->getName(), rpAttrType->getDefaultValue(), rpAttrType->getTypeAsString());
				
				attSet.addAttribute(rpAttr.get());

				//
				// If we have had to add a defaulted attribute, and if the attribute
				// definition is external, and the document claims to be standalone
				// then we have a vandity constraint error
				//
				if(bValidate && parser.isStandaloneDocument() && rpAttrType->isExternallyDeclared())
				{
					const String& errMsg = MessageFormatter::Format(
						System::GetSysMessage(sXML, EXML_ATTRDEFAULTNOTSA,
						"externally declared attribute '{0}' for element '{1}' has a default value of '{2}' which must be specified in a standalone document"),
						rpAttrType->getName().getRawName(),
						getName().getRawName(),
						rpAttrType->getDefaultValue());

					parser.errorDetected(Parser::Error, errMsg, EXML_ATTRDEFAULTNOTSA);
				}
			}
		}
	}
}
开发者ID:twangjie,项目名称:quickcpp,代码行数:56,代码来源:ElementType.cpp

示例6: collectEvalFunctionAttribs

AttributeSet DecisionTreeCompiler::collectEvalFunctionAttribs() {
  std::vector<std::string> features;
  for (const StringMapEntry<bool> &feature : CpuFeatures) {
    if (feature.getValue())
      features.emplace_back("+" + feature.getKey().str());
  }

  AttributeSet attributeSet;
  if (features.empty())
    return attributeSet;

  std::sort(features.begin(), features.end());
  return attributeSet.addAttribute(
      Ctx, AttributeSet::FunctionIndex, "target-features",
      join(features.begin(), features.end(), ","));
}
开发者ID:weliveindetail,项目名称:EvalTreeJit,代码行数:16,代码来源:DecisionTreeCompiler.cpp

示例7: processCallSite

/// processCallSite - Infer nonnull attributes for the arguments at the
/// specified callsite.
bool CorrelatedValuePropagation::processCallSite(CallSite CS) {
  bool Changed = false;

  unsigned ArgNo = 0;
  for (Value *V : CS.args()) {
    PointerType *Type = dyn_cast<PointerType>(V->getType());

    if (Type && !CS.paramHasAttr(ArgNo + 1, Attribute::NonNull) &&
        LVI->getPredicateAt(ICmpInst::ICMP_EQ, V,
                            ConstantPointerNull::get(Type),
                            CS.getInstruction()) == LazyValueInfo::False) {
      AttributeSet AS = CS.getAttributes();
      AS = AS.addAttribute(CS.getInstruction()->getContext(), ArgNo + 1,
                           Attribute::NonNull);
      CS.setAttributes(AS);
      Changed = true;
    }
    ArgNo++;
  }
  assert(ArgNo == CS.arg_size() && "sanity check");

  return Changed;
}
开发者ID:alessandrostone,项目名称:metashell,代码行数:25,代码来源:CorrelatedValuePropagation.cpp

示例8: visitAlloca

void AMDGPUPromoteAlloca::visitAlloca(AllocaInst &I) {
  IRBuilder<> Builder(&I);

  // First try to replace the alloca with a vector
  Type *AllocaTy = I.getAllocatedType();

  DEBUG(dbgs() << "Trying to promote " << I << '\n');

  if (tryPromoteAllocaToVector(&I))
    return;

  DEBUG(dbgs() << " alloca is not a candidate for vectorization.\n");

  // FIXME: This is the maximum work group size.  We should try to get
  // value from the reqd_work_group_size function attribute if it is
  // available.
  unsigned WorkGroupSize = 256;
  int AllocaSize = WorkGroupSize *
      Mod->getDataLayout()->getTypeAllocSize(AllocaTy);

  if (AllocaSize > LocalMemAvailable) {
    DEBUG(dbgs() << " Not enough local memory to promote alloca.\n");
    return;
  }

  std::vector<Value*> WorkList;

  if (!collectUsesWithPtrTypes(&I, WorkList)) {
    DEBUG(dbgs() << " Do not know how to convert all uses\n");
    return;
  }

  DEBUG(dbgs() << "Promoting alloca to local memory\n");
  LocalMemAvailable -= AllocaSize;

  GlobalVariable *GV = new GlobalVariable(
      *Mod, ArrayType::get(I.getAllocatedType(), 256), false,
      GlobalValue::ExternalLinkage, 0, I.getName(), 0,
      GlobalVariable::NotThreadLocal, AMDGPUAS::LOCAL_ADDRESS);

  FunctionType *FTy = FunctionType::get(
      Type::getInt32Ty(Mod->getContext()), false);
  AttributeSet AttrSet;
  AttrSet.addAttribute(Mod->getContext(), 0, Attribute::ReadNone);

  Value *ReadLocalSizeY = Mod->getOrInsertFunction(
      "llvm.r600.read.local.size.y", FTy, AttrSet);
  Value *ReadLocalSizeZ = Mod->getOrInsertFunction(
      "llvm.r600.read.local.size.z", FTy, AttrSet);
  Value *ReadTIDIGX = Mod->getOrInsertFunction(
      "llvm.r600.read.tidig.x", FTy, AttrSet);
  Value *ReadTIDIGY = Mod->getOrInsertFunction(
      "llvm.r600.read.tidig.y", FTy, AttrSet);
  Value *ReadTIDIGZ = Mod->getOrInsertFunction(
      "llvm.r600.read.tidig.z", FTy, AttrSet);


  Value *TCntY = Builder.CreateCall(ReadLocalSizeY);
  Value *TCntZ = Builder.CreateCall(ReadLocalSizeZ);
  Value *TIdX  = Builder.CreateCall(ReadTIDIGX);
  Value *TIdY  = Builder.CreateCall(ReadTIDIGY);
  Value *TIdZ  = Builder.CreateCall(ReadTIDIGZ);

  Value *Tmp0 = Builder.CreateMul(TCntY, TCntZ);
  Tmp0 = Builder.CreateMul(Tmp0, TIdX);
  Value *Tmp1 = Builder.CreateMul(TIdY, TCntZ);
  Value *TID = Builder.CreateAdd(Tmp0, Tmp1);
  TID = Builder.CreateAdd(TID, TIdZ);

  std::vector<Value*> Indices;
  Indices.push_back(Constant::getNullValue(Type::getInt32Ty(Mod->getContext())));
  Indices.push_back(TID);

  Value *Offset = Builder.CreateGEP(GV, Indices);
  I.mutateType(Offset->getType());
  I.replaceAllUsesWith(Offset);
  I.eraseFromParent();

  for (std::vector<Value*>::iterator i = WorkList.begin(),
                                     e = WorkList.end(); i != e; ++i) {
    Value *V = *i;
    CallInst *Call = dyn_cast<CallInst>(V);
    if (!Call) {
      Type *EltTy = V->getType()->getPointerElementType();
      PointerType *NewTy = PointerType::get(EltTy, AMDGPUAS::LOCAL_ADDRESS);

      // The operand's value should be corrected on its own.
      if (isa<AddrSpaceCastInst>(V))
        continue;

      // FIXME: It doesn't really make sense to try to do this for all
      // instructions.
      V->mutateType(NewTy);
      continue;
    }

    IntrinsicInst *Intr = dyn_cast<IntrinsicInst>(Call);
    if (!Intr) {
      std::vector<Type*> ArgTypes;
      for (unsigned ArgIdx = 0, ArgEnd = Call->getNumArgOperands();
//.........这里部分代码省略.........
开发者ID:A2-Collaboration,项目名称:root,代码行数:101,代码来源:AMDGPUPromoteAlloca.cpp

示例9: 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;
  int32_t ResultIndex = -1;
  SmallVector<Type *, 16> ArgumentTypes(Args.size() + NumExtraArgs);

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

  uint32_t I = 0;
  for (auto &Arg : Args) {
    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();
    }
    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());

    AttributeSet Attrs = F->getAttributes();
    F->setAttributes(
        Attrs.addAttribute(Context, F->arg_size(), "CLR_SecretParameter"));
    CC = CallingConv::CLR_SecretParameter;
  } else {
    CC = CallingConv::C;
  }
  F->setCallingConv(CC);

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

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


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