diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-10-23 14:19:52 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-10-23 14:19:52 +0000 |
commit | 4a142eb28942073eb27a112b5ca1cca3f01beb9c (patch) | |
tree | 22cc59e4b240d84c3a5a60531119c4eca914a256 /lib/AsmParser/LLParser.cpp | |
parent | 5cd822fa9bbb9622241e3bf4d7674ed49ccde5b9 (diff) | |
download | src-4a142eb28942073eb27a112b5ca1cca3f01beb9c.tar.gz src-4a142eb28942073eb27a112b5ca1cca3f01beb9c.zip |
Notes
Diffstat (limited to 'lib/AsmParser/LLParser.cpp')
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 71 |
1 files changed, 49 insertions, 22 deletions
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 09bc5f736fc6..271567bd1e9b 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -69,6 +69,23 @@ bool LLParser::Run() { /// ValidateEndOfModule - Do final validity and sanity checks at the end of the /// module. 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 (!ForwardRefTypes.empty()) return Error(ForwardRefTypes.begin()->second.second, "use of undefined type named '" + @@ -1029,14 +1046,12 @@ bool LLParser::ParseOptionalCallingConv(CallingConv::ID &CC) { /// ::= /* empty */ /// ::= !dbg !42 bool LLParser::ParseOptionalCustomMetadata() { - - std::string Name; - if (Lex.getKind() == lltok::NamedOrCustomMD) { - Name = Lex.getStrVal(); - Lex.Lex(); - } else + if (Lex.getKind() != lltok::NamedOrCustomMD) return false; + std::string Name = Lex.getStrVal(); + Lex.Lex(); + if (Lex.getKind() != lltok::Metadata) return TokError("Expected '!' here"); Lex.Lex(); @@ -1047,7 +1062,7 @@ bool LLParser::ParseOptionalCustomMetadata() { MetadataContext &TheMetadata = M->getContext().getMetadata(); unsigned MDK = TheMetadata.getMDKind(Name.c_str()); if (!MDK) - MDK = TheMetadata.RegisterMDKind(Name.c_str()); + MDK = TheMetadata.registerMDKind(Name.c_str()); MDsOnInst.push_back(std::make_pair(MDK, cast<MDNode>(Node))); return false; @@ -1959,17 +1974,17 @@ bool LLParser::ParseValID(ValID &ID) { return false; case lltok::kw_asm: { - // ValID ::= 'asm' SideEffect? MsAsm? STRINGCONSTANT ',' STRINGCONSTANT - bool HasSideEffect, MsAsm; + // ValID ::= 'asm' SideEffect? AlignStack? STRINGCONSTANT ',' STRINGCONSTANT + bool HasSideEffect, AlignStack; Lex.Lex(); if (ParseOptionalToken(lltok::kw_sideeffect, HasSideEffect) || - ParseOptionalToken(lltok::kw_msasm, MsAsm) || + ParseOptionalToken(lltok::kw_alignstack, AlignStack) || ParseStringConstant(ID.StrVal) || ParseToken(lltok::comma, "expected comma in inline asm expression") || ParseToken(lltok::StringConstant, "expected constraint string")) return true; ID.StrVal2 = Lex.getStrVal(); - ID.UIntVal = HasSideEffect | ((unsigned)MsAsm<<1); + ID.UIntVal = HasSideEffect | ((unsigned)AlignStack<<1); ID.Kind = ValID::t_InlineAsm; return false; } @@ -2783,8 +2798,8 @@ bool LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB, case lltok::kw_call: return ParseCall(Inst, PFS, false); case lltok::kw_tail: return ParseCall(Inst, PFS, true); // Memory. - case lltok::kw_alloca: - case lltok::kw_malloc: return ParseAlloc(Inst, PFS, KeywordVal); + 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); case lltok::kw_load: return ParseLoad(Inst, PFS, false); case lltok::kw_store: return ParseStore(Inst, PFS, false); @@ -2858,8 +2873,6 @@ bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB, if (ParseType(Ty, true /*void allowed*/)) return true; if (Ty->isVoidTy()) { - if (EatIfPresent(lltok::comma)) - if (ParseOptionalCustomMetadata()) return true; Inst = ReturnInst::Create(Context); return false; } @@ -2895,8 +2908,6 @@ bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB, } } } - if (EatIfPresent(lltok::comma)) - if (ParseOptionalCustomMetadata()) return true; Inst = ReturnInst::Create(Context, RV); return false; @@ -3294,7 +3305,7 @@ bool LLParser::ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS) { } /// ParsePHI -/// ::= 'phi' Type '[' Value ',' Value ']' (',' '[' Value ',' Valueß ']')* +/// ::= 'phi' Type '[' Value ',' Value ']' (',' '[' Value ',' Value ']')* bool LLParser::ParsePHI(Instruction *&Inst, PerFunctionState &PFS) { PATypeHolder Ty(Type::getVoidTy(Context)); Value *Op0, *Op1; @@ -3315,6 +3326,9 @@ bool LLParser::ParsePHI(Instruction *&Inst, PerFunctionState &PFS) { if (!EatIfPresent(lltok::comma)) break; + if (Lex.getKind() == lltok::NamedOrCustomMD) + break; + if (ParseToken(lltok::lsquare, "expected '[' in phi value list") || ParseValue(Ty, Op0, PFS) || ParseToken(lltok::comma, "expected ',' after insertelement value") || @@ -3323,6 +3337,9 @@ bool LLParser::ParsePHI(Instruction *&Inst, PerFunctionState &PFS) { return true; } + if (Lex.getKind() == lltok::NamedOrCustomMD) + if (ParseOptionalCustomMetadata()) return true; + if (!Ty->isFirstClassType()) return Error(TypeLoc, "phi node must have first class type"); @@ -3439,7 +3456,7 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS, /// ::= 'malloc' Type (',' TypeAndValue)? (',' OptionalInfo)? /// ::= 'alloca' Type (',' TypeAndValue)? (',' OptionalInfo)? bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS, - unsigned Opc) { + BasicBlock* BB, bool isAlloca) { PATypeHolder Ty(Type::getVoidTy(Context)); Value *Size = 0; LocTy SizeLoc; @@ -3460,10 +3477,20 @@ bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS, if (Size && Size->getType() != Type::getInt32Ty(Context)) return Error(SizeLoc, "element count must be i32"); - if (Opc == Instruction::Malloc) - Inst = new MallocInst(Ty, Size, Alignment); - else + if (isAlloca) { Inst = new AllocaInst(Ty, Size, Alignment); + return false; + } + + // Autoupgrade old malloc instruction to malloc call. + // FIXME: Remove in LLVM 3.0. + const Type *IntPtrTy = Type::getInt32Ty(Context); + 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, Size, MallocF); return false; } |