[llvm-dev] Passing llvm option -mem2reg to clang

887 views
Skip to first unread message

Syed Rafiul Hussain via llvm-dev

unread,
Mar 21, 2016, 8:52:22 PM3/21/16
to llvm-dev
Hi,

I was trying to pass llvm option -mem2reg to clang using -mllvm and I
found the following error:

clang (LLVM option parsing): Unknown command line argument '-mem2reg'.
Try: 'clang (LLVM option parsing) -help'
clang (LLVM option parsing): Did you mean '-debug'?

I would appreciate if anyone could help me.

--
Syed Rafiul Hussain
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Mehdi Amini via llvm-dev

unread,
Mar 21, 2016, 9:01:22 PM3/21/16
to Syed Rafiul Hussain, llvm-dev
Hi,

You can't schedule passes from the command line using clang, only `opt` has this ability (AFAIK).

If you tell us what is your use-case, we may be able to point you to an alternative solution.

--
Mehdi

Syed Rafiul Hussain via llvm-dev

unread,
Mar 21, 2016, 9:23:51 PM3/21/16
to Mehdi Amini, llvm-dev
I have my own llvm pass which requires mem2reg. It worked fine with
opt. However, I was trying to make it work with clang as I needed it
to run some spec cpu benchmarks.

Is there any way that I can mention mem2reg (PromotePass) pass as a
pre-requisite in my own pass's implementation?


On Mon, Mar 21, 2016 at 9:01 PM, Mehdi Amini <mehdi...@apple.com> wrote:
> Hi,
>
> You can't schedule passes from the command line using clang, only `opt` has this ability (AFAIK).
>
> If you tell us what is your use-case, we may be able to point you to an alternative solution.
>
> --
> Mehdi
>
>> On Mar 21, 2016, at 5:52 PM, Syed Rafiul Hussain via llvm-dev <llvm...@lists.llvm.org> wrote:
>>
>> Hi,
>>
>> I was trying to pass llvm option -mem2reg to clang using -mllvm and I
>> found the following error:
>>
>> clang (LLVM option parsing): Unknown command line argument '-mem2reg'.
>> Try: 'clang (LLVM option parsing) -help'
>> clang (LLVM option parsing): Did you mean '-debug'?
>>
>> I would appreciate if anyone could help me.
>>
>> --
>> Syed Rafiul Hussain
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm...@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>

--
Rafi

Mehdi Amini via llvm-dev

unread,
Mar 21, 2016, 9:26:32 PM3/21/16
to Syed Rafiul Hussain, llvm-dev

> On Mar 21, 2016, at 6:23 PM, Syed Rafiul Hussain <rafiu...@gmail.com> wrote:
>
> I have my own llvm pass which requires mem2reg. It worked fine with
> opt. However, I was trying to make it work with clang as I needed it
> to run some spec cpu benchmarks.
>
> Is there any way that I can mention mem2reg (PromotePass) pass as a
> pre-requisite in my own pass's implementation?

How are you inserting your pass in the pipeline setup by clang?
You should be able to insert mem2reg before the same way.
Also mem2reg is ran by clang when optimizations are enabled, depending on what your pass is doing it may be a matter of inserting it at the right place.

--
Mehdi

Syed Rafiul Hussain via llvm-dev

unread,
Mar 21, 2016, 9:30:40 PM3/21/16
to Mehdi Amini, llvm-dev
I have used the following command for my pass (without -mem2reg):

clang -Xclang -load -Xclang MYPASS.so -c ../../tests/test1.c


For mem2reg, I tried the following:

clang -mllvm -mem2reg -Xclang -load -Xclang MYPASS.so -c ../../tests/test1.c

Kevin Hu via llvm-dev

unread,
Mar 22, 2016, 12:32:40 AM3/22/16
to Syed Rafiul Hussain, llvm...@lists.llvm.org
Hi,

> Is there any way that I can mention mem2reg (PromotePass) pass as a
> pre-requisite in my own pass's implementation?

I think you can consider overriding the Pass::getAnalysisUsage(AnalysisUsage &)
method. Described as follows in manual:

http://www.llvm.org/docs/doxygen/html/classllvm_1_1Pass.html#a048082a5be9ae0d8901ea64de59e5c8f

In your own pass in method getAnalysisUsage(Analysis &AU), you can add required
pass by:

AU.addRequired<PassName>();

And get the analysis from the pass:

PassName &P = getAnalysis<PassName>();

See:

http://www.llvm.org/docs/doxygen/html/classllvm_1_1Pass.html#ab78af013d3a11515403da8517f8f3d4a

Remember to include the necessary header files. This is a way of making sure your
pass always rely on the other passes you want.

BTW I also have a question for the mailing list, is it acceptable to allow an analysis
pass to depend on a transformation pass (like -mem2reg pass)? Is this acceptable so long
as it doesn't cause loop dependencies?


Regards,
Kevin

mats petersson via llvm-dev

unread,
Mar 22, 2016, 10:15:38 AM3/22/16
to Kevin Hu, llvm-dev, Syed Rafiul Hussain
Unless mem2reg does something other than my understanding of it, I can't see why any pass would "require" that... It is not guaranteed to do anything to any particular piece of code, so relying on it seems very unreliable, I would think.

--
Mats

Syed Rafiul Hussain via llvm-dev

unread,
Mar 22, 2016, 11:05:43 AM3/22/16
to mats petersson, llvm-dev
I tried with -mllvm -mem2reg in different ways to fit mem2reg with
clang. I used the following command:

clang -Xclang -mllvm -mem2reg -Xclang -load -Xclang myPass.so -c
../../tests/testIfElse.c


However, it does not work as it gives the error below:
clang-3.8: error: unknown argument: '-mem2reg'


Then I wrote a pass similar to PmotePass (mem2reg), added it as
dependency pass. It works fine with opt. Then I tried to load my
passes with clang using this command:

clang -Xclang -load -Xclang myPass.so -c ../../tests/testIfElse.c

It does not throw any error, however, I found that my pass did not
run and I became sure of that as I could not see any debug messages.
Also, the clang command did not create the corresponding binary.

Could any of you please give any hint what I am doing wrong with clang?

Thanks,
Syed

Reply all
Reply to author
Forward
0 new messages