本文整理汇总了C++中AttrBuilder::addAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ AttrBuilder::addAttribute方法的具体用法?C++ AttrBuilder::addAttribute怎么用?C++ AttrBuilder::addAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AttrBuilder
的用法示例。
在下文中一共展示了AttrBuilder::addAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例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);
}
示例3: 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);
}
}
示例4: 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);
}
示例5: 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);
}
示例6: 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));
}
示例7: needPassByRef
bool needPassByRef(jl_datatype_t *dt, AttrBuilder &ab) override
{
size_t size = jl_datatype_size(dt);
if (is_complex64(dt) || is_complex128(dt) || (jl_is_primitivetype(dt) && size <= 8))
return false;
ab.addAttribute(Attribute::ByVal);
return true;
}
示例8: codeGen
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;
}
示例9: 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);
}
示例10: 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));
}
示例11: needPassByRef
bool needPassByRef(jl_datatype_t *dt, AttrBuilder &ab) override
{
jl_datatype_t *ty0 = NULL;
bool hva = false;
if (jl_datatype_size(dt) > 64 && isHFA(dt, &ty0, &hva) > 8) {
ab.addAttribute(Attribute::ByVal);
return true;
}
return false;
}
示例12: 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;
}
示例13: 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));
}
示例14: addArgumentReturnedAttrs
/// Deduce returned attributes for the SCC.
static bool addArgumentReturnedAttrs(const SCCNodeSet &SCCNodes) {
bool Changed = false;
AttrBuilder B;
B.addAttribute(Attribute::Returned);
// Check each function in turn, determining if an argument is always returned.
for (Function *F : SCCNodes) {
// We can infer and propagate function attributes only when we know that the
// definition we'll get at link time is *exactly* the definition we see now.
// For more details, see GlobalValue::mayBeDerefined.
if (!F->hasExactDefinition())
continue;
if (F->getReturnType()->isVoidTy())
continue;
// There is nothing to do if an argument is already marked as 'returned'.
if (any_of(F->args(),
[](const Argument &Arg) { return Arg.hasReturnedAttr(); }))
continue;
auto FindRetArg = [&]() -> Value * {
Value *RetArg = nullptr;
for (BasicBlock &BB : *F)
if (auto *Ret = dyn_cast<ReturnInst>(BB.getTerminator())) {
// Note that stripPointerCasts should look through functions with
// returned arguments.
Value *RetVal = Ret->getReturnValue()->stripPointerCasts();
if (!isa<Argument>(RetVal) || RetVal->getType() != F->getReturnType())
return nullptr;
if (!RetArg)
RetArg = RetVal;
else if (RetArg != RetVal)
return nullptr;
}
return RetArg;
};
if (Value *RetArg = FindRetArg()) {
auto *A = cast<Argument>(RetArg);
A->addAttr(AttributeSet::get(F->getContext(), A->getArgNo() + 1, B));
++NumReturned;
Changed = true;
}
}
return Changed;
}
示例15: sprintf
/**
* Set the shader type we want to compile
*
* @param type shader type to set
*/
extern "C" void
radeon_llvm_shader_type(LLVMValueRef F, unsigned type)
{
Function *Func = unwrap<Function>(F);
int Idx = AttributeSet::FunctionIndex;
AttrBuilder B;
char Str[2];
sprintf(Str, "%1d", type);
B.addAttribute("ShaderType", Str);
AttributeSet Set = AttributeSet::get(Func->getContext(), Idx, B);
Func->addAttributes(Idx, Set);
}