diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2018-01-24 22:35:11 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2018-01-24 22:35:11 +0000 |
| commit | 4890a71f021fa521163d45f8e8af5d9e1fa6f34f (patch) | |
| tree | 1d58f2e0d31ef3e295534fdbe995321a3811b512 /llvm/utils | |
| parent | 0c352b15d78e7fe2eff1d22799411f9be05b5ff2 (diff) | |
| download | bcm5719-llvm-4890a71f021fa521163d45f8e8af5d9e1fa6f34f.tar.gz bcm5719-llvm-4890a71f021fa521163d45f8e8af5d9e1fa6f34f.zip | |
[TableGen] Add a way of getting the number of generic opcodes without including modular CodeGen headers.
This is a bit of a hack, but removes a cycle that broke modular builds
of LLVM. Of course the cycle is still there in form of a dependency
on the .def file.
llvm-svn: 323383
Diffstat (limited to 'llvm/utils')
| -rw-r--r-- | llvm/utils/TableGen/CodeGenSchedule.cpp | 9 | ||||
| -rw-r--r-- | llvm/utils/TableGen/CodeGenTarget.cpp | 15 | ||||
| -rw-r--r-- | llvm/utils/TableGen/CodeGenTarget.h | 3 |
3 files changed, 18 insertions, 9 deletions
diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp index 93409104313..076b891f91f 100644 --- a/llvm/utils/TableGen/CodeGenSchedule.cpp +++ b/llvm/utils/TableGen/CodeGenSchedule.cpp @@ -19,7 +19,6 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/CodeGen/TargetOpcodes.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Regex.h" @@ -104,9 +103,10 @@ struct InstRegexOp : public SetTheory::Operator { RegexList.push_back(std::make_pair(Prefix, Regex(pat))); } for (auto &R : RegexList) { + unsigned NumGeneric = Target.getNumFixedInstructions(); // The generic opcodes are unsorted, handle them manually. - for (auto *Inst : Target.getInstructionsByEnumValue().slice( - 0, TargetOpcode::GENERIC_OP_END + 1)) { + for (auto *Inst : + Target.getInstructionsByEnumValue().slice(0, NumGeneric + 1)) { if (Inst->TheDef->getName().startswith(R.first) && (!R.second || R.second->match(Inst->TheDef->getName().substr(R.first.size())))) @@ -114,8 +114,7 @@ struct InstRegexOp : public SetTheory::Operator { } ArrayRef<const CodeGenInstruction *> Instructions = - Target.getInstructionsByEnumValue().slice( - TargetOpcode::GENERIC_OP_END + 1); + Target.getInstructionsByEnumValue().slice(NumGeneric + 1); // Target instructions are sorted. Find the range that starts with our // prefix. diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp index 168bd690831..2f1f20d4772 100644 --- a/llvm/utils/TableGen/CodeGenTarget.cpp +++ b/llvm/utils/TableGen/CodeGenTarget.cpp @@ -345,13 +345,18 @@ GetInstByName(const char *Name, return I->second.get(); } +static const char *const FixedInstrs[] = { +#define HANDLE_TARGET_OPCODE(OPC) #OPC, +#include "llvm/CodeGen/TargetOpcodes.def" + nullptr}; + +unsigned CodeGenTarget::getNumFixedInstructions() { + return array_lengthof(FixedInstrs) - 1; +} + /// \brief Return all of the instructions defined by the target, ordered by /// their enum value. void CodeGenTarget::ComputeInstrsByEnum() const { - static const char *const FixedInstrs[] = { -#define HANDLE_TARGET_OPCODE(OPC) #OPC, -#include "llvm/CodeGen/TargetOpcodes.def" - nullptr}; const auto &Insts = getInstructions(); for (const char *const *p = FixedInstrs; *p; ++p) { const CodeGenInstruction *Instr = GetInstByName(*p, Insts, Records); @@ -360,6 +365,8 @@ void CodeGenTarget::ComputeInstrsByEnum() const { InstrsByEnum.push_back(Instr); } unsigned EndOfPredefines = InstrsByEnum.size(); + assert(EndOfPredefines == getNumFixedInstructions() && + "Missing generic opcode"); for (const auto &I : Insts) { const CodeGenInstruction *CGI = I.second.get(); diff --git a/llvm/utils/TableGen/CodeGenTarget.h b/llvm/utils/TableGen/CodeGenTarget.h index 7280d707fba..4d5a0ed685c 100644 --- a/llvm/utils/TableGen/CodeGenTarget.h +++ b/llvm/utils/TableGen/CodeGenTarget.h @@ -140,6 +140,9 @@ public: return *I->second; } + /// Returns the number of predefined instructions. + static unsigned getNumFixedInstructions(); + /// getInstructionsByEnumValue - Return all of the instructions defined by the /// target, ordered by their enum value. ArrayRef<const CodeGenInstruction *> |

