Skip to content

[TableGen] Change CodeGenInstruction record members to const #107921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/AsmMatcherEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ struct MatchableInfo {

/// TheDef - This is the definition of the instruction or InstAlias that this
/// matchable came from.
Record *const TheDef;
const Record *const TheDef;

// ResInstSize - The size of the resulting instruction for this matchable.
unsigned ResInstSize;
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/CodeEmitterGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void CodeEmitterGen::emitInstructionBaseValues(
<< HWM.getModeName(HwMode, /*IncludeDefault=*/true) << "[] = {\n";

for (const CodeGenInstruction *CGI : NumberedInstructions) {
Record *R = CGI->TheDef;
const Record *R = CGI->TheDef;

if (R->getValueAsString("Namespace") == "TargetOpcode" ||
R->getValueAsBit("isPseudo")) {
Expand Down Expand Up @@ -485,7 +485,7 @@ void CodeEmitterGen::run(raw_ostream &o) {
std::set<unsigned> HwModes;
BitWidth = 0;
for (const CodeGenInstruction *CGI : NumberedInstructions) {
Record *R = CGI->TheDef;
const Record *R = CGI->TheDef;
if (R->getValueAsString("Namespace") == "TargetOpcode" ||
R->getValueAsBit("isPseudo"))
continue;
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/CodeGenMapTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class MapTableEmitter {

// KeyInstrVec - list of key instructions.
std::vector<Record *> KeyInstrVec;
DenseMap<Record *, std::vector<Record *>> MapTable;
DenseMap<const Record *, std::vector<Record *>> MapTable;

public:
MapTableEmitter(CodeGenTarget &Target, RecordKeeper &Records, Record *IMRec)
Expand Down Expand Up @@ -371,7 +371,7 @@ unsigned MapTableEmitter::emitBinSearchTable(raw_ostream &OS) {
// emitted as first column.
OS << "Table[][" << NumCol + 1 << "] = {\n";
for (unsigned i = 0; i < TotalNumInstr; i++) {
Record *CurInstr = NumberedInstructions[i]->TheDef;
const Record *CurInstr = NumberedInstructions[i]->TheDef;
std::vector<Record *> ColInstrs = MapTable[CurInstr];
std::string OutStr;
unsigned RelExists = 0;
Expand Down
49 changes: 24 additions & 25 deletions llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,28 +1255,28 @@ bool TreePredicateFn::isAtomicOrderingWeakerThanRelease() const {
false);
}
Record *TreePredicateFn::getMemoryVT() const {
Record *R = getOrigPatFragRecord()->getRecord();
const Record *R = getOrigPatFragRecord()->getRecord();
if (R->isValueUnset("MemoryVT"))
return nullptr;
return R->getValueAsDef("MemoryVT");
}

ListInit *TreePredicateFn::getAddressSpaces() const {
Record *R = getOrigPatFragRecord()->getRecord();
const Record *R = getOrigPatFragRecord()->getRecord();
if (R->isValueUnset("AddressSpaces"))
return nullptr;
return R->getValueAsListInit("AddressSpaces");
}

int64_t TreePredicateFn::getMinAlignment() const {
Record *R = getOrigPatFragRecord()->getRecord();
const Record *R = getOrigPatFragRecord()->getRecord();
if (R->isValueUnset("MinAlignment"))
return 0;
return R->getValueAsInt("MinAlignment");
}

Record *TreePredicateFn::getScalarMemoryVT() const {
Record *R = getOrigPatFragRecord()->getRecord();
const Record *R = getOrigPatFragRecord()->getRecord();
if (R->isValueUnset("ScalarMemoryVT"))
return nullptr;
return R->getValueAsDef("ScalarMemoryVT");
Expand Down Expand Up @@ -1390,7 +1390,7 @@ std::string TreePredicateFn::getCodeToRunOnSDNode() const {
if (Tree->isLeaf())
TreeClassName = "SDNode";
else {
Record *Op = Tree->getOperator();
const Record *Op = Tree->getOperator();
const SDNodeInfo &Info = PatFragRec->getDAGPatterns().getSDNodeInfo(Op);
TreeClassName = Info.getSDClassName();
}
Expand Down Expand Up @@ -1848,7 +1848,8 @@ MVT::SimpleValueType SDNodeInfo::getKnownType(unsigned ResNo) const {
// TreePatternNode implementation
//

static unsigned GetNumNodeResults(Record *Operator, CodeGenDAGPatterns &CDP) {
static unsigned GetNumNodeResults(const Record *Operator,
CodeGenDAGPatterns &CDP) {
if (Operator->getName() == "set" || Operator->getName() == "implicit")
return 0; // All return nothing.

Expand Down Expand Up @@ -2077,7 +2078,7 @@ void TreePatternNode::InlinePatternFragments(
return;
}

Record *Op = getOperator();
const Record *Op = getOperator();

if (!Op->isSubClassOf("PatFrags")) {
if (getNumChildren() == 0) {
Expand Down Expand Up @@ -2340,7 +2341,7 @@ TreePatternNode::getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const {
/// return the ComplexPattern information, otherwise return null.
const ComplexPattern *
TreePatternNode::getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const {
Record *Rec;
const Record *Rec;
if (isLeaf()) {
DefInit *DI = dyn_cast<DefInit>(getLeafValue());
if (!DI)
Expand Down Expand Up @@ -2793,23 +2794,23 @@ bool TreePatternNode::canPatternMatch(std::string &Reason,
// TreePattern implementation
//

TreePattern::TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
TreePattern::TreePattern(const Record *TheRec, ListInit *RawPat, bool isInput,
CodeGenDAGPatterns &cdp)
: TheRecord(TheRec), CDP(cdp), isInputPattern(isInput), HasError(false),
Infer(*this) {
for (Init *I : RawPat->getValues())
Trees.push_back(ParseTreePattern(I, ""));
}

TreePattern::TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
TreePattern::TreePattern(const Record *TheRec, DagInit *Pat, bool isInput,
CodeGenDAGPatterns &cdp)
: TheRecord(TheRec), CDP(cdp), isInputPattern(isInput), HasError(false),
Infer(*this) {
Trees.push_back(ParseTreePattern(Pat, ""));
}

TreePattern::TreePattern(Record *TheRec, TreePatternNodePtr Pat, bool isInput,
CodeGenDAGPatterns &cdp)
TreePattern::TreePattern(const Record *TheRec, TreePatternNodePtr Pat,
bool isInput, CodeGenDAGPatterns &cdp)
: TheRecord(TheRec), CDP(cdp), isInputPattern(isInput), HasError(false),
Infer(*this) {
Trees.push_back(Pat);
Expand Down Expand Up @@ -3389,7 +3390,7 @@ static bool HandleUse(TreePattern &I, TreePatternNodePtr Pat,
return false;
}

Record *Rec;
const Record *Rec;
if (Pat->isLeaf()) {
DefInit *DI = dyn_cast<DefInit>(Pat->getLeafValue());
if (!DI)
Expand All @@ -3408,7 +3409,7 @@ static bool HandleUse(TreePattern &I, TreePatternNodePtr Pat,
Slot = Pat;
return true;
}
Record *SlotRec;
const Record *SlotRec;
if (Slot->isLeaf()) {
SlotRec = cast<DefInit>(Slot->getLeafValue())->getDef();
} else {
Expand Down Expand Up @@ -3633,7 +3634,8 @@ class InstAnalyzer {
};

static bool InferFromPattern(CodeGenInstruction &InstInfo,
const InstAnalyzer &PatInfo, Record *PatDef) {
const InstAnalyzer &PatInfo,
const Record *PatDef) {
bool Error = false;

// Remember where InstInfo got its flags.
Expand Down Expand Up @@ -3729,7 +3731,7 @@ static bool hasNullFragReference(ListInit *LI) {

/// Get all the instructions in a tree.
static void getInstructionsInTree(TreePatternNode &Tree,
SmallVectorImpl<Record *> &Instrs) {
SmallVectorImpl<const Record *> &Instrs) {
if (Tree.isLeaf())
return;
if (Tree.getOperator()->isSubClassOf("Instruction"))
Expand Down Expand Up @@ -3935,8 +3937,7 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,

// Create and insert the instruction.
// FIXME: InstImpResults should not be part of DAGInstruction.
Record *R = I.getRecord();
DAGInsts.try_emplace(R, std::move(Results), std::move(Operands),
DAGInsts.try_emplace(I.getRecord(), std::move(Results), std::move(Operands),
std::move(InstImpResults), SrcPattern, ResultPattern);

LLVM_DEBUG(I.dump());
Expand Down Expand Up @@ -3989,9 +3990,7 @@ void CodeGenDAGPatterns::ParseInstructions() {
}

// If we can, convert the instructions to be patterns that are matched!
for (auto &Entry : Instructions) {
Record *Instr = Entry.first;
DAGInstruction &TheInst = Entry.second;
for (const auto &[Instr, TheInst] : Instructions) {
TreePatternNodePtr SrcPattern = TheInst.getSrcPattern();
TreePatternNodePtr ResultPattern = TheInst.getResultPattern();

Expand Down Expand Up @@ -4078,7 +4077,7 @@ void CodeGenDAGPatterns::InferInstructionFlags() {
for (const PatternToMatch &PTM : ptms()) {
// We can only infer from single-instruction patterns, otherwise we won't
// know which instruction should get the flags.
SmallVector<Record *, 8> PatInstrs;
SmallVector<const Record *, 8> PatInstrs;
getInstructionsInTree(PTM.getDstPattern(), PatInstrs);
if (PatInstrs.size() != 1)
continue;
Expand Down Expand Up @@ -4135,7 +4134,7 @@ void CodeGenDAGPatterns::InferInstructionFlags() {
void CodeGenDAGPatterns::VerifyInstructionFlags() {
unsigned Errors = 0;
for (const PatternToMatch &PTM : ptms()) {
SmallVector<Record *, 8> Instrs;
SmallVector<const Record *, 8> Instrs;
getInstructionsInTree(PTM.getDstPattern(), Instrs);
if (Instrs.empty())
continue;
Expand Down Expand Up @@ -4245,7 +4244,7 @@ static TreePatternNodePtr PromoteXForms(TreePatternNodePtr N) {
}

void CodeGenDAGPatterns::ParseOnePattern(
Record *TheDef, TreePattern &Pattern, TreePattern &Result,
const Record *TheDef, TreePattern &Pattern, TreePattern &Result,
const std::vector<Record *> &InstImpResults, bool ShouldIgnore) {

// Inline pattern fragments and expand multiple alternatives.
Expand Down Expand Up @@ -4591,7 +4590,7 @@ GatherChildrenOfAssociativeOpcode(TreePatternNodePtr N,
std::vector<TreePatternNodePtr> &Children) {
assert(N->getNumChildren() == 2 &&
"Associative but doesn't have 2 children!");
Record *Operator = N->getOperator();
const Record *Operator = N->getOperator();

// Only permit raw nodes.
if (!N->getName().empty() || !N->getPredicateCalls().empty() ||
Expand Down
Loading
Loading