Ryan Taylor | 1 Feb 02:16
Picon

Loop Unroll a constant number of times?

Is it possible to unroll a loop (forcibly if necessary) with llvm (possibly the -loop-unroll pass) a constant number of times.

I believe that I read that the -unroll-count=x option was removed, correct? So is there some other way to do this or is this just not possible in llvm?

_______________________________________________
LLVM Developers mailing list
LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Chad Rosier | 1 Feb 02:30
Picon
Favicon

Re: Loop Unroll a constant number of times?

Ryan,
I see the following command line options in LoopUnrollPass.cpp:

static cl::opt<unsigned>
UnrollThreshold("unroll-threshold", cl::init(150), cl::Hidden,
  cl::desc("The cut-off point for automatic loop unrolling"));

static cl::opt<unsigned>
UnrollCount("unroll-count", cl::init(0), cl::Hidden,
  cl::desc("Use this unroll count for all loops, for testing purposes"));

static cl::opt<bool>
UnrollAllowPartial("unroll-allow-partial", cl::init(false), cl::Hidden,
  cl::desc("Allows loops to be partially unrolled until "
           "-unroll-threshold loop size is reached."));

static cl::opt<bool>
UnrollRuntime("unroll-runtime", cl::ZeroOrMore, cl::init(false), cl::Hidden,
  cl::desc("Unroll loops with run-time trip counts"));

I assume the first two are most applicable to what you're trying to do.  I've never used these options, so it
would be a good idea to look at the source to see what these are really doing.

Also, you'll probably need to put -mllvm before the argument to pass it to the backend (clang -mllvm -unroll-threshold=10).

You can also use the -debug-only=loop-unroll option to get debug information.  It too requires the -mllvm option.

Hope this helps,
  Chad

On Jan 31, 2012, at 5:16 PM, Ryan Taylor <ryta1203 <at> gmail.com> wrote:

> Is it possible to unroll a loop (forcibly if necessary) with llvm (possibly the -loop-unroll pass) a
constant number of times. 
> 
> I believe that I read that the -unroll-count=x option was removed, correct? So is there some other way to do
this or is this just not possible in llvm?
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Adarsh HV | 1 Feb 08:47
Picon

Call DeadCodeElimination pass of LLVM

Hi,
Please let me know how to follow my pass in LLVM by Dead Code Elimination pass of LLVM. getAnalysisUsage(...) only allows me to run passes before my pass. I want to run Dead Code Elimination pass after my pass.

Regards,
Adarsh

_______________________________________________
LLVM Developers mailing list
LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Nick Lewycky | 1 Feb 09:03
Picon

Re: Call DeadCodeElimination pass of LLVM

Adarsh HV wrote:
> Hi,
> Please let me know how to follow my pass in LLVM by Dead Code
> Elimination pass of LLVM. getAnalysisUsage(...) only allows me to run
> passes before my pass. I want to run Dead Code Elimination pass after my
> pass.

Your pass does not control that; where the PassManager is created, 
insert your pass, then insert the DCE pass.

Nick
rohit bhat | 1 Feb 09:35
Picon
Favicon

Function Insertion Error

Hi,
I am trying to insert a function into the LLVM IR. But i get a stack dump exception. My code is as follows.

 

#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/IRBuilder.h"
using namespace llvm;
 

namespace {
  struct FunctionInsert : public ModulePass {
    static char ID;
    FunctionInsert() : ModulePass(ID) {}

  };
    virtual bool runOnModule(Module &M) {
    

     FunctionType* ty=FunctionType::get(Type::getInt32Ty(M.getContext()),false);
       Function *func =  cast<Function>(M.getOrInsertFunction("func", ty,Type::getInt32Ty(M.getContext()),  (Type *)0)); 
      BasicBlock *BB = BasicBlock::Create(M.getContext(), "bb1", func);
      IRBuilder<> builder(BB);
       Value *One = builder.getInt32(1);
      Argument *ArgX = func->arg_begin();   
      ArgX->setName("firstarg");            
     Value *Add = builder.CreateAdd(One, ArgX);
     builder.CreateRet(Add);
    return true;
    }
  };
}
 
char FunctionInsert::ID = 0;
static RegisterPass<FunctionInsert> X("FunctionInsert", "Function Insertion Pass");

Most of the above code is from the file examples/HowToUseJIT/HowToUseJIT.cpp.
Thanks
_______________________________________________
LLVM Developers mailing list
LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Duncan Sands | 1 Feb 10:03
Picon
Favicon

Re: Function Insertion Error

Hi Rohit,

> I am trying to insert a function into the LLVM IR. But i get a stack dump
> exception.

you should include the message since it can help us understand what you did
wrong.  You built LLVM with assertions enabled, right?

  My code is as follows.
>
>
>
> #include "llvm/Pass.h"
> #include "llvm/Function.h"
> #include "llvm/Module.h"
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/ADT/Statistic.h"
> #include "llvm/Support/IRBuilder.h"
> using namespace llvm;
>
>
> namespace {
> struct FunctionInsert : public ModulePass {
> static char ID;
> FunctionInsert() : ModulePass(ID) {}
>
> };
> virtual bool runOnModule(Module &M) {
>
>
> FunctionType* ty=FunctionType::get(Type::getInt32Ty(M.getContext()),false);

A function with no parameters that returns an int: int func(void)
However I think you wanted a function that also has an int argument, thus
this should have been

   FunctionType* ty=FunctionType::get(Type::getInt32Ty(M.getContext()),
     Type::getInt32Ty(M.getContext()), false);

which corresponds to: int func(int)

> Function *func = cast<Function>(M.getOrInsertFunction("func",
> ty,Type::getInt32Ty(M.getContext()), (Type *)0));

Inserting a function that returns type ty and has one argument of type int.
Clearly you don't mean to have your function return a value of function type
(which is what ty is).  Probably you meant:

   Function *func = cast<Function>(M.getOrInsertFunction("func", ty));

This will insert a function with type ty, i.e. int func(int)

I didn't look at the rest since this first part needs to be sorted out
before worrying about anything else.

Ciao, Duncan.

> BasicBlock *BB = BasicBlock::Create(M.getContext(), "bb1", func);
> IRBuilder<> builder(BB);
> Value *One = builder.getInt32(1);
> Argument *ArgX = func->arg_begin();
> ArgX->setName("firstarg");
> Value *Add = builder.CreateAdd(One, ArgX);
> builder.CreateRet(Add);
> return true;
> }
> };
> }
>
> char FunctionInsert::ID = 0;
> static RegisterPass<FunctionInsert> X("FunctionInsert", "Function Insertion Pass");
>
> Most of the above code is from the file examples/HowToUseJIT/HowToUseJIT.cpp.
> Thanks:) happy
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Chad Rosier | 1 Feb 10:03
Picon
Favicon

Re: Call DeadCodeElimination pass of LLVM

Adarsh,
I believe you want to look at lib/Transforms/IPO/PassManagerBuilder.cpp

 Chad

On Feb 1, 2012, at 12:03 AM, Nick Lewycky wrote:

> Adarsh HV wrote:
>> Hi,
>> Please let me know how to follow my pass in LLVM by Dead Code
>> Elimination pass of LLVM. getAnalysisUsage(...) only allows me to run
>> passes before my pass. I want to run Dead Code Elimination pass after my
>> pass.
> 
> Your pass does not control that; where the PassManager is created, 
> insert your pass, then insert the DCE pass.
> 
> Nick
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Chandler Carruth | 1 Feb 11:04
Picon
Favicon

Re: CommandGuide documentation points to outdated pages?

Anton, is this something you can look into? I don't expect Tanya to be fixing the website around now.... ;]

On Fri, Jan 27, 2012 at 8:55 PM, Eli Bendersky <eliben <at> gmail.com> wrote:
Hello,

I noticed something strange in the links from
http://llvm.org/docs/CommandGuide/index.html
They all point to HTML files in http://llvm.org/cmds/, which were last
updated on 11-May-2010. There were many updates to the CommandGuide
documents since that time, according to the SVN logs, however.

One manifestation of this problem is that a fix made in r147721
(07-Jan-2012) to one of the documents (lit.html) is invisible on the
website.
Another manifestation is PR11562 - a dead link in the
http://llvm.org/docs/LLVMBuild.html doc because it points to
llvm-build.html - a relatively new document which isn't present on the
website.

Eli
_______________________________________________
LLVM Developers mailing list
LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
LLVMdev <at> cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Patrik Hägglund | 1 Feb 12:11
Picon
Favicon

Issues with the llvm.stackrestore intrinsic

Hi,

I have two problems regarding the llvm.stackrestore intrinsic. I'm
running on 3.0, but a quick test on trunk also showed the same behavior.

First problem:
---------------
I have code like:

   tmp1 = call llvm.stacksave()
   tmp2 = alloca
   [do some stuff with tmp2]
   call llvm.stackrestore(tmp1)

   [some other stuff]

   tmp3 = call llvm.stacksave()
   tmp4 = alloca
   [do some stuff with tmp4]
   call llvm.stackrestore(tmp3)

Then some transformation rewrites this to

   tmp1 = call llvm.stacksave()
   tmp2 = alloca
   [do some stuff with tmp2]
   call llvm.stackrestore(tmp1)

   [some other stuff]

   tmp3 = call llvm.stacksave()
   tmp4 = tmp2      <----- Ops!!!
   [do some stuff with tmp4]
   call llvm.stackrestore(tmp3)

Unfortunately the tmp2 pointer isn't valid after the first stackrestore, 
since the memory it's pointing at has in fact been deallocated by the 
intrinsic, so the uses of it through the variable tmp4 are wrong.

Maybe some dependencies between alloca and the stackrestore instrinsic
are missing or how should this work?

In Intrinsics.td it says

// Note: we treat stacksave/stackrestore as writemem because we don't
otherwise
// model their dependencies on allocas.
def int_stacksave     : Intrinsic<[llvm_ptr_ty]>,
                          GCCBuiltin<"__builtin_stack_save">;
def int_stackrestore  : Intrinsic<[], [llvm_ptr_ty]>,
                          GCCBuiltin<"__builtin_stack_restore">;

Does "GCCBuiltin" imply "writemem", or how does the comment and the code 
correspond?

Second problem:
---------------
It seems that calls to stackrestore are removed if they are close to a
ret instruction. I suppose the idea is that the function epilogue will
restore the stack pointer anyway, so the llvm.stackrestore can be safely 
removed.

However, in my target, the stack restoration in the epilogue is
currently done by adding the used stacksize to the stackpointer, so I do 
indeed need the call to the stackrestore intrinsic to be left.

Am I breaking some design rule by reading the stackpointer in the
epilogue or how is this supposed to work?
Duncan Sands | 1 Feb 16:16
Picon
Favicon

Re: dragonegg arm patch

Hi Jin Gu Kang,

> I send a modified patch which doesn't use reference type of CallingConv::ID.

thanks for the patch.  I applied it with some cosmetic changes, and now I can
compile bzip2 for ARM!  I didn't check if the compiled program works though :)

Ciao, Duncan.

Gmane