[CSSPGO] Explicitly disallow Binary and Compact Binary profile format for CSSPGO
authorWenlei He <aktoon@gmail.com>
Sat, 24 Apr 2021 17:37:55 +0000 (10:37 -0700)
committerWenlei He <aktoon@gmail.com>
Mon, 26 Apr 2021 16:10:24 +0000 (09:10 -0700)
CSSPGO only supports text and extended binary profile now. Raw binary does not have the metadata section CSSPGO needs, and Compact binary profile needs special handling for GUID based context names, which is not yet implemented.

Disasslow these two format for CSSPGO profile writing to avoid silently generating invalid profiles.

Differential Revision: https://reviews.llvm.org/D101300

llvm/lib/ProfileData/SampleProfWriter.cpp

index 43cfb93..73565f2 100644 (file)
@@ -776,6 +776,11 @@ SampleProfileWriter::create(std::unique_ptr<raw_ostream> &OS,
   std::error_code EC;
   std::unique_ptr<SampleProfileWriter> Writer;
 
+  // Currently only Text and Extended Binary format are supported for CSSPGO.
+  if ((FunctionSamples::ProfileIsCS || FunctionSamples::ProfileIsProbeBased) &&
+      (Format == SPF_Binary || Format == SPF_Compact_Binary))
+    return sampleprof_error::unsupported_writing_format;
+
   if (Format == SPF_Binary)
     Writer.reset(new SampleProfileWriterRawBinary(OS));
   else if (Format == SPF_Ext_Binary)