[PATCH] [lld] add InputGraph to process Command line arguments

Shankar Kalpathi Easwaran shankarke at gmail.com
Fri Jul 26 15:18:12 PDT 2013


  As me/Bigcheese discussed on IRC, these are the changes planned in the revised patch.

  - The name of the class remains as InputGraph, as we dont plan on flattening it to a list, and the data structure resembles a tree.
  - InputGraph would have functionality to just add Input Nodes and will not know anything about llvm::opt
  - Move OptionInfo to the driver, OptionInfo would create nodes for the InputGraph
  - The InputElement will have an additional function to create a lld::File from it, for lld to use

  Changes to lld::File

  - lld::File will have positional attributes (forceLoadArchive, asNeeded etc).


================
Comment at: include/lld/Driver/InputGraph.h:33-76
@@ +32,46 @@
+
+/// \brief Each flavor of lld creates a OptionInfo object that defines the set
+/// of options that the flavor handles. It also associates the command line
+/// with the Option Type thats associated with it.
+class OptionInfo {
+public:
+  /// \brief The various types of options that are supported
+  /// Positional option indicates that processing the next argument depends
+  /// on the current positional argument. The positional argument would decide
+  /// the way the following argument is processed by lld
+  /// Control options indicate how the next set of options would be processed
+  /// by lld. This would control how the arguments would be processed by the
+  /// linker
+  enum class OptType : uint8_t {
+    Opt_Unknown,       // The option is Unknown
+    Opt_LLVMOption,    // The Option is handled by LLVM
+    Opt_Positional,    // Positional Option
+    Opt_SimpleControl, // A simple control flag
+    Opt_ControlEnter,  // Start the control option
+    Opt_ControlExit,   // Exit the control option
+    Opt_Global,        // Global Option
+    Opt_Input          // Input File
+  };
+
+  OptionInfo() {}
+
+  /// \brief Determine the option type for a particular Input argument
+  virtual OptType getInputOptionType(llvm::opt::Arg &arg) = 0;
+
+  /// \brief Create an input element corresponding to the Input option
+  virtual std::unique_ptr<InputElement> getInputElement(llvm::opt::Arg &arg,
+                                                        OptType optionType) = 0;
+
+  /// \brief process Global option
+  virtual bool processGlobalOption(llvm::opt::Arg &arg, OptType optionType) = 0;
+
+  /// \brief process LLVM Options
+  virtual bool processLLVMOption(llvm::opt::Arg &arg, OptType optionType) = 0;
+
+  /// \brief process Unknown Option
+  virtual bool processUnknownOption(llvm::opt::Arg &arg,
+                                    OptType optionType) = 0;
+
+  virtual ~OptionInfo() {}
+};
+
----------------
Michael Spencer wrote:
> This should not be part of InputGraph.
Will move this to a seperate header file and have the driver deal with handling Options. 

OptionInfo class would still remain and would be used as a place that creates InputGraph nodes and add them to the InputGraph.

================
Comment at: include/lld/Driver/InputGraph.h:83-84
@@ +82,4 @@
+/// to do when it processes the option. Each InputElement that is part of the
+/// Graph has also an Ordinal value associated with it. The ordinal value is
+/// needed for components to figure out the relative position of the arguments
+/// that appeared in the Command Line. One such example is adding the list of
----------------
Michael Spencer wrote:
> The InputGraph should replace the ordinal, as ordinals change as the graph is processed if new files get added.
Current Implementation doesnot handle this and its likely to be part of another API that the InputGraph would have to expand Input Elements, which would replace ordinals.

================
Comment at: include/lld/Driver/InputGraph.h:89
@@ +88,3 @@
+/// weight of the file, for statistical purposes. The InputGraph also would
+/// contain a set of General options that are processed by the linker, which
+/// control the output
----------------
Michael Spencer wrote:
> The only options handled by the InputGraph should be those that effect the graph.
Will change the API, so that InputGraph only has functionality to add / expand a node.

================
Comment at: include/lld/Driver/InputGraph.h:101-109
@@ +100,11 @@
+
+  /// \brief Read inputs that were passed
+  virtual bool processArgs(const llvm::opt::InputArgList &inputArgList);
+
+  /// \brief Process Argument, Process argument determines what
+  /// the current argument type is and creates either a ControlNode
+  /// or an InputFileNode. If the argument is a positional option
+  /// it appends the positional option to the InputElement, which
+  /// is either a a control node or an InputFileNode.
+  virtual bool processArg(llvm::opt::Arg &arg);
+
----------------
Michael Spencer wrote:
> The InputGraph should know nothing of llvm::opt. Some other code should build an InputGraph using the command line.
Agree.

================
Comment at: include/lld/Driver/InputGraph.h:165
@@ +164,3 @@
+  int64_t _ordinal;
+  int64_t _weight;
+};
----------------
Michael Spencer wrote:
> I don't get the purpose of this.
Weight was added to the InputElement to mainly display information to the user. For example, say the number of symbols resolved from the .o or .a or .so.


http://llvm-reviews.chandlerc.com/D1217



More information about the llvm-commits mailing list