Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
IR: print value numbers for unnamed function arguments
Browse files Browse the repository at this point in the history
For consistency with normal instructions and clarity when reading IR,
it's best to print the %0, %1, ... names of function arguments in
definitions.

Also modifies the parser to accept IR in that form for obvious reasons.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367755 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
TNorthover committed Aug 3, 2019
1 parent a6035d1 commit 61325b6
Show file tree
Hide file tree
Showing 49 changed files with 394 additions and 258 deletions.
7 changes: 7 additions & 0 deletions docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ Non-comprehensive list of changes in this release
Changes to the LLVM IR
----------------------

* Unnamed function arguments now get printed with their automatically
generated name (e.g. "i32 %0") in definitions. This may require front-ends
to update their tests; if so there is a script utils/add_argument_names.py
that correctly converted 80-90% of Clang tests. Some manual work will almost
certainly still be needed.


Changes to building LLVM
------------------------

Expand Down
14 changes: 14 additions & 0 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,7 @@ bool LLParser::ParseOptionalOperandBundles(
///
bool LLParser::ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool &isVarArg){
unsigned CurValID = 0;
isVarArg = false;
assert(Lex.getKind() == lltok::lparen);
Lex.Lex(); // eat the (.
Expand All @@ -2575,6 +2576,12 @@ bool LLParser::ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
if (Lex.getKind() == lltok::LocalVar) {
Name = Lex.getStrVal();
Lex.Lex();
} else if (Lex.getKind() == lltok::LocalVarID) {
if (Lex.getUIntVal() != CurValID)
return Error(TypeLoc, "argument expected to be numbered '%" +
Twine(CurValID) + "'");
++CurValID;
Lex.Lex();
}

if (!FunctionType::isValidArgumentType(ArgTy))
Expand Down Expand Up @@ -2602,6 +2609,13 @@ bool LLParser::ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
Name = Lex.getStrVal();
Lex.Lex();
} else {
if (Lex.getKind() == lltok::LocalVarID) {
if (Lex.getUIntVal() != CurValID)
return Error(TypeLoc, "argument expected to be numbered '%" +
Twine(CurValID) + "'");
Lex.Lex();
}
++CurValID;
Name = "";
}

Expand Down
4 changes: 4 additions & 0 deletions lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,10 @@ void AssemblyWriter::printArgument(const Argument *Arg, AttributeSet Attrs) {
if (Arg->hasName()) {
Out << ' ';
PrintLLVMName(Out, Arg);
} else {
int Slot = Machine.getLocalSlot(Arg);
assert(Slot != -1 && "expect argument in function here");
Out << " %" << Slot;
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/Assembler/block-labels.ll
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ $N:
; CHECK-NEXT: ret i32 %4
; CHECK-NEXT: }

define void @test2(i32, i32) {
define void @test2(i32 %0, i32 %1) {
; entry label id still not printed on output
2:
ret void
}

; CHECK-LABEL: define void @test2(i32, i32) {
; CHECK-LABEL: define void @test2(i32 %0, i32 %1) {
; CHECK-NEXT: ret void
8 changes: 4 additions & 4 deletions test/Assembler/byval-type-attr.ll
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s

; CHECK: define void @foo(i32* byval(i32) align 4)
define void @foo(i32* byval(i32) align 4) {
; CHECK: define void @foo(i32* byval(i32) align 4 %0)
define void @foo(i32* byval(i32) align 4 %0) {
ret void
}

; CHECK: define void @bar({ i32*, i8 }* byval({ i32*, i8 }) align 4)
define void @bar({i32*, i8}* byval({i32*, i8}) align 4) {
; CHECK: define void @bar({ i32*, i8 }* byval({ i32*, i8 }) align 4 %0)
define void @bar({i32*, i8}* byval({i32*, i8}) align 4 %0) {
ret void
}

Expand Down
4 changes: 2 additions & 2 deletions test/Assembler/call-nonzero-program-addrspace-2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

; Check that numbered variables in a nonzero program address space 200 can be used in a call instruction

define i8 @test_unnamed(i8(i32)*, i8(i32) addrspace(42)*) {
define i8 @test_unnamed(i8(i32)*, i8(i32) addrspace(42)* %0) {
; Calls with explicit address spaces are fine:
call addrspace(0) i8 %0(i32 0)
call addrspace(42) i8 %1(i32 0)
Expand All @@ -14,7 +14,7 @@ define i8 @test_unnamed(i8(i32)*, i8(i32) addrspace(42)*) {
}

; PROGAS42: target datalayout = "P42"
; PROGAS42: define i8 @test_unnamed(i8 (i32)*, i8 (i32) addrspace(42)*) addrspace(42) {
; PROGAS42: define i8 @test_unnamed(i8 (i32)* %0, i8 (i32) addrspace(42)* %1) addrspace(42) {
; PROGAS42-NEXT: %3 = call addrspace(0) i8 %0(i32 0)
; PROGAS42-NEXT: %4 = call addrspace(42) i8 %1(i32 0)
; PROGAS42-NEXT: %5 = call addrspace(42) i8 %1(i32 0)
Expand Down
2 changes: 1 addition & 1 deletion test/Assembler/incorrect-tdep-attrs-parsing.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: llvm-as < %s | llvm-dis | FileCheck %s

; CHECK: define i32 @f(i64 "foo bar", i64, i64, i64 "xyz") {
; CHECK: define i32 @f(i64 "foo bar" %0, i64 %1, i64 %2, i64 "xyz" %3) {
define i32 @f(i64 "foo bar", i64, i64, i64 "xyz") {
ret i32 41
}
6 changes: 6 additions & 0 deletions test/Assembler/invalid-arg-num-1.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s

; CHECK: error: argument expected to be numbered '%1'
define void @foo(i32 %0, i32 %5) {
ret void
}
6 changes: 6 additions & 0 deletions test/Assembler/invalid-arg-num-2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s

; CHECK: error: argument expected to be numbered '%1'
define void @foo(i8 %0, i32 %named, i32 %2) {
ret void
}
6 changes: 6 additions & 0 deletions test/Assembler/invalid-arg-num-3.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s

; CHECK: error: argument expected to be numbered '%0'
define void @foo(i8 %1) {
ret void
}
2 changes: 1 addition & 1 deletion test/Bindings/llvm-c/debug_info.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
; CHECK: ; ModuleID = 'debuginfo.c'
; CHECK-NEXT: source_filename = "debuginfo.c"

; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !20 {
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !20 {
; CHECK-NEXT: entry:
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !27, metadata !DIExpression()), !dbg !32
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !28, metadata !DIExpression()), !dbg !32
Expand Down
36 changes: 18 additions & 18 deletions test/Bitcode/attributes-3.3.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
; The test checks that LLVM does not silently misread attributes of
; older bitcode files.

define void @f1(i8 zeroext)
; CHECK: define void @f1(i8 zeroext)
define void @f1(i8 zeroext %0)
; CHECK: define void @f1(i8 zeroext %0)
{
ret void;
}

define void @f2(i8 signext)
; CHECK: define void @f2(i8 signext)
define void @f2(i8 signext %0)
; CHECK: define void @f2(i8 signext %0)
{
ret void;
}
Expand All @@ -23,14 +23,14 @@ define void @f3() noreturn
ret void;
}

define void @f4(i8 inreg)
; CHECK: define void @f4(i8 inreg)
define void @f4(i8 inreg %0)
; CHECK: define void @f4(i8 inreg %0)
{
ret void;
}

define void @f5(i8* sret)
; CHECK: define void @f5(i8* sret)
define void @f5(i8* sret %0)
; CHECK: define void @f5(i8* sret %0)
{
ret void;
}
Expand All @@ -41,20 +41,20 @@ define void @f6() nounwind
ret void;
}

define void @f7(i8* noalias)
; CHECK: define void @f7(i8* noalias)
define void @f7(i8* noalias %0)
; CHECK: define void @f7(i8* noalias %0)
{
ret void;
}

define void @f8(i8* byval)
; CHECK: define void @f8(i8* byval(i8))
define void @f8(i8* byval %0)
; CHECK: define void @f8(i8* byval(i8) %0)
{
ret void;
}

define void @f9(i8* nest)
; CHECK: define void @f9(i8* nest)
define void @f9(i8* nest %0)
; CHECK: define void @f9(i8* nest %0)
{
ret void;
}
Expand Down Expand Up @@ -101,14 +101,14 @@ define void @f16() sspreq
ret void;
}

define void @f17(i8 align 4)
; CHECK: define void @f17(i8 align 4)
define void @f17(i8 align 4 %0)
; CHECK: define void @f17(i8 align 4 %0)
{
ret void;
}

define void @f18(i8* nocapture)
; CHECK: define void @f18(i8* nocapture)
define void @f18(i8* nocapture %0)
; CHECK: define void @f18(i8* nocapture %0)
{
ret void;
}
Expand Down
72 changes: 36 additions & 36 deletions test/Bitcode/attributes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
; RUN: verify-uselistorder < %s
; PR12696

define void @f1(i8 zeroext)
; CHECK: define void @f1(i8 zeroext)
define void @f1(i8 zeroext %0)
; CHECK: define void @f1(i8 zeroext %0)
{
ret void;
}

define void @f2(i8 signext)
; CHECK: define void @f2(i8 signext)
define void @f2(i8 signext %0)
; CHECK: define void @f2(i8 signext %0)
{
ret void;
}
Expand All @@ -20,14 +20,14 @@ define void @f3() noreturn
ret void;
}

define void @f4(i8 inreg)
; CHECK: define void @f4(i8 inreg)
define void @f4(i8 inreg %0)
; CHECK: define void @f4(i8 inreg %0)
{
ret void;
}

define void @f5(i8* sret)
; CHECK: define void @f5(i8* sret)
define void @f5(i8* sret %0)
; CHECK: define void @f5(i8* sret %0)
{
ret void;
}
Expand All @@ -38,20 +38,20 @@ define void @f6() nounwind
ret void;
}

define void @f7(i8* noalias)
; CHECK: define void @f7(i8* noalias)
define void @f7(i8* noalias %0)
; CHECK: define void @f7(i8* noalias %0)
{
ret void;
}

define void @f8(i8* byval)
; CHECK: define void @f8(i8* byval(i8))
define void @f8(i8* byval %0)
; CHECK: define void @f8(i8* byval(i8) %0)
{
ret void;
}

define void @f9(i8* nest)
; CHECK: define void @f9(i8* nest)
define void @f9(i8* nest %0)
; CHECK: define void @f9(i8* nest %0)
{
ret void;
}
Expand Down Expand Up @@ -98,14 +98,14 @@ define void @f16() sspreq
ret void;
}

define void @f17(i8 align 4)
; CHECK: define void @f17(i8 align 4)
define void @f17(i8 align 4 %0)
; CHECK: define void @f17(i8 align 4 %0)
{
ret void;
}

define void @f18(i8* nocapture)
; CHECK: define void @f18(i8* nocapture)
define void @f18(i8* nocapture %0)
; CHECK: define void @f18(i8* nocapture %0)
{
ret void;
}
Expand Down Expand Up @@ -214,8 +214,8 @@ define void @f35() optnone noinline
ret void;
}

define void @f36(i8* inalloca) {
; CHECK: define void @f36(i8* inalloca) {
define void @f36(i8* inalloca %0) {
; CHECK: define void @f36(i8* inalloca %0) {
ret void
}

Expand All @@ -240,8 +240,8 @@ define dereferenceable(18446744073709551606) i8* @f40(i8* dereferenceable(184467
ret i8* %a
}

define void @f41(i8* align 32, double* align 64) {
; CHECK: define void @f41(i8* align 32, double* align 64) {
define void @f41(i8* align 32 %0, double* align 64 %1) {
; CHECK: define void @f41(i8* align 32 %0, double* align 64 %1) {
ret void
}

Expand All @@ -262,13 +262,13 @@ define void @f44() argmemonly
ret void;
}

; CHECK: define "string_attribute" void @f45(i32 "string_attribute")
define "string_attribute" void @f45(i32 "string_attribute") {
; CHECK: define "string_attribute" void @f45(i32 "string_attribute" %0)
define "string_attribute" void @f45(i32 "string_attribute" %0) {
ret void
}

; CHECK: define "string_attribute_with_value"="value" void @f46(i32 "string_attribute_with_value"="value")
define "string_attribute_with_value"="value" void @f46(i32 "string_attribute_with_value"="value") {
; CHECK: define "string_attribute_with_value"="value" void @f46(i32 "string_attribute_with_value"="value" %0)
define "string_attribute_with_value"="value" void @f46(i32 "string_attribute_with_value"="value" %0) {
ret void
}

Expand All @@ -287,20 +287,20 @@ define void @f49() inaccessiblemem_or_argmemonly {
ret void
}

; CHECK: define void @f50(i8* swiftself)
define void @f50(i8* swiftself)
; CHECK: define void @f50(i8* swiftself %0)
define void @f50(i8* swiftself %0)
{
ret void;
}

; CHECK: define i32 @f51(i8** swifterror)
define i32 @f51(i8** swifterror)
; CHECK: define i32 @f51(i8** swifterror %0)
define i32 @f51(i8** swifterror %0)
{
ret i32 0
}

; CHECK: define i32 @f52(i32, i8** swifterror)
define i32 @f52(i32, i8** swifterror)
; CHECK: define i32 @f52(i32 %0, i8** swifterror %1)
define i32 @f52(i32 %0, i8** swifterror %1)
{
ret i32 0
}
Expand All @@ -318,13 +318,13 @@ entry:
ret float 1.0
}

; CHECK: define i8* @f54(i32) #30
define i8* @f54(i32) allocsize(0) {
; CHECK: define i8* @f54(i32 %0) #30
define i8* @f54(i32 %0) allocsize(0) {
ret i8* null
}

; CHECK: define i8* @f55(i32, i32) #31
define i8* @f55(i32, i32) allocsize(0, 1) {
; CHECK: define i8* @f55(i32 %0, i32 %1) #31
define i8* @f55(i32 %0, i32 %1) allocsize(0, 1) {
ret i8* null
}

Expand Down
Loading

0 comments on commit 61325b6

Please sign in to comment.