Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ORC] FastISel and ORCv2/LLJIT #70666

Closed
wjakob opened this issue Oct 30, 2023 · 4 comments · Fixed by #70806
Closed

[ORC] FastISel and ORCv2/LLJIT #70666

wjakob opened this issue Oct 30, 2023 · 4 comments · Fixed by #70806
Assignees
Labels
enhancement Improving things as opposed to bug fixing, e.g. new or missing feature llvm:as-a-library LLVM-C and C++ API orcjit

Comments

@wjakob
Copy link
Contributor

wjakob commented Oct 30, 2023

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.

@EugeneZelenko EugeneZelenko added question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! orcjit and removed new issue labels Oct 30, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 30, 2023

@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
Copy link
Member

dtcxzyw commented Oct 31, 2023

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
Copy link
Contributor Author

wjakob commented Oct 31, 2023

That would be wonderful ❤️

@dtcxzyw dtcxzyw added enhancement Improving things as opposed to bug fixing, e.g. new or missing feature llvm:as-a-library LLVM-C and C++ API and removed question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! labels Oct 31, 2023
@dtcxzyw dtcxzyw self-assigned this Oct 31, 2023
@dtcxzyw
Copy link
Member

dtcxzyw commented Oct 31, 2023

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);

dtcxzyw added a commit that referenced this issue Nov 1, 2023
This PR exposes four APIs to C/OCaml bindings for `TargetMachine`:
```
/** 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);
```

Fixes #70666.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving things as opposed to bug fixing, e.g. new or missing feature llvm:as-a-library LLVM-C and C++ API orcjit
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants