Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPIRV] Emitting DebugSource, DebugCompileUnit #97558

Merged
merged 19 commits into from
Aug 23, 2024

Conversation

bwlodarcz
Copy link
Contributor

@bwlodarcz bwlodarcz commented Jul 3, 2024

This commit introduces emission of DebugSource, DebugCompileUnit from NonSemantic.Shader.DebugInfo.100 and required OpString with filename.
NonSemantic.Shader.DebugInfo.100 is divided, following DWARF into two main concepts – emitting DIE and Line.
In DWARF .debug_abbriev and .debug_info sections are responsible for emitting tree with information (DEIs) about e.g. types, compilation unit. Corresponding to that in NonSemantic.Shader.DebugInfo.100 have instructions like DebugSource, DebugCompileUnit etc. which preforms same role in SPIR-V file. The difference is in fact that in SPIR-V there are no sections but logical layout which forces order of the instruction emission.
The NonSemantic.Shader.DebugInfo.100 requires for this type of global information to be emitted after OpTypeXXX and OpConstantXXX instructions.
One of the goals was to minimize changes and interaction with SPIRVModuleAnalysis as possible which current commit achieves by emitting it’s instructions directly into MachineFunction.
The possibility of duplicates are mitigated by guard inside pass which emits the global information only once in one function.
By that method duplicates don’t have chance to be emitted.
From that point, adding new debug global instructions should be straightforward.

@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2024

@llvm/pr-subscribers-backend-spir-v

Author: None (bwlodarcz)

Changes

This commit introduces emission of DebugSource, DebugCompileUnit from NonSemantic.Shader.DebugInfo.100 and required OpString with filename.
NonSemantic.Shader.DebugInfo.100 is divided, following DWARF into two main concepts – emitting DIE and Line.
In DWARF .debug_abbriev and .debug_line sections are responsible for emitting tree with information (DEIs) about e.g. types, compilation unit. Corresponding to that in NonSemantic.Shader.DebugInfo.100 have instructions like DebugSource, DebugCompileUnit etc. which preforms same role in SPIR-V file. The difference is in fact that in SPIR-V there are no sections but logical layout which forces order of the instruction emission.
The NonSemantic.Shader.DebugInfo.100 requires for this type of global information to be emitted after OpTypeXXX and OpConstantXXX instructions.
One of the goals was to minimize changes and interaction with SPIRVModuleAnalysis as possible which current commit achieves by emitting it’s instructions directly into MachineFunction.
The possibility of duplicates are mitigated by guard inside pass which emits the global information only once in one function.
By that method duplicates don’t have chance to be emitted.
From that point, adding new debug global instructions should be straightforward.


Full diff: https://github.com/llvm/llvm-project/pull/97558.diff

7 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/CMakeLists.txt (+1)
  • (modified) llvm/lib/Target/SPIRV/SPIRV.h (+2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp (+6-2)
  • (added) llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp (+148)
  • (modified) llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp (+15-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h (+2-1)
  • (modified) llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp (+1)
diff --git a/llvm/lib/Target/SPIRV/CMakeLists.txt b/llvm/lib/Target/SPIRV/CMakeLists.txt
index 14647e92f5d08..5f8aea5fc8d84 100644
--- a/llvm/lib/Target/SPIRV/CMakeLists.txt
+++ b/llvm/lib/Target/SPIRV/CMakeLists.txt
@@ -40,6 +40,7 @@ add_llvm_target(SPIRVCodeGen
   SPIRVSubtarget.cpp
   SPIRVTargetMachine.cpp
   SPIRVUtils.cpp
+  SPIRVEmitNonSemanticDI.cpp
 
   LINK_COMPONENTS
   Analysis
diff --git a/llvm/lib/Target/SPIRV/SPIRV.h b/llvm/lib/Target/SPIRV/SPIRV.h
index e597a1dc8dc06..6c35a467f53be 100644
--- a/llvm/lib/Target/SPIRV/SPIRV.h
+++ b/llvm/lib/Target/SPIRV/SPIRV.h
@@ -26,6 +26,7 @@ FunctionPass *createSPIRVRegularizerPass();
 FunctionPass *createSPIRVPreLegalizerPass();
 FunctionPass *createSPIRVPostLegalizerPass();
 ModulePass *createSPIRVEmitIntrinsicsPass(SPIRVTargetMachine *TM);
+MachineFunctionPass *createSPIRVEmitNonSemanticDIPass(SPIRVTargetMachine *TM);
 InstructionSelector *
 createSPIRVInstructionSelector(const SPIRVTargetMachine &TM,
                                const SPIRVSubtarget &Subtarget,
@@ -36,6 +37,7 @@ void initializeSPIRVConvergenceRegionAnalysisWrapperPassPass(PassRegistry &);
 void initializeSPIRVPreLegalizerPass(PassRegistry &);
 void initializeSPIRVPostLegalizerPass(PassRegistry &);
 void initializeSPIRVEmitIntrinsicsPass(PassRegistry &);
+void initializeSPIRVEmitNonSemanticDIPass(PassRegistry &);
 } // namespace llvm
 
 #endif // LLVM_LIB_TARGET_SPIRV_SPIRV_H
diff --git a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
index 3206c264f99d3..f9f36cc25eec5 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
@@ -273,6 +273,8 @@ void SPIRVAsmPrinter::outputDebugSourceAndStrings(const Module &M) {
     addStringImm(Str.first(), Inst);
     outputMCInst(Inst);
   }
+  // Output OpString.
+  outputModuleSection(SPIRV::MB_DebugStrings);
   // Output OpSource.
   MCInst Inst;
   Inst.setOpcode(SPIRV::OpSource);
@@ -588,9 +590,11 @@ void SPIRVAsmPrinter::outputModuleSections() {
   // the first section to allow use of: OpLine and OpNoLine debug information;
   // non-semantic instructions with OpExtInst.
   outputModuleSection(SPIRV::MB_TypeConstVars);
-  // 10. All function declarations (functions without a body).
+  // 10. All global NonSemantic.Shader.DebugInfo.100 instructions.
+  outputModuleSection(SPIRV::MB_NonSemanticGlobalDI);
+  // 11. All function declarations (functions without a body).
   outputExtFuncDecls();
-  // 11. All function definitions (functions with a body).
+  // 12. All function definitions (functions with a body).
   // This is done in regular function output.
 }
 
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
new file mode 100644
index 0000000000000..f630685d98ac8
--- /dev/null
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
@@ -0,0 +1,148 @@
+#include "MCTargetDesc/SPIRVBaseInfo.h"
+#include "SPIRVGlobalRegistry.h"
+#include "SPIRVRegisterInfo.h"
+#include "SPIRVTargetMachine.h"
+#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/CodeGen/MachineOperand.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/PassRegistry.h"
+#include "llvm/Support/Casting.h"
+
+namespace llvm {
+struct SPIRVEmitNonSemanticDI : public MachineFunctionPass {
+  static char ID;
+  SPIRVTargetMachine *TM;
+  SPIRVEmitNonSemanticDI(SPIRVTargetMachine *TM);
+  SPIRVEmitNonSemanticDI();
+
+  bool runOnMachineFunction(MachineFunction &MF) override;
+
+private:
+  bool IsGlobalDIEmitted = false;
+  bool emitGlobalDI(MachineFunction &MF);
+};
+
+void initializeSPIRVEmitNonSemanticDIPass(PassRegistry &);
+
+FunctionPass *createSPIRVEmitNonSemanticDIPass(SPIRVTargetMachine *TM) {
+  return new SPIRVEmitNonSemanticDI(TM);
+}
+} // namespace llvm
+
+using namespace llvm;
+
+INITIALIZE_PASS(SPIRVEmitNonSemanticDI, "spirv-nonsemantic-debug-info",
+                "SPIRV NonSemantic.Shader.DebugInfo.100 emitter", false, false)
+
+char SPIRVEmitNonSemanticDI::ID = 0;
+
+SPIRVEmitNonSemanticDI::SPIRVEmitNonSemanticDI(SPIRVTargetMachine *TM)
+    : MachineFunctionPass(ID), TM(TM) {
+  initializeSPIRVEmitNonSemanticDIPass(*PassRegistry::getPassRegistry());
+}
+
+SPIRVEmitNonSemanticDI::SPIRVEmitNonSemanticDI() : MachineFunctionPass(ID) {
+  initializeSPIRVEmitNonSemanticDIPass(*PassRegistry::getPassRegistry());
+}
+
+bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
+  MachineModuleInfo &MMI = MF.getMMI();
+  const Module *M = MMI.getModule();
+  NamedMDNode *DbgCu = M->getNamedMetadata("llvm.dbg.cu");
+  if (!DbgCu) {
+    return false;
+  }
+  std::string FilePath;
+  unsigned SourceLanguage;
+  unsigned NumOp = DbgCu->getNumOperands();
+  if (NumOp) {
+    if (const auto *CompileUnit =
+            dyn_cast<DICompileUnit>(DbgCu->getOperand(0))) {
+      DIFile *File = CompileUnit->getFile();
+      FilePath = ((File->getDirectory() + "/" + File->getFilename())).str();
+      SourceLanguage = CompileUnit->getSourceLanguage();
+    }
+  }
+  NamedMDNode *ModuleFlags = M->getNamedMetadata("llvm.module.flags");
+  int64_t DwarfVersion = 0;
+  int64_t DebugInfoVersion = 0;
+  for (auto *Op : ModuleFlags->operands()) {
+    const MDOperand &StrOp = Op->getOperand(1);
+    if (StrOp.equalsStr("Dwarf Version")) {
+      DwarfVersion =
+          cast<ConstantInt>(
+              cast<ConstantAsMetadata>(Op->getOperand(2))->getValue())
+              ->getSExtValue();
+    } else if (StrOp.equalsStr("Debug Info Version")) {
+      DebugInfoVersion =
+          cast<ConstantInt>(
+              cast<ConstantAsMetadata>(Op->getOperand(2))->getValue())
+              ->getSExtValue();
+    }
+  }
+  const SPIRVInstrInfo *TII = TM->getSubtargetImpl()->getInstrInfo();
+  const SPIRVRegisterInfo *TRI = TM->getSubtargetImpl()->getRegisterInfo();
+  const RegisterBankInfo *RBI = TM->getSubtargetImpl()->getRegBankInfo();
+  SPIRVGlobalRegistry *GR = TM->getSubtargetImpl()->getSPIRVGlobalRegistry();
+  MachineRegisterInfo &MRI = MF.getRegInfo();
+  for (MachineBasicBlock &MBB : MF) {
+    MachineIRBuilder MIRBuilder(MBB, MBB.begin());
+
+    MachineInstrBuilder MIB = MIRBuilder.buildInstr(SPIRV::OpString);
+    Register StrReg = MRI.createVirtualRegister(&SPIRV::IDRegClass);
+    MachineOperand StrRegOp = MachineOperand::CreateReg(StrReg, true);
+    MIB.add(StrRegOp);
+    addStringImm(FilePath, MIB);
+
+    const MachineInstr *VoidTyMI =
+        GR->getOrCreateSPIRVType(Type::getVoidTy(M->getContext()), MIRBuilder);
+
+    MIB = MIRBuilder.buildInstr(SPIRV::OpExtInst);
+    Register DebugSourceResIdReg =
+        MRI.createVirtualRegister(&SPIRV::IDRegClass);
+    MIB.addDef(DebugSourceResIdReg);              // Result ID
+    MIB.addUse(VoidTyMI->getOperand(0).getReg()); // Result Type
+    MIB.addImm(static_cast<int64_t>(
+        SPIRV::InstructionSet::NonSemantic_Shader_DebugInfo_100)); // Set ID
+    MIB.addImm(SPIRV::NonSemanticExtInst::DebugSource);            //
+    MIB.addUse(StrReg);
+    MIB.constrainAllUses(*TII, *TRI, *RBI);
+
+    Register DwarfVersionReg = GR->buildConstantInt(DwarfVersion, MIRBuilder);
+    Register DebugInfoVersionReg =
+        GR->buildConstantInt(DebugInfoVersion, MIRBuilder);
+    Register SourceLanguageReg =
+        GR->buildConstantInt(SourceLanguage, MIRBuilder);
+
+    MIB = MIRBuilder.buildInstr(SPIRV::OpExtInst);
+    Register DebugCompUnitResIdReg =
+        MRI.createVirtualRegister(&SPIRV::IDRegClass);
+    MIB.addDef(DebugCompUnitResIdReg);            // Result ID
+    MIB.addUse(VoidTyMI->getOperand(0).getReg()); // Result Type
+    MIB.addImm(static_cast<int64_t>(
+        SPIRV::InstructionSet::NonSemantic_Shader_DebugInfo_100)); // Set ID
+    MIB.addImm(SPIRV::NonSemanticExtInst::DebugCompilationUnit);
+    MIB.addUse(DebugInfoVersionReg);
+    MIB.addUse(DwarfVersionReg);
+    MIB.addUse(DebugSourceResIdReg);
+    MIB.addUse(SourceLanguageReg);
+    MIB.constrainAllUses(*TII, *TRI, *RBI);
+  }
+
+  return true;
+}
+
+bool SPIRVEmitNonSemanticDI::runOnMachineFunction(MachineFunction &MF) {
+  bool Res = false;
+  if (!IsGlobalDIEmitted) {
+    Res = emitGlobalDI(MF);
+    IsGlobalDIEmitted = true;
+  }
+  return Res;
+}
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index ac0aa682ea4be..c69a82db14bb8 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -21,7 +21,6 @@
 #include "SPIRVSubtarget.h"
 #include "SPIRVTargetMachine.h"
 #include "SPIRVUtils.h"
-#include "TargetInfo/SPIRVTargetInfo.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
@@ -427,7 +426,21 @@ void SPIRVModuleAnalysis::processOtherInstrs(const Module &M) {
         if (MAI.getSkipEmission(&MI))
           continue;
         const unsigned OpCode = MI.getOpcode();
-        if (OpCode == SPIRV::OpName || OpCode == SPIRV::OpMemberName) {
+        if (OpCode == SPIRV::OpString) {
+          collectOtherInstr(MI, MAI, SPIRV::MB_DebugStrings, IS);
+        } else if (OpCode == SPIRV::OpExtInst) {
+          MachineOperand Ins = MI.getOperand(3);
+          namespace NS = SPIRV::NonSemanticExtInst;
+          static constexpr int64_t GlobalNonSemanticDITy[] = {
+              NS::DebugSource, NS::DebugCompilationUnit};
+          bool IsGlobalDI = false;
+          for (unsigned Idx = 0; Idx < std::size(GlobalNonSemanticDITy); ++Idx) {
+            IsGlobalDI |= Ins.getImm() == GlobalNonSemanticDITy[Idx];
+          }
+          if (IsGlobalDI) {
+            collectOtherInstr(MI, MAI, SPIRV::MB_NonSemanticGlobalDI, IS);
+          }
+        } else if (OpCode == SPIRV::OpName || OpCode == SPIRV::OpMemberName) {
           collectOtherInstr(MI, MAI, SPIRV::MB_DebugNames, IS);
         } else if (OpCode == SPIRV::OpEntryPoint) {
           collectOtherInstr(MI, MAI, SPIRV::MB_EntryPoints, IS);
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
index 79226d6d93efb..024728c347e8a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
@@ -20,7 +20,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringMap.h"
 
 namespace llvm {
 class SPIRVSubtarget;
@@ -34,9 +33,11 @@ enum ModuleSectionType {
   MB_EntryPoints, // All OpEntryPoint instructions (if any).
   //  MB_ExecutionModes, MB_DebugSourceAndStrings,
   MB_DebugNames,           // All OpName and OpMemberName intrs.
+  MB_DebugStrings,         // All OpString intrs.
   MB_DebugModuleProcessed, // All OpModuleProcessed instructions.
   MB_Annotations,          // OpDecorate, OpMemberDecorate etc.
   MB_TypeConstVars,        // OpTypeXXX, OpConstantXXX, and global OpVariables.
+  MB_NonSemanticGlobalDI,  // OpExtInst with e.g. DebugSource, DebugTypeBasic.
   MB_ExtFuncDecls,         // OpFunction etc. to declare for external funcs.
   NUM_MODULE_SECTIONS      // Total number of sections requiring basic blocks.
 };
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
index 52fc6f33b4ef1..bffc079981bc1 100644
--- a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
@@ -199,6 +199,7 @@ void SPIRVPassConfig::addPreLegalizeMachineIR() {
 bool SPIRVPassConfig::addLegalizeMachineIR() {
   addPass(new Legalizer());
   addPass(createSPIRVPostLegalizerPass());
+  addPass(createSPIRVEmitNonSemanticDIPass(&getTM<SPIRVTargetMachine>()));
   return false;
 }
 

Copy link

github-actions bot commented Jul 3, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@bwlodarcz bwlodarcz force-pushed the spirv_non_semantic_di branch from c263d71 to 12854b3 Compare July 3, 2024 11:39
@michalpaszkowski
Copy link
Member

@bwlodarcz Would it be possible to add a couple LIT tests demonstrating the currently expected behavior? You could create a new directory for the DebugInfo tests.

Also, if you think it would be beneficial for the development of this pass and to definitely make debugging easier, you could follow the tests for the SPIRVEmitIntrinsics and create some LITs which would verify just the output of this pass using -print-after-all and CHECK line with the pass name,

@VyacheslavLevytskyy
Copy link
Contributor

I also regard a comprehensive test suite as a very important part of this and following PRs, and probably we have one possible initial approach that is both easier to start with and has the benefit of preserving stability (and in ideal case certain compatibility with Khronos Translator). I mean DebugInfo section of Khronos Translator's test suite: https://github.com/KhronosGroup/SPIRV-LLVM-Translator/tree/main/test/DebugInfo

@bwlodarcz Would it be possible to take some tests from that test suite on this early stage of development of the extension? Do you see LIT tests cases from the Khronos Translator's test suite relevant to this initial PR?

@VyacheslavLevytskyy VyacheslavLevytskyy self-requested a review July 4, 2024 08:56
Copy link
Contributor

@VyacheslavLevytskyy VyacheslavLevytskyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bwlodarcz Thank you for this PR that introduces the "SPIR-V NonSemantic Shader DebugInfo Instructions" extension.

@bwlodarcz bwlodarcz force-pushed the spirv_non_semantic_di branch from ea8b9cb to f162159 Compare July 5, 2024 12:42
@bwlodarcz
Copy link
Contributor Author

bwlodarcz commented Jul 8, 2024

@michalpaszkowski @VyacheslavLevytskyy Lit test is added. The SPIRVEmitNonSemanticDI is the last machine pass before SPIRVModuleAnalysis (there are no other passes after) and it's not self contained. It's dependent from what's SPIRVModuleAnalysis is doing during during it's analytics pass. I think that to assess it's correctness is necessary to check if after SPIRVAsmPrinter instruction emission.

@VyacheslavLevytskyy A lot of tests inside the Khronos Translator is using SPT (internal, textual, used only for tests) format and/or are mostly covering OpenCL.DebugInfo.100 standard which we aren't. Some mixing NonSemantic.DI and OpenCL.DI in the same test file (by separate RUN). Finding which tests are useful for us, translating them, is maybe worth an effort but the risk (of time investment) to reward (finding useful tests) ratio have, in my opinion, question mark when we compare it to just creating new set of tests. In addition to that - especially at the beginning of development there is a lot of cases which aren't covered and with broken tests (inevitable if we port them) - PR's won't be merged - so we would need to disable a lot of them. At some point it's likely that the risk-reward ratio will change. Nevertheless if someone want's to do it, go through them and add to the Backend useful ones - I'm fully supporting it as a optional side quest for everyone who want to participate in DebugInfo development.

@bwlodarcz bwlodarcz force-pushed the spirv_non_semantic_di branch from a6cafc5 to 3443716 Compare August 22, 2024 11:20
@michalpaszkowski michalpaszkowski merged commit 62da359 into llvm:main Aug 23, 2024
8 of 10 checks passed
@michalpaszkowski
Copy link
Member

Thank you @bwlodarcz for working on this! The change is now merged.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 23, 2024

LLVM Buildbot has detected a new failure on builder sanitizer-aarch64-linux-fuzzer running on sanitizer-buildbot11 while building llvm at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/159/builds/4482

Here is the relevant piece of the build log for the reference:

Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
-- Configuring done (9.4s)
-- Generating done (0.1s)
CMake Warning:
  Manually-specified variables were not used by the project:

    LIBCXX_HAS_GCC_S_LIB


-- Build files have been written to: /home/b/sanitizer-aarch64-linux-fuzzer/build/llvm_build0/runtimes/runtimes-bins/compiler-rt/lib/fuzzer/libcxx_fuzzer_aarch64
[1882/1986] Building CXX object compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o
FAILED: compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o 
/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm_build0/./bin/clang++ --target=aarch64-unknown-linux-gnu -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/compiler-rt/lib/ubsan_minimal/.. -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -O3 -DNDEBUG -std=c++17 -march=armv8-a -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -ftrivial-auto-var-init=pattern -nostdinc++ -DSANITIZER_COMMON_NO_REDEFINE_BUILTINS -fno-rtti -MD -MT compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o -MF compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o.d -o compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o -c /home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
fatal error: error in backend: Cannot select: 0xabd198ca4380: v16i8 = insert_subvector 0xabd198ca4000, 0xabd198af3a20, Constant:i64<10>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
  0xabd198ca4000: v16i8 = insert_subvector 0xabd198af4350, 0xabd198852f50, Constant:i64<12>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
    0xabd198af4350: v16i8 = insert_vector_elt 0xabd198853030, 0xabd198af36a0, Constant:i64<9>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
      0xabd198853030: v16i8 = insert_vector_elt 0xabd198a62d40, 0xabd198a62b80, Constant:i64<8>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
        0xabd198a62d40: v16i8 = insert_vector_elt 0xabd198cae640, 0xabd198cae3a0, Constant:i64<7>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
          0xabd198cae640: v16i8 = insert_vector_elt 0xabd198ca9050, 0xabd198cae330, Constant:i64<6>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
            0xabd198ca9050: v16i8 = insert_vector_elt 0xabd198853d50, 0xabd198cae2c0, Constant:i64<5>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
              0xabd198853d50: v16i8 = insert_vector_elt 0xabd198ca4850, 0xabd198ca7180, Constant:i64<4>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
                0xabd198ca4850: v16i8 = insert_vector_elt 0xabd198cae870, 0xabd198ca9980, Constant:i64<3>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
                  0xabd198cae870: v16i8 = insert_vector_elt 0xabd198cae800, 0xabd198ca7420, Constant:i64<2>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16



                  0xabd198ca9980: i32 = extract_vector_elt 0xabd198cae090, Constant:i64<1>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16


                  0xabd198af3be0: i64 = Constant<3>
                0xabd198ca7180: i32 = extract_vector_elt 0xabd198cae100, Constant:i64<0>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
                  0xabd198cae100: v8i16 = insert_subvector undef:v8i16, 0xabd198ca7030, Constant:i64<0>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23



                  0xabd198a62cd0: i64 = Constant<0>
                0xabd198a63210: i64 = Constant<4>
              0xabd198cae2c0: i32 = extract_vector_elt 0xabd198cae100, Constant:i64<1>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
                0xabd198cae100: v8i16 = insert_subvector undef:v8i16, 0xabd198ca7030, Constant:i64<0>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23
                  0xabd198cae5d0: v8i16 = undef
                  0xabd198ca7030: v4i16 = and 0xabd198ca7340, 0xabd198853c00, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23


                  0xabd198a62cd0: i64 = Constant<0>
                0xabd198853960: i64 = Constant<1>
              0xabd198853260: i64 = Constant<5>
            0xabd198cae330: i32 = extract_vector_elt 0xabd198cae100, Constant:i64<2>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
              0xabd198cae100: v8i16 = insert_subvector undef:v8i16, 0xabd198ca7030, Constant:i64<0>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23
                0xabd198cae5d0: v8i16 = undef
                0xabd198ca7030: v4i16 = and 0xabd198ca7340, 0xabd198853c00, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23
Step 7 (stage1 build all) failure: stage1 build all (failure)
...
-- Performing Test CXX_SUPPORTS_FSIZED_DEALLOCATION_FLAG - Success
-- check-runtimes does nothing.
-- Configuring done (9.4s)
-- Generating done (0.1s)
CMake Warning:
  Manually-specified variables were not used by the project:

    LIBCXX_HAS_GCC_S_LIB
-- Build files have been written to: /home/b/sanitizer-aarch64-linux-fuzzer/build/llvm_build0/runtimes/runtimes-bins/compiler-rt/lib/fuzzer/libcxx_fuzzer_aarch64
[1882/1986] Building CXX object compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o
FAILED: compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o 
/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm_build0/./bin/clang++ --target=aarch64-unknown-linux-gnu -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/compiler-rt/lib/ubsan_minimal/.. -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -O3 -DNDEBUG -std=c++17 -march=armv8-a -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -ftrivial-auto-var-init=pattern -nostdinc++ -DSANITIZER_COMMON_NO_REDEFINE_BUILTINS -fno-rtti -MD -MT compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o -MF compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o.d -o compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.aarch64.dir/ubsan_minimal_handlers.cpp.o -c /home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
fatal error: error in backend: Cannot select: 0xabd198ca4380: v16i8 = insert_subvector 0xabd198ca4000, 0xabd198af3a20, Constant:i64<10>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
  0xabd198ca4000: v16i8 = insert_subvector 0xabd198af4350, 0xabd198852f50, Constant:i64<12>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
    0xabd198af4350: v16i8 = insert_vector_elt 0xabd198853030, 0xabd198af36a0, Constant:i64<9>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
      0xabd198853030: v16i8 = insert_vector_elt 0xabd198a62d40, 0xabd198a62b80, Constant:i64<8>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
        0xabd198a62d40: v16i8 = insert_vector_elt 0xabd198cae640, 0xabd198cae3a0, Constant:i64<7>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
          0xabd198cae640: v16i8 = insert_vector_elt 0xabd198ca9050, 0xabd198cae330, Constant:i64<6>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
            0xabd198ca9050: v16i8 = insert_vector_elt 0xabd198853d50, 0xabd198cae2c0, Constant:i64<5>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
              0xabd198853d50: v16i8 = insert_vector_elt 0xabd198ca4850, 0xabd198ca7180, Constant:i64<4>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
                0xabd198ca4850: v16i8 = insert_vector_elt 0xabd198cae870, 0xabd198ca9980, Constant:i64<3>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
                  0xabd198cae870: v16i8 = insert_vector_elt 0xabd198cae800, 0xabd198ca7420, Constant:i64<2>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16



                  0xabd198ca9980: i32 = extract_vector_elt 0xabd198cae090, Constant:i64<1>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16


                  0xabd198af3be0: i64 = Constant<3>
                0xabd198ca7180: i32 = extract_vector_elt 0xabd198cae100, Constant:i64<0>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
                  0xabd198cae100: v8i16 = insert_subvector undef:v8i16, 0xabd198ca7030, Constant:i64<0>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23



                  0xabd198a62cd0: i64 = Constant<0>
                0xabd198a63210: i64 = Constant<4>
              0xabd198cae2c0: i32 = extract_vector_elt 0xabd198cae100, Constant:i64<1>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
                0xabd198cae100: v8i16 = insert_subvector undef:v8i16, 0xabd198ca7030, Constant:i64<0>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23
                  0xabd198cae5d0: v8i16 = undef
                  0xabd198ca7030: v4i16 = and 0xabd198ca7340, 0xabd198853c00, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23


                  0xabd198a62cd0: i64 = Constant<0>
                0xabd198853960: i64 = Constant<1>
              0xabd198853260: i64 = Constant<5>
            0xabd198cae330: i32 = extract_vector_elt 0xabd198cae100, Constant:i64<2>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:60:16
              0xabd198cae100: v8i16 = insert_subvector undef:v8i16, 0xabd198ca7030, Constant:i64<0>, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23
                0xabd198cae5d0: v8i16 = undef
                0xabd198ca7030: v4i16 = and 0xabd198ca7340, 0xabd198853c00, llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:59:23

cjdb pushed a commit to cjdb/llvm-project that referenced this pull request Aug 23, 2024
This commit introduces emission of DebugSource, DebugCompileUnit from
NonSemantic.Shader.DebugInfo.100 and required OpString with filename.
NonSemantic.Shader.DebugInfo.100 is divided, following DWARF into two
main concepts – emitting DIE and Line.
In DWARF .debug_abbriev and .debug_info sections are responsible for
emitting tree with information (DEIs) about e.g. types, compilation
unit. Corresponding to that in NonSemantic.Shader.DebugInfo.100 have
instructions like DebugSource, DebugCompileUnit etc. which preforms same
role in SPIR-V file. The difference is in fact that in SPIR-V there are
no sections but logical layout which forces order of the instruction
emission.
The NonSemantic.Shader.DebugInfo.100 requires for this type of global
information to be emitted after OpTypeXXX and OpConstantXXX
instructions.
One of the goals was to minimize changes and interaction with
SPIRVModuleAnalysis as possible which current commit achieves by
emitting it’s instructions directly into MachineFunction.
The possibility of duplicates are mitigated by guard inside pass which
emits the global information only once in one function.
By that method duplicates don’t have chance to be emitted.
From that point, adding new debug global instructions should be
straightforward.
bogner added a commit that referenced this pull request Aug 23, 2024
…#105889)

The declaration in SPIRV.h had this returning a `MachineFunctionPass *`,
but the implementation returned a `FunctionPass *`. This showed up as a
build error on windows, but it was clearly a mistake regardless.

I also updated the pass to include SPIRV.h rather than using its own
declarations for pass initialization, as this results in better errors
for this kind of typo.

Fixes a build break after #97558
5chmidti pushed a commit that referenced this pull request Aug 24, 2024
…#105889)

The declaration in SPIRV.h had this returning a `MachineFunctionPass *`,
but the implementation returned a `FunctionPass *`. This showed up as a
build error on windows, but it was clearly a mistake regardless.

I also updated the pass to include SPIRV.h rather than using its own
declarations for pass initialization, as this results in better errors
for this kind of typo.

Fixes a build break after #97558
bogner added a commit that referenced this pull request Aug 26, 2024
…#105965)

I don't know if this is the right thing to do or if the emitter should
be normalizing path separators, but this gets this test to pass on
windows where `sys::path::append` will use "\" instead of "/".

This is another follow up to #97558, as #105889 managed to fix the
build, but not all of the tests.
5c4lar pushed a commit to 5c4lar/llvm-project that referenced this pull request Aug 29, 2024
…llvm#105965)

I don't know if this is the right thing to do or if the emitter should
be normalizing path separators, but this gets this test to pass on
windows where `sys::path::append` will use "\" instead of "/".

This is another follow up to llvm#97558, as llvm#105889 managed to fix the
build, but not all of the tests.
dmpolukhin pushed a commit to dmpolukhin/llvm-project that referenced this pull request Sep 2, 2024
This commit introduces emission of DebugSource, DebugCompileUnit from
NonSemantic.Shader.DebugInfo.100 and required OpString with filename.
NonSemantic.Shader.DebugInfo.100 is divided, following DWARF into two
main concepts – emitting DIE and Line.
In DWARF .debug_abbriev and .debug_info sections are responsible for
emitting tree with information (DEIs) about e.g. types, compilation
unit. Corresponding to that in NonSemantic.Shader.DebugInfo.100 have
instructions like DebugSource, DebugCompileUnit etc. which preforms same
role in SPIR-V file. The difference is in fact that in SPIR-V there are
no sections but logical layout which forces order of the instruction
emission.
The NonSemantic.Shader.DebugInfo.100 requires for this type of global
information to be emitted after OpTypeXXX and OpConstantXXX
instructions.
One of the goals was to minimize changes and interaction with
SPIRVModuleAnalysis as possible which current commit achieves by
emitting it’s instructions directly into MachineFunction.
The possibility of duplicates are mitigated by guard inside pass which
emits the global information only once in one function.
By that method duplicates don’t have chance to be emitted.
From that point, adding new debug global instructions should be
straightforward.
dmpolukhin pushed a commit to dmpolukhin/llvm-project that referenced this pull request Sep 2, 2024
…llvm#105889)

The declaration in SPIRV.h had this returning a `MachineFunctionPass *`,
but the implementation returned a `FunctionPass *`. This showed up as a
build error on windows, but it was clearly a mistake regardless.

I also updated the pass to include SPIRV.h rather than using its own
declarations for pass initialization, as this results in better errors
for this kind of typo.

Fixes a build break after llvm#97558
dmpolukhin pushed a commit to dmpolukhin/llvm-project that referenced this pull request Sep 2, 2024
…llvm#105965)

I don't know if this is the right thing to do or if the emitter should
be normalizing path separators, but this gets this test to pass on
windows where `sys::path::append` will use "\" instead of "/".

This is another follow up to llvm#97558, as llvm#105889 managed to fix the
build, but not all of the tests.
VyacheslavLevytskyy added a commit that referenced this pull request Sep 3, 2024
…Shader_DebugInfo_100 are not mixed up with other OpExtInst instructions (#107007)

This PR is to ensure that OpExtInst instructions generated by
NonSemantic_Shader_DebugInfo_100 are not mixed up with other OpExtInst
instructions.

Original implementation
(#97558) has introduced an
issue by moving OpExtInst instruction with the 3rd operand equal to
DebugSource (value 35) or DebugCompilationUnit (value 1) even if
OpExtInst is not generated by NonSemantic_Shader_DebugInfo_100
implementation code.

The reproducer is attached as a new test case. The code of the test case
reproduces the issue, because "lgamma" has the same code (35) inside
OpenCL_std as DebugSource inside NonSemantic_Shader_DebugInfo_100.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants