13
13
// - specialization constant intrinsic transformation
14
14
// ===----------------------------------------------------------------------===//
15
15
16
+ #include " SPIRKernelParamOptInfo.h"
16
17
#include " SpecConstants.h"
18
+
17
19
#include " llvm/ADT/SetVector.h"
18
20
#include " llvm/ADT/Triple.h"
19
21
#include " llvm/Bitcode/BitcodeWriterPass.h"
34
36
#include " llvm/Transforms/IPO.h"
35
37
#include " llvm/Transforms/IPO/GlobalDCE.h"
36
38
#include " llvm/Transforms/Utils/Cloning.h"
39
+
37
40
#include < memory>
38
41
39
42
using namespace llvm ;
@@ -117,11 +120,16 @@ static cl::opt<SpecConstMode> SpecConstLower{
117
120
" set spec constants to C++ defaults" )),
118
121
cl::cat (PostLinkCat)};
119
122
123
+ static cl::opt<bool > EmitKernelParamInfo{
124
+ " emit-param-info" , cl::desc (" emit kernel parameter optimization info" ),
125
+ cl::cat (PostLinkCat)};
126
+
120
127
struct ImagePropSaveInfo {
121
128
bool NeedDeviceLibReqMask;
122
129
bool DoSpecConst;
123
130
bool SetSpecConstAtRT;
124
131
bool SpecConstsMet;
132
+ bool EmitKernelParamInfo;
125
133
};
126
134
// Please update DeviceLibFuncMap if any item is added to or removed from
127
135
// fallback device libraries in libdevice.
@@ -508,6 +516,30 @@ static string_vector saveDeviceImageProperty(
508
516
llvm::util::PropertySetRegistry::SYCL_SPECIALIZATION_CONSTANTS,
509
517
TmpSpecIDMap);
510
518
}
519
+ if (ImgPSInfo.EmitKernelParamInfo ) {
520
+ // extract kernel parameter optimization info per module
521
+ ModuleAnalysisManager MAM;
522
+ // Register required analysis
523
+ MAM.registerPass ([&] { return PassInstrumentationAnalysis (); });
524
+ // Register the payload analysis
525
+ MAM.registerPass ([&] { return SPIRKernelParamOptInfoAnalysis (); });
526
+ SPIRKernelParamOptInfo PInfo =
527
+ MAM.getResult <SPIRKernelParamOptInfoAnalysis>(*ResultModules[I]);
528
+
529
+ // convert analysis results into properties and record them
530
+ llvm::util::PropertySet &Props =
531
+ PropSet[llvm::util::PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO];
532
+
533
+ for (const auto &NameInfoPair : PInfo) {
534
+ const llvm::BitVector &Bits = NameInfoPair.second ;
535
+ const llvm::ArrayRef<uintptr_t > Arr = NameInfoPair.second .getData ();
536
+ const unsigned char *Data =
537
+ reinterpret_cast <const unsigned char *>(Arr.begin ());
538
+ llvm::util::PropertyValue::SizeTy DataBitSize = Bits.size ();
539
+ Props.insert (std::make_pair (
540
+ NameInfoPair.first , llvm::util::PropertyValue (Data, DataBitSize)));
541
+ }
542
+ }
511
543
std::error_code EC;
512
544
std::string SCFile = makeResultFileName (" .prop" , I);
513
545
raw_fd_ostream SCOut (SCFile, EC);
@@ -580,8 +612,9 @@ int main(int argc, char **argv) {
580
612
581
613
bool DoSplit = SplitMode.getNumOccurrences () > 0 ;
582
614
bool DoSpecConst = SpecConstLower.getNumOccurrences () > 0 ;
615
+ bool DoParamInfo = EmitKernelParamInfo.getNumOccurrences () > 0 ;
583
616
584
- if (!DoSplit && !DoSpecConst && !DoSymGen) {
617
+ if (!DoSplit && !DoSpecConst && !DoSymGen && !DoParamInfo ) {
585
618
errs () << " no actions specified; try --help for usage info\n " ;
586
619
return 1 ;
587
620
}
@@ -595,6 +628,11 @@ int main(int argc, char **argv) {
595
628
<< IROutputOnly.ArgStr << " \n " ;
596
629
return 1 ;
597
630
}
631
+ if (IROutputOnly && DoParamInfo) {
632
+ errs () << " error: -" << EmitKernelParamInfo.ArgStr << " can't be used with"
633
+ << " -" << IROutputOnly.ArgStr << " \n " ;
634
+ return 1 ;
635
+ }
598
636
SMDiagnostic Err;
599
637
std::unique_ptr<Module> M = parseIRFile (InputFilename, Err, Context);
600
638
// It is OK to use raw pointer here as we control that it does not outlive M
@@ -664,7 +702,7 @@ int main(int argc, char **argv) {
664
702
665
703
{
666
704
ImagePropSaveInfo ImgPSInfo = {true , DoSpecConst, SetSpecConstAtRT,
667
- SpecConstsMet};
705
+ SpecConstsMet, EmitKernelParamInfo };
668
706
string_vector Files = saveDeviceImageProperty (ResultModules, ImgPSInfo);
669
707
Error Err = Table.addColumn (COL_PROPS, Files);
670
708
CHECK_AND_EXIT (Err);
0 commit comments