NuPlusTargetLowering class

From NaplesPU Documentation
Revision as of 16:32, 17 October 2017 by Catello (talk | contribs)
Jump to: navigation, search

The NuPlusTargetLowering class implements the TargetLowering interface and is contained in the NuPlusISelLowering.h/.cpp files. The class must describe how to lower LLVM code to machine code. This has two main components:

  1. Which ValueTypes are natively supported by the target.
  2. Which operations are supported for supported ValueTypes.

The NuPlusTargetLowering class can be thought of being composed by four sections:

  1. The class constructor.
  2. The custom SDNode lowering.
  3. The custom MachineInstruction insertion.
  4. The implementation of other TargetLowering virtual methods.

The Class Constructor

The NuPlusTargetLowering class constructor describes the MachineValueTypes supported by nu+ with the corresponding RegisterClass, the operations not supported for supported MachineValueTypes and the corresponding action to perform, other useful information concerning the Instruction-Lowering phase. These informations are described using the protected methods provided by the base class TargetLowering.

addRegisterClass

The addRegisterClass method tells the CodeGenerator the supported MachineValueTypes and the RegisterClass to use. The MachineValueTypes are defined in the MVT class in "compiler/include/llvm/CodeGen/MachineValueType.h", while the RegisterClass are those defined in NuPLusRegisterInfo.td. The following table summarize the supported MachineValueTypes and the relative RegisterClass.

RegisterClass MVT
GPR32RegClass i32, f32
GPR64RegClass i64, f64
VR512WRegClass v16i32, v16f32
VR512LRegClass v8i64, v8f64

The corresponding code is:


  // Scalar data types
  addRegisterClass(MVT::i32, &NuPlus::GPR32RegClass);
  addRegisterClass(MVT::f32, &NuPlus::GPR32RegClass);

  addRegisterClass(MVT::i64, &NuPlus::GPR64RegClass);
  addRegisterClass(MVT::f64, &NuPlus::GPR64RegClass);

  // Vector data types (512-bit wide)
  addRegisterClass(MVT::v16i32, &NuPlus::VR512WRegClass);
  addRegisterClass(MVT::v16f32, &NuPlus::VR512WRegClass);

  addRegisterClass(MVT::v8i64, &NuPlus::VR512LRegClass);
  addRegisterClass(MVT::v8f64, &NuPlus::VR512LRegClass);


setOperationAction

The setOperationAction method is used to tell the CodeGenerator the unsupported operation for the specified MachineValueType and the action to perform, this because by default every operation is considered Legal.

This information is used by the LLVM CodeGenerator during the InstructionSelection phase. So the input to give the function are the Operation Code (defined in the NodeType enum in "/compiler/include/llvm/CodeGen/ISDOpcodes.h"), the associated MachineValueTypes and the action to perform in order to legalize the operation. At this stage each operation is described by a Node in the SelectionDAG.

The action must be one of those in the LegalizeAction enum contained in the TargetLoweringBase class (/compiler/include/llvm/Target/TargetLowering.h). Hence the possible actions are:

  • Legal, the target natively supports this operation.
  • Promote, this operation should be executed in a larger type.
  • Expand, try to expand this to other ops, otherwise use a libcall.
  • LibCall, don't try to expand this to other ops, always use a libcall.
  • Custom, use the LowerOperation hook to implement custom lowering.

The most used in the nu++ backend are the Expand and the Custom actions. As mentioned before, the Expand action tries to expand the node using equivalent operations, if this cannot be done, a function call is generated. The signature is defined in the InitLibcallNames in "/compiler/lib/CodeGen/TargetLoweringBase.cpp". With the Custom action, the lowering must be manually done implementing a proper function.

Custom Lowering

Custom MachineInstruction Insertion

Other Methods