Path: blob/main/contrib/llvm-project/llvm/lib/Target/Xtensa/XtensaUtils.cpp
35271 views
//===--- XtensaUtils.cpp ---- Xtensa Utility Functions ----------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains miscellaneous utility functions.9//10//===----------------------------------------------------------------------===//1112#include "XtensaUtils.h"1314namespace llvm {1516bool isValidAddrOffset(int Scale, int64_t OffsetVal) {17bool Valid = false;1819switch (Scale) {20case 1:21Valid = (OffsetVal >= 0 && OffsetVal <= 255);22break;23case 2:24Valid = (OffsetVal >= 0 && OffsetVal <= 510) && ((OffsetVal & 0x1) == 0);25break;26case 4:27Valid = (OffsetVal >= 0 && OffsetVal <= 1020) && ((OffsetVal & 0x3) == 0);28break;29default:30break;31}32return Valid;33}3435bool isValidAddrOffset(MachineInstr &MI, int64_t Offset) {36int Scale = 0;3738switch (MI.getOpcode()) {39case Xtensa::L8UI:40case Xtensa::S8I:41Scale = 1;42break;43case Xtensa::L16SI:44case Xtensa::L16UI:45case Xtensa::S16I:46Scale = 2;47break;48case Xtensa::LEA_ADD:49return (Offset >= -128 && Offset <= 127);50default:51// assume that MI is 32-bit load/store operation52Scale = 4;53break;54}55return isValidAddrOffset(Scale, Offset);56}5758} // namespace llvm596061