[LLVMdev] Adding function attributes
Arnaldo
arnaldo.cruz at upr.edu
Mon Nov 5 16:44:58 PST 2012
Below is a stripped down version of the pass.
The compile line is: clang -O0 -S -emit-llvm -o test.S test.c && opt -S
-mem2reg -load <path to extract lib> -extract < test.S > test_opt.S
#include "llvm/Analysis/DependenceAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace std;
namespace
{
class ExtractFeatures : public ModulePass
{
public:
static char ID;
ExtractFeatures() : ModulePass(ID)
{
module = NULL;
loopInfo = NULL;
scalarEvolution = NULL;
}
virtual bool runOnModule(Module& m)
{
module = &m;
bool modified = false;
for (Module::iterator functionIter = module->begin();
functionIter != module->end(); functionIter++)
{
if (functionIter->isDeclaration())
continue;
Attributes attributes = functionIter->getFnAttributes();
if (!attributes.hasAttribute(Attributes::AlwaysInline))
{
functionIter->addFnAttr(llvm::Attributes::AlwaysInline);
errs() << "AlwaysInline NOT detected\n";
modified = true;
}
else
{
errs() << "AlwaysInline detected\n";
}
}
return modified;
}
virtual void getAnalysisUsage(AnalysisUsage &analysisUsage)
const
{
analysisUsage.addRequired<LoopInfo>();
analysisUsage.addPreserved<LoopInfo>();
analysisUsage.addRequired<ScalarEvolution>();
analysisUsage.addPreserved<ScalarEvolution>();
analysisUsage.addRequired<DependenceAnalysis>();
analysisUsage.addPreserved<DependenceAnalysis>();
}
private:
DependenceAnalysis* dependenceAnalysis;
LoopInfo* loopInfo;
Module* module;
ScalarEvolution* scalarEvolution;
};
char ExtractFeatures::ID = 0;
static RegisterPass<ExtractFeatures> X("extract", "Extract source
features", true, true);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121106/c88c60dc/attachment.html>
More information about the llvm-dev
mailing list