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. llvm-svn: 14790
This commit is contained in:
parent
30b35cf3f7
commit
d9c9c496e6
|
@ -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
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -69,6 +69,11 @@ static struct PerModuleInfo {
|
||||||
std::vector<PATypeHolder> Types;
|
std::vector<PATypeHolder> Types;
|
||||||
std::map<ValID, PATypeHolder> LateResolveTypes;
|
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
|
// GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
|
||||||
// references to global values. Global values may be referenced before they
|
// references to global values. Global values may be referenced before they
|
||||||
// are defined, and if so, the temporary object that they represent is held
|
// 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// getVal - This function is identical to getValNonImprovising, except that if a
|
// getVal - This function is identical to getValNonImprovising, except that if a
|
||||||
// value is not already defined, it "improvises" by creating a placeholder var
|
// 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
|
// 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
|
// 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...
|
// forward, so just create an entry to be resolved later and get to it...
|
||||||
//
|
//
|
||||||
Value *d = 0;
|
if (Ty == Type::LabelTy)
|
||||||
switch (Ty->getTypeID()) {
|
V = new BasicBlock();
|
||||||
case Type::LabelTyID: d = new BBPlaceHolder(Ty, D); break;
|
|
||||||
default: d = new ValuePlaceHolder(Ty, D); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(d != 0 && "How did we not make something?");
|
|
||||||
if (inFunctionScope())
|
|
||||||
InsertValue(d, CurFun.LateResolveValues);
|
|
||||||
else
|
else
|
||||||
InsertValue(d, CurModule.LateResolveValues);
|
V = new Argument(Ty);
|
||||||
return d;
|
|
||||||
|
// 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)));
|
||||||
|
|
||||||
|
if (inFunctionScope())
|
||||||
|
InsertValue(V, CurFun.LateResolveValues);
|
||||||
|
else
|
||||||
|
InsertValue(V, CurModule.LateResolveValues);
|
||||||
|
return V;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -413,12 +420,18 @@ static void ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
|
||||||
while (!List.empty()) {
|
while (!List.empty()) {
|
||||||
Value *V = List.back();
|
Value *V = List.back();
|
||||||
List.pop_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);
|
Value *TheRealValue = getValNonImprovising(LRI->first, DID);
|
||||||
if (TheRealValue) {
|
if (TheRealValue) {
|
||||||
V->replaceAllUsesWith(TheRealValue);
|
V->replaceAllUsesWith(TheRealValue);
|
||||||
delete V;
|
delete V;
|
||||||
|
CurModule.PlaceHolderInfo.erase(PHI);
|
||||||
} else if (FutureLateResolvers) {
|
} else if (FutureLateResolvers) {
|
||||||
// Functions have their unresolved items forwarded to the module late
|
// Functions have their unresolved items forwarded to the module late
|
||||||
// resolver table
|
// resolver table
|
||||||
|
@ -427,12 +440,12 @@ static void ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
|
||||||
if (DID.Type == ValID::NameVal)
|
if (DID.Type == ValID::NameVal)
|
||||||
ThrowException("Reference to an invalid definition: '" +DID.getName()+
|
ThrowException("Reference to an invalid definition: '" +DID.getName()+
|
||||||
"' of type '" + V->getType()->getDescription() + "'",
|
"' of type '" + V->getType()->getDescription() + "'",
|
||||||
getLineNumFromPlaceHolder(V));
|
PHI->second.second);
|
||||||
else
|
else
|
||||||
ThrowException("Reference to an invalid definition: #" +
|
ThrowException("Reference to an invalid definition: #" +
|
||||||
itostr(DID.Num) + " of type '" +
|
itostr(DID.Num) + " of type '" +
|
||||||
V->getType()->getDescription() + "'",
|
V->getType()->getDescription() + "'",
|
||||||
getLineNumFromPlaceHolder(V));
|
PHI->second.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue