mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Make structs and arrays first-class types, and add assembly
and bitcode support for the extractvalue and insertvalue instructions and constant expressions. Note that this does not yet include CodeGen support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51468 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -605,6 +605,8 @@ int LLLexer::LexIdentifier() {
|
||||
INSTKEYWORD("insertelement", OtherOpVal, InsertElement, INSERTELEMENT);
|
||||
INSTKEYWORD("shufflevector", OtherOpVal, ShuffleVector, SHUFFLEVECTOR);
|
||||
INSTKEYWORD("getresult", OtherOpVal, GetResult, GETRESULT);
|
||||
INSTKEYWORD("extractvalue", OtherOpVal, ExtractValue, EXTRACTVALUE);
|
||||
INSTKEYWORD("insertvalue", OtherOpVal, InsertValue, INSERTVALUE);
|
||||
#undef INSTKEYWORD
|
||||
|
||||
// Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -175,21 +175,23 @@
|
||||
INSERTELEMENT = 391,
|
||||
SHUFFLEVECTOR = 392,
|
||||
GETRESULT = 393,
|
||||
SIGNEXT = 394,
|
||||
ZEROEXT = 395,
|
||||
NORETURN = 396,
|
||||
INREG = 397,
|
||||
SRET = 398,
|
||||
NOUNWIND = 399,
|
||||
NOALIAS = 400,
|
||||
BYVAL = 401,
|
||||
NEST = 402,
|
||||
READNONE = 403,
|
||||
READONLY = 404,
|
||||
GC = 405,
|
||||
DEFAULT = 406,
|
||||
HIDDEN = 407,
|
||||
PROTECTED = 408
|
||||
EXTRACTVALUE = 394,
|
||||
INSERTVALUE = 395,
|
||||
SIGNEXT = 396,
|
||||
ZEROEXT = 397,
|
||||
NORETURN = 398,
|
||||
INREG = 399,
|
||||
SRET = 400,
|
||||
NOUNWIND = 401,
|
||||
NOALIAS = 402,
|
||||
BYVAL = 403,
|
||||
NEST = 404,
|
||||
READNONE = 405,
|
||||
READONLY = 406,
|
||||
GC = 407,
|
||||
DEFAULT = 408,
|
||||
HIDDEN = 409,
|
||||
PROTECTED = 410
|
||||
};
|
||||
#endif
|
||||
/* Tokens. */
|
||||
@@ -329,28 +331,30 @@
|
||||
#define INSERTELEMENT 391
|
||||
#define SHUFFLEVECTOR 392
|
||||
#define GETRESULT 393
|
||||
#define SIGNEXT 394
|
||||
#define ZEROEXT 395
|
||||
#define NORETURN 396
|
||||
#define INREG 397
|
||||
#define SRET 398
|
||||
#define NOUNWIND 399
|
||||
#define NOALIAS 400
|
||||
#define BYVAL 401
|
||||
#define NEST 402
|
||||
#define READNONE 403
|
||||
#define READONLY 404
|
||||
#define GC 405
|
||||
#define DEFAULT 406
|
||||
#define HIDDEN 407
|
||||
#define PROTECTED 408
|
||||
#define EXTRACTVALUE 394
|
||||
#define INSERTVALUE 395
|
||||
#define SIGNEXT 396
|
||||
#define ZEROEXT 397
|
||||
#define NORETURN 398
|
||||
#define INREG 399
|
||||
#define SRET 400
|
||||
#define NOUNWIND 401
|
||||
#define NOALIAS 402
|
||||
#define BYVAL 403
|
||||
#define NEST 404
|
||||
#define READNONE 405
|
||||
#define READONLY 406
|
||||
#define GC 407
|
||||
#define DEFAULT 408
|
||||
#define HIDDEN 409
|
||||
#define PROTECTED 410
|
||||
|
||||
|
||||
|
||||
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
#line 949 "/Volumes/LLVM/llvm/lib/AsmParser/llvmAsmParser.y"
|
||||
#line 949 "/Users/gohman/LLVM/llvm/lib/AsmParser/llvmAsmParser.y"
|
||||
{
|
||||
llvm::Module *ModuleVal;
|
||||
llvm::Function *FunctionVal;
|
||||
@@ -398,7 +402,7 @@ typedef union YYSTYPE
|
||||
llvm::FCmpInst::Predicate FPredicate;
|
||||
}
|
||||
/* Line 1529 of yacc.c. */
|
||||
#line 402 "llvmAsmParser.tab.h"
|
||||
#line 406 "llvmAsmParser.tab.h"
|
||||
YYSTYPE;
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
|
@@ -475,7 +475,7 @@ static Value *getVal(const Type *Ty, const ValID &ID) {
|
||||
if (TriggerError) return 0;
|
||||
|
||||
if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty)) {
|
||||
GenerateError("Invalid use of a composite type");
|
||||
GenerateError("Invalid use of a non-first-class type");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1093,6 +1093,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
|
||||
%token <OtherOpVal> PHI_TOK SELECT VAARG
|
||||
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
||||
%token <OtherOpVal> GETRESULT
|
||||
%token <OtherOpVal> EXTRACTVALUE INSERTVALUE
|
||||
|
||||
// Function Attributes
|
||||
%token SIGNEXT ZEROEXT NORETURN INREG SRET NOUNWIND NOALIAS BYVAL NEST
|
||||
@@ -1966,6 +1967,48 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
|
||||
GEN_ERROR("Invalid shufflevector operands");
|
||||
$$ = ConstantExpr::getShuffleVector($3, $5, $7);
|
||||
CHECK_FOR_ERROR
|
||||
}
|
||||
| EXTRACTVALUE '(' ConstVal IndexList ')' {
|
||||
if (!isa<StructType>($3->getType()) && !isa<ArrayType>($3->getType()))
|
||||
GEN_ERROR("ExtractValue requires an aggregate operand");
|
||||
|
||||
const Type *IdxTy =
|
||||
ExtractValueInst::getIndexedType($3->getType(), $4->begin(), $4->end());
|
||||
if (!IdxTy)
|
||||
GEN_ERROR("Index list invalid for constant extractvalue");
|
||||
|
||||
SmallVector<Constant*, 8> IdxVec;
|
||||
for (unsigned i = 0, e = $4->size(); i != e; ++i)
|
||||
if (Constant *C = dyn_cast<Constant>((*$4)[i]))
|
||||
IdxVec.push_back(C);
|
||||
else
|
||||
GEN_ERROR("Indices to constant extractvalue must be constants");
|
||||
|
||||
delete $4;
|
||||
|
||||
$$ = ConstantExpr::getExtractValue($3, &IdxVec[0], IdxVec.size());
|
||||
CHECK_FOR_ERROR
|
||||
}
|
||||
| INSERTVALUE '(' ConstVal ',' ConstVal IndexList ')' {
|
||||
if (!isa<StructType>($3->getType()) && !isa<ArrayType>($3->getType()))
|
||||
GEN_ERROR("InsertValue requires an aggregate operand");
|
||||
|
||||
const Type *IdxTy =
|
||||
ExtractValueInst::getIndexedType($3->getType(), $6->begin(), $6->end());
|
||||
if (IdxTy != $5->getType())
|
||||
GEN_ERROR("Index list invalid for constant insertvalue");
|
||||
|
||||
SmallVector<Constant*, 8> IdxVec;
|
||||
for (unsigned i = 0, e = $6->size(); i != e; ++i)
|
||||
if (Constant *C = dyn_cast<Constant>((*$6)[i]))
|
||||
IdxVec.push_back(C);
|
||||
else
|
||||
GEN_ERROR("Indices to constant insertvalue must be constants");
|
||||
|
||||
delete $6;
|
||||
|
||||
$$ = ConstantExpr::getInsertValue($3, $5, &IdxVec[0], IdxVec.size());
|
||||
CHECK_FOR_ERROR
|
||||
};
|
||||
|
||||
|
||||
@@ -3165,7 +3208,7 @@ MemoryInst : MALLOC Types OptCAlign {
|
||||
$$ = new StoreInst($3, tmpVal, $1, $7);
|
||||
delete $5;
|
||||
}
|
||||
| GETRESULT Types ValueRef ',' EUINT64VAL {
|
||||
| GETRESULT Types ValueRef ',' EUINT64VAL {
|
||||
Value *TmpVal = getVal($2->get(), $3);
|
||||
if (!GetResultInst::isValidOperands(TmpVal, $5))
|
||||
GEN_ERROR("Invalid getresult operands");
|
||||
@@ -3187,6 +3230,38 @@ MemoryInst : MALLOC Types OptCAlign {
|
||||
$$ = GetElementPtrInst::Create(tmpVal, $4->begin(), $4->end());
|
||||
delete $2;
|
||||
delete $4;
|
||||
}
|
||||
| EXTRACTVALUE Types ValueRef IndexList {
|
||||
if (!UpRefs.empty())
|
||||
GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
|
||||
if (!isa<StructType>($2->get()) && !isa<ArrayType>($2->get()))
|
||||
GEN_ERROR("extractvalue insn requires an aggregate operand");
|
||||
|
||||
if (!ExtractValueInst::getIndexedType(*$2, $4->begin(), $4->end()))
|
||||
GEN_ERROR("Invalid extractvalue indices for type '" +
|
||||
(*$2)->getDescription()+ "'");
|
||||
Value* tmpVal = getVal(*$2, $3);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = ExtractValueInst::Create(tmpVal, $4->begin(), $4->end());
|
||||
delete $2;
|
||||
delete $4;
|
||||
}
|
||||
| INSERTVALUE Types ValueRef ',' Types ValueRef IndexList {
|
||||
if (!UpRefs.empty())
|
||||
GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
|
||||
if (!isa<StructType>($2->get()) && !isa<ArrayType>($2->get()))
|
||||
GEN_ERROR("extractvalue insn requires an aggregate operand");
|
||||
|
||||
if (ExtractValueInst::getIndexedType(*$2, $7->begin(), $7->end()) != $5->get())
|
||||
GEN_ERROR("Invalid insertvalue indices for type '" +
|
||||
(*$2)->getDescription()+ "'");
|
||||
Value* aggVal = getVal(*$2, $3);
|
||||
Value* tmpVal = getVal(*$5, $6);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = InsertValueInst::Create(aggVal, tmpVal, $7->begin(), $7->end());
|
||||
delete $2;
|
||||
delete $5;
|
||||
delete $7;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -475,7 +475,7 @@ static Value *getVal(const Type *Ty, const ValID &ID) {
|
||||
if (TriggerError) return 0;
|
||||
|
||||
if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty)) {
|
||||
GenerateError("Invalid use of a composite type");
|
||||
GenerateError("Invalid use of a non-first-class type");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1093,6 +1093,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
|
||||
%token <OtherOpVal> PHI_TOK SELECT VAARG
|
||||
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
||||
%token <OtherOpVal> GETRESULT
|
||||
%token <OtherOpVal> EXTRACTVALUE INSERTVALUE
|
||||
|
||||
// Function Attributes
|
||||
%token SIGNEXT ZEROEXT NORETURN INREG SRET NOUNWIND NOALIAS BYVAL NEST
|
||||
@@ -1966,6 +1967,48 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
|
||||
GEN_ERROR("Invalid shufflevector operands");
|
||||
$$ = ConstantExpr::getShuffleVector($3, $5, $7);
|
||||
CHECK_FOR_ERROR
|
||||
}
|
||||
| EXTRACTVALUE '(' ConstVal IndexList ')' {
|
||||
if (!isa<StructType>($3->getType()) && !isa<ArrayType>($3->getType()))
|
||||
GEN_ERROR("ExtractValue requires an aggregate operand");
|
||||
|
||||
const Type *IdxTy =
|
||||
ExtractValueInst::getIndexedType($3->getType(), $4->begin(), $4->end());
|
||||
if (!IdxTy)
|
||||
GEN_ERROR("Index list invalid for constant extractvalue");
|
||||
|
||||
SmallVector<Constant*, 8> IdxVec;
|
||||
for (unsigned i = 0, e = $4->size(); i != e; ++i)
|
||||
if (Constant *C = dyn_cast<Constant>((*$4)[i]))
|
||||
IdxVec.push_back(C);
|
||||
else
|
||||
GEN_ERROR("Indices to constant extractvalue must be constants");
|
||||
|
||||
delete $4;
|
||||
|
||||
$$ = ConstantExpr::getExtractValue($3, &IdxVec[0], IdxVec.size());
|
||||
CHECK_FOR_ERROR
|
||||
}
|
||||
| INSERTVALUE '(' ConstVal ',' ConstVal IndexList ')' {
|
||||
if (!isa<StructType>($3->getType()) && !isa<ArrayType>($3->getType()))
|
||||
GEN_ERROR("InsertValue requires an aggregate operand");
|
||||
|
||||
const Type *IdxTy =
|
||||
ExtractValueInst::getIndexedType($3->getType(), $6->begin(), $6->end());
|
||||
if (IdxTy != $5->getType())
|
||||
GEN_ERROR("Index list invalid for constant insertvalue");
|
||||
|
||||
SmallVector<Constant*, 8> IdxVec;
|
||||
for (unsigned i = 0, e = $6->size(); i != e; ++i)
|
||||
if (Constant *C = dyn_cast<Constant>((*$6)[i]))
|
||||
IdxVec.push_back(C);
|
||||
else
|
||||
GEN_ERROR("Indices to constant insertvalue must be constants");
|
||||
|
||||
delete $6;
|
||||
|
||||
$$ = ConstantExpr::getInsertValue($3, $5, &IdxVec[0], IdxVec.size());
|
||||
CHECK_FOR_ERROR
|
||||
};
|
||||
|
||||
|
||||
@@ -2852,7 +2895,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
CHECK_FOR_ERROR
|
||||
Value* val2 = getVal(*$2, $5);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = BinaryOperator::create($1, val1, val2);
|
||||
$$ = BinaryOperator::Create($1, val1, val2);
|
||||
if ($$ == 0)
|
||||
GEN_ERROR("binary operator returned null");
|
||||
delete $2;
|
||||
@@ -2869,7 +2912,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
CHECK_FOR_ERROR
|
||||
Value* tmpVal2 = getVal(*$2, $5);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = BinaryOperator::create($1, tmpVal1, tmpVal2);
|
||||
$$ = BinaryOperator::Create($1, tmpVal1, tmpVal2);
|
||||
if ($$ == 0)
|
||||
GEN_ERROR("binary operator returned null");
|
||||
delete $2;
|
||||
@@ -2883,7 +2926,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
CHECK_FOR_ERROR
|
||||
Value* tmpVal2 = getVal(*$3, $6);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
|
||||
$$ = CmpInst::Create($1, $2, tmpVal1, tmpVal2);
|
||||
if ($$ == 0)
|
||||
GEN_ERROR("icmp operator returned null");
|
||||
delete $3;
|
||||
@@ -2897,7 +2940,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
CHECK_FOR_ERROR
|
||||
Value* tmpVal2 = getVal(*$3, $6);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
|
||||
$$ = CmpInst::Create($1, $2, tmpVal1, tmpVal2);
|
||||
if ($$ == 0)
|
||||
GEN_ERROR("fcmp operator returned null");
|
||||
delete $3;
|
||||
@@ -2911,7 +2954,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
CHECK_FOR_ERROR
|
||||
Value* tmpVal2 = getVal(*$3, $6);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
|
||||
$$ = CmpInst::Create($1, $2, tmpVal1, tmpVal2);
|
||||
if ($$ == 0)
|
||||
GEN_ERROR("icmp operator returned null");
|
||||
delete $3;
|
||||
@@ -2925,7 +2968,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
CHECK_FOR_ERROR
|
||||
Value* tmpVal2 = getVal(*$3, $6);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
|
||||
$$ = CmpInst::Create($1, $2, tmpVal1, tmpVal2);
|
||||
if ($$ == 0)
|
||||
GEN_ERROR("fcmp operator returned null");
|
||||
delete $3;
|
||||
@@ -2939,7 +2982,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
||||
GEN_ERROR("invalid cast opcode for cast from '" +
|
||||
Val->getType()->getDescription() + "' to '" +
|
||||
DestTy->getDescription() + "'");
|
||||
$$ = CastInst::create($1, Val, DestTy);
|
||||
$$ = CastInst::Create($1, Val, DestTy);
|
||||
delete $4;
|
||||
}
|
||||
| SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
|
||||
@@ -3165,7 +3208,7 @@ MemoryInst : MALLOC Types OptCAlign {
|
||||
$$ = new StoreInst($3, tmpVal, $1, $7);
|
||||
delete $5;
|
||||
}
|
||||
| GETRESULT Types ValueRef ',' EUINT64VAL {
|
||||
| GETRESULT Types ValueRef ',' EUINT64VAL {
|
||||
Value *TmpVal = getVal($2->get(), $3);
|
||||
if (!GetResultInst::isValidOperands(TmpVal, $5))
|
||||
GEN_ERROR("Invalid getresult operands");
|
||||
@@ -3187,6 +3230,38 @@ MemoryInst : MALLOC Types OptCAlign {
|
||||
$$ = GetElementPtrInst::Create(tmpVal, $4->begin(), $4->end());
|
||||
delete $2;
|
||||
delete $4;
|
||||
}
|
||||
| EXTRACTVALUE Types ValueRef IndexList {
|
||||
if (!UpRefs.empty())
|
||||
GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
|
||||
if (!isa<StructType>($2->get()) && !isa<ArrayType>($2->get()))
|
||||
GEN_ERROR("extractvalue insn requires an aggregate operand");
|
||||
|
||||
if (!ExtractValueInst::getIndexedType(*$2, $4->begin(), $4->end()))
|
||||
GEN_ERROR("Invalid extractvalue indices for type '" +
|
||||
(*$2)->getDescription()+ "'");
|
||||
Value* tmpVal = getVal(*$2, $3);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = ExtractValueInst::Create(tmpVal, $4->begin(), $4->end());
|
||||
delete $2;
|
||||
delete $4;
|
||||
}
|
||||
| INSERTVALUE Types ValueRef ',' Types ValueRef IndexList {
|
||||
if (!UpRefs.empty())
|
||||
GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
|
||||
if (!isa<StructType>($2->get()) && !isa<ArrayType>($2->get()))
|
||||
GEN_ERROR("extractvalue insn requires an aggregate operand");
|
||||
|
||||
if (ExtractValueInst::getIndexedType(*$2, $7->begin(), $7->end()) != $5->get())
|
||||
GEN_ERROR("Invalid insertvalue indices for type '" +
|
||||
(*$2)->getDescription()+ "'");
|
||||
Value* aggVal = getVal(*$2, $3);
|
||||
Value* tmpVal = getVal(*$5, $6);
|
||||
CHECK_FOR_ERROR
|
||||
$$ = InsertValueInst::Create(aggVal, tmpVal, $7->begin(), $7->end());
|
||||
delete $2;
|
||||
delete $5;
|
||||
delete $7;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user