[llvm] r253820 - Avoid dependency between TableGen and CodeGen

Yaron Keren via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 22 07:31:27 PST 2015


Instead of copy&paste duplication, wouldn't it be better to introduce a .h
or .inc file shared by both cpp sources?


2015-11-22 17:20 GMT+02:00 Krzysztof Parzyszek via llvm-commits <
llvm-commits at lists.llvm.org>:

> Author: kparzysz
> Date: Sun Nov 22 09:20:19 2015
> New Revision: 253820
>
> URL: http://llvm.org/viewvc/llvm-project?rev=253820&view=rev
> Log:
> Avoid dependency between TableGen and CodeGen
>
> Duplicate a few common definitions between DFAPacketizer.cpp and
> DFAPacketizerEmitter.cpp to avoid including files from CodeGen
> in TableGen.
>
> Removed:
>     llvm/trunk/include/llvm/CodeGen/DFAPacketizerDefs.h
> Modified:
>     llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h
>     llvm/trunk/lib/CodeGen/DFAPacketizer.cpp
>     llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h?rev=253820&r1=253819&r2=253820&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/DFAPacketizer.h Sun Nov 22 09:20:19
> 2015
> @@ -27,7 +27,6 @@
>  #define LLVM_CODEGEN_DFAPACKETIZER_H
>
>  #include "llvm/ADT/DenseMap.h"
> -#include "llvm/CodeGen/DFAPacketizerDefs.h"
>  #include "llvm/CodeGen/MachineBasicBlock.h"
>  #include <map>
>
> @@ -41,6 +40,34 @@ class InstrItineraryData;
>  class DefaultVLIWScheduler;
>  class SUnit;
>
> +// --------------------------------------------------------------------
> +// Definitions shared between DFAPacketizer.cpp and
> DFAPacketizerEmitter.cpp
> +
> +// DFA_MAX_RESTERMS * DFA_MAX_RESOURCES must fit within sizeof DFAInput.
> +// This is verified in DFAPacketizer.cpp:DFAPacketizer::DFAPacketizer.
> +//
> +// e.g. terms x resource bit combinations that fit in uint32_t:
> +//      4 terms x 8  bits = 32 bits
> +//      3 terms x 10 bits = 30 bits
> +//      2 terms x 16 bits = 32 bits
> +//
> +// e.g. terms x resource bit combinations that fit in uint64_t:
> +//      8 terms x 8  bits = 64 bits
> +//      7 terms x 9  bits = 63 bits
> +//      6 terms x 10 bits = 60 bits
> +//      5 terms x 12 bits = 60 bits
> +//      4 terms x 16 bits = 64 bits <--- current
> +//      3 terms x 21 bits = 63 bits
> +//      2 terms x 32 bits = 64 bits
> +//
> +#define DFA_MAX_RESTERMS        4   // The max # of AND'ed resource terms.
> +#define DFA_MAX_RESOURCES       16  // The max # of resource bits in one
> term.
> +
> +typedef uint64_t                DFAInput;
> +typedef int64_t                 DFAStateInput;
> +#define DFA_TBLTYPE             "int64_t" // For generating
> DFAStateInputTable.
> +// --------------------------------------------------------------------
> +
>  class DFAPacketizer {
>  private:
>    typedef std::pair<unsigned, DFAInput> UnsignPair;
> @@ -69,9 +96,7 @@ public:
>    DFAInput getInsnInput(unsigned InsnClass);
>
>    // getInsnInput - Return the DFAInput for an instruction class input
> vector.
> -  static DFAInput getInsnInput(const std::vector<unsigned> &InsnClass) {
> -    return getDFAInsnInput(InsnClass);
> -  }
> +  static DFAInput getInsnInput(const std::vector<unsigned> &InsnClass);
>
>    // canReserveResources - Check if the resources occupied by a
> MCInstrDesc
>    // are available in the current state.
>
> Removed: llvm/trunk/include/llvm/CodeGen/DFAPacketizerDefs.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DFAPacketizerDefs.h?rev=253819&view=auto
>
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/DFAPacketizerDefs.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/DFAPacketizerDefs.h (removed)
> @@ -1,63 +0,0 @@
> -//=- llvm/CodeGen/DFAPacketizerDefs.h - DFA Packetizer for VLIW ---*- C++
> -*-=//
> -//
> -//                     The LLVM Compiler Infrastructure
> -//
> -// This file is distributed under the University of Illinois Open Source
> -// License. See LICENSE.TXT for details.
> -//
>
> -//===----------------------------------------------------------------------===//
> -// Common definitions used by TableGen and the DFAPacketizer in CodeGen.
>
> -//===----------------------------------------------------------------------===//
> -
> -#ifndef LLVM_CODEGEN_DFAPACKETIZERDEFS_H
> -#define LLVM_CODEGEN_DFAPACKETIZERDEFS_H
> -
> -#include <vector>
> -
> -namespace llvm {
> -
> -// DFA_MAX_RESTERMS * DFA_MAX_RESOURCES must fit within sizeof DFAInput.
> -// This is verified in DFAPacketizer.cpp:DFAPacketizer::DFAPacketizer.
> -//
> -// e.g. terms x resource bit combinations that fit in uint32_t:
> -//      4 terms x 8  bits = 32 bits
> -//      3 terms x 10 bits = 30 bits
> -//      2 terms x 16 bits = 32 bits
> -//
> -// e.g. terms x resource bit combinations that fit in uint64_t:
> -//      8 terms x 8  bits = 64 bits
> -//      7 terms x 9  bits = 63 bits
> -//      6 terms x 10 bits = 60 bits
> -//      5 terms x 12 bits = 60 bits
> -//      4 terms x 16 bits = 64 bits <--- current
> -//      3 terms x 21 bits = 63 bits
> -//      2 terms x 32 bits = 64 bits
> -//
> -#define DFA_MAX_RESTERMS        4   // The max # of AND'ed resource terms.
> -#define DFA_MAX_RESOURCES       16  // The max # of resource bits in one
> term.
> -
> -typedef uint64_t                DFAInput;
> -typedef int64_t                 DFAStateInput;
> -#define DFA_TBLTYPE             "int64_t" // For generating
> DFAStateInputTable.
> -
> -namespace {
> -  DFAInput addDFAFuncUnits(DFAInput Inp, unsigned FuncUnits) {
> -    return (Inp << DFA_MAX_RESOURCES) | FuncUnits;
> -  }
> -
> -  /// Return the DFAInput for an instruction class input vector.
> -  /// This function is used in both DFAPacketizer.cpp and in
> -  /// DFAPacketizerEmitter.cpp.
> -  DFAInput getDFAInsnInput(const std::vector<unsigned> &InsnClass) {
> -    DFAInput InsnInput = 0;
> -    assert ((InsnClass.size() <= DFA_MAX_RESTERMS) &&
> -            "Exceeded maximum number of DFA terms");
> -    for (auto U : InsnClass)
> -      InsnInput = addDFAFuncUnits(InsnInput, U);
> -    return InsnInput;
> -  }
> -}
> -
> -}
> -
> -#endif
>
> Modified: llvm/trunk/lib/CodeGen/DFAPacketizer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/DFAPacketizer.cpp?rev=253820&r1=253819&r2=253820&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/DFAPacketizer.cpp (original)
> +++ llvm/trunk/lib/CodeGen/DFAPacketizer.cpp Sun Nov 22 09:20:19 2015
> @@ -31,6 +31,28 @@
>  #include "llvm/Target/TargetInstrInfo.h"
>  using namespace llvm;
>
> +// --------------------------------------------------------------------
> +// Definitions shared between DFAPacketizer.cpp and
> DFAPacketizerEmitter.cpp
> +
> +namespace {
> +  DFAInput addDFAFuncUnits(DFAInput Inp, unsigned FuncUnits) {
> +    return (Inp << DFA_MAX_RESOURCES) | FuncUnits;
> +  }
> +
> +  /// Return the DFAInput for an instruction class input vector.
> +  /// This function is used in both DFAPacketizer.cpp and in
> +  /// DFAPacketizerEmitter.cpp.
> +  DFAInput getDFAInsnInput(const std::vector<unsigned> &InsnClass) {
> +    DFAInput InsnInput = 0;
> +    assert ((InsnClass.size() <= DFA_MAX_RESTERMS) &&
> +            "Exceeded maximum number of DFA terms");
> +    for (auto U : InsnClass)
> +      InsnInput = addDFAFuncUnits(InsnInput, U);
> +    return InsnInput;
> +  }
> +}
> +// --------------------------------------------------------------------
> +
>  DFAPacketizer::DFAPacketizer(const InstrItineraryData *I,
>                               const DFAStateInput (*SIT)[2],
>                               const unsigned *SET):
> @@ -82,6 +104,11 @@ DFAInput DFAPacketizer::getInsnInput(uns
>    return InsnInput;
>  }
>
> +// getInsnInput - Return the DFAInput for an instruction class input
> vector.
> +DFAInput DFAPacketizer::getInsnInput(const std::vector<unsigned>
> &InsnClass) {
> +  return getDFAInsnInput(InsnClass);
> +}
> +
>  // canReserveResources - Check if the resources occupied by a MCInstrDesc
>  // are available in the current state.
>  bool DFAPacketizer::canReserveResources(const llvm::MCInstrDesc *MID) {
>
> Modified: llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp?rev=253820&r1=253819&r2=253820&view=diff
>
> ==============================================================================
> --- llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp (original)
> +++ llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp Sun Nov 22 09:20:19
> 2015
> @@ -21,7 +21,6 @@
>  #include "llvm/ADT/DenseSet.h"
>  #include "llvm/ADT/STLExtras.h"
>  #include "llvm/ADT/StringExtras.h"
> -#include "llvm/CodeGen/DFAPacketizerDefs.h"
>  #include "llvm/TableGen/Record.h"
>  #include "llvm/TableGen/TableGenBackend.h"
>  #include "llvm/Support/Debug.h"
> @@ -31,6 +30,52 @@
>  #include <queue>
>  using namespace llvm;
>
> +// --------------------------------------------------------------------
> +// Definitions shared between DFAPacketizer.cpp and
> DFAPacketizerEmitter.cpp
> +
> +// DFA_MAX_RESTERMS * DFA_MAX_RESOURCES must fit within sizeof DFAInput.
> +// This is verified in DFAPacketizer.cpp:DFAPacketizer::DFAPacketizer.
> +//
> +// e.g. terms x resource bit combinations that fit in uint32_t:
> +//      4 terms x 8  bits = 32 bits
> +//      3 terms x 10 bits = 30 bits
> +//      2 terms x 16 bits = 32 bits
> +//
> +// e.g. terms x resource bit combinations that fit in uint64_t:
> +//      8 terms x 8  bits = 64 bits
> +//      7 terms x 9  bits = 63 bits
> +//      6 terms x 10 bits = 60 bits
> +//      5 terms x 12 bits = 60 bits
> +//      4 terms x 16 bits = 64 bits <--- current
> +//      3 terms x 21 bits = 63 bits
> +//      2 terms x 32 bits = 64 bits
> +//
> +#define DFA_MAX_RESTERMS        4   // The max # of AND'ed resource terms.
> +#define DFA_MAX_RESOURCES       16  // The max # of resource bits in one
> term.
> +
> +typedef uint64_t                DFAInput;
> +typedef int64_t                 DFAStateInput;
> +#define DFA_TBLTYPE             "int64_t" // For generating
> DFAStateInputTable.
> +
> +namespace {
> +  DFAInput addDFAFuncUnits(DFAInput Inp, unsigned FuncUnits) {
> +    return (Inp << DFA_MAX_RESOURCES) | FuncUnits;
> +  }
> +
> +  /// Return the DFAInput for an instruction class input vector.
> +  /// This function is used in both DFAPacketizer.cpp and in
> +  /// DFAPacketizerEmitter.cpp.
> +  DFAInput getDFAInsnInput(const std::vector<unsigned> &InsnClass) {
> +    DFAInput InsnInput = 0;
> +    assert ((InsnClass.size() <= DFA_MAX_RESTERMS) &&
> +            "Exceeded maximum number of DFA terms");
> +    for (auto U : InsnClass)
> +      InsnInput = addDFAFuncUnits(InsnInput, U);
> +    return InsnInput;
> +  }
> +}
> +// --------------------------------------------------------------------
> +
>  #ifndef NDEBUG
>  // To enable debugging, run llvm-tblgen with: "-debug-only dfa-emitter".
>  //
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151122/c80de378/attachment-0001.html>


More information about the llvm-commits mailing list