@@ -329,20 +329,22 @@ class BinaryWrapper {
329329 // / Represents a single image to wrap.
330330 class Image {
331331 public:
332- Image (const llvm::StringRef File_,
333332#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
334- const llvm::StringRef Manif_,
335- #endif // __INTEL_PREVIEW_BREAKING_CHANGES
333+ Image (const llvm::StringRef File_, const llvm::StringRef Manif_,
336334 const llvm::StringRef Tgt_, BinaryImageFormat Fmt_,
337335 const llvm::StringRef CompileOpts_, const llvm::StringRef LinkOpts_,
338336 const llvm::StringRef EntriesFile_, const llvm::StringRef PropsFile_)
339- : File(File_.str()),
340- # ifndef __INTEL_PREVIEW_BREAKING_CHANGES
341- Manif (Manif_ .str()),
337+ : File(File_.str()), Manif(Manif_.str()), Tgt(Tgt_.str()), Fmt(Fmt_),
338+ CompileOpts(CompileOpts_.str()), LinkOpts(LinkOpts_.str()),
339+ EntriesFile(EntriesFile_ .str()), PropsFile(PropsFile_.str()) {}
342340#endif // __INTEL_PREVIEW_BREAKING_CHANGES
343- Tgt (Tgt_.str()), Fmt(Fmt_), CompileOpts(CompileOpts_.str()),
344- LinkOpts(LinkOpts_.str()), EntriesFile(EntriesFile_.str()),
345- PropsFile(PropsFile_.str()) {}
341+ Image (const llvm::StringRef File_, const llvm::StringRef Tgt_,
342+ BinaryImageFormat Fmt_, const llvm::StringRef CompileOpts_,
343+ const llvm::StringRef LinkOpts_, const llvm::StringRef EntriesFile_,
344+ const llvm::StringRef PropsFile_)
345+ : File(File_.str()), Tgt(Tgt_.str()), Fmt(Fmt_),
346+ CompileOpts (CompileOpts_.str()), LinkOpts(LinkOpts_.str()),
347+ EntriesFile(EntriesFile_.str()), PropsFile(PropsFile_.str()) {}
346348
347349 // / Name of the file with actual contents
348350 const std::string File;
@@ -391,23 +393,28 @@ class BinaryWrapper {
391393 llvm::SmallVector<std::unique_ptr<MemoryBuffer>, 4 > AutoGcBufs;
392394
393395public:
394- void addImage (const OffloadKind Kind, llvm::StringRef File,
395396#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
396- llvm::StringRef Manif,
397- #endif // __INTEL_PREVIEW_BREAKING_CHANGES
398- llvm::StringRef Tgt,
397+ void addImage (const OffloadKind Kind, llvm::StringRef File,
398+ llvm::StringRef Manif, llvm::StringRef Tgt,
399399 const BinaryImageFormat Fmt, llvm::StringRef CompileOpts,
400400 llvm::StringRef LinkOpts, llvm::StringRef EntriesFile,
401401 llvm::StringRef PropsFile) {
402402 std::unique_ptr<SameKindPack> &Pack = Packs[Kind];
403403 if (!Pack)
404404 Pack.reset (new SameKindPack ());
405405 Pack->emplace_back (std::make_unique<Image>(
406- File,
407- #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
408- Manif,
406+ File, Manif, Tgt, Fmt, CompileOpts, LinkOpts, EntriesFile, PropsFile));
407+ }
409408#endif // __INTEL_PREVIEW_BREAKING_CHANGES
410- Tgt, Fmt, CompileOpts, LinkOpts, EntriesFile, PropsFile));
409+ void addImage (const OffloadKind Kind, llvm::StringRef File,
410+ llvm::StringRef Tgt, const BinaryImageFormat Fmt,
411+ llvm::StringRef CompileOpts, llvm::StringRef LinkOpts,
412+ llvm::StringRef EntriesFile, llvm::StringRef PropsFile) {
413+ std::unique_ptr<SameKindPack> &Pack = Packs[Kind];
414+ if (!Pack)
415+ Pack.reset (new SameKindPack ());
416+ Pack->emplace_back (std::make_unique<Image>(
417+ File, Tgt, Fmt, CompileOpts, LinkOpts, EntriesFile, PropsFile));
411418 }
412419
413420 std::string ToolName;
@@ -1086,9 +1093,14 @@ class BinaryWrapper {
10861093 if (Verbose)
10871094 errs () << " adding image: offload kind=" << offloadKindToString (Kind)
10881095 << Img << " \n " ;
1089- // STOPPED HERE
1096+
10901097 auto *Fver =
1091- ConstantInt::get (Type::getInt16Ty (C), DeviceImageStructVersion);
1098+ ConstantInt::get (Type::getInt16Ty (C),
1099+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
1100+ PreviewBreakingChanges ? 3 : DeviceImageStructVersion);
1101+ #else
1102+ DeviceImageStructVersion);
1103+ #endif // __INTEL_PREVIEW_BREAKING_CHANGES
10921104 auto *Fknd = ConstantInt::get (Type::getInt8Ty (C), Kind);
10931105 auto *Ffmt = ConstantInt::get (Type::getInt8Ty (C), Img.Fmt );
10941106 auto *Ftgt = addStringToModule (
@@ -1099,24 +1111,29 @@ class BinaryWrapper {
10991111 auto *Foptlink = addStringToModule (Img.LinkOpts , Twine (OffloadKindTag) +
11001112 Twine (" opts.link." ) +
11011113 Twine (ImgId));
1114+
1115+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
11021116 std::pair<Constant *, Constant *> FMnf;
11031117
1118+ if (!PreviewBreakingChanges) {
1119+ if (Img.Manif .empty ()) {
1120+ // no manifest - zero out the fields
1121+ FMnf = std::make_pair (NullPtr, NullPtr);
1122+ } else {
1123+ Expected<MemoryBuffer *> MnfOrErr = loadFile (Img.Manif );
1124+ if (!MnfOrErr)
1125+ return MnfOrErr.takeError ();
1126+ MemoryBuffer *Mnf = *MnfOrErr;
1127+ FMnf = addArrayToModule (
1128+ ArrayRef<char >(Mnf->getBufferStart (), Mnf->getBufferSize ()),
1129+ Twine (OffloadKindTag) + Twine (ImgId) + Twine (" .manifest" ));
1130+ }
1131+ }
1132+ #endif // __INTEL_PREVIEW_BREAKING_CHANGES
1133+
11041134 if (MySymPropReader)
11051135 MySymPropReader->getNextDeviceImageInitializer ();
11061136
1107- if (Img.Manif .empty ()) {
1108- // no manifest - zero out the fields
1109- FMnf = std::make_pair (NullPtr, NullPtr);
1110- } else {
1111- Expected<MemoryBuffer *> MnfOrErr = loadFile (Img.Manif );
1112- if (!MnfOrErr)
1113- return MnfOrErr.takeError ();
1114- MemoryBuffer *Mnf = *MnfOrErr;
1115- FMnf = addArrayToModule (
1116- ArrayRef<char >(Mnf->getBufferStart (), Mnf->getBufferSize ()),
1117- Twine (OffloadKindTag) + Twine (ImgId) + Twine (" .manifest" ));
1118- }
1119-
11201137 Expected<std::pair<Constant *, Constant *>> PropSets =
11211138 tformSYCLPropertySetRegistryFileToIR (Img.PropsFile );
11221139 if (!PropSets)
@@ -1215,11 +1232,19 @@ class BinaryWrapper {
12151232 if (!EntriesOrErr)
12161233 return EntriesOrErr.takeError ();
12171234 std::pair<Constant *, Constant *> ImageEntriesPtrs = *EntriesOrErr;
1218- ImagesInits.push_back (ConstantStruct::get (
1219- getSyclDeviceImageTy (), Fver, Fknd, Ffmt, Ftgt, Foptcompile,
1220- Foptlink, FMnf.first , FMnf.second , Fbin.first , Fbin.second ,
1221- ImageEntriesPtrs.first , ImageEntriesPtrs.second ,
1222- PropSets.get ().first , PropSets.get ().second ));
1235+ ImagesInits.push_back (
1236+ PreviewBreakingChanges
1237+ ? ConstantStruct::get (
1238+ getSyclDeviceImageTy (), Fver, Fknd, Ffmt, Ftgt,
1239+ Foptcompile, Foptlink, Fbin.first , Fbin.second ,
1240+ ImageEntriesPtrs.first , ImageEntriesPtrs.second ,
1241+ PropSets.get ().first , PropSets.get ().second )
1242+ : ConstantStruct::get (
1243+ getSyclDeviceImageTy (), Fver, Fknd, Ffmt, Ftgt,
1244+ Foptcompile, Foptlink, FMnf.first , FMnf.second ,
1245+ Fbin.first , Fbin.second , ImageEntriesPtrs.first ,
1246+ ImageEntriesPtrs.second , PropSets.get ().first ,
1247+ PropSets.get ().second ));
12231248 } else
12241249 ImagesInits.push_back (ConstantStruct::get (
12251250 getDeviceImageTy (), Fbin.first , Fbin.second , EntriesB, EntriesE));
@@ -1690,7 +1715,9 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
16901715 const BinaryWrapper::Image &Img) {
16911716 Out << " \n {\n " ;
16921717 Out << " file = " << Img.File << " \n " ;
1718+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
16931719 Out << " manifest = " << (Img.Manif .empty () ? " -" : Img.Manif ) << " \n " ;
1720+ #endif // __INTEL_PREVIEW_BREAKING_CHANGES
16941721 Out << " format = " << formatToString (Img.Fmt ) << " \n " ;
16951722 Out << " target = " << (Img.Tgt .empty () ? " -" : Img.Tgt ) << " \n " ;
16961723 Out << " compile options = "
@@ -1846,14 +1873,22 @@ int main(int argc, const char **argv) {
18461873 cl::ParseCommandLineOptions (
18471874 argc, argv,
18481875 " A tool to create a wrapper bitcode for offload target binaries.\n "
1876+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
18491877 " Takes offload target binaries and optional manifest files as input\n "
1878+ #else
1879+ " Takes offload target binaries as input\n "
1880+ #endif // __INTEL_PREVIEW_BREAKING_CHANGES
18501881 " and produces bitcode file containing target binaries packaged as data\n "
18511882 " and initialization code which registers target binaries in the offload\n "
1883+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
18521884 " runtime. Manifest files format and contents are not restricted and are\n "
18531885 " a subject of agreement between the device compiler and the native\n "
18541886 " runtime for that device. When present, manifest file name should\n "
18551887 " immediately follow the corresponding device image filename on the\n "
18561888 " command line. Options annotating a device binary have effect on all\n "
1889+ #else
1890+ " runtime. Options annotating a device binary have effect on all\n "
1891+ #endif // __INTEL_PREVIEW_BREAKING_CHANGES
18571892 " subsequent input, until redefined.\n "
18581893 " \n "
18591894 " For example:\n "
@@ -1867,27 +1902,40 @@ int main(int argc, const char **argv) {
18671902 " -entries=sym.txt \\\n "
18681903 " -properties=props.txt \\\n "
18691904 " a.spv \\\n "
1905+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
18701906 " a_mf.txt \\\n "
1907+ #endif // __INTEL_PREVIEW_BREAKING_CHANGES
18711908 " -target=xxx \\\n "
18721909 " -format=native \\\n "
18731910 " -compile-opts=\"\" \\\n "
18741911 " -link-opts=\"\" \\\n "
18751912 " -entries=\"\" \\\n "
18761913 " -properties=\"\" \\\n "
18771914 " b.bin \\\n "
1915+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
18781916 " b_mf.txt \\\n "
1917+ #endif // __INTEL_PREVIEW_BREAKING_CHANGES
18791918 " -kind=openmp \\\n "
18801919 " c.bin\\ n"
18811920 " \n "
18821921 " This command generates an x86 wrapper object (.bc) enclosing the\n "
18831922 " following tuples describing a single device binary each:\n "
18841923 " \n "
1924+ #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
18851925 " |offload|target|data |data |manifest|compile|entries|properties|...|\n "
18861926 " | kind | |format| | |options| | |...|\n "
18871927 " |-------|------|------|-----|--------|-------|-------|----------|---|\n "
18881928 " |sycl |spir64|spirv |a.spv|a_mf.txt| -g |sym.txt|props.txt |...|\n "
18891929 " |sycl |xxx |native|b.bin|b_mf.txt| | | |...|\n "
18901930 " |openmp |xxx |native|c.bin| | | | |...|\n "
1931+ #else
1932+ " |offload|target|data |data |compile|entries|properties|...|\n "
1933+ " | kind | |format| |options| | |...|\n "
1934+ " |-------|------|------|-----|-------|-------|----------|---|\n "
1935+ " |sycl |spir64|spirv |a.spv| -g |sym.txt|props.txt |...|\n "
1936+ " |sycl |xxx |native|b.bin| | | |...|\n "
1937+ " |openmp |xxx |native|c.bin| | | |...|\n "
1938+ #endif // __INTEL_PREVIEW_BREAKING_CHANGES
18911939 " \n "
18921940 " |...| link |\n "
18931941 " |...| options |\n "
@@ -1954,13 +2002,19 @@ int main(int argc, const char **argv) {
19542002 // ID != 0 signal that a new image(s) must be added
19552003 if (ID != 0 ) {
19562004 // create an image instance using current state
1957- if (CurInputGroup.size () > 2 ) {
2005+ if (!PreviewBreakingChanges && CurInputGroup.size () > 2 ) {
19582006 reportError (
19592007 createStringError (errc::invalid_argument,
19602008 " too many inputs for a single binary image, "
19612009 " <binary file> <manifest file>{opt}expected" ));
19622010 return 1 ;
19632011 }
2012+ if (PreviewBreakingChanges && CurInputGroup.size () > 1 ) {
2013+ reportError (createStringError (
2014+ errc::invalid_argument,
2015+ " too many inputs for a single binary image, <binary file> expected" ));
2016+ return 1 ;
2017+ }
19642018 if (CurInputGroup.size () != 0 ) {
19652019 if (BatchMode) {
19662020 // transform the batch job (a table of filenames) into a series of
@@ -1977,10 +2031,16 @@ int main(int argc, const char **argv) {
19772031
19782032 // iterate via records
19792033 for (const auto &Row : T.rows ()) {
1980- Wr.addImage (Knd, Row.getCell (COL_CODE),
1981- Row.getCell (COL_MANIFEST, " " ), Tgt, Fmt, CompileOpts,
1982- LinkOpts, Row.getCell (COL_SYM, " " ),
1983- Row.getCell (COL_PROPS, " " ));
2034+ if (!PreviewBreakingChanges)
2035+ Wr.addImage (Knd, Row.getCell (COL_CODE),
2036+ Row.getCell (COL_MANIFEST, " " ), Tgt, Fmt, CompileOpts,
2037+ LinkOpts, Row.getCell (COL_SYM, " " ),
2038+ Row.getCell (COL_PROPS, " " ));
2039+ else
2040+ Wr.addImage (Knd, Row.getCell (COL_CODE),
2041+ Tgt, Fmt, CompileOpts,
2042+ LinkOpts, Row.getCell (COL_SYM, " " ),
2043+ Row.getCell (COL_PROPS, " " ));
19842044 }
19852045 } else {
19862046 if (Knd == OffloadKind::Unknown) {
@@ -1989,9 +2049,14 @@ int main(int argc, const char **argv) {
19892049 return 1 ;
19902050 }
19912051 StringRef File = CurInputGroup[0 ];
1992- StringRef Manif = CurInputGroup.size () > 1 ? CurInputGroup[1 ] : " " ;
1993- Wr.addImage (Knd, File, Manif, Tgt, Fmt, CompileOpts, LinkOpts,
1994- EntriesFile, PropsFile);
2052+ if (!PreviewBreakingChanges) {
2053+ StringRef Manif = CurInputGroup.size () > 1 ? CurInputGroup[1 ] : " " ;
2054+ Wr.addImage (Knd, File, Manif, Tgt, Fmt, CompileOpts, LinkOpts,
2055+ EntriesFile, PropsFile);
2056+ } else {
2057+ Wr.addImage (Knd, File, Tgt, Fmt, CompileOpts, LinkOpts,
2058+ EntriesFile, PropsFile);
2059+ }
19952060 }
19962061 CurInputGroup.clear ();
19972062 }
0 commit comments