mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
Remove old backwards compatibility support from the parser for autoupgrading
the old malloc/free instructions, and for 'sext' and 'zext' as function attributes (they are spelled signext/zeroext now), and support for result value attributes being specified after a function. Additionally, diagnose invalid attributes on functions with an error message instead of an abort in the verifier. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133229 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
26b0000166
commit
f3a789d931
@ -406,17 +406,6 @@ lltok::Kind LLLexer::LexQuote() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
static bool JustWhitespaceNewLine(const char *&Ptr) {
|
||||
const char *ThisPtr = Ptr;
|
||||
while (*ThisPtr == ' ' || *ThisPtr == '\t')
|
||||
++ThisPtr;
|
||||
if (*ThisPtr == '\n' || *ThisPtr == '\r') {
|
||||
Ptr = ThisPtr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// LexExclaim:
|
||||
/// !foo
|
||||
/// !
|
||||
@ -601,26 +590,6 @@ lltok::Kind LLLexer::LexIdentifier() {
|
||||
TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context));
|
||||
#undef TYPEKEYWORD
|
||||
|
||||
// Handle special forms for autoupgrading. Drop these in LLVM 3.0. This is
|
||||
// to avoid conflicting with the sext/zext instructions, below.
|
||||
if (Len == 4 && !memcmp(StartChar, "sext", 4)) {
|
||||
// Scan CurPtr ahead, seeing if there is just whitespace before the newline.
|
||||
if (JustWhitespaceNewLine(CurPtr))
|
||||
return lltok::kw_signext;
|
||||
} else if (Len == 4 && !memcmp(StartChar, "zext", 4)) {
|
||||
// Scan CurPtr ahead, seeing if there is just whitespace before the newline.
|
||||
if (JustWhitespaceNewLine(CurPtr))
|
||||
return lltok::kw_zeroext;
|
||||
} else if (Len == 6 && !memcmp(StartChar, "malloc", 6)) {
|
||||
// FIXME: Remove in LLVM 3.0.
|
||||
// Autoupgrade malloc instruction.
|
||||
return lltok::kw_malloc;
|
||||
} else if (Len == 4 && !memcmp(StartChar, "free", 4)) {
|
||||
// FIXME: Remove in LLVM 3.0.
|
||||
// Autoupgrade malloc instruction.
|
||||
return lltok::kw_free;
|
||||
}
|
||||
|
||||
// Keywords for instructions.
|
||||
#define INSTKEYWORD(STR, Enum) \
|
||||
if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
|
||||
@ -692,14 +661,6 @@ lltok::Kind LLLexer::LexIdentifier() {
|
||||
return lltok::kw_cc;
|
||||
}
|
||||
|
||||
// If this starts with "call", return it as CALL. This is to support old
|
||||
// broken .ll files. FIXME: remove this with LLVM 3.0.
|
||||
if (CurPtr-TokStart > 4 && !memcmp(TokStart, "call", 4)) {
|
||||
CurPtr = TokStart+4;
|
||||
UIntVal = Instruction::Call;
|
||||
return lltok::kw_call;
|
||||
}
|
||||
|
||||
// Finally, if this isn't known, return an error.
|
||||
CurPtr = TokStart+1;
|
||||
return lltok::Error;
|
||||
|
@ -59,24 +59,6 @@ bool LLParser::ValidateEndOfModule() {
|
||||
}
|
||||
|
||||
|
||||
// Update auto-upgraded malloc calls to "malloc".
|
||||
// FIXME: Remove in LLVM 3.0.
|
||||
if (MallocF) {
|
||||
MallocF->setName("malloc");
|
||||
// If setName() does not set the name to "malloc", then there is already a
|
||||
// declaration of "malloc". In that case, iterate over all calls to MallocF
|
||||
// and get them to call the declared "malloc" instead.
|
||||
if (MallocF->getName() != "malloc") {
|
||||
Constant *RealMallocF = M->getFunction("malloc");
|
||||
if (RealMallocF->getType() != MallocF->getType())
|
||||
RealMallocF = ConstantExpr::getBitCast(RealMallocF, MallocF->getType());
|
||||
MallocF->replaceAllUsesWith(RealMallocF);
|
||||
MallocF->eraseFromParent();
|
||||
MallocF = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If there are entries in ForwardRefBlockAddresses at this point, they are
|
||||
// references after the function was defined. Resolve those now.
|
||||
while (!ForwardRefBlockAddresses.empty()) {
|
||||
@ -176,7 +158,6 @@ bool LLParser::ParseTopLevelEntities() {
|
||||
switch (Lex.getKind()) {
|
||||
default: return TokError("expected top-level entity");
|
||||
case lltok::Eof: return false;
|
||||
//case lltok::kw_define:
|
||||
case lltok::kw_declare: if (ParseDeclare()) return true; break;
|
||||
case lltok::kw_define: if (ParseDefine()) return true; break;
|
||||
case lltok::kw_module: if (ParseModuleAsm()) return true; break;
|
||||
@ -931,33 +912,23 @@ bool LLParser::ParseOptionalAddrSpace(unsigned &AddrSpace) {
|
||||
/// ParseOptionalAttrs - Parse a potentially empty attribute list. AttrKind
|
||||
/// indicates what kind of attribute list this is: 0: function arg, 1: result,
|
||||
/// 2: function attr.
|
||||
/// 3: function arg after value: FIXME: REMOVE IN LLVM 3.0
|
||||
bool LLParser::ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind) {
|
||||
Attrs = Attribute::None;
|
||||
LocTy AttrLoc = Lex.getLoc();
|
||||
|
||||
while (1) {
|
||||
switch (Lex.getKind()) {
|
||||
case lltok::kw_sext:
|
||||
case lltok::kw_zext:
|
||||
// Treat these as signext/zeroext if they occur in the argument list after
|
||||
// the value, as in "call i8 @foo(i8 10 sext)". If they occur before the
|
||||
// value, as in "call i8 @foo(i8 sext (" then it is part of a constant
|
||||
// expr.
|
||||
// FIXME: REMOVE THIS IN LLVM 3.0
|
||||
if (AttrKind == 3) {
|
||||
if (Lex.getKind() == lltok::kw_sext)
|
||||
Attrs |= Attribute::SExt;
|
||||
else
|
||||
Attrs |= Attribute::ZExt;
|
||||
break;
|
||||
}
|
||||
// FALL THROUGH.
|
||||
default: // End of attributes.
|
||||
if (AttrKind != 2 && (Attrs & Attribute::FunctionOnly))
|
||||
return Error(AttrLoc, "invalid use of function-only attribute");
|
||||
|
||||
if (AttrKind != 0 && AttrKind != 3 && (Attrs & Attribute::ParameterOnly))
|
||||
// As a hack, we allow "align 2" on functions as a synonym for
|
||||
// "alignstack 2".
|
||||
if (AttrKind == 2 &&
|
||||
(Attrs & ~(Attribute::FunctionOnly | Attribute::Alignment)))
|
||||
return Error(AttrLoc, "invalid use of attribute on a function");
|
||||
|
||||
if (AttrKind != 0 && (Attrs & Attribute::ParameterOnly))
|
||||
return Error(AttrLoc, "invalid use of parameter-only attribute");
|
||||
|
||||
return false;
|
||||
@ -1496,11 +1467,7 @@ bool LLParser::ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
|
||||
return true;
|
||||
|
||||
// Otherwise, handle normal operands.
|
||||
if (ParseOptionalAttrs(ArgAttrs1, 0) ||
|
||||
ParseValue(ArgTy, V, PFS) ||
|
||||
// FIXME: Should not allow attributes after the argument, remove this
|
||||
// in LLVM 3.0.
|
||||
ParseOptionalAttrs(ArgAttrs2, 3))
|
||||
if (ParseOptionalAttrs(ArgAttrs1, 0) || ParseValue(ArgTy, V, PFS))
|
||||
return true;
|
||||
ArgList.push_back(ParamInfo(ArgLoc, V, ArgAttrs1|ArgAttrs2));
|
||||
}
|
||||
@ -2763,13 +2730,6 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
|
||||
// and do semantic checks.
|
||||
std::vector<const Type*> ParamTypeList;
|
||||
SmallVector<AttributeWithIndex, 8> Attrs;
|
||||
// FIXME : In 3.0, stop accepting zext, sext and inreg as optional function
|
||||
// attributes.
|
||||
unsigned ObsoleteFuncAttrs = Attribute::ZExt|Attribute::SExt|Attribute::InReg;
|
||||
if (FuncAttrs & ObsoleteFuncAttrs) {
|
||||
RetAttrs |= FuncAttrs & ObsoleteFuncAttrs;
|
||||
FuncAttrs &= ~ObsoleteFuncAttrs;
|
||||
}
|
||||
|
||||
if (RetAttrs != Attribute::None)
|
||||
Attrs.push_back(AttributeWithIndex::get(0, RetAttrs));
|
||||
@ -3063,8 +3023,6 @@ int LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB,
|
||||
case lltok::kw_tail: return ParseCall(Inst, PFS, true);
|
||||
// Memory.
|
||||
case lltok::kw_alloca: return ParseAlloc(Inst, PFS);
|
||||
case lltok::kw_malloc: return ParseAlloc(Inst, PFS, BB, false);
|
||||
case lltok::kw_free: return ParseFree(Inst, PFS, BB);
|
||||
case lltok::kw_load: return ParseLoad(Inst, PFS, false);
|
||||
case lltok::kw_store: return ParseStore(Inst, PFS, false);
|
||||
case lltok::kw_volatile:
|
||||
@ -3342,14 +3300,6 @@ bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
|
||||
Value *Callee;
|
||||
if (ConvertValIDToValue(PFTy, CalleeID, Callee, &PFS)) return true;
|
||||
|
||||
// FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional
|
||||
// function attributes.
|
||||
unsigned ObsoleteFuncAttrs = Attribute::ZExt|Attribute::SExt|Attribute::InReg;
|
||||
if (FnAttrs & ObsoleteFuncAttrs) {
|
||||
RetAttrs |= FnAttrs & ObsoleteFuncAttrs;
|
||||
FnAttrs &= ~ObsoleteFuncAttrs;
|
||||
}
|
||||
|
||||
// Set up the Attributes for the function.
|
||||
SmallVector<AttributeWithIndex, 8> Attrs;
|
||||
if (RetAttrs != Attribute::None)
|
||||
@ -3687,14 +3637,6 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
|
||||
Value *Callee;
|
||||
if (ConvertValIDToValue(PFTy, CalleeID, Callee, &PFS)) return true;
|
||||
|
||||
// FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional
|
||||
// function attributes.
|
||||
unsigned ObsoleteFuncAttrs = Attribute::ZExt|Attribute::SExt|Attribute::InReg;
|
||||
if (FnAttrs & ObsoleteFuncAttrs) {
|
||||
RetAttrs |= FnAttrs & ObsoleteFuncAttrs;
|
||||
FnAttrs &= ~ObsoleteFuncAttrs;
|
||||
}
|
||||
|
||||
// Set up the Attributes for the function.
|
||||
SmallVector<AttributeWithIndex, 8> Attrs;
|
||||
if (RetAttrs != Attribute::None)
|
||||
@ -3744,10 +3686,8 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// ParseAlloc
|
||||
/// ::= 'malloc' Type (',' TypeAndValue)? (',' OptionalInfo)?
|
||||
/// ::= 'alloca' Type (',' TypeAndValue)? (',' OptionalInfo)?
|
||||
int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS,
|
||||
BasicBlock* BB, bool isAlloca) {
|
||||
int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
|
||||
PATypeHolder Ty(Type::getVoidTy(Context));
|
||||
Value *Size = 0;
|
||||
LocTy SizeLoc;
|
||||
@ -3770,37 +3710,8 @@ int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS,
|
||||
if (Size && !Size->getType()->isIntegerTy())
|
||||
return Error(SizeLoc, "element count must have integer type");
|
||||
|
||||
if (isAlloca) {
|
||||
Inst = new AllocaInst(Ty, Size, Alignment);
|
||||
return AteExtraComma ? InstExtraComma : InstNormal;
|
||||
}
|
||||
|
||||
// Autoupgrade old malloc instruction to malloc call.
|
||||
// FIXME: Remove in LLVM 3.0.
|
||||
if (Size && !Size->getType()->isIntegerTy(32))
|
||||
return Error(SizeLoc, "element count must be i32");
|
||||
const Type *IntPtrTy = Type::getInt32Ty(Context);
|
||||
Constant *AllocSize = ConstantExpr::getSizeOf(Ty);
|
||||
AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, IntPtrTy);
|
||||
if (!MallocF)
|
||||
// Prototype malloc as "void *(int32)".
|
||||
// This function is renamed as "malloc" in ValidateEndOfModule().
|
||||
MallocF = cast<Function>(
|
||||
M->getOrInsertFunction("", Type::getInt8PtrTy(Context), IntPtrTy, NULL));
|
||||
Inst = CallInst::CreateMalloc(BB, IntPtrTy, Ty, AllocSize, Size, MallocF);
|
||||
return AteExtraComma ? InstExtraComma : InstNormal;
|
||||
}
|
||||
|
||||
/// ParseFree
|
||||
/// ::= 'free' TypeAndValue
|
||||
bool LLParser::ParseFree(Instruction *&Inst, PerFunctionState &PFS,
|
||||
BasicBlock* BB) {
|
||||
Value *Val; LocTy Loc;
|
||||
if (ParseTypeAndValue(Val, Loc, PFS)) return true;
|
||||
if (!Val->getType()->isPointerTy())
|
||||
return Error(Loc, "operand to free must be a pointer");
|
||||
Inst = CallInst::CreateFree(Val, BB);
|
||||
return false;
|
||||
Inst = new AllocaInst(Ty, Size, Alignment);
|
||||
return AteExtraComma ? InstExtraComma : InstNormal;
|
||||
}
|
||||
|
||||
/// ParseLoad
|
||||
|
@ -131,11 +131,10 @@ namespace llvm {
|
||||
std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > >
|
||||
ForwardRefBlockAddresses;
|
||||
|
||||
Function *MallocF;
|
||||
public:
|
||||
LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) :
|
||||
Context(m->getContext()), Lex(F, SM, Err, m->getContext()),
|
||||
M(m), MallocF(NULL) {}
|
||||
M(m) {}
|
||||
bool Run();
|
||||
|
||||
LLVMContext& getContext() { return Context; }
|
||||
@ -359,9 +358,7 @@ namespace llvm {
|
||||
bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS);
|
||||
int ParsePHI(Instruction *&I, PerFunctionState &PFS);
|
||||
bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail);
|
||||
int ParseAlloc(Instruction *&I, PerFunctionState &PFS,
|
||||
BasicBlock *BB = 0, bool isAlloca = true);
|
||||
bool ParseFree(Instruction *&I, PerFunctionState &PFS, BasicBlock *BB);
|
||||
int ParseAlloc(Instruction *&I, PerFunctionState &PFS);
|
||||
int ParseLoad(Instruction *&I, PerFunctionState &PFS, bool isVolatile);
|
||||
int ParseStore(Instruction *&I, PerFunctionState &PFS, bool isVolatile);
|
||||
bool ParseGetResult(Instruction *&I, PerFunctionState &PFS);
|
||||
|
@ -122,7 +122,7 @@ namespace lltok {
|
||||
kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_unwind,
|
||||
kw_unreachable,
|
||||
|
||||
kw_malloc, kw_alloca, kw_free, kw_load, kw_store, kw_getelementptr,
|
||||
kw_alloca, kw_load, kw_store, kw_getelementptr,
|
||||
|
||||
kw_extractelement, kw_insertelement, kw_shufflevector, kw_getresult,
|
||||
kw_extractvalue, kw_insertvalue, kw_blockaddress,
|
||||
|
Loading…
x
Reference in New Issue
Block a user