diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -125,6 +125,7 @@ kw_pre_instr_symbol, kw_post_instr_symbol, kw_heap_alloc_marker, + kw_pcsections, kw_cfi_type, kw_bbsections, kw_unknown_size, diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -270,6 +270,7 @@ .Case("pre-instr-symbol", MIToken::kw_pre_instr_symbol) .Case("post-instr-symbol", MIToken::kw_post_instr_symbol) .Case("heap-alloc-marker", MIToken::kw_heap_alloc_marker) + .Case("pcsections", MIToken::kw_pcsections) .Case("cfi-type", MIToken::kw_cfi_type) .Case("bbsections", MIToken::kw_bbsections) .Case("unknown-size", MIToken::kw_unknown_size) diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -509,6 +509,7 @@ bool parseMachineMemoryOperand(MachineMemOperand *&Dest); bool parsePreOrPostInstrSymbol(MCSymbol *&Symbol); bool parseHeapAllocMarker(MDNode *&Node); + bool parsePCSections(MDNode *&Node); bool parseTargetImmMnemonic(const unsigned OpCode, const unsigned OpIdx, MachineOperand &Dest, const MIRFormatter &MF); @@ -1016,6 +1017,7 @@ while (!Token.isNewlineOrEOF() && Token.isNot(MIToken::kw_pre_instr_symbol) && Token.isNot(MIToken::kw_post_instr_symbol) && Token.isNot(MIToken::kw_heap_alloc_marker) && + Token.isNot(MIToken::kw_pcsections) && Token.isNot(MIToken::kw_cfi_type) && Token.isNot(MIToken::kw_debug_location) && Token.isNot(MIToken::kw_debug_instr_number) && @@ -1046,6 +1048,10 @@ if (Token.is(MIToken::kw_heap_alloc_marker)) if (parseHeapAllocMarker(HeapAllocMarker)) return true; + MDNode *PCSections = nullptr; + if (Token.is(MIToken::kw_pcsections)) + if (parsePCSections(PCSections)) + return true; unsigned CFIType = 0; if (Token.is(MIToken::kw_cfi_type)) { @@ -1140,6 +1146,8 @@ MI->setPostInstrSymbol(MF, PostInstrSymbol); if (HeapAllocMarker) MI->setHeapAllocMarker(MF, HeapAllocMarker); + if (PCSections) + MI->setPCSections(MF, PCSections); if (CFIType) MI->setCFIType(MF, CFIType); if (!MemOperands.empty()) @@ -3417,6 +3425,22 @@ return false; } +bool MIParser::parsePCSections(MDNode *&Node) { + assert(Token.is(MIToken::kw_pcsections) && + "Invalid token for a PC sections!"); + lex(); + parseMDNode(Node); + if (!Node) + return error("expected a MDNode after 'pcsections'"); + if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) || + Token.is(MIToken::lbrace)) + return false; + if (Token.isNot(MIToken::comma)) + return error("expected ',' before the next machine operand"); + lex(); + return false; +} + static void initSlots2BasicBlocks( const Function &F, DenseMap &Slots2BasicBlocks) { diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -819,6 +819,13 @@ HeapAllocMarker->printAsOperand(OS, MST); NeedComma = true; } + if (MDNode *PCSections = MI.getPCSections()) { + if (NeedComma) + OS << ','; + OS << " pcsections "; + PCSections->printAsOperand(OS, MST); + NeedComma = true; + } if (uint32_t CFIType = MI.getCFIType()) { if (NeedComma) OS << ','; diff --git a/llvm/test/CodeGen/MIR/X86/instr-pcsections.mir b/llvm/test/CodeGen/MIR/X86/instr-pcsections.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/MIR/X86/instr-pcsections.mir @@ -0,0 +1,34 @@ +# RUN: llc -march=x86-64 -run-pass none -o - %s | FileCheck %s +# This test ensures that the MIR parser parses pcsections metadata correctly. + +--- | + + define i8 @test(i8* %a) { + entry: + %0 = load i8, i8* %a, align 1, !pcsections !0 + ret i8 %0 + } + + !0 = !{!"foo"} + +... +--- +name: test +alignment: 16 +tracksRegLiveness: true +liveins: + - { reg: '$rdi' } +frameInfo: + maxAlignment: 1 + maxCallFrameSize: 0 +machineFunctionInfo: {} +body: | + bb.0.entry: + liveins: $rdi + + ; CHECK-LABEL: name: test + ; CHECK: MOV{{.*}} pcsections !0 + renamable $al = MOV8rm killed renamable $rdi, 1, $noreg, 0, $noreg, pcsections !0 + RET64 implicit killed $al + +...