[llvm] r326620 - [unittests] Make some parseIR calls more readable, NFC
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 2 13:36:33 PST 2018
Author: vedantk
Date: Fri Mar 2 13:36:33 2018
New Revision: 326620
URL: http://llvm.org/viewvc/llvm-project?rev=326620&view=rev
Log:
[unittests] Make some parseIR calls more readable, NFC
Modified:
llvm/trunk/unittests/Transforms/Utils/Local.cpp
Modified: llvm/trunk/unittests/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Local.cpp?rev=326620&r1=326619&r2=326620&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/unittests/Transforms/Utils/Local.cpp Fri Mar 2 13:36:33 2018
@@ -113,37 +113,31 @@ TEST(Local, ReplaceDbgDeclare) {
// Original C source to get debug info for a local variable:
// void f() { int x; }
- std::unique_ptr<Module> M = parseIR(
- C,
- "define void @f() !dbg !8 {\n"
- "entry:\n"
- " %x = alloca i32, align 4\n"
- " call void @llvm.dbg.declare(metadata i32* %x, metadata !11, metadata "
- "!DIExpression()), !dbg !13\n"
- " call void @llvm.dbg.declare(metadata i32* %x, metadata !11, metadata "
- "!DIExpression()), !dbg !13\n"
- " ret void, !dbg !14\n"
- "}\n"
- "declare void @llvm.dbg.declare(metadata, metadata, metadata)\n"
- "!llvm.dbg.cu = !{!0}\n"
- "!llvm.module.flags = !{!3, !4}\n"
- "!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "
- "\"clang version 6.0.0 \", isOptimized: false, runtimeVersion: 0, "
- "emissionKind: FullDebug, enums: !2)\n"
- "!1 = !DIFile(filename: \"t2.c\", directory: \"foo\")\n"
- "!2 = !{}\n"
- "!3 = !{i32 2, !\"Dwarf Version\", i32 4}\n"
- "!4 = !{i32 2, !\"Debug Info Version\", i32 3}\n"
- "!8 = distinct !DISubprogram(name: \"f\", scope: !1, file: !1, line: 1, "
- "type: !9, isLocal: false, isDefinition: true, scopeLine: 1, "
- "isOptimized: false, unit: !0, variables: !2)\n"
- "!9 = !DISubroutineType(types: !10)\n"
- "!10 = !{null}\n"
- "!11 = !DILocalVariable(name: \"x\", scope: !8, file: !1, line: 2, type: "
- "!12)\n"
- "!12 = !DIBasicType(name: \"int\", size: 32, encoding: DW_ATE_signed)\n"
- "!13 = !DILocation(line: 2, column: 7, scope: !8)\n"
- "!14 = !DILocation(line: 3, column: 1, scope: !8)\n");
+ std::unique_ptr<Module> M = parseIR(C,
+ R"(
+ define void @f() !dbg !8 {
+ entry:
+ %x = alloca i32, align 4
+ call void @llvm.dbg.declare(metadata i32* %x, metadata !11, metadata !DIExpression()), !dbg !13
+ call void @llvm.dbg.declare(metadata i32* %x, metadata !11, metadata !DIExpression()), !dbg !13
+ ret void, !dbg !14
+ }
+ declare void @llvm.dbg.declare(metadata, metadata, metadata)
+ !llvm.dbg.cu = !{!0}
+ !llvm.module.flags = !{!3, !4}
+ !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+ !1 = !DIFile(filename: "t2.c", directory: "foo")
+ !2 = !{}
+ !3 = !{i32 2, !"Dwarf Version", i32 4}
+ !4 = !{i32 2, !"Debug Info Version", i32 3}
+ !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, variables: !2)
+ !9 = !DISubroutineType(types: !10)
+ !10 = !{null}
+ !11 = !DILocalVariable(name: "x", scope: !8, file: !1, line: 2, type: !12)
+ !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+ !13 = !DILocation(line: 2, column: 7, scope: !8)
+ !14 = !DILocation(line: 3, column: 1, scope: !8)
+ )");
auto *GV = M->getNamedValue("f");
ASSERT_TRUE(GV);
auto *F = dyn_cast<Function>(GV);
@@ -182,23 +176,24 @@ static void runWithDomTree(
TEST(Local, MergeBasicBlockIntoOnlyPred) {
LLVMContext C;
- std::unique_ptr<Module> M = parseIR(
- C,
- "define i32 @f(i8* %str) {\n"
- "entry:\n"
- " br label %bb2.i\n"
- "bb2.i: ; preds = %bb4.i, %entry\n"
- " br i1 false, label %bb4.i, label %base2flt.exit204\n"
- "bb4.i: ; preds = %bb2.i\n"
- " br i1 false, label %base2flt.exit204, label %bb2.i\n"
- "bb10.i196.bb7.i197_crit_edge: ; No predecessors!\n"
- " br label %bb7.i197\n"
- "bb7.i197: ; preds = %bb10.i196.bb7.i197_crit_edge\n"
- " %.reg2mem.0 = phi i32 [ %.reg2mem.0, %bb10.i196.bb7.i197_crit_edge ]\n"
- " br i1 undef, label %base2flt.exit204, label %base2flt.exit204\n"
- "base2flt.exit204: ; preds = %bb7.i197, %bb7.i197, %bb2.i, %bb4.i\n"
- " ret i32 0\n"
- "}\n");
+ std::unique_ptr<Module> M = parseIR(C,
+ R"(
+ define i32 @f(i8* %str) {
+ entry:
+ br label %bb2.i
+ bb2.i: ; preds = %bb4.i, %entry
+ br i1 false, label %bb4.i, label %base2flt.exit204
+ bb4.i: ; preds = %bb2.i
+ br i1 false, label %base2flt.exit204, label %bb2.i
+ bb10.i196.bb7.i197_crit_edge: ; No predecessors!
+ br label %bb7.i197
+ bb7.i197: ; preds = %bb10.i196.bb7.i197_crit_edge
+ %.reg2mem.0 = phi i32 [ %.reg2mem.0, %bb10.i196.bb7.i197_crit_edge ]
+ br i1 undef, label %base2flt.exit204, label %base2flt.exit204
+ base2flt.exit204: ; preds = %bb7.i197, %bb7.i197, %bb2.i, %bb4.i
+ ret i32 0
+ }
+ )");
runWithDomTree(
*M, "f", [&](Function &F, DominatorTree *DT) {
for (Function::iterator I = F.begin(), E = F.end(); I != E;) {
@@ -216,104 +211,103 @@ TEST(Local, MergeBasicBlockIntoOnlyPred)
TEST(Local, ConstantFoldTerminator) {
LLVMContext C;
- std::unique_ptr<Module> M = parseIR(
- C,
- "define void @br_same_dest() {\n"
- "entry:\n"
- " br i1 false, label %bb0, label %bb0\n"
- "bb0:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define void @br_different_dest() {\n"
- "entry:\n"
- " br i1 true, label %bb0, label %bb1\n"
- "bb0:\n"
- " br label %exit\n"
- "bb1:\n"
- " br label %exit\n"
- "exit:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define void @switch_2_different_dest() {\n"
- "entry:\n"
- " switch i32 0, label %default [ i32 0, label %bb0 ]\n"
- "default:\n"
- " ret void\n"
- "bb0:\n"
- " ret void\n"
- "}\n"
- "define void @switch_2_different_dest_default() {\n"
- "entry:\n"
- " switch i32 1, label %default [ i32 0, label %bb0 ]\n"
- "default:\n"
- " ret void\n"
- "bb0:\n"
- " ret void\n"
- "}\n"
- "define void @switch_3_different_dest() {\n"
- "entry:\n"
- " switch i32 0, label %default [ i32 0, label %bb0\n"
- " i32 1, label %bb1 ]\n"
- "default:\n"
- " ret void\n"
- "bb0:\n"
- " ret void\n"
- "bb1:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define void @switch_variable_2_default_dest(i32 %arg) {\n"
- "entry:\n"
- " switch i32 %arg, label %default [ i32 0, label %default ]\n"
- "default:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define void @switch_constant_2_default_dest() {\n"
- "entry:\n"
- " switch i32 1, label %default [ i32 0, label %default ]\n"
- "default:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define void @switch_constant_3_repeated_dest() {\n"
- "entry:\n"
- " switch i32 0, label %default [ i32 0, label %bb0\n"
- " i32 1, label %bb0 ]\n"
- " bb0:\n"
- " ret void\n"
- "default:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define void @indirectbr() {\n"
- "entry:\n"
- " indirectbr i8* blockaddress(@indirectbr, %bb0), [label %bb0, label %bb1]\n"
- "bb0:\n"
- " ret void\n"
- "bb1:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define void @indirectbr_repeated() {\n"
- "entry:\n"
- " indirectbr i8* blockaddress(@indirectbr_repeated, %bb0), [label %bb0, label %bb0]\n"
- "bb0:\n"
- " ret void\n"
- "}\n"
- "\n"
- "define void @indirectbr_unreachable() {\n"
- "entry:\n"
- " indirectbr i8* blockaddress(@indirectbr_unreachable, %bb0), [label %bb1]\n"
- "bb0:\n"
- " ret void\n"
- "bb1:\n"
- " ret void\n"
- "}\n"
- "\n"
- );
+ std::unique_ptr<Module> M = parseIR(C,
+ R"(
+ define void @br_same_dest() {
+ entry:
+ br i1 false, label %bb0, label %bb0
+ bb0:
+ ret void
+ }
+
+ define void @br_different_dest() {
+ entry:
+ br i1 true, label %bb0, label %bb1
+ bb0:
+ br label %exit
+ bb1:
+ br label %exit
+ exit:
+ ret void
+ }
+
+ define void @switch_2_different_dest() {
+ entry:
+ switch i32 0, label %default [ i32 0, label %bb0 ]
+ default:
+ ret void
+ bb0:
+ ret void
+ }
+ define void @switch_2_different_dest_default() {
+ entry:
+ switch i32 1, label %default [ i32 0, label %bb0 ]
+ default:
+ ret void
+ bb0:
+ ret void
+ }
+ define void @switch_3_different_dest() {
+ entry:
+ switch i32 0, label %default [ i32 0, label %bb0
+ i32 1, label %bb1 ]
+ default:
+ ret void
+ bb0:
+ ret void
+ bb1:
+ ret void
+ }
+
+ define void @switch_variable_2_default_dest(i32 %arg) {
+ entry:
+ switch i32 %arg, label %default [ i32 0, label %default ]
+ default:
+ ret void
+ }
+
+ define void @switch_constant_2_default_dest() {
+ entry:
+ switch i32 1, label %default [ i32 0, label %default ]
+ default:
+ ret void
+ }
+
+ define void @switch_constant_3_repeated_dest() {
+ entry:
+ switch i32 0, label %default [ i32 0, label %bb0
+ i32 1, label %bb0 ]
+ bb0:
+ ret void
+ default:
+ ret void
+ }
+
+ define void @indirectbr() {
+ entry:
+ indirectbr i8* blockaddress(@indirectbr, %bb0), [label %bb0, label %bb1]
+ bb0:
+ ret void
+ bb1:
+ ret void
+ }
+
+ define void @indirectbr_repeated() {
+ entry:
+ indirectbr i8* blockaddress(@indirectbr_repeated, %bb0), [label %bb0, label %bb0]
+ bb0:
+ ret void
+ }
+
+ define void @indirectbr_unreachable() {
+ entry:
+ indirectbr i8* blockaddress(@indirectbr_unreachable, %bb0), [label %bb1]
+ bb0:
+ ret void
+ bb1:
+ ret void
+ }
+ )");
auto CFAllTerminators = [&](Function &F, DominatorTree *DT) {
DeferredDominance DDT(*DT);
More information about the llvm-commits
mailing list