mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-03-03 01:48:15 +00:00
Constify GetConstantStringInfo.
llvm-svn: 101298
This commit is contained in:
parent
8e94bbf2e1
commit
5c72d507d7
@ -122,7 +122,8 @@ namespace llvm {
|
||||
/// StopAtNul is set to true (the default), the returned string is truncated
|
||||
/// by a nul character in the global. If StopAtNul is false, the nul
|
||||
/// character is included in the result string.
|
||||
bool GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset = 0,
|
||||
bool GetConstantStringInfo(const Value *V, std::string &Str,
|
||||
uint64_t Offset = 0,
|
||||
bool StopAtNul = true);
|
||||
|
||||
/// GetStringLength - If we can compute the length of the string pointed to by
|
||||
|
@ -1342,22 +1342,23 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
|
||||
/// GetConstantStringInfo - This function computes the length of a
|
||||
/// null-terminated C string pointed to by V. If successful, it returns true
|
||||
/// and returns the string in Str. If unsuccessful, it returns false.
|
||||
bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset,
|
||||
bool llvm::GetConstantStringInfo(const Value *V, std::string &Str,
|
||||
uint64_t Offset,
|
||||
bool StopAtNul) {
|
||||
// If V is NULL then return false;
|
||||
if (V == NULL) return false;
|
||||
|
||||
// Look through bitcast instructions.
|
||||
if (BitCastInst *BCI = dyn_cast<BitCastInst>(V))
|
||||
if (const BitCastInst *BCI = dyn_cast<BitCastInst>(V))
|
||||
return GetConstantStringInfo(BCI->getOperand(0), Str, Offset, StopAtNul);
|
||||
|
||||
// If the value is not a GEP instruction nor a constant expression with a
|
||||
// GEP instruction, then return false because ConstantArray can't occur
|
||||
// any other way
|
||||
User *GEP = 0;
|
||||
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) {
|
||||
const User *GEP = 0;
|
||||
if (const GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) {
|
||||
GEP = GEPI;
|
||||
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
|
||||
} else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
|
||||
if (CE->getOpcode() == Instruction::BitCast)
|
||||
return GetConstantStringInfo(CE->getOperand(0), Str, Offset, StopAtNul);
|
||||
if (CE->getOpcode() != Instruction::GetElementPtr)
|
||||
@ -1378,7 +1379,7 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset,
|
||||
|
||||
// Check to make sure that the first operand of the GEP is an integer and
|
||||
// has value 0 so that we are sure we're indexing into the initializer.
|
||||
ConstantInt *FirstIdx = dyn_cast<ConstantInt>(GEP->getOperand(1));
|
||||
const ConstantInt *FirstIdx = dyn_cast<ConstantInt>(GEP->getOperand(1));
|
||||
if (FirstIdx == 0 || !FirstIdx->isZero())
|
||||
return false;
|
||||
|
||||
@ -1386,7 +1387,7 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset,
|
||||
// into the array. If this occurs, we can't say anything meaningful about
|
||||
// the string.
|
||||
uint64_t StartIdx = 0;
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(GEP->getOperand(2)))
|
||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(GEP->getOperand(2)))
|
||||
StartIdx = CI->getZExtValue();
|
||||
else
|
||||
return false;
|
||||
@ -1397,10 +1398,10 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset,
|
||||
// The GEP instruction, constant or instruction, must reference a global
|
||||
// variable that is a constant and is initialized. The referenced constant
|
||||
// initializer is the array that we'll use for optimization.
|
||||
GlobalVariable* GV = dyn_cast<GlobalVariable>(V);
|
||||
const GlobalVariable* GV = dyn_cast<GlobalVariable>(V);
|
||||
if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
|
||||
return false;
|
||||
Constant *GlobalInit = GV->getInitializer();
|
||||
const Constant *GlobalInit = GV->getInitializer();
|
||||
|
||||
// Handle the ConstantAggregateZero case
|
||||
if (isa<ConstantAggregateZero>(GlobalInit)) {
|
||||
@ -1411,7 +1412,7 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset,
|
||||
}
|
||||
|
||||
// Must be a Constant Array
|
||||
ConstantArray *Array = dyn_cast<ConstantArray>(GlobalInit);
|
||||
const ConstantArray *Array = dyn_cast<ConstantArray>(GlobalInit);
|
||||
if (Array == 0 || !Array->getType()->getElementType()->isIntegerTy(8))
|
||||
return false;
|
||||
|
||||
@ -1425,8 +1426,8 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset,
|
||||
// to in the array.
|
||||
Str.reserve(NumElts-Offset);
|
||||
for (unsigned i = Offset; i != NumElts; ++i) {
|
||||
Constant *Elt = Array->getOperand(i);
|
||||
ConstantInt *CI = dyn_cast<ConstantInt>(Elt);
|
||||
const Constant *Elt = Array->getOperand(i);
|
||||
const ConstantInt *CI = dyn_cast<ConstantInt>(Elt);
|
||||
if (!CI) // This array isn't suitable, non-int initializer.
|
||||
return false;
|
||||
if (StopAtNul && CI->isZero())
|
||||
|
Loading…
x
Reference in New Issue
Block a user