From f8d7eda663f32f1defed69a46782d3547a2b6620 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 25 Mar 2010 18:52:01 +0000 Subject: [PATCH] Teach TableGen to understand X.Y notation in the TSFlagsFields strings. Remove much horribleness from X86InstrFormats as a result. Similar simplifications are probably possible for other targets. llvm-svn: 99539 --- llvm/lib/Target/X86/X86.td | 6 +++--- llvm/lib/Target/X86/X86InstrFormats.td | 9 +++------ llvm/lib/Target/X86/X86InstrInfo.td | 2 +- llvm/utils/TableGen/InstrInfoEmitter.cpp | 2 +- llvm/utils/TableGen/Record.cpp | 10 ++++++++++ llvm/utils/TableGen/Record.h | 3 +++ 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Target/X86/X86.td b/llvm/lib/Target/X86/X86.td index 5788e2a71f64..b0847a854361 100644 --- a/llvm/lib/Target/X86/X86.td +++ b/llvm/lib/Target/X86/X86.td @@ -160,11 +160,11 @@ def X86InstrInfo : InstrInfo { "hasAdSizePrefix", "Prefix", "hasREX_WPrefix", - "ImmTypeBits", - "FPFormBits", + "ImmT.Value", + "FPForm.Value", "hasLockPrefix", "SegOvrBits", - "DomainBits", + "ExeDomain.Value", "Opcode"]; let TSFlagsShifts = [0, 6, diff --git a/llvm/lib/Target/X86/X86InstrFormats.td b/llvm/lib/Target/X86/X86InstrFormats.td index a811638c39ef..31dc5956e86c 100644 --- a/llvm/lib/Target/X86/X86InstrFormats.td +++ b/llvm/lib/Target/X86/X86InstrFormats.td @@ -111,7 +111,6 @@ class X86Inst opcod, Format f, ImmType i, dag outs, dag ins, Format Form = f; bits<6> FormBits = Form.Value; ImmType ImmT = i; - bits<3> ImmTypeBits = ImmT.Value; dag OutOperandList = outs; dag InOperandList = ins; @@ -125,12 +124,10 @@ class X86Inst opcod, Format f, ImmType i, dag outs, dag ins, bits<4> Prefix = 0; // Which prefix byte does this inst have? bit hasREX_WPrefix = 0; // Does this inst requires the REX.W prefix? - FPFormat FPForm; // What flavor of FP instruction is this? - bits<3> FPFormBits = 0; + FPFormat FPForm = NotFP; // What flavor of FP instruction is this? bit hasLockPrefix = 0; // Does this inst have a 0xF0 prefix? bits<2> SegOvrBits = 0; // Segment override prefix. - Domain Dom = d; - bits<2> DomainBits = Dom.Value; + Domain ExeDomain = d; } class I o, Format f, dag outs, dag ins, string asm, @@ -179,7 +176,7 @@ class FPI o, Format F, dag outs, dag ins, string asm> // FpI_ - Floating Point Psuedo Instruction template. Not Predicated. class FpI_ pattern> : X86Inst<0, Pseudo, NoImm, outs, ins, ""> { - let FPForm = fp; let FPFormBits = FPForm.Value; + let FPForm = fp; let Pattern = pattern; } diff --git a/llvm/lib/Target/X86/X86InstrInfo.td b/llvm/lib/Target/X86/X86InstrInfo.td index 67d935a669cd..a029a24f8b63 100644 --- a/llvm/lib/Target/X86/X86InstrInfo.td +++ b/llvm/lib/Target/X86/X86InstrInfo.td @@ -587,7 +587,7 @@ let neverHasSideEffects = 1, isNotDuplicable = 1, Uses = [ESP] in // Return instructions. let isTerminator = 1, isReturn = 1, isBarrier = 1, - hasCtrlDep = 1, FPForm = SpecialFP, FPFormBits = SpecialFP.Value in { + hasCtrlDep = 1, FPForm = SpecialFP in { def RET : I <0xC3, RawFrm, (outs), (ins variable_ops), "ret", [(X86retflag 0)]>; diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp index 8f7550b84810..9bc545928d9b 100644 --- a/llvm/utils/TableGen/InstrInfoEmitter.cpp +++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp @@ -337,7 +337,7 @@ void InstrInfoEmitter::emitShiftedValue(Record *R, StringInit *Val, IntInit *ShiftInt, raw_ostream &OS) { if (Val == 0 || ShiftInt == 0) throw std::string("Illegal value or shift amount in TargetInfo*!"); - RecordVal *RV = R->getValue(Val->getValue()); + RecordVal *RV = R->getDottedValue(Val->getValue()); int Shift = ShiftInt->getValue(); if (RV == 0 || RV->getValue() == 0) { diff --git a/llvm/utils/TableGen/Record.cpp b/llvm/utils/TableGen/Record.cpp index 0e3593b6a11f..55c998926c0a 100644 --- a/llvm/utils/TableGen/Record.cpp +++ b/llvm/utils/TableGen/Record.cpp @@ -1307,6 +1307,16 @@ void Record::resolveReferencesTo(const RecordVal *RV) { } } +RecordVal *Record::getDottedValue(StringRef Name) { + size_t pos = Name.find('.'); + if (pos == StringRef::npos) + return getValue(Name); + RecordVal *RV = getValue(Name.substr(0, pos)); + if (!RV) return 0; + DefInit *DI = dynamic_cast(RV->getValue()); + if (!DI) return 0; + return DI->getDef()->getDottedValue(Name.substr(pos+1)); +} void Record::dump() const { errs() << *this; } diff --git a/llvm/utils/TableGen/Record.h b/llvm/utils/TableGen/Record.h index 55c1a80f9b6a..41373c799a0d 100644 --- a/llvm/utils/TableGen/Record.h +++ b/llvm/utils/TableGen/Record.h @@ -1262,6 +1262,9 @@ public: return 0; } + // Like getValue, but allow dotting into members: X.Y + RecordVal *getDottedValue(StringRef Name); + void addTemplateArg(StringRef Name) { assert(!isTemplateArg(Name) && "Template arg already defined!"); TemplateArgs.push_back(Name);