[llvm-commits] [llvm] r55539 - in /llvm/trunk: lib/AsmParser/llvmAsmParser.y test/Assembler/numbered-values.ll
Chris Lattner
sabre at nondot.org
Fri Aug 29 10:12:15 PDT 2008
Author: lattner
Date: Fri Aug 29 12:12:13 2008
New Revision: 55539
URL: http://llvm.org/viewvc/llvm-project?rev=55539&view=rev
Log:
Add support for parsing .ll files that have numbers in front of
nameless values, such as:
%3 = add i32 4, 2
This fixes the first half of PR2480
Added:
llvm/trunk/test/Assembler/numbered-values.ll
Modified:
llvm/trunk/lib/AsmParser/llvmAsmParser.y
Modified: llvm/trunk/lib/AsmParser/llvmAsmParser.y
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/llvmAsmParser.y?rev=55539&r1=55538&r2=55539&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/llvmAsmParser.y (original)
+++ llvm/trunk/lib/AsmParser/llvmAsmParser.y Fri Aug 29 12:12:13 2008
@@ -249,10 +249,12 @@
// Code to handle definitions of all the types
//===----------------------------------------------------------------------===//
-static void InsertValue(Value *V, ValueList &ValueTab = CurFun.Values) {
+/// InsertValue - Insert a value into the value table. If it is named, this
+/// returns -1, otherwise it returns the slot number for the value.
+static int InsertValue(Value *V, ValueList &ValueTab = CurFun.Values) {
// Things that have names or are void typed don't get slot numbers
if (V->hasName() || (V->getType() == Type::VoidTy))
- return;
+ return -1;
// In the case of function values, we have to allow for the forward reference
// of basic blocks, which are included in the numbering. Consequently, we keep
@@ -262,10 +264,11 @@
if (ValueTab.size() <= CurFun.NextValNum)
ValueTab.resize(CurFun.NextValNum+1);
ValueTab[CurFun.NextValNum++] = V;
- return;
+ return CurFun.NextValNum-1;
}
// For all other lists, its okay to just tack it on the back of the vector.
ValueTab.push_back(V);
+ return ValueTab.size()-1;
}
static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
@@ -1084,7 +1087,7 @@
%token CC_TOK CCC_TOK FASTCC_TOK COLDCC_TOK X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
%token X86_SSECALLCC_TOK
%token DATALAYOUT
-%type <UIntVal> OptCallingConv
+%type <UIntVal> OptCallingConv LocalNumber
%type <ParamAttrs> OptParamAttrs ParamAttr
%type <ParamAttrs> OptFuncAttrs FuncAttr
@@ -1177,6 +1180,12 @@
CHECK_FOR_ERROR
};
+LocalNumber : LOCALVAL_ID '=' {
+ $$ = $1;
+ CHECK_FOR_ERROR
+};
+
+
GlobalName : GLOBALVAR | ATSTRINGCONSTANT ;
OptGlobalAssign : GlobalAssign
@@ -2673,7 +2682,7 @@
// Basic blocks are terminated by branching instructions:
// br, br/cc, switch, ret
//
-BasicBlock : InstructionList OptLocalAssign BBTerminatorInst {
+BasicBlock : InstructionList OptLocalAssign BBTerminatorInst {
setValueName($3, $2);
CHECK_FOR_ERROR
InsertValue($3);
@@ -2682,6 +2691,19 @@
CHECK_FOR_ERROR
};
+BasicBlock : InstructionList LocalNumber BBTerminatorInst {
+ CHECK_FOR_ERROR
+ int ValNum = InsertValue($3);
+ if (ValNum != (int)$2)
+ GEN_ERROR("Result value number %" + utostr($2) +
+ " is incorrect, expected %" + utostr((unsigned)ValNum));
+
+ $1->getInstList().push_back($3);
+ $$ = $1;
+ CHECK_FOR_ERROR
+};
+
+
InstructionList : InstructionList Inst {
if (CastInst *CI1 = dyn_cast<CastInst>($2))
if (CastInst *CI2 = dyn_cast<CastInst>(CI1->getOperand(0)))
@@ -2901,6 +2923,18 @@
CHECK_FOR_ERROR
};
+Inst : LocalNumber InstVal {
+ CHECK_FOR_ERROR
+ int ValNum = InsertValue($2);
+
+ if (ValNum != (int)$1)
+ GEN_ERROR("Result value number %" + utostr($1) +
+ " is incorrect, expected %" + utostr((unsigned)ValNum));
+
+ $$ = $2;
+ CHECK_FOR_ERROR
+ };
+
PHIList : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
if (!UpRefs.empty())
Added: llvm/trunk/test/Assembler/numbered-values.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/numbered-values.ll?rev=55539&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/numbered-values.ll (added)
+++ llvm/trunk/test/Assembler/numbered-values.ll Fri Aug 29 12:12:13 2008
@@ -0,0 +1,16 @@
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis
+; PR2480
+
+define i32 @test(i32 %X) nounwind {
+entry:
+ %X_addr = alloca i32 ; <i32*> [#uses=2]
+ %retval = alloca i32 ; <i32*> [#uses=2]
+ %0 = alloca i32 ; <i32*>:0 [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 %X, i32* %X_addr
+ %1 = load i32* %X_addr, align 4 ; <i32>:1 [#uses=1]
+ mul i32 %1, 4 ; <i32>:2 [#uses=1]
+ %3 = add i32 %2, 123 ; <i32>:3 [#uses=1]
+ store i32 %3, i32* %0, align 4
+ ret i32 %3
+}
More information about the llvm-commits
mailing list