[llvm-commits] [SignlessTypes] CVS: llvm/lib/AsmParser/llvmAsmParser.y
Reid Spencer
reid at x10sys.com
Wed Oct 25 18:58:36 PDT 2006
Changes in directory llvm/lib/AsmParser:
llvmAsmParser.y updated: 1.266.2.8 -> 1.266.2.9
---
Log message:
Round 2 of DIV updates.
---
Diffs of the changes: (+47 -45)
llvmAsmParser.y | 92 ++++++++++++++++++++++++++++----------------------------
1 files changed, 47 insertions(+), 45 deletions(-)
Index: llvm/lib/AsmParser/llvmAsmParser.y
diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.266.2.8 llvm/lib/AsmParser/llvmAsmParser.y:1.266.2.9
--- llvm/lib/AsmParser/llvmAsmParser.y:1.266.2.8 Mon Oct 23 13:13:26 2006
+++ llvm/lib/AsmParser/llvmAsmParser.y Wed Oct 25 20:58:05 2006
@@ -813,50 +813,48 @@
return Ty;
}
-// This template function is used to obtain the correct opcode for an
-// instruction when an obsolete opcode is encountered. The OpcodeInfo template
-// keeps track of the opcode and the "obsolete" flag. These are generated by
-// the lexer and obsolete will be true when the lexer encounters the token for
+// This function is used to obtain the correct opcode for an instruction when
+// an obsolete opcode is encountered. The OI parameter (OpcodeInfo) has both
+// an opcode and an "obsolete" flag. These are generated by the lexer and
+// the "obsolete" member will be true when the lexer encounters the token for
// an obsolete opcode. For example, "div" was replaced by [usf]div but we need
// to maintain backwards compatibility for asm files that still have the "div"
// instruction. This function handles converting div -> [usf]div appropriately.
-template <class EnumKind>
-static void sanitizeOpCode(OpcodeInfo<EnumKind> &OI, const PATypeHolder& Ty) {
- if (OI.obsolete) {
- switch (OI.opcode) {
- default:
- GenerateError("Invalid Obsolete OpCode");
- break;
- case Instruction::UDiv:
- if (Ty->isFloatingPoint())
- OI.opcode = Instruction::FDiv;
- else if (Ty->isSigned())
- OI.opcode = Instruction::SDiv;
- break;
- case Instruction::SDiv:
- if (Ty->isFloatingPoint())
- OI.opcode = Instruction::FDiv;
- else if (Ty->isUnsigned())
- OI.opcode = Instruction::UDiv;
- break;
- case Instruction::URem:
- if (Ty->isFloatingPoint())
- OI.opcode = Instruction::FRem;
- else if (Ty->isSigned())
- OI.opcode = Instruction::SRem;
- break;
- case Instruction::SRem:
- if (Ty->isFloatingPoint())
- OI.opcode = Instruction::FRem;
- else if (Ty->isUnsigned())
- OI.opcode = Instruction::URem;
- break;
- }
- OI.obsolete = false;
+static void
+sanitizeOpCode(OpcodeInfo<Instruction::BinaryOps> &OI, const PATypeHolder& PATy)
+{
+ // If its not obsolete, don't do anything
+ if (!OI.obsolete)
+ return;
+
+ // If its a packed type we want to use the element type
+ const Type* Ty = PATy;
+ if (const PackedType* PTy = dyn_cast<PackedType>(Ty))
+ Ty = PTy->getElementType();
+
+ // Depending on the opcode ..
+ switch (OI.opcode) {
+ default:
+ GenerateError("Invalid Obsolete OpCode");
+ break;
+ case Instruction::UDiv:
+ // Handle cases where the opcode needs to change
+ if (Ty->isFloatingPoint())
+ OI.opcode = Instruction::FDiv;
+ else if (Ty->isSigned())
+ OI.opcode = Instruction::SDiv;
+ break;
+ case Instruction::URem:
+ if (Ty->isFloatingPoint())
+ OI.opcode = Instruction::FRem;
+ else if (Ty->isSigned())
+ OI.opcode = Instruction::SRem;
+ break;
}
+ // Its not obsolete any more, we fixed it.
+ OI.obsolete = false;
}
-
-
+
// common code from the two 'RunVMAsmParser' functions
static Module* RunParser(Module * M) {
@@ -1045,13 +1043,13 @@
bool BoolVal;
char *StrVal; // This memory is strdup'd!
- llvm::ValID ValIDVal; // strdup'd memory maybe!
+ llvm::ValID ValIDVal; // strdup'd memory maybe!
- BinaryOpInfo BinaryOpVal;
- TermOpInfo TermOpVal;
- MemOpInfo MemOpVal;
- OtherOpInfo OtherOpVal;
- llvm::Module::Endianness Endianness;
+ BinaryOpInfo BinaryOpVal;
+ TermOpInfo TermOpVal;
+ MemOpInfo MemOpVal;
+ OtherOpInfo OtherOpVal;
+ llvm::Module::Endianness Endianness;
}
%type <ModuleVal> Module FunctionList
@@ -1685,8 +1683,11 @@
| ArithmeticOps '(' ConstVal ',' ConstVal ')' {
if ($3->getType() != $5->getType())
GEN_ERROR("Binary operator types must match!");
+ // First, make sure we're dealing with the right opcode by upgrading from
+ // obsolete versions.
sanitizeOpCode($1,$3->getType());
CHECK_FOR_ERROR;
+
// HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
// To retain backward compatibility with these early compilers, we emit a
// cast to the appropriate integer type automatically if we are in the
@@ -2473,6 +2474,7 @@
if (isa<PackedType>((*$2).get()) &&
($1.opcode == Instruction::URem || $1.opcode == Instruction::SRem))
GEN_ERROR("URem and SRem not supported on packed types!");
+ // Upgrade the opcode from obsolete versions before we do anything with it.
sanitizeOpCode($1,*$2);
CHECK_FOR_ERROR;
Value* val1 = getVal(*$2, $3);
More information about the llvm-commits
mailing list