Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit adaebc8

Browse files
author
Sumanth Gundapaneni
committed
Use ".arch_extension" ARM directive to support hwdiv on krait
In case of "krait" CPU, asm printer doesn't emit any ".cpu" so the features bits are not computed. This patch lets the asm printer emit ".cpu cortex-a9" directive for krait and the hwdiv feature is enabled through ".arch_extension". In short, krait is treated as "cortex-a9" with hwdiv. We can not emit ".krait" as CPU since it is not supported bu GNU GAS yet git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230651 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7c0f2ab commit adaebc8

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

lib/Target/ARM/ARMAsmPrinter.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "ARM.h"
1717
#include "ARMConstantPoolValue.h"
1818
#include "ARMFPUName.h"
19+
#include "ARMArchExtName.h"
1920
#include "ARMMachineFunctionInfo.h"
2021
#include "ARMTargetMachine.h"
2122
#include "ARMTargetObjectFile.h"
@@ -668,9 +669,17 @@ void ARMAsmPrinter::emitAttributes() {
668669

669670
std::string CPUString = STI.getCPUString();
670671

671-
// FIXME: remove krait check when GNU tools support krait cpu
672-
if (CPUString != "generic" && CPUString != "krait")
673-
ATS.emitTextAttribute(ARMBuildAttrs::CPU_name, CPUString);
672+
if (CPUString != "generic") {
673+
// FIXME: remove krait check when GNU tools support krait cpu
674+
if (STI.isKrait()) {
675+
ATS.emitTextAttribute(ARMBuildAttrs::CPU_name, "cortex-a9");
676+
// We consider krait as a "cortex-a9" + hwdiv CPU
677+
// Enable hwdiv through ".arch_extension idiv"
678+
if (STI.hasDivide() || STI.hasDivideInARMMode())
679+
ATS.emitArchExtension(ARM::HWDIV);
680+
} else
681+
ATS.emitTextAttribute(ARMBuildAttrs::CPU_name, CPUString);
682+
}
674683

675684
ATS.emitAttribute(ARMBuildAttrs::CPU_arch, getArchForCPU(CPUString, &STI));
676685

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; Tests the genration of ".arch_extension" attribute for hardware
2+
; division on krait CPU. For now, krait is recognized as "cortex-a9" + hwdiv
3+
; Also, tests for the hwdiv instruction on krait CPU
4+
5+
; check for arch_extension/cpu directive
6+
; RUN: llc < %s -mtriple=armv7-linux-gnueabi -mcpu=krait | FileCheck %s --check-prefix=DIV_EXTENSION
7+
; RUN: llc < %s -mtriple=thumbv7-linux-gnueabi -mcpu=krait | FileCheck %s --check-prefix=DIV_EXTENSION
8+
; RUN: llc < %s -mtriple=armv7-linux-gnueabi -mcpu=cortex-a9 | FileCheck %s --check-prefix=NODIV_KRAIT
9+
; RUN: llc < %s -mtriple=thumbv7-linux-gnueabi -mcpu=cortex-a9 | FileCheck %s --check-prefix=NODIV_KRAIT
10+
; RUN: llc < %s -mcpu=krait -mattr=-hwdiv,-hwdiv-arm | FileCheck %s --check-prefix=NODIV_KRAIT
11+
12+
; check if correct instruction is emitted by integrated assembler
13+
; RUN: llc < %s -mtriple=armv7-linux-gnueabi -mcpu=krait -filetype=obj | llvm-objdump -mcpu=krait -triple armv7-linux-gnueabi -d - | FileCheck %s --check-prefix=HWDIV
14+
; RUN: llc < %s -mtriple=thumbv7-linux-gnueabi -mcpu=krait -filetype=obj | llvm-objdump -mcpu=krait -triple thumbv7-linux-gnueabi -d - | FileCheck %s --check-prefix=HWDIV
15+
16+
; arch_extension attribute
17+
; DIV_EXTENSION: .cpu cortex-a9
18+
; DIV_EXTENSION: .arch_extension idiv
19+
; NODIV_KRAIT-NOT: .arch_extension idiv
20+
; HWDIV: sdiv
21+
22+
define i32 @main() #0 {
23+
entry:
24+
%retval = alloca i32, align 4
25+
%a = alloca i32, align 4
26+
%b = alloca i32, align 4
27+
%c = alloca i32, align 4
28+
store i32 0, i32* %retval
29+
store volatile i32 100, i32* %b, align 4
30+
store volatile i32 32, i32* %c, align 4
31+
%0 = load volatile i32* %b, align 4
32+
%1 = load volatile i32* %c, align 4
33+
%div = sdiv i32 %0, %1
34+
store volatile i32 %div, i32* %a, align 4
35+
ret i32 0
36+
}

0 commit comments

Comments
 (0)