I'm trying to learn LLVM tablegen. http://llvm.org/docs/TableGen/LangRef.html shows that field keyword exists but doesn't explain its meaning. Does anybody know what it means?
I found the following code in a tutorial
class Cpu0Reg<string n> : Register<n> {
field bits<4> Num;
let Namespace = "Cpu0";
}
Can I do the following instead (notice the field keyword is missing)
class Cpu0Reg<string n> : Register<n> {
bits<4> Num;
let Namespace = "Cpu0";
}
Later in the tutorial I found this code (notice the bits<20> addr, it doesn't have field keyword in front of it):
class FMem<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern,
InstrItinClass itin>: FL<op, outs, ins, asmstr, pattern, itin> {
bits<20> addr;
let Inst{19-16} = addr{19-16};
let Inst{15-0} = addr{15-0};
let DecoderMethod = "DecodeMem";
}
So what is the difference between field bits<n> and bits<n> and what does field keyword do?
Any help is appreciated.
As far as I can tell, it does nothing, unless you use positionally-encoded operands (which you should not be using).
Follow me as I go code diving:
https://github.com/llvm-mirror/llvm/blob/8ff4fe417f7993462cf4e16a0eb43b09bc26ad36/lib/TableGen/TGParser.cpp#L1707
This comment on line 1691 suggests that the field is optional.
/// Declaration ::= FIELD? Type ID ('=' Value)?
Note that the purpose of these lines is to simply remove the field token if it exists.
// Read the field prefix if present.
bool HasField = Lex.getCode() == tgtok::Field;
if (HasField) Lex.Lex();
The presence of field is also noted in the variable HasField, which is passed into the constructor of RecordVal on line 1722.
RecordVal::RecordVal(StringRef N, RecTy *T, bool P)
: Name(StringInit::get(N)), TyAndPrefix(T, P) {
Value = UnsetInit::get()->convertInitializerTo(T);
assert(Value && "Cannot create unset value for current type!");
}
https://github.com/llvm-mirror/llvm/blob/8ff4fe417f7993462cf4e16a0eb43b09bc26ad36/lib/TableGen/Record.cpp#L1583
RecordVal initializes TyAndPrefix, a pair of (type, bool). The bool stores whether the field prefix was used in the declaration. The presence of field is queried using RecordVal::getPrefix.
https://github.com/llvm-mirror/llvm/search?utf8=%E2%9C%93&q=getPrefix+path%3Autils%2FTableGen+path%3Alib%2FTableGen&type=Code
This search turns up no uses, apart from the presence of field inhibiting processing of positionally-encoded operands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With