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

Commit

Permalink
[ARM] Define subtarget feature strict-align.
Browse files Browse the repository at this point in the history
This commit defines subtarget feature strict-align and uses it instead of
cl::opt -arm-strict-align to decide whether strict alignment should be
forced. Also, remove the logic that was checking the OS and architecture
as clang is now responsible for setting strict-align based on the command
line options specified and the target architecute and OS.

rdar://problem/21529937

http://reviews.llvm.org/D11470

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243493 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ahatanaka committed Jul 28, 2015
1 parent db059db commit 4fb2f33
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 129 deletions.
5 changes: 5 additions & 0 deletions lib/Target/ARM/ARM.td
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ def FeatureAClass : SubtargetFeature<"aclass", "ARMProcClass", "AClass",
def FeatureNaClTrap : SubtargetFeature<"nacl-trap", "UseNaClTrap", "true",
"NaCl trap">;

def FeatureStrictAlign : SubtargetFeature<"strict-align",
"StrictAlign", "true",
"Disallow all unaligned memory "
"access">;

def FeatureLongCalls : SubtargetFeature<"long-calls", "GenLongCalls", "true",
"Generate calls via indirect call "
"instructions">;
Expand Down
49 changes: 1 addition & 48 deletions lib/Target/ARM/ARMSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,6 @@ static cl::opt<bool>
UseFusedMulOps("arm-use-mulops",
cl::init(true), cl::Hidden);

namespace {
enum AlignMode {
DefaultAlign,
StrictAlign,
NoStrictAlign
};
}

static cl::opt<AlignMode>
Align(cl::desc("Load/store alignment support"),
cl::Hidden, cl::init(DefaultAlign),
cl::values(
clEnumValN(DefaultAlign, "arm-default-align",
"Generate unaligned accesses only on hardware/OS "
"combinations that are known to support them"),
clEnumValN(StrictAlign, "arm-strict-align",
"Disallow all unaligned memory accesses"),
clEnumValN(NoStrictAlign, "arm-no-strict-align",
"Allow unaligned memory accesses"),
clEnumValEnd));

enum ITMode {
DefaultIT,
RestrictedIT,
Expand Down Expand Up @@ -161,7 +140,7 @@ void ARMSubtarget::initializeEnvironment() {
HasCrypto = false;
HasCRC = false;
HasZeroCycleZeroing = false;
AllowsUnalignedMem = false;
StrictAlign = false;
Thumb2DSP = false;
UseNaClTrap = false;
GenLongCalls = false;
Expand Down Expand Up @@ -213,32 +192,6 @@ void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
else
SupportsTailCall = !isThumb1Only();

if (Align == DefaultAlign) {
// Assume pre-ARMv6 doesn't support unaligned accesses.
//
// ARMv6 may or may not support unaligned accesses depending on the
// SCTLR.U bit, which is architecture-specific. We assume ARMv6
// Darwin and NetBSD targets support unaligned accesses, and others don't.
//
// ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
// which raises an alignment fault on unaligned accesses. Linux
// defaults this bit to 0 and handles it as a system-wide (not
// per-process) setting. It is therefore safe to assume that ARMv7+
// Linux targets support unaligned accesses. The same goes for NaCl.
//
// The above behavior is consistent with GCC.
AllowsUnalignedMem =
(hasV7Ops() && (isTargetLinux() || isTargetNaCl() ||
isTargetNetBSD())) ||
(hasV6Ops() && (isTargetMachO() || isTargetNetBSD()));
} else {
AllowsUnalignedMem = !(Align == StrictAlign);
}

// No v6M core supports unaligned memory access (v6M ARM ARM A3.2)
if (isV6M())
AllowsUnalignedMem = false;

switch (IT) {
case DefaultIT:
RestrictIT = hasV8Ops();
Expand Down
10 changes: 3 additions & 7 deletions lib/Target/ARM/ARMSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
/// particularly effective at zeroing a VFP register.
bool HasZeroCycleZeroing;

/// AllowsUnalignedMem - If true, the subtarget allows unaligned memory
/// StrictAlign - If true, the subtarget disallows unaligned memory
/// accesses for some types. For details, see
/// ARMTargetLowering::allowsMisalignedMemoryAccesses().
bool AllowsUnalignedMem;
bool StrictAlign;

/// RestrictIT - If true, the subtarget disallows generation of deprecated IT
/// blocks to conform to ARMv8 rule.
Expand Down Expand Up @@ -409,10 +409,6 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
bool isRClass() const { return ARMProcClass == RClass; }
bool isAClass() const { return ARMProcClass == AClass; }

bool isV6M() const {
return isThumb1Only() && isMClass();
}

bool isR9Reserved() const {
return isTargetMachO() ? (ReserveR9 || !HasV6Ops) : ReserveR9;
}
Expand All @@ -421,7 +417,7 @@ class ARMSubtarget : public ARMGenSubtargetInfo {

bool supportsTailCall() const { return SupportsTailCall; }

bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
bool allowsUnalignedMem() const { return !StrictAlign; }

bool restrictIT() const { return RestrictIT; }

Expand Down
2 changes: 1 addition & 1 deletion test/CodeGen/ARM/2011-10-26-memset-inline.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; Make sure short memsets on ARM lower to stores, even when optimizing for size.
; RUN: llc -march=arm < %s | FileCheck %s -check-prefix=CHECK-GENERIC
; RUN: llc -march=arm -mattr=+strict-align < %s | FileCheck %s -check-prefix=CHECK-GENERIC
; RUN: llc -march=arm -mcpu=cortex-a8 < %s | FileCheck %s -check-prefix=CHECK-UNALIGNED

target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32"
Expand Down
Loading

0 comments on commit 4fb2f33

Please sign in to comment.