mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-16 00:33:10 +00:00
eliminate temporary vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33693 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2b9a5daf7c
commit
55eb1c47de
@ -25,6 +25,7 @@
|
||||
#include "llvm/Analysis/ConstantFolding.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include <algorithm>
|
||||
@ -443,11 +444,12 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV) {
|
||||
// Form a shorter GEP if needed.
|
||||
if (GEP->getNumOperands() > 3)
|
||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(GEP)) {
|
||||
std::vector<Constant*> Idxs;
|
||||
SmallVector<Constant*, 8> Idxs;
|
||||
Idxs.push_back(NullInt);
|
||||
for (unsigned i = 3, e = CE->getNumOperands(); i != e; ++i)
|
||||
Idxs.push_back(CE->getOperand(i));
|
||||
NewPtr = ConstantExpr::getGetElementPtr(cast<Constant>(NewPtr), Idxs);
|
||||
NewPtr = ConstantExpr::getGetElementPtr(cast<Constant>(NewPtr),
|
||||
&Idxs[0], Idxs.size());
|
||||
} else {
|
||||
GetElementPtrInst *GEPI = cast<GetElementPtrInst>(GEP);
|
||||
std::vector<Value*> Idxs;
|
||||
@ -576,16 +578,17 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) {
|
||||
}
|
||||
} else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(I)) {
|
||||
// Should handle GEP here.
|
||||
std::vector<Constant*> Indices;
|
||||
Indices.reserve(GEPI->getNumOperands()-1);
|
||||
SmallVector<Constant*, 8> Idxs;
|
||||
Idxs.reserve(GEPI->getNumOperands()-1);
|
||||
for (unsigned i = 1, e = GEPI->getNumOperands(); i != e; ++i)
|
||||
if (Constant *C = dyn_cast<Constant>(GEPI->getOperand(i)))
|
||||
Indices.push_back(C);
|
||||
Idxs.push_back(C);
|
||||
else
|
||||
break;
|
||||
if (Indices.size() == GEPI->getNumOperands()-1)
|
||||
if (Idxs.size() == GEPI->getNumOperands()-1)
|
||||
Changed |= OptimizeAwayTrappingUsesOfValue(GEPI,
|
||||
ConstantExpr::getGetElementPtr(NewV, Indices));
|
||||
ConstantExpr::getGetElementPtr(NewV, &Idxs[0],
|
||||
Idxs.size()));
|
||||
if (GEPI->use_empty()) {
|
||||
Changed = true;
|
||||
GEPI->eraseFromParent();
|
||||
@ -1744,10 +1747,10 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
|
||||
getVal(Values, SI->getOperand(2)));
|
||||
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CurInst)) {
|
||||
Constant *P = getVal(Values, GEP->getOperand(0));
|
||||
std::vector<Constant*> GEPOps;
|
||||
SmallVector<Constant*, 8> GEPOps;
|
||||
for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i)
|
||||
GEPOps.push_back(getVal(Values, GEP->getOperand(i)));
|
||||
InstResult = ConstantExpr::getGetElementPtr(P, GEPOps);
|
||||
InstResult = ConstantExpr::getGetElementPtr(P, &GEPOps[0], GEPOps.size());
|
||||
} else if (LoadInst *LI = dyn_cast<LoadInst>(CurInst)) {
|
||||
if (LI->isVolatile()) return false; // no volatile accesses.
|
||||
InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)),
|
||||
|
@ -173,9 +173,10 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
|
||||
/*empty*/;
|
||||
if (isa<SequentialType>(*GTI)) {
|
||||
// Pull the last index out of the constant expr GEP.
|
||||
std::vector<Value*> CEIdxs(CE->op_begin()+1, CE->op_end()-1);
|
||||
SmallVector<Value*, 8> CEIdxs(CE->op_begin()+1, CE->op_end()-1);
|
||||
Constant *NCE = ConstantExpr::getGetElementPtr(CE->getOperand(0),
|
||||
CEIdxs);
|
||||
&CEIdxs[0],
|
||||
CEIdxs.size());
|
||||
GetElementPtrInst *NGEPI =
|
||||
new GetElementPtrInst(NCE, Constant::getNullValue(Type::Int32Ty),
|
||||
NewAdd, GEPI->getName(), GEPI);
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/PatternMatch.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include <algorithm>
|
||||
@ -7797,13 +7798,14 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||
// constants, we can promote this to a constexpr instead of an instruction.
|
||||
|
||||
// Scan for nonconstants...
|
||||
std::vector<Constant*> Indices;
|
||||
SmallVector<Constant*, 8> Indices;
|
||||
User::op_iterator I = GEP.idx_begin(), E = GEP.idx_end();
|
||||
for (; I != E && isa<Constant>(*I); ++I)
|
||||
Indices.push_back(cast<Constant>(*I));
|
||||
|
||||
if (I == E) { // If they are all constants...
|
||||
Constant *CE = ConstantExpr::getGetElementPtr(GV, Indices);
|
||||
Constant *CE = ConstantExpr::getGetElementPtr(GV,
|
||||
&Indices[0],Indices.size());
|
||||
|
||||
// Replace all uses of the GEP with the new constexpr...
|
||||
return ReplaceInstUsesWith(GEP, CE);
|
||||
@ -8001,8 +8003,9 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI) {
|
||||
if (const ArrayType *ASrcTy = dyn_cast<ArrayType>(SrcPTy))
|
||||
if (Constant *CSrc = dyn_cast<Constant>(CastOp))
|
||||
if (ASrcTy->getNumElements() != 0) {
|
||||
std::vector<Value*> Idxs(2, Constant::getNullValue(Type::Int32Ty));
|
||||
CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs);
|
||||
Value *Idxs[2];
|
||||
Idxs[0] = Idxs[1] = Constant::getNullValue(Type::Int32Ty);
|
||||
CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs, 2);
|
||||
SrcTy = cast<PointerType>(CastOp->getType());
|
||||
SrcPTy = SrcTy->getElementType();
|
||||
}
|
||||
@ -8188,8 +8191,9 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
|
||||
if (const ArrayType *ASrcTy = dyn_cast<ArrayType>(SrcPTy))
|
||||
if (Constant *CSrc = dyn_cast<Constant>(CastOp))
|
||||
if (ASrcTy->getNumElements() != 0) {
|
||||
std::vector<Value*> Idxs(2, Constant::getNullValue(Type::Int32Ty));
|
||||
CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs);
|
||||
Value* Idxs[2];
|
||||
Idxs[0] = Idxs[1] = Constant::getNullValue(Type::Int32Ty);
|
||||
CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs, 2);
|
||||
SrcTy = cast<PointerType>(CastOp->getType());
|
||||
SrcPTy = SrcTy->getElementType();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user