hbarve1/tessl-llvm/add-calling-convention
Claude Code and agent skill by hbarve1/tessl-llvm
- community
Checking that the SKILL.md file is still in the repository.
Add or wire a calling convention in an LLVM 22 in-tree target or document IR-level ABI choices for out-of-tree frontends. Covers CallingConv IDs, TableGen CallingConv.td, CCState/CCValAssign hooks, ISel lowering, and tests.
Install
npx vskill@latest install hbarve1/tessl-llvm/add-calling-conventionSKILL.md
The same SKILL.md was published earlier as hbarve1/tessl-llvm/add-calling-convention.
Skill: Add a Custom Calling Convention (LLVM 22)
Use this skill when the user needs a new or customized ABI for a target inside the LLVM tree, or when an out-of-tree frontend must choose among existing conventions and attributes.
Scope boundary: Truly new register/stack rules require target TableGen + lowering changes inside LLVM. Out-of-tree projects that only consume an installed LLVM should not expect to add a global CallingConv::ID without rebuilding LLVM.
Step 0 — Classify the request
| Goal | Where to work | |
|---|---|---|
| Use standard C/fast call on existing target | IR only: setCallingConv, parameter attributes | |
| Language needs special struct return / copies | sret, byval, inalloca, alignment attrs | |
| New register/stack layout for a target | In-tree: CallingConv.h, *CallingConv.td, *ISelLowering.cpp | |
| Document/embedder custom protocol | Often metadata + existing CC, or a dedicated in-tree target fork |
Read calling-conventions.md for terminology (CCState, CCValAssign, related IR features).
Step 1 — IR-level wiring (all projects)
- Pick an existing
llvm::CallingConv::IDthat matches the platform (usuallyCorFast). - On each
llvm::Functionand onCallInst/InvokeInst, callsetCallingConv. - Add parameter/return attributes (
sret,byval,nest,swiftself, etc.) per LangRef. - Run
verifyModuleand compile withllc(or your driver) for the intended triple.
If this satisfies the ABI, stop—no TableGen work needed.
Step 2 — Reserve a CallingConv ID (in-tree only)
- Open
llvm/include/llvm/IR/CallingConv.h. - Add a new enumerator in the correct numeric range for your class of conventions (follow comments in that file; avoid reserved values).
- If the convention is user-visible in IR text, update LangRef (
LangRef.rst) with the spelling and number. - Rebuild; fix any
switch (CC)exhaustiveness warnings in tree.
Step 3 — Target TableGen (*CallingConv.td)
- Locate the target’s calling-convention definitions, e.g.
llvm/lib/Target/X86/X86CallingConv.td(pattern:Target/*/*CallingConv.td). - Add a
def/multiclassinstance for your convention that hooks CCAssignFn-style logic the same way sibling conventions do. - Regenerate TableGen outputs via CMake (
cmake --build --target <Target>CommonTableGenor full target build)—never hand-edit*Gen*.inc.
If you are unsure which multiclass to extend, clone the closest existing convention (e.g. a variant of Fast) and adjust register/stack rules incrementally.
Step 4 — ISel lowering (C++)
In the target’s *ISelLowering.cpp (and related files):
- `LowerFormalArguments` — handle the new
CallingConvwhen assigning incoming values toSDValues / registers. - `LowerCall` / `LowerCallTo` — match outgoing call setup (caller-side).
- `CanLowerReturn` / `LowerReturn` — return-value rules (registers, sret, multiple values).
Use CCState / CCValAssign consistently with the TableGen side. Mismatches here cause silent ABI bugs.
Search the target for getCallingConv() / callconv dispatch to find existing patterns.
Step 5 — Frontend (optional)
If Clang (or another frontend) must expose the convention:
- Add an attribute or calling-convention keyword in the frontend.
- Map it to
setCallingConvon the IR function and calls. - Add semantic checks (e.g. incompatible with varargs).
Step 6 — Tests
- IR test —
.llshowingcall/definewith the newccnumber or name (as printed by LLVM). - Assembly or MIR test — show expected registers/stack for a minimal function (one or two args + return).
- Negative test — invalid combination of CC + attributes if the verifier should reject it.
Run llvm-lit on the new files.
Step 7 — Review checklist
Out-of-tree summary
You cannot complete Steps 2–4 from a standalone plugin; they live in the LLVM target sources. Out-of-tree frontends should:
- Use existing
CallingConvvalues and attributes, and/or - Vendor a patched LLVM with the new convention if the ABI is non-standard.
Common mistakes
- Do NOT change only the IR
ccwithout matching backend assignment logic. - Do NOT reuse a reserved calling-convention number.
- Do NOT edit generated TableGen inc files manually.
- ALWAYS test varargs and sret/byval interactions for your CC.
See also
- calling-conventions.md
- codegen.md
- tablegen.md
- add-intrinsic — if the ABI also needs a new intrinsic
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingtiles/tessl-llvm/skills/add-calling-convention/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hbarve1/tessl-llvm/add-calling-convention)