Skip to content

Commit

Permalink
[MSP430] Add subtarget features for hardware multiplier.
Browse files Browse the repository at this point in the history
Also add more processors to make -mcpu option behave similar to gcc.

Differential Revision: https://reviews.llvm.org/D33335

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303695 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
pftbest committed May 23, 2017
1 parent 5be8b93 commit 50bd917
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 25 deletions.
14 changes: 14 additions & 0 deletions lib/Target/MSP430/MSP430.td
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,27 @@ def FeatureX
: SubtargetFeature<"ext", "ExtendedInsts", "true",
"Enable MSP430-X extensions">;

def FeatureHWMult16
: SubtargetFeature<"hwmult16", "HWMultMode", "HWMult16",
"Enable 16-bit hardware multiplier">;

def FeatureHWMult32
: SubtargetFeature<"hwmult32", "HWMultMode", "HWMult32",
"Enable 32-bit hardware multiplier">;

def FeatureHWMultF5
: SubtargetFeature<"hwmultf5", "HWMultMode", "HWMultF5",
"Enable F5 series hardware multiplier">;

//===----------------------------------------------------------------------===//
// MSP430 supported processors.
//===----------------------------------------------------------------------===//
class Proc<string Name, list<SubtargetFeature> Features>
: Processor<Name, NoItineraries, Features>;

def : Proc<"generic", []>;
def : Proc<"msp430", []>;
def : Proc<"msp430x", [FeatureX]>;

//===----------------------------------------------------------------------===//
// Register File Description
Expand Down
27 changes: 3 additions & 24 deletions lib/Target/MSP430/MSP430ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,6 @@ using namespace llvm;

#define DEBUG_TYPE "msp430-lower"

typedef enum {
NoHWMult,
HWMult16,
HWMult32,
HWMultF5
} HWMultUseMode;

static cl::opt<HWMultUseMode>
HWMultMode("mhwmult", cl::Hidden,
cl::desc("Hardware multiplier use mode"),
cl::init(NoHWMult),
cl::values(
clEnumValN(NoHWMult, "none",
"Do not use hardware multiplier"),
clEnumValN(HWMult16, "16bit",
"Use 16-bit hardware multiplier"),
clEnumValN(HWMult32, "32bit",
"Use 32-bit hardware multiplier"),
clEnumValN(HWMultF5, "f5series",
"Use F5 series hardware multiplier")));

MSP430TargetLowering::MSP430TargetLowering(const TargetMachine &TM,
const MSP430Subtarget &STI)
: TargetLowering(TM) {
Expand Down Expand Up @@ -262,7 +241,7 @@ MSP430TargetLowering::MSP430TargetLowering(const TargetMachine &TM,
setCmpLibcallCC(LC.Op, LC.Cond);
}

if (HWMultMode == HWMult16) {
if (STI.hasHWMult16()) {
const struct {
const RTLIB::Libcall Op;
const char * const Name;
Expand All @@ -277,7 +256,7 @@ MSP430TargetLowering::MSP430TargetLowering(const TargetMachine &TM,
for (const auto &LC : LibraryCalls) {
setLibcallName(LC.Op, LC.Name);
}
} else if (HWMultMode == HWMult32) {
} else if (STI.hasHWMult32()) {
const struct {
const RTLIB::Libcall Op;
const char * const Name;
Expand All @@ -292,7 +271,7 @@ MSP430TargetLowering::MSP430TargetLowering(const TargetMachine &TM,
for (const auto &LC : LibraryCalls) {
setLibcallName(LC.Op, LC.Name);
}
} else if (HWMultMode == HWMultF5) {
} else if (STI.hasHWMultF5()) {
const struct {
const RTLIB::Libcall Op;
const char * const Name;
Expand Down
27 changes: 26 additions & 1 deletion lib/Target/MSP430/MSP430Subtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ using namespace llvm;

#define DEBUG_TYPE "msp430-subtarget"

static cl::opt<MSP430Subtarget::HWMultEnum>
HWMultModeOption("mhwmult", cl::Hidden,
cl::desc("Hardware multiplier use mode for MSP430"),
cl::init(MSP430Subtarget::NoHWMult),
cl::values(
clEnumValN(MSP430Subtarget::NoHWMult, "none",
"Do not use hardware multiplier"),
clEnumValN(MSP430Subtarget::HWMult16, "16bit",
"Use 16-bit hardware multiplier"),
clEnumValN(MSP430Subtarget::HWMult32, "32bit",
"Use 32-bit hardware multiplier"),
clEnumValN(MSP430Subtarget::HWMultF5, "f5series",
"Use F5 series hardware multiplier")));

#define GET_SUBTARGETINFO_TARGET_DESC
#define GET_SUBTARGETINFO_CTOR
#include "MSP430GenSubtargetInfo.inc"
Expand All @@ -27,7 +41,18 @@ void MSP430Subtarget::anchor() { }

MSP430Subtarget &
MSP430Subtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
ParseSubtargetFeatures("generic", FS);
ExtendedInsts = false;
HWMultMode = NoHWMult;

std::string CPUName = CPU;
if (CPUName.empty())
CPUName = "msp430";

ParseSubtargetFeatures(CPUName, FS);

if (HWMultModeOption != NoHWMult)
HWMultMode = HWMultModeOption;

return *this;
}

Expand Down
11 changes: 11 additions & 0 deletions lib/Target/MSP430/MSP430Subtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ namespace llvm {
class StringRef;

class MSP430Subtarget : public MSP430GenSubtargetInfo {
public:
enum HWMultEnum {
NoHWMult, HWMult16, HWMult32, HWMultF5
};

private:
virtual void anchor();
bool ExtendedInsts;
HWMultEnum HWMultMode;
MSP430FrameLowering FrameLowering;
MSP430InstrInfo InstrInfo;
MSP430TargetLowering TLInfo;
Expand All @@ -50,6 +57,10 @@ class MSP430Subtarget : public MSP430GenSubtargetInfo {
/// subtarget options. Definition of function is auto generated by tblgen.
void ParseSubtargetFeatures(StringRef CPU, StringRef FS);

bool hasHWMult16() const { return HWMultMode == HWMult16; }
bool hasHWMult32() const { return HWMultMode == HWMult32; }
bool hasHWMultF5() const { return HWMultMode == HWMultF5; }

const TargetFrameLowering *getFrameLowering() const override {
return &FrameLowering;
}
Expand Down
1 change: 1 addition & 0 deletions test/CodeGen/MSP430/hwmult16.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: llc -O0 -mhwmult=16bit < %s | FileCheck %s
; RUN: llc -O0 -mattr=+hwmult16 < %s | FileCheck %s

target datalayout = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16-a0:16:16"
target triple = "msp430---elf"
Expand Down
1 change: 1 addition & 0 deletions test/CodeGen/MSP430/hwmult32.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: llc -O0 -mhwmult=32bit < %s | FileCheck %s
; RUN: llc -O0 -mattr=+hwmult32 < %s | FileCheck %s

target datalayout = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16-a0:16:16"
target triple = "msp430---elf"
Expand Down
1 change: 1 addition & 0 deletions test/CodeGen/MSP430/hwmultf5.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: llc -O0 -mhwmult=f5series < %s | FileCheck %s
; RUN: llc -O0 -mattr=+hwmultf5 < %s | FileCheck %s

target datalayout = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16-a0:16:16"
target triple = "msp430---elf"
Expand Down

0 comments on commit 50bd917

Please sign in to comment.