Re: [Mesa-dev] [PATCH v2 05/14] swr: [rasterizer jitter] cleanup supporting different llvm versions
On 22 June 2016 at 21:01, Rowley, Timothy Owrote: > >> On Jun 22, 2016, at 2:27 PM, Emil Velikov wrote: >> >> On 22 June 2016 at 20:19, Rowley, Timothy O >> wrote: >>> On Jun 22, 2016, at 1:52 PM, Emil Velikov wrote: On 20 June 2016 at 22:36, Tim Rowley wrote: > --- > .../drivers/swr/rasterizer/jitter/JitManager.cpp | 9 +-- > .../drivers/swr/rasterizer/jitter/JitManager.h | 7 - > .../drivers/swr/rasterizer/jitter/blend_jit.cpp| 8 +- > .../drivers/swr/rasterizer/jitter/builder_misc.cpp | 31 > +++--- > .../drivers/swr/rasterizer/jitter/builder_misc.h | 6 + > .../drivers/swr/rasterizer/jitter/fetch_jit.cpp| 15 ++- > .../jitter/scripts/gen_llvm_ir_macros.py | 24 - > .../swr/rasterizer/jitter/streamout_jit.cpp| 7 + > 8 files changed, 73 insertions(+), 34 deletions(-) > > diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp > b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp > index 4bbd9ad..6e00a70 100644 > --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp > +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp > @@ -35,11 +35,13 @@ > #include "JitManager.h" > #include "fetch_jit.h" > > +#pragma push_macro("DEBUG") > +#undef DEBUG > + > #if defined(_WIN32) > #include "llvm/ADT/Triple.h" > #endif > #include "llvm/IR/Function.h" > -#include "llvm/Support/DynamicLibrary.h" > > #include "llvm/Support/MemoryBuffer.h" > #include "llvm/Support/SourceMgr.h" > @@ -53,6 +55,8 @@ > #include "llvm/ExecutionEngine/JITEventListener.h" > #endif > > +#pragma pop_macro("DEBUG") > + I'm afraid that these still are still off - they should be wrapped in "if HAVE_LLVM >= 0x0307 ... endif". Plus the ones in JitManager.h really want a similar treatment. >>> >>> Any reason to avoid the push/pop on older LLVM? Saves things from becoming >>> too messy with preprocessor directives. >>> >> Because those are used by gallium (and mesa). If you undefine it here, >> then somewhere down the chain of includes you'll end up in headers >> that use it and things will go meh. > > I think I’m missing something obvious - the push/undef/pop sequence surrounds > just the llvm includes in JitManager.{h,cpp}, and at the end of pop_macro the > DEBUG macro will be back to what it was originally defined as. The reason > for adding them is to isolate the llvm usage. > It's a bit fragile, as there's nothing stopping others (yourself X months down the line) from moving a swr/gallium header between the push and pop. But at the end of the day I won't be debugging (if it breaks) or keeping track, so don't mind me. >> >> a>> Mildly related bugs/cleanups: - There's a few cases of _DEBUG which should (?) be replaced with ifndef NDEBUG >>> >>> Ok, I can address this in another patch. >>> >> IMHO it's worth sorting both identical issues (and checking for other >> offenders) in one patch. Be that here, or as follow on it's up-to you. > > _DEBUG usage spills into rasterizer/{common,core} which is why I was thinking > of addressing it in a different commit rather than this one which concerns > itself just with the jitter directory. > Apologies, got the line ordering wrong - my suggestion does not apply here. - swr uses both mesa and LLVM provided version macros. Please stick to one. If the latter is reliable (available all the way to min. supported LLVM version) and can be used in both C and C++ sources I'm inclined to just use it everywhere in mesa and drop out local macros… >>> >>> Are you referring to the HAVE_LLVM macro? I can remove the conditional >>> definition of this from swr (since Mesa provides the definition). >>> >> Mesa provides HAVE_LLVM and MESA_LLVM_VERSION_PATCH while LLVM does >> LLVM_VERSION_{MAJOR,MINOR,PATCH}. Personally I'm in faviour of the >> latter (considering the 'reliable' note above), but using one of them >> (regardless which) is what you want imho. > > Conditional code for different llvm versions is much easier with the > HAVE_LLVM style combined major/minor rather than using LLVM_VERSION_* (which > if not done properly will break if they ever switch to llvm-4.x). > I hope they don't break that one ... there'll be dozens of projects that'll be busted :-) -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v2 05/14] swr: [rasterizer jitter] cleanup supporting different llvm versions
> On Jun 22, 2016, at 2:27 PM, Emil Velikovwrote: > > On 22 June 2016 at 20:19, Rowley, Timothy O > wrote: >> >>> On Jun 22, 2016, at 1:52 PM, Emil Velikov wrote: >>> >>> On 20 June 2016 at 22:36, Tim Rowley wrote: --- .../drivers/swr/rasterizer/jitter/JitManager.cpp | 9 +-- .../drivers/swr/rasterizer/jitter/JitManager.h | 7 - .../drivers/swr/rasterizer/jitter/blend_jit.cpp| 8 +- .../drivers/swr/rasterizer/jitter/builder_misc.cpp | 31 +++--- .../drivers/swr/rasterizer/jitter/builder_misc.h | 6 + .../drivers/swr/rasterizer/jitter/fetch_jit.cpp| 15 ++- .../jitter/scripts/gen_llvm_ir_macros.py | 24 - .../swr/rasterizer/jitter/streamout_jit.cpp| 7 + 8 files changed, 73 insertions(+), 34 deletions(-) diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp index 4bbd9ad..6e00a70 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp @@ -35,11 +35,13 @@ #include "JitManager.h" #include "fetch_jit.h" +#pragma push_macro("DEBUG") +#undef DEBUG + #if defined(_WIN32) #include "llvm/ADT/Triple.h" #endif #include "llvm/IR/Function.h" -#include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" @@ -53,6 +55,8 @@ #include "llvm/ExecutionEngine/JITEventListener.h" #endif +#pragma pop_macro("DEBUG") + >>> I'm afraid that these still are still off - they should be wrapped in >>> "if HAVE_LLVM >= 0x0307 ... endif". Plus the ones in JitManager.h >>> really want a similar treatment. >> >> Any reason to avoid the push/pop on older LLVM? Saves things from becoming >> too messy with preprocessor directives. >> > Because those are used by gallium (and mesa). If you undefine it here, > then somewhere down the chain of includes you'll end up in headers > that use it and things will go meh. I think I’m missing something obvious - the push/undef/pop sequence surrounds just the llvm includes in JitManager.{h,cpp}, and at the end of pop_macro the DEBUG macro will be back to what it was originally defined as. The reason for adding them is to isolate the llvm usage. > > a>> Mildly related bugs/cleanups: >>> - There's a few cases of _DEBUG which should (?) be replaced with ifndef >>> NDEBUG >> >> Ok, I can address this in another patch. >> > IMHO it's worth sorting both identical issues (and checking for other > offenders) in one patch. Be that here, or as follow on it's up-to you. _DEBUG usage spills into rasterizer/{common,core} which is why I was thinking of addressing it in a different commit rather than this one which concerns itself just with the jitter directory. >>> - swr uses both mesa and LLVM provided version macros. Please stick to one. >>> If the latter is reliable (available all the way to min. supported >>> LLVM version) and can be used in both C and C++ sources I'm inclined >>> to just use it everywhere in mesa and drop out local macros… >> >> Are you referring to the HAVE_LLVM macro? I can remove the conditional >> definition of this from swr (since Mesa provides the definition). >> > Mesa provides HAVE_LLVM and MESA_LLVM_VERSION_PATCH while LLVM does > LLVM_VERSION_{MAJOR,MINOR,PATCH}. Personally I'm in faviour of the > latter (considering the 'reliable' note above), but using one of them > (regardless which) is what you want imho. Conditional code for different llvm versions is much easier with the HAVE_LLVM style combined major/minor rather than using LLVM_VERSION_* (which if not done properly will break if they ever switch to llvm-4.x). > All of ^^ are just ideas, feel free to take or leave them. > -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v2 05/14] swr: [rasterizer jitter] cleanup supporting different llvm versions
On 22 June 2016 at 20:19, Rowley, Timothy Owrote: > >> On Jun 22, 2016, at 1:52 PM, Emil Velikov wrote: >> >> On 20 June 2016 at 22:36, Tim Rowley wrote: >>> --- >>> .../drivers/swr/rasterizer/jitter/JitManager.cpp | 9 +-- >>> .../drivers/swr/rasterizer/jitter/JitManager.h | 7 - >>> .../drivers/swr/rasterizer/jitter/blend_jit.cpp| 8 +- >>> .../drivers/swr/rasterizer/jitter/builder_misc.cpp | 31 >>> +++--- >>> .../drivers/swr/rasterizer/jitter/builder_misc.h | 6 + >>> .../drivers/swr/rasterizer/jitter/fetch_jit.cpp| 15 ++- >>> .../jitter/scripts/gen_llvm_ir_macros.py | 24 - >>> .../swr/rasterizer/jitter/streamout_jit.cpp| 7 + >>> 8 files changed, 73 insertions(+), 34 deletions(-) >>> >>> diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp >>> b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp >>> index 4bbd9ad..6e00a70 100644 >>> --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp >>> +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp >>> @@ -35,11 +35,13 @@ >>> #include "JitManager.h" >>> #include "fetch_jit.h" >>> >>> +#pragma push_macro("DEBUG") >>> +#undef DEBUG >>> + >>> #if defined(_WIN32) >>> #include "llvm/ADT/Triple.h" >>> #endif >>> #include "llvm/IR/Function.h" >>> -#include "llvm/Support/DynamicLibrary.h" >>> >>> #include "llvm/Support/MemoryBuffer.h" >>> #include "llvm/Support/SourceMgr.h" >>> @@ -53,6 +55,8 @@ >>> #include "llvm/ExecutionEngine/JITEventListener.h" >>> #endif >>> >>> +#pragma pop_macro("DEBUG") >>> + >> I'm afraid that these still are still off - they should be wrapped in >> "if HAVE_LLVM >= 0x0307 ... endif". Plus the ones in JitManager.h >> really want a similar treatment. > > Any reason to avoid the push/pop on older LLVM? Saves things from becoming > too messy with preprocessor directives. > Because those are used by gallium (and mesa). If you undefine it here, then somewhere down the chain of includes you'll end up in headers that use it and things will go meh. a>> Mildly related bugs/cleanups: >> - There's a few cases of _DEBUG which should (?) be replaced with ifndef >> NDEBUG > > Ok, I can address this in another patch. > IMHO it's worth sorting both identical issues (and checking for other offenders) in one patch. Be that here, or as follow on it's up-to you. >> - swr uses both mesa and LLVM provided version macros. Please stick to one. >> If the latter is reliable (available all the way to min. supported >> LLVM version) and can be used in both C and C++ sources I'm inclined >> to just use it everywhere in mesa and drop out local macros… > > Are you referring to the HAVE_LLVM macro? I can remove the conditional > definition of this from swr (since Mesa provides the definition). > Mesa provides HAVE_LLVM and MESA_LLVM_VERSION_PATCH while LLVM does LLVM_VERSION_{MAJOR,MINOR,PATCH}. Personally I'm in faviour of the latter (considering the 'reliable' note above), but using one of them (regardless which) is what you want imho. All of ^^ are just ideas, feel free to take or leave them. -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v2 05/14] swr: [rasterizer jitter] cleanup supporting different llvm versions
> On Jun 22, 2016, at 1:52 PM, Emil Velikovwrote: > > On 20 June 2016 at 22:36, Tim Rowley wrote: >> --- >> .../drivers/swr/rasterizer/jitter/JitManager.cpp | 9 +-- >> .../drivers/swr/rasterizer/jitter/JitManager.h | 7 - >> .../drivers/swr/rasterizer/jitter/blend_jit.cpp| 8 +- >> .../drivers/swr/rasterizer/jitter/builder_misc.cpp | 31 >> +++--- >> .../drivers/swr/rasterizer/jitter/builder_misc.h | 6 + >> .../drivers/swr/rasterizer/jitter/fetch_jit.cpp| 15 ++- >> .../jitter/scripts/gen_llvm_ir_macros.py | 24 - >> .../swr/rasterizer/jitter/streamout_jit.cpp| 7 + >> 8 files changed, 73 insertions(+), 34 deletions(-) >> >> diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp >> b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp >> index 4bbd9ad..6e00a70 100644 >> --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp >> +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp >> @@ -35,11 +35,13 @@ >> #include "JitManager.h" >> #include "fetch_jit.h" >> >> +#pragma push_macro("DEBUG") >> +#undef DEBUG >> + >> #if defined(_WIN32) >> #include "llvm/ADT/Triple.h" >> #endif >> #include "llvm/IR/Function.h" >> -#include "llvm/Support/DynamicLibrary.h" >> >> #include "llvm/Support/MemoryBuffer.h" >> #include "llvm/Support/SourceMgr.h" >> @@ -53,6 +55,8 @@ >> #include "llvm/ExecutionEngine/JITEventListener.h" >> #endif >> >> +#pragma pop_macro("DEBUG") >> + > I'm afraid that these still are still off - they should be wrapped in > "if HAVE_LLVM >= 0x0307 ... endif". Plus the ones in JitManager.h > really want a similar treatment. Any reason to avoid the push/pop on older LLVM? Saves things from becoming too messy with preprocessor directives. > Mildly related bugs/cleanups: > - There's a few cases of _DEBUG which should (?) be replaced with ifndef > NDEBUG Ok, I can address this in another patch. > - swr uses both mesa and LLVM provided version macros. Please stick to one. > If the latter is reliable (available all the way to min. supported > LLVM version) and can be used in both C and C++ sources I'm inclined > to just use it everywhere in mesa and drop out local macros… Are you referring to the HAVE_LLVM macro? I can remove the conditional definition of this from swr (since Mesa provides the definition). -Tim ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v2 05/14] swr: [rasterizer jitter] cleanup supporting different llvm versions
On 20 June 2016 at 22:36, Tim Rowleywrote: > --- > .../drivers/swr/rasterizer/jitter/JitManager.cpp | 9 +-- > .../drivers/swr/rasterizer/jitter/JitManager.h | 7 - > .../drivers/swr/rasterizer/jitter/blend_jit.cpp| 8 +- > .../drivers/swr/rasterizer/jitter/builder_misc.cpp | 31 > +++--- > .../drivers/swr/rasterizer/jitter/builder_misc.h | 6 + > .../drivers/swr/rasterizer/jitter/fetch_jit.cpp| 15 ++- > .../jitter/scripts/gen_llvm_ir_macros.py | 24 - > .../swr/rasterizer/jitter/streamout_jit.cpp| 7 + > 8 files changed, 73 insertions(+), 34 deletions(-) > > diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp > b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp > index 4bbd9ad..6e00a70 100644 > --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp > +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp > @@ -35,11 +35,13 @@ > #include "JitManager.h" > #include "fetch_jit.h" > > +#pragma push_macro("DEBUG") > +#undef DEBUG > + > #if defined(_WIN32) > #include "llvm/ADT/Triple.h" > #endif > #include "llvm/IR/Function.h" > -#include "llvm/Support/DynamicLibrary.h" > > #include "llvm/Support/MemoryBuffer.h" > #include "llvm/Support/SourceMgr.h" > @@ -53,6 +55,8 @@ > #include "llvm/ExecutionEngine/JITEventListener.h" > #endif > > +#pragma pop_macro("DEBUG") > + I'm afraid that these still are still off - they should be wrapped in "if HAVE_LLVM >= 0x0307 ... endif". Plus the ones in JitManager.h really want a similar treatment. Mildly related bugs/cleanups: - There's a few cases of _DEBUG which should (?) be replaced with ifndef NDEBUG - swr uses both mesa and LLVM provided version macros. Please stick to one. If the latter is reliable (available all the way to min. supported LLVM version) and can be used in both C and C++ sources I'm inclined to just use it everywhere in mesa and drop out local macros... The python changes look great imho :-) -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 05/14] swr: [rasterizer jitter] cleanup supporting different llvm versions
--- .../drivers/swr/rasterizer/jitter/JitManager.cpp | 9 +-- .../drivers/swr/rasterizer/jitter/JitManager.h | 7 - .../drivers/swr/rasterizer/jitter/blend_jit.cpp| 8 +- .../drivers/swr/rasterizer/jitter/builder_misc.cpp | 31 +++--- .../drivers/swr/rasterizer/jitter/builder_misc.h | 6 + .../drivers/swr/rasterizer/jitter/fetch_jit.cpp| 15 ++- .../jitter/scripts/gen_llvm_ir_macros.py | 24 - .../swr/rasterizer/jitter/streamout_jit.cpp| 7 + 8 files changed, 73 insertions(+), 34 deletions(-) diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp index 4bbd9ad..6e00a70 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp @@ -35,11 +35,13 @@ #include "JitManager.h" #include "fetch_jit.h" +#pragma push_macro("DEBUG") +#undef DEBUG + #if defined(_WIN32) #include "llvm/ADT/Triple.h" #endif #include "llvm/IR/Function.h" -#include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" @@ -53,6 +55,8 @@ #include "llvm/ExecutionEngine/JITEventListener.h" #endif +#pragma pop_macro("DEBUG") + #include "core/state.h" #include "state_llvm.h" @@ -237,6 +241,8 @@ bool JitManager::SetupModuleFromIR(const uint8_t *pIR) return false; } +newModule->setDataLayout(mpExec->getDataLayout()); + mpCurrentModule = newModule.get(); #if defined(_WIN32) // Needed for MCJIT on windows @@ -251,7 +257,6 @@ bool JitManager::SetupModuleFromIR(const uint8_t *pIR) return true; } - // /// @brief Dump function x86 assembly to file. /// @note This should only be called after the module has been jitted to x86 and the diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h index 14ba893..354bfe8 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h @@ -54,7 +54,7 @@ #endif #ifndef HAVE_LLVM -#define HAVE_LLVM (LLVM_VERSION_MAJOR << 8) || LLVM_VERSION_MINOR +#define HAVE_LLVM ((LLVM_VERSION_MAJOR << 8) | LLVM_VERSION_MINOR) #endif #include "llvm/IR/Verifier.h" @@ -66,8 +66,12 @@ #if HAVE_LLVM == 0x306 #include "llvm/PassManager.h" +using FunctionPassManager = llvm::FunctionPassManager; +using PassManager = llvm::PassManager; #else #include "llvm/IR/LegacyPassManager.h" +using FunctionPassManager = llvm::legacy::FunctionPassManager; +using PassManager = llvm::legacy::PassManager; #endif #include "llvm/CodeGen/Passes.h" @@ -77,6 +81,7 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/Host.h" +#include "llvm/Support/DynamicLibrary.h" #pragma pop_macro("DEBUG") diff --git a/src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp b/src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp index 1b5290c..940399c 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp @@ -31,7 +31,6 @@ #include "blend_jit.h" #include "builder.h" #include "state_llvm.h" -#include "llvm/IR/DataLayout.h" #include @@ -725,12 +724,7 @@ struct BlendJit : public Builder JitManager::DumpToFile(blendFunc, ""); -#if HAVE_LLVM == 0x306 -FunctionPassManager -#else -llvm::legacy::FunctionPassManager -#endif -passes(JM()->mpCurrentModule); +::FunctionPassManager passes(JM()->mpCurrentModule); passes.add(createBreakCriticalEdgesPass()); passes.add(createCFGSimplificationPass()); diff --git a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp index 2f4fa38..671178f 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp @@ -30,8 +30,6 @@ #include "builder.h" #include "common/rdtsc_buckets.h" -#include "llvm/Support/DynamicLibrary.h" - void __cdecl CallPrint(const char* fmt, ...); // @@ -322,6 +320,32 @@ CallInst *Builder::CALL(Value *Callee, const std::initializer_listreturn CALLA(Callee, args); } +#if HAVE_LLVM > 0x306 +CallInst *Builder::CALL(Value *Callee, Value* arg) +{ +std::vector args; +args.push_back(arg); +return CALLA(Callee, args); +} + +CallInst *Builder::CALL2(Value *Callee, Value* arg1, Value* arg2) +{ +std::vector args; +args.push_back(arg1); +args.push_back(arg2); +return CALLA(Callee, args); +} + +CallInst *Builder::CALL3(Value *Callee, Value* arg1, Value* arg2, Value* arg3) +{ +