mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-27 15:02:16 +00:00
Get rid of the multiple copies of getStringValue. Now a Constant:: method.
llvm-svn: 26616
This commit is contained in:
parent
a3c5cd22e1
commit
a1ad999bba
@ -90,6 +90,11 @@ public:
|
|||||||
/// constant subsystem, which can be used in environments where this memory
|
/// constant subsystem, which can be used in environments where this memory
|
||||||
/// is otherwise reported as a leak.
|
/// is otherwise reported as a leak.
|
||||||
static void clearAllValueMaps();
|
static void clearAllValueMaps();
|
||||||
|
|
||||||
|
/// getStringValue - Turn an LLVM constant pointer that eventually points to a
|
||||||
|
/// global into a string value. Return an empty string if we can't do it.
|
||||||
|
///
|
||||||
|
std::string getStringValue(unsigned Offset = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
@ -1244,7 +1244,6 @@ DIE *DwarfWriter::NewBasicType(DIE *Context, Type *Ty) {
|
|||||||
/// NewType - Create a new type DIE.
|
/// NewType - Create a new type DIE.
|
||||||
///
|
///
|
||||||
DIE *DwarfWriter::NewType(DIE *Context, TypeDesc *TyDesc) {
|
DIE *DwarfWriter::NewType(DIE *Context, TypeDesc *TyDesc) {
|
||||||
// FIXME - hack to get around NULL types short term.
|
|
||||||
if (!TyDesc) return NewBasicType(Context, Type::IntTy);
|
if (!TyDesc) return NewBasicType(Context, Type::IntTy);
|
||||||
|
|
||||||
// FIXME - Should handle other contexts that compile units.
|
// FIXME - Should handle other contexts that compile units.
|
||||||
|
@ -67,45 +67,6 @@ getGlobalVariablesUsing(Module &M, const std::string &RootName) {
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getStringValue - Turn an LLVM constant pointer that eventually points to a
|
|
||||||
/// global into a string value. Return an empty string if we can't do it.
|
|
||||||
///
|
|
||||||
static const std::string getStringValue(Value *V, unsigned Offset = 0) {
|
|
||||||
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
|
|
||||||
if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
|
|
||||||
ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
|
|
||||||
if (Init->isString()) {
|
|
||||||
std::string Result = Init->getAsString();
|
|
||||||
if (Offset < Result.size()) {
|
|
||||||
// If we are pointing INTO The string, erase the beginning...
|
|
||||||
Result.erase(Result.begin(), Result.begin()+Offset);
|
|
||||||
|
|
||||||
// Take off the null terminator, and any string fragments after it.
|
|
||||||
std::string::size_type NullPos = Result.find_first_of((char)0);
|
|
||||||
if (NullPos != std::string::npos)
|
|
||||||
Result.erase(Result.begin()+NullPos, Result.end());
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (Constant *C = dyn_cast<Constant>(V)) {
|
|
||||||
if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
|
|
||||||
return getStringValue(GV, Offset);
|
|
||||||
else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
|
||||||
if (CE->getOpcode() == Instruction::GetElementPtr) {
|
|
||||||
// Turn a gep into the specified offset.
|
|
||||||
if (CE->getNumOperands() == 3 &&
|
|
||||||
cast<Constant>(CE->getOperand(1))->isNullValue() &&
|
|
||||||
isa<ConstantInt>(CE->getOperand(2))) {
|
|
||||||
return getStringValue(CE->getOperand(0),
|
|
||||||
Offset+cast<ConstantInt>(CE->getOperand(2))->getRawValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// isStringValue - Return true if the given value can be coerced to a string.
|
/// isStringValue - Return true if the given value can be coerced to a string.
|
||||||
///
|
///
|
||||||
static bool isStringValue(Value *V) {
|
static bool isStringValue(Value *V) {
|
||||||
@ -250,7 +211,7 @@ public:
|
|||||||
}
|
}
|
||||||
virtual void Apply(std::string &Field) {
|
virtual void Apply(std::string &Field) {
|
||||||
Constant *C = CI->getOperand(I++);
|
Constant *C = CI->getOperand(I++);
|
||||||
Field = getStringValue(C);
|
Field = C->getStringValue();
|
||||||
}
|
}
|
||||||
virtual void Apply(DebugInfoDesc *&Field) {
|
virtual void Apply(DebugInfoDesc *&Field) {
|
||||||
Constant *C = CI->getOperand(I++);
|
Constant *C = CI->getOperand(I++);
|
||||||
@ -571,7 +532,7 @@ void AnchorDesc::ApplyToFields(DIVisitor *Visitor) {
|
|||||||
|
|
||||||
/// getDescString - Return a string used to compose global names and labels. A
|
/// getDescString - Return a string used to compose global names and labels. A
|
||||||
/// A global variable name needs to be defined for each debug descriptor that is
|
/// A global variable name needs to be defined for each debug descriptor that is
|
||||||
/// anchored. NOTE: that each global variable name here also needs to be added
|
/// anchored. NOTE: that each global variable named here also needs to be added
|
||||||
/// to the list of names left external in the internalizer.
|
/// to the list of names left external in the internalizer.
|
||||||
/// ExternalNames.insert("llvm.dbg.compile_units");
|
/// ExternalNames.insert("llvm.dbg.compile_units");
|
||||||
/// ExternalNames.insert("llvm.dbg.global_variables");
|
/// ExternalNames.insert("llvm.dbg.global_variables");
|
||||||
|
@ -873,24 +873,6 @@ void SelectionDAGLowering::visitAlloca(AllocaInst &I) {
|
|||||||
CurMBB->getParent()->getFrameInfo()->CreateVariableSizedObject();
|
CurMBB->getParent()->getFrameInfo()->CreateVariableSizedObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getStringValue - Turn an LLVM constant pointer that eventually points to a
|
|
||||||
/// global into a string value. Return an empty string if we can't do it.
|
|
||||||
///
|
|
||||||
static std::string getStringValue(GlobalVariable *GV, unsigned Offset = 0) {
|
|
||||||
if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
|
|
||||||
ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
|
|
||||||
if (Init->isString()) {
|
|
||||||
std::string Result = Init->getAsString();
|
|
||||||
if (Offset < Result.size()) {
|
|
||||||
// If we are pointing INTO The string, erase the beginning...
|
|
||||||
Result.erase(Result.begin(), Result.begin()+Offset);
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
void SelectionDAGLowering::visitLoad(LoadInst &I) {
|
void SelectionDAGLowering::visitLoad(LoadInst &I) {
|
||||||
SDOperand Ptr = getValue(I.getOperand(0));
|
SDOperand Ptr = getValue(I.getOperand(0));
|
||||||
|
|
||||||
@ -1962,7 +1944,7 @@ void SelectionDAGLowering::visitMemIntrinsic(CallInst &I, unsigned Op) {
|
|||||||
if (G) {
|
if (G) {
|
||||||
GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getGlobal());
|
GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getGlobal());
|
||||||
if (GV) {
|
if (GV) {
|
||||||
Str = getStringValue(GV);
|
Str = GV->getStringValue();
|
||||||
if (!Str.empty()) {
|
if (!Str.empty()) {
|
||||||
CopyFromStr = true;
|
CopyFromStr = true;
|
||||||
SrcOff += SrcDelta;
|
SrcOff += SrcDelta;
|
||||||
|
@ -38,45 +38,6 @@ static void getGlobalVariablesUsing(Value *V,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getStringValue - Turn an LLVM constant pointer that eventually points to a
|
|
||||||
/// global into a string value. Return an empty string if we can't do it.
|
|
||||||
///
|
|
||||||
static std::string getStringValue(Value *V, unsigned Offset = 0) {
|
|
||||||
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
|
|
||||||
if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
|
|
||||||
ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
|
|
||||||
if (Init->isString()) {
|
|
||||||
std::string Result = Init->getAsString();
|
|
||||||
if (Offset < Result.size()) {
|
|
||||||
// If we are pointing INTO The string, erase the beginning...
|
|
||||||
Result.erase(Result.begin(), Result.begin()+Offset);
|
|
||||||
|
|
||||||
// Take off the null terminator, and any string fragments after it.
|
|
||||||
std::string::size_type NullPos = Result.find_first_of((char)0);
|
|
||||||
if (NullPos != std::string::npos)
|
|
||||||
Result.erase(Result.begin()+NullPos, Result.end());
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (Constant *C = dyn_cast<Constant>(V)) {
|
|
||||||
if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
|
|
||||||
return getStringValue(GV, Offset);
|
|
||||||
else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
|
||||||
if (CE->getOpcode() == Instruction::GetElementPtr) {
|
|
||||||
// Turn a gep into the specified offset.
|
|
||||||
if (CE->getNumOperands() == 3 &&
|
|
||||||
cast<Constant>(CE->getOperand(1))->isNullValue() &&
|
|
||||||
isa<ConstantInt>(CE->getOperand(2))) {
|
|
||||||
return getStringValue(CE->getOperand(0),
|
|
||||||
Offset+cast<ConstantInt>(CE->getOperand(2))->getRawValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getNextStopPoint - Follow the def-use chains of the specified LLVM value,
|
/// getNextStopPoint - Follow the def-use chains of the specified LLVM value,
|
||||||
/// traversing the use chains until we get to a stoppoint. When we do, return
|
/// traversing the use chains until we get to a stoppoint. When we do, return
|
||||||
/// the source location of the stoppoint. If we don't find a stoppoint, return
|
/// the source location of the stoppoint. If we don't find a stoppoint, return
|
||||||
@ -158,8 +119,8 @@ SourceFileInfo::SourceFileInfo(const GlobalVariable *Desc,
|
|||||||
if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(CS->getOperand(1)))
|
if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(CS->getOperand(1)))
|
||||||
Version = CUI->getValue();
|
Version = CUI->getValue();
|
||||||
|
|
||||||
BaseName = getStringValue(CS->getOperand(3));
|
BaseName = CS->getOperand(3)->getStringValue();
|
||||||
Directory = getStringValue(CS->getOperand(4));
|
Directory = CS->getOperand(4)->getStringValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +160,7 @@ SourceFunctionInfo::SourceFunctionInfo(ProgramInfo &PI,
|
|||||||
SourceFile = &PI.getSourceFile(GV);
|
SourceFile = &PI.getSourceFile(GV);
|
||||||
|
|
||||||
// Entry #2 is the function name.
|
// Entry #2 is the function name.
|
||||||
Name = getStringValue(CS->getOperand(2));
|
Name = CS->getOperand(2)->getStringValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1712,3 +1712,43 @@ void Constant::clearAllValueMaps() {
|
|||||||
(*I)->destroyConstantImpl();
|
(*I)->destroyConstantImpl();
|
||||||
Constants.clear();
|
Constants.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// getStringValue - Turn an LLVM constant pointer that eventually points to a
|
||||||
|
/// global into a string value. Return an empty string if we can't do it.
|
||||||
|
///
|
||||||
|
std::string Constant::getStringValue(unsigned Offset) {
|
||||||
|
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(this)) {
|
||||||
|
if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
|
||||||
|
ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
|
||||||
|
if (Init->isString()) {
|
||||||
|
std::string Result = Init->getAsString();
|
||||||
|
if (Offset < Result.size()) {
|
||||||
|
// If we are pointing INTO The string, erase the beginning...
|
||||||
|
Result.erase(Result.begin(), Result.begin()+Offset);
|
||||||
|
|
||||||
|
// Take off the null terminator, and any string fragments after it.
|
||||||
|
std::string::size_type NullPos = Result.find_first_of((char)0);
|
||||||
|
if (NullPos != std::string::npos)
|
||||||
|
Result.erase(Result.begin()+NullPos, Result.end());
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (Constant *C = dyn_cast<Constant>(this)) {
|
||||||
|
if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
|
||||||
|
return GV->getStringValue(Offset);
|
||||||
|
else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
||||||
|
if (CE->getOpcode() == Instruction::GetElementPtr) {
|
||||||
|
// Turn a gep into the specified offset.
|
||||||
|
if (CE->getNumOperands() == 3 &&
|
||||||
|
cast<Constant>(CE->getOperand(1))->isNullValue() &&
|
||||||
|
isa<ConstantInt>(CE->getOperand(2))) {
|
||||||
|
Offset += cast<ConstantInt>(CE->getOperand(2))->getRawValue();
|
||||||
|
return CE->getOperand(0)->getStringValue(Offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user