[llvm] 21abe21 - [TableGen][PGO] Disable profile instrumentation for printInstruction function

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 14 13:43:01 PDT 2021


Author: Rong Xu
Date: 2021-10-14T13:41:55-07:00
New Revision: 21abe21280585401ce13d3217d051aa4bcfcc584

URL: https://github.com/llvm/llvm-project/commit/21abe21280585401ce13d3217d051aa4bcfcc584
DIFF: https://github.com/llvm/llvm-project/commit/21abe21280585401ce13d3217d051aa4bcfcc584.diff

LOG: [TableGen][PGO] Disable profile instrumentation for printInstruction function

We are seeing extremely long time in building AMDGPUInstPrinter.cpp
when profile instrumentation is enabled: It takes more than 5 minutes
(compared to ~8 seconds in non-instrument build).

This caused by the huge statements in printInstruction functions. In
profile instrumentation build, we need have extra control flow to
differentiate each case statement. This in turn adds significant
compile time in block placement and branch folding.

Function printInstruction is not likely to benefit from PGO build
as it's rarely executed in a typical compilation. So here I disable
the profile instrumentation for this function.

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

Added: 
    

Modified: 
    llvm/include/llvm/Support/Compiler.h
    llvm/utils/TableGen/AsmWriterEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 3aa76546fd1d2..c5318137ed3d0 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -556,4 +556,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
 #define LLVM_ENABLE_EXCEPTIONS 1
 #endif
 
+/// \macro LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
+/// Disable the profile instrument for a function.
+#if __has_attribute(no_profile_instrument_function)
+#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION                                    \
+  __attribute__((no_profile_instrument_function))
+#else
+#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
+#endif
+
 #endif

diff  --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp
index 94fd8f7e92b4b..bb13c4033db7b 100644
--- a/llvm/utils/TableGen/AsmWriterEmitter.cpp
+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp
@@ -457,9 +457,14 @@ void AsmWriterEmitter::EmitPrintInstruction(
   StringRef ClassName = AsmWriter->getValueAsString("AsmWriterClassName");
   bool PassSubtarget = AsmWriter->getValueAsInt("PassSubtarget");
 
+  // This function has some huge switch statements that causing excessive
+  // compile time in LLVM profile instrumenation build. This print function
+  // usually is not frequently called in compilation. Here we disable the
+  // profile instrumenation for this function.
   O << "/// printInstruction - This method is automatically generated by "
        "tablegen\n"
        "/// from the instruction set description.\n"
+       "LLVM_NO_PROFILE_INSTRUMENT_FUNCTION\n"
        "void "
     << Target.getName() << ClassName
     << "::printInstruction(const MCInst *MI, uint64_t Address, "


        


More information about the llvm-commits mailing list