Skip to content
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
32 changes: 30 additions & 2 deletions llvm/lib/CodeGen/GlobalISel/PatternGen.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//===- llvm/CodeGen/GlobalISel/PatternGen.cpp - PatternGen ---==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
Expand Down Expand Up @@ -65,6 +65,8 @@
STATISTIC(PatternGenNumErrorFormatImm, "Errors of type: FORMAT_IMM");
STATISTIC(PatternGenNumErrorFormat, "Errors of type: FORMAT");
STATISTIC(PatternGenNumErrorMultipleStores, "Errors of type: MULTIPLE STORES");
STATISTIC(PatternGenNumErrorUnusedOperand, "Errors of type: UNUSED_OPERAND");
STATISTIC(PatternGenNumErrorOperandMissmatch, "Errors of type: OPERAND_MISSMATCH");

#ifdef LLVM_GISEL_COV_PREFIX
static cl::opt<std::string>
Expand Down Expand Up @@ -142,7 +144,8 @@
FORMAT_LOAD,
FORMAT_IMM,
FORMAT,
MULTIPLE_STORES
MULTIPLE_STORES,
UNUSED_OPERANDS
};
struct PatternError {
PatternErrorT Type;
Expand All @@ -163,7 +166,8 @@
&PatternGenNumErrorFormatLoad,
&PatternGenNumErrorFormatImm,
&PatternGenNumErrorFormat,
&PatternGenNumErrorMultipleStores};
&PatternGenNumErrorMultipleStores,
&PatternGenNumErrorUnusedOperand};

static const std::unordered_map<unsigned, std::string> CmpStr = {
{CmpInst::Predicate::ICMP_EQ, "SETEQ"},
Expand Down Expand Up @@ -697,7 +701,7 @@
abort();
}

static bool classof(const PatternNode *p) { return p->getKind() == PN_Load; }

Check warning on line 704 in llvm/lib/CodeGen/GlobalISel/PatternGen.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for parameter 'p'
};

struct CastNode : public PatternNode {
Expand All @@ -711,7 +715,7 @@
return "(" + LLTString + " " + Value->patternString() + ")";
}

static bool classof(const PatternNode *p) { return p->getKind() == PN_Cast; }

Check warning on line 718 in llvm/lib/CodeGen/GlobalISel/PatternGen.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for parameter 'p'
};

struct StoreNode : public PatternNode {
Expand Down Expand Up @@ -739,20 +743,20 @@
abort();
}

static bool classof(const PatternNode *p) { return p->getKind() == PN_Cast; }

Check warning on line 746 in llvm/lib/CodeGen/GlobalISel/PatternGen.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for parameter 'p'
};

using PatternOrError = std::pair<PatternError, std::unique_ptr<PatternNode>>;
static PatternOrError pError(PatternErrorT Type, MachineInstr *Inst) {
return std::make_pair(PatternError(Type, Inst), nullptr);
}
static PatternOrError PError(PatternError Error) {

Check warning on line 753 in llvm/lib/CodeGen/GlobalISel/PatternGen.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for function 'PError'
return std::make_pair(Error, nullptr);
}
static PatternOrError PError(PatternErrorT Type) {

Check warning on line 756 in llvm/lib/CodeGen/GlobalISel/PatternGen.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for function 'PError'
return std::make_pair(PatternError(Type), nullptr);
}
static PatternOrError PPattern(std::unique_ptr<PatternNode> Pattern) {

Check warning on line 759 in llvm/lib/CodeGen/GlobalISel/PatternGen.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for function 'PPattern'
return std::make_pair(PatternError(SUCCESS), std::move(Pattern));
}

Expand Down Expand Up @@ -1366,6 +1370,30 @@
std::string OutsString;
std::string InsString;
for (size_t I = 0; I < CurInstr->fields.size() - 1; I++) {
// TODO: move to helper func

// handle unused operands
if (!PatternArgs[I].In && !PatternArgs[I].Out) {
llvm::errs() << "Pattern Generation failed for " << MF.getName() << ": "
<< "Operand '" << CurInstr->fields[I].ident << "' not used in pattern!\n";
++PatternGenNumErrorUnusedOperand;
return true;
}

// check for missmatches between operands
if ((CurInstr->fields[I].type & CDSLInstr::IN) && !PatternArgs[I].In) {
llvm::errs() << "Pattern Generation failed for " << MF.getName() << ": "
<< "Operand '" << CurInstr->fields[I].ident << "' should be an input!\n";
++PatternGenNumErrorOperandMissmatch;
return true;
}
if ((CurInstr->fields[I].type & CDSLInstr::OUT) && !PatternArgs[I].Out) {
llvm::errs() << "Pattern Generation failed for " << MF.getName() << ": "
<< "Operand '" << CurInstr->fields[I].ident << "' should be an output!\n";
++PatternGenNumErrorOperandMissmatch;
return true;
}

if (PatternArgs[I].In) {
InsString += PatternArgs[I].ArgTypeStr + ":$" +
std::string(CurInstr->fields[I].ident) + ", ";
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/pattern-gen/lib/Parser.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include "Parser.hpp"
#include "InstrInfo.hpp"
#include "Token.hpp"
Expand Down Expand Up @@ -40,10 +40,10 @@
using namespace std::placeholders;

struct Value {
llvm::Value *ll;

Check warning on line 43 in llvm/tools/pattern-gen/lib/Parser.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for member 'll'
int bitWidth;

Check warning on line 44 in llvm/tools/pattern-gen/lib/Parser.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for member 'bitWidth'
bool isSigned;

Check warning on line 45 in llvm/tools/pattern-gen/lib/Parser.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for member 'isSigned'
bool isLValue;

Check warning on line 46 in llvm/tools/pattern-gen/lib/Parser.cpp

View workflow job for this annotation

GitHub Actions / Run linters

invalid case style for member 'isLValue'

Value(llvm::Value *llvalue, bool isSigned = false)
: ll(llvalue), isSigned(isSigned) {
Expand Down Expand Up @@ -1371,7 +1371,7 @@
strNew =
std::regex_replace(str, std::regex("\\{" + fstr + "\\}"), "$" + fstr);
if (strNew != str)
f.type = (CDSLInstr::FieldType)(f.type | CDSLInstr::FieldType::IMM);
f.type = (CDSLInstr::FieldType)(f.type | CDSLInstr::FieldType::IMM | CDSLInstr::FieldType::IN);
str = strNew;
}

Expand Down