mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-04 10:04:33 +00:00
Eliminate some mega-cruft here. There is no reason to DERIVE FROM IR CLASSES
just to keep track of some per-object state! Gaah! Whoever wrote this stuff... oh wait, that would be me. Never mind. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14790 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c9aea52ae4
commit
bc721ed100
@ -158,60 +158,6 @@ struct ValID {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<class SuperType>
|
||||
class PlaceholderValue : public SuperType {
|
||||
ValID D;
|
||||
int LineNum;
|
||||
public:
|
||||
PlaceholderValue(const Type *Ty, const ValID &d) : SuperType(Ty), D(d) {
|
||||
LineNum = llvmAsmlineno;
|
||||
}
|
||||
ValID &getDef() { return D; }
|
||||
int getLineNum() const { return LineNum; }
|
||||
};
|
||||
|
||||
struct InstPlaceHolderHelper : public Instruction {
|
||||
InstPlaceHolderHelper(const Type *Ty) : Instruction(Ty, UserOp1, "") {}
|
||||
|
||||
virtual Instruction *clone() const { abort(); return 0; }
|
||||
virtual const char *getOpcodeName() const { return "placeholder"; }
|
||||
};
|
||||
|
||||
struct BBPlaceHolderHelper : public BasicBlock {
|
||||
BBPlaceHolderHelper(const Type *Ty) : BasicBlock() {
|
||||
assert(Ty == Type::LabelTy);
|
||||
}
|
||||
};
|
||||
|
||||
typedef PlaceholderValue<InstPlaceHolderHelper> ValuePlaceHolder;
|
||||
typedef PlaceholderValue<BBPlaceHolderHelper> BBPlaceHolder;
|
||||
|
||||
static inline ValID &getValIDFromPlaceHolder(const Value *Val) {
|
||||
const Type *Ty = Val->getType();
|
||||
if (isa<PointerType>(Ty) &&
|
||||
isa<FunctionType>(cast<PointerType>(Ty)->getElementType()))
|
||||
Ty = cast<PointerType>(Ty)->getElementType();
|
||||
|
||||
switch (Ty->getTypeID()) {
|
||||
case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getDef();
|
||||
default: return ((ValuePlaceHolder*)Val)->getDef();
|
||||
}
|
||||
}
|
||||
|
||||
static inline int getLineNumFromPlaceHolder(const Value *Val) {
|
||||
const Type *Ty = Val->getType();
|
||||
if (isa<PointerType>(Ty) &&
|
||||
isa<FunctionType>(cast<PointerType>(Ty)->getElementType()))
|
||||
Ty = cast<PointerType>(Ty)->getElementType();
|
||||
|
||||
switch (Ty->getTypeID()) {
|
||||
case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getLineNum();
|
||||
default: return ((ValuePlaceHolder*)Val)->getLineNum();
|
||||
}
|
||||
}
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
#endif
|
||||
|
@ -69,6 +69,11 @@ static struct PerModuleInfo {
|
||||
std::vector<PATypeHolder> Types;
|
||||
std::map<ValID, PATypeHolder> LateResolveTypes;
|
||||
|
||||
/// PlaceHolderInfo - When temporary placeholder objects are created, remember
|
||||
/// how they were referenced and one which line of the input they came from so
|
||||
/// that we can resolve them alter and print error messages as appropriate.
|
||||
std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
|
||||
|
||||
// GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
|
||||
// references to global values. Global values may be referenced before they
|
||||
// are defined, and if so, the temporary object that they represent is held
|
||||
@ -356,7 +361,6 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// getVal - This function is identical to getValNonImprovising, except that if a
|
||||
// value is not already defined, it "improvises" by creating a placeholder var
|
||||
// that looks and acts just like the requested variable. When the value is
|
||||
@ -373,18 +377,21 @@ static Value *getVal(const Type *Ty, const ValID &D) {
|
||||
// or an id number that hasn't been read yet. We may be referencing something
|
||||
// forward, so just create an entry to be resolved later and get to it...
|
||||
//
|
||||
Value *d = 0;
|
||||
switch (Ty->getTypeID()) {
|
||||
case Type::LabelTyID: d = new BBPlaceHolder(Ty, D); break;
|
||||
default: d = new ValuePlaceHolder(Ty, D); break;
|
||||
}
|
||||
if (Ty == Type::LabelTy)
|
||||
V = new BasicBlock();
|
||||
else
|
||||
V = new Argument(Ty);
|
||||
|
||||
// Remember where this forward reference came from. FIXME, shouldn't we try
|
||||
// to recycle these things??
|
||||
CurModule.PlaceHolderInfo.insert(std::make_pair(V, std::make_pair(D,
|
||||
llvmAsmlineno)));
|
||||
|
||||
assert(d != 0 && "How did we not make something?");
|
||||
if (inFunctionScope())
|
||||
InsertValue(d, CurFun.LateResolveValues);
|
||||
InsertValue(V, CurFun.LateResolveValues);
|
||||
else
|
||||
InsertValue(d, CurModule.LateResolveValues);
|
||||
return d;
|
||||
InsertValue(V, CurModule.LateResolveValues);
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
@ -413,12 +420,18 @@ static void ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
|
||||
while (!List.empty()) {
|
||||
Value *V = List.back();
|
||||
List.pop_back();
|
||||
ValID &DID = getValIDFromPlaceHolder(V);
|
||||
|
||||
std::map<Value*, std::pair<ValID, int> >::iterator PHI =
|
||||
CurModule.PlaceHolderInfo.find(V);
|
||||
assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error!");
|
||||
|
||||
ValID &DID = PHI->second.first;
|
||||
|
||||
Value *TheRealValue = getValNonImprovising(LRI->first, DID);
|
||||
if (TheRealValue) {
|
||||
V->replaceAllUsesWith(TheRealValue);
|
||||
delete V;
|
||||
CurModule.PlaceHolderInfo.erase(PHI);
|
||||
} else if (FutureLateResolvers) {
|
||||
// Functions have their unresolved items forwarded to the module late
|
||||
// resolver table
|
||||
@ -427,12 +440,12 @@ static void ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
|
||||
if (DID.Type == ValID::NameVal)
|
||||
ThrowException("Reference to an invalid definition: '" +DID.getName()+
|
||||
"' of type '" + V->getType()->getDescription() + "'",
|
||||
getLineNumFromPlaceHolder(V));
|
||||
PHI->second.second);
|
||||
else
|
||||
ThrowException("Reference to an invalid definition: #" +
|
||||
itostr(DID.Num) + " of type '" +
|
||||
V->getType()->getDescription() + "'",
|
||||
getLineNumFromPlaceHolder(V));
|
||||
PHI->second.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user