mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-12 14:20:33 +00:00
Add helper function.
Don't touch GEPs for which DecomposeArrayRef is not going to do anything special (e.g., < 2 indices, or 2 indices and the last one is a constant.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14647 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a9e7781b3b
commit
10585d92da
@ -24,6 +24,7 @@
|
|||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "Support/Statistic.h"
|
#include "Support/Statistic.h"
|
||||||
|
#include "Support/Debug.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -52,6 +53,10 @@ FunctionPass *llvm::createDecomposeMultiDimRefsPass() {
|
|||||||
return new DecomposePass();
|
return new DecomposePass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool isZeroConst (Value *V) {
|
||||||
|
return isa<Constant> (V) && (cast<Constant>(V)->isNullValue());
|
||||||
|
}
|
||||||
|
|
||||||
// Function: DecomposeArrayRef()
|
// Function: DecomposeArrayRef()
|
||||||
//
|
//
|
||||||
// For any GetElementPtrInst with 2 or more array and structure indices:
|
// For any GetElementPtrInst with 2 or more array and structure indices:
|
||||||
@ -76,8 +81,15 @@ FunctionPass *llvm::createDecomposeMultiDimRefsPass() {
|
|||||||
// Return value: true if the instruction was replaced; false otherwise.
|
// Return value: true if the instruction was replaced; false otherwise.
|
||||||
//
|
//
|
||||||
bool llvm::DecomposeArrayRef(GetElementPtrInst* GEP) {
|
bool llvm::DecomposeArrayRef(GetElementPtrInst* GEP) {
|
||||||
if (GEP->getNumIndices() < 2)
|
if (GEP->getNumIndices() < 2
|
||||||
|
|| (GEP->getNumIndices() == 2
|
||||||
|
&& isZeroConst(GEP->getOperand(1))
|
||||||
|
&& isa<ConstantInt>(GEP->getOperand(2)))) {
|
||||||
|
DEBUG (std::cerr << "DecomposeArrayRef: Skipping " << *GEP);
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
DEBUG (std::cerr << "DecomposeArrayRef: Decomposing " << *GEP);
|
||||||
|
}
|
||||||
|
|
||||||
BasicBlock *BB = GEP->getParent();
|
BasicBlock *BB = GEP->getParent();
|
||||||
Value *LastPtr = GEP->getPointerOperand();
|
Value *LastPtr = GEP->getPointerOperand();
|
||||||
@ -90,7 +102,7 @@ bool llvm::DecomposeArrayRef(GetElementPtrInst* GEP) {
|
|||||||
|
|
||||||
// If this is the first index and is 0, skip it and move on!
|
// If this is the first index and is 0, skip it and move on!
|
||||||
if (OI == GEP->idx_begin()) {
|
if (OI == GEP->idx_begin()) {
|
||||||
if (*OI == ConstantInt::getNullValue((*OI)->getType()))
|
if (isZeroConst (*OI))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else // Not the first index: include initial [0] to deref the last ptr
|
else // Not the first index: include initial [0] to deref the last ptr
|
||||||
|
Loading…
Reference in New Issue
Block a user