mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-29 13:32:33 +00:00
Change the interface to constant expressions to allow automatic folding
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5793 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dabaa46c66
commit
fb242b6edc
@ -476,17 +476,19 @@ protected:
|
|||||||
~ConstantExpr() {}
|
~ConstantExpr() {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Static methods to construct a ConstantExpr of different kinds.
|
// Static methods to construct a ConstantExpr of different kinds. Note that
|
||||||
|
// these methods can return a constant of an arbitrary type, because they will
|
||||||
|
// attempt to fold the constant expression into something simple if they can.
|
||||||
|
|
||||||
/// Cast constant expr
|
/// Cast constant expr
|
||||||
static ConstantExpr *getCast(Constant *C, const Type *Ty);
|
static Constant *getCast(Constant *C, const Type *Ty);
|
||||||
|
|
||||||
/// Binary constant expr - Use with binary operators...
|
/// Binary constant expr - Use with binary operators...
|
||||||
static ConstantExpr *get(unsigned Opcode, Constant *C1, Constant *C2);
|
static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
|
||||||
|
|
||||||
/// Getelementptr form...
|
/// Getelementptr form...
|
||||||
static ConstantExpr *getGetElementPtr(Constant *C,
|
static Constant *getGetElementPtr(Constant *C,
|
||||||
const std::vector<Constant*> &IdxList);
|
const std::vector<Constant*> &IdxList);
|
||||||
|
|
||||||
/// isNullValue - Return true if this is the value that would be returned by
|
/// isNullValue - Return true if this is the value that would be returned by
|
||||||
/// getNullValue.
|
/// getNullValue.
|
||||||
|
@ -207,7 +207,7 @@ static bool ResolveGlobalVariables(Module &M,
|
|||||||
std::vector<Constant*> Args;
|
std::vector<Constant*> Args;
|
||||||
Args.push_back(Constant::getNullValue(Type::LongTy));
|
Args.push_back(Constant::getNullValue(Type::LongTy));
|
||||||
Args.push_back(Constant::getNullValue(Type::LongTy));
|
Args.push_back(Constant::getNullValue(Type::LongTy));
|
||||||
ConstantExpr *Replacement =
|
Constant *Replacement =
|
||||||
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(Concrete), Args);
|
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(Concrete), Args);
|
||||||
|
|
||||||
for (unsigned i = 0; i != Globals.size(); ++i)
|
for (unsigned i = 0; i != Globals.size(); ++i)
|
||||||
|
@ -1011,7 +1011,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
Indices.push_back(cast<Constant>(*I));
|
Indices.push_back(cast<Constant>(*I));
|
||||||
|
|
||||||
if (I == E) { // If they are all constants...
|
if (I == E) { // If they are all constants...
|
||||||
ConstantExpr *CE =
|
Constant *CE =
|
||||||
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(GV), Indices);
|
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(GV), Indices);
|
||||||
|
|
||||||
// Replace all uses of the GEP with the new constexpr...
|
// Replace all uses of the GEP with the new constexpr...
|
||||||
|
@ -418,7 +418,7 @@ void ConstantPointerRef::replaceUsesOfWithOnConstant(Value *From, Value *To) {
|
|||||||
void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *To) {
|
void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *To) {
|
||||||
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
||||||
|
|
||||||
ConstantExpr *Replacement = 0;
|
Constant *Replacement = 0;
|
||||||
if (getOpcode() == Instruction::GetElementPtr) {
|
if (getOpcode() == Instruction::GetElementPtr) {
|
||||||
std::vector<Constant*> Indices;
|
std::vector<Constant*> Indices;
|
||||||
Constant *Pointer = cast<Constant>(getOperand(0));
|
Constant *Pointer = cast<Constant>(getOperand(0));
|
||||||
@ -635,8 +635,7 @@ void ConstantPointerRef::destroyConstant() {
|
|||||||
typedef pair<unsigned, vector<Constant*> > ExprMapKeyType;
|
typedef pair<unsigned, vector<Constant*> > ExprMapKeyType;
|
||||||
static ValueMap<const ExprMapKeyType, ConstantExpr> ExprConstants;
|
static ValueMap<const ExprMapKeyType, ConstantExpr> ExprConstants;
|
||||||
|
|
||||||
ConstantExpr *ConstantExpr::getCast(Constant *C, const Type *Ty) {
|
Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) {
|
||||||
|
|
||||||
// Look up the constant in the table first to ensure uniqueness
|
// Look up the constant in the table first to ensure uniqueness
|
||||||
vector<Constant*> argVec(1, C);
|
vector<Constant*> argVec(1, C);
|
||||||
const ExprMapKeyType &Key = make_pair(Instruction::Cast, argVec);
|
const ExprMapKeyType &Key = make_pair(Instruction::Cast, argVec);
|
||||||
@ -649,7 +648,7 @@ ConstantExpr *ConstantExpr::getCast(Constant *C, const Type *Ty) {
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantExpr *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
|
Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
|
||||||
// Look up the constant in the table first to ensure uniqueness
|
// Look up the constant in the table first to ensure uniqueness
|
||||||
vector<Constant*> argVec(1, C1); argVec.push_back(C2);
|
vector<Constant*> argVec(1, C1); argVec.push_back(C2);
|
||||||
const ExprMapKeyType &Key = make_pair(Opcode, argVec);
|
const ExprMapKeyType &Key = make_pair(Opcode, argVec);
|
||||||
@ -670,8 +669,8 @@ ConstantExpr *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantExpr *ConstantExpr::getGetElementPtr(Constant *C,
|
Constant *ConstantExpr::getGetElementPtr(Constant *C,
|
||||||
const std::vector<Constant*> &IdxList) {
|
const std::vector<Constant*> &IdxList){
|
||||||
const Type *Ty = C->getType();
|
const Type *Ty = C->getType();
|
||||||
|
|
||||||
// Look up the constant in the table first to ensure uniqueness
|
// Look up the constant in the table first to ensure uniqueness
|
||||||
|
Loading…
x
Reference in New Issue
Block a user