aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Target/CSKY
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-09-02 21:17:18 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-01-07 17:46:17 +0000
commitfe013be447cd855ccaf6094a1d06aea570450629 (patch)
tree9adc1e0a5d25b6280995832bb29d592fb80554a6 /contrib/llvm-project/llvm/lib/Target/CSKY
parent2f3b605b2e159522ecab77fd518e8139aaf581e9 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/CSKY')
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp354
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/CSKY.td8
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/CSKYAsmPrinter.h2
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelDAGToDAG.cpp4
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.cpp45
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.h3
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo.td256
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo16Instr.td54
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/CSKYSubtarget.h2
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/Disassembler/CSKYDisassembler.cpp6
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp4
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp6
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp2
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp2
-rw-r--r--contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp2
15 files changed, 412 insertions, 338 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
index 94ef40e658a3..19f33f38cbfd 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
@@ -13,6 +13,7 @@
#include "TargetInfo/CSKYTargetInfo.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/CodeGen/Register.h"
@@ -29,10 +30,10 @@
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/CSKYAttributes.h"
-#include "llvm/Support/CSKYTargetParser.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
+#include "llvm/TargetParser/CSKYTargetParser.h"
using namespace llvm;
@@ -61,7 +62,8 @@ class CSKYAsmParser : public MCTargetAsmParser {
unsigned Kind) override;
bool generateImmOutOfRangeError(OperandVector &Operands, uint64_t ErrorInfo,
- int64_t Lower, int64_t Upper, Twine Msg);
+ int64_t Lower, int64_t Upper,
+ const Twine &Msg);
SMLoc getLoc() const { return getParser().getTok().getLoc(); }
@@ -76,7 +78,7 @@ class CSKYAsmParser : public MCTargetAsmParser {
bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
SMLoc NameLoc, OperandVector &Operands) override;
- bool ParseDirective(AsmToken DirectiveID) override;
+ ParseStatus parseDirective(AsmToken DirectiveID) override;
// Helper to actually emit an instruction to the MCStreamer. Also, when
// possible, compression of the instruction is performed.
@@ -102,15 +104,15 @@ class CSKYAsmParser : public MCTargetAsmParser {
#define GET_ASSEMBLER_HEADER
#include "CSKYGenAsmMatcher.inc"
- OperandMatchResultTy parseImmediate(OperandVector &Operands);
- OperandMatchResultTy parseRegister(OperandVector &Operands);
- OperandMatchResultTy parseBaseRegImm(OperandVector &Operands);
- OperandMatchResultTy parseCSKYSymbol(OperandVector &Operands);
- OperandMatchResultTy parseConstpoolSymbol(OperandVector &Operands);
- OperandMatchResultTy parseDataSymbol(OperandVector &Operands);
- OperandMatchResultTy parsePSRFlag(OperandVector &Operands);
- OperandMatchResultTy parseRegSeq(OperandVector &Operands);
- OperandMatchResultTy parseRegList(OperandVector &Operands);
+ ParseStatus parseImmediate(OperandVector &Operands);
+ ParseStatus parseRegister(OperandVector &Operands);
+ ParseStatus parseBaseRegImm(OperandVector &Operands);
+ ParseStatus parseCSKYSymbol(OperandVector &Operands);
+ ParseStatus parseConstpoolSymbol(OperandVector &Operands);
+ ParseStatus parseDataSymbol(OperandVector &Operands);
+ ParseStatus parsePSRFlag(OperandVector &Operands);
+ ParseStatus parseRegSeq(OperandVector &Operands);
+ ParseStatus parseRegList(OperandVector &Operands);
bool parseOperand(OperandVector &Operands, StringRef Mnemonic);
@@ -650,7 +652,7 @@ static std::string CSKYMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS,
bool CSKYAsmParser::generateImmOutOfRangeError(
OperandVector &Operands, uint64_t ErrorInfo, int64_t Lower, int64_t Upper,
- Twine Msg = "immediate must be an integer in the range") {
+ const Twine &Msg = "immediate must be an integer in the range") {
SMLoc ErrorLoc = ((CSKYOperand &)*Operands[ErrorInfo]).getStartLoc();
return Error(ErrorLoc, Msg + " [" + Twine(Lower) + ", " + Twine(Upper) + "]");
}
@@ -835,7 +837,7 @@ bool CSKYAsmParser::processLRW(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out) {
if (isUInt<8>(Inst.getOperand(1).getImm()) &&
Inst.getOperand(0).getReg() <= CSKY::R7) {
Opcode = CSKY::MOVI16;
- } else if (getSTI().getFeatureBits()[CSKY::HasE2] &&
+ } else if (getSTI().hasFeature(CSKY::HasE2) &&
isUInt<16>(Inst.getOperand(1).getImm())) {
Opcode = CSKY::MOVI32;
} else {
@@ -1021,93 +1023,84 @@ bool CSKYAsmParser::parseRegister(MCRegister &RegNo, SMLoc &StartLoc,
return false;
}
- return MatchOperand_NoMatch;
+ return true;
}
-OperandMatchResultTy CSKYAsmParser::parseRegister(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseRegister(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
switch (getLexer().getKind()) {
default:
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
case AsmToken::Identifier: {
StringRef Name = getLexer().getTok().getIdentifier();
MCRegister RegNo;
if (matchRegisterNameHelper(getSTI(), (MCRegister &)RegNo, Name))
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
getLexer().Lex();
Operands.push_back(CSKYOperand::createReg(RegNo, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
}
}
-OperandMatchResultTy CSKYAsmParser::parseBaseRegImm(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseBaseRegImm(OperandVector &Operands) {
assert(getLexer().is(AsmToken::LParen));
Operands.push_back(CSKYOperand::createToken("(", getLoc()));
auto Tok = getParser().Lex(); // Eat '('
- if (parseRegister(Operands) != MatchOperand_Success) {
+ if (!parseRegister(Operands).isSuccess()) {
getLexer().UnLex(Tok);
Operands.pop_back();
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
}
if (getLexer().is(AsmToken::RParen)) {
Operands.push_back(CSKYOperand::createToken(")", getLoc()));
getParser().Lex(); // Eat ')'
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
- if (getLexer().isNot(AsmToken::Comma)) {
- Error(getLoc(), "expected ','");
- return MatchOperand_ParseFail;
- }
+ if (getLexer().isNot(AsmToken::Comma))
+ return Error(getLoc(), "expected ','");
getParser().Lex(); // Eat ','
- if (parseRegister(Operands) == MatchOperand_Success) {
- if (getLexer().isNot(AsmToken::LessLess)) {
- Error(getLoc(), "expected '<<'");
- return MatchOperand_ParseFail;
- }
+ if (parseRegister(Operands).isSuccess()) {
+ if (getLexer().isNot(AsmToken::LessLess))
+ return Error(getLoc(), "expected '<<'");
Operands.push_back(CSKYOperand::createToken("<<", getLoc()));
getParser().Lex(); // Eat '<<'
- if (parseImmediate(Operands) != MatchOperand_Success) {
- Error(getLoc(), "expected imm");
- return MatchOperand_ParseFail;
- }
+ if (!parseImmediate(Operands).isSuccess())
+ return Error(getLoc(), "expected imm");
- } else if (parseImmediate(Operands) != MatchOperand_Success) {
- Error(getLoc(), "expected imm");
- return MatchOperand_ParseFail;
+ } else if (!parseImmediate(Operands).isSuccess()) {
+ return Error(getLoc(), "expected imm");
}
- if (getLexer().isNot(AsmToken::RParen)) {
- Error(getLoc(), "expected ')'");
- return MatchOperand_ParseFail;
- }
+ if (getLexer().isNot(AsmToken::RParen))
+ return Error(getLoc(), "expected ')'");
Operands.push_back(CSKYOperand::createToken(")", getLoc()));
getParser().Lex(); // Eat ')'
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parseImmediate(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseImmediate(OperandVector &Operands) {
switch (getLexer().getKind()) {
default:
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
case AsmToken::LParen:
case AsmToken::Minus:
case AsmToken::Plus:
@@ -1118,14 +1111,12 @@ OperandMatchResultTy CSKYAsmParser::parseImmediate(OperandVector &Operands) {
const MCExpr *IdVal;
SMLoc S = getLoc();
- if (getParser().parseExpression(IdVal)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseExpression(IdVal))
+ return Error(getLoc(), "unknown expression");
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
Operands.push_back(CSKYOperand::createImm(IdVal, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
/// Looks at a token type and creates the relevant operand from this
@@ -1134,33 +1125,33 @@ OperandMatchResultTy CSKYAsmParser::parseImmediate(OperandVector &Operands) {
bool CSKYAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
// Check if the current operand has a custom associated parser, if so, try to
// custom parse the operand, or fallback to the general approach.
- OperandMatchResultTy Result =
+ ParseStatus Result =
MatchOperandParserImpl(Operands, Mnemonic, /*ParseForAllFeatures=*/true);
- if (Result == MatchOperand_Success)
+ if (Result.isSuccess())
return false;
- if (Result == MatchOperand_ParseFail)
+ if (Result.isFailure())
return true;
// Attempt to parse token as register
auto Res = parseRegister(Operands);
- if (Res == MatchOperand_Success)
+ if (Res.isSuccess())
return false;
- else if (Res == MatchOperand_ParseFail)
+ if (Res.isFailure())
return true;
// Attempt to parse token as (register, imm)
if (getLexer().is(AsmToken::LParen)) {
Res = parseBaseRegImm(Operands);
- if (Res == MatchOperand_Success)
+ if (Res.isSuccess())
return false;
- else if (Res == MatchOperand_ParseFail)
+ if (Res.isFailure())
return true;
}
Res = parseImmediate(Operands);
- if (Res == MatchOperand_Success)
+ if (Res.isSuccess())
return false;
- else if (Res == MatchOperand_ParseFail)
+ if (Res.isFailure())
return true;
// Finally we have exhausted all options and must declare defeat.
@@ -1168,21 +1159,19 @@ bool CSKYAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
return true;
}
-OperandMatchResultTy CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
const MCExpr *Res;
if (getLexer().getKind() != AsmToken::Identifier)
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
StringRef Identifier;
AsmToken Tok = getLexer().getTok();
- if (getParser().parseIdentifier(Identifier)) {
- Error(getLoc(), "unknown identifier");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseIdentifier(Identifier))
+ return Error(getLoc(), "unknown identifier");
CSKYMCExpr::VariantKind Kind = CSKYMCExpr::VK_CSKY_None;
if (Identifier.consume_back("@GOT"))
@@ -1213,8 +1202,7 @@ OperandMatchResultTy CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
const MCExpr *V = Sym->getVariableValue(/*SetUsed=*/false);
if (!isa<MCSymbolRefExpr>(V)) {
getLexer().UnLex(Tok); // Put back if it's not a bare symbol.
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
}
Res = V;
} else
@@ -1227,7 +1215,7 @@ OperandMatchResultTy CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
Res = CSKYMCExpr::create(Res, Kind, getContext());
Operands.push_back(CSKYOperand::createImm(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
case AsmToken::Plus:
Opcode = MCBinaryExpr::Add;
break;
@@ -1239,50 +1227,37 @@ OperandMatchResultTy CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
getLexer().Lex(); // eat + or -
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
Res = MCBinaryExpr::create(Opcode, Res, Expr, getContext());
Operands.push_back(CSKYOperand::createImm(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
const MCExpr *Res;
- if (getLexer().getKind() != AsmToken::LBrac)
- return MatchOperand_NoMatch;
-
- getLexer().Lex(); // Eat '['.
-
+ if (!parseOptionalToken(AsmToken::LBrac))
+ return ParseStatus::NoMatch;
if (getLexer().getKind() != AsmToken::Identifier) {
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
- if (getLexer().getKind() != AsmToken::RBrac) {
- Error(getLoc(), "expected ]");
- return MatchOperand_ParseFail;
- }
-
- getLexer().Lex(); // Eat ']'.
+ if (parseToken(AsmToken::RBrac, "expected ']'"))
+ return ParseStatus::Failure;
Operands.push_back(CSKYOperand::createConstpoolOp(Expr, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
AsmToken Tok = getLexer().getTok();
StringRef Identifier;
- if (getParser().parseIdentifier(Identifier)) {
- Error(getLoc(), "unknown identifier " + Identifier);
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseIdentifier(Identifier))
+ return Error(getLoc(), "unknown identifier " + Identifier);
CSKYMCExpr::VariantKind Kind = CSKYMCExpr::VK_CSKY_None;
if (Identifier.consume_back("@GOT"))
@@ -1299,8 +1274,7 @@ OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
const MCExpr *V = Sym->getVariableValue(/*SetUsed=*/false);
if (!isa<MCSymbolRefExpr>(V)) {
getLexer().UnLex(Tok); // Put back if it's not a bare symbol.
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
}
Res = V;
} else {
@@ -1310,8 +1284,7 @@ OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
MCBinaryExpr::Opcode Opcode;
switch (getLexer().getKind()) {
default:
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
case AsmToken::RBrac:
getLexer().Lex(); // Eat ']'.
@@ -1320,7 +1293,7 @@ OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
Res = CSKYMCExpr::create(Res, Kind, getContext());
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
case AsmToken::Plus:
Opcode = MCBinaryExpr::Add;
break;
@@ -1332,59 +1305,40 @@ OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
getLexer().Lex(); // eat + or -
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
-
- if (getLexer().getKind() != AsmToken::RBrac) {
- Error(getLoc(), "expected ']'");
- return MatchOperand_ParseFail;
- }
-
- getLexer().Lex(); // Eat ']'.
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
+ if (parseToken(AsmToken::RBrac, "expected ']'"))
+ return ParseStatus::Failure;
Res = MCBinaryExpr::create(Opcode, Res, Expr, getContext());
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy
-CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
const MCExpr *Res;
- if (getLexer().getKind() != AsmToken::LBrac)
- return MatchOperand_NoMatch;
-
- getLexer().Lex(); // Eat '['.
+ if (!parseOptionalToken(AsmToken::LBrac))
+ return ParseStatus::NoMatch;
if (getLexer().getKind() != AsmToken::Identifier) {
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
-
- if (getLexer().getKind() != AsmToken::RBrac) {
- Error(getLoc(), "expected ']'");
- return MatchOperand_ParseFail;
- }
-
- getLexer().Lex(); // Eat ']'.
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
+ if (parseToken(AsmToken::RBrac))
+ return ParseStatus::Failure;
Operands.push_back(CSKYOperand::createConstpoolOp(Expr, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
AsmToken Tok = getLexer().getTok();
StringRef Identifier;
- if (getParser().parseIdentifier(Identifier)) {
- Error(getLoc(), "unknown identifier");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseIdentifier(Identifier))
+ return Error(getLoc(), "unknown identifier");
MCSymbol *Sym = getContext().getInlineAsmLabel(Identifier);
@@ -1395,8 +1349,7 @@ CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
const MCExpr *V = Sym->getVariableValue(/*SetUsed=*/false);
if (!isa<MCSymbolRefExpr>(V)) {
getLexer().UnLex(Tok); // Put back if it's not a bare symbol.
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
}
Res = V;
} else {
@@ -1406,14 +1359,13 @@ CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
MCBinaryExpr::Opcode Opcode;
switch (getLexer().getKind()) {
default:
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
case AsmToken::RBrac:
getLexer().Lex(); // Eat ']'.
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
case AsmToken::Plus:
Opcode = MCBinaryExpr::Add;
break;
@@ -1425,24 +1377,17 @@ CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
getLexer().Lex(); // eat + or -
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
-
- if (getLexer().getKind() != AsmToken::RBrac) {
- Error(getLoc(), "expected ']'");
- return MatchOperand_ParseFail;
- }
-
- getLexer().Lex(); // Eat ']'.
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
+ if (parseToken(AsmToken::RBrac, "expected ']'"))
+ return ParseStatus::Failure;
Res = MCBinaryExpr::create(Opcode, Res, Expr, getContext());
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parsePSRFlag(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parsePSRFlag(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
@@ -1450,10 +1395,8 @@ OperandMatchResultTy CSKYAsmParser::parsePSRFlag(OperandVector &Operands) {
while (getLexer().isNot(AsmToken::EndOfStatement)) {
StringRef Identifier;
- if (getParser().parseIdentifier(Identifier)) {
- Error(getLoc(), "unknown identifier " + Identifier);
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseIdentifier(Identifier))
+ return Error(getLoc(), "unknown identifier " + Identifier);
if (Identifier == "sie")
Flag = (1 << 4) | Flag;
@@ -1465,77 +1408,58 @@ OperandMatchResultTy CSKYAsmParser::parsePSRFlag(OperandVector &Operands) {
Flag = (1 << 1) | Flag;
else if (Identifier == "af")
Flag = (1 << 0) | Flag;
- else {
- Error(getLoc(), "expected " + Identifier);
- return MatchOperand_ParseFail;
- }
+ else
+ return Error(getLoc(), "expected " + Identifier);
if (getLexer().is(AsmToken::EndOfStatement))
break;
- if (getLexer().is(AsmToken::Comma)) {
- getLexer().Lex(); // eat ','
- } else {
- Error(getLoc(), "expected ,");
- return MatchOperand_ParseFail;
- }
+ if (parseToken(AsmToken::Comma, "expected ','"))
+ return ParseStatus::Failure;
}
Operands.push_back(
CSKYOperand::createImm(MCConstantExpr::create(Flag, getContext()), S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parseRegSeq(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseRegSeq(OperandVector &Operands) {
SMLoc S = getLoc();
- if (parseRegister(Operands) != MatchOperand_Success)
- return MatchOperand_NoMatch;
+ if (!parseRegister(Operands).isSuccess())
+ return ParseStatus::NoMatch;
auto Ry = Operands.back()->getReg();
Operands.pop_back();
- if (getLexer().isNot(AsmToken::Minus)) {
- Error(getLoc(), "expected '-'");
- return MatchOperand_ParseFail;
- }
-
- getLexer().Lex(); // eat '-'
-
- if (parseRegister(Operands) != MatchOperand_Success) {
- Error(getLoc(), "invalid register");
- return MatchOperand_ParseFail;
- }
+ if (parseToken(AsmToken::Minus, "expected '-'"))
+ return ParseStatus::Failure;
+ if (!parseRegister(Operands).isSuccess())
+ return Error(getLoc(), "invalid register");
auto Rz = Operands.back()->getReg();
Operands.pop_back();
Operands.push_back(CSKYOperand::createRegSeq(Ry, Rz, S));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parseRegList(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseRegList(OperandVector &Operands) {
SMLoc S = getLoc();
SmallVector<unsigned, 4> reglist;
while (true) {
- if (parseRegister(Operands) != MatchOperand_Success) {
- Error(getLoc(), "invalid register");
- return MatchOperand_ParseFail;
- }
+ if (!parseRegister(Operands).isSuccess())
+ return Error(getLoc(), "invalid register");
auto Ry = Operands.back()->getReg();
Operands.pop_back();
- if (getLexer().is(AsmToken::Minus)) {
- getLexer().Lex(); // eat '-'
-
- if (parseRegister(Operands) != MatchOperand_Success) {
- Error(getLoc(), "invalid register");
- return MatchOperand_ParseFail;
- }
+ if (parseOptionalToken(AsmToken::Minus)) {
+ if (!parseRegister(Operands).isSuccess())
+ return Error(getLoc(), "invalid register");
auto Rz = Operands.back()->getReg();
Operands.pop_back();
@@ -1543,28 +1467,23 @@ OperandMatchResultTy CSKYAsmParser::parseRegList(OperandVector &Operands) {
reglist.push_back(Ry);
reglist.push_back(Rz);
- if (getLexer().is(AsmToken::Comma))
- getLexer().Lex(); // eat ','
- else if (getLexer().is(AsmToken::EndOfStatement))
+ if (getLexer().is(AsmToken::EndOfStatement))
break;
-
- } else if (getLexer().is(AsmToken::Comma)) {
+ (void)parseOptionalToken(AsmToken::Comma);
+ } else if (parseOptionalToken(AsmToken::Comma)) {
reglist.push_back(Ry);
reglist.push_back(Ry);
-
- getLexer().Lex(); // eat ','
} else if (getLexer().is(AsmToken::EndOfStatement)) {
reglist.push_back(Ry);
reglist.push_back(Ry);
break;
} else {
- Error(getLoc(), "invalid register list");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "invalid register list");
}
}
Operands.push_back(CSKYOperand::createRegList(reglist, S));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
bool CSKYAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
@@ -1581,14 +1500,9 @@ bool CSKYAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
return true;
// Parse until end of statement, consuming commas between operands.
- while (getLexer().is(AsmToken::Comma)) {
- // Consume comma token.
- getLexer().Lex();
-
- // Parse next operand.
+ while (parseOptionalToken(AsmToken::Comma))
if (parseOperand(Operands, Name))
return true;
- }
if (getLexer().isNot(AsmToken::EndOfStatement)) {
SMLoc Loc = getLexer().getLoc();
@@ -1616,17 +1530,13 @@ OperandMatchResultTy CSKYAsmParser::tryParseRegister(MCRegister &RegNo,
return MatchOperand_Success;
}
-bool CSKYAsmParser::ParseDirective(AsmToken DirectiveID) {
- // This returns false if this function recognizes the directive
- // regardless of whether it is successfully handles or reports an
- // error. Otherwise it returns true to give the generic parser a
- // chance at recognizing it.
+ParseStatus CSKYAsmParser::parseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getString();
if (IDVal == ".csky_attribute")
return parseDirectiveAttribute();
- return true;
+ return ParseStatus::NoMatch;
}
/// parseDirectiveAttribute
@@ -1640,10 +1550,8 @@ bool CSKYAsmParser::parseDirectiveAttribute() {
StringRef Name = Parser.getTok().getIdentifier();
std::optional<unsigned> Ret =
ELFAttrs::attrTypeFromString(Name, CSKYAttrs::getCSKYAttributeTags());
- if (!Ret) {
- Error(TagLoc, "attribute name not recognised: " + Name);
- return false;
- }
+ if (!Ret)
+ return Error(TagLoc, "attribute name not recognised: " + Name);
Tag = *Ret;
Parser.Lex();
} else {
@@ -1654,13 +1562,13 @@ bool CSKYAsmParser::parseDirectiveAttribute() {
return true;
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
- if (check(!CE, TagLoc, "expected numeric constant"))
- return true;
+ if (!CE)
+ return Error(TagLoc, "expected numeric constant");
Tag = CE->getValue();
}
- if (Parser.parseToken(AsmToken::Comma, "comma expected"))
+ if (Parser.parseComma())
return true;
StringRef StringValue;
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKY.td b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKY.td
index e5ac106c9b59..9809caa8bd8f 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKY.td
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKY.td
@@ -40,17 +40,17 @@ def HasFdivdu : Predicate<"Subtarget->hasFdivdu()">,
def FeatureFPUV3_HI
: SubtargetFeature<"fpuv3_hi", "HasFPUv3HalfWord", "true",
- "Enable FPUv3 harf word converting instructions">;
+ "Enable FPUv3 half word converting instructions">;
def HasFPUv3_HI : Predicate<"Subtarget->hasFPUv3HalfWord()">,
AssemblerPredicate<(all_of FeatureFPUV3_HI),
- "Enable FPUv3 harf word converting instructions">;
+ "Enable FPUv3 half word converting instructions">;
def FeatureFPUV3_HF
: SubtargetFeature<"fpuv3_hf", "HasFPUv3HalfFloat", "true",
- "Enable FPUv3 harf precision operate instructions">;
+ "Enable FPUv3 half precision operate instructions">;
def HasFPUv3_HF : Predicate<"Subtarget->hasFPUv3HalfFloat()">,
AssemblerPredicate<(all_of FeatureFPUV3_HF),
- "Enable FPUv3 harf precision operate instructions">;
+ "Enable FPUv3 half precision operate instructions">;
def FeatureFPUV3_SF
: SubtargetFeature<"fpuv3_sf", "HasFPUv3SingleFloat", "true",
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYAsmPrinter.h b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYAsmPrinter.h
index 5e87594e4fdf..379189512405 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYAsmPrinter.h
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYAsmPrinter.h
@@ -57,7 +57,7 @@ public:
bool runOnMachineFunction(MachineFunction &MF) override;
// we emit constant pools customly!
- void emitConstantPool() override{};
+ void emitConstantPool() override {}
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
const char *ExtraCode, raw_ostream &OS) override;
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelDAGToDAG.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelDAGToDAG.cpp
index 09c2d5161aba..702053e02332 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelDAGToDAG.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelDAGToDAG.cpp
@@ -74,10 +74,10 @@ void CSKYDAGToDAGISel::Select(SDNode *N) {
switch (Opcode) {
default:
break;
- case ISD::ADDCARRY:
+ case ISD::UADDO_CARRY:
IsSelected = selectAddCarry(N);
break;
- case ISD::SUBCARRY:
+ case ISD::USUBO_CARRY:
IsSelected = selectSubCarry(N);
break;
case ISD::GLOBAL_OFFSET_TABLE: {
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.cpp
index a65a0283777f..5d21aab513dd 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.cpp
@@ -51,8 +51,8 @@ CSKYTargetLowering::CSKYTargetLowering(const TargetMachine &TM,
addRegisterClass(MVT::f64, &CSKY::FPR64RegClass);
}
- setOperationAction(ISD::ADDCARRY, MVT::i32, Legal);
- setOperationAction(ISD::SUBCARRY, MVT::i32, Legal);
+ setOperationAction(ISD::UADDO_CARRY, MVT::i32, Legal);
+ setOperationAction(ISD::USUBO_CARRY, MVT::i32, Legal);
setOperationAction(ISD::BITREVERSE, MVT::i32, Legal);
setOperationAction(ISD::SREM, MVT::i32, Expand);
@@ -116,8 +116,9 @@ CSKYTargetLowering::CSKYTargetLowering(const TargetMachine &TM,
ISD::SETUGE, ISD::SETULT, ISD::SETULE,
};
- ISD::NodeType FPOpToExpand[] = {ISD::FSIN, ISD::FCOS, ISD::FSINCOS,
- ISD::FPOW, ISD::FREM, ISD::FCOPYSIGN};
+ ISD::NodeType FPOpToExpand[] = {
+ ISD::FSIN, ISD::FCOS, ISD::FSINCOS, ISD::FPOW,
+ ISD::FREM, ISD::FCOPYSIGN, ISD::FP16_TO_FP, ISD::FP_TO_FP16};
if (STI.useHardFloat()) {
@@ -136,10 +137,14 @@ CSKYTargetLowering::CSKYTargetLowering(const TargetMachine &TM,
if (STI.hasFPUv2SingleFloat() || STI.hasFPUv3SingleFloat()) {
setOperationAction(ISD::ConstantFP, MVT::f32, Legal);
+ setLoadExtAction(ISD::EXTLOAD, MVT::f32, MVT::f16, Expand);
+ setTruncStoreAction(MVT::f32, MVT::f16, Expand);
}
if (STI.hasFPUv2DoubleFloat() || STI.hasFPUv3DoubleFloat()) {
setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f32, Expand);
setTruncStoreAction(MVT::f64, MVT::f32, Expand);
+ setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f16, Expand);
+ setTruncStoreAction(MVT::f64, MVT::f16, Expand);
}
}
@@ -153,8 +158,7 @@ CSKYTargetLowering::CSKYTargetLowering(const TargetMachine &TM,
setMaxAtomicSizeInBitsSupported(0);
setStackPointerRegisterToSaveRestore(CSKY::R14);
- const Align FunctionAlignment(2);
- setMinFunctionAlignment(FunctionAlignment);
+ setMinFunctionAlignment(Align(2));
setSchedulingPreference(Sched::Source);
}
@@ -379,7 +383,7 @@ SDValue CSKYTargetLowering::LowerFormalArguments(
// If all registers are allocated, then all varargs must be passed on the
// stack and we don't need to save any argregs.
if (ArgRegs.size() == Idx) {
- VaArgOffset = CCInfo.getNextStackOffset();
+ VaArgOffset = CCInfo.getStackSize();
VarArgsSaveSize = 0;
} else {
VarArgsSaveSize = XLenInBytes * (ArgRegs.size() - Idx);
@@ -532,7 +536,7 @@ SDValue CSKYTargetLowering::LowerCall(CallLoweringInfo &CLI,
"site marked musttail");
// Get a count of how many bytes are to be pushed on the stack.
- unsigned NumBytes = ArgCCInfo.getNextStackOffset();
+ unsigned NumBytes = ArgCCInfo.getStackSize();
// Create local copies for byval args
SmallVector<SDValue, 8> ByValArgs;
@@ -1372,3 +1376,28 @@ SDValue CSKYTargetLowering::getDynamicTLSAddr(GlobalAddressSDNode *N,
return V;
}
+
+bool CSKYTargetLowering::decomposeMulByConstant(LLVMContext &Context, EVT VT,
+ SDValue C) const {
+ if (!VT.isScalarInteger())
+ return false;
+
+ // Omit if data size exceeds.
+ if (VT.getSizeInBits() > Subtarget.XLen)
+ return false;
+
+ if (auto *ConstNode = dyn_cast<ConstantSDNode>(C.getNode())) {
+ const APInt &Imm = ConstNode->getAPIntValue();
+ // Break MULT to LSLI + ADDU/SUBU.
+ if ((Imm + 1).isPowerOf2() || (Imm - 1).isPowerOf2() ||
+ (1 - Imm).isPowerOf2())
+ return true;
+ // Only break MULT for sub targets without MULT32, since an extra
+ // instruction will be generated against the above 3 cases. We leave it
+ // unchanged on sub targets with MULT32, since not sure it is better.
+ if (!Subtarget.hasE2() && (-1 - Imm).isPowerOf2())
+ return true;
+ }
+
+ return false;
+}
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.h b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.h
index d0abc7e9a7e4..c724882c6042 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.h
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.h
@@ -173,6 +173,9 @@ private:
CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg) const;
CCAssignFn *CCAssignFnForReturn(CallingConv::ID CC, bool IsVarArg) const;
+
+ bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
+ SDValue C) const override;
};
} // namespace llvm
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo.td b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo.td
index b99dbf08f112..549c883c34a7 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo.td
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo.td
@@ -102,6 +102,14 @@ class oimm<int num> : Operand<i32>,
let DecoderMethod = "decodeOImmOperand<"#num#">";
}
+def imm_neg_XFORM : SDNodeXForm<imm, [{
+ return CurDAG->getTargetConstant(-N->getSExtValue(), SDLoc(N), MVT::i32);
+}]>;
+
+class oimm_neg<int num> : Operand<i32>,
+ ImmLeaf<i32, "return isUInt<"#num#">(-Imm - 1);"> {
+}
+
class uimm<int num, int shift = 0> : Operand<i32>,
ImmLeaf<i32, "return isShiftedUInt<"#num#", "#shift#">(Imm);"> {
let EncoderMethod = "getImmOpValue<"#shift#">";
@@ -112,6 +120,10 @@ class uimm<int num, int shift = 0> : Operand<i32>,
let DecoderMethod = "decodeUImmOperand<"#num#", "#shift#">";
}
+class uimm_neg<int num, int shift = 0> : Operand<i32>,
+ ImmLeaf<i32, "return isShiftedUInt<"#num#", "#shift#">(-Imm);"> {
+}
+
class simm<int num, int shift = 0> : Operand<i32>,
ImmLeaf<i32, "return isShiftedInt<"#num#", "#shift#">(Imm);"> {
let EncoderMethod = "getImmOpValue<"#shift#">";
@@ -259,6 +271,23 @@ def oimm16 : oimm<16> {
}];
}
+def oimm8_neg : oimm_neg<8> {
+ let MCOperandPredicate = [{
+ int64_t Imm;
+ if (MCOp.evaluateAsConstantImm(Imm))
+ return isUInt<8>(-Imm - 1);
+ return MCOp.isBareSymbolRef();
+ }];
+}
+def oimm12_neg : oimm_neg<12> {
+ let MCOperandPredicate = [{
+ int64_t Imm;
+ if (MCOp.evaluateAsConstantImm(Imm))
+ return isUInt<12>(-Imm - 1);
+ return MCOp.isBareSymbolRef();
+ }];
+}
+
def nimm12 : nimm<12>;
def uimm1 : uimm<1>;
@@ -371,6 +400,8 @@ def uimm20 : uimm<20>;
def uimm24 : uimm<24>;
def uimm24_8 : uimm<24, 8>;
+def uimm5_neg : uimm_neg<5>;
+
def simm8_2 : simm<8, 2>;
class RegSeqAsmOperand<string Suffix = ""> : AsmOperandClass {
@@ -518,6 +549,9 @@ let Predicates = [iHasE2] in {
let Size = 8 in
def RSUBI32 : CSKYPseudo<(outs GPR:$rd), (ins GPR:$rx, uimm12:$imm12), "rsubi32 $rd, $rx, $imm12", []>;
+ def : Pat<(add GPR:$rs1, (oimm12_neg:$im)),
+ (SUBI32 GPR:$rs1, (imm_neg_XFORM oimm12_neg:$im))>;
+
def LSL32 : R_YXZ_SP_F1<0x10, 0x1,
BinOpFrag<(shl node:$LHS, node:$RHS)>, "lsl32">;
def LSR32 : R_YXZ_SP_F1<0x10, 0x2,
@@ -885,9 +919,9 @@ let Predicates = [iHasE2] in {
def XTRB3 : R_XZ<0x1C, 0x8, "xtrb3.32">;
def BTSTI32 : I_5_X<0x0A, 0x4, "btsti32", uimm5, []>;
def BCLRI32 : I_5_XZ<0xA, 0x1, "bclri32",
- (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>;
+ (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>;
def BSETI32 : I_5_XZ<0xA, 0x2, "bseti32",
- (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>;
+ (outs GPR:$rz), (ins GPR:$rx, uimm5:$imm5), []>;
}
//===----------------------------------------------------------------------===//
@@ -1131,22 +1165,19 @@ def : Pat<(i32 (load constpool:$src)), (LRW32 (to_tconstpool tconstpool:$src))>;
// Branch Patterns.
let Predicates = [iHasE2] in {
- def : Pat<(brcond CARRY:$ca, bb:$imm16),
+def : Pat<(brcond CARRY:$ca, bb:$imm16),
(BT32 CARRY:$ca, bb:$imm16)>;
- def : Pat<(brcond (i32 (setne GPR:$rs1, uimm16:$rs2)), bb:$imm16),
- (BT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), bb:$imm16)>;
- def : Pat<(brcond (i32 (seteq GPR:$rs1, uimm16:$rs2)), bb:$imm16),
- (BF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), bb:$imm16)>;
- def : Pat<(brcond (i32 (setuge GPR:$rs1, oimm16:$rs2)), bb:$imm16),
- (BT32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
- def : Pat<(brcond (i32 (setult GPR:$rs1, oimm16:$rs2)), bb:$imm16),
- (BF32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
- def : Pat<(brcond (i32 (setlt GPR:$rs1, oimm16:$rs2)), bb:$imm16),
- (BT32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
- def : Pat<(brcond (i32 (setge GPR:$rs1, oimm16:$rs2)), bb:$imm16),
- (BF32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), bb:$imm16)>;
+multiclass BTF32Pat0<PatFrag cond0, PatFrag cond1, ImmLeaf imm_ty, Instruction inst> {
+ def : Pat<(brcond (i32 (cond0 GPR:$rs1, uimm16:$rs2)), bb:$imm16),
+ (BT32 (inst GPR:$rs1, imm_ty:$rs2), bb:$imm16)>;
+ def : Pat<(brcond (i32 (cond1 GPR:$rs1, uimm16:$rs2)), bb:$imm16),
+ (BF32 (inst GPR:$rs1, imm_ty:$rs2), bb:$imm16)>;
+}
+defm : BTF32Pat0<setne, seteq, uimm16, CMPNEI32>;
+defm : BTF32Pat0<setuge, setult, oimm16, CMPHSI32>;
+defm : BTF32Pat0<setlt, setge, oimm16, CMPLTI32>;
}
let Predicates = [iHas2E3] in {
@@ -1155,22 +1186,19 @@ def : Pat<(brcond (i32 (setne GPR:$rs1, GPR:$rs2)), bb:$imm16),
(BT32 (CMPNE32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
def : Pat<(brcond (i32 (seteq GPR:$rs1, GPR:$rs2)), bb:$imm16),
(BF32 (CMPNE32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
-def : Pat<(brcond (i32 (setuge GPR:$rs1, GPR:$rs2)), bb:$imm16),
- (BT32 (CMPHS32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
-def : Pat<(brcond (i32 (setule GPR:$rs1, GPR:$rs2)), bb:$imm16),
- (BT32 (CMPHS32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
-def : Pat<(brcond (i32 (setult GPR:$rs1, GPR:$rs2)), bb:$imm16),
- (BF32 (CMPHS32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
-def : Pat<(brcond (i32 (setugt GPR:$rs1, GPR:$rs2)), bb:$imm16),
- (BF32 (CMPHS32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
-def : Pat<(brcond (i32 (setlt GPR:$rs1, GPR:$rs2)), bb:$imm16),
- (BT32 (CMPLT32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
-def : Pat<(brcond (i32 (setgt GPR:$rs1, GPR:$rs2)), bb:$imm16),
- (BT32 (CMPLT32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
-def : Pat<(brcond (i32 (setge GPR:$rs1, GPR:$rs2)), bb:$imm16),
- (BF32 (CMPLT32 GPR:$rs1, GPR:$rs2), bb:$imm16)>;
-def : Pat<(brcond (i32 (setle GPR:$rs1, GPR:$rs2)), bb:$imm16),
- (BF32 (CMPLT32 GPR:$rs2, GPR:$rs1), bb:$imm16)>;
+
+multiclass BTF32Pat1<PatFrag cond0, PatFrag cond1, Instruction cmp,
+ Instruction br> {
+ def : Pat<(brcond (i32 (cond0 GPR:$rs1, GPR:$rs2)), bb:$imm16),
+ (br (cmp GPR:$rs1, GPR:$rs2), bb:$imm16)>;
+ def : Pat<(brcond (i32 (cond1 GPR:$rs1, GPR:$rs2)), bb:$imm16),
+ (br (cmp GPR:$rs2, GPR:$rs1), bb:$imm16)>;
+}
+
+defm : BTF32Pat1<setuge, setule, CMPHS32, BT32>;
+defm : BTF32Pat1<setult, setugt, CMPHS32, BF32>;
+defm : BTF32Pat1<setlt, setgt, CMPLT32, BT32>;
+defm : BTF32Pat1<setge, setle, CMPLT32, BF32>;
def : Pat<(brcond (i32 (seteq GPR:$rs1, (i32 0))), bb:$imm16),
(BEZ32 GPR:$rs1, bb:$imm16)>;
@@ -1178,12 +1206,20 @@ def : Pat<(brcond (i32 (setne GPR:$rs1, (i32 0))), bb:$imm16),
(BNEZ32 GPR:$rs1, bb:$imm16)>;
def : Pat<(brcond (i32 (setlt GPR:$rs1, (i32 0))), bb:$imm16),
(BLZ32 GPR:$rs1, bb:$imm16)>;
+def : Pat<(brcond (i32 (setlt GPR:$rs1, (i32 1))), bb:$imm16),
+ (BLSZ32 GPR:$rs1, bb:$imm16)>;
def : Pat<(brcond (i32 (setge GPR:$rs1, (i32 0))), bb:$imm16),
(BHSZ32 GPR:$rs1, bb:$imm16)>;
+def : Pat<(brcond (i32 (setge GPR:$rs1, (i32 1))), bb:$imm16),
+ (BHZ32 GPR:$rs1, bb:$imm16)>;
def : Pat<(brcond (i32 (setgt GPR:$rs1, (i32 0))), bb:$imm16),
(BHZ32 GPR:$rs1, bb:$imm16)>;
+def : Pat<(brcond (i32 (setgt GPR:$rs1, (i32 -1))), bb:$imm16),
+ (BHSZ32 GPR:$rs1, bb:$imm16)>;
def : Pat<(brcond (i32 (setle GPR:$rs1, (i32 0))), bb:$imm16),
(BLSZ32 GPR:$rs1, bb:$imm16)>;
+def : Pat<(brcond (i32 (setle GPR:$rs1, (i32 -1))), bb:$imm16),
+ (BLZ32 GPR:$rs1, bb:$imm16)>;
}
// Compare Patterns.
@@ -1231,25 +1267,76 @@ let Predicates = [iHasE2] in {
// Select Patterns.
let Predicates = [iHasE2] in {
+def : Pat<(select (i32 (setne GPR:$rs1, uimm16:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$false),
+ (INCT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$false, GPR:$rx, uimm5:$imm)>;
+def : Pat<(select (i32 (seteq GPR:$rs1, uimm16:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$false),
+ (INCF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$false, GPR:$rx, uimm5:$imm)>;
+def : Pat<(select (i32 (setne GPR:$rs1, uimm16:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$false),
+ (DECT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$false, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+def : Pat<(select (i32 (seteq GPR:$rs1, uimm16:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$false),
+ (DECF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$false, GPR:$rx,
+ (imm_neg_XFORM uimm5:$imm))>;
+
+multiclass INCDECPat<PatFrag cond0, PatFrag cond1, Instruction cmp> {
+ def : Pat<(select (i32 (cond0 GPR:$rs1, oimm16:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$other),
+ (INCT32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, oimm16:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$other),
+ (INCF32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>;
+ def : Pat<(select (i32 (cond0 GPR:$rs1, oimm16:$rs2)), GPR:$other, (add GPR:$rx, uimm5:$imm)),
+ (INCF32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, oimm16:$rs2)), GPR:$other, (add GPR:$rx, uimm5:$imm)),
+ (INCT32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>;
+ def : Pat<(select (i32 (cond0 GPR:$rs1, oimm16:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$other),
+ (DECT32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, oimm16:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$other),
+ (DECF32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+ def : Pat<(select (i32 (cond0 GPR:$rs1, oimm16:$rs2)), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)),
+ (DECF32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, oimm16:$rs2)), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)),
+ (DECT32 (cmp GPR:$rs1, oimm16:$rs2), GPR:$other, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+}
+
+defm : INCDECPat<setuge, setult, CMPHSI32>;
+defm : INCDECPat<setlt, setge, CMPLTI32>;
+
+def : Pat<(select CARRY:$ca, (add GPR:$rx, uimm5:$imm), GPR:$other),
+ (INCT32 CARRY:$ca, GPR:$other, GPR:$rx, uimm5:$imm)>;
+def : Pat<(select CARRY:$ca, GPR:$other, (add GPR:$rx, uimm5:$imm)),
+ (INCF32 CARRY:$ca, GPR:$other, GPR:$rx, uimm5:$imm)>;
+def : Pat<(select (and CARRY:$ca, 1), (add GPR:$rx, uimm5:$imm), GPR:$other),
+ (INCT32 CARRY:$ca, GPR:$other, GPR:$rx, uimm5:$imm)>;
+def : Pat<(select (and CARRY:$ca, 1), GPR:$other, (add GPR:$rx, uimm5:$imm)),
+ (INCF32 CARRY:$ca, GPR:$other, GPR:$rx, uimm5:$imm)>;
+
+def : Pat<(select CARRY:$ca, (add GPR:$rx, uimm5_neg:$imm), GPR:$other),
+ (DECT32 CARRY:$ca, GPR:$other, GPR:$rx, (imm_neg_XFORM uimm5_neg:$imm))>;
+def : Pat<(select CARRY:$ca, GPR:$other, (add GPR:$rx, uimm5_neg:$imm)),
+ (DECF32 CARRY:$ca, GPR:$other, GPR:$rx, (imm_neg_XFORM uimm5_neg:$imm))>;
+def : Pat<(select (and CARRY:$ca, 1), (add GPR:$rx, uimm5_neg:$imm), GPR:$other),
+ (DECT32 CARRY:$ca, GPR:$other, GPR:$rx, (imm_neg_XFORM uimm5_neg:$imm))>;
+def : Pat<(select (and CARRY:$ca, 1), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)),
+ (DECF32 CARRY:$ca, GPR:$other, GPR:$rx, (imm_neg_XFORM uimm5_neg:$imm))>;
+
def : Pat<(select CARRY:$ca, GPR:$rx, GPR:$false),
(MOVT32 CARRY:$ca, GPR:$rx, GPR:$false)>;
def : Pat<(select (and CARRY:$ca, 1), GPR:$rx, GPR:$false),
(MOVT32 CARRY:$ca, GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setne GPR:$rs1, uimm16:$rs2)), GPR:$rx, GPR:$false),
- (MOVT32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (seteq GPR:$rs1, uimm16:$rs2)), GPR:$rx, GPR:$false),
- (MOVF32 (CMPNEI32 GPR:$rs1, uimm16:$rs2), GPR:$rx, GPR:$false)>;
-
-def : Pat<(select (i32 (setuge GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
- (MOVT32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setult GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
- (MOVF32 (CMPHSI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
+multiclass MOVTF32Pat0<PatFrag cond0, PatFrag cond1, ImmLeaf imm_ty, Instruction inst> {
+ def : Pat<(select (i32 (cond0 GPR:$rs1, imm_ty:$rs2)), GPR:$rx, GPR:$false),
+ (MOVT32 (inst GPR:$rs1, imm_ty:$rs2), GPR:$rx, GPR:$false)>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, imm_ty:$rs2)), GPR:$rx, GPR:$false),
+ (MOVF32 (inst GPR:$rs1, imm_ty:$rs2), GPR:$rx, GPR:$false)>;
+}
-def : Pat<(select (i32 (setlt GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
- (MOVT32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setge GPR:$rs1, oimm16:$rs2)), GPR:$rx, GPR:$false),
- (MOVF32 (CMPLTI32 GPR:$rs1, oimm16:$rs2), GPR:$rx, GPR:$false)>;
+defm : MOVTF32Pat0<setne, seteq, uimm16, CMPNEI32>;
+defm : MOVTF32Pat0<setuge, setult, oimm16, CMPHSI32>;
+defm : MOVTF32Pat0<setlt, setge, oimm16, CMPLTI32>;
def : Pat<(select CARRY:$ca, GPR:$rx, GPR:$false),
(ISEL32 CARRY:$ca, GPR:$rx, GPR:$false)>;
@@ -1259,30 +1346,75 @@ def : Pat<(select (and CARRY:$ca, 1), GPR:$rx, GPR:$false),
let Predicates = [iHas2E3] in {
+def : Pat<(select (i32 (setne GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$false),
+ (INCT32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$false, GPR:$rx, uimm5:$imm)>;
+def : Pat<(select (i32 (seteq GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$false),
+ (INCF32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$false, GPR:$rx, uimm5:$imm)>;
+def : Pat<(select (i32 (setne GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$false),
+ (DECT32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$false, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+def : Pat<(select (i32 (seteq GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$false),
+ (DECF32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$false, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+
+multiclass INCPat<PatFrag cond0, PatFrag cond1, Instruction cmp, Instruction inc0, Instruction inc1> {
+ def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$other),
+ (inc0 (cmp GPR:$rs1, GPR:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>;
+ def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), GPR:$other, (add GPR:$rx, uimm5:$imm)),
+ (inc1 (cmp GPR:$rs1, GPR:$rs2), GPR:$other, GPR:$rx, uimm5:$imm)>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5:$imm), GPR:$other),
+ (inc0 (cmp GPR:$rs2, GPR:$rs1), GPR:$other, GPR:$rx, uimm5:$imm)>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), GPR:$other, (add GPR:$rx, uimm5:$imm)),
+ (inc1 (cmp GPR:$rs2, GPR:$rs1), GPR:$other, GPR:$rx, uimm5:$imm)>;
+}
+
+defm : INCPat<setuge, setule, CMPHS32, INCT32, INCF32>;
+defm : INCPat<setult, setugt, CMPHS32, INCF32, INCT32>;
+defm : INCPat<setlt, setgt, CMPLT32, INCT32, INCF32>;
+defm : INCPat<setge, setle, CMPLT32, INCF32, INCT32>;
+
+multiclass DECPat<PatFrag cond0, PatFrag cond1, Instruction cmp, Instruction dec0, Instruction dec1> {
+ def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$other),
+ (dec0 (cmp GPR:$rs1, GPR:$rs2), GPR:$other, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+ def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)),
+ (dec1 (cmp GPR:$rs1, GPR:$rs2), GPR:$other, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), (add GPR:$rx, uimm5_neg:$imm), GPR:$other),
+ (dec0 (cmp GPR:$rs2, GPR:$rs1), GPR:$other, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), GPR:$other, (add GPR:$rx, uimm5_neg:$imm)),
+ (dec1 (cmp GPR:$rs2, GPR:$rs1), GPR:$other, GPR:$rx,
+ (imm_neg_XFORM uimm5_neg:$imm))>;
+}
+
+defm : DECPat<setuge, setule, CMPHS32, DECT32, DECF32>;
+defm : DECPat<setult, setugt, CMPHS32, DECF32, DECT32>;
+defm : DECPat<setlt, setgt, CMPLT32, DECT32, DECF32>;
+defm : DECPat<setge, setle, CMPLT32, DECF32, DECT32>;
def : Pat<(select (i32 (setne GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
(MOVT32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
def : Pat<(select (i32 (seteq GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
(MOVF32 (CMPNE32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setuge GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
- (MOVT32 (CMPHS32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setule GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
- (MOVT32 (CMPHS32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setult GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
- (MOVF32 (CMPHS32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setugt GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
- (MOVF32 (CMPHS32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
+multiclass MOVTF32Pat1<PatFrag cond0, PatFrag cond1, Instruction cmp_inst,
+ Instruction mov_inst> {
+ def : Pat<(select (i32 (cond0 GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
+ (mov_inst (cmp_inst GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
+ def : Pat<(select (i32 (cond1 GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
+ (mov_inst (cmp_inst GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
+}
-def : Pat<(select (i32 (setlt GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
- (MOVT32 (CMPLT32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setgt GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
- (MOVT32 (CMPLT32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setge GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
- (MOVF32 (CMPLT32 GPR:$rs1, GPR:$rs2), GPR:$rx, GPR:$false)>;
-def : Pat<(select (i32 (setle GPR:$rs1, GPR:$rs2)), GPR:$rx, GPR:$false),
- (MOVF32 (CMPLT32 GPR:$rs2, GPR:$rs1), GPR:$rx, GPR:$false)>;
+defm : MOVTF32Pat1<setuge, setule, CMPHS32, MOVT32>;
+defm : MOVTF32Pat1<setult, setugt, CMPHS32, MOVF32>;
+defm : MOVTF32Pat1<setlt, setgt, CMPLT32, MOVT32>;
+defm : MOVTF32Pat1<setge, setle, CMPLT32, MOVF32>;
+def : Pat<(select CARRY:$ca, (i32 0), GPR:$other),
+ (CLRT32 CARRY:$ca, GPR:$other)>;
+def : Pat<(select CARRY:$ca, GPR:$other, (i32 0)),
+ (CLRF32 CARRY:$ca, GPR:$other)>;
}
// Constant materialize patterns.
@@ -1290,7 +1422,6 @@ let Predicates = [iHasE2] in
def : Pat<(i32 imm:$imm),
(ORI32 (MOVIH32 (uimm32_hi16 imm:$imm)), (uimm32_lo16 imm:$imm))>;
-
// Other operations.
let Predicates = [iHasE2] in {
def : Pat<(rotl GPR:$rs1, GPR:$rs2),
@@ -1353,9 +1484,6 @@ def JBF_E : CSKYPseudo<(outs), (ins CARRY:$ca, br_symbol:$src1), "!jbf_e\t$src1"
let mayLoad = 1, Size = 2, isCodeGenOnly = 0 in
def PseudoLRW32 : CSKYPseudo<(outs GPR:$rz), (ins bare_symbol:$src), "lrw32 $rz, $src", []>;
-
-
-
let mayLoad = 1, Size = 4, isCodeGenOnly = 0 in
def PseudoJSRI32 : CSKYPseudo<(outs), (ins call_symbol:$src), "jsri32 $src", []>;
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo16Instr.td b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo16Instr.td
index 86719d36d23e..3e248019d73f 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo16Instr.td
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrInfo16Instr.td
@@ -97,6 +97,9 @@ let Constraints = "$rZ = $rz", isReMaterializable = 1, isAsCheapAsAMove = 1 in {
def SUBI16 : I16_Z_8<0b101, (ins mGPR:$rZ, oimm8:$imm8), "subi16\t$rz, $imm8">;
}
+def : Pat<(add GPR:$rs1, (oimm8_neg:$im)),
+ (SUBI16 GPR:$rs1, (imm_neg_XFORM oimm8_neg:$im))>;
+
let isAdd = 1 in
def ADDI16ZSP : I16_Z_8<0b011, (ins GPRSP:$sp, uimm8_2:$imm8),
"addi16\t$rz, $sp, $imm8">;
@@ -483,39 +486,34 @@ def : Pat<(brcond CARRY:$ca, bb:$offset),
def : Pat<(br bb:$offset), (BR16 bb:$offset)>;
-def : Pat<(brcond (i32 (setne mGPR:$rs1, uimm5:$rs2)), bb:$offset),
- (BT16 (CMPNEI16 mGPR:$rs1, uimm5:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (seteq mGPR:$rs1, uimm5:$rs2)), bb:$offset),
- (BF16 (CMPNEI16 mGPR:$rs1, uimm5:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (setuge mGPR:$rs1, oimm5:$rs2)), bb:$offset),
- (BT16 (CMPHSI16 mGPR:$rs1, oimm5:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (setult mGPR:$rs1, oimm5:$rs2)), bb:$offset),
- (BF16 (CMPHSI16 mGPR:$rs1, oimm5:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (setlt mGPR:$rs1, oimm5:$rs2)), bb:$offset),
- (BT16 (CMPLTI16 mGPR:$rs1, oimm5:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (setge mGPR:$rs1, oimm5:$rs2)), bb:$offset),
- (BF16 (CMPLTI16 mGPR:$rs1, oimm5:$rs2), bb:$offset)>;
+multiclass BTF16Pat0<PatFrag cond0, PatFrag cond1, ImmLeaf imm_ty, Instruction inst> {
+ def : Pat<(brcond (i32 (cond0 mGPR:$rs1, imm_ty:$rs2)), bb:$offset),
+ (BT16 (inst mGPR:$rs1, imm_ty:$rs2), bb:$offset)>;
+ def : Pat<(brcond (i32 (cond1 mGPR:$rs1, imm_ty:$rs2)), bb:$offset),
+ (BF16 (inst mGPR:$rs1, imm_ty:$rs2), bb:$offset)>;
+}
+
+defm : BTF16Pat0<setne, seteq, uimm5, CMPNEI16>;
+defm : BTF16Pat0<setuge, setult, oimm5, CMPHSI16>;
+defm : BTF16Pat0<setlt, setge, oimm5, CMPLTI16>;
def : Pat<(brcond (i32 (setne sGPR:$rs1, sGPR:$rs2)), bb:$offset),
(BT16 (CMPNE16 sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
def : Pat<(brcond (i32 (seteq sGPR:$rs1, sGPR:$rs2)), bb:$offset),
(BF16 (CMPNE16 sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (setuge sGPR:$rs1, sGPR:$rs2)), bb:$offset),
- (BT16 (CMPHS16 sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (setule sGPR:$rs1, sGPR:$rs2)), bb:$offset),
- (BT16 (CMPHS16 sGPR:$rs2, sGPR:$rs1), bb:$offset)>;
-def : Pat<(brcond (i32 (setult sGPR:$rs1, sGPR:$rs2)), bb:$offset),
- (BF16 (CMPHS16 sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (setugt sGPR:$rs1, sGPR:$rs2)), bb:$offset),
- (BF16 (CMPHS16 sGPR:$rs2, sGPR:$rs1), bb:$offset)>;
-def : Pat<(brcond (i32 (setlt sGPR:$rs1, sGPR:$rs2)), bb:$offset),
- (BT16 (CMPLT16 sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (setgt sGPR:$rs1, sGPR:$rs2)), bb:$offset),
- (BT16 (CMPLT16 sGPR:$rs2, sGPR:$rs1), bb:$offset)>;
-def : Pat<(brcond (i32 (setge sGPR:$rs1, sGPR:$rs2)), bb:$offset),
- (BF16 (CMPLT16 sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
-def : Pat<(brcond (i32 (setle sGPR:$rs1, sGPR:$rs2)), bb:$offset),
- (BF16 (CMPLT16 sGPR:$rs2, sGPR:$rs1), bb:$offset)>;
+
+multiclass BTF16Pat1<PatFrag cond0, PatFrag cond1, Instruction cmp,
+ Instruction br> {
+ def : Pat<(brcond (i32 (cond0 sGPR:$rs1, sGPR:$rs2)), bb:$offset),
+ (br (cmp sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
+ def : Pat<(brcond (i32 (cond1 sGPR:$rs1, sGPR:$rs2)), bb:$offset),
+ (br (cmp sGPR:$rs2, sGPR:$rs1), bb:$offset)>;
+}
+
+defm : BTF16Pat1<setuge, setule, CMPHS16, BT16>;
+defm : BTF16Pat1<setult, setugt, CMPHS16, BF16>;
+defm : BTF16Pat1<setlt, setgt, CMPLT16, BT16>;
+defm : BTF16Pat1<setge, setle, CMPLT16, BF16>;
// Compare Patterns.
def : Pat<(setne sGPR:$rs1, sGPR:$rs2),
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYSubtarget.h b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYSubtarget.h
index 9e7ad00c0a50..b8be347935ac 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYSubtarget.h
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYSubtarget.h
@@ -206,6 +206,8 @@ public:
bool isCK810V() const { return CSKYProcFamily == CK810V; }
bool isCK860() const { return CSKYProcFamily == CK860; }
bool isCK860V() const { return CSKYProcFamily == CK860V; }
+
+ const unsigned XLen = 32;
};
} // namespace llvm
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/Disassembler/CSKYDisassembler.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/Disassembler/CSKYDisassembler.cpp
index ce0f63b99d68..d78d9acc2aa2 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/Disassembler/CSKYDisassembler.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/Disassembler/CSKYDisassembler.cpp
@@ -496,9 +496,9 @@ static bool decodeFPUV3Instruction(MCInst &MI, uint32_t insn, uint64_t Address,
const MCDisassembler *DisAsm,
const MCSubtargetInfo &STI) {
LLVM_DEBUG(dbgs() << "Trying CSKY 32-bit fpuv3 table :\n");
- if (!STI.getFeatureBits()[CSKY::FeatureFPUV3_HF] &&
- !STI.getFeatureBits()[CSKY::FeatureFPUV3_SF] &&
- !STI.getFeatureBits()[CSKY::FeatureFPUV3_DF])
+ if (!STI.hasFeature(CSKY::FeatureFPUV3_HF) &&
+ !STI.hasFeature(CSKY::FeatureFPUV3_SF) &&
+ !STI.hasFeature(CSKY::FeatureFPUV3_DF))
return false;
DecodeStatus Result =
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp
index 4171a97e9000..d53d2e9e00e9 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp
@@ -248,7 +248,7 @@ bool CSKYAsmBackend::mayNeedRelaxation(const MCInst &Inst,
case CSKY::JBT32:
case CSKY::JBF32:
case CSKY::JBSR32:
- if (!STI.getFeatureBits()[CSKY::Has2E3])
+ if (!STI.hasFeature(CSKY::Has2E3))
return false;
return true;
case CSKY::JBR16:
@@ -330,7 +330,7 @@ void CSKYAsmBackend::relaxInstruction(MCInst &Inst,
case CSKY::JBF16:
// ck801
unsigned opcode;
- if (STI.getFeatureBits()[CSKY::HasE2])
+ if (STI.hasFeature(CSKY::HasE2))
opcode = Inst.getOpcode() == CSKY::JBT16 ? CSKY::JBT32 : CSKY::JBF32;
else
opcode = Inst.getOpcode() == CSKY::JBT16 ? CSKY::JBT_E : CSKY::JBF_E;
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
index d7cc4c8525ee..2548c83770ff 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
@@ -117,6 +117,12 @@ unsigned CSKYELFObjectWriter::getRelocType(MCContext &Ctx,
return ELF::R_CKCORE_GOTOFF;
case MCSymbolRefExpr::VK_PLT:
return ELF::R_CKCORE_PLT32;
+ case MCSymbolRefExpr::VK_TLSGD:
+ return ELF::R_CKCORE_TLS_GD32;
+ case MCSymbolRefExpr::VK_TLSLDM:
+ return ELF::R_CKCORE_TLS_LDM32;
+ case MCSymbolRefExpr::VK_TPOFF:
+ return ELF::R_CKCORE_TLS_LE32;
case MCSymbolRefExpr::VK_None:
return ELF::R_CKCORE_ADDR32;
}
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp
index 90775c1b70f2..059c3c143c31 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFStreamer.cpp
@@ -21,9 +21,9 @@
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/Support/CSKYAttributes.h"
-#include "llvm/Support/CSKYTargetParser.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/LEB128.h"
+#include "llvm/TargetParser/CSKYTargetParser.h"
using namespace llvm;
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp
index 3e4fdb5e67c3..9af7958112fc 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYInstPrinter.cpp
@@ -113,7 +113,7 @@ void CSKYInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
if (Reg == CSKY::C)
O << "";
- else if (STI.getFeatureBits()[CSKY::FeatureJAVA]) {
+ else if (STI.hasFeature(CSKY::FeatureJAVA)) {
if (Reg == CSKY::R23)
O << (useABIName ? "fp" : "r23");
else if (Reg == CSKY::R24)
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp
index 540f901fd479..ea41d53ef30f 100644
--- a/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp
@@ -82,7 +82,7 @@ void CSKYMCCodeEmitter::expandJBTF(const MCInst &MI, raw_ostream &OS,
Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
writeData(Binary, 2, OS);
- if (!STI.getFeatureBits()[CSKY::Has2E3])
+ if (!STI.hasFeature(CSKY::Has2E3))
TmpInst = MCInstBuilder(CSKY::BR32)
.addOperand(MI.getOperand(1))
.addOperand(MI.getOperand(2));