LLVM笔记(3) - PASS

匿名 (未验证) 提交于 2019-12-02 23:43:01

1. pass的概念


2. 跟踪与调试pass


 1 [13:38:49] hansy@hansy:~$ cat test.c  2 int sigma(int cnt)  3 {  4   int sum = 0, i = 0;  5   for (i = 0; i < cnt; i++)  6     sum += i;  7   return sum;  8 }  9  10 [13:38:55] hansy@hansy:~$ clang test.c -O2 -mllvm -debug -S 2>test.ll 11 [13:39:02] hansy@hansy:~$ clang test.c -O2 -mllvm -debug-only=early-cse -S 2>test.ll 12 [13:39:05] hansy@hansy:~$ clang test.c -O2 -mllvm -print-before-all -S 2>test.ll 13 [13:39:16] hansy@hansy:~$ clang test.c -O2 -mllvm -print-after-all -S 2>test.ll 14 [13:39:25] hansy@hansy:~$ clang test.c -O2 -mllvm -print-after-all -mllvm -filter-print-funcs=sigma -S 2>test.ll 





3. DEBUG in LLVM


 1 #ifndef NDEBUG  2 #define DEBUG_WITH_TYPE(TYPE, X)                                        \  3   do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)) { X; } \  4   } while (false)  5 #else  6 #define DEBUG_WITH_TYPE(TYPE, X) do { } while (false)  7 #endif  8   9 #define LLVM_DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X) 10  11 #ifndef NDEBUG 12 static cl::opt<bool, true> 13 Debug("debug", cl::desc("Enable debug output"), cl::Hidden, 14       cl::location(DebugFlag)); 15 static cl::opt<DebugOnlyOpt, true, cl::parser<std::string> > 16 DebugOnly("debug-only", cl::desc("Enable a specific type of debug output (comma separated list of types)"), 17           cl::Hidden, cl::ZeroOrMore, cl::value_desc("debug string"), 18           cl::location(DebugOnlyOptLoc), cl::ValueRequired); 19 #endif 20  21 bool isCurrentDebugType(const char *DebugType) { 22   if (CurrentDebugType->empty()) 23     return true; 24   for (auto &d : *CurrentDebugType) { 25     if (d == DebugType) 26       return true; 27   } 28   return false; 29 } 30  31 raw_ostream &llvm::dbgs() { 32   static struct dbgstream { 33     circular_raw_ostream strm; 34  35     dbgstream() : 36         strm(errs(), "*** Debug Log Output ***\n", 37              (!EnableDebugBuffering || !DebugFlag) ? 0 : DebugBufferSize) { 38       if (EnableDebugBuffering && DebugFlag && DebugBufferSize != 0) 39         sys::AddSignalHandler(&debug_user_sig_handler, nullptr); 40     } 41   } thestrm; 42  43   return thestrm.strm; 44 }






 1 if( LLVM_ENABLE_ASSERTIONS )  2   # MSVC doesn't like _DEBUG on release builds. See PR 4379.  3   if( NOT MSVC )  4     add_definitions( -D_DEBUG )  5   endif()  6   # On non-Debug builds cmake automatically defines NDEBUG, so we  7   # explicitly undefine it:  8   if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )  9     add_definitions( -UNDEBUG ) 10     # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. 11     foreach (flags_var_to_scrub 12         CMAKE_CXX_FLAGS_RELEASE 13         CMAKE_CXX_FLAGS_RELWITHDEBINFO 14         CMAKE_CXX_FLAGS_MINSIZEREL 15         CMAKE_C_FLAGS_RELEASE 16         CMAKE_C_FLAGS_RELWITHDEBINFO 17         CMAKE_C_FLAGS_MINSIZEREL) 18       string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " 19         "${flags_var_to_scrub}" "${${flags_var_to_scrub}}") 20     endforeach() 21   endif() 22 endif()


4. 编写一个简单pass


5. pass的分类










6. 注册pass


7. 略

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!