//
//===----------------------------------------------------------------------===//
-#define DEBUG_TYPE "decoder-emitter"
-
#include "CodeGenTarget.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
-#include "llvm/TableGen/TableGenBackend.h"
#include <map>
#include <string>
#include <vector>
using namespace llvm;
+#define DEBUG_TYPE "decoder-emitter"
+
namespace {
struct EncodingField {
unsigned Base, Width, Offset;
std::vector<unsigned> VariableInstructions;
// Map of well-known segment value to its delegate.
- std::map<unsigned, const FilterChooser*> FilterChooserMap;
+ std::map<unsigned, std::unique_ptr<const FilterChooser>> FilterChooserMap;
// Number of instructions which fall under FilteredInstructions category.
unsigned NumFiltered;
return *(FilterChooserMap.find((unsigned)-1)->second);
}
- Filter(const Filter &f);
+ Filter(Filter &&f);
Filter(FilterChooser &owner, unsigned startBit, unsigned numBits, bool mixed);
~Filter();
// Parent emitter
const FixedLenDecoderEmitter *Emitter;
+ FilterChooser(const FilterChooser &) LLVM_DELETED_FUNCTION;
+ void operator=(const FilterChooser &) LLVM_DELETED_FUNCTION;
public:
- FilterChooser(const FilterChooser &FC)
- : AllInstructions(FC.AllInstructions), Opcodes(FC.Opcodes),
- Operands(FC.Operands), Filters(FC.Filters),
- FilterBitValues(FC.FilterBitValues), Parent(FC.Parent),
- BestIndex(FC.BestIndex), BitWidth(FC.BitWidth),
- Emitter(FC.Emitter) { }
FilterChooser(const std::vector<const CodeGenInstruction*> &Insts,
const std::vector<unsigned> &IDs,
unsigned BW,
const FixedLenDecoderEmitter *E)
: AllInstructions(Insts), Opcodes(IDs), Operands(Ops), Filters(),
- Parent(NULL), BestIndex(-1), BitWidth(BW), Emitter(E) {
+ Parent(nullptr), BestIndex(-1), BitWidth(BW), Emitter(E) {
for (unsigned i = 0; i < BitWidth; ++i)
FilterBitValues.push_back(BIT_UNFILTERED);
// //
///////////////////////////
-Filter::Filter(const Filter &f)
+Filter::Filter(Filter &&f)
: Owner(f.Owner), StartBit(f.StartBit), NumBits(f.NumBits), Mixed(f.Mixed),
- FilteredInstructions(f.FilteredInstructions),
- VariableInstructions(f.VariableInstructions),
- FilterChooserMap(f.FilterChooserMap), NumFiltered(f.NumFiltered),
+ FilteredInstructions(std::move(f.FilteredInstructions)),
+ VariableInstructions(std::move(f.VariableInstructions)),
+ FilterChooserMap(std::move(f.FilterChooserMap)), NumFiltered(f.NumFiltered),
LastOpcFiltered(f.LastOpcFiltered) {
}
}
Filter::~Filter() {
- std::map<unsigned, const FilterChooser*>::iterator filterIterator;
- for (filterIterator = FilterChooserMap.begin();
- filterIterator != FilterChooserMap.end();
- filterIterator++) {
- delete filterIterator->second;
- }
}
// Divides the decoding task into sub tasks and delegates them to the
// Delegates to an inferior filter chooser for further processing on this
// group of instructions whose segment values are variable.
- FilterChooserMap.insert(std::pair<unsigned, const FilterChooser*>(
- (unsigned)-1,
- new FilterChooser(Owner->AllInstructions,
- VariableInstructions,
- Owner->Operands,
- BitValueArray,
- *Owner)
- ));
+ FilterChooserMap.insert(
+ std::make_pair(-1U, llvm::make_unique<FilterChooser>(
+ Owner->AllInstructions, VariableInstructions,
+ Owner->Operands, BitValueArray, *Owner)));
}
// No need to recurse for a singleton filtered instruction.
// Delegates to an inferior filter chooser for further processing on this
// category of instructions.
- FilterChooserMap.insert(std::pair<unsigned, const FilterChooser*>(
- mapIterator->first,
- new FilterChooser(Owner->AllInstructions,
- mapIterator->second,
- Owner->Operands,
- BitValueArray,
- *Owner)
- ));
+ FilterChooserMap.insert(std::make_pair(
+ mapIterator->first, llvm::make_unique<FilterChooser>(
+ Owner->AllInstructions, mapIterator->second,
+ Owner->Operands, BitValueArray, *Owner)));
}
}
// A new filter entry begins a new scope for fixup resolution.
TableInfo.FixupStack.push_back(FixupList());
- std::map<unsigned, const FilterChooser*>::const_iterator filterIterator;
+ std::map<unsigned,
+ std::unique_ptr<const FilterChooser>>::const_iterator filterIterator;
DecoderTable &Table = TableInfo.Table;
void FilterChooser::runSingleFilter(unsigned startBit, unsigned numBit,
bool mixed) {
Filters.clear();
- Filter F(*this, startBit, numBit, true);
- Filters.push_back(F);
+ Filters.push_back(Filter(*this, startBit, numBit, true));
BestIndex = 0; // Sole Filter instance to choose from.
bestFilter().recurse();
}
const std::vector<RecordVal> &Vals = Def.getValues();
unsigned NumberedOp = 0;
+ std::set<unsigned> NamedOpIndices;
+ if (Target.getInstructionSet()->
+ getValueAsBit("noNamedPositionallyEncodedOperands"))
+ // Collect the set of operand indices that might correspond to named
+ // operand, and skip these when assigning operands based on position.
+ for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
+ unsigned OpIdx;
+ if (!CGI.Operands.hasOperandNamed(Vals[i].getName(), OpIdx))
+ continue;
+
+ NamedOpIndices.insert(OpIdx);
+ }
+
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 = { ?, ?, ?, ?, ? };
// Determine if Vals[i] actually contributes to the Inst encoding.
unsigned bi = 0;
for (; bi < Bits.getNumBits(); ++bi) {
- VarInit *Var = 0;
+ VarInit *Var = nullptr;
VarBitInit *BI = dyn_cast<VarBitInit>(Bits.getBit(bi));
if (BI)
Var = dyn_cast<VarInit>(BI->getBitVar());
// Get the bit range for this operand:
unsigned bitStart = bi++, bitWidth = 1;
for (; bi < Bits.getNumBits(); ++bi) {
- VarInit *Var = 0;
+ VarInit *Var = nullptr;
VarBitInit *BI = dyn_cast<VarBitInit>(Bits.getBit(bi));
if (BI)
Var = dyn_cast<VarInit>(BI->getBitVar());
unsigned NumberOps = CGI.Operands.size();
while (NumberedOp < NumberOps &&
- CGI.Operands.isFlatOperandNotEmitted(NumberedOp))
+ (CGI.Operands.isFlatOperandNotEmitted(NumberedOp) ||
+ (NamedOpIndices.size() && NamedOpIndices.count(
+ CGI.Operands.getSubOperandNumber(NumberedOp).first))))
++NumberedOp;
OpIdx = NumberedOp++;
RecordVal *DecoderString = TypeRecord->getValue("DecoderMethod");
StringInit *String = DecoderString ?
- dyn_cast<StringInit>(DecoderString->getValue()) : 0;
+ dyn_cast<StringInit>(DecoderString->getValue()) : nullptr;
if (String && String->getValue() != "")
Decoder = String->getValue();
DecoderString = TypeRecord->getValue("DecoderMethod");
String = DecoderString ?
- dyn_cast<StringInit>(DecoderString->getValue()) : 0;
+ dyn_cast<StringInit>(DecoderString->getValue()) : nullptr;
if (!isReg && String && String->getValue() != "")
Decoder = String->getValue();
RecordVal *DecoderString = TypeRecord->getValue("DecoderMethod");
StringInit *String = DecoderString ?
- dyn_cast<StringInit>(DecoderString->getValue()) : 0;
+ dyn_cast<StringInit>(DecoderString->getValue()) : nullptr;
if (!isReg && String && String->getValue() != "")
Decoder = String->getValue();
unsigned Offset = 0;
for (unsigned bi = 0; bi < Bits.getNumBits(); ++bi) {
- VarInit *Var = 0;
+ VarInit *Var = nullptr;
VarBitInit *BI = dyn_cast<VarBitInit>(Bits.getBit(bi));
if (BI)
Var = dyn_cast<VarInit>(BI->getBitVar());