2009-06-02 17:52:33 +00:00
|
|
|
//===- CodeEmitterGen.cpp - Code Emitter Generator ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// CodeEmitterGen uses the descriptions of instructions and their fields to
|
|
|
|
// construct an automated code emitter: a function that, given a MachineInstr,
|
|
|
|
// returns the (currently, 32-bit unsigned) value of the instruction.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
#include "CodeGenInstruction.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include "CodeGenTarget.h"
|
2017-01-02 19:17:04 +00:00
|
|
|
#include "SubtargetFeatureInfo.h"
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2017-01-02 19:17:04 +00:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/TableGen/Record.h"
|
2012-08-15 19:34:23 +00:00
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
2017-01-02 19:17:04 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
2011-02-20 12:57:14 +00:00
|
|
|
#include <map>
|
2017-01-02 19:17:04 +00:00
|
|
|
#include <set>
|
2012-08-15 19:34:23 +00:00
|
|
|
#include <string>
|
2017-01-02 19:17:04 +00:00
|
|
|
#include <utility>
|
2012-08-15 19:34:23 +00:00
|
|
|
#include <vector>
|
2017-01-02 19:17:04 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class CodeEmitterGen {
|
|
|
|
RecordKeeper &Records;
|
2017-01-02 19:17:04 +00:00
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
public:
|
|
|
|
CodeEmitterGen(RecordKeeper &R) : Records(R) {}
|
|
|
|
|
|
|
|
void run(raw_ostream &o);
|
2017-01-02 19:17:04 +00:00
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
private:
|
|
|
|
int getVariableBit(const std::string &VarName, BitsInit *BI, int bit);
|
|
|
|
std::string getInstructionCase(Record *R, CodeGenTarget &Target);
|
|
|
|
void AddCodeToMergeInOperand(Record *R, BitsInit *BI,
|
|
|
|
const std::string &VarName,
|
|
|
|
unsigned &NumberedOp,
|
2014-11-24 09:08:18 +00:00
|
|
|
std::set<unsigned> &NamedOpIndices,
|
2012-08-15 19:34:23 +00:00
|
|
|
std::string &Case, CodeGenTarget &Target);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
// If the VarBitInit at position 'bit' matches the specified variable then
|
|
|
|
// return the variable bit position. Otherwise return -1.
|
2010-01-01 10:31:22 +00:00
|
|
|
int CodeEmitterGen::getVariableBit(const std::string &VarName,
|
2011-02-20 12:57:14 +00:00
|
|
|
BitsInit *BI, int bit) {
|
2012-12-02 13:10:19 +00:00
|
|
|
if (VarBitInit *VBI = dyn_cast<VarBitInit>(BI->getBit(bit))) {
|
|
|
|
if (VarInit *VI = dyn_cast<VarInit>(VBI->getBitVar()))
|
2011-02-20 12:57:14 +00:00
|
|
|
if (VI->getName() == VarName)
|
|
|
|
return VBI->getBitNum();
|
2012-12-02 13:10:19 +00:00
|
|
|
} else if (VarInit *VI = dyn_cast<VarInit>(BI->getBit(bit))) {
|
2011-05-02 19:34:44 +00:00
|
|
|
if (VI->getName() == VarName)
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-20 12:57:14 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeEmitterGen::
|
|
|
|
AddCodeToMergeInOperand(Record *R, BitsInit *BI, const std::string &VarName,
|
|
|
|
unsigned &NumberedOp,
|
2014-11-24 09:08:18 +00:00
|
|
|
std::set<unsigned> &NamedOpIndices,
|
2011-02-20 12:57:14 +00:00
|
|
|
std::string &Case, CodeGenTarget &Target) {
|
|
|
|
CodeGenInstruction &CGI = Target.getInstruction(R);
|
|
|
|
|
|
|
|
// Determine if VarName actually contributes to the Inst encoding.
|
|
|
|
int bit = BI->getNumBits()-1;
|
|
|
|
|
|
|
|
// Scan for a bit that this contributed to.
|
|
|
|
for (; bit >= 0; ) {
|
|
|
|
if (getVariableBit(VarName, BI, bit) != -1)
|
|
|
|
break;
|
2010-01-01 10:31:22 +00:00
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
--bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we found no bits, ignore this value, otherwise emit the call to get the
|
|
|
|
// operand encoding.
|
|
|
|
if (bit < 0) return;
|
|
|
|
|
|
|
|
// If the operand matches by name, reference according to that
|
|
|
|
// operand number. Non-matching operands are assumed to be in
|
|
|
|
// order.
|
|
|
|
unsigned OpIdx;
|
|
|
|
if (CGI.Operands.hasOperandNamed(VarName, OpIdx)) {
|
|
|
|
// Get the machine operand number for the indicated operand.
|
|
|
|
OpIdx = CGI.Operands[OpIdx].MIOperandNo;
|
|
|
|
assert(!CGI.Operands.isFlatOperandNotEmitted(OpIdx) &&
|
|
|
|
"Explicitly used operand also marked as not emitted!");
|
|
|
|
} else {
|
2012-12-02 13:10:19 +00:00
|
|
|
unsigned NumberOps = CGI.Operands.size();
|
2011-02-20 12:57:14 +00:00
|
|
|
/// If this operand is not supposed to be emitted by the
|
|
|
|
/// generated emitter, skip it.
|
2012-12-02 13:10:19 +00:00
|
|
|
while (NumberedOp < NumberOps &&
|
2014-11-24 09:08:18 +00:00
|
|
|
(CGI.Operands.isFlatOperandNotEmitted(NumberedOp) ||
|
2015-05-27 18:44:32 +00:00
|
|
|
(!NamedOpIndices.empty() && NamedOpIndices.count(
|
2014-11-24 09:08:18 +00:00
|
|
|
CGI.Operands.getSubOperandNumber(NumberedOp).first)))) {
|
2011-02-20 12:57:14 +00:00
|
|
|
++NumberedOp;
|
2012-12-02 13:10:19 +00:00
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
if (NumberedOp >= CGI.Operands.back().MIOperandNo +
|
|
|
|
CGI.Operands.back().MINumOperands) {
|
|
|
|
errs() << "Too few operands in record " << R->getName() <<
|
|
|
|
" (no match for variable " << VarName << "):\n";
|
|
|
|
errs() << *R;
|
|
|
|
errs() << '\n';
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
OpIdx = NumberedOp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<unsigned, unsigned> SO = CGI.Operands.getSubOperandNumber(OpIdx);
|
|
|
|
std::string &EncoderMethodName = CGI.Operands[SO.first].EncoderMethodName;
|
|
|
|
|
|
|
|
// If the source operand has a custom encoder, use it. This will
|
|
|
|
// get the encoding for all of the suboperands.
|
|
|
|
if (!EncoderMethodName.empty()) {
|
|
|
|
// A custom encoder has all of the information for the
|
|
|
|
// sub-operands, if there are more than one, so only
|
|
|
|
// query the encoder once per source operand.
|
|
|
|
if (SO.second == 0) {
|
|
|
|
Case += " // op: " + VarName + "\n" +
|
|
|
|
" op = " + EncoderMethodName + "(MI, " + utostr(OpIdx);
|
2015-01-18 16:17:27 +00:00
|
|
|
Case += ", Fixups, STI";
|
2011-02-20 12:57:14 +00:00
|
|
|
Case += ");\n";
|
2010-01-01 10:31:22 +00:00
|
|
|
}
|
2011-02-20 12:57:14 +00:00
|
|
|
} else {
|
|
|
|
Case += " // op: " + VarName + "\n" +
|
|
|
|
" op = getMachineOpValue(MI, MI.getOperand(" + utostr(OpIdx) + ")";
|
2015-01-18 16:17:27 +00:00
|
|
|
Case += ", Fixups, STI";
|
2011-02-20 12:57:14 +00:00
|
|
|
Case += ");\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
for (; bit >= 0; ) {
|
|
|
|
int varBit = getVariableBit(VarName, BI, bit);
|
|
|
|
|
|
|
|
// If this bit isn't from a variable, skip it.
|
|
|
|
if (varBit == -1) {
|
|
|
|
--bit;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Figure out the consecutive range of bits covered by this operand, in
|
|
|
|
// order to generate better encoding code.
|
|
|
|
int beginInstBit = bit;
|
|
|
|
int beginVarBit = varBit;
|
|
|
|
int N = 1;
|
|
|
|
for (--bit; bit >= 0;) {
|
|
|
|
varBit = getVariableBit(VarName, BI, bit);
|
|
|
|
if (varBit == -1 || varBit != (beginVarBit - N)) break;
|
|
|
|
++N;
|
|
|
|
--bit;
|
|
|
|
}
|
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
uint64_t opMask = ~(uint64_t)0 >> (64-N);
|
2011-02-20 12:57:14 +00:00
|
|
|
int opShift = beginVarBit - N + 1;
|
|
|
|
opMask <<= opShift;
|
|
|
|
opShift = beginInstBit - beginVarBit;
|
|
|
|
|
|
|
|
if (opShift > 0) {
|
2012-04-14 13:54:10 +00:00
|
|
|
Case += " Value |= (op & UINT64_C(" + utostr(opMask) + ")) << " +
|
2011-02-20 12:57:14 +00:00
|
|
|
itostr(opShift) + ";\n";
|
|
|
|
} else if (opShift < 0) {
|
2012-04-14 13:54:10 +00:00
|
|
|
Case += " Value |= (op & UINT64_C(" + utostr(opMask) + ")) >> " +
|
2011-02-20 12:57:14 +00:00
|
|
|
itostr(-opShift) + ";\n";
|
|
|
|
} else {
|
2012-04-14 13:54:10 +00:00
|
|
|
Case += " Value |= op & UINT64_C(" + utostr(opMask) + ");\n";
|
2011-02-20 12:57:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
std::string CodeEmitterGen::getInstructionCase(Record *R,
|
|
|
|
CodeGenTarget &Target) {
|
|
|
|
std::string Case;
|
|
|
|
|
|
|
|
BitsInit *BI = R->getValueAsBitsInit("Inst");
|
|
|
|
const std::vector<RecordVal> &Vals = R->getValues();
|
|
|
|
unsigned NumberedOp = 0;
|
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
std::set<unsigned> NamedOpIndices;
|
|
|
|
// Collect the set of operand indices that might correspond to named
|
|
|
|
// operand, and skip these when assigning operands based on position.
|
|
|
|
if (Target.getInstructionSet()->
|
|
|
|
getValueAsBit("noNamedPositionallyEncodedOperands")) {
|
|
|
|
CodeGenInstruction &CGI = Target.getInstruction(R);
|
|
|
|
for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
|
|
|
|
unsigned OpIdx;
|
|
|
|
if (!CGI.Operands.hasOperandNamed(Vals[i].getName(), OpIdx))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
NamedOpIndices.insert(OpIdx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
// Loop over all of the fields in the instruction, determining which are the
|
|
|
|
// operands to the instruction.
|
|
|
|
for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
|
|
|
|
// Ignore fixed fields in the record, we're looking for values like:
|
|
|
|
// bits<5> RST = { ?, ?, ?, ?, ? };
|
|
|
|
if (Vals[i].getPrefix() || Vals[i].getValue()->isComplete())
|
|
|
|
continue;
|
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
AddCodeToMergeInOperand(R, BI, Vals[i].getName(), NumberedOp,
|
|
|
|
NamedOpIndices, Case, Target);
|
2011-02-20 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string PostEmitter = R->getValueAsString("PostEncoderMethod");
|
2014-11-24 09:08:18 +00:00
|
|
|
if (!PostEmitter.empty()) {
|
|
|
|
Case += " Value = " + PostEmitter + "(MI, Value";
|
2015-01-18 16:17:27 +00:00
|
|
|
Case += ", STI";
|
2014-11-24 09:08:18 +00:00
|
|
|
Case += ");\n";
|
|
|
|
}
|
2011-02-20 12:57:14 +00:00
|
|
|
|
|
|
|
return Case;
|
|
|
|
}
|
|
|
|
|
2009-07-04 13:58:26 +00:00
|
|
|
void CodeEmitterGen::run(raw_ostream &o) {
|
2011-02-20 12:57:14 +00:00
|
|
|
CodeGenTarget Target(Records);
|
2009-06-02 17:52:33 +00:00
|
|
|
std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
|
2011-02-20 12:57:14 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
// For little-endian instruction bit encodings, reverse the bit order
|
2014-11-24 09:08:18 +00:00
|
|
|
Target.reverseBitsForLittleEndianEncoding();
|
2011-02-20 12:57:14 +00:00
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
ArrayRef<const CodeGenInstruction*> NumberedInstructions =
|
2010-03-21 10:49:05 +00:00
|
|
|
Target.getInstructionsByEnumValue();
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
// Emit function declaration
|
2012-04-14 13:54:10 +00:00
|
|
|
o << "uint64_t " << Target.getName();
|
2015-01-18 16:17:27 +00:00
|
|
|
o << "MCCodeEmitter::getBinaryCodeForInstr(const MCInst &MI,\n"
|
|
|
|
<< " SmallVectorImpl<MCFixup> &Fixups,\n"
|
|
|
|
<< " const MCSubtargetInfo &STI) const {\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
// Emit instruction base values
|
2012-04-14 13:54:10 +00:00
|
|
|
o << " static const uint64_t InstBits[] = {\n";
|
2016-07-23 20:41:05 +00:00
|
|
|
for (const CodeGenInstruction *CGI : NumberedInstructions) {
|
2009-06-02 17:52:33 +00:00
|
|
|
Record *R = CGI->TheDef;
|
2011-02-20 12:57:14 +00:00
|
|
|
|
2011-07-17 15:36:56 +00:00
|
|
|
if (R->getValueAsString("Namespace") == "TargetOpcode" ||
|
|
|
|
R->getValueAsBit("isPseudo")) {
|
2012-04-14 13:54:10 +00:00
|
|
|
o << " UINT64_C(0),\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-02-20 12:57:14 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
BitsInit *BI = R->getValueAsBitsInit("Inst");
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
// Start by filling in fixed values.
|
2012-04-14 13:54:10 +00:00
|
|
|
uint64_t Value = 0;
|
2009-06-02 17:52:33 +00:00
|
|
|
for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i) {
|
2012-12-02 13:10:19 +00:00
|
|
|
if (BitInit *B = dyn_cast<BitInit>(BI->getBit(e-i-1)))
|
2012-04-14 13:54:10 +00:00
|
|
|
Value |= (uint64_t)B->getValue() << (e-i-1);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2012-04-14 13:54:10 +00:00
|
|
|
o << " UINT64_C(" << Value << ")," << '\t' << "// " << R->getName() << "\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2012-04-14 13:54:10 +00:00
|
|
|
o << " UINT64_C(0)\n };\n";
|
2011-02-20 12:57:14 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
// Map to accumulate all the cases.
|
2017-01-02 19:17:04 +00:00
|
|
|
std::map<std::string, std::vector<std::string>> CaseMap;
|
2011-02-20 12:57:14 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
// Construct all cases statement for each opcode
|
|
|
|
for (std::vector<Record*>::iterator IC = Insts.begin(), EC = Insts.end();
|
|
|
|
IC != EC; ++IC) {
|
|
|
|
Record *R = *IC;
|
2011-07-17 15:36:56 +00:00
|
|
|
if (R->getValueAsString("Namespace") == "TargetOpcode" ||
|
|
|
|
R->getValueAsBit("isPseudo"))
|
2010-07-13 17:19:57 +00:00
|
|
|
continue;
|
2011-02-20 12:57:14 +00:00
|
|
|
const std::string &InstName = R->getValueAsString("Namespace") + "::"
|
2017-01-02 19:17:04 +00:00
|
|
|
+ R->getName().str();
|
2011-02-20 12:57:14 +00:00
|
|
|
std::string Case = getInstructionCase(R, Target);
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
CaseMap[Case].push_back(InstName);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Emit initial function code
|
|
|
|
o << " const unsigned opcode = MI.getOpcode();\n"
|
2012-04-14 13:54:10 +00:00
|
|
|
<< " uint64_t Value = InstBits[opcode];\n"
|
|
|
|
<< " uint64_t op = 0;\n"
|
2011-02-20 12:57:14 +00:00
|
|
|
<< " (void)op; // suppress warning\n"
|
2009-06-02 17:52:33 +00:00
|
|
|
<< " switch (opcode) {\n";
|
|
|
|
|
|
|
|
// Emit each case statement
|
2017-01-02 19:17:04 +00:00
|
|
|
std::map<std::string, std::vector<std::string>>::iterator IE, EE;
|
2009-06-02 17:52:33 +00:00
|
|
|
for (IE = CaseMap.begin(), EE = CaseMap.end(); IE != EE; ++IE) {
|
|
|
|
const std::string &Case = IE->first;
|
|
|
|
std::vector<std::string> &InstList = IE->second;
|
|
|
|
|
|
|
|
for (int i = 0, N = InstList.size(); i < N; i++) {
|
|
|
|
if (i) o << "\n";
|
2011-02-20 12:57:14 +00:00
|
|
|
o << " case " << InstList[i] << ":";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
o << " {\n";
|
|
|
|
o << Case;
|
|
|
|
o << " break;\n"
|
|
|
|
<< " }\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default case: unhandled opcode
|
|
|
|
o << " default:\n"
|
2009-10-14 17:57:32 +00:00
|
|
|
<< " std::string msg;\n"
|
|
|
|
<< " raw_string_ostream Msg(msg);\n"
|
|
|
|
<< " Msg << \"Not supported instr: \" << MI;\n"
|
2010-05-04 16:11:02 +00:00
|
|
|
<< " report_fatal_error(Msg.str());\n"
|
2009-06-02 17:52:33 +00:00
|
|
|
<< " }\n"
|
|
|
|
<< " return Value;\n"
|
|
|
|
<< "}\n\n";
|
2017-01-02 19:17:04 +00:00
|
|
|
|
|
|
|
const auto &All = SubtargetFeatureInfo::getAll(Records);
|
|
|
|
std::map<Record *, SubtargetFeatureInfo, LessRecordByID> SubtargetFeatures;
|
|
|
|
SubtargetFeatures.insert(All.begin(), All.end());
|
|
|
|
|
|
|
|
o << "#ifdef ENABLE_INSTR_PREDICATE_VERIFIER\n"
|
|
|
|
<< "#undef ENABLE_INSTR_PREDICATE_VERIFIER\n"
|
|
|
|
<< "#include <sstream>\n\n";
|
|
|
|
|
|
|
|
// Emit the subtarget feature enumeration.
|
|
|
|
SubtargetFeatureInfo::emitSubtargetFeatureFlagEnumeration(SubtargetFeatures,
|
|
|
|
o);
|
|
|
|
|
|
|
|
// Emit the name table for error messages.
|
|
|
|
o << "#ifndef NDEBUG\n";
|
|
|
|
SubtargetFeatureInfo::emitNameTable(SubtargetFeatures, o);
|
|
|
|
o << "#endif // NDEBUG\n";
|
|
|
|
|
|
|
|
// Emit the available features compute function.
|
|
|
|
SubtargetFeatureInfo::emitComputeAvailableFeatures(
|
|
|
|
Target.getName(), "MCCodeEmitter", "computeAvailableFeatures",
|
|
|
|
SubtargetFeatures, o);
|
|
|
|
|
|
|
|
// Emit the predicate verifier.
|
|
|
|
o << "void " << Target.getName()
|
|
|
|
<< "MCCodeEmitter::verifyInstructionPredicates(\n"
|
|
|
|
<< " const MCInst &Inst, uint64_t AvailableFeatures) const {\n"
|
|
|
|
<< "#ifndef NDEBUG\n"
|
|
|
|
<< " static uint64_t RequiredFeatures[] = {\n";
|
|
|
|
unsigned InstIdx = 0;
|
|
|
|
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
|
|
|
|
o << " ";
|
|
|
|
for (Record *Predicate : Inst->TheDef->getValueAsListOfDefs("Predicates")) {
|
|
|
|
const auto &I = SubtargetFeatures.find(Predicate);
|
|
|
|
if (I != SubtargetFeatures.end())
|
|
|
|
o << I->second.getEnumName() << " | ";
|
|
|
|
}
|
|
|
|
o << "0, // " << Inst->TheDef->getName() << " = " << InstIdx << "\n";
|
|
|
|
InstIdx++;
|
|
|
|
}
|
|
|
|
o << " };\n\n";
|
|
|
|
o << " assert(Inst.getOpcode() < " << InstIdx << ");\n";
|
|
|
|
o << " uint64_t MissingFeatures =\n"
|
|
|
|
<< " (AvailableFeatures & RequiredFeatures[Inst.getOpcode()]) ^\n"
|
|
|
|
<< " RequiredFeatures[Inst.getOpcode()];\n"
|
|
|
|
<< " if (MissingFeatures) {\n"
|
|
|
|
<< " std::ostringstream Msg;\n"
|
|
|
|
<< " Msg << \"Attempting to emit \" << "
|
|
|
|
"MCII.getName(Inst.getOpcode()).str()\n"
|
|
|
|
<< " << \" instruction but the \";\n"
|
|
|
|
<< " for (unsigned i = 0; i < 8 * sizeof(MissingFeatures); ++i)\n"
|
|
|
|
<< " if (MissingFeatures & (1ULL << i))\n"
|
|
|
|
<< " Msg << SubtargetFeatureNames[i] << \" \";\n"
|
|
|
|
<< " Msg << \"predicate(s) are not met\";\n"
|
|
|
|
<< " report_fatal_error(Msg.str());\n"
|
|
|
|
<< " }\n"
|
|
|
|
<< "#else\n"
|
|
|
|
<< "// Silence unused variable warning on targets that don't use MCII for "
|
|
|
|
"other purposes (e.g. BPF).\n"
|
|
|
|
<< "(void)MCII;\n"
|
|
|
|
<< "#endif // NDEBUG\n";
|
|
|
|
o << "}\n";
|
|
|
|
o << "#endif\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
} // end anonymous namespace
|
2012-08-15 19:34:23 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
void EmitCodeEmitter(RecordKeeper &RK, raw_ostream &OS) {
|
|
|
|
emitSourceFileHeader("Machine Code Emitter", OS);
|
|
|
|
CodeEmitterGen(RK).run(OS);
|
|
|
|
}
|
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
} // end namespace llvm
|