mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
[PM] [cleanup] Rename some of the Verifier's members, re-arrange them,
and tweak comments prior to more invasive surgery. Also clean up some other non-doxygen comments, and run clang-format over the parts that are going to change dramatically in subsequent commits so that those don't get cluttered with formatting changes. No functionality changed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199489 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
bd2c711cdd
commit
825488c539
@ -51,6 +51,9 @@ createVerifierPass(VerifierFailureAction action = AbortProcessAction);
|
||||
|
||||
/// \brief Check a function for errors, useful for use when debugging a
|
||||
/// pass.
|
||||
///
|
||||
/// If there are no errors, the function returns false. If an error is found,
|
||||
/// the action taken depends on the \p action parameter.
|
||||
bool verifyFunction(const Function &F,
|
||||
VerifierFailureAction action = AbortProcessAction);
|
||||
|
||||
|
@ -80,51 +80,52 @@ static cl::opt<bool> DisableDebugInfoVerifier("disable-debug-info-verifier",
|
||||
cl::init(true));
|
||||
|
||||
namespace {
|
||||
struct Verifier : public FunctionPass, public InstVisitor<Verifier> {
|
||||
static char ID; // Pass ID, replacement for typeid
|
||||
bool Broken; // Is this module found to be broken?
|
||||
VerifierFailureAction action;
|
||||
// What to do if verification fails.
|
||||
Module *Mod; // Module we are verifying right now
|
||||
LLVMContext *Context; // Context within which we are verifying
|
||||
DominatorTree DT;
|
||||
const DataLayout *DL;
|
||||
struct Verifier : public FunctionPass, public InstVisitor<Verifier> {
|
||||
static char ID;
|
||||
|
||||
// What to do if verification fails.
|
||||
VerifierFailureAction Action;
|
||||
|
||||
Module *M;
|
||||
LLVMContext *Context;
|
||||
const DataLayout *DL;
|
||||
DominatorTree DT;
|
||||
|
||||
bool Broken;
|
||||
std::string Messages;
|
||||
raw_string_ostream MessagesStr;
|
||||
|
||||
/// InstInThisBlock - when verifying a basic block, keep track of all of the
|
||||
/// instructions we have seen so far. This allows us to do efficient
|
||||
/// dominance checks for the case when an instruction has an operand that is
|
||||
/// an instruction in the same block.
|
||||
SmallPtrSet<Instruction*, 16> InstsInThisBlock;
|
||||
/// \brief When verifying a basic block, keep track of all of the
|
||||
/// instructions we have seen so far.
|
||||
///
|
||||
/// This allows us to do efficient dominance checks for the case when an
|
||||
/// instruction has an operand that is an instruction in the same block.
|
||||
SmallPtrSet<Instruction *, 16> InstsInThisBlock;
|
||||
|
||||
/// MDNodes - keep track of the metadata nodes that have been checked
|
||||
/// already.
|
||||
/// \brief Keep track of the metadata nodes that have been checked already.
|
||||
SmallPtrSet<MDNode *, 32> MDNodes;
|
||||
|
||||
/// PersonalityFn - The personality function referenced by the
|
||||
/// LandingPadInsts. All LandingPadInsts within the same function must use
|
||||
/// the same personality function.
|
||||
/// \brief The personality function referenced by the LandingPadInsts.
|
||||
/// All LandingPadInsts within the same function must use the same
|
||||
/// personality function.
|
||||
const Value *PersonalityFn;
|
||||
|
||||
/// Finder keeps track of all debug info MDNodes in a Module.
|
||||
/// \brief Finder keeps track of all debug info MDNodes in a Module.
|
||||
DebugInfoFinder Finder;
|
||||
|
||||
Verifier()
|
||||
: FunctionPass(ID), Broken(false),
|
||||
action(AbortProcessAction), Mod(0), Context(0), DL(0),
|
||||
MessagesStr(Messages), PersonalityFn(0) {
|
||||
: FunctionPass(ID), Action(AbortProcessAction), M(0), Context(0), DL(0),
|
||||
Broken(false), MessagesStr(Messages), PersonalityFn(0) {
|
||||
initializeVerifierPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
explicit Verifier(VerifierFailureAction ctn)
|
||||
: FunctionPass(ID), Broken(false), action(ctn), Mod(0),
|
||||
Context(0), DL(0), MessagesStr(Messages), PersonalityFn(0) {
|
||||
explicit Verifier(VerifierFailureAction Action)
|
||||
: FunctionPass(ID), Action(Action), M(0), Context(0), DL(0),
|
||||
Broken(false), MessagesStr(Messages), PersonalityFn(0) {
|
||||
initializeVerifierPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool doInitialization(Module &M) {
|
||||
Mod = &M;
|
||||
this->M = &M;
|
||||
Context = &M.getContext();
|
||||
|
||||
DL = getAnalysisIfAvailable<DataLayout>();
|
||||
@ -157,8 +158,9 @@ namespace {
|
||||
// run this code outside of a pass manager.
|
||||
DT.recalculate(F);
|
||||
|
||||
Mod = F.getParent();
|
||||
if (!Context) Context = &F.getContext();
|
||||
M = F.getParent();
|
||||
if (!Context)
|
||||
Context = &F.getContext();
|
||||
|
||||
Finder.reset();
|
||||
visit(F);
|
||||
@ -180,19 +182,21 @@ namespace {
|
||||
visitGlobalValue(*I);
|
||||
|
||||
// Check to make sure function prototypes are okay.
|
||||
if (I->isDeclaration()) visitFunction(*I);
|
||||
if (I->isDeclaration())
|
||||
visitFunction(*I);
|
||||
}
|
||||
|
||||
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
||||
I != E; ++I)
|
||||
visitGlobalVariable(*I);
|
||||
|
||||
for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
|
||||
I != E; ++I)
|
||||
for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E;
|
||||
++I)
|
||||
visitGlobalAlias(*I);
|
||||
|
||||
for (Module::named_metadata_iterator I = M.named_metadata_begin(),
|
||||
E = M.named_metadata_end(); I != E; ++I)
|
||||
E = M.named_metadata_end();
|
||||
I != E; ++I)
|
||||
visitNamedMDNode(*I);
|
||||
|
||||
visitModuleFlags(M);
|
||||
@ -217,9 +221,10 @@ namespace {
|
||||
/// this condition, do so.
|
||||
///
|
||||
bool abortIfBroken() {
|
||||
if (!Broken) return false;
|
||||
if (!Broken)
|
||||
return false;
|
||||
MessagesStr << "Broken module found, ";
|
||||
switch (action) {
|
||||
switch (Action) {
|
||||
case AbortProcessAction:
|
||||
MessagesStr << "compilation aborted!\n";
|
||||
dbgs() << MessagesStr.str();
|
||||
@ -236,7 +241,6 @@ namespace {
|
||||
llvm_unreachable("Invalid action");
|
||||
}
|
||||
|
||||
|
||||
// Verification methods...
|
||||
void visitGlobalValue(GlobalValue &GV);
|
||||
void visitGlobalVariable(GlobalVariable &GV);
|
||||
@ -245,8 +249,8 @@ namespace {
|
||||
void visitMDNode(MDNode &MD, Function *F);
|
||||
void visitModuleIdents(Module &M);
|
||||
void visitModuleFlags(Module &M);
|
||||
void visitModuleFlag(MDNode *Op, DenseMap<MDString*, MDNode*> &SeenIDs,
|
||||
SmallVectorImpl<MDNode*> &Requirements);
|
||||
void visitModuleFlag(MDNode *Op, DenseMap<MDString *, MDNode *> &SeenIDs,
|
||||
SmallVectorImpl<MDNode *> &Requirements);
|
||||
void visitFunction(Function &F);
|
||||
void visitBasicBlock(BasicBlock &BB);
|
||||
using InstVisitor<Verifier>::visit;
|
||||
@ -299,16 +303,15 @@ namespace {
|
||||
void visitLandingPadInst(LandingPadInst &LPI);
|
||||
|
||||
void VerifyCallSite(CallSite CS);
|
||||
bool PerformTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty,
|
||||
int VT, unsigned ArgNo, std::string &Suffix);
|
||||
bool VerifyIntrinsicType(Type *Ty,
|
||||
ArrayRef<Intrinsic::IITDescriptor> &Infos,
|
||||
SmallVectorImpl<Type*> &ArgTys);
|
||||
bool PerformTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty, int VT,
|
||||
unsigned ArgNo, std::string &Suffix);
|
||||
bool VerifyIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
|
||||
SmallVectorImpl<Type *> &ArgTys);
|
||||
bool VerifyIntrinsicIsVarArg(bool isVarArg,
|
||||
ArrayRef<Intrinsic::IITDescriptor> &Infos);
|
||||
bool VerifyAttributeCount(AttributeSet Attrs, unsigned Params);
|
||||
void VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx,
|
||||
bool isFunction, const Value *V);
|
||||
void VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx, bool isFunction,
|
||||
const Value *V);
|
||||
void VerifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty,
|
||||
bool isReturnValue, const Value *V);
|
||||
void VerifyFunctionAttrs(FunctionType *FT, AttributeSet Attrs,
|
||||
@ -320,27 +323,28 @@ namespace {
|
||||
void verifyDebugInfo();
|
||||
|
||||
void WriteValue(const Value *V) {
|
||||
if (!V) return;
|
||||
if (!V)
|
||||
return;
|
||||
if (isa<Instruction>(V)) {
|
||||
MessagesStr << *V << '\n';
|
||||
} else {
|
||||
V->printAsOperand(MessagesStr, true, Mod);
|
||||
V->printAsOperand(MessagesStr, true, M);
|
||||
MessagesStr << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void WriteType(Type *T) {
|
||||
if (!T) return;
|
||||
if (!T)
|
||||
return;
|
||||
MessagesStr << ' ' << *T;
|
||||
}
|
||||
|
||||
|
||||
// CheckFailed - A check failed, so print out the condition and the message
|
||||
// that failed. This provides a nice place to put a breakpoint if you want
|
||||
// to see why something is not correct.
|
||||
void CheckFailed(const Twine &Message,
|
||||
const Value *V1 = 0, const Value *V2 = 0,
|
||||
const Value *V3 = 0, const Value *V4 = 0) {
|
||||
void CheckFailed(const Twine &Message, const Value *V1 = 0,
|
||||
const Value *V2 = 0, const Value *V3 = 0,
|
||||
const Value *V4 = 0) {
|
||||
MessagesStr << Message.str() << "\n";
|
||||
WriteValue(V1);
|
||||
WriteValue(V2);
|
||||
@ -349,8 +353,8 @@ namespace {
|
||||
Broken = true;
|
||||
}
|
||||
|
||||
void CheckFailed(const Twine &Message, const Value *V1,
|
||||
Type *T2, const Value *V3 = 0) {
|
||||
void CheckFailed(const Twine &Message, const Value *V1, Type *T2,
|
||||
const Value *V3 = 0) {
|
||||
MessagesStr << Message.str() << "\n";
|
||||
WriteValue(V1);
|
||||
WriteType(T2);
|
||||
@ -358,15 +362,14 @@ namespace {
|
||||
Broken = true;
|
||||
}
|
||||
|
||||
void CheckFailed(const Twine &Message, Type *T1,
|
||||
Type *T2 = 0, Type *T3 = 0) {
|
||||
void CheckFailed(const Twine &Message, Type *T1, Type *T2 = 0, Type *T3 = 0) {
|
||||
MessagesStr << Message.str() << "\n";
|
||||
WriteType(T1);
|
||||
WriteType(T2);
|
||||
WriteType(T3);
|
||||
Broken = true;
|
||||
}
|
||||
};
|
||||
};
|
||||
} // End anonymous namespace
|
||||
|
||||
char Verifier::ID = 0;
|
||||
@ -2064,7 +2067,7 @@ void Verifier::visitInstruction(Instruction &I) {
|
||||
Assert1(!F->isIntrinsic() || isa<CallInst>(I) ||
|
||||
F->getIntrinsicID() == Intrinsic::donothing,
|
||||
"Cannot invoke an intrinsinc other than donothing", &I);
|
||||
Assert1(F->getParent() == Mod, "Referencing function in another module!",
|
||||
Assert1(F->getParent() == M, "Referencing function in another module!",
|
||||
&I);
|
||||
} else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {
|
||||
Assert1(OpBB->getParent() == BB->getParent(),
|
||||
@ -2073,7 +2076,7 @@ void Verifier::visitInstruction(Instruction &I) {
|
||||
Assert1(OpArg->getParent() == BB->getParent(),
|
||||
"Referring to an argument in another function!", &I);
|
||||
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) {
|
||||
Assert1(GV->getParent() == Mod, "Referencing global in another module!",
|
||||
Assert1(GV->getParent() == M, "Referencing global in another module!",
|
||||
&I);
|
||||
} else if (isa<Instruction>(I.getOperand(i))) {
|
||||
verifyDominatesUse(I, i);
|
||||
@ -2124,7 +2127,7 @@ void Verifier::visitInstruction(Instruction &I) {
|
||||
|
||||
if (!DisableDebugInfoVerifier) {
|
||||
MD = I.getMetadata(LLVMContext::MD_dbg);
|
||||
Finder.processLocation(*Mod, DILocation(MD));
|
||||
Finder.processLocation(*M, DILocation(MD));
|
||||
}
|
||||
|
||||
InstsInThisBlock.insert(&I);
|
||||
@ -2302,13 +2305,13 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
|
||||
Assert1(MD->getNumOperands() == 1,
|
||||
"invalid llvm.dbg.declare intrinsic call 2", &CI);
|
||||
if (!DisableDebugInfoVerifier)
|
||||
Finder.processDeclare(*Mod, cast<DbgDeclareInst>(&CI));
|
||||
Finder.processDeclare(*M, cast<DbgDeclareInst>(&CI));
|
||||
} break;
|
||||
case Intrinsic::dbg_value: { //llvm.dbg.value
|
||||
if (!DisableDebugInfoVerifier) {
|
||||
Assert1(CI.getArgOperand(0) && isa<MDNode>(CI.getArgOperand(0)),
|
||||
"invalid llvm.dbg.value intrinsic call 1", &CI);
|
||||
Finder.processValue(*Mod, cast<DbgValueInst>(&CI));
|
||||
Finder.processValue(*M, cast<DbgValueInst>(&CI));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -2403,12 +2406,8 @@ FunctionPass *llvm::createVerifierPass(VerifierFailureAction action) {
|
||||
return new Verifier(action);
|
||||
}
|
||||
|
||||
|
||||
/// verifyFunction - Check a function for errors, printing messages on stderr.
|
||||
/// Return true if the function is corrupt.
|
||||
///
|
||||
bool llvm::verifyFunction(const Function &f, VerifierFailureAction action) {
|
||||
Function &F = const_cast<Function&>(f);
|
||||
Function &F = const_cast<Function &>(f);
|
||||
assert(!F.isDeclaration() && "Cannot verify external functions");
|
||||
|
||||
FunctionPassManager FPM(F.getParent());
|
||||
@ -2419,15 +2418,12 @@ bool llvm::verifyFunction(const Function &f, VerifierFailureAction action) {
|
||||
return V->Broken;
|
||||
}
|
||||
|
||||
/// verifyModule - Check a module for errors, printing messages on stderr.
|
||||
/// Return true if the module is corrupt.
|
||||
///
|
||||
bool llvm::verifyModule(const Module &M, VerifierFailureAction action,
|
||||
std::string *ErrorInfo) {
|
||||
PassManager PM;
|
||||
Verifier *V = new Verifier(action);
|
||||
PM.add(V);
|
||||
PM.run(const_cast<Module&>(M));
|
||||
PM.run(const_cast<Module &>(M));
|
||||
|
||||
if (ErrorInfo && V->Broken)
|
||||
*ErrorInfo = V->MessagesStr.str();
|
||||
|
Loading…
Reference in New Issue
Block a user