LLVM 20.0.0git
XtensaUtils.cpp
Go to the documentation of this file.
1//===--- XtensaUtils.cpp ---- Xtensa Utility Functions ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains miscellaneous utility functions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "XtensaUtils.h"
14
15namespace llvm {
16
17bool isValidAddrOffset(int Scale, int64_t OffsetVal) {
18 bool Valid = false;
19
20 switch (Scale) {
21 case 1:
22 Valid = (OffsetVal >= 0 && OffsetVal <= 255);
23 break;
24 case 2:
25 Valid = (OffsetVal >= 0 && OffsetVal <= 510) && ((OffsetVal & 0x1) == 0);
26 break;
27 case 4:
28 Valid = (OffsetVal >= 0 && OffsetVal <= 1020) && ((OffsetVal & 0x3) == 0);
29 break;
30 default:
31 break;
32 }
33 return Valid;
34}
35
37 int Scale = 0;
38
39 switch (MI.getOpcode()) {
40 case Xtensa::L8UI:
41 case Xtensa::S8I:
42 Scale = 1;
43 break;
44 case Xtensa::L16SI:
45 case Xtensa::L16UI:
46 case Xtensa::S16I:
47 Scale = 2;
48 break;
49 case Xtensa::LEA_ADD:
50 return (Offset >= -128 && Offset <= 127);
51 default:
52 // assume that MI is 32-bit load/store operation
53 Scale = 4;
54 break;
55 }
56 return isValidAddrOffset(Scale, Offset);
57}
58
59} // namespace llvm
IRTranslator LLVM IR MI
Representation of each machine instruction.
Definition: MachineInstr.h:69
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
bool isValidAddrOffset(int Scale, int64_t OffsetVal)
Definition: XtensaUtils.cpp:17