globalisel
play

GlobalISel LLVMs Latest Instruction Selection Framework Diana Picu - PowerPoint PPT Presentation

GlobalISel LLVMs Latest Instruction Selection Framework Diana Picu Instruction Selection Target-independent IR ISel Machine-dependent IR 2 Instruction Selection define i32 @add(i32 %a, i32 %b) { entry: LLVM IR %add = add nsw i32 %b,


  1. GlobalISel LLVM’s Latest Instruction Selection Framework Diana Picuş

  2. Instruction Selection Target-independent IR ISel Machine-dependent IR 2

  3. Instruction Selection define i32 @add(i32 %a, i32 %b) { entry: LLVM IR %add = add nsw i32 %b, %a ret i32 %add } ISel Machine-dependent IR 3

  4. Instruction Selection define i32 @add(i32 %a, i32 %b) { entry: LLVM IR %add = add nsw i32 %b, %a ret i32 %add } ISel name: add registers: - { id: 0, class: gpr32 } - { id: 1, class: gpr32 } - { id: 2, class: gpr32 } body: | MachineInstr bb.0.entry: liveins: %w0, %w1 (MIR) %0 = COPY %w0 %1 = COPY %w1 %2 = ADDWrr %1, %0 %w0 = COPY %2 RET_ReallyLR implicit %w0 4

  5. Instruction Selection LLVM IR ● Static Single Assignment ISel name: add registers: - { id: 0, class: gpr32 } - { id: 1, class: gpr32 } - { id: 2, class: gpr32 } body: | MachineInstr bb.0.entry: liveins: %w0, %w1 %0 = COPY %w0 %1 = COPY %w1 %2 = ADDWrr %1, %0 %w0 = COPY %2 RET_ReallyLR implicit %w0 5

  6. Instruction Selection LLVM IR ● Static Single Assignment ● Virtual registers ISel name: add registers: - { id: 0, class: gpr32 } - { id: 1, class: gpr32 } - { id: 2, class: gpr32 } body: | MachineInstr bb.0.entry: liveins: %w0, %w1 %0 = COPY %w0 %1 = COPY %w1 %2 = ADDWrr %1, %0 %w0 = COPY %2 RET_ReallyLR implicit %w0 6

  7. Instruction Selection LLVM IR ● Static Single Assignment ● Virtual registers ● Pseudoinstructions ISel name: add registers: - { id: 0, class: gpr32 } - { id: 1, class: gpr32 } - { id: 2, class: gpr32 } body: | MachineInstr bb.0.entry: liveins: %w0, %w1 %0 = COPY %w0 %1 = COPY %w1 %2 = ADDWrr %1, %0 %w0 = COPY %2 RET_ReallyLR implicit %w0 7

  8. Currently in LLVM LLVM IR DAGISel MachineInstr 8

  9. Currently in LLVM LLVM IR DAGISel Build SelectionDAG DAG combine Legalize types More DAG combine Legalize vectors Legalize types More DAG combine MachineInstr Legalize (operations) More DAG combine Select instructions Schedule instructions Emit MachineInstr 9

  10. Currently in LLVM LLVM IR DAGISel MachineInstr 10

  11. Currently in LLVM LLVM IR DAGISel FastISel MachineInstr 11

  12. In the Making LLVM IR GlobalISel MachineInstr 12

  13. In the Making LLVM IR MachineInstr GlobalISel + Register banks + Generic instructions MachineInstr 13

  14. In the Making LLVM IR MachineInstr GlobalISel => Machine Passes MachineInstr 14

  15. The GlobalISel Pipeline LLVM IR IRTranslator Legalizer RegBankSelect InstructionSelect MachineInstr 15

  16. IRTranslator LLVM IR IRTranslator Generic MachineInstr G_ADD G_LOAD G_ANYEXT G_FRAME_INDEX G_CONSTANT G_BRCOND G_INTRINSIC G_FADD ... 16

  17. IRTranslator Final goal of IRTranslator output instruction selection (Generic MIR): (MIR): name: add name: add registers: registers: - { id: 0, class: _ } - { id: 0, class: gpr32 } - { id: 1, class: _ } - { id: 1, class: gpr32 } - { id: 2, class: _ } - { id: 2, class: gpr32 } body: | body: | bb.1.entry: bb.0.entry: liveins: %w0, %w1 liveins: %w0, %w1 %0(s32) = COPY %w0 %0 = COPY %w0 %1(s32) = COPY %w1 %1 = COPY %w1 %2(s32) = G_ADD %1, %0 %2 = ADDWrr %1, %0 %w0 = COPY %2(s32) %w0 = COPY %2 RET_ReallyLR implicit %w0 RET_ReallyLR implicit %w0 17

  18. IRTranslator Final goal of IRTranslator output instruction selection (Generic MIR): (MIR): name: add name: add registers: registers: - { id: 0, class: _ } - { id: 0, class: gpr32 } - { id: 1, class: _ } - { id: 1, class: gpr32 } - { id: 2, class: _ } - { id: 2, class: gpr32 } body: | body: | bb.1.entry: bb.0.entry: liveins: %w0, %w1 liveins: %w0, %w1 %0(s32) = COPY %w0 %0 = COPY %w0 %1(s32) = COPY %w1 %1 = COPY %w1 %2(s32) = G_ADD %1, %0 %2 = ADDWrr %1, %0 %w0 = COPY %2(s32) %w0 = COPY %2 RET_ReallyLR implicit %w0 RET_ReallyLR implicit %w0 18

  19. IRTranslator Final goal of IRTranslator output instruction selection (Generic MIR): (MIR): name: add name: add registers: registers: - { id: 0, class: _ } - { id: 0, class: gpr32 } - { id: 1, class: _ } - { id: 1, class: gpr32 } - { id: 2, class: _ } - { id: 2, class: gpr32 } body: | body: | bb.1.entry: bb.0.entry: liveins: %w0, %w1 liveins: %w0, %w1 %0(s32) = COPY %w0 %0 = COPY %w0 %1(s32) = COPY %w1 %1 = COPY %w1 %2(s32) = G_ADD %1, %0 %2 = ADDWrr %1, %0 %w0 = COPY %2(s32) %w0 = COPY %2 RET_ReallyLR implicit %w0 RET_ReallyLR implicit %w0 Scalar sN (number of bits) Pointer pN (address space) Vector M x sN (lanes x number of bits) 19

  20. IRTranslator Final goal of IRTranslator output instruction selection (Generic MIR): (MIR): name: add name: add registers: registers: - { id: 0, class: _ } - { id: 0, class: gpr32 } - { id: 1, class: _ } - { id: 1, class: gpr32 } - { id: 2, class: _ } - { id: 2, class: gpr32 } body: | body: | bb.1.entry: bb.0.entry: liveins: %w0, %w1 liveins: %w0, %w1 %0(s32) = COPY %w0 %0 = COPY %w0 %1(s32) = COPY %w1 %1 = COPY %w1 %2(s32) = G_ADD %1, %0 %2 = ADDWrr %1, %0 %w0 = COPY %2(s32) %w0 = COPY %2 RET_ReallyLR implicit %w0 RET_ReallyLR implicit %w0 20

  21. IRTranslator Final goal of IRTranslator output instruction selection (Generic MIR): (MIR): name: add name: add registers: registers: - { id: 0, class: _ } - { id: 0, class: gpr32 } - { id: 1, class: _ } - { id: 1, class: gpr32 } - { id: 2, class: _ } - { id: 2, class: gpr32 } body: | body: | bb.1.entry: bb.0.entry: liveins: %w0, %w1 liveins: %w0, %w1 %0(s32) = COPY %w0 %0 = COPY %w0 %1(s32) = COPY %w1 %1 = COPY %w1 %2(s32) = G_ADD %1, %0 %2 = ADDWrr %1, %0 %w0 = COPY %2(s32) %w0 = COPY %2 RET_ReallyLR implicit %w0 RET_ReallyLR implicit %w0 21

  22. Legalizer LLVM IR (operation, type) ● Legal IRTranslator ● NarrowScalar ● WidenScalar ● FewerElements Legalizer ● MoreElements ● Lower ● Libcall ● Custom Generic MachineInstr ● Unsupported 22

  23. Register Bank Selection LLVM IR X0, W0 X1, W1 IRTranslator ... GPR X30, W30 Legalizer Q0, D0, S0, H0, B0 RegBankSelect Q1, D1, S1, H1, B1 ... FPR Q31, D31, S31, H31, B31 Generic MachineInstr 23

  24. Instruction Selection LLVM IR IRTranslator Legalizer RegBankSelect InstructionSelect MachineInstr 24

  25. Instruction Selection Before instruction After instruction selection: selection: name: add name: add registers: registers: - { id: 0, class: gpr } - { id: 0, class: gpr32 } - { id: 1, class: gpr } - { id: 1, class: gpr32 } - { id: 2, class: gpr } - { id: 2, class: gpr32 } body: | body: | bb.1.entry: bb.0.entry: liveins: %w0, %w1 liveins: %w0, %w1 %0(s32) = COPY %w0 %0 = COPY %w0 %1(s32) = COPY %w1 %1 = COPY %w1 %2(s32) = G_ADD %1, %0 %2 = ADDWrr %1, %0 %w0 = COPY %2(s32) %w0 = COPY %2 RET_ReallyLR implicit %w0 RET_ReallyLR implicit %w0 25

  26. Instruction Selection Before instruction After instruction selection: selection: name: add name: add registers: registers: - { id: 0, class: gpr } - { id: 0, class: gpr32 } - { id: 1, class: gpr } - { id: 1, class: gpr32 } - { id: 2, class: gpr } - { id: 2, class: gpr32 } body: | body: | bb.1.entry: bb.0.entry: liveins: %w0, %w1 liveins: %w0, %w1 %0(s32) = COPY %w0 %0 = COPY %w0 %1(s32) = COPY %w1 %1 = COPY %w1 %2(s32) = G_ADD %1, %0 %2 = ADDWrr %1, %0 %w0 = COPY %2(s32) %w0 = COPY %2 RET_ReallyLR implicit %w0 RET_ReallyLR implicit %w0 26

  27. Instruction Selection Before instruction After instruction selection: selection: name: add name: add registers: registers: - { id: 0, class: gpr } - { id: 0, class: gpr32 } - { id: 1, class: gpr } - { id: 1, class: gpr32 } - { id: 2, class: gpr } - { id: 2, class: gpr32 } body: | body: | bb.1.entry: bb.0.entry: liveins: %w0, %w1 liveins: %w0, %w1 %0(s32) = COPY %w0 %0 = COPY %w0 %1(s32) = COPY %w1 %1 = COPY %w1 %2(s32) = G_ADD %1, %0 %2 = ADDWrr %1, %0 %w0 = COPY %2(s32) %w0 = COPY %2 RET_ReallyLR implicit %w0 RET_ReallyLR implicit %w0 27

  28. Instruction Selection name: add registers: - { id: 0, class: gpr32 } - { id: 1, class: gpr32 } - { id: 2, class: gpr32 } Backend body: | bb.0.entry: liveins: %w0, %w1 Passes %0 = COPY %w0 %1 = COPY %w1 %2 = ADDWrr %1, %0 %w0 = COPY %2 RET_ReallyLR implicit %w0 28

  29. Current Status ● Prototype, disabled by default llc -global-isel [...] clang -mllvm -global-isel [...] llc -global-isel -global-isel-abort=0 [...] 29

  30. Current Status ● Work in progress: Improving the framework (e.g. TableGen) /// General Purpose Registers: W, X. def GPRRegBank : RegisterBank<"GPR", [GPR64all]>; /// Floating Point/Vector Registers: B, H, S, D, Q. def FPRRegBank : RegisterBank<"FPR", [QQQQ]>; /// Conditional register: NZCV. def CCRRegBank : RegisterBank<"CCR", [CCR]>; 30

More recommend