[llvm] r328433 - [RISCV] Use init_array instead of ctors for RISCV target, by default
Mandeep Singh Grang via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 24 11:37:19 PDT 2018
Author: mgrang
Date: Sat Mar 24 11:37:19 2018
New Revision: 328433
URL: http://llvm.org/viewvc/llvm-project?rev=328433&view=rev
Log:
[RISCV] Use init_array instead of ctors for RISCV target, by default
Summary:
LLVM defaults to the newer .init_array/.fini_array scheme for static
constructors rather than the less desirable .ctors/.dtors (the UseCtors
flag defaults to false). This wasn't being respected in the RISC-V
backend because it fails to call TargetLoweringObjectFileELF::InitializeELF with the the appropriate
flag for UseInitArray.
This patch fixes this by implementing RISCVELFTargetObjectFile and overriding its Initialize method to call
InitializeELF(TM.Options.UseInitArray).
Reviewers: asb, apazos
Reviewed By: asb
Subscribers: mgorny, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, llvm-commits
Differential Revision: https://reviews.llvm.org/D44750
Added:
llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.cpp
llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.h
llvm/trunk/test/CodeGen/RISCV/init-array.ll
Modified:
llvm/trunk/lib/Target/RISCV/CMakeLists.txt
llvm/trunk/lib/Target/RISCV/RISCVTargetMachine.cpp
Modified: llvm/trunk/lib/Target/RISCV/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/CMakeLists.txt?rev=328433&r1=328432&r2=328433&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/CMakeLists.txt (original)
+++ llvm/trunk/lib/Target/RISCV/CMakeLists.txt Sat Mar 24 11:37:19 2018
@@ -22,6 +22,7 @@ add_llvm_target(RISCVCodeGen
RISCVRegisterInfo.cpp
RISCVSubtarget.cpp
RISCVTargetMachine.cpp
+ RISCVTargetObjectFile.cpp
)
add_subdirectory(AsmParser)
Modified: llvm/trunk/lib/Target/RISCV/RISCVTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/RISCVTargetMachine.cpp?rev=328433&r1=328432&r2=328433&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/RISCVTargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/RISCV/RISCVTargetMachine.cpp Sat Mar 24 11:37:19 2018
@@ -13,6 +13,7 @@
#include "RISCV.h"
#include "RISCVTargetMachine.h"
+#include "RISCVTargetObjectFile.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
@@ -59,7 +60,7 @@ RISCVTargetMachine::RISCVTargetMachine(c
: LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options,
getEffectiveRelocModel(TT, RM),
getEffectiveCodeModel(CM), OL),
- TLOF(make_unique<TargetLoweringObjectFileELF>()),
+ TLOF(make_unique<RISCVELFTargetObjectFile>()),
Subtarget(TT, CPU, FS, *this) {
initAsmInfo();
}
Added: llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.cpp?rev=328433&view=auto
==============================================================================
--- llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.cpp (added)
+++ llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.cpp Sat Mar 24 11:37:19 2018
@@ -0,0 +1,19 @@
+//===-- RISCVTargetObjectFile.cpp - RISCV Object Info -----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "RISCVTargetObjectFile.h"
+#include "RISCVTargetMachine.h"
+
+using namespace llvm;
+
+void RISCVELFTargetObjectFile::Initialize(MCContext &Ctx,
+ const TargetMachine &TM) {
+ TargetLoweringObjectFileELF::Initialize(Ctx, TM);
+ InitializeELF(TM.Options.UseInitArray);
+}
Added: llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.h?rev=328433&view=auto
==============================================================================
--- llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.h (added)
+++ llvm/trunk/lib/Target/RISCV/RISCVTargetObjectFile.h Sat Mar 24 11:37:19 2018
@@ -0,0 +1,25 @@
+//===-- RISCVTargetObjectFile.h - RISCV Object Info -*- C++ ---------*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_RISCV_RISCVTARGETOBJECTFILE_H
+#define LLVM_LIB_TARGET_RISCV_RISCVTARGETOBJECTFILE_H
+
+#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
+
+namespace llvm {
+class RISCVTargetMachine;
+
+/// This implementation is used for RISCV ELF targets.
+class RISCVELFTargetObjectFile : public TargetLoweringObjectFileELF {
+ void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
+};
+
+} // end namespace llvm
+
+#endif
Added: llvm/trunk/test/CodeGen/RISCV/init-array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/RISCV/init-array.ll?rev=328433&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/RISCV/init-array.ll (added)
+++ llvm/trunk/test/CodeGen/RISCV/init-array.ll Sat Mar 24 11:37:19 2018
@@ -0,0 +1,30 @@
+; RUN: llc -mtriple=riscv32-unknown-linux-gnu -verify-machineinstrs -o - %s \
+; RUN: | FileCheck --check-prefix=INITARRAY %s
+; RUN: llc -mtriple=riscv32-unknown-elf -verify-machineinstrs -o - %s \
+; RUN: | FileCheck --check-prefix=INITARRAY %s
+; RUN: llc -mtriple=riscv64-unknown-linux-gnu -verify-machineinstrs -o - %s \
+; RUN: | FileCheck --check-prefix=INITARRAY %s
+; RUN: llc -mtriple=riscv64-unknown-elf -verify-machineinstrs -o - %s \
+; RUN: | FileCheck --check-prefix=INITARRAY %s
+
+; RUN: llc -mtriple=riscv32-unknown-linux-gnu -verify-machineinstrs -use-ctors -o - %s \
+; RUN: | FileCheck --check-prefix=CTOR %s
+; RUN: llc -mtriple=riscv32-unknown-elf -verify-machineinstrs -use-ctors -o - %s \
+; RUN: | FileCheck --check-prefix=CTOR %s
+; RUN: llc -mtriple=riscv64-unknown-linux-gnu -verify-machineinstrs -use-ctors -o - %s \
+; RUN: | FileCheck --check-prefix=CTOR %s
+; RUN: llc -mtriple=riscv64-unknown-elf -verify-machineinstrs -use-ctors -o - %s \
+; RUN: | FileCheck --check-prefix=CTOR %s
+
+define internal void @_GLOBAL__I_a() section ".text.startup" {
+ ret void
+}
+
+ at llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
+
+;INITARRAY: section .init_array
+;INITARRAY-NOT: .section .ctors
+
+;CTOR: .section .ctors
+;CTOR-NOT: section .init_array
+
More information about the llvm-commits
mailing list