[SPIRV] Add Lifetime intrinsics/instructions (#85391)
This PR:
* adds Lifetime intrinsics/instructions
* fixes how the binary header is emitted (correct version and better
approximation of Bound)
* add validation into more test cases
diff --git a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
index 1fbf3c3..30c67d3 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
@@ -29,7 +29,9 @@
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/TargetRegistry.h"
@@ -101,6 +103,21 @@
if (ModuleSectionsEmitted == false) {
outputModuleSections();
ModuleSectionsEmitted = true;
+ } else {
+ ST = static_cast<const SPIRVTargetMachine &>(TM).getSubtargetImpl();
+ uint32_t DecSPIRVVersion = ST->getSPIRVVersion();
+ uint32_t Major = DecSPIRVVersion / 10;
+ uint32_t Minor = DecSPIRVVersion - Major * 10;
+ // TODO: calculate Bound more carefully from maximum used register number,
+ // accounting for generated OpLabels and other related instructions if
+ // needed.
+ unsigned Bound = 2 * (ST->getBound() + 1);
+ bool FlagToRestore = OutStreamer->getUseAssemblerInfoForParsing();
+ OutStreamer->setUseAssemblerInfoForParsing(true);
+ if (MCAssembler *Asm = OutStreamer->getAssemblerPtr())
+ Asm->setBuildVersion(static_cast<MachO::PlatformType>(0), Major, Minor,
+ Bound, VersionTuple(Major, Minor, 0, Bound));
+ OutStreamer->setUseAssemblerInfoForParsing(FlagToRestore);
}
}
@@ -507,6 +524,13 @@
report_fatal_error("Unsupported value in llvm.global.annotations");
Function *Func = cast<Function>(AnnotatedVar);
Register Reg = MAI->getFuncReg(Func);
+ if (!Reg.isValid()) {
+ std::string DiagMsg;
+ raw_string_ostream OS(DiagMsg);
+ AnnotatedVar->print(OS);
+ DiagMsg = "Unknown function in llvm.global.annotations: " + DiagMsg;
+ report_fatal_error(DiagMsg.c_str());
+ }
// The second field contains a pointer to a global annotation string.
GlobalVariable *GV =