intel / intel-graphics-compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined reference to `llvm::Value::dump() const' in GenXCodeGen/GenXSimdCFConformance.cpp

frantisekz opened this issue · comments

Somewhere between igc 1.0.13700.7 and 1.0.14896.8, the build regressed with (I can do a proper bisect if needed):

/usr/bin/g++ -flto=auto -ffat-lto-objects -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -DNDEBUG -Wp,-D_GLIBCXX_ASSERTIONS -m64   -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -w -fexceptions -fdata-sections -ffunction-sections -O2 -fmessage-length=0 -march=corei7 -mstackrealign -fms-extensions -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wwrite-strings -Wno-long-long -Wswitch -Wno-sign-compare -Wno-unused-result -Wno-enum-compare -Wno-type-limits -Wno-ignored-qualifiers -Wno-shadow -Wformat -Wformat-security -Wno-extra -Wno-write-strings -finline -fno-strict-aliasing -msse -msse2 -msse3 -mssse3 -msse4 -msse4.1 -msse4.2 -Wno-unknown-pragmas -fPIC -Bsymbolic -D_FORTIFY_SOURCE=2 -fstack-protector -finline-functions -funswitch-loops -Wno-maybe-uninitialized -lrt -fno-rtti -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG -g -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -Wl,--build-id=sha1 -g -Wl,--gc-sections IGC/VectorCompiler/utils/vcb/CMakeFiles/vcb.dir/vcb.cpp.o IGC/VectorCompiler/utils/vcb/CMakeFiles/vcb.dir/UniqueCompilation.cpp.o -o IGC/Release/vcb  -Wl,-rpath,/usr/lib64/llvm15/lib  IGC/Release/libVCCodeGen.a  IGC/Release/libVCDriver.a  IGC/Release/libVCCodeGen.a  IGC/Release/libGenXDebugInfo.a  IGC/visa/igfxcmjit64.a  IGC/Release/libiga_enc64.a  IGC/Release/libiga_s64.a  IGC/Release/libLLVMGenXIntrinsics.a  IGC/Release/libIGCOptions.a  /usr/lib64/llvm15/lib/libLLVM-15.so  -ldl  /usr/lib64/libLLVMSPIRVLib.so
/usr/bin/ld: /tmp/ccA4xyin.ltrans40.ltrans.o: in function `(anonymous namespace)::GenXSimdCFConformance::ensureConformance()':
/builddir/build/BUILD/intel-graphics-compiler-igc-1.0.15223.2/IGC/VectorCompiler/lib/GenXCodeGen/GenXSimdCFConformance.cpp:1921:(.text._ZN12_GLOBAL__N_121GenXSimdCFConformance17ensureConformanceEv+0x8e6): undefined reference to `llvm::Value::dump() const'
/usr/bin/ld: /builddir/build/BUILD/intel-graphics-compiler-igc-1.0.15223.2/IGC/VectorCompiler/lib/GenXCodeGen/GenXSimdCFConformance.cpp:1926:(.text._ZN12_GLOBAL__N_121GenXSimdCFConformance17ensureConformanceEv+0x94e): undefined reference to `llvm::Value::dump() const'
collect2: error: ld returned 1 exit status

The relevant flags and params are:

CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64   -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -w '
CXXFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64   -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -w '
LDFLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes '

And the configure is called with:

%cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS:BOOL=OFF \
    -DIGC_OPTION__LLVM_PREFERRED_VERSION='%(rpm -q --qf '%%{version}' llvm15-devel | cut -d. -f1 | sed "s/$/.0.0/")' \
    -DVC_INTRINSICS_SRC="%{_builddir}/vc-intrinsics-%{vc_commit}" \
%ifarch x86_64
    -DIGC_OPTION__ARCHITECTURE_TARGET='Linux64' \
%endif
%ifarch i686
    -DIGC_OPTION__ARCHITECTURE_TARGET='Linux32' \
%endif
    -DIGC_OPTION__LINK_KHRONOS_SPIRV_TRANSLATOR=ON \
    -DIGC_BUILD__VC_ENABLED=ON \
    -DIGC_OPTION__SPIRV_TRANSLATOR_MODE=Prebuilds \
    -DIGC_OPTION__CLANG_MODE=Prebuilds \
    -DIGC_OPTION__LLD_MODE=Prebuilds \
    -DIGC_OPTION__LLVM_MODE=Prebuilds \
    -DLLVM_ROOT=%{_libdir}/llvm15/ \
    -DIGC_OPTION__SPIRV_TOOLS_MODE=Prebuilds \
    -DIGC_OPTION__USE_PREINSTALLED_SPIRV_HEADERS=ON \
    -DIGC_OPTION__VC_INTRINSICS_MODE=Source \
    -DINSTALL_GENX_IR=ON \
    -Wno-dev \
    -G Ninja

Used llvm version is 15.0.7, opencl-clang bc1d13ecc1c6f7aa5da3acf33165037d3fc5ed06, and vc fe92a377338258b725cfbd0a1bd49a9cf5e2864c .

I can confirm this issue here. Enabling VC (-DIGC_BUILD__VC_ENABLED=ON) causes the reported compilation failiure for me.

Version 1.0.14062.11 is one of the lastest releases, which works for me with enabled VC.

@ConiKost If I understand it correctly, the failing functions are only for debugging, I was able to make it build with the following workaround:

--- a/IGC/VectorCompiler/lib/GenXCodeGen/GenXSimdCFConformance.cpp
+++ b/IGC/VectorCompiler/lib/GenXCodeGen/GenXSimdCFConformance.cpp
@@ -1867,11 +1867,13 @@ void GenXSimdCFConformance::ensureConformance() {
         IID != GenXIntrinsic::genx_simdcf_unmask &&
         IID != GenXIntrinsic::genx_simdcf_remask) {
       EMValsStack.insert(*i);
+      #ifdef DEBUG_VERBOSE_ON
       LLVM_DEBUG(if (auto *Inst = dyn_cast<Instruction>(i->getValue())) {
         auto FuncName = Inst->getFunction()->getName();
         dbgs() << "Entry EMVals " << FuncName << " - ";
         i->getValue()->dump();
       });
+      #endif
     }
   }
   for (auto i = EMVals.begin(), e = EMVals.end(); i != e; ++i) {
@@ -1919,6 +1921,7 @@ void GenXSimdCFConformance::ensureConformance() {
     // been identified in the early pass, unless passes in between have
     // transformed the code in an unexpected way that has made the simd CF
     // non-conformant. Give an error here if this has happened.
+    #ifdef DEBUG_VERBOSE_ON
     if (!GotosToLower.empty()) {
       dbgs() << "Not empty GotosToLower:";
       for (auto *Dump : GotosToLower)
@@ -1929,6 +1932,7 @@ void GenXSimdCFConformance::ensureConformance() {
       for (auto *Dump : JoinsToLower)
         Dump->dump();
     }
+    #endif
     IGC_ASSERT_EXIT_MESSAGE(
         GotosToLower.empty(),
         "unexpected non-conformant SIMD CF in late SIMD CF conformance pass");
@@ -2460,8 +2464,10 @@ static bool checkAllUsesAreSelectOrWrRegion(Value *V) {
     auto User2 = cast<Instruction>(ui2->getUser());
     unsigned OpNum = ui2->getOperandNo();
     ++ui2;
+    #ifdef DEBUG_VERBOSE_ON
     LLVM_DEBUG(dbgs() << "checkAllUsesAreSelectOrWrRegion: for user ";
                User2->dump());
+    #endif
 
     if (isa<SelectInst>(User2))
       continue;
@@ -3006,12 +3012,14 @@ bool GenXSimdCFConformance::getConnectedVals(
     }
   } else {
     if (!UsersToLower.empty()) {
+      #ifdef DEBUG_VERBOSE_ON
       LLVM_DEBUG(dbgs() << "getConnectedVals: find bad users:\n";
                  for (auto &BadUser
                       : UsersToLower) {
                    dbgs() << "    ";
                    BadUser.dump();
                  });
+      #endif
       return false;
     }
   }
-- 

@frantisekz Yes, I can confirm. Patch fixes the error for me.

@frantisekz thanks a lot for reporting and triage! Will fix this issue as soon as possible. But it is better to use default llvm-debug defines:

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

If you build with a "Debug" llvm, then the llvm::Value::dump symbol is available (in libLLVMCore, maybe?). But if you are using a production (Release) build of llvm, then it's not.

The culprit commit to GenXSimdCFConfrmance.cpp was 6db7f87 back in March, 2023:

+    if (auto *Inst = dyn_cast<Instruction>(i->getValue())) {
+      auto FuncName = Inst->getFunction()->getName();
+      LLVM_DEBUG(dbgs() << "Entry EMVals " << FuncName << " - ";
+                 i->getValue()->dump());
+    }

Similarly, if you build intel-graphics-compiler with as Release (invoke cmake with -DCMAKE_BUILD_TYPE=Release), then the build should use -DNDEBUG and LLVM_DEBUG becomes a no-op. And that IS true (i.e., -DNDEBUG is used) for some of the compilation commands in the tree. But not for anything under GenXCodeGen. So that just looks like some cmake work to ensure -DNDEBUG gets passed in the GenXCodeGen compilation. I don't have a CMakeLists.txt patch at the moment.

For me, for the moment, I reverted to building Release 1.0.13463.18 - that was before the above commit.

Fix has been merged in 9be3363 . Please re-check, because I can't reproduce bug locally.

@igorban-intel Thank you! :-) I can confirm, applying your patch solves the issue.

Fix has been merged in 9be3363 . Please re-check, because I can't reproduce bug locally.

That does not fix the problem that when building intel-graphics-compiler with -DCMAKE_BUILD_TYPE=Release, -DNDEBUG is not passed to compilation in GenXCodeGen/.

The above commit does remove the call to llvm::Value::dump (even when -DNDEBUG is not defined). So it does address the undefined reference.

But -NDEBUG should be passed to compilation when doing a Release build. -DNDEBUG has the effect of disabling LLVM_DEBUG (as intended and is documented in LLVM_DEBUG usage).

Granted that problem (-DNDEBUG should be passed to compilation when building for Release thus disabling LLVM_DEBUG) is a separate bug than the one posted in this issue. But it would have solved this issue.

Fix has been merged in 9be3363 . Please re-check, because I can't reproduce bug locally.

And to reproduce it locally, the recipe would have been to build intel-graphics-compiler (the version that called llvm::Value::dump) against a Release version of llvm - i.e., one where libLLVMCore does not define llvm::Value::dump (a Debug version of llvm defines that symbol).

llvm could also be built with -DLLVM_ENABLE_ASSERTIONS=ON or -DLLVM_ENABLE_DUMP to get llvm::Value::dump.

See also https://stackoverflow.com/a/46700512 for an alleged equivalent to using llvm::Value::dump()
See also https://groups.google.com/g/llvm-dev/c/rO1zCNxET5U

Thanks @jhgit for your investigation - we will re-check builds to pass NDEBUG-option

@igorban-intel ,
How about

LLVM_DEBUG(
    dbgs() << *Instr;
    // OR
    Instr->print(dbgs());
)

?