mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
Implement upgrade of setcc instruction to icmp/fcmp, but don't enable it
yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32139 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a5ce97b15a
commit
2b40438597
@ -182,6 +182,28 @@ setlt { RET_TOK( SETLT); }
|
|||||||
setgt { RET_TOK( SETGT); }
|
setgt { RET_TOK( SETGT); }
|
||||||
setle { RET_TOK( SETLE); }
|
setle { RET_TOK( SETLE); }
|
||||||
setge { RET_TOK( SETGE); }
|
setge { RET_TOK( SETGE); }
|
||||||
|
icmp { RET_TOK(ICMP); }
|
||||||
|
fcmp { RET_TOK(FCMP); }
|
||||||
|
eq { RET_TOK(EQ); }
|
||||||
|
ne { RET_TOK(NE); }
|
||||||
|
slt { RET_TOK(SLT); }
|
||||||
|
sgt { RET_TOK(SGT); }
|
||||||
|
sle { RET_TOK(SLE); }
|
||||||
|
sge { RET_TOK(SGE); }
|
||||||
|
oeq { RET_TOK(OEQ); }
|
||||||
|
one { RET_TOK(ONE); }
|
||||||
|
olt { RET_TOK(OLT); }
|
||||||
|
ogt { RET_TOK(OGT); }
|
||||||
|
ole { RET_TOK(OLE); }
|
||||||
|
oge { RET_TOK(OGE); }
|
||||||
|
ord { RET_TOK(ORD); }
|
||||||
|
uno { RET_TOK(UNO); }
|
||||||
|
ueq { RET_TOK(UEQ); }
|
||||||
|
une { RET_TOK(UNE); }
|
||||||
|
ult { RET_TOK(ULT); }
|
||||||
|
ugt { RET_TOK(UGT); }
|
||||||
|
ule { RET_TOK(ULE); }
|
||||||
|
uge { RET_TOK(UGE); }
|
||||||
|
|
||||||
phi { RET_TOK( PHI_TOK); }
|
phi { RET_TOK( PHI_TOK); }
|
||||||
call { RET_TOK( CALL); }
|
call { RET_TOK( CALL); }
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#define YYERROR_VERBOSE 1
|
#define YYERROR_VERBOSE 1
|
||||||
#define YYINCLUDED_STDLIB_H
|
#define YYINCLUDED_STDLIB_H
|
||||||
#define YYDEBUG 1
|
#define YYDEBUG 1
|
||||||
|
#define UPGRADE_SETCOND_OPS 0
|
||||||
|
|
||||||
int yylex(); // declaration" of xxx warnings.
|
int yylex(); // declaration" of xxx warnings.
|
||||||
int yyparse();
|
int yyparse();
|
||||||
@ -232,6 +233,34 @@ const char* getDivRemOpcode(const std::string& opcode, const TypeInfo& TI) {
|
|||||||
yyerror("Invalid type for rem instruction");
|
yyerror("Invalid type for rem instruction");
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
getCompareOp(const std::string& setcc, const TypeInfo& TI) {
|
||||||
|
assert(setcc.length() == 5);
|
||||||
|
char cc1 = setcc[3];
|
||||||
|
char cc2 = setcc[4];
|
||||||
|
assert(cc1 == 'e' || cc1 == 'n' || cc1 == 'l' || cc1 == 'g');
|
||||||
|
assert(cc2 == 'q' || cc2 == 'e' || cc2 == 'e' || cc2 == 't');
|
||||||
|
std::string result("xcmp xxx");
|
||||||
|
result[6] = cc1;
|
||||||
|
result[7] = cc2;
|
||||||
|
if (TI.isFloatingPoint()) {
|
||||||
|
result[0] = 'f';
|
||||||
|
result[5] = 'o'; // FIXME: Always map to ordered comparison ?
|
||||||
|
} else if (TI.isIntegral() || TI.isPointer()) {
|
||||||
|
result[0] = 'i';
|
||||||
|
if ((cc1 == 'e' && cc2 == 'q') || (cc1 == 'n' && cc2 == 'e'))
|
||||||
|
result.erase(5,1);
|
||||||
|
else if (TI.isSigned())
|
||||||
|
result[5] = 's';
|
||||||
|
else if (TI.isUnsigned() || TI.isPointer())
|
||||||
|
result[5] = 'u';
|
||||||
|
else
|
||||||
|
yyerror("Invalid integral type for setcc");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%file-prefix="UpgradeParser"
|
%file-prefix="UpgradeParser"
|
||||||
@ -262,6 +291,8 @@ const char* getDivRemOpcode(const std::string& opcode, const TypeInfo& TI) {
|
|||||||
%token <String> RET BR SWITCH INVOKE EXCEPT UNWIND UNREACHABLE
|
%token <String> RET BR SWITCH INVOKE EXCEPT UNWIND UNREACHABLE
|
||||||
%token <String> ADD SUB MUL DIV UDIV SDIV FDIV REM UREM SREM FREM AND OR XOR
|
%token <String> ADD SUB MUL DIV UDIV SDIV FDIV REM UREM SREM FREM AND OR XOR
|
||||||
%token <String> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators
|
%token <String> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators
|
||||||
|
%token <String> ICMP FCMP EQ NE SLT SGT SLE SGE OEQ ONE OLT OGT OLE OGE
|
||||||
|
%token <String> ORD UNO UEQ UNE ULT UGT ULE UGE
|
||||||
%token <String> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
|
%token <String> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
|
||||||
%token <String> PHI_TOK SELECT SHL SHR ASHR LSHR VAARG
|
%token <String> PHI_TOK SELECT SHL SHR ASHR LSHR VAARG
|
||||||
%token <String> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
%token <String> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
||||||
@ -279,7 +310,8 @@ const char* getDivRemOpcode(const std::string& opcode, const TypeInfo& TI) {
|
|||||||
%type <String> MemoryInst SymbolicValueRef OptSideEffect GlobalType
|
%type <String> MemoryInst SymbolicValueRef OptSideEffect GlobalType
|
||||||
%type <String> FnDeclareLinkage BasicBlockList BigOrLittle AsmBlock
|
%type <String> FnDeclareLinkage BasicBlockList BigOrLittle AsmBlock
|
||||||
%type <String> Name ConstValueRef ConstVector External
|
%type <String> Name ConstValueRef ConstVector External
|
||||||
%type <String> ShiftOps SetCondOps LogicalOps ArithmeticOps CastOps
|
%type <String> ShiftOps SetCondOps LogicalOps ArithmeticOps CastOps CompareOps
|
||||||
|
%type <String> Predicates
|
||||||
|
|
||||||
%type <ValList> ValueRefList ValueRefListE IndexList
|
%type <ValList> ValueRefList ValueRefListE IndexList
|
||||||
|
|
||||||
@ -305,6 +337,9 @@ ArithmeticOps: ADD | SUB | MUL | DIV | UDIV | SDIV | FDIV
|
|||||||
| REM | UREM | SREM | FREM;
|
| REM | UREM | SREM | FREM;
|
||||||
LogicalOps : AND | OR | XOR;
|
LogicalOps : AND | OR | XOR;
|
||||||
SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
|
SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
|
||||||
|
CompareOps : ICMP | FCMP;
|
||||||
|
Predicates : EQ | NE | SLT | SGT | SLE | SGE | ULT | UGT | ULE | UGE
|
||||||
|
| OEQ | ONE | OLT | OGT | OLE | OGE | ORD | UNO | UEQ | UNE ;
|
||||||
ShiftOps : SHL | SHR | ASHR | LSHR;
|
ShiftOps : SHL | SHR | ASHR | LSHR;
|
||||||
CastOps : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | FPTOUI | FPTOSI |
|
CastOps : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | FPTOUI | FPTOSI |
|
||||||
UITOFP | SITOFP | PTRTOINT | INTTOPTR | BITCAST | CAST
|
UITOFP | SITOFP | PTRTOINT | INTTOPTR | BITCAST | CAST
|
||||||
@ -627,10 +662,18 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
|
|||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
| SetCondOps '(' ConstVal ',' ConstVal ')' {
|
| SetCondOps '(' ConstVal ',' ConstVal ')' {
|
||||||
|
#if UPGRADE_SETCOND_OPS
|
||||||
|
*$1 = getCompareOp(*$1, $3.type);
|
||||||
|
#endif
|
||||||
*$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
|
*$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
|
||||||
$3.destroy(); $5.destroy();
|
$3.destroy(); $5.destroy();
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
|
| CompareOps Predicates '(' ConstVal ',' ConstVal ')' {
|
||||||
|
*$1 += "(" + *$2 + "," + *$4.cnst + "," + *$6.cnst + ")";
|
||||||
|
delete $2; $4.destroy(); $6.destroy();
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
| ShiftOps '(' ConstVal ',' ConstVal ')' {
|
| ShiftOps '(' ConstVal ',' ConstVal ')' {
|
||||||
const char* shiftop = $1->c_str();
|
const char* shiftop = $1->c_str();
|
||||||
if (*$1 == "shr")
|
if (*$1 == "shr")
|
||||||
@ -1132,10 +1175,18 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
|||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
| SetCondOps Types ValueRef ',' ValueRef {
|
| SetCondOps Types ValueRef ',' ValueRef {
|
||||||
|
#if UPGRADE_SETCOND_OPS
|
||||||
|
*$1 = getCompareOp(*$1, $2);
|
||||||
|
#endif
|
||||||
*$1 += " " + *$2.newTy + " " + *$3.val + ", " + *$5.val;
|
*$1 += " " + *$2.newTy + " " + *$3.val + ", " + *$5.val;
|
||||||
$2.destroy(); $3.destroy(); $5.destroy();
|
$2.destroy(); $3.destroy(); $5.destroy();
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
|
| CompareOps Predicates Types ValueRef ',' ValueRef ')' {
|
||||||
|
*$1 += " " + *$2 + " " + *$4.val + "," + *$6.val + ")";
|
||||||
|
delete $2; $4.destroy(); $6.destroy();
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
| NOT ResolvedVal {
|
| NOT ResolvedVal {
|
||||||
*$1 += " " + *$2.val;
|
*$1 += " " + *$2.val;
|
||||||
$2.destroy();
|
$2.destroy();
|
||||||
|
Loading…
Reference in New Issue
Block a user