summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShiva Chen <shiva0217@gmail.com>2018-04-12 11:30:59 +0000
committerShiva Chen <shiva0217@gmail.com>2018-04-12 11:30:59 +0000
commitb48b027d05eb28a868ffda436c4409b6b606a0cc (patch)
tree365b3c067fe7b44dc36f84e39b448dcaa8e3f916
parent69e0e8e3d418a5031b082b69acb8f96adc1225dd (diff)
downloadbcm5719-llvm-b48b027d05eb28a868ffda436c4409b6b606a0cc.tar.gz
bcm5719-llvm-b48b027d05eb28a868ffda436c4409b6b606a0cc.zip
[RISCV] Change function alignment to 4 bytes, and 2 bytes for RVC
Summary: According RISC-V ELF psABI specification, base RV32 and RV64 ISAs only allow 32-bit instruction alignment, but instruction allow to be aligned to 16-bit boundaries for C-extension. So we just align to 4 bytes and 2 bytes for C-extension is enough. Reviewers: asb, apazos Differential Revision: https://reviews.llvm.org/D45560 Patch by Kito Cheng. llvm-svn: 329899
-rw-r--r--llvm/lib/Target/RISCV/RISCVISelLowering.cpp5
-rw-r--r--llvm/test/CodeGen/RISCV/align.ll13
2 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 8e9ab54bf00..0018a9c750f 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -142,8 +142,9 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
setBooleanContents(ZeroOrOneBooleanContent);
// Function alignments (log2).
- setMinFunctionAlignment(3);
- setPrefFunctionAlignment(3);
+ unsigned FunctionAlignment = Subtarget.hasStdExtC() ? 1 : 2;
+ setMinFunctionAlignment(FunctionAlignment);
+ setPrefFunctionAlignment(FunctionAlignment);
// Effectively disable jump table generation.
setMinimumJumpTableEntries(INT_MAX);
diff --git a/llvm/test/CodeGen/RISCV/align.ll b/llvm/test/CodeGen/RISCV/align.ll
new file mode 100644
index 00000000000..f044f3bb156
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/align.ll
@@ -0,0 +1,13 @@
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
+; RUN: | FileCheck %s -check-prefix=RV32I
+; RUN: llc -mtriple=riscv32 -mattr=+c -verify-machineinstrs < %s \
+; RUN: | FileCheck %s -check-prefix=RV32C
+
+define void @foo() {
+;RV32I: .p2align 2
+;RV32I: foo:
+;RV32C: .p2align 1
+;RV32C: foo:
+entry:
+ ret void
+}
OpenPOWER on IntegriCloud