本文整理汇总了C++中llvm::Function类的典型用法代码示例。如果您正苦于以下问题:C++ Function类的具体用法?C++ Function怎么用?C++ Function使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Function类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runOnFunction
bool IndependentBlocks::runOnFunction(llvm::Function &F) {
bool Changed = false;
RI = &getAnalysis<RegionInfoPass>().getRegionInfo();
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
SD = &getAnalysis<ScopDetection>();
SE = &getAnalysis<ScalarEvolution>();
AllocaBlock = &F.getEntryBlock();
DEBUG(dbgs() << "Run IndepBlock on " << F.getName() << '\n');
for (const Region *R : *SD) {
Changed |= createIndependentBlocks(R);
Changed |= eliminateDeadCode(R);
// This may change the RegionTree.
if (!DisableIntraScopScalarToArray || !PollyModelPHINodes)
Changed |= splitExitBlock(const_cast<Region *>(R));
}
DEBUG(dbgs() << "Before Scalar to Array------->\n");
DEBUG(F.dump());
if (!DisableIntraScopScalarToArray || !PollyModelPHINodes)
for (const Region *R : *SD)
Changed |= translateScalarToArray(R);
DEBUG(dbgs() << "After Independent Blocks------------->\n");
DEBUG(F.dump());
verifyAnalysis();
return Changed;
}
示例2: incrementFunctionVersion
void md::incrementFunctionVersion(llvm::Function &fn)
{
unsigned newVersion = getFunctionVersion(fn) + 1;
auto& ctx = fn.getContext();
ConstantInt* cNewVersion = ConstantInt::get(Type::getInt32Ty(ctx), newVersion);
MDNode* versionNode = MDNode::get(ctx, ConstantAsMetadata::get(cNewVersion));
fn.setMetadata("fcd.funver", versionNode);
}
示例3: shouldIgnoreFunction
bool DINOGlobal::shouldIgnoreFunction (const llvm::Function &F) {
if (F.getName().find(DINOPrefix) == 0) {
#ifdef DINO_VERBOSE
llvm::outs() << "Skipping DINO function " << F.getName() << "\n";
#endif //DINO_VERBOSE
return true;
}
return false;
}
示例4: InspectFunction
//------------------------------------------------------------------
/// Scan a function to see if any instructions are interesting
///
/// @param[in] f
/// The function to be inspected.
///
/// @return
/// False if there was an error scanning; true otherwise.
//------------------------------------------------------------------
virtual bool InspectFunction(llvm::Function &f)
{
for (llvm::Function::iterator bbi = f.begin(), last_bbi = f.end();
bbi != last_bbi;
++bbi)
{
if (!InspectBasicBlock(*bbi))
return false;
}
return true;
}
示例5: runOnFunction
void AstBackEnd::runOnFunction(llvm::Function& fn)
{
grapher.reset(new AstGrapher);
// Before doing anything, create statements for blocks in reverse post-order. This ensures that values exist
// before they are used. (Post-order would try to use statements before they were created.)
for (BasicBlock* block : ReversePostOrderTraversal<BasicBlock*>(&fn.getEntryBlock()))
{
grapher->createRegion(*block, *output->basicBlockToStatement(*block));
}
// Identify loops, then visit basic blocks in post-order. If the basic block if the head
// of a cyclic region, process the loop. Otherwise, if the basic block is the start of a single-entry-single-exit
// region, process that region.
auto& domTreeWrapper = getAnalysis<DominatorTreeWrapperPass>(fn);
domTree = &domTreeWrapper.getDomTree();
postDomTree->recalculate(fn);
RootedPostDominatorTree::treeFromIncompleteTree(fn, postDomTree);
// Traverse graph in post-order. Try to detect regions with the post-dominator tree.
// Cycles are only considered once.
for (BasicBlock* entry : post_order(&fn.getEntryBlock()))
{
BasicBlock* postDominator = entry;
while (postDominator != nullptr)
{
AstGraphNode* graphNode = grapher->getGraphNodeFromEntry(postDominator);
BasicBlock* exit = graphNode->hasExit()
? graphNode->getExit()
: postDominatorOf(*postDomTree, *postDominator);
RegionType region = isRegion(*entry, exit);
if (region == Acyclic)
{
runOnRegion(fn, *entry, exit);
}
else if (region == Cyclic)
{
runOnLoop(fn, *entry, exit);
}
if (!domTree->dominates(entry, exit))
{
break;
}
postDominator = exit;
}
}
Statement* bodyStatement = grapher->getGraphNodeFromEntry(&fn.getEntryBlock())->node;
output->setBody(bodyStatement);
}
示例6: while
bool BitcastCallEliminator::runOnFunction(llvm::Function &function)
{
bool res = false;
bool doLoop = true;
while (doLoop) {
doLoop = false;
for (llvm::Function::iterator i = function.begin(), e = function.end(); i != e; ++i) {
llvm::BasicBlock *bb = &*i;
bool bbchanged = false;
for (llvm::BasicBlock::iterator ibb = bb->begin(), ebb = bb->end(); ibb != ebb; ++ibb) {
llvm::Instruction *inst = &*ibb;
if (llvm::isa<llvm::CallInst>(inst) && llvm::cast<llvm::CallInst>(inst)->getCalledFunction() == NULL) {
llvm::CallInst *callInst = llvm::cast<llvm::CallInst>(inst);
llvm::Value *calledValue = callInst->getCalledValue();
llvm::Value *bareCalledValue = calledValue->stripPointerCasts();
if (llvm::isa<llvm::Function>(bareCalledValue)) {
const llvm::FunctionType *calledType = llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>(calledValue->getType())->getContainedType(0));
const llvm::FunctionType *calleeType = llvm::cast<llvm::Function>(bareCalledValue)->getFunctionType();
if (calledType->getReturnType() == calleeType->getReturnType()) {
if (argsMatch(calleeType, callInst)) {
std::vector<llvm::Value*> args;
unsigned int numArgs = callInst->getNumArgOperands();
for (unsigned int k = 0; k < numArgs; ++k) {
args.push_back(callInst->getArgOperand(k));
}
#if LLVM_VERSION < VERSION(3, 0)
llvm::CallInst *newCall = llvm::CallInst::Create(bareCalledValue, args.begin(), args.end(), "", inst);
#else
llvm::CallInst *newCall = llvm::CallInst::Create(bareCalledValue, args, "", inst);
#endif
inst->replaceAllUsesWith(newCall);
llvm::StringRef name = inst->getName();
inst->eraseFromParent();
newCall->setName(name);
res = true;
doLoop = true;
bbchanged = true;
}
}
}
}
if (bbchanged) {
break;
}
}
}
}
return res;
}
示例7: runOnFunction
bool InstructionCount::runOnFunction(llvm::Function &Fun) {
ICount = 0;
// A llvm::Function is just a list of llvm::BasicBlock. In order to get
// instruction count we can visit all llvm::BasicBlocks ...
for(llvm::Function::const_iterator I = Fun.begin(),
E = Fun.end();
I != E;
++I)
// ... and sum the llvm::BasicBlock size -- A llvm::BasicBlock size is just
// a list of instructions!
ICount += I->size();
return false;
}
示例8: runOnFunction
bool Unboxing::runOnFunction(llvm::Function & f) {
//std::cout << "running Unboxing optimization..." << std::endl;
m = reinterpret_cast<RiftModule*>(f.getParent());
ta = &getAnalysis<TypeAnalysis>();
for (auto & b : f) {
auto i = b.begin();
while (i != b.end()) {
ins = i;
bool erase = false;
if (CallInst * ci = dyn_cast<CallInst>(ins)) {
StringRef s = ci->getCalledFunction()->getName();
if (s == "genericAdd") {
erase = genericArithmetic(Instruction::FAdd);
} else if (s == "genericSub") {
erase = genericArithmetic(Instruction::FSub);
} else if (s == "genericMul") {
erase = genericArithmetic(Instruction::FMul);
} else if (s == "genericDiv") {
erase = genericArithmetic(Instruction::FDiv);
} else if (s == "genericLt") {
erase = genericRelational(FCmpInst::FCMP_OLT);
} else if (s == "genericGt") {
erase = genericRelational(FCmpInst::FCMP_OGT);
} else if (s == "genericEq") {
erase = genericRelational(FCmpInst::FCMP_OEQ);
} else if (s == "genericNeq") {
erase = genericRelational(FCmpInst::FCMP_ONE);
} else if (s == "genericGetElement") {
erase = genericGetElement();
}
}
if (erase) {
llvm::Instruction * v = i;
++i;
state().erase(v);
v->eraseFromParent();
} else {
++i;
}
}
}
if (DEBUG) {
cout << "After unboxing optimization: --------------------------------" << endl;
f.dump();
state().print(cout);
}
return false;
}
示例9: runOnFunction
bool CLIPSFunctionPass::runOnFunction(llvm::Function& function) {
if(!function.isDeclaration()) {
void* env = getEnvironment();
CLIPSEnvironment* clEnv = new CLIPSEnvironment(env);
EnvReset(env);
CLIPSPassHeader* header = (CLIPSPassHeader*)getIndirectPassHeader();
char* passes = CharBuffer(strlen(header->getPasses()) + 64);
sprintf(passes,"(passes %s)", header->getPasses());
EnvAssertString(env, passes);
free(passes);
KnowledgeConstructor tmp;
if(header->needsLoops() && header->needsRegions()) {
llvm::LoopInfo& li = getAnalysis<LoopInfo>();
llvm::RegionInfo& ri = getAnalysis<RegionInfo>();
tmp.route(function, li, ri);
} else if(header->needsLoops() && !header->needsRegions()) {
llvm::LoopInfo& li = getAnalysis<LoopInfo>();
tmp.route(function, li);
} else if(header->needsRegions() && !header->needsLoops()) {
llvm::RegionInfo& ri = getAnalysis<RegionInfo>();
tmp.route(function, ri);
} else {
tmp.route(function);
}
clEnv->makeInstances((char*)tmp.getInstancesAsString().c_str());
//TODO: put in the line to build the actual knowledge
EnvRun(env, -1L);
//it's up to the code in the expert system to make changes
EnvReset(env);
return true;
} else {
return false;
}
}
示例10: runOnFunction
bool ArgumentRenamePass::runOnFunction(llvm::Function &F) {
for (auto &A : F.args()) {
A.setName("arg." + A.getName());
}
return true;
}
示例11: runOnFunction
bool BasicFunctionPass::runOnFunction(llvm::Function& function) {
RemoveRedundantCallsToSetVisibility optimize_set_visibility;
bool changed = false;
for (auto& block : function.getBasicBlockList()) {
bool block_changed = optimize_set_visibility.runOnBasicBlock(block);
changed = changed || block_changed;
}
return changed;
}
示例12: emitValidRemarks
void emitValidRemarks(const llvm::Function &F, const Region *R) {
LLVMContext &Ctx = F.getContext();
DebugLoc Begin, End;
getDebugLocations(R, Begin, End);
emitOptimizationRemark(Ctx, DEBUG_TYPE, F, Begin,
"A valid Scop begins here.");
emitOptimizationRemark(Ctx, DEBUG_TYPE, F, End, "A valid Scop ends here.");
}
示例13: visitBasicBlock
std::vector<llvm::BasicBlock*> BasicBlockSorter::sortBasicBlocks(llvm::Function &function)
{
std::vector<llvm::BasicBlock*> ret;
std::set<llvm::BasicBlock*> visited;
llvm::BasicBlock &entryBlock = function.getEntryBlock();
visitBasicBlock(ret, visited, &entryBlock);
return ret;
}
示例14: createPrimitiveDestructor
void createPrimitiveDestructor(Module& module, const SEM::TypeInstance* const typeInstance, llvm::Function& llvmFunction) {
assert(llvmFunction.isDeclaration());
Function functionGenerator(module, llvmFunction, destructorArgInfo(module, *typeInstance), &(module.templateBuilder(TemplatedObject::TypeInstance(typeInstance))));
const auto debugInfo = genDebugDestructorFunction(module, *typeInstance, &llvmFunction);
functionGenerator.attachDebugInfo(debugInfo);
functionGenerator.setDebugPosition(getDebugDestructorPosition(module, *typeInstance));
genPrimitiveDestructorCall(functionGenerator, typeInstance->selfType(), functionGenerator.getRawContextValue());
functionGenerator.getBuilder().CreateRetVoid();
functionGenerator.verify();
}
示例15: useEntryBuilder
Function::Function(Module& pModule, llvm::Function& function, const ArgInfo& argInfo, TemplateBuilder* pTemplateBuilder)
: module_(pModule), function_(function),
entryBuilder_(pModule.getLLVMContext()),
builder_(pModule.getLLVMContext()),
createdEntryBlock_(false),
useEntryBuilder_(false),
argInfo_(argInfo),
templateBuilder_(pTemplateBuilder),
#if LOCIC_LLVM_VERSION < 307
debugInfo_(nullptr),
#endif
exceptionInfo_(nullptr),
returnValuePtr_(nullptr),
templateArgs_(nullptr),
unwindState_(nullptr) {
assert(function.isDeclaration());
assert(argInfo_.numArguments() == function_.getFunctionType()->getNumParams());
// Add a bottom level unwind stack.
unwindStackStack_.push(UnwindStack());
// Add bottom level action for this function.
unwindStack().push_back(UnwindAction::FunctionMarker());
const auto startBB = createBasicBlock("");
builder_.SetInsertPoint(startBB);
argValues_.reserve(function_.arg_size());
for (auto arg = function_.arg_begin(); arg != function_.arg_end(); ++arg) {
argValues_.push_back(arg);
}
std::vector<llvm_abi::Type*> argABITypes;
argABITypes.reserve(argInfo.argumentTypes().size());
std::vector<llvm::Type*> argLLVMTypes;
argLLVMTypes.reserve(argInfo.argumentTypes().size());
for (const auto& typePair : argInfo.argumentTypes()) {
argABITypes.push_back(typePair.first);
argLLVMTypes.push_back(typePair.second);
}
SetUseEntryBuilder useEntryBuilder(*this);
// Decode arguments according to ABI.
decodeABIValues(argValues_, argABITypes, argLLVMTypes);
}