本文整理汇总了C++中function::const_arg_iterator类的典型用法代码示例。如果您正苦于以下问题:C++ const_arg_iterator类的具体用法?C++ const_arg_iterator怎么用?C++ const_arg_iterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了const_arg_iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CloneFunctionInto
/// CloneFunction - Return a copy of the specified function, but without
/// embedding the function into another module. Also, any references specified
/// in the VMap are changed to refer to their mapped value instead of the
/// original one. If any of the arguments to the function are in the VMap,
/// the arguments are deleted from the resultant function. The VMap is
/// updated to include mappings from all of the instructions and basicblocks in
/// the function from their old to new values.
///
Function *llvm::CloneFunction(const Function *F, ValueToValueMapTy &VMap,
bool ModuleLevelChanges,
ClonedCodeInfo *CodeInfo) {
std::vector<Type*> ArgTypes;
// The user might be deleting arguments to the function by specifying them in
// the VMap. If so, we need to not add the arguments to the arg ty vector
//
for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
I != E; ++I)
if (VMap.count(I) == 0) // Haven't mapped the argument to anything yet?
ArgTypes.push_back(I->getType());
// Create a new function type...
FunctionType *FTy = FunctionType::get(F->getFunctionType()->getReturnType(),
ArgTypes, F->getFunctionType()->isVarArg());
// Create the new function...
Function *NewF = Function::Create(FTy, F->getLinkage(), F->getName());
// Loop over the arguments, copying the names of the mapped arguments over...
Function::arg_iterator DestI = NewF->arg_begin();
for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
I != E; ++I)
if (VMap.count(I) == 0) { // Is this argument preserved?
DestI->setName(I->getName()); // Copy the name over...
VMap[I] = DestI++; // Add mapping to VMap
}
SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
CloneFunctionInto(NewF, F, VMap, ModuleLevelChanges, Returns, "", CodeInfo);
return NewF;
}
示例2: calculateFunctionInfo
static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
const TargetData *TD) {
X86MachineFunctionInfo Info;
uint64_t Size = 0;
switch (F->getCallingConv()) {
case CallingConv::X86_StdCall:
Info.setDecorationStyle(StdCall);
break;
case CallingConv::X86_FastCall:
Info.setDecorationStyle(FastCall);
break;
default:
return Info;
}
unsigned argNum = 1;
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
AI != AE; ++AI, ++argNum) {
const Type* Ty = AI->getType();
// 'Dereference' type in case of byval parameter attribute
if (F->paramHasAttr(argNum, Attribute::ByVal))
Ty = cast<PointerType>(Ty)->getElementType();
// Size should be aligned to DWORD boundary
Size += ((TD->getTypePaddedSize(Ty) + 3)/4)*4;
}
// We're not supporting tooooo huge arguments :)
Info.setBytesToPopOnReturn((unsigned int)Size);
return Info;
}
示例3: collectConstraintsForGlobals
void Andersen::collectConstraintsForGlobals(Module& M)
{
// Create a pointer and an object for each global variable
for (auto const& globalVal: M.globals())
{
NodeIndex gVal = nodeFactory.createValueNode(&globalVal);
NodeIndex gObj = nodeFactory.createObjectNode(&globalVal);
constraints.emplace_back(AndersConstraint::ADDR_OF, gVal, gObj);
}
// Functions and function pointers are also considered global
for (auto const& f: M)
{
// If f is an addr-taken function, create a pointer and an object for it
if (f.hasAddressTaken())
{
NodeIndex fVal = nodeFactory.createValueNode(&f);
NodeIndex fObj = nodeFactory.createObjectNode(&f);
constraints.emplace_back(AndersConstraint::ADDR_OF, fVal, fObj);
}
if (f.isDeclaration() || f.isIntrinsic())
continue;
// Create return node
if (f.getFunctionType()->getReturnType()->isPointerTy())
{
nodeFactory.createReturnNode(&f);
}
// Create vararg node
if (f.getFunctionType()->isVarArg())
nodeFactory.createVarargNode(&f);
// Add nodes for all formal arguments.
for (Function::const_arg_iterator itr = f.arg_begin(), ite = f.arg_end(); itr != ite; ++itr)
{
if (isa<PointerType>(itr->getType()))
nodeFactory.createValueNode(itr);
}
}
// Init globals here since an initializer may refer to a global var/func below it
for (auto const& globalVal: M.globals())
{
NodeIndex gObj = nodeFactory.getObjectNodeFor(&globalVal);
assert(gObj != AndersNodeFactory::InvalidIndex && "Cannot find global object!");
if (globalVal.hasDefinitiveInitializer())
{
addGlobalInitializerConstraints(gObj, globalVal.getInitializer());
}
else
{
// If it doesn't have an initializer (i.e. it's defined in another translation unit), it points to the universal set.
constraints.emplace_back(AndersConstraint::COPY,
gObj, nodeFactory.getUniversalObjNode());
}
}
}
示例4: getArgumentType
const Type* getArgumentType(const Function* f, const unsigned arg_index) {
assert (f);
assert (arg_index < f->arg_size());
Function::const_arg_iterator A = f->arg_begin();
for (unsigned i=0; i<arg_index; ++i) ++A; //is there a better way? :P
return A->getType();
}
示例5:
bool TriCoreCallingConvHook::isRegVali64Type (MachineFunction& _mf) {
Function::const_arg_iterator FI;
FI = _mf.getFunction()->arg_begin();
std::advance(FI,curArg);
outs() << "size: " << FI->getType()->getScalarSizeInBits() << "\n";
return (FI->getType()->getScalarSizeInBits() == 64) ? true : false;
}
示例6: setFuncVariable
void ProgramCFG::setFuncVariable(const Function *F,string func, CFG* cfg, bool initial){
for (Function::const_arg_iterator it = F->arg_begin(), E = F->arg_end();it != E; ++it) {
Type *Ty = it->getType();
if(initial){
string varNum = it->getName();
string varName = func+"_"+varNum;
if(Ty->isPointerTy()){
Type *ETy = Ty->getPointerElementType();
int ID = cfg->counter_variable++;
Variable var(varName, ID, PTR);
cfg->variableList.push_back(var);
InstParser::setVariable(cfg, NULL, ETy, varName, true);
}
else{
VarType type;
if(Ty->isIntegerTy())
type = INT;
else if(Ty->isFloatingPointTy())
type = FP;
else
errs()<<"0:programCFG.type error\n";
int ID = cfg->counter_variable++;
Variable var(varName, ID, type);
cfg->variableList.push_back(var);
cfg->mainInput.push_back(ID);
}
}
else{
int ID = cfg->counter_variable++;
string varNum = it->getName();
string varName = func+"_"+varNum;
VarType type;
if(Ty->isPointerTy())
type = PTR;
else if(Ty->isIntegerTy())
type = INT;
else if(Ty->isFloatingPointTy())
type = FP;
else
errs()<<"1:programCFG.type error\n";
if(!cfg->hasVariable(varName)){
Variable var(varName, ID, type);
cfg->variableList.push_back(var);
}
else
errs()<<"1:setFuncVariable error 10086!!\t"<<varName<<"\n";
}
}
}
示例7: CCInfo
bool AArch64CallLowering::LowerFormalArguments(
MachineIRBuilder &MIRBuilder, const Function::ArgumentListType &Args,
const SmallVectorImpl<unsigned> &VRegs) const {
if (!EMIT_IMPLEMENTATION)
return false;
MachineFunction &MF = MIRBuilder.getMF();
const Function &F = *MF.getFunction();
SmallVector<CCValAssign, 16> ArgLocs;
CCState CCInfo(F.getCallingConv(), F.isVarArg(), MF, ArgLocs, F.getContext());
unsigned NumArgs = Args.size();
Function::const_arg_iterator CurOrigArg = Args.begin();
const AArch64TargetLowering &TLI = *getTLI<AArch64TargetLowering>();
for (unsigned i = 0; i != NumArgs; ++i, ++CurOrigArg) {
MVT ValVT = MVT::getVT(CurOrigArg->getType());
CCAssignFn *AssignFn =
TLI.CCAssignFnForCall(F.getCallingConv(), /*IsVarArg=*/false);
bool Res =
AssignFn(i, ValVT, ValVT, CCValAssign::Full, ISD::ArgFlagsTy(), CCInfo);
assert(!Res && "Call operand has unhandled type");
(void)Res;
}
assert(ArgLocs.size() == Args.size() &&
"We have a different number of location and args?!");
for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
CCValAssign &VA = ArgLocs[i];
assert(VA.isRegLoc() && "Not yet implemented");
// Transform the arguments in physical registers into virtual ones.
MIRBuilder.getMBB().addLiveIn(VA.getLocReg());
MIRBuilder.buildInstr(TargetOpcode::COPY, VRegs[i], VA.getLocReg());
switch (VA.getLocInfo()) {
default:
llvm_unreachable("Unknown loc info!");
case CCValAssign::Full:
break;
case CCValAssign::BCvt:
// We don't care about bitcast.
break;
case CCValAssign::AExt:
case CCValAssign::SExt:
case CCValAssign::ZExt:
// Zero/Sign extend the register.
assert(0 && "Not yet implemented");
break;
}
}
return true;
}
示例8: copyFunctionBody
void llvm::copyFunctionBody(Function &New, const Function &Orig,
ValueToValueMapTy &VMap) {
if (!Orig.isDeclaration()) {
Function::arg_iterator DestI = New.arg_begin();
for (Function::const_arg_iterator J = Orig.arg_begin(); J != Orig.arg_end();
++J) {
DestI->setName(J->getName());
VMap[J] = DestI++;
}
SmallVector<ReturnInst *, 8> Returns; // Ignore returns cloned.
CloneFunctionInto(&New, &Orig, VMap, /*ModuleLevelChanges=*/true, Returns);
}
}
示例9: AddFastCallStdCallSuffix
/// AddFastCallStdCallSuffix - Microsoft fastcall and stdcall functions require
/// a suffix on their name indicating the number of words of arguments they
/// take.
static void AddFastCallStdCallSuffix(SmallVectorImpl<char> &OutName,
const Function *F, const DataLayout &TD) {
// Calculate arguments size total.
unsigned ArgWords = 0;
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
AI != AE; ++AI) {
Type *Ty = AI->getType();
// 'Dereference' type in case of byval parameter attribute
if (AI->hasByValAttr())
Ty = cast<PointerType>(Ty)->getElementType();
// Size should be aligned to DWORD boundary
ArgWords += ((TD.getTypeAllocSize(Ty) + 3)/4)*4;
}
raw_svector_ostream(OutName) << '@' << ArgWords;
}
示例10: SectionForFrame
void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
const Function *F = MF.getFunction();
const TargetData *TD = TM.getTargetData();
// Emit the data section name.
O << "\n";
PIC16Section *fPDataSection =
const_cast<PIC16Section *>(getObjFileLowering().
SectionForFrame(CurrentFnSym->getName()));
fPDataSection->setColor(getFunctionColor(F));
OutStreamer.SwitchSection(fPDataSection);
// Emit function frame label
O << PAN::getFrameLabel(CurrentFnSym->getName()) << ":\n";
const Type *RetType = F->getReturnType();
unsigned RetSize = 0;
if (RetType->getTypeID() != Type::VoidTyID)
RetSize = TD->getTypeAllocSize(RetType);
//Emit function return value space
// FIXME: Do not emit RetvalLable when retsize is zero. To do this
// we will need to avoid printing a global directive for Retval label
// in emitExternandGloblas.
if(RetSize > 0)
O << PAN::getRetvalLabel(CurrentFnSym->getName())
<< " RES " << RetSize << "\n";
else
O << PAN::getRetvalLabel(CurrentFnSym->getName()) << ": \n";
// Emit variable to hold the space for function arguments
unsigned ArgSize = 0;
for (Function::const_arg_iterator argi = F->arg_begin(),
arge = F->arg_end(); argi != arge ; ++argi) {
const Type *Ty = argi->getType();
ArgSize += TD->getTypeAllocSize(Ty);
}
O << PAN::getArgsLabel(CurrentFnSym->getName()) << " RES " << ArgSize << "\n";
// Emit temporary space
int TempSize = PTLI->GetTmpSize();
if (TempSize > 0)
O << PAN::getTempdataLabel(CurrentFnSym->getName()) << " RES "
<< TempSize << '\n';
}
示例11: addByteCountSuffix
/// Microsoft fastcall and stdcall functions require a suffix on their name
/// indicating the number of words of arguments they take.
static void addByteCountSuffix(raw_ostream &OS, const Function *F,
const DataLayout &DL) {
// Calculate arguments size total.
unsigned ArgWords = 0;
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
AI != AE; ++AI) {
Type *Ty = AI->getType();
// 'Dereference' type in case of byval or inalloca parameter attribute.
if (AI->hasByValOrInAllocaAttr())
Ty = cast<PointerType>(Ty)->getElementType();
// Size should be aligned to pointer size.
unsigned PtrSize = DL.getPointerSize();
ArgWords += RoundUpToAlignment(DL.getTypeAllocSize(Ty), PtrSize);
}
OS << '@' << ArgWords;
}
示例12: SwitchToSection
void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
const Function *F = MF.getFunction();
std::string FuncName = Mang->getValueName(F);
const TargetData *TD = TM.getTargetData();
// Emit the data section name.
O << "\n";
const char *SectionName = PAN::getFrameSectionName(CurrentFnName).c_str();
const Section *fPDataSection = TAI->getNamedSection(SectionName,
SectionFlags::Writeable);
SwitchToSection(fPDataSection);
// Emit function frame label
O << PAN::getFrameLabel(CurrentFnName) << ":\n";
const Type *RetType = F->getReturnType();
unsigned RetSize = 0;
if (RetType->getTypeID() != Type::VoidTyID)
RetSize = TD->getTypeAllocSize(RetType);
//Emit function return value space
// FIXME: Do not emit RetvalLable when retsize is zero. To do this
// we will need to avoid printing a global directive for Retval label
// in emitExternandGloblas.
if(RetSize > 0)
O << PAN::getRetvalLabel(CurrentFnName) << " RES " << RetSize << "\n";
else
O << PAN::getRetvalLabel(CurrentFnName) << ": \n";
// Emit variable to hold the space for function arguments
unsigned ArgSize = 0;
for (Function::const_arg_iterator argi = F->arg_begin(),
arge = F->arg_end(); argi != arge ; ++argi) {
const Type *Ty = argi->getType();
ArgSize += TD->getTypeAllocSize(Ty);
}
O << PAN::getArgsLabel(CurrentFnName) << " RES " << ArgSize << "\n";
// Emit temporary space
int TempSize = PTLI->GetTmpSize();
if (TempSize > 0 )
O << PAN::getTempdataLabel(CurrentFnName) << " RES " << TempSize <<"\n";
}
示例13: lowerJuliaArrayArguments
std::vector<Type*> lowerJuliaArrayArguments(Function *OldFunc) {
Module* M = OldFunc->getParent();
LLVMContext &context = M->getContext();
NamedMDNode* JuliaArgs = M->getOrInsertNamedMetadata("julia.args");
MDNode *node = JuliaArgs->getOperand(0);
int operand = 0;
std::vector<Type*> ArgTypes;
for (Function::const_arg_iterator I = OldFunc->arg_begin(), E = OldFunc->arg_end(); I != E; ++I) {
Type* argType = I->getType();
if (is_jl_array_type(argType)) {
// Gets the type from custom metadata
Value *value = node->getOperand(operand);
if (MDString* mdstring = dyn_cast<MDString>(value)) {
if (Type* type = extractType(context, mdstring->getString())) {
ArgTypes.push_back(type);
} else {
errs() << "Could not extract type: ";
mdstring->print(errs());
errs() << "\n";
exit(1);
}
} else {
errs() << "Could not extract type: ";
value->print(errs());
errs() << "\n";
exit(1);
}
} else {
ArgTypes.push_back(I->getType());
}
operand++;
}
return ArgTypes;
}
示例14: getMachineFunction
/// Identify lowered values that originated from f128 arguments and record
/// this.
void MipsCCState::PreAnalyzeFormalArgumentsForF128(
const SmallVectorImpl<ISD::InputArg> &Ins) {
const MachineFunction &MF = getMachineFunction();
for (unsigned i = 0; i < Ins.size(); ++i) {
Function::const_arg_iterator FuncArg = MF.getFunction()->arg_begin();
// SRet arguments cannot originate from f128 or {f128} returns so we just
// push false. We have to handle this specially since SRet arguments
// aren't mapped to an original argument.
if (Ins[i].Flags.isSRet()) {
OriginalArgWasF128.push_back(false);
OriginalArgWasFloat.push_back(false);
continue;
}
assert(Ins[i].getOrigArgIndex() < MF.getFunction()->arg_size());
std::advance(FuncArg, Ins[i].getOrigArgIndex());
OriginalArgWasF128.push_back(
originalTypeIsF128(FuncArg->getType(), nullptr));
OriginalArgWasFloat.push_back(FuncArg->getType()->isFloatingPointTy());
}
}
示例15: GlobalVariable
std::unique_ptr<Module> llvm::CloneModule(
const Module *M, ValueToValueMapTy &VMap,
std::function<bool(const GlobalValue *)> ShouldCloneDefinition) {
// First off, we need to create the new module.
std::unique_ptr<Module> New =
llvm::make_unique<Module>(M->getModuleIdentifier(), M->getContext());
New->setDataLayout(M->getDataLayout());
New->setTargetTriple(M->getTargetTriple());
New->setModuleInlineAsm(M->getModuleInlineAsm());
// Loop over all of the global variables, making corresponding globals in the
// new module. Here we add them to the VMap and to the new Module. We
// don't worry about attributes or initializers, they will come later.
//
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) {
GlobalVariable *GV = new GlobalVariable(*New,
I->getValueType(),
I->isConstant(), I->getLinkage(),
(Constant*) nullptr, I->getName(),
(GlobalVariable*) nullptr,
I->getThreadLocalMode(),
I->getType()->getAddressSpace());
GV->copyAttributesFrom(&*I);
VMap[&*I] = GV;
}
// Loop over the functions in the module, making external functions as before
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
Function *NF =
Function::Create(cast<FunctionType>(I->getValueType()),
I->getLinkage(), I->getName(), New.get());
NF->copyAttributesFrom(&*I);
VMap[&*I] = NF;
}
// Loop over the aliases in the module
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I) {
if (!ShouldCloneDefinition(&*I)) {
// An alias cannot act as an external reference, so we need to create
// either a function or a global variable depending on the value type.
// FIXME: Once pointee types are gone we can probably pick one or the
// other.
GlobalValue *GV;
if (I->getValueType()->isFunctionTy())
GV = Function::Create(cast<FunctionType>(I->getValueType()),
GlobalValue::ExternalLinkage, I->getName(),
New.get());
else
GV = new GlobalVariable(
*New, I->getValueType(), false, GlobalValue::ExternalLinkage,
(Constant *)nullptr, I->getName(), (GlobalVariable *)nullptr,
I->getThreadLocalMode(), I->getType()->getAddressSpace());
VMap[&*I] = GV;
// We do not copy attributes (mainly because copying between different
// kinds of globals is forbidden), but this is generally not required for
// correctness.
continue;
}
auto *GA = GlobalAlias::create(I->getValueType(),
I->getType()->getPointerAddressSpace(),
I->getLinkage(), I->getName(), New.get());
GA->copyAttributesFrom(&*I);
VMap[&*I] = GA;
}
// Now that all of the things that global variable initializer can refer to
// have been created, loop through and copy the global variable referrers
// over... We also set the attributes on the global now.
//
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) {
GlobalVariable *GV = cast<GlobalVariable>(VMap[&*I]);
if (!ShouldCloneDefinition(&*I)) {
// Skip after setting the correct linkage for an external reference.
GV->setLinkage(GlobalValue::ExternalLinkage);
continue;
}
if (I->hasInitializer())
GV->setInitializer(MapValue(I->getInitializer(), VMap));
}
// Similarly, copy over function bodies now...
//
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
Function *F = cast<Function>(VMap[&*I]);
if (!ShouldCloneDefinition(&*I)) {
// Skip after setting the correct linkage for an external reference.
F->setLinkage(GlobalValue::ExternalLinkage);
// Personality function is not valid on a declaration.
F->setPersonalityFn(nullptr);
continue;
}
if (!I->isDeclaration()) {
Function::arg_iterator DestI = F->arg_begin();
for (Function::const_arg_iterator J = I->arg_begin(); J != I->arg_end();
++J) {
DestI->setName(J->getName());
VMap[&*J] = &*DestI++;
//.........这里部分代码省略.........