[PATCH][Clang Driver] Driver::IsUsingLTO no longer return true when seeing -emit-llvm
Shuxin Yang
shuxin.llvm at gmail.com
Tue Aug 13 16:20:08 PDT 2013
Hi,
Driver::IsUsingLTO() returns true when "-emit-llvm" is seen, which is
quite awkward if we need to differentiate following two commands, where
1) is just go through regular passes and stop at llc, while 2) needs to
go through
pre-ipo passes.
1) clang -emit-llvm a.c -c , and
2) clang -flto a.c -c
With this tiny patch is to differentiate these two situations.
However, it changes the semantic of this command:
clang -emit-llvm a.c # NOTE: no -c.
I'm wondering if this command make sense or not.
Without my change, Clang will first generate a BC files, and then
invoke LTO and finally get a.out.
With this change, clang will first generate a BC, and feed the resulting
BC to linker without explicitly saying LTO needs to be turned on; it works
fine on Darwin as Apple LD will invoke LTO if it see a BC file, however,
Other-Unixes + GNU-gold will complains as it see a "corrupted" object file.
Thanks
Shuxin
-------------- next part --------------
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp (revision 188313)
+++ lib/Driver/Driver.cpp (working copy)
@@ -1325,6 +1325,10 @@
types::ID Output =
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
return new CompileJobAction(Input, Output);
+ } else if (Args.hasArg(options::OPT_emit_llvm)) {
+ types::ID Output =
+ Args.hasArg(options::OPT_S) ? types::TY_LLVM_IR : types::TY_LLVM_BC;
+ return new CompileJobAction(Input, Output);
} else {
return new CompileJobAction(Input, types::TY_PP_Asm);
}
@@ -1337,9 +1341,7 @@
}
bool Driver::IsUsingLTO(const ArgList &Args) const {
- // Check for -emit-llvm or -flto.
- if (Args.hasArg(options::OPT_emit_llvm) ||
- Args.hasFlag(options::OPT_flto, options::OPT_fno_lto, false))
+ if (Args.hasFlag(options::OPT_flto, options::OPT_fno_lto, false))
return true;
// Check for -O4.
More information about the llvm-commits
mailing list