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


C++ AttrBuilder类代码示例

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


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

示例1: init_builtins

void init_builtins(CodeGenState *code_gen) {
    code_gen->builtin_types[Builtin::Void] = Type::getVoidTy(code_gen->ctx);
    code_gen->builtin_types[Builtin::S8] = Type::getInt8Ty(code_gen->ctx);
    code_gen->builtin_types[Builtin::U8] = Type::getInt8Ty(code_gen->ctx);
    code_gen->builtin_types[Builtin::S16] = Type::getInt16Ty(code_gen->ctx);
    code_gen->builtin_types[Builtin::U16] = Type::getInt16Ty(code_gen->ctx);
    code_gen->builtin_types[Builtin::S32] = Type::getInt32Ty(code_gen->ctx);
    code_gen->builtin_types[Builtin::U32] = Type::getInt32Ty(code_gen->ctx);
    code_gen->builtin_types[Builtin::S64] = Type::getInt64Ty(code_gen->ctx);
    code_gen->builtin_types[Builtin::U64] = Type::getInt64Ty(code_gen->ctx);
    code_gen->builtin_types[Builtin::Float32] = Type::getFloatTy(code_gen->ctx);
    code_gen->builtin_types[Builtin::Float64] = Type::getDoubleTy(code_gen->ctx);
    // TODO: is it a good idea to use i1 here?
    code_gen->builtin_types[Builtin::Bool] = Type::getInt1Ty(code_gen->ctx);

    {
        // TODO: read doxygen, not sure how it works
        SmallVector<AttributeSet, 4> Attrs;
        AttributeSet PAS;
        {
            AttrBuilder B;
            B.addAttribute(Attribute::NoUnwind);
            PAS = AttributeSet::get(code_gen->ctx, ~0U, B);
        }

        Attrs.push_back(PAS);
        code_gen->default_func_attr = AttributeSet::get(code_gen->ctx, Attrs);
    }
}
开发者ID:vbo,项目名称:hmlang,代码行数:29,代码来源:llvm_middleware.cpp

示例2: RemoveAttrs

// removeAttribute() currently does not work on Attribute::Alignment
// (it fails with an assertion error), so we have to take a more
// convoluted route to removing this attribute by recreating the
// AttributeSet.
AttributeSet RemoveAttrs(LLVMContext &Context, AttributeSet Attrs) {
  SmallVector<AttributeSet, 8> AttrList;
  for (unsigned Slot = 0; Slot < Attrs.getNumSlots(); ++Slot) {
    unsigned Index = Attrs.getSlotIndex(Slot);
    AttrBuilder AB;
    for (AttributeSet::iterator Attr = Attrs.begin(Slot), E = Attrs.end(Slot);
         Attr != E; ++Attr) {
      if (Attr->isEnumAttribute() &&
          Attr->getKindAsEnum() != Attribute::ByVal &&
          Attr->getKindAsEnum() != Attribute::StructRet) {
        AB.addAttribute(*Attr);
      }
      // IR semantics require that ByVal implies NoAlias.  However, IR
      // semantics do not require StructRet to imply NoAlias.  For
      // example, a global variable address can be passed as a
      // StructRet argument, although Clang does not do so and Clang
      // explicitly adds NoAlias to StructRet arguments.
      if (Attr->isEnumAttribute() &&
          Attr->getKindAsEnum() == Attribute::ByVal) {
        AB.addAttribute(Attribute::get(Context, Attribute::NoAlias));
      }
    }
    AttrList.push_back(AttributeSet::get(Context, Index, AB));
  }
  return AttributeSet::get(Context, AttrList);
}
开发者ID:eugenecode,项目名称:emscripten-fastcomp,代码行数:30,代码来源:ExpandByVal.cpp

示例3: AdjustCallerSSPLevel

/// \brief If the inlined function had a higher stack protection level than the
/// calling function, then bump up the caller's stack protection level.
static void AdjustCallerSSPLevel(Function *Caller, Function *Callee) {
  // If upgrading the SSP attribute, clear out the old SSP Attributes first.
  // Having multiple SSP attributes doesn't actually hurt, but it adds useless
  // clutter to the IR.
  AttrBuilder B;
  B.addAttribute(Attribute::StackProtect)
    .addAttribute(Attribute::StackProtectStrong)
    .addAttribute(Attribute::StackProtectReq);
  AttributeSet OldSSPAttr = AttributeSet::get(Caller->getContext(),
                                              AttributeSet::FunctionIndex,
                                              B);

  if (Callee->hasFnAttribute(Attribute::SafeStack)) {
    Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
    Caller->addFnAttr(Attribute::SafeStack);
  } else if (Callee->hasFnAttribute(Attribute::StackProtectReq) &&
             !Caller->hasFnAttribute(Attribute::SafeStack)) {
    Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
    Caller->addFnAttr(Attribute::StackProtectReq);
  } else if (Callee->hasFnAttribute(Attribute::StackProtectStrong) &&
             !Caller->hasFnAttribute(Attribute::SafeStack) &&
             !Caller->hasFnAttribute(Attribute::StackProtectReq)) {
    Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
    Caller->addFnAttr(Attribute::StackProtectStrong);
  } else if (Callee->hasFnAttribute(Attribute::StackProtect) &&
             !Caller->hasFnAttribute(Attribute::SafeStack) &&
             !Caller->hasFnAttribute(Attribute::StackProtectReq) &&
             !Caller->hasFnAttribute(Attribute::StackProtectStrong))
    Caller->addFnAttr(Attribute::StackProtect);
}
开发者ID:hsorby,项目名称:opencor,代码行数:32,代码来源:Inliner.cpp

示例4: LLVMAddFunctionAttribute

extern "C" void LLVMAddFunctionAttribute(LLVMValueRef Fn, unsigned index,
                                         uint64_t Val) {
  Function *A = unwrap<Function>(Fn);
  AttrBuilder B;
  B.addRawValue(Val);
  A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
}
开发者ID:Arubaruba,项目名称:rust,代码行数:7,代码来源:RustWrapper.cpp

示例5: assert

void X86RetpolineThunks::createThunkFunction(Module &M, StringRef Name) {
  assert(Name.startswith(ThunkNamePrefix) &&
         "Created a thunk with an unexpected prefix!");

  LLVMContext &Ctx = M.getContext();
  auto Type = FunctionType::get(Type::getVoidTy(Ctx), false);
  Function *F =
      Function::Create(Type, GlobalValue::LinkOnceODRLinkage, Name, &M);
  F->setVisibility(GlobalValue::HiddenVisibility);
  F->setComdat(M.getOrInsertComdat(Name));

  // Add Attributes so that we don't create a frame, unwind information, or
  // inline.
  AttrBuilder B;
  B.addAttribute(llvm::Attribute::NoUnwind);
  B.addAttribute(llvm::Attribute::Naked);
  F->addAttributes(llvm::AttributeList::FunctionIndex, B);

  // Populate our function a bit so that we can verify.
  BasicBlock *Entry = BasicBlock::Create(Ctx, "entry", F);
  IRBuilder<> Builder(Entry);

  Builder.CreateRetVoid();

  // MachineFunctions/MachineBasicBlocks aren't created automatically for the
  // IR-level constructs we already made. Create them and insert them into the
  // module.
  MachineFunction &MF = MMI->getOrCreateMachineFunction(*F);
  MachineBasicBlock *EntryMBB = MF.CreateMachineBasicBlock(Entry);

  // Insert EntryMBB into MF. It's not in the module until we do this.
  MF.insert(MF.end(), EntryMBB);
}
开发者ID:bkaradzic,项目名称:SwiftShader,代码行数:33,代码来源:X86RetpolineThunks.cpp

示例6: insertInstrumentation

void DynInstMarker::insertInstrumentation(BasicBlock::iterator& ii, 
                                          Function::iterator& bi,
                                            Module* mod) {
  std::vector<Type*>FuncTy_4_args;
  FunctionType* FuncTy_4 = FunctionType::get(
   /*Result=*/Type::getVoidTy(mod->getContext()),
   /*Params=*/FuncTy_4_args,
   /*isVarArg=*/false);
  
  InlineAsm* ptr_10 = InlineAsm::get(FuncTy_4, "nop", "~{dirflag},~{fpsr},~{flags}",true);
   CallInst* void_9 = CallInst::Create(ptr_10, "", (&(*ii)));
   void_9->setCallingConv(CallingConv::C);
   void_9->setTailCall(false);
   AttributeSet void_9_PAL;
   {
    SmallVector<AttributeSet, 4> Attrs;
    AttributeSet PAS;
     {
      AttrBuilder B;
      B.addAttribute(Attribute::NoUnwind);
      PAS = AttributeSet::get(mod->getContext(), ~0U, B);
     }
 
    Attrs.push_back(PAS);
    void_9_PAL = AttributeSet::get(mod->getContext(), Attrs);
 
   }
   void_9->setAttributes(void_9_PAL);
}
开发者ID:chyyuu,项目名称:gist-static-analyzer,代码行数:29,代码来源:DynInstMarker.cpp

示例7: LLVMRustAddDereferenceableAttr

extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
                                               uint64_t Bytes) {
  Function *A = unwrap<Function>(Fn);
  AttrBuilder B;
  B.addDereferenceableAttr(Bytes);
  A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B));
}
开发者ID:Boreeas,项目名称:rust,代码行数:7,代码来源:RustWrapper.cpp

示例8: LLVMAddFunctionAttrStringValue

extern "C" void LLVMAddFunctionAttrStringValue(LLVMValueRef Fn, unsigned index,
                                               const char *Name,
                                               const char *Value) {
  Function *F = unwrap<Function>(Fn);
  AttrBuilder B;
  B.addAttribute(Name, Value);
  F->addAttributes(index, AttributeSet::get(F->getContext(), index, B));
}
开发者ID:Arubaruba,项目名称:rust,代码行数:8,代码来源:RustWrapper.cpp

示例9: makeArrayRef

Value* NFunctionDeclaration::codeGen(CodeGenContext& context)
{
	vector<Type*> argTypes;
	VariableList::const_iterator it;

	for (it = arguments.begin(); it != arguments.end(); it++) 
	{
		argTypes.push_back(typeOf((**it).type));
	}
	FunctionType *ftype = FunctionType::get(typeOf(type), makeArrayRef(argTypes), false);
	Function *function = Function::Create(ftype, GlobalValue::ExternalLinkage, id.name.c_str(), context.module);
	BasicBlock *bblock = BasicBlock::Create(getGlobalContext(), "entry", function, 0);
	BasicBlock *returnBlock = BasicBlock::Create(getGlobalContext(), "return", function, 0);

	function->setCallingConv(CallingConv::C);

	AttributeSet func_func_PAL;
	{
	 	SmallVector<AttributeSet, 4> Attrs;
	  	AttributeSet PAS;
	  	{
	    	AttrBuilder B;
	    	B.addAttribute(Attribute::NoUnwind);
	    	PAS = AttributeSet::get(getGlobalContext(), ~0U, B);
	    }
	  
	  	Attrs.push_back(PAS);
	  	func_func_PAL = AttributeSet::get(getGlobalContext(), Attrs);
	}
	function->setAttributes(func_func_PAL);

	context.setCurrentFunction(function);
	context.setReturnBlock(returnBlock);
	context.isTopLevel = false;

	context.pushBlock(bblock, false);

	Function::arg_iterator argsValues = function->arg_begin();
    Value* argumentValue;

	for (it = arguments.begin(); it != arguments.end(); it++) 
	{
		(**it).codeGen(context);
		
		argumentValue = argsValues++;
		argumentValue->setName((*it)->id.name.c_str());
		StoreInst *inst = new StoreInst(argumentValue, context.locals()[(*it)->id.name], false, bblock);
	}
	
	block.codeGen(context);
	ReturnInst::Create(getGlobalContext(), context.getCurrentReturnValue(), context.getReturnBlock());

	context.popBlock();
	context.isTopLevel = true;
	std::cout << "Creating function: " << id.name << endl;
	
	return function;
}
开发者ID:maveric94,项目名称:my_toy_compiler,代码行数:58,代码来源:codegen.cpp

示例10: LLVMAddCallSiteAttribute

extern "C" void LLVMAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, uint64_t Val) {
  CallSite Call = CallSite(unwrap<Instruction>(Instr));
  AttrBuilder B;
  B.addRawValue(Val);
  Call.setAttributes(
    Call.getAttributes().addAttributes(Call->getContext(), index,
                                       AttributeSet::get(Call->getContext(),
                                                         index, B)));
}
开发者ID:Arubaruba,项目名称:rust,代码行数:9,代码来源:RustWrapper.cpp

示例11: LLVMAddDereferenceableCallSiteAttr

extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef Instr, unsigned idx, uint64_t b) {
  CallSite Call = CallSite(unwrap<Instruction>(Instr));
  AttrBuilder B;
  B.addDereferenceableAttr(b);
  Call.setAttributes(
    Call.getAttributes().addAttributes(Call->getContext(), idx,
                                       AttributeSet::get(Call->getContext(),
                                                         idx, B)));
}
开发者ID:Arubaruba,项目名称:rust,代码行数:9,代码来源:RustWrapper.cpp

示例12: removeUseSoftFloat

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

示例13: wrap

const AttributeSetImpl *LLVM_General_GetSlotAttributeSet(
	LLVMContextRef context,
	unsigned index,
	const AttributeImpl **attributes,
	unsigned length
) {
	AttrBuilder builder;
	for (unsigned i = 0; i < length; i++) builder.addAttribute(unwrap(attributes[i]));
	return wrap(AttributeSet::get(*unwrap(context), index, builder));
}
开发者ID:acowley,项目名称:llvm-general,代码行数:10,代码来源:AttributeC.cpp

示例14: addReadAttrs

static bool addReadAttrs(const SCCNodeSet &SCCNodes, AARGetterT AARGetter) {
    // Check if any of the functions in the SCC read or write memory.  If they
    // write memory then they can't be marked readnone or readonly.
    bool ReadsMemory = false;
    for (Function *F : SCCNodes) {
        // Call the callable parameter to look up AA results for this function.
        AAResults &AAR = AARGetter(*F);

        switch (checkFunctionMemoryAccess(*F, AAR, SCCNodes)) {
        case MAK_MayWrite:
            return false;
        case MAK_ReadOnly:
            ReadsMemory = true;
            break;
        case MAK_ReadNone:
            // Nothing to do!
            break;
        }
    }

    // Success!  Functions in this SCC do not access memory, or only read memory.
    // Give them the appropriate attribute.
    bool MadeChange = false;
    for (Function *F : SCCNodes) {
        if (F->doesNotAccessMemory())
            // Already perfect!
            continue;

        if (F->onlyReadsMemory() && ReadsMemory)
            // No change.
            continue;

        MadeChange = true;

        // Clear out any existing attributes.
        AttrBuilder B;
        B.addAttribute(Attribute::ReadOnly).addAttribute(Attribute::ReadNone);
        F->removeAttributes(
            AttributeSet::FunctionIndex,
            AttributeSet::get(F->getContext(), AttributeSet::FunctionIndex, B));

        // Add in the new attribute.
        F->addAttribute(AttributeSet::FunctionIndex,
                        ReadsMemory ? Attribute::ReadOnly : Attribute::ReadNone);

        if (ReadsMemory)
            ++NumReadOnly;
        else
            ++NumReadNone;
    }

    return MadeChange;
}
开发者ID:zhiyongLee,项目名称:llvm,代码行数:53,代码来源:FunctionAttrs.cpp

示例15: LLVMRemoveFunctionAttrString

extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, unsigned index, const char *Name) {
  Function *f = unwrap<Function>(fn);
  LLVMContext &C = f->getContext();
  AttrBuilder B;
  B.addAttribute(Name);
  AttributeSet to_remove = AttributeSet::get(C, index, B);

  AttributeSet attrs = f->getAttributes();
  f->setAttributes(attrs.removeAttributes(f->getContext(),
                                          index,
                                          to_remove));
}
开发者ID:Arubaruba,项目名称:rust,代码行数:12,代码来源:RustWrapper.cpp


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