[llvm] r258344 - [GlobalISel] Add the proper cmake plumbing.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 20 12:58:57 PST 2016


Author: qcolombet
Date: Wed Jan 20 14:58:56 2016
New Revision: 258344

URL: http://llvm.org/viewvc/llvm-project?rev=258344&view=rev
Log:
[GlobalISel] Add the proper cmake plumbing.

This patch adds the necessary plumbing to cmake to build the sources related to
GlobalISel.

To build the sources related to GlobalISel, we need to add -DBUILD_GLOBAL_ISEL=ON.
By default, this is OFF, thus GlobalISel sources will not impact people that do
not explicitly opt-in.

Differential Revision: http://reviews.llvm.org/D15983

Added:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/
    llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
    llvm/trunk/include/llvm/CodeGen/GlobalISel/Types.h
    llvm/trunk/lib/CodeGen/GlobalISel/
    llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt
    llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
    llvm/trunk/lib/CodeGen/GlobalISel/LLVMBuild.txt
Modified:
    llvm/trunk/CMakeLists.txt
    llvm/trunk/lib/CodeGen/CMakeLists.txt
    llvm/trunk/lib/CodeGen/LLVMBuild.txt
    llvm/trunk/tools/llc/CMakeLists.txt

Modified: llvm/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=258344&r1=258343&r2=258344&view=diff
==============================================================================
--- llvm/trunk/CMakeLists.txt (original)
+++ llvm/trunk/CMakeLists.txt Wed Jan 20 14:58:56 2016
@@ -68,6 +68,8 @@ if(LLVM_PARALLEL_COMPILE_JOBS)
   endif()
 endif()
 
+set(LLVM_BUILD_GLOBAL_ISEL OFF CACHE BOOL "Experimental: Build GlobalISel")
+
 set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
   "Define the maximum number of concurrent link jobs.")
 if(LLVM_PARALLEL_LINK_JOBS)

Added: llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h?rev=258344&view=auto
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h (added)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h Wed Jan 20 14:58:56 2016
@@ -0,0 +1,127 @@
+//===-- llvm/CodeGen/GlobalISel/IRTranslator.h - IRTranslator ---*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+/// \file
+/// This file declares the IRTranslator pass.
+/// This pass is responsible for translating LLVM IR into MachineInstr.
+/// It uses target hooks to lower the ABI but aside from that, the pass
+/// generated code is generic. This is the default translator used for
+/// GlobalISel.
+///
+/// \todo Replace the comments with actual doxygen comments.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_GLOBALISEL_IRTRANSLATOR_H
+#define LLVM_CODEGEN_GLOBALISEL_IRTRANSLATOR_H
+
+#include "Types.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/IR/Constants.h"
+
+namespace llvm {
+// Forward declarations.
+class Constant;
+class Instruction;
+class MachineInstr;
+class MachineIRBuilder;
+
+// Technically the pass should run on an hypothetical MachineModule,
+// since it should translate Global into some sort of MachineGlobal.
+// The MachineGlobal should ultimately just be a transfer of ownership of
+// the interesting bits that are relevant to represent a global value.
+// That being said, we could investigate what would it cost to just duplicate
+// the information from the LLVM IR.
+// The idea is that ultimately we would be able to free up the memory used
+// by the LLVM IR as soon as the translation is over.
+class IRTranslator : public MachineFunctionPass {
+public:
+  static char ID;
+
+private:
+  // Interface used to lower the everything related to calls.
+  //  TargetLowering *CallLowering;
+  // Mapping of the values of the current LLVM IR function
+  // to the related virtual registers.
+  // We need several virtual registers for the lowering of things
+  // like structures. Right now, this is just a list of virtual
+  // registers, but we would need to encapsulate that in a higher
+  // level class.
+  ValueToVRegs ValToVRegs;
+  // Mapping of a constant to the instructions to produce
+  // that constant.
+  // Constants are special because when we encounter one,
+  // we do not know at first where to insert the definition since
+  // this depends on all its uses.
+  // Thus, we will insert the sequences to materialize them when
+  // we know all their users.
+  // In the meantime, just keep it in a map.
+  // Note: Constants that end up as immediate in the related instructions,
+  // do not appear in that map.
+  DenseMap<const Constant *, SmallVector<MachineInstr *, 1>> ConstantToSequence;
+
+  /* A bunch of methods targeting ADD, SUB, etc. */
+  // Return true if the translation was successful, false
+  // otherwise.
+  // Note: The MachineIRBuilder would encapsulate a
+  // MachineRegisterInfo to create virtual registers.
+  //
+  // Algo:
+  // 1. Look for a virtual register for each operand or
+  //    create one.
+  // 2 Update the ValToVReg accordingly.
+  // 2.alt. For constant arguments, if they are compile time constants,
+  //   produce an immediate in the right operand and do not touch
+  //   ValToReg. Otherwise, update ValToVReg and register the
+  //   sequence to materialize the constant in ConstantToSequence.
+  // 3. Create the generic instruction.
+  bool translateADD(const Instruction &Inst);
+
+  // Builder for machine instruction a la IRBuilder.
+  // I.e., compared to regular MIBuilder, this one also inserts the instruction
+  // in the current block, it can creates block, etc., basically a kind of
+  // IRBuilder, but for Machine IR.
+  MachineIRBuilder *MIRBuilder;
+
+  // Return true if the translation from LLVM IR to Machine IR
+  // suceeded.
+  // See translateXXX for details.
+  bool translate(const Instruction &);
+
+  // * Insert all the code needed to materialize the constants
+  // at the proper place. E.g., Entry block or dominator block
+  // of each constant depending ob how fancy we want to be.
+  // * Clear the different maps.
+  void finalize();
+public:
+  // Ctor, nothing fancy.
+  IRTranslator();
+
+  // Instead of having the instance of the IRTranslatorToolkit
+  // as an argument of the constructor of IRTranslator, we ask
+  // the target the instance of the toolkit for each MachineFunction.
+  // The interest is that we may have different translator for different
+  // subtract or optimization. E.g., we could have a translator optimized
+  // to produce small code size.
+  //
+  // Algo:
+  //   CallLowering = MF.subtarget.getCallLowering()
+  //   F = MF.getParent()
+  //   MIRBuilder.reset(MF)
+  //   MIRBuilder.getOrCreateBB(F.getEntryBB())
+  //   CallLowering->translateArguments(MIRBuilder, F, ValToVReg)
+  //   for each bb in F
+  //     MIRBuilder.getOrCreateBB(bb)
+  //     for each inst in bb
+  //       if (!translate(MIRBuilder, inst, ValToVReg, ConstantToSequence))
+  //         report_fatal_error(“Don’t know how to translate input");
+  //   finalize()
+  bool runOnMachineFunction(MachineFunction &MF) override;
+};
+
+} // End namespace llvm.
+#endif

Added: llvm/trunk/include/llvm/CodeGen/GlobalISel/Types.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/Types.h?rev=258344&view=auto
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/Types.h (added)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/Types.h Wed Jan 20 14:58:56 2016
@@ -0,0 +1,34 @@
+//===-- llvm/CodeGen/GlobalISel/Types.h - Types used by GISel ----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file describes high level types that are used by several passes or
+/// APIs involved in the GlobalISel pipeline.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_GLOBALISEL_TYPES_H
+#define LLVM_CODEGEN_GLOBALISEL_TYPES_H
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/Value.h"
+
+namespace llvm {
+
+/// Map a value to virtual registers.
+/// We must support several virtual registers for a value.
+/// Indeed each virtual register is mapped to one EVT, but a value
+/// may span over several EVT when it is a type representing a structure.
+/// In that case the value will be break into EVTs.
+/// Note: We need to expose this type to the target hooks for thing like
+/// ABI lowering that would be used during IRTranslation.
+typedef DenseMap<const Value *, SmallVector<unsigned, 1>> ValueToVRegs;
+
+} // End namespace llvm.
+#endif

Modified: llvm/trunk/lib/CodeGen/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CMakeLists.txt?rev=258344&r1=258343&r2=258344&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CMakeLists.txt (original)
+++ llvm/trunk/lib/CodeGen/CMakeLists.txt Wed Jan 20 14:58:56 2016
@@ -142,3 +142,6 @@ add_dependencies(LLVMCodeGen intrinsics_
 add_subdirectory(SelectionDAG)
 add_subdirectory(AsmPrinter)
 add_subdirectory(MIRParser)
+if(LLVM_BUILD_GLOBAL_ISEL)
+  add_subdirectory(GlobalISel)
+endif()

Added: llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt?rev=258344&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt (added)
+++ llvm/trunk/lib/CodeGen/GlobalISel/CMakeLists.txt Wed Jan 20 14:58:56 2016
@@ -0,0 +1,5 @@
+add_llvm_library(LLVMGlobalISel
+        IRTranslator.cpp
+  )
+
+add_dependencies(LLVMGlobalISel intrinsics_gen)

Added: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=258344&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (added)
+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Wed Jan 20 14:58:56 2016
@@ -0,0 +1,37 @@
+//===-- llvm/CodeGen/GlobalISel/IRTranslator.cpp - IRTranslator --*- C++ -*-==//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+/// \file
+/// This file implements the IRTranslator class.
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/GlobalISel/IRTranslator.h"
+
+using namespace llvm;
+
+char IRTranslator::ID = 0;
+
+bool IRTranslator::translateADD(const Instruction &Inst) {
+  return false;
+}
+
+bool IRTranslator::translate(const Instruction &) {
+  return false;
+}
+
+
+void IRTranslator::finalize() {
+}
+
+IRTranslator::IRTranslator()
+  : MachineFunctionPass(ID) {
+}
+
+bool IRTranslator::runOnMachineFunction(MachineFunction &MF) {
+  return false;
+}

Added: llvm/trunk/lib/CodeGen/GlobalISel/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LLVMBuild.txt?rev=258344&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LLVMBuild.txt (added)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LLVMBuild.txt Wed Jan 20 14:58:56 2016
@@ -0,0 +1,22 @@
+;===- ./lib/CodeGen/GlobalISel/LLVMBuild.txt -----------------*- Conf -*--===;
+;
+;                     The LLVM Compiler Infrastructure
+;
+; This file is distributed under the University of Illinois Open Source
+; License. See LICENSE.TXT for details.
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+;   http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+type = Library
+name = GlobalISel
+parent = CodeGen
+required_libraries = Analysis CodeGen Core MC Support Target TransformUtils

Modified: llvm/trunk/lib/CodeGen/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMBuild.txt?rev=258344&r1=258343&r2=258344&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMBuild.txt (original)
+++ llvm/trunk/lib/CodeGen/LLVMBuild.txt Wed Jan 20 14:58:56 2016
@@ -16,7 +16,7 @@
 ;===------------------------------------------------------------------------===;
 
 [common]
-subdirectories = AsmPrinter SelectionDAG MIRParser
+subdirectories = AsmPrinter SelectionDAG MIRParser GlobalISel
 
 [component_0]
 type = Library

Modified: llvm/trunk/tools/llc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/CMakeLists.txt?rev=258344&r1=258343&r2=258344&view=diff
==============================================================================
--- llvm/trunk/tools/llc/CMakeLists.txt (original)
+++ llvm/trunk/tools/llc/CMakeLists.txt Wed Jan 20 14:58:56 2016
@@ -1,3 +1,10 @@
+# Add GlobalISel to the dependencies if the user wants to build it.
+if(LLVM_BUILD_GLOBAL_ISEL)
+  set(GLOBAL_ISEL GlobalISel)
+else()
+  set(GLOBAL_ISEL "")
+endif()
+
 set(LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
   Analysis
@@ -5,6 +12,7 @@ set(LLVM_LINK_COMPONENTS
   CodeGen
   Core
   IRReader
+  ${GLOBAL_ISEL}
   MC
   MIRParser
   ScalarOpts




More information about the llvm-commits mailing list