global instruction selection
play

Global Instruction Selection A Proposal Quentin Colombet Apple - PowerPoint PPT Presentation

Global Instruction Selection A Proposal Quentin Colombet Apple What Is Instruction Selection? Translation from target independent intermediate representation (IR) to target specific IR. LLVM IR -> MachineInstr 2 SelectionDAG (SD) ISel


  1. Global Instruction Selection A Proposal Quentin Colombet Apple

  2. What Is Instruction Selection? Translation from target independent intermediate representation (IR) to target specific IR. LLVM IR -> MachineInstr 2

  3. SelectionDAG (SD) ISel LLVM IR FastPath GoodPath SDBuilder FastISel Fail SDNode Hooks DAGCombiner Target Legalize* DAGCombiner Select Schedule MachineInstr 3

  4. SelectionDAG (SD) ISel LLVM IR FastPath GoodPath SDBuilder FastISel Fail SDNode Hooks DAGCombiner Target Legalize* DAGCombiner Select LLVM IR (-> SDNode) -> MachineInstr Schedule MachineInstr 3

  5. Problems with SDISel • Basic block scope • SDNode IR, specific to instruction selection • Monolithic 4

  6. Goals • Global • Fast • Shared code for fast and good paths • IR that represents ISA concepts better • More flexible pipeline • Easier to maintain/understand • Self contained representation • No change to LLVM IR 5

  7. Non-Goals for the Prototype • Reuse of InstCombine • Improve TableGen • Support target specific features 6

  8. Why Not Fix SDISel? • Hard limitations of the underlying representation • Would introduce SDNode IR to optimizers • SDNode IR can be avoided • Inherent overhead 7

  9. Global ISel

  10. LLVM IR 9

  11. LLVM IR IRTranslator 9

  12. IRTranslator define double @foo(double %val, double* %addr) { %intval = bitcast double %val to i64 %loaded = load double, double* %addr %mask = bitcast double %loaded to i64 %and = and i64 %intval, %mask %res = bitcast i64 %and to double ret double %res } • LLVM IR to generic (G) MachineInstr 10

  13. IRTranslator define double @foo(double %val, foo: double* %addr) { val = VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr = COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask R0,R1 = VMOVRRD and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res } • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • Virtual registers have a size • ABI lowering 10

  14. IRTranslator define double @foo(double %val, foo: double* %addr) { val = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr = … COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask R0,R1 = VMOVRRD and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res } • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • Virtual registers have a size • ABI lowering 10

  15. IRTranslator define double @foo(double %val, foo: double* %addr) { val = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr = … COPY R2 %loaded = load double, double* %addr loaded = gLD addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask R0,R1 = VMOVRRD and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res } • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • Virtual registers have a size • ABI lowering 10

  16. IRTranslator define double @foo(double %val, foo: double* %addr) { val = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr = … COPY R2 %loaded = load double, double* %addr loaded = gLD addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask R0,R1 = VMOVRRD and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res }q • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type New • Virtual registers get a size • ABI lowering 10

  17. IRTranslator define double @foo(double %val, foo: double* %addr) { val = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr = … COPY R2 %loaded = load double, double* %addr loaded = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask R0,R1 = VMOVRRD and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res }q • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type N EW • Virtual registers get a size New • ABI lowering 10

  18. IRTranslator define double @foo(double %val, foo: double* %addr) { val = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr = … COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask R0,R1 = VMOVRRD and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res }q • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type N EW • Virtual registers get a size N EW • ABI lowering 10

  19. IRTranslator define double @foo(double %val, foo: double* %addr) { val(64) = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr(32) = … COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask R0,R1 = VMOVRRD and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res }q • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type N EW • Virtual registers get a size N EW • ABI lowering 10

  20. IRTranslator define double @foo(double %val, foo: double* %addr) { val(64) = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr(32) = … COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask R0,R1 = VMOVRRD and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res } • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type N EW • Virtual registers get a size N EW • ABI lowering 10

  21. IRTranslator define double @foo(double %val, foo: double* %addr) { val(64) = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr(32) = … COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask R0,R1 = VMOVRRD and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res } • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type N EW • Virtual registers get a size N EW • ABI lowering 10

  22. IRTranslator define double @foo(double %val, foo: double* %addr) { val(64) = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr(32) = … COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask = and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res } • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type N EW • Virtual registers get a size N EW • ABI lowering 10

  23. IRTranslator define double @foo(double %val, foo: double* %addr) { val(64) = … VMOVDRR R0,R1 %intval = bitcast double %val to i64 addr(32) = … COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask … = and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res } • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type N EW • Virtual registers get a size N EW • ABI lowering 10

  24. IRTranslator define double @foo(double %val, foo: double* %addr) { val(64) = … R0,R1 %intval = bitcast double %val to i64 addr(32) = … COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask … = and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res }q • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type N EW • Virtual registers get a size N EW • ABI lowering 10

  25. IRTranslator define double @foo(double %val, foo: double* %addr) { val(64) = … R0,R1 %intval = bitcast double %val to i64 addr(32) = … COPY R2 %loaded = load double, double* %addr loaded(64) = gLD (double) addr %mask = bitcast double %loaded to i64 and(64) = gAND (i64) val, loaded %and = and i64 %intval, %mask … = and %res = bitcast i64 %and to double tBX_RET R0<imp-use>,R1<imp-use> ret double %res }q • LLVM IR to generic (G) MachineInstr • One IR instruction to 0..* (G) MachineInstr • MachineInstrs get a type N EW • Virtual registers get a size N EW • ABI lowering 10

Recommend


More recommend