[PATCH] D99487: [CodeGen] Port basic block sections from ELF to COFF
TaoPan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 29 00:31:58 PDT 2021
TaoPan created this revision.
TaoPan added reviewers: tmsriram, snehasish, MaskRay, pengfei.
Herald added a subscriber: hiraditya.
TaoPan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Ignore size check as COFF assembly doesn't supprt .size directive.
Signed-off-by: Pan, Tao <tao.pan at intel.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99487
Files:
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/X86/basic-block-sections.ll
Index: llvm/test/CodeGen/X86/basic-block-sections.ll
===================================================================
--- llvm/test/CodeGen/X86/basic-block-sections.ll
+++ llvm/test/CodeGen/X86/basic-block-sections.ll
@@ -3,6 +3,8 @@
; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=all -unique-basic-block-section-names -split-machine-functions | FileCheck %s -check-prefix=LINUX-SECTIONS
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -function-sections -basic-block-sections=all -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -basic-block-sections=all -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
+; RUN: llc < %s -mtriple=x86_64-windows-msvc -function-sections -basic-block-sections=all -unique-basic-block-section-names | FileCheck %s -check-prefix=WINDOWS-SECTIONS
+; RUN: llc < %s -mtriple=x86_64-windows-msvc -basic-block-sections=all -unique-basic-block-section-names | FileCheck %s -check-prefix=WINDOWS-SECTIONS
define void @_Z3bazb(i1 zeroext) nounwind {
%2 = alloca i8, align 1
@@ -39,3 +41,9 @@
; LINUX-SECTIONS: [[SECTION_LABEL_2]]:
; LINUX-SECTIONS: .LBB_END0_2:
; LINUX-SECTIONS-NEXT: .size [[SECTION_LABEL_2]], .LBB_END0_2-[[SECTION_LABEL_2]]
+; WINDOWS-SECTIONS: .section .text,"xr",one_only,_Z3bazb
+; WINDOWS-SECTIONS: _Z3bazb:
+; WINDOWS-SECTIONS: .section .text,"xr",one_only,[[SECTION_LABEL_1:_Z3bazb.__part.[0-9]+]]
+; WINDOWS-SECTIONS: [[SECTION_LABEL_1]]:
+; WINDOWS-SECTIONS: .section .text,"xr",one_only,[[SECTION_LABEL_2:_Z3bazb.__part.[0-9]+]]
+; WINDOWS-SECTIONS: [[SECTION_LABEL_2]]:
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1693,6 +1693,36 @@
COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE, UniqueID);
}
+/// Returns a unique section for the given machine basic block.
+MCSection *TargetLoweringObjectFileCOFF::getSectionForMachineBasicBlock(
+ const Function &F, const MachineBasicBlock &MBB,
+ const TargetMachine &TM) const {
+ assert(MBB.isBeginSection() && "Basic block does not start a section!");
+ unsigned UniqueID = MCContext::GenericSectionID;
+ SmallString<128> COMDATSymName;
+ if (TM.getUniqueBasicBlockSectionNames())
+ COMDATSymName += MBB.getSymbol()->getName();
+ else
+ UniqueID = NextUniqueID++;
+
+ return getContext().getCOFFSection(
+ getCOFFSectionNameForUniqueGlobal(SectionKind::getText()),
+ COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
+ COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_LNK_COMDAT,
+ SectionKind::getText(), COMDATSymName,
+ COFF::IMAGE_COMDAT_SELECT_NODUPLICATES, UniqueID);
+}
+
+MCSection *TargetLoweringObjectFileCOFF::getUniqueSectionForFunction(
+ const Function &F, const TargetMachine &TM) const {
+ SectionKind Kind = SectionKind::getText();
+ return getContext().getCOFFSection(
+ getCOFFSectionNameForUniqueGlobal(Kind),
+ getCOFFSectionFlags(Kind, TM) | COFF::IMAGE_SCN_LNK_COMDAT, Kind,
+ TM.getSymbol(&F)->getName(), COFF::IMAGE_COMDAT_SELECT_NODUPLICATES,
+ NextUniqueID++);
+}
+
void TargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer,
Module &M) const {
emitLinkerDirectives(Streamer, M);
Index: llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -174,6 +174,15 @@
MCSection *getSectionForJumpTable(const Function &F,
const TargetMachine &TM) const override;
+ MCSection *
+ getSectionForMachineBasicBlock(const Function &F,
+ const MachineBasicBlock &MBB,
+ const TargetMachine &TM) const override;
+
+ MCSection *
+ getUniqueSectionForFunction(const Function &F,
+ const TargetMachine &TM) const override;
+
/// Emit Obj-C garbage collection and linker options.
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99487.333777.patch
Type: text/x-patch
Size: 4418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210329/f884d95b/attachment.bin>
More information about the llvm-commits
mailing list