Chris Lattner wrote:> On Thu, 13 Jul 2006, Kenneth Hoste wrote: >> Chris Lattner wrote: >>> Hacking on the interpreter is easy, but has several drawbacks. In >>> particular, the interpreter is very slow (even compared to other >>> interpreters) and it is missing functionality: you cannot call >>> arbitrary external functions, which causes many programs to fail in it. >> >> What do you mean by external functions? I only need to print stuff to >> file, the measuring of the characteristics should be pretty easy I think. > > I mean things like printf, exit, write, etc. Take a look at > lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp > > If there is a small set of things you need to support, this shouldn't be > a problem. Adding functions is easy. > >>> OTOH, writing an llvm-to-llvm transformation has many advantages: we >>> have plenty of robust infrastructure for doing such a thing, many >>> people use this, you can use any code generator you like with it >>> (JIT, static compiler, or C backend), and you can even use LLVM >>> optimizations to reduce the cost of your instrumentation. >> >> Is there some kind of tutorial on this? Or an example program or >> something? This sounds quite interesting... > > There is extensive documentation at http://llvm.org/docs/After browsing through the docs, at a first glance I think I should write a plugin for the 'analyze' tool. I think http://llvm.org/docs/WritingAnLLVMPass.html is where I should start from. The only problem I see now is that there doesn't seem to be a way to get information on a single instruction while being able to keep state over all instructions... Is that possible, and if it is, can oyu tell me how (or where I can find an example of it?). greetings (and thanks for your help), Kenneth -- Statistics are like a bikini. What they reveal is suggestive, but what they conceal is vital (Aaron Levenstein) Kenneth Hoste ELIS - Ghent University kenneth.hoste at elis.ugent.be http://www.elis.ugent.be/~kehoste
On Thu, 13 Jul 2006, Kenneth Hoste wrote:> After browsing through the docs, at a first glance I think I should write a > plugin for the 'analyze' tool. I think > http://llvm.org/docs/WritingAnLLVMPass.html is where I should start from. > The only problem I see now is that there doesn't seem to be a way to get > information on a single instruction while being able to keep state over all > instructions... Is that possible, and if it is, can oyu tell me how (or where > I can find an example of it?).I don't really understand what you mean by this, but a ModulePass is fully general, it can do anything. Can you explain what you're trying to do? -Chris -- http://nondot.org/sabre/ http://llvm.org/
Chris Lattner wrote:> On Thu, 13 Jul 2006, Kenneth Hoste wrote: >> After browsing through the docs, at a first glance I think I should >> write a plugin for the 'analyze' tool. I think >> http://llvm.org/docs/WritingAnLLVMPass.html is where I should start from. >> The only problem I see now is that there doesn't seem to be a way to >> get information on a single instruction while being able to keep state >> over all instructions... Is that possible, and if it is, can oyu tell >> me how (or where I can find an example of it?). > > I don't really understand what you mean by this, but a ModulePass is > fully general, it can do anything. Can you explain what you're trying > to do?The way we're characterizing programs now, is adding our own code after every instruction. When that instruction gets executed (which can happen several times, for example inside a loop), we update our state. A simple example is counting the number of dynamic instructions executed, or the instruction mix (% loads, % stores, ...) in the dynamic execution. If I was able to do that using LLVM, we would have characteristics on a higher level of abstraction. The documentation on the BasicBlock pass mentions not to keep state over different basic blocks, but I do want that. Also, I need a way to iterate over the _dynamic_ instruction stream. Is there a way to do that? Example static vs dynamic: static: L: add x, y sub y, z jmpif z>100 mul x, z dynamic: add x, y sub y, z jmpif z>100 add x, y sub y, z jmpif z>100 ... jmpif z>100 mul x, z If my problem still isn't clear, it's because I didn't explain it well. Feel free to ask further questions. I'll look into the documentation/examples today, to see if I can find some kind of dynamic analysis. greetings, Kennneth -- Statistics are like a bikini. What they reveal is suggestive, but what they conceal is vital (Aaron Levenstein) Kenneth Hoste ELIS - Ghent University kenneth.hoste at elis.ugent.be http://www.elis.ugent.be/~kehoste