llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.13k stars 12.02k forks source link

[ORC] FastISel and ORCv2/LLJIT #70666

Closed wjakob closed 1 year ago

wjakob commented 1 year ago

Dear LLVM team,

a while back, I ported an application from MCJIT to ORCv2/LLJIT (using the C bindings). One feature that was lost during this rewrite was the ability to control the method used to perform instruction selection. The MCJIT interface exposed this through a convenient parameter:

struct LLVMMCJITCompilerOptions {
 ...
  LLVMBool EnableFastISel;
};

but no such thing exists for ORCv2/LLJIT (that I am aware of..).

Thus, I was wondering if there is any way to enable/disable FastISel for ORCv2/LLJIT, either using the C API or via annotations in the generated LLVM IR? I'd be really grateful for feedback from somebody familiar with this part of LLVM (@lhames?)

PS: I saw that the TargetMachine C++ API has a setFastISel() method, but it is likewise not exposed through the C-level LLVMCreateTargetMachine call.

llvmbot commented 1 year ago

@llvm/issue-subscribers-orcjit

Author: Wenzel Jakob (wjakob)

Dear LLVM team, a while back, I ported an application from MCJIT to ORCv2/LLJIT (using the C bindings). One feature that was lost during this rewrite was the ability to control the method used to perform instruction selection. The MCJIT interface exposed this through a convenient parameter: ``` struct LLVMMCJITCompilerOptions { ... LLVMBool EnableFastISel; }; ``` but no such thing exists for ORCv2/LLJIT (that I am aware of..). Thus, I was wondering if there is any way to enable/disable `FastISel` for ORCv2/LLJIT, either using the C API or via annotations in the generated LLVM IR? I'd be really grateful for feedback from somebody familiar with this part of LLVM (@lhames?) PS: I saw that the `TargetMachine` C++ API has a `setFastISel()` method, but it is likewise not exposed through the C-level `LLVMCreateTargetMachine` call.
dtcxzyw commented 1 year ago

We can expose some frequently used APIs for TargetMachine to the C-level.

typedef enum {
    LLVMGlobalISelAbortDisable,
    LLVMGlobalISelAbortEnable,
    LLVMGlobalISelAbortDisableWithDiag,
} LLVMGlobalISelAbortMode;
void LLVMSetTargetMachineFastISel(LLVMTargetMachineRef T, LLVMBool Enable);
void LLVMSetTargetMachineO0WantsFastISel(LLVMTargetMachineRef T, LLVMBool Enable);
void LLVMSetTargetMachineGlobalISel(LLVMTargetMachineRef T, LLVMBool Enable);
void LLVMSetTargetMachineGlobalISelAbort(LLVMTargetMachineRef T, LLVMGlobalISelAbortMode Mode);
void LLVMSetTargetMachineMachineOutliner(LLVMTargetMachineRef T, LLVMBool Enable);
void LLVMSetTargetMachineSupportsDefaultOutlining(LLVMTargetMachineRef T, LLVMBool Enable);
void LLVMSetTargetMachineSupportsDebugEntryValues(LLVMTargetMachineRef T, LLVMBool Enable);
void LLVMSetTargetMachineCFIFixup(LLVMTargetMachineRef T, LLVMBool Enable);
wjakob commented 1 year ago

That would be wonderful ❤️

dtcxzyw commented 1 year ago

Apologize for my misunderstanding. Some APIs/flags are designed to be used by targets instead of JIT users. I think exposing the following APIs makes sense.

/** Enable fast-path instruction selection. */
void LLVMSetTargetMachineFastISel(LLVMTargetMachineRef T, LLVMBool Enable);

/** Enable global instruction selection. */
void LLVMSetTargetMachineGlobalISel(LLVMTargetMachineRef T, LLVMBool Enable);

/** Set abort behaviour when global instruction selection fails to lower/select an instruction. */
void LLVMSetTargetMachineGlobalISelAbort(LLVMTargetMachineRef T, LLVMGlobalISelAbortMode Mode);

/** Enable the MachineOutliner pass. */
void LLVMSetTargetMachineMachineOutliner(LLVMTargetMachineRef T, LLVMBool Enable);