Guide for adding a new IR instruction to the Hermes compiler. Use when the user asks to add, create, or define a new IR instruction (Inst/Instruction) in the Hermes intermediate representation. Covers all required files and the patterns for each.
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "add-ir-instruction" 技能: 1. 下载 https://raw.githubusercontent.com/facebook/hermes/static_h/.claude/skills/add-ir-instruction/SKILL.md 2. 保存为 ~/.claude/skills/add-ir-instruction/SKILL.md 3. 装好后重载技能,告诉我可以用了
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;
}
…
帮助开发者编写和审查符合 Hermes VM 垃圾回收安全规范的 C++ 代码
分析 hermesvm 在一段提交范围内的二进制体积变化与回归原因
指导在 JSI Runtime 层新增方法与功能,并同步 Hermes 与 SynthTrace 支持。
无需交互式编辑器,程序化重排、拆分、删除或修订任意 Git 历史提交。
帮助排查常见故障、版本兼容与会话流诊断问题,提升开发调试效率
帮助开发者完成 Meta AI 应用注册与设备权限接入流程配置。