Skip to content

[Xtensa] Move XtensaUtils to MCTargetDesc #123969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion llvm/lib/Target/Xtensa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ add_llvm_target(XtensaCodeGen
XtensaRegisterInfo.cpp
XtensaSubtarget.cpp
XtensaTargetMachine.cpp
XtensaUtils.cpp

LINK_COMPONENTS
AsmPrinter
Expand Down
42 changes: 42 additions & 0 deletions llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,48 @@

using namespace llvm;

bool Xtensa::isValidAddrOffset(int Scale, int64_t OffsetVal) {
bool Valid = false;

switch (Scale) {
case 1:
Valid = (OffsetVal >= 0 && OffsetVal <= 255);
break;
case 2:
Valid = (OffsetVal >= 0 && OffsetVal <= 510) && ((OffsetVal & 0x1) == 0);
break;
case 4:
Valid = (OffsetVal >= 0 && OffsetVal <= 1020) && ((OffsetVal & 0x3) == 0);
break;
default:
break;
}
return Valid;
}

bool Xtensa::isValidAddrOffsetForOpcode(unsigned Opcode, int64_t Offset) {
int Scale = 0;

switch (Opcode) {
case Xtensa::L8UI:
case Xtensa::S8I:
Scale = 1;
break;
case Xtensa::L16SI:
case Xtensa::L16UI:
case Xtensa::S16I:
Scale = 2;
break;
case Xtensa::LEA_ADD:
return (Offset >= -128 && Offset <= 127);
default:
// assume that MI is 32-bit load/store operation
Scale = 4;
break;
}
return isValidAddrOffset(Scale, Offset);
}

static MCAsmInfo *createXtensaMCAsmInfo(const MCRegisterInfo &MRI,
const Triple &TT,
const MCTargetOptions &Options) {
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCTargetDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MCObjectWriter;
class MCRegisterInfo;
class MCSubtargetInfo;
class MCTargetOptions;
class MachineInstr;
class StringRef;
class Target;
class raw_ostream;
Expand All @@ -43,6 +44,15 @@ MCAsmBackend *createXtensaMCAsmBackend(const Target &T,
const MCTargetOptions &Options);
std::unique_ptr<MCObjectTargetWriter>
createXtensaObjectWriter(uint8_t OSABI, bool IsLittleEndian);

namespace Xtensa {
// Check address offset for load/store instructions.
// The offset should be multiple of scale.
bool isValidAddrOffset(int Scale, int64_t OffsetVal);

// Check address offset for load/store instructions.
bool isValidAddrOffsetForOpcode(unsigned Opcode, int64_t Offset);
} // namespace Xtensa
} // end namespace llvm

// Defines symbolic names for Xtensa registers.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/Xtensa/XtensaISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
//
//===----------------------------------------------------------------------===//

#include "MCTargetDesc/XtensaMCTargetDesc.h"
#include "Xtensa.h"
#include "XtensaTargetMachine.h"
#include "XtensaUtils.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/SelectionDAGISel.h"
Expand Down Expand Up @@ -75,7 +75,7 @@ class XtensaDAGToDAGISel : public SelectionDAGISel {
ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
int64_t OffsetVal = CN->getSExtValue();

Valid = isValidAddrOffset(Scale, OffsetVal);
Valid = Xtensa::isValidAddrOffset(Scale, OffsetVal);

if (Valid) {
// If the first operand is a FI, get the TargetFI Node.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/Xtensa/XtensaRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
//===----------------------------------------------------------------------===//

#include "XtensaRegisterInfo.h"
#include "MCTargetDesc/XtensaMCTargetDesc.h"
#include "XtensaInstrInfo.h"
#include "XtensaSubtarget.h"
#include "XtensaUtils.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
Expand Down Expand Up @@ -99,7 +99,7 @@ bool XtensaRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
int64_t Offset =
SPOffset + (int64_t)StackSize + MI.getOperand(FIOperandNum + 1).getImm();

bool Valid = isValidAddrOffset(MI, Offset);
bool Valid = Xtensa::isValidAddrOffsetForOpcode(MI.getOpcode(), Offset);

// If MI is not a debug value, make sure Offset fits in the 16-bit immediate
// field.
Expand Down
59 changes: 0 additions & 59 deletions llvm/lib/Target/Xtensa/XtensaUtils.cpp

This file was deleted.

27 changes: 0 additions & 27 deletions llvm/lib/Target/Xtensa/XtensaUtils.h

This file was deleted.

Loading