[llvm] f020544 - [NewPM][HelloWorld] Move HelloWorld to Utils

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 3 13:00:31 PST 2021


Author: Arthur Eubanks
Date: 2021-02-03T12:59:40-08:00
New Revision: f02054460137940d66559b0c4e675a86af23439a

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

LOG: [NewPM][HelloWorld] Move HelloWorld to Utils

To prevent creating a new component, which creates a new library.

Reviewed By: ychen

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

Added: 
    llvm/include/llvm/Transforms/Utils/HelloWorld.h
    llvm/lib/Transforms/Utils/HelloWorld.cpp

Modified: 
    llvm/docs/WritingAnLLVMNewPMPass.rst
    llvm/lib/Passes/CMakeLists.txt
    llvm/lib/Passes/PassBuilder.cpp
    llvm/lib/Transforms/CMakeLists.txt
    llvm/lib/Transforms/Utils/CMakeLists.txt
    llvm/utils/gn/secondary/llvm/lib/Passes/BUILD.gn
    llvm/utils/gn/secondary/llvm/lib/Transforms/Utils/BUILD.gn

Removed: 
    llvm/include/llvm/Transforms/HelloNew/HelloWorld.h
    llvm/lib/Transforms/HelloNew/CMakeLists.txt
    llvm/lib/Transforms/HelloNew/HelloWorld.cpp
    llvm/utils/gn/secondary/llvm/lib/Transforms/HelloNew/BUILD.gn


################################################################################
diff  --git a/llvm/docs/WritingAnLLVMNewPMPass.rst b/llvm/docs/WritingAnLLVMNewPMPass.rst
index ad8a9d5a1926..6a8d3c90b30e 100644
--- a/llvm/docs/WritingAnLLVMNewPMPass.rst
+++ b/llvm/docs/WritingAnLLVMNewPMPass.rst
@@ -48,20 +48,11 @@ Setting up the build
 First, configure and build LLVM as described in :doc:`GettingStarted`.
 
 Next, we will reuse an existing directory (creating a new directory involves
-modifying more ``CMakeLists.txt``s than we want). For
-this example, we'll use ``llvm/lib/Transforms/HelloNew/HelloWorld.cpp``,
-which has already been created. If you'd like to create your own pass, add a
-new source file into ``llvm/lib/Transforms/HelloNew/CMakeLists.txt`` under
-``HelloWorld.cpp``:
-
-.. code-block:: cmake
-
-  add_llvm_component_library(LLVMHelloWorld
-    HelloWorld.cpp
-
-    DEPENDS
-    intrinsics_gen
-    )
+messing around with more CMake files than we want). For this example, we'll use
+``llvm/lib/Transforms/Utils/HelloWorld.cpp``, which has already been created.
+If you'd like to create your own pass, add a new source file into
+``llvm/lib/Transforms/Utils/CMakeLists.txt`` (assuming you want your pass in
+the ``Transforms/Utils`` directory.
 
 Now that we have the build set up for a new pass, we need to write the code
 for the pass itself.
@@ -74,7 +65,7 @@ Basic code required
 Now that the build is setup for a new pass, we just have to write it.
 
 First we need to define the pass in a header file. We'll create
-``llvm/include/llvm/Transforms/HelloNew/HelloWorld.h``. The file should
+``llvm/include/llvm/Transforms/Utils/HelloWorld.h``. The file should
 contain the following boilerplate:
 
 .. code-block:: c++
@@ -102,12 +93,12 @@ sets up some more boilerplate so that we don't have to write it ourselves.
 Our class is in the ``llvm`` namespace so that we don't pollute the global
 namespace.
 
-Next we'll create ``llvm/lib/Transforms/HelloNew/HelloWorld.cpp``, starting
+Next we'll create ``llvm/lib/Transforms/Utils/HelloWorld.cpp``, starting
 with
 
 .. code-block:: c++
 
-  #include "llvm/Transforms/HelloNew/HelloWorld.h"
+  #include "llvm/Transforms/Utils/HelloWorld.h"
 
 ... to include the header file we just created.
 
@@ -135,7 +126,7 @@ tree) are still valid after this pass since we didn't modify any functions.
 
 That's it for the pass itself. Now in order to "register" the pass, we need
 to add it to a couple places. Add the following to
-``llvm\lib\Passes\PassRegistry.def`` in the ``FUNCTION_PASS`` section
+``llvm/lib/Passes/PassRegistry.def`` in the ``FUNCTION_PASS`` section
 
 .. code-block:: c++
 
@@ -143,14 +134,14 @@ to add it to a couple places. Add the following to
 
 ... which adds the pass under the name "helloworld".
 
-``llvm\lib\Passes\PassRegistry.def`` is #include'd into
-``llvm\lib\Passes\PassBuilder.cpp`` multiple times for various reasons. Since
+``llvm/lib/Passes/PassRegistry.def`` is #include'd into
+``llvm/lib/Passes/PassBuilder.cpp`` multiple times for various reasons. Since
 it constructs our pass, we need to also add the proper #include in
-``llvm\lib\Passes\PassBuilder.cpp``:
+``llvm/lib/Passes/PassBuilder.cpp``:
 
 .. code-block:: c++
 
-  #include "llvm/Transforms/HelloNew/HelloWorld.h"
+  #include "llvm/Transforms/Utils/HelloWorld.h"
 
 This should be all the code necessary for our pass, now it's time to compile
 and run it.
@@ -186,12 +177,12 @@ Testing a pass
 --------------
 
 Testing our pass is important to prevent future regressions. We'll add a lit
-test at ``llvm/test/Transforms/HelloNew/helloworld.ll``. See
+test at ``llvm/test/Transforms/Utils/helloworld.ll``. See
 :doc:`TestingGuide` for more information on testing.
 
 .. code-block:: llvm
 
-  $ cat llvm/test/Transforms/HelloNew/helloworld.ll
+  $ cat llvm/test/Transforms/Utils/helloworld.ll
   ; RUN: opt -disable-output -passes=helloworld %s 2>&1 | FileCheck %s
 
   ; CHECK: {{^}}foo{{$}}

diff  --git a/llvm/include/llvm/Transforms/HelloNew/HelloWorld.h b/llvm/include/llvm/Transforms/Utils/HelloWorld.h
similarity index 100%
rename from llvm/include/llvm/Transforms/HelloNew/HelloWorld.h
rename to llvm/include/llvm/Transforms/Utils/HelloWorld.h

diff  --git a/llvm/lib/Passes/CMakeLists.txt b/llvm/lib/Passes/CMakeLists.txt
index d834c0db4b45..f517136223ec 100644
--- a/llvm/lib/Passes/CMakeLists.txt
+++ b/llvm/lib/Passes/CMakeLists.txt
@@ -15,7 +15,6 @@ add_llvm_component_library(LLVMPasses
   Analysis
   Core
   Coroutines
-  HelloNew
   IPO
   InstCombine
   ObjCARC

diff  --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index f801bcd879d3..29c2eb82c3bb 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -84,7 +84,6 @@
 #include "llvm/Transforms/Coroutines/CoroEarly.h"
 #include "llvm/Transforms/Coroutines/CoroElide.h"
 #include "llvm/Transforms/Coroutines/CoroSplit.h"
-#include "llvm/Transforms/HelloNew/HelloWorld.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/Annotation2Metadata.h"
 #include "llvm/Transforms/IPO/ArgumentPromotion.h"
@@ -215,6 +214,7 @@
 #include "llvm/Transforms/Utils/CanonicalizeFreezeInLoops.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/FixIrreducible.h"
+#include "llvm/Transforms/Utils/HelloWorld.h"
 #include "llvm/Transforms/Utils/InjectTLIMappings.h"
 #include "llvm/Transforms/Utils/InstructionNamer.h"
 #include "llvm/Transforms/Utils/LCSSA.h"

diff  --git a/llvm/lib/Transforms/CMakeLists.txt b/llvm/lib/Transforms/CMakeLists.txt
index 2a0abebdf19b..dda5f6de11e3 100644
--- a/llvm/lib/Transforms/CMakeLists.txt
+++ b/llvm/lib/Transforms/CMakeLists.txt
@@ -6,7 +6,6 @@ add_subdirectory(Scalar)
 add_subdirectory(IPO)
 add_subdirectory(Vectorize)
 add_subdirectory(Hello)
-add_subdirectory(HelloNew)
 add_subdirectory(ObjCARC)
 add_subdirectory(Coroutines)
 add_subdirectory(CFGuard)

diff  --git a/llvm/lib/Transforms/HelloNew/CMakeLists.txt b/llvm/lib/Transforms/HelloNew/CMakeLists.txt
deleted file mode 100644
index 76ac8ada6e32..000000000000
--- a/llvm/lib/Transforms/HelloNew/CMakeLists.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-add_llvm_component_library(LLVMHelloNew
-  HelloWorld.cpp
-
-  DEPENDS
-  intrinsics_gen
-
-  LINK_COMPONENTS
-  Core
-  Support
-  )

diff  --git a/llvm/lib/Transforms/Utils/CMakeLists.txt b/llvm/lib/Transforms/Utils/CMakeLists.txt
index b3bdc192a877..30c9a3daa90b 100644
--- a/llvm/lib/Transforms/Utils/CMakeLists.txt
+++ b/llvm/lib/Transforms/Utils/CMakeLists.txt
@@ -27,6 +27,7 @@ add_llvm_component_library(LLVMTransformUtils
   FunctionImportUtils.cpp
   GlobalStatus.cpp
   GuardUtils.cpp
+  HelloWorld.cpp
   InlineFunction.cpp
   InjectTLIMappings.cpp
   InstructionNamer.cpp

diff  --git a/llvm/lib/Transforms/HelloNew/HelloWorld.cpp b/llvm/lib/Transforms/Utils/HelloWorld.cpp
similarity index 92%
rename from llvm/lib/Transforms/HelloNew/HelloWorld.cpp
rename to llvm/lib/Transforms/Utils/HelloWorld.cpp
index dea94f8a8f62..7019e9e4451b 100644
--- a/llvm/lib/Transforms/HelloNew/HelloWorld.cpp
+++ b/llvm/lib/Transforms/Utils/HelloWorld.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Transforms/HelloNew/HelloWorld.h"
+#include "llvm/Transforms/Utils/HelloWorld.h"
 
 using namespace llvm;
 

diff  --git a/llvm/utils/gn/secondary/llvm/lib/Passes/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Passes/BUILD.gn
index bb8a671dd6a7..9afe48db159b 100644
--- a/llvm/utils/gn/secondary/llvm/lib/Passes/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/Passes/BUILD.gn
@@ -8,7 +8,6 @@ static_library("Passes") {
     "//llvm/lib/Target",
     "//llvm/lib/Transforms/AggressiveInstCombine",
     "//llvm/lib/Transforms/Coroutines",
-    "//llvm/lib/Transforms/HelloNew",
     "//llvm/lib/Transforms/IPO",
     "//llvm/lib/Transforms/InstCombine",
     "//llvm/lib/Transforms/Instrumentation",

diff  --git a/llvm/utils/gn/secondary/llvm/lib/Transforms/HelloNew/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Transforms/HelloNew/BUILD.gn
deleted file mode 100644
index 5e6167324a4a..000000000000
--- a/llvm/utils/gn/secondary/llvm/lib/Transforms/HelloNew/BUILD.gn
+++ /dev/null
@@ -1,9 +0,0 @@
-static_library("HelloNew") {
-  output_name = "LLVMHelloNew"
-  deps = [
-    "//llvm/lib/Analysis",
-    "//llvm/lib/IR",
-    "//llvm/lib/Support",
-  ]
-  sources = [ "HelloWorld.cpp" ]
-}

diff  --git a/llvm/utils/gn/secondary/llvm/lib/Transforms/Utils/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Transforms/Utils/BUILD.gn
index efdded38c7c2..a7cae6b4b889 100644
--- a/llvm/utils/gn/secondary/llvm/lib/Transforms/Utils/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/Transforms/Utils/BUILD.gn
@@ -34,6 +34,7 @@ static_library("Utils") {
     "FunctionImportUtils.cpp",
     "GlobalStatus.cpp",
     "GuardUtils.cpp",
+    "HelloWorld.cpp",
     "InjectTLIMappings.cpp",
     "InlineFunction.cpp",
     "InstructionNamer.cpp",


        


More information about the llvm-commits mailing list