本文整理汇总了C++中Attributes::hasAttributes方法的典型用法代码示例。如果您正苦于以下问题:C++ Attributes::hasAttributes方法的具体用法?C++ Attributes::hasAttributes怎么用?C++ Attributes::hasAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attributes
的用法示例。
在下文中一共展示了Attributes::hasAttributes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rewrite_invoke_site
void HeterotbbTransform::rewrite_invoke_site(Module &M, CallSite &CS,Function *NF,int type) {
// create_hetero_clone_void(f);
Instruction *OldCall = CS.getInstruction();
Instruction *NewCall; // New Call Instruction created
SmallVector<Value*, 16> Args; // Argument lists to the new call
//DEBUG(dbgs() << "Old Call Instruction:");
//OldCall->dump();
// Any attributes (parameter attribute list PAL) of the
// parallel_for_hetero is
#if defined(LLVM_3_2)
SmallVector<AttributeWithIndex, 8> AttrVec; // Attributes list to the new call
const AttrListPtr &OldCallPAL = CS.getAttributes();
// Add any return attributes.
Attributes attrs = OldCallPAL.getRetAttributes();
if (attrs.hasAttributes())
AttrVec.push_back(AttributeWithIndex::get(0, attrs));
#endif
SmallVector<AttributeSet, 8> AttrVec;
const AttributeSet &OldCallPAL = CS.getAttributes();
// Add any return attributes.
if (OldCallPAL.hasAttributes(AttributeSet::ReturnIndex))
AttrVec.push_back(AttributeSet::get(NF->getContext(),
OldCallPAL.getRetAttributes()));
CallSite::arg_iterator AI = CS.arg_begin();
Args.push_back(CS.getArgument(0)); // num_iters
//Args.push_back(CS.getArgument(1));
//params.push_back(CS.getArgument(1)->getType());
//create a new cast from class_name to i8* before the old instruction site
CastInst *StrucCast = CastInst::Create(Instruction::BitCast, CS.getArgument(1),
PointerType::get(Type::getInt8Ty(M.getContext()), 0), "temp_cast", OldCall);
//push the type into the argument list
Args.push_back(StrucCast); // struct
//push the function as third argument
Args.push_back(NF);
//NF->dump();
//NF->getType()->dump();
//Args.push_back(CS.getArgument(2));
vector</*const*/ Type *> params;
const FunctionType *FTy = NF->getFunctionType();
//#ifndef IVB_64
params.push_back(Type::getInt32Ty(M.getContext()));
/*#else
params.push_back(Type::getInt64Ty(M.getContext()));
#endif*/
params.push_back(PointerType::get(Type::getInt8Ty(M.getContext()),0));
params.push_back(NF->getType());
//params.push_back(Type::getInt32Ty(M.getContext()));
/*const*/ Type *RetTy = FTy->getReturnType();
FunctionType *NFty = FunctionType::get(RetTy,params, false);
//NF->getType()->dump();
//NFty->dump();
Constant *hetero_f_const;
//if (hetero_f_const == NULL) {
hetero_f_const = /*cast<Function>*/(M.getOrInsertFunction("offload", NFty));
//}
//hetero_f_const->dump();
NewCall = InvokeInst::Create(hetero_f_const,cast<InvokeInst>(OldCall)->getNormalDest(),cast<InvokeInst>(OldCall)->getUnwindDest(), Args, "", OldCall);
cast<InvokeInst>(NewCall)->setCallingConv(CS.getCallingConv());
//cast<InvokeInst>(NewCall)->setAttributes(AttrListPtr::get(NF->getContext(), AttrVec));
cast<InvokeInst>(NewCall)->setAttributes(AttributeSet::get(NF->getContext(), AttrVec));
//NewCall->dump();
//NewCall = CallInst::Create(hetero_f_const, Args.begin(), Args.end(), "", OldCall);
//NewCall->dump();
//cast<CallInst>(NewCall)->setCallingConv(CS.getCallingConv());
//cast<CallInst>(NewCall)->setAttributes(AttrListPtr::get(AttrVec.begin(), AttrVec.end()));
//if (CallInst *c=dyn_cast<CallInst>(OldCall)){
// if(c->isTailCall()) cast<CallInst>(NewCall)->setTailCall();
//}
char buf[32];
ConstantInt *ci;
//DEBUG(dbgs() << "original scheduler_hint=");
//CS.getArgument(2)->dump();
if (ci = dyn_cast<ConstantInt>(CS.getArgument(2))) {
DEBUG(dbgs() << "scheduler_hint=" << ci->getZExtValue());
sprintf(buf,"%d",ci->getZExtValue());
}
else {
DEBUG(dbgs() << "scheduler_hint is not supplied and assumed 0");
sprintf(buf,"%d",0);
}
Value *e2[] = {MDString::get(M.getContext(),buf)};
MDNode *n2 = MDNode::get(M.getContext(), e2);
NewCall->setMetadata("scheduler_hint",n2);
if(type==2) { //add meta data for reduction
Function *join=get_join_func(M,CS);
Value *Elts[] = {MDString::get(M.getContext(), join->getName())};
MDNode *Node = MDNode::get(M.getContext(), Elts);
NewCall->setMetadata("join_cpu",Node);
//.........这里部分代码省略.........
示例2: RemoveDeadStuffFromFunction
// RemoveDeadStuffFromFunction - Remove any arguments and return values from F
// that are not in LiveValues. Transform the function and all of the callees of
// the function to not have these arguments and return values.
//
bool DAE::RemoveDeadStuffFromFunction(Function *F) {
// Don't modify fully live functions
if (LiveFunctions.count(F))
return false;
// Start by computing a new prototype for the function, which is the same as
// the old function, but has fewer arguments and a different return type.
FunctionType *FTy = F->getFunctionType();
std::vector<Type*> Params;
// Set up to build a new list of parameter attributes.
SmallVector<AttributeWithIndex, 8> AttributesVec;
const AttrListPtr &PAL = F->getAttributes();
// The existing function return attributes.
Attributes RAttrs = PAL.getRetAttributes();
Attributes FnAttrs = PAL.getFnAttributes();
// Find out the new return value.
Type *RetTy = FTy->getReturnType();
Type *NRetTy = NULL;
unsigned RetCount = NumRetVals(F);
// -1 means unused, other numbers are the new index
SmallVector<int, 5> NewRetIdxs(RetCount, -1);
std::vector<Type*> RetTypes;
if (RetTy->isVoidTy()) {
NRetTy = RetTy;
} else {
StructType *STy = dyn_cast<StructType>(RetTy);
if (STy)
// Look at each of the original return values individually.
for (unsigned i = 0; i != RetCount; ++i) {
RetOrArg Ret = CreateRet(F, i);
if (LiveValues.erase(Ret)) {
RetTypes.push_back(STy->getElementType(i));
NewRetIdxs[i] = RetTypes.size() - 1;
} else {
++NumRetValsEliminated;
DEBUG(dbgs() << "DAE - Removing return value " << i << " from "
<< F->getName() << "\n");
}
}
else
// We used to return a single value.
if (LiveValues.erase(CreateRet(F, 0))) {
RetTypes.push_back(RetTy);
NewRetIdxs[0] = 0;
} else {
DEBUG(dbgs() << "DAE - Removing return value from " << F->getName()
<< "\n");
++NumRetValsEliminated;
}
if (RetTypes.size() > 1)
// More than one return type? Return a struct with them. Also, if we used
// to return a struct and didn't change the number of return values,
// return a struct again. This prevents changing {something} into
// something and {} into void.
// Make the new struct packed if we used to return a packed struct
// already.
NRetTy = StructType::get(STy->getContext(), RetTypes, STy->isPacked());
else if (RetTypes.size() == 1)
// One return type? Just a simple value then, but only if we didn't use to
// return a struct with that simple value before.
NRetTy = RetTypes.front();
else if (RetTypes.size() == 0)
// No return types? Make it void, but only if we didn't use to return {}.
NRetTy = Type::getVoidTy(F->getContext());
}
assert(NRetTy && "No new return type found?");
// Remove any incompatible attributes, but only if we removed all return
// values. Otherwise, ensure that we don't have any conflicting attributes
// here. Currently, this should not be possible, but special handling might be
// required when new return value attributes are added.
if (NRetTy->isVoidTy())
RAttrs =
Attributes::get(NRetTy->getContext(), AttrBuilder(RAttrs).
removeAttributes(Attributes::typeIncompatible(NRetTy)));
else
assert(!AttrBuilder(RAttrs).
hasAttributes(Attributes::typeIncompatible(NRetTy)) &&
"Return attributes no longer compatible?");
if (RAttrs.hasAttributes())
AttributesVec.push_back(AttributeWithIndex::get(AttrListPtr::ReturnIndex,
RAttrs));
// Remember which arguments are still alive.
SmallVector<bool, 10> ArgAlive(FTy->getNumParams(), false);
// Construct the new parameter list from non-dead arguments. Also construct
// a new set of parameter attributes to correspond. Skip the first parameter
// attribute, since that belongs to the return value.
unsigned i = 0;
//.........这里部分代码省略.........
示例3: CS
/// DoPromotion - This method actually performs the promotion of the specified
/// arguments, and returns the new function. At this point, we know that it's
/// safe to do so.
CallGraphNode *ArgPromotion::DoPromotion(Function *F,
SmallPtrSet<Argument*, 8> &ArgsToPromote,
SmallPtrSet<Argument*, 8> &ByValArgsToTransform) {
// Start by computing a new prototype for the function, which is the same as
// the old function, but has modified arguments.
FunctionType *FTy = F->getFunctionType();
std::vector<Type*> Params;
typedef std::set<IndicesVector> ScalarizeTable;
// ScalarizedElements - If we are promoting a pointer that has elements
// accessed out of it, keep track of which elements are accessed so that we
// can add one argument for each.
//
// Arguments that are directly loaded will have a zero element value here, to
// handle cases where there are both a direct load and GEP accesses.
//
std::map<Argument*, ScalarizeTable> ScalarizedElements;
// OriginalLoads - Keep track of a representative load instruction from the
// original function so that we can tell the alias analysis implementation
// what the new GEP/Load instructions we are inserting look like.
std::map<IndicesVector, LoadInst*> OriginalLoads;
// Attributes - Keep track of the parameter attributes for the arguments
// that we are *not* promoting. For the ones that we do promote, the parameter
// attributes are lost
SmallVector<AttributeWithIndex, 8> AttributesVec;
const AttributeSet &PAL = F->getAttributes();
// Add any return attributes.
Attributes attrs = PAL.getRetAttributes();
if (attrs.hasAttributes())
AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex,
attrs));
// First, determine the new argument list
unsigned ArgIndex = 1;
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
++I, ++ArgIndex) {
if (ByValArgsToTransform.count(I)) {
// Simple byval argument? Just add all the struct element types.
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
StructType *STy = cast<StructType>(AgTy);
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
Params.push_back(STy->getElementType(i));
++NumByValArgsPromoted;
} else if (!ArgsToPromote.count(I)) {
// Unchanged argument
Params.push_back(I->getType());
Attributes attrs = PAL.getParamAttributes(ArgIndex);
if (attrs.hasAttributes())
AttributesVec.push_back(AttributeWithIndex::get(Params.size(), attrs));
} else if (I->use_empty()) {
// Dead argument (which are always marked as promotable)
++NumArgumentsDead;
} else {
// Okay, this is being promoted. This means that the only uses are loads
// or GEPs which are only used by loads
// In this table, we will track which indices are loaded from the argument
// (where direct loads are tracked as no indices).
ScalarizeTable &ArgIndices = ScalarizedElements[I];
for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;
++UI) {
Instruction *User = cast<Instruction>(*UI);
assert(isa<LoadInst>(User) || isa<GetElementPtrInst>(User));
IndicesVector Indices;
Indices.reserve(User->getNumOperands() - 1);
// Since loads will only have a single operand, and GEPs only a single
// non-index operand, this will record direct loads without any indices,
// and gep+loads with the GEP indices.
for (User::op_iterator II = User->op_begin() + 1, IE = User->op_end();
II != IE; ++II)
Indices.push_back(cast<ConstantInt>(*II)->getSExtValue());
// GEPs with a single 0 index can be merged with direct loads
if (Indices.size() == 1 && Indices.front() == 0)
Indices.clear();
ArgIndices.insert(Indices);
LoadInst *OrigLoad;
if (LoadInst *L = dyn_cast<LoadInst>(User))
OrigLoad = L;
else
// Take any load, we will use it only to update Alias Analysis
OrigLoad = cast<LoadInst>(User->use_back());
OriginalLoads[Indices] = OrigLoad;
}
// Add a parameter to the function for each element passed in.
for (ScalarizeTable::iterator SI = ArgIndices.begin(),
E = ArgIndices.end(); SI != E; ++SI) {
// not allowed to dereference ->begin() if size() is 0
Params.push_back(GetElementPtrInst::getIndexedType(I->getType(), *SI));
assert(Params.back());
}
//.........这里部分代码省略.........
示例4: DeleteDeadVarargs
/// DeleteDeadVarargs - If this is an function that takes a ... list, and if
/// llvm.vastart is never called, the varargs list is dead for the function.
bool DAE::DeleteDeadVarargs(Function &Fn) {
assert(Fn.getFunctionType()->isVarArg() && "Function isn't varargs!");
if (Fn.isDeclaration() || !Fn.hasLocalLinkage()) return false;
// Ensure that the function is only directly called.
if (Fn.hasAddressTaken())
return false;
// Okay, we know we can transform this function if safe. Scan its body
// looking for calls to llvm.vastart.
for (Function::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
if (II->getIntrinsicID() == Intrinsic::vastart)
return false;
}
}
}
// If we get here, there are no calls to llvm.vastart in the function body,
// remove the "..." and adjust all the calls.
// Start by computing a new prototype for the function, which is the same as
// the old function, but doesn't have isVarArg set.
FunctionType *FTy = Fn.getFunctionType();
std::vector<Type*> Params(FTy->param_begin(), FTy->param_end());
FunctionType *NFTy = FunctionType::get(FTy->getReturnType(),
Params, false);
unsigned NumArgs = Params.size();
// Create the new function body and insert it into the module...
Function *NF = Function::Create(NFTy, Fn.getLinkage());
NF->copyAttributesFrom(&Fn);
Fn.getParent()->getFunctionList().insert(&Fn, NF);
NF->takeName(&Fn);
// Loop over all of the callers of the function, transforming the call sites
// to pass in a smaller number of arguments into the new function.
//
std::vector<Value*> Args;
while (!Fn.use_empty()) {
CallSite CS(Fn.use_back());
Instruction *Call = CS.getInstruction();
// Pass all the same arguments.
Args.assign(CS.arg_begin(), CS.arg_begin() + NumArgs);
// Drop any attributes that were on the vararg arguments.
AttrListPtr PAL = CS.getAttributes();
if (!PAL.isEmpty() && PAL.getSlot(PAL.getNumSlots() - 1).Index > NumArgs) {
SmallVector<AttributeWithIndex, 8> AttributesVec;
for (unsigned i = 0; PAL.getSlot(i).Index <= NumArgs; ++i)
AttributesVec.push_back(PAL.getSlot(i));
Attributes FnAttrs = PAL.getFnAttributes();
if (FnAttrs.hasAttributes())
AttributesVec.push_back(AttributeWithIndex::get(AttrListPtr::FunctionIndex,
FnAttrs));
PAL = AttrListPtr::get(AttributesVec);
}
Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args, "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setAttributes(PAL);
} else {
New = CallInst::Create(NF, Args, "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setAttributes(PAL);
if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall();
}
New->setDebugLoc(Call->getDebugLoc());
Args.clear();
if (!Call->use_empty())
Call->replaceAllUsesWith(New);
New->takeName(Call);
// Finally, remove the old call from the program, reducing the use-count of
// F.
Call->eraseFromParent();
}
// Since we have now created the new function, splice the body of the old
// function right into the new function, leaving the old rotting hulk of the
// function empty.
NF->getBasicBlockList().splice(NF->begin(), Fn.getBasicBlockList());
// Loop over the argument list, transferring uses of the old arguments over to
// the new arguments, also transferring over the names as well. While we're at
// it, remove the dead arguments from the DeadArguments list.
//
for (Function::arg_iterator I = Fn.arg_begin(), E = Fn.arg_end(),
//.........这里部分代码省略.........