Skip to content

Commit

Permalink
[Misc] update llvm version to 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinkela authored and LFsWang committed Nov 23, 2021
1 parent b7f0911 commit c4413c3
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ include_directories(BEFORE
include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_INCLUDE_DIR}")
link_directories("${LLVM_LIBRARY_DIR}")

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
Expand Down
2 changes: 1 addition & 1 deletion include/soll/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "soll/Frontend/FrontendOptions.h"
#include <llvm/ADT/APInt.h>
#include <llvm/ADT/IntrusiveRefCntPtr.h>
#include <llvm/ADT/StringMap.h>
#include <llvm/IR/Value.h>

namespace soll {

class ASTContext : public llvm::RefCountedBase<ASTContext> {
Expand Down
2 changes: 2 additions & 0 deletions include/soll/Basic/FileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#pragma once
#include "soll/Basic/FileSystemOptions.h"
#include <llvm/ADT/IntrusiveRefCntPtr.h>
#include <llvm/ADT/StringMap.h>
#include <llvm/Support/Allocator.h>
#include <llvm/Support/VirtualFileSystem.h>
#include <map>
#include <memory>
Expand Down
1 change: 1 addition & 0 deletions include/soll/Basic/IdentifierTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "soll/Basic/TokenKinds.h"
#include <llvm/ADT/StringMap.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/Allocator.h>

namespace soll {

Expand Down
21 changes: 15 additions & 6 deletions lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "soll/Basic/TargetOptions.h"
#include "soll/CodeGen/LoweringInteger.h"
#include <llvm/ADT/Triple.h>
#include <llvm/Analysis/AliasAnalysis.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/Analysis/TargetTransformInfo.h>
#include <llvm/Bitcode/BitcodeWriterPass.h>
Expand Down Expand Up @@ -142,7 +143,10 @@ void EmitAssemblyHelper::EmitAssembly(
TheModule->setDataLayout(TM->createDataLayout());
}

#if LLVM_VERSION_MAJOR >= 9
#if LLVM_VERSION_MAJOR >= 12
llvm::PassBuilder PB(false, TM.get(), llvm::PipelineTuningOptions(),
llvm::None);
#elif LLVM_VERSION_MAJOR >= 9
llvm::PassBuilder PB(TM.get(), llvm::PipelineTuningOptions(), llvm::None);
#else
llvm::PassBuilder PB(TM.get(), llvm::None);
Expand Down Expand Up @@ -183,19 +187,24 @@ void EmitAssemblyHelper::EmitAssembly(
default:
break;
case O1:
MPM.addPass(PB.buildPerModuleDefaultPipeline(llvm::PassBuilder::O1));
MPM.addPass(PB.buildPerModuleDefaultPipeline(
llvm::PassBuilder::OptimizationLevel::O1));
break;
case O2:
MPM.addPass(PB.buildPerModuleDefaultPipeline(llvm::PassBuilder::O2));
MPM.addPass(PB.buildPerModuleDefaultPipeline(
llvm::PassBuilder::OptimizationLevel::O2));
break;
case O3:
MPM.addPass(PB.buildPerModuleDefaultPipeline(llvm::PassBuilder::O3));
MPM.addPass(PB.buildPerModuleDefaultPipeline(
llvm::PassBuilder::OptimizationLevel::O3));
break;
case Os:
MPM.addPass(PB.buildPerModuleDefaultPipeline(llvm::PassBuilder::Os));
MPM.addPass(PB.buildPerModuleDefaultPipeline(
llvm::PassBuilder::OptimizationLevel::Os));
break;
case Oz:
MPM.addPass(PB.buildPerModuleDefaultPipeline(llvm::PassBuilder::Oz));
MPM.addPass(PB.buildPerModuleDefaultPipeline(
llvm::PassBuilder::OptimizationLevel::Oz));
break;
}
MPM.addPass(llvm::AlwaysInlinerPass());
Expand Down
13 changes: 10 additions & 3 deletions lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "llvm/Support/Alignment.h"
#include <lld/Common/Driver.h>
#include <llvm/IR/ConstantFolder.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/DiagnosticInfo.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/Support/ToolOutputFile.h>
Expand Down Expand Up @@ -131,7 +132,13 @@ class BackendConsumer : public ASTConsumer {
llvm::BasicBlock *Entry =
llvm::BasicBlock::Create(VMContext, "entry", Func);
Builder.SetInsertPoint(Entry);
llvm::Value *Result = llvm::UndefValue::get(Module.getTypeByName("bytes"));
llvm::Value *Result =
#if LLVM_VERSION_MAJOR >= 12
llvm::UndefValue::get(
llvm::StructType::getTypeByName(VMContext, "bytes"));
#else
llvm::UndefValue::get(Module.getTypeByName("bytes"));
#endif
Result = Builder.CreateInsertValue(Result, Builder.getIntN(256, Length), 0);
Result = Builder.CreateInsertValue(
Result, Builder.CreateBitCast(GV, Builder.getInt8PtrTy()), 1);
Expand Down Expand Up @@ -181,7 +188,7 @@ class BackendConsumer : public ASTConsumer {
if (auto Error = removeExports(Wasm->TmpName)) {
llvm::consumeError(Wasm->discard());
llvm::consumeError(Object->discard());
return Error;
return std::move(Error);
}

auto Binary = llvm::MemoryBuffer::getFile(Wasm->TmpName);
Expand Down Expand Up @@ -289,7 +296,7 @@ std::unique_ptr<ASTConsumer>
CodeGenAction::CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) {
return std::make_unique<BackendConsumer>(
Action, CI.getDiagnostics(), CI.getCodeGenOpts(), CI.getTargetOpts(),
InFile, *VMContext, CI.GetOutputStreamFunc());
InFile.str(), *VMContext, CI.GetOutputStreamFunc());
}

EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *VMContext)
Expand Down
17 changes: 16 additions & 1 deletion lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ void CodeGenModule::emitStructDecl(const StructDecl *SD) {

void CodeGenModule::emitYulObject(const YulObject *YO) {
{
const std::string Name = YO->getUniqueName();
const std::string Name = YO->getUniqueName().str();
emitNestedObjectGetter(Name + ".object");
NestedEntries.emplace_back(Name + ".main", Name + ".object", nullptr);
/*
Expand All @@ -1627,6 +1627,21 @@ void CodeGenModule::emitYulObject(const YulObject *YO) {
}
for (const auto *O : YO->getObjectList()) {
emitYulObject(O);
// FIXME
{
const std::string Name = O->getName().str();
emitNestedObjectGetter(Name + ".object");
NestedEntries.emplace_back(Name + ".main", Name + ".object", nullptr);
/*
llvm::Function *DataSize = llvm::Function::Create(
llvm::FunctionType::get(Int256Ty, false),
llvm::Function::InternalLinkage, ".datasize", TheModule);
llvm::Function *DataOffset = llvm::Function::Create(
llvm::FunctionType::get(Int8PtrTy, false),
llvm::Function::InternalLinkage, ".dataoffset", TheModule);
*/
// LookupYulDataOrYulObject.try_emplace(Name, O);
}
getEntry().clear();
getEntry().resize(1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,

CI.createASTContext();

std::string PresumedInputFile = getCurrentFileOrBufferName();
std::string PresumedInputFile = getCurrentFileOrBufferName().str();

std::unique_ptr<ASTConsumer> Consumer =
CreateASTConsumer(CI, PresumedInputFile);
Expand Down
6 changes: 3 additions & 3 deletions lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ Parser::parseFunctionHeader(bool ForceEmptyName, bool AllowModifiers) {
if (AllowModifiers && Tok.is(tok::identifier)) {
Diag(diag::err_unimplemented_token) << tok::identifier;

std::string ModifierName = Tok.getIdentifierInfo()->getName();
std::string ModifierName = Tok.getIdentifierInfo()->getName().str();
ConsumeToken(); // identifier

std::vector<ExprPtr> Arguments;
Expand Down Expand Up @@ -963,7 +963,7 @@ Parser::parseVariableDeclaration(VarDeclParserOptions const &Options,

std::unique_ptr<EventDecl> Parser::parseEventDefinition() {
const SourceLocation Begin = Tok.getLocation();
const std::string Name = Tok.getIdentifierInfo()->getName();
const std::string Name = Tok.getIdentifierInfo()->getName().str();
ConsumeToken(); // identifier
VarDeclParserOptions Options;
Options.AllowIndexed = true;
Expand All @@ -989,7 +989,7 @@ void Parser::parseUserDefinedTypeName() {
std::unique_ptr<IdentifierPath>
Parser::parseIdentifierPath(tok::TokenKind SplitTok) {
assert(Tok.isAnyIdentifier());
std::vector<std::string> path{Tok.getIdentifierInfo()->getName()};
std::vector<std::string> path{Tok.getIdentifierInfo()->getName().str()};
ConsumeToken(); // identifier

while (Tok.is(SplitTok)) {
Expand Down
15 changes: 15 additions & 0 deletions test/yul/metadata.yul
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// RUN: %soll --lang=Yul %s
object "metadata_x" {
code {
// sstore(dataoffset(".metadata.x"), 0)
let size := datasize("x")
}

object ".metadata" {
code {}
data "x" "ABC"
}

data "x" "CDE"
}
1 change: 1 addition & 0 deletions tools/soll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ target_link_libraries(soll
sollBasic
sollFrontend
sollFrontendTool
Threads::Threads
)

0 comments on commit c4413c3

Please sign in to comment.