forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SandboxIR] Functions to find vectorizor-relevant properties (llvm#10…
…9221) When vectorizing, the destination type and value of stores is more relevant than the type of the instruction itself. Similarly for return instructions. These functions provide a convenient way to do that without special-casing them everywhere, and avoids the need for friending any class that needs access to Value::LLVMTy to calculate it. Open to better naming.
- Loading branch information
1 parent
6267f12
commit d1edef5
Showing
3 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===- Utils.h --------------------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Collector for SandboxIR related convenience functions that don't belong in | ||
// other classes. | ||
|
||
#ifndef LLVM_SANDBOXIR_UTILS_H | ||
#define LLVM_SANDBOXIR_UTILS_H | ||
|
||
namespace llvm::sandboxir { | ||
|
||
class Utils { | ||
public: | ||
/// \Returns the expected type of \p Value V. For most Values this is | ||
/// equivalent to getType, but for stores returns the stored type, rather | ||
/// than void, and for ReturnInsts returns the returned type. | ||
static Type *getExpectedType(const Value *V) { | ||
if (auto *I = dyn_cast<Instruction>(V)) { | ||
// A Return's value operand can be null if it returns void. | ||
if (auto *RI = dyn_cast<ReturnInst>(I)) { | ||
if (RI->getReturnValue() == nullptr) | ||
return RI->getType(); | ||
} | ||
return getExpectedValue(I)->getType(); | ||
} | ||
return V->getType(); | ||
} | ||
|
||
/// \Returns the expected Value for this instruction. For most instructions, | ||
/// this is the instruction itself, but for stores returns the stored | ||
/// operand, and for ReturnInstructions returns the returned value. | ||
static Value *getExpectedValue(const Instruction *I) { | ||
if (auto *SI = dyn_cast<StoreInst>(I)) | ||
return SI->getValueOperand(); | ||
if (auto *RI = dyn_cast<ReturnInst>(I)) | ||
return RI->getReturnValue(); | ||
return const_cast<Instruction *>(I); | ||
} | ||
|
||
/// \Returns the number of bits required to represent the operands or return | ||
/// value of \p V in \p DL. | ||
static unsigned getNumBits(Value *V, const DataLayout &DL) { | ||
Type *Ty = getExpectedType(V); | ||
return DL.getTypeSizeInBits(Ty->LLVMTy); | ||
} | ||
}; | ||
} // namespace llvm::sandboxir | ||
|
||
#endif // LLVM_SANDBOXIR_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters