class Instruction : InstructionEncoding {
…
// Code size, for instruction selection.
// FIXME: What does this actually mean?
int CodeSize = 0;
…
}
This CodeSize is used in X86/AArch64 backends and is poorly documented. I’m a beginner in LLVM, and can’t find much information about this. Like when and where to use this CodeSize, what’s the difference setting it to 1/2/3, and why this is not in definition of MCInstrDesc, and how can I even reference it?
It is not the answer you are looking for, but whenever there is something undocumented that you cannot find how it works, you can find occurences of the symbol within the source code. I recommend using an IDE for that (although it is just a simple text matching, it is easier to browse the results). I personally use VSCode
A quick search of “CodeSize” in “match whole word” and “match case” got me a bunch of unwanted results, and one that might be the one you want:
/// getResultPatternCodeSize - Compute the code size of instructions for this
/// pattern.
static unsigned getResultPatternSize(TreePatternNode *P,
CodeGenDAGPatterns &CGP) {
if (P->isLeaf()) return 0;
unsigned Cost = 0;
Record *Op = P->getOperator();
if (Op->isSubClassOf("Instruction")) {
Cost += Op->getValueAsInt("CodeSize");
}
for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
Cost += getResultPatternSize(P->getChild(i), CGP);
return Cost;
}
(in DAGISelEmitter.cpp)
To further figure out how this is used (e.g. what is Cost exactly?), you need to find where getResultPatternSize is used and what does it decide.
Much thanks! (Actually I just watched your presentation about your backend on youtube!)
I did searched for the code and probably missed this result, because there’re too many occurrence and some of them is a bool type which confused me.
Anyway thanks! I thought this CodeSize will be processed in TableGen sources so I did not dig into iseldag too much.