Guides adding a new IR instruction to the Hermes compiler correctly.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "add-ir-instruction" skill from askskill: 1. Download https://raw.githubusercontent.com/facebook/hermes/static_h/.claude/skills/add-ir-instruction/SKILL.md 2. Save it as ~/.claude/skills/add-ir-instruction/SKILL.md 3. Reload skills and tell me it's ready
Guide me to add a new IR instruction named MyNewInst in Hermes. List the files I need to modify in the right order and explain what to change in each one.
A step-by-step checklist covering docs, instruction registration, class definition, builder, verifier, type inference, backend codegen, and tests.
My new Hermes IR instruction does not map directly to bytecode. Tell me which Lowering-related files I must update to declare, implement, and register the pass.
An additional Lowering file checklist, plus instructions for registering the pass in the HBC and SH pipelines.
Based on the Hermes new IR instruction workflow, help me check whether my changes are missing verifier logic, type inference, codegen stubs, or tests.
A file-by-file review result that highlights common omissions and where they should be added.
When a developer introduces a new intermediate representation instruction in Hermes, this skill helps confirm the required source files, coding patterns, and integration order to reduce missed changes.
When a new instruction needs more than just declaration, this skill serves as a checklist for verifier, type inference, and backend code generation stubs or implementations.
If the new instruction cannot map directly to bytecode, this skill points to the extra Lowering declaration, implementation, and HBC/SH pipeline registration updates required.
The document explains the full set of files involved when adding a new IR instruction to the Hermes compiler. It walks through documentation in IR.md, instruction registration, class definition, builder declaration and implementation, verifier logic, type inference, backend codegen, and tests. For instructions that do not map directly to bytecode, it also covers Lowering declarations, implementation, and pass registration in the HBC and SH pipelines.
When adding a new IR instruction, you must touch a specific set of files. This skill describes each file, the pattern to follow, and important conventions.
doc/IR.md — Documentation (the only place for doc-comments)include/hermes/IR/Instrs.def — Instruction registrationinclude/hermes/IR/Instrs.h — Class definition (NO doc-comments here)include/hermes/IR/IRBuilder.h — Builder declarationlib/IR/IRBuilder.cpp — Builder implementationlib/IR/IRVerifier.cpp — Verification logiclib/Optimizer/Scalar/TypeInference.cpp — Type inference stublib/BCGen/HBC/ISel.cpp — HBC instruction selection (stub or implementation)lib/BCGen/SH/SH.cpp — Static Hermes codegen (stub or implementation)lib/BCGen/facebook/Mins/Mins.cpp — Mins codegen (stub or implementation)test/If the instruction needs lowering (i.e., it does not map directly to a bytecode opcode), you also need:
include/hermes/BCGen/Lowering.h — Lowering pass declarationlib/BCGen/Lowering.cpp — Lowering pass implementationlib/BCGen/HBC/LoweringPipelines.cpp — Register pass in HBC pipelinelib/BCGen/SH/SH.cpp (in lowerModuleIR) — Register pass in SH pipelinedoc/IR.mdThis is the ONLY place to put documentation for the instruction. Do NOT add
doc-comments to Instrs.h.
Add a markdown table entry in the appropriate section:
### MyNewInst
MyNewInst | _
--- | --- |
Description | Brief description of what the instruction does.
Example | `MyNewInst %arg1, %arg2 : type`
Arguments | *%arg1* is ... *%arg2* is ...
Semantics | Describe the semantics, referencing the spec where appropriate.
Effects | Describe side effects (e.g., "May read and write memory.", "May read memory and throw.", "Does not read or write memory.").
Instrs.defAdd a DEF_VALUE entry. Place it near related instructions:
DEF_VALUE(MyNewInst, Instruction)
If it's a subclass of another instruction, use the parent as the second argument.
If it's a terminator, use TERMINATOR instead of DEF_VALUE.
Instrs.hDo NOT add doc-comments to this file. Documentation belongs in doc/IR.md.
Follow this exact pattern:
class MyNewInst : public Instruction {
MyNewInst(const MyNewInst &) = delete;
void operator=(const MyNewInst &) = delete;
public:
enum { Arg1Idx, Arg2Idx };
explicit MyNewInst(Value *arg1, Value *arg2)
: Instruction(ValueKind::MyNewInstKind) {
// Optional assertions on operand types:
// assert(arg2->getType().isSomeType() && "message");
// Set the result type:
setType(Type::createNoType()); // for instructions with no output
// or: setType(Type::createFoo()); for typed instructions
pushOperand(arg1);
pushOperand(arg2);
}
explicit MyNewInst(
const MyNewInst *src,
llvh::ArrayRef<Value *> operands)
: Instruction(src, operands) {}
Value *getArg1() const {
return getOperand(Arg1Idx);
}
Value *getArg2() const {
return getOperand(Arg2Idx);
}
static bool hasOutput() {
return false; // true if the instruction produces a value
}
static bool isTyped() {
return false; // true if the output type is meaningful
}
SideEffect getSideEffectImpl() const {
// Compose side effects. Common patterns:
// return {}; // pure
// return SideEffect{}.setReadHeap(); // reads memory
// return SideEffect{}.setReadHeap().setWriteHeap(); // reads+writes
// return SideEffect{}.setThrow().setReadHeap(); // may throw + read
return SideEffect{}.setThrow().setReadHeap();
}
static bool classof(const Value *V) {
ValueKind kind = V->getKind();
return kind == ValueKind::MyNewInstKind;
}
…
It guides adding a new IR instruction to the Hermes compiler by listing the required files, the pattern for each, and how to wire in lowering and tests when needed.
The excerpt lists core files including doc/IR.md, Instrs.def, Instrs.h, IRBuilder.h, IRBuilder.cpp, IRVerifier.cpp, TypeInference.cpp, multiple codegen files, and test/. If the instruction requires lowering, additional Lowering declaration, implementation, and pipeline registration files are also needed.
According to the excerpt, instruction documentation belongs in doc/IR.md, and doc-comments should not be added to Instrs.h.
Programmatically rewrite non-top Git commits without needing an interactive editor.
Write and review GC-safe C++ code for the Hermes VM runtime.
Analyze hermesvm binary size changes and regressions across commit ranges.
Add new JSI Runtime features with Hermes and SynthTrace support.
Fix lint, formatting, and common code issues before passing CI.
Run Flow type checks and fix React type errors quickly.