diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index f46ff336c9268a748849f358fe3cdefc9fe022f2..aa47e275e146f8ed0b5ea9810140c78dd36ba70f 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 9457b0d371761f863cee7c03a720f79dc897535d..018bb9422754068d146501f377f70b369af50ac4 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 266a5bd2e5af1a293036598d7c3fc42d885a5402..8574dce4d6150d78f205d8f4cd31d466187134ff 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/deplibs/libmaple_driverutil.a b/src/deplibs/libmaple_driverutil.a index 63349fa0f13814f279dc7685821101ef1aac7211..258d971bac8e5b937eb0e8e73b04d2c03d1e45da 100644 Binary files a/src/deplibs/libmaple_driverutil.a and b/src/deplibs/libmaple_driverutil.a differ diff --git a/src/deplibs/libmempool.a b/src/deplibs/libmempool.a index 77f7f9b4b4549f791375f4f42bd8ab5f3c69bcfd..509e3b7701651d0836ba77e48e2de8a36c4461cd 100644 Binary files a/src/deplibs/libmempool.a and b/src/deplibs/libmempool.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 3e790dba23889a214cb1ad93dac4e64dfc2e843e..f10aef3f805b53f7b4fe1fd262fc947f54090437 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/huawei_secure_c/src/Makefile b/src/huawei_secure_c/src/Makefile deleted file mode 100644 index f60f3334a39b312ec84f24cae1a223dc1b81b7d4..0000000000000000000000000000000000000000 --- a/src/huawei_secure_c/src/Makefile +++ /dev/null @@ -1,138 +0,0 @@ -###### -### This is a sample file for linux platform, please write the Makefile according to the actual situation of the product -###### - -PROJECT=libsecurec.so -#if you need a debug version library, use "-g" instead of "-s -DNDEBUG -O2". -# If you compiler report a warning on "break strict-aliasing rules", there is no problem. If you need to clear all warnings, you can add "-fno-strict-aliasing" option to your compiler, but this will impact the performance a little. - -#for linux secure compile options from stdandard 2018.8 -SECURE_CFLAG_FOR_SHARED_LIBRARY = -fstack-protector-all -fPIC -SECURE_LDFLAG_FOR_SHARED_LIBRARY += -Wl,-z,relro,-z,now,-z,noexecstack - - -#-fvisibility=hidden need modify source code -#SECURE_CFLAG_FOR_SHARED_LIBRARY_OPTIONAL += -fvisibility=hidden - -#-ftrapv -D_FORTIFY_SOURCE=2 -fstack-check May result in performance degradation after opening -#SECURE_CFLAG_FOR_SHARED_LIBRARY_OPTIONAL += -D_FORTIFY_SOURCE=2 -O2 -#SECURE_CFLAG_FOR_SHARED_LIBRARY_OPTIONAL += -ftrapv -#SECURE_CFLAG_FOR_SHARED_LIBRARY_OPTIONAL += -fstack-check - - -SECURE_CFLAG_FOR_SHARED_LIBRARY_OPTIONAL += -s -SECURE_CFLAG_FOR_SHARED_LIBRARY_OPTIONAL += -Wformat=2 -Wfloat-equal -Wshadow -# about pie option , We compiled a dynamic library, so we did not use it. ,If you want to compile executable files, please open this option -#SECURE_CFLAG_FOR_EXE = -fPIE -pie - - - -## code standard options -SECUREC_CODE_STANDARD_OPTION = -Wconversion -SECUREC_CODE_STANDARD_OPTION += -Wformat-security -SECUREC_CODE_STANDARD_OPTION += -Wextra -SECUREC_CODE_STANDARD_OPTION += --param ssp-buffer-size=4 -#repeat options -#SECUREC_CODE_STANDARD_OPTION += -D_FORTIFY_SOURCE=2 -#SECUREC_CODE_STANDARD_OPTION += -Wl,-z,relro,-z,now -#SECUREC_CODE_STANDARD_OPTION += -fstack-protector -#this option just break compile -#SECUREC_CODE_STANDARD_OPTION += -Werror - -#from product options -PRODUCT_OPTION = -Warray-bounds -PRODUCT_OPTION += -Wpointer-arith -PRODUCT_OPTION += -Wcast-qual -PRODUCT_OPTION += -Wstrict-prototypes -PRODUCT_OPTION += -Wmissing-prototypes -PRODUCT_OPTION += -Wstrict-overflow=1 -PRODUCT_OPTION += -Wstrict-aliasing=2 -PRODUCT_OPTION += -Wswitch -Wswitch-default - -CFLAG = -Wall -s -DNDEBUG -O2 $(SECURE_CFLAG_FOR_SHARED_LIBRARY) $(SECURE_CFLAG_FOR_EXE) $(SECURE_CFLAG_FOR_SHARED_LIBRARY_OPTIONAL) $(SECUREC_CODE_STANDARD_OPTION) $(PRODUCT_OPTION) -#CFLAG += -DSECUREC_VXWORKS_PLATFORM -#CFLAG += -DSECUREC_SUPPORT_STRTOLD -#CFLAG += -DSECUREC_VXWORKS_VERSION_5_4 -#CFLAG += -D__STDC_WANT_LIB_EXT1__=0 -CFLAG += $(CFLAG_EXT) - - -CC?=gcc -ARCH:=$(shell getconf LONG_BIT) - -#The GCC High version will report an alarm with no break in the switch case statement, using this option to suppress -#There is a case statement without break in code, in order to reduce code size. -#GCCVERSION = $(shell $(CC) --version | head -1 | sed -e 's/^[^0-9]*\([0-9]\).*/\1/g') -#CHKVERSION= $(shell if [ $(GCCVERSION) -ge 5 ];then echo 1;else echo 0;fi) -#ifeq "$(CHKVERSION)" "1" -#CFLAG += -Wno-implicit-fallthrough -#endif - -ifeq ($(MAKECMDGOALS),lib) -#Set static library related options -CFLAG :=$(filter-out "xxxxx",$(CFLAG)) -endif - -SOURCES=$(wildcard *.c) -OBJECTS=$(patsubst %.c,%.o,$(SOURCES)) - -.PHONY:clean lib kernel - -ENABLE_SCANF_FILE=$(findstring SECUREC_ENABLE_SCANF_FILE=0,$(CFLAG)) -ifeq ($(ENABLE_SCANF_FILE),SECUREC_ENABLE_SCANF_FILE=0) -OBJECTS:=$(filter-out fscanf_s.o vfscanf_s.o vscanf_s.o scanf_s.o vwscanf_s.o wscanf_s.o fwscanf_s.o vfwscanf_s.o,$(OBJECTS)) -endif - - -ifneq ($(CFLAGS),) -CFLAG :=$(CFLAGS) -endif -CFLAG += -I../include -LD_FLAG ?= $(SECURE_LDFLAG_FOR_SHARED_LIBRARY) $(SECURE_CFLAG_FOR_SHARED_LIBRARY) -AR ?=ar -RANLIB ?=ranlib - -$(PROJECT):$(OBJECTS) - @mkdir -p ../obj - mkdir -p ../lib - $(CC) -shared -o ../lib/$@ $(patsubst %.o,../obj/%.o,$^) $(LD_FLAG) - @echo "finish $(PROJECT)" - #you may add you custom commands here - -lib:$(OBJECTS) - $(AR) crv libsecurec.a $(patsubst %.o,../obj/%.o,$^) - $(RANLIB) libsecurec.a - -mkdir -p ../lib - -cp libsecurec.a ../lib - @echo "finish libsecurec.a" - #you may add you custom commands here -.c.o: - @mkdir -p ../obj - $(CC) -c $< $(CFLAG) -o ../obj/$(patsubst %.c,%.o,$<) - -EXTRA_CFLAGS += -I$(INCDIR) -fstack-protector - -# provide the default value to module name and ccflags-y -ifeq ($(MODULE),) - MODULE := ksecurec -endif -ifeq ($(DEBUG),y) - ccflags-y += -DDEBUG -endif - -ifneq ($(KERNELRELEASE),) - obj-m := ksecurec.o - ksecurec-objs := memcpy_s.o memmove_s.o memset_s.o securecutil.o strcat_s.o strcpy_s.o strncat_s.o strncpy_s.o # sprintf_s.o vsprintf_s.o snprintf_s.o vsnprintf_s.o secureprintoutput_a.o sscanf_s.o vsscanf_s.o secureinput_a.o -else - KERNELDIR := /lib/modules/$(shell uname -r)/build - PWD := $(shell pwd) -kernel: - $(MAKE) -C $(KERNELDIR) M=$(PWD) INCDIR=$(PWD)/../include modules -endif - -clean: - echo "cleaning ...." - -rm modules.order Module.symvers $(MODULE).ko $(MODULE).mod.c $(MODULE).mod.o $(MODULE).o *.o - -rm -rf *.o ../obj ../lib $(PROJECT) - echo "clean up" - diff --git a/src/maple_driver/include/compiler_selector.h b/src/maple_driver/include/compiler_selector.h index 05457ae96e6378c12b5a5c7f5f1053059bcdad70..c9bf437544652dc5c038bd3c4b7e79afdac1a0ee 100644 --- a/src/maple_driver/include/compiler_selector.h +++ b/src/maple_driver/include/compiler_selector.h @@ -23,9 +23,9 @@ namespace maple { using SupportedCompilers = std::unordered_map; class CompilerSelector { public: - CompilerSelector() {} + CompilerSelector() = default; - virtual ~CompilerSelector() {} + virtual ~CompilerSelector() = default; virtual const ErrorCode Select(const SupportedCompilers &supportedCompilers, const MplOptions &mplOptions, std::vector &selected) const { @@ -35,12 +35,12 @@ class CompilerSelector { class CompilerSelectorImpl : public CompilerSelector { public: - CompilerSelectorImpl() {} + CompilerSelectorImpl() = default; - ~CompilerSelectorImpl() {} + ~CompilerSelectorImpl() = default; const ErrorCode Select(const SupportedCompilers &supportedCompilers, const MplOptions &mplOptions, - std::vector &selected) const; + std::vector &selected) const override; private: Compiler *FindCompiler(const SupportedCompilers &compilers, const std::string &name) const; diff --git a/src/maple_driver/include/driver_runner.h b/src/maple_driver/include/driver_runner.h index cc5681b71fd0486ace1504e05796ecebc13015ba..9b0d2827a1b134c563e4ec6e666ec9bc55d0fd4c 100644 --- a/src/maple_driver/include/driver_runner.h +++ b/src/maple_driver/include/driver_runner.h @@ -22,18 +22,15 @@ #include "error_code.h" -extern const char *kNoFile; -extern const char *kMpl2Mpl; -extern const char *kMe; - namespace maple { -enum OptLevel { kLevelO0, kLevelO1, kLevelO2 }; +extern const std::string mpl2Mpl; +extern const std::string mplME; class DriverRunner final { public: DriverRunner(MIRModule *theModule, const std::vector &exeNames, Options *mpl2mplOptions, - std::string mpl2mplInput, MeOption *meOptions, std::string meInput, std::string actualInput, + std::string mpl2mplInput, MeOption *meOptions, const std::string &meInput, std::string actualInput, MemPool *optMp, bool timePhases = false, bool genMemPl = false) : theModule(theModule), @@ -45,31 +42,15 @@ class DriverRunner final { actualInput(actualInput), optMp(optMp), timePhases(timePhases), - genMemPl(genMemPl) { - } + genMemPl(genMemPl) {} DriverRunner(MIRModule *theModule, const std::vector &exeNames, std::string actualInput, MemPool *optMp, bool timePhases = false, bool genVtableImpl = false, bool genMemPl = false) - : DriverRunner(theModule, exeNames, nullptr, "", nullptr, "", actualInput, optMp, timePhases, genMemPl) { - } + : DriverRunner(theModule, exeNames, nullptr, "", nullptr, "", actualInput, optMp, timePhases, genMemPl) {} - ~DriverRunner() {} + ~DriverRunner() = default; ErrorCode Run(); - void ReleaseOptions(); - ErrorCode ParseInput(std::string outputFile, std::string oriBasename) const; - bool VerifyModule(MIRModulePtr &mModule) const; - void ProcessMpl2mplAndMePhases(std::string outputFile, std::string vtableImplFile) const; - - void SetMpl2mplInfo(Options *mpl2mplOptions, const std::string &mpl2mplInput) { - this->mpl2mplOptions = mpl2mplOptions; - this->mpl2mplInput = mpl2mplInput; - } - - void SetMeInfo(MeOption *meOptions, const std::string &meInput) { - this->meOptions = meOptions; - this->meInput = meInput; - } private: @@ -88,10 +69,14 @@ class DriverRunner final { static bool FuncOrderLessThan(const MIRFunction *left, const MIRFunction *right); bool IsFramework() const; + bool VerifyModule(MIRModulePtr &mModule) const; + ErrorCode ParseInput(const std::string &outputFile, const std::string &oriBasename) const; std::string GetPostfix() const; - void InitPhases(InterleavedManager &mgr, std::vector &phases) const; - void AddPhases(InterleavedManager &mgr, std::vector &phases, const PhaseManager &phaseManager) const; - void AddPhase(std::vector &phases, std::string phase, const PhaseManager &phaseManager) const; + void InitPhases(InterleavedManager &mgr, const std::vector &phases) const; + void AddPhases(InterleavedManager &mgr, const std::vector &phases, + const PhaseManager &phaseManager) const; + void AddPhase(std::vector &phases, const std::string phase, const PhaseManager &phaseManager) const; + void ProcessMpl2mplAndMePhases(const std::string &outputFile, const std::string &vtableImplFile) const; }; } // namespace maple diff --git a/src/maple_driver/src/driver_runner.cpp b/src/maple_driver/src/driver_runner.cpp index 572c3a335ee80e53044aeda424348d0f56fc6719..666ad48700e5eba1ef40f283e9d09aed2d6d1936 100644 --- a/src/maple_driver/src/driver_runner.cpp +++ b/src/maple_driver/src/driver_runner.cpp @@ -21,16 +21,12 @@ #include "mir_function.h" #include "mir_parser.h" -const char *kNoFile = "nofile"; -const char *kMpl2Mpl = "mpl2mpl"; -const char *kMe = "me"; - #define JAVALANG (theModule->IsJavaModule()) #define CHECK_MODULE(errorCode...) \ do { \ if (theModule == nullptr) { \ - LogInfo::MapleLogger() << "Fatal error: the module is null" << std::endl; \ + LogInfo::MapleLogger() << "Fatal error: the module is null" << '\n'; \ return errorCode; \ } \ } while (0) @@ -56,11 +52,17 @@ const char *kMe = "me"; } namespace maple { + +const std::string mpl2Mpl = "mpl2mpl"; +const std::string mplME = "me"; + +enum OptLevel { kLevelO0, kLevelO1, kLevelO2 }; + ErrorCode DriverRunner::Run() { CHECK_MODULE(ErrorCode::kErrorExit); if (exeNames.empty()) { - LogInfo::MapleLogger() << "Fatal error: no exe specified" << std::endl; + LogInfo::MapleLogger() << "Fatal error: no exe specified" << '\n'; return ErrorCode::kErrorExit; } @@ -74,26 +76,18 @@ ErrorCode DriverRunner::Run() { ErrorCode ret = ParseInput(outputFile, originBaseName); - if (ret == ErrorCode::kErrorNoError) { - if (mpl2mplOptions || meOptions) { - std::string vtableImplFile = originBaseName; - vtableImplFile.append(".VtableImpl.mpl"); - originBaseName.append(".VtableImpl"); - ProcessMpl2mplAndMePhases(outputFile, vtableImplFile); - } - - } else { + if (ret != ErrorCode::kErrorNoError) { return ErrorCode::kErrorExit; } - + if (mpl2mplOptions || meOptions) { + std::string vtableImplFile = originBaseName; + vtableImplFile.append(".VtableImpl.mpl"); + originBaseName.append(".VtableImpl"); + ProcessMpl2mplAndMePhases(outputFile, vtableImplFile); + } return ErrorCode::kErrorNoError; } -void DriverRunner::ReleaseOptions() { - RELEASE(mpl2mplOptions); - RELEASE(meOptions); -} - bool DriverRunner::FuncOrderLessThan(const MIRFunction *left, const MIRFunction *right) { return left->GetLayoutType() < right->GetLayoutType(); } @@ -103,22 +97,21 @@ bool DriverRunner::IsFramework() const { } std::string DriverRunner::GetPostfix() const { - std::string postFix; - - if (printOutExe == kMe) { - postFix = ".me.mpl"; - } else if (printOutExe == kMpl2Mpl) { - postFix = ".VtableImpl.mpl"; + if (printOutExe == mplME) { + return ".me.mpl"; + } else if (printOutExe == mpl2Mpl) { + return ".VtableImpl.mpl"; } else { } - return postFix; + return ""; } -ErrorCode DriverRunner::ParseInput(std::string outputFile, std::string originBaseName) const { + +ErrorCode DriverRunner::ParseInput(const std::string &outputFile, const std::string &originBaseName) const { CHECK_MODULE(ErrorCode::kErrorExit); - LogInfo::MapleLogger() << "Starting parse input" << std::endl; + LogInfo::MapleLogger() << "Starting parse input" << '\n'; MPLTimer timer; timer.Start(); @@ -130,23 +123,23 @@ ErrorCode DriverRunner::ParseInput(std::string outputFile, std::string originBas parser.EmitError(outputFile); } timer.Stop(); - LogInfo::MapleLogger() << "Parse consumed " << timer.Elapsed() << "s" << std::endl; + LogInfo::MapleLogger() << "Parse consumed " << timer.Elapsed() << "s" << '\n'; return ret; } bool DriverRunner::VerifyModule(MIRModulePtr &mModule) const { - LogInfo::MapleLogger() << "========== Starting Verify Module =====================" << std::endl; + LogInfo::MapleLogger() << "========== Starting Verify Module =====================" << '\n'; bool res = true; - LogInfo::MapleLogger() << "========== Finished Verify Module =====================" << std::endl; + LogInfo::MapleLogger() << "========== Finished Verify Module =====================" << '\n'; return res; } -void DriverRunner::ProcessMpl2mplAndMePhases(std::string outputFile, std::string vtableImplFile) const { +void DriverRunner::ProcessMpl2mplAndMePhases(const std::string &outputFile, const std::string &vtableImplFile) const { CHECK_MODULE(); if (mpl2mplOptions || meOptions) { - LogInfo::MapleLogger() << "Processing mpl2mpl&mplme" << std::endl; + LogInfo::MapleLogger() << "Processing mpl2mpl&mplme" << '\n'; MPLTimer timer; timer.Start(); @@ -159,11 +152,11 @@ void DriverRunner::ProcessMpl2mplAndMePhases(std::string outputFile, std::string theModule->Emit(vtableImplFile); timer.Stop(); - LogInfo::MapleLogger() << "Mpl2mpl&mplme consumed " << timer.Elapsed() << "s" << std::endl; + LogInfo::MapleLogger() << "Mpl2mpl&mplme consumed " << timer.Elapsed() << "s" << '\n'; } } -void DriverRunner::InitPhases(InterleavedManager &mgr, std::vector &phases) const { +void DriverRunner::InitPhases(InterleavedManager &mgr, const std::vector &phases) const { if (phases.empty()) { return; } @@ -192,18 +185,19 @@ void DriverRunner::InitPhases(InterleavedManager &mgr, std::vector } } -void DriverRunner::AddPhases(InterleavedManager &mgr, std::vector &phases, +void DriverRunner::AddPhases(InterleavedManager &mgr, const std::vector &phases, const PhaseManager &phaseManager) const { - if (typeid(phaseManager) == typeid(ModulePhaseManager)) { + const std::type_info &type = typeid(phaseManager); + if (type == typeid(ModulePhaseManager)) { mgr.AddPhases(phases, true, timePhases); - } else if (typeid(phaseManager) == typeid(MeFuncPhaseManager)) { + } else if (type == typeid(MeFuncPhaseManager)) { mgr.AddPhases(phases, false, timePhases, genMemPl); } else { CHECK_FATAL(false, "Should not reach here, phases should be handled"); } } -void DriverRunner::AddPhase(std::vector &phases, std::string phase, +void DriverRunner::AddPhase(std::vector &phases, const std::string phase, const PhaseManager &phaseManager) const { if (typeid(phaseManager) == typeid(ModulePhaseManager)) { if (mpl2mplOptions && Options::skipPhase.compare(phase) != 0) { diff --git a/src/maple_driver/src/maple_comb_compiler.cpp b/src/maple_driver/src/maple_comb_compiler.cpp index b32730844c5b03ea12ec9d76509426860d29597f..a63b82e35766e3c21500fee4cd0ed99bd5ed14d3 100644 --- a/src/maple_driver/src/maple_comb_compiler.cpp +++ b/src/maple_driver/src/maple_comb_compiler.cpp @@ -240,31 +240,24 @@ ErrorCode MapleCombCompiler::Compile(const MplOptions &options, MIRModulePtr &th MemPool *optMp = mempoolctrler.NewMemPool("maplecomb mempool"); std::string fileName = GetInputFileName(options); theModule = new MIRModule(fileName); - MeOption *meOptions = nullptr; - Options *mpl2mplOptions = nullptr; + std::unique_ptr meOptions; + std::unique_ptr mpl2mplOptions; auto iterMe = std::find(options.runningExes.begin(), options.runningExes.end(), kBinNameMe); if (iterMe != options.runningExes.end()) { - meOptions = MakeMeOptions(options, *optMp); + meOptions.reset(MakeMeOptions(options, *optMp)); } auto iterMpl2Mpl = std::find(options.runningExes.begin(), options.runningExes.end(), kBinNameMpl2mpl); if (iterMpl2Mpl != options.runningExes.end()) { - mpl2mplOptions = MakeMpl2MplOptions(options, *optMp); + mpl2mplOptions.reset(MakeMpl2MplOptions(options, *optMp)); } LogInfo::MapleLogger() << "Starting mpl2mpl&mplme" << std::endl; PrintCommand(options); - DriverRunner runner(theModule, options.runningExes, mpl2mplOptions, fileName, meOptions, fileName, fileName, optMp, + DriverRunner runner(theModule, options.runningExes, mpl2mplOptions.get(), fileName, meOptions.get(), + fileName, fileName, optMp, options.timePhases, options.genMemPl); ErrorCode nErr = runner.Run(); - if (mpl2mplOptions != nullptr) { - delete mpl2mplOptions; - mpl2mplOptions = nullptr; - } - if (meOptions != nullptr) { - delete meOptions; - meOptions = nullptr; - } mempoolctrler.DeleteMemPool(optMp); return nErr; } diff --git a/src/maple_ipa/include/interleaved_manager.h b/src/maple_ipa/include/interleaved_manager.h index 887d0b48577e70af7ffdb9b35f65a651cf74b86f..5797e3b9b7424daf781e633bbd6e0c9a46911e90 100644 --- a/src/maple_ipa/include/interleaved_manager.h +++ b/src/maple_ipa/include/interleaved_manager.h @@ -50,7 +50,8 @@ class InterleavedManager { return allocator.GetMemPool(); } - void AddPhases(std::vector &phases, bool isModulePhase, bool timePhases = false, bool genMpl = false); + void AddPhases(const std::vector &phases, bool isModulePhase, bool timePhases = false, + bool genMpl = false); void AddIPAPhases(std::vector &phases, bool timePhases = false, bool genMpl = false); void Run(); void IPARun(MeFuncPhaseManager&); diff --git a/src/maple_ipa/include/module_phase_manager.h b/src/maple_ipa/include/module_phase_manager.h index 794891d699320bbdae230839c3868dfefd382d74..35eb2eb8176cdc2ee5d6e699cafd05524ce2c1ab 100644 --- a/src/maple_ipa/include/module_phase_manager.h +++ b/src/maple_ipa/include/module_phase_manager.h @@ -50,7 +50,7 @@ class ModulePhaseManager : public PhaseManager { // register all module phases defined in module_phases.def void RegisterModulePhases(); // Add module phases which are going to be run - void AddModulePhases(std::vector &phases); + void AddModulePhases(const std::vector &phases); void RunModulePhases() const; ModuleResultMgr *GetModResultMgr() override { return arModuleMgr; diff --git a/src/maple_ipa/src/interleaved_manager.cpp b/src/maple_ipa/src/interleaved_manager.cpp index 963de3278dd117489e2c5d72d3af84b13cec200b..39388e9031bc4c35e10e6c70c09c389ddb0794dd 100644 --- a/src/maple_ipa/src/interleaved_manager.cpp +++ b/src/maple_ipa/src/interleaved_manager.cpp @@ -28,7 +28,8 @@ using namespace maple; -void InterleavedManager::AddPhases(std::vector &phases, bool isModulePhase, bool timePhases, bool genMpl) { +void InterleavedManager::AddPhases(const std::vector &phases, bool isModulePhase, bool timePhases, + bool genMpl) { ModuleResultMgr *mrm = nullptr; if (!phaseManagers.empty()) { // ModuleResult such class hierarchy need to be carried on diff --git a/src/maple_ipa/src/module_phase_manager.cpp b/src/maple_ipa/src/module_phase_manager.cpp index 96f37fc26ad0dfcb53e8d89b656e7dfaf49e89df..ac2f772b990e88334c9220aa1cabd6b883253a1a 100644 --- a/src/maple_ipa/src/module_phase_manager.cpp +++ b/src/maple_ipa/src/module_phase_manager.cpp @@ -70,7 +70,7 @@ void ModulePhaseManager::RegisterModulePhases() { #undef MODTPHASE } -void ModulePhaseManager::AddModulePhases(std::vector &phases) { +void ModulePhaseManager::AddModulePhases(const std::vector &phases) { for (std::string const &phase : phases) { AddPhase(phase.c_str()); } diff --git a/src/maple_ir/include/metadata_layout.h b/src/maple_ir/include/metadata_layout.h index d02dd41a41e3c4e07f3e190c1536ec63c2d610b2..fde800e54389ccd2370c0871223d2e062a283965 100644 --- a/src/maple_ir/include/metadata_layout.h +++ b/src/maple_ir/include/metadata_layout.h @@ -109,83 +109,19 @@ enum DataRefFormat { kDataRefBitMask = 3, }; -template -struct BaseDataRef { - INT refVal; - - void* DecodeDataRef() const { - intptr_t ref = static_cast(refVal); - intptr_t format = refVal & kDataRefBitMask; - switch (format) { - case kDataRefIsDirect: return reinterpret_cast(ref); - case kDataRefIsOffset: { - ref += reinterpret_cast(this); - return reinterpret_cast(ref); - } - case kDataRefIsCompact: return reinterpret_cast(ref); // TODO - case kDataRefIsIndirect: { - ref += reinterpret_cast(this); - void **pRef = reinterpret_cast(ref); - return *pRef; - } - } - } -}; - // specialized for int32_t, check for out-of-boundary -struct DataRef32 : public BaseDataRef { - void EncodeDataRef(void* ref, DataRefFormat format) { - intptr_t val = reinterpret_cast(ref); - switch (format) { - case kDataRefIsDirect: { - if (INT32_MIN <= val && val <= INT32_MAX) { - refVal = static_cast(val); - return; - } else { - std::abort(); - } - } - case kDataRefIsOffset: { - intptr_t offset = val - reinterpret_cast(this); - if ((offset & kDataRefBitMask) == 0 && INT32_MIN <= refVal && refVal <= INT32_MAX) { - refVal = static_cast(offset) | kDataRefIsOffset; - return; - } else { - std::abort(); - } - } - case kDataRefIsCompact: - case kDataRefIsIndirect: { - std::abort(); - } - } - } +struct DataRef32 { + // be careful when *refVal* is treated as an offset which is a signed integer actually. + uint32_t refVal; + void *DecodeDataRef() const; + void EncodeDataRef(void* ref, DataRefFormat format = kDataRefIsDirect); }; // DataRef is meant to have pointer size. -struct DataRef : public BaseDataRef { - void EncodeDataRef(void* ref, DataRefFormat format) { - intptr_t val = reinterpret_cast(ref); - switch (format) { - case kDataRefIsDirect: { - refVal = val; - return; - } - case kDataRefIsOffset: { - intptr_t offset = val - reinterpret_cast(this); - if ((offset & kDataRefBitMask) == 0) { - refVal = offset | kDataRefIsOffset; - return; - } else { - std::abort(); - } - } - case kDataRefIsCompact: - case kDataRefIsIndirect: { - std::abort(); - } - } - } +struct DataRef { + void *refVal; + void *DecodeDataRef() const; + void EncodeDataRef(void *ref, DataRefFormat format = kDataRefIsDirect); }; // MethodMeta defined in MethodMeta.h @@ -228,10 +164,6 @@ struct ClassMetadataRO { int32_t clinitAddr; }; -struct DexFile; -struct DexClassDef; -struct DexClassData; - static constexpr size_t PageSize = 4096; // Note there is no state to indicate a class is already initialized. @@ -280,9 +212,9 @@ struct ClassMetadata { void *gctib; // for rc union { - ClassMetadataRO *classinforo64; // ifndef USE_32BIT_REF + DataRef classinforo64; // ifndef USE_32BIT_REF struct { - uint32_t classinforo32; // ifdef USE_32BIT_REF + DataRef32 classinforo32; // ifdef USE_32BIT_REF uint32_t cacheFalseClass; }; }; @@ -293,6 +225,11 @@ struct ClassMetadata { }; public: + static inline intptr_t OffsetOfInitState() { + ClassMetadata *base = nullptr; + return reinterpret_cast(&(base->initState)); + } + bool IsInitialized(); ClassInitState GetInitState(); @@ -306,11 +243,6 @@ struct ClassMetadata { } }; -static inline intptr_t ClassMetadataOffsetOfInitFlag() { - ClassMetadata *base = reinterpret_cast(0); - return reinterpret_cast(&(base->initState)); -} - // function to set Class/Field/Method metadata's shadow field to avoid type conversion // Note 1: here we don't do NULL-check and type-compatibility check // NOte 2: C should be of jclass/ClassMetata* type diff --git a/src/maple_ir/include/mir_symbol.h b/src/maple_ir/include/mir_symbol.h index 2900cbd469ab011dd6a69b9f8ad1ac4daf0f79df..14e1820594feaf0b7306d335151c4e1af259b0c7 100644 --- a/src/maple_ir/include/mir_symbol.h +++ b/src/maple_ir/include/mir_symbol.h @@ -21,6 +21,7 @@ constexpr int kScopeLocal = 2; // the default scope level for function variables constexpr int kScopeGlobal = 1; // the scope level for global variables + namespace maple { enum MIRSymKind { kStInvalid, @@ -85,7 +86,7 @@ class MIRSymbol { nameStrIdx(0), value({ nullptr }) { } - ~MIRSymbol() {} + ~MIRSymbol() = default; void SetIsTmp(bool temp) { isTmp = temp; @@ -404,7 +405,7 @@ class MIRSymbolTable { public: explicit MIRSymbolTable(MapleAllocator *allocator) : mAllocator(allocator), strIdxToStIdxMap(mAllocator->Adapter()), symbolTable(mAllocator->Adapter()) { - symbolTable.push_back(static_cast(nullptr)); + symbolTable.push_back(nullptr); } ~MIRSymbolTable() = default; @@ -429,6 +430,9 @@ class MIRSymbolTable { // add sym from other symbol table, happens in inline bool AddStOutside(MIRSymbol *sym) { + if (sym == nullptr) { + return false; + } sym->SetStIdx(StIdx(sym->GetScopeIdx(), symbolTable.size())); symbolTable.push_back(sym); return AddToStringSymbolMap(*sym); @@ -481,7 +485,7 @@ class MIRLabelTable { labelTable.push_back(GStrIdx(kDummyLabel)); // push dummy label index 0 } - ~MIRLabelTable() {} + ~MIRLabelTable() = default; LabelIdx CreateLabel() { LabelIdx labelIdx = labelTable.size(); diff --git a/src/maple_ir/src/mir_symbol.cpp b/src/maple_ir/src/mir_symbol.cpp index 469aa1c3f75db7d662d8dc445008a7d6a1fc0f31..a720be1841520916ad22ca6822b240a4e6711c42 100644 --- a/src/maple_ir/src/mir_symbol.cpp +++ b/src/maple_ir/src/mir_symbol.cpp @@ -312,6 +312,7 @@ void MIRSymbol::DumpAsLiteralVar(int32 indent) const { } } + void MIRSymbolTable::Dump(bool isLocal, int32 indent, bool printDeleted) const { size_t size = symbolTable.size(); for (size_t i = 0; i < size; i++) { diff --git a/src/maple_ir/src/mir_type.cpp b/src/maple_ir/src/mir_type.cpp index dc0a6f3d22e4dc6562646793925214e4ce50835f..eedf814c8a822fb0512345eb5d90017fc240fc17 100644 --- a/src/maple_ir/src/mir_type.cpp +++ b/src/maple_ir/src/mir_type.cpp @@ -1390,10 +1390,10 @@ TyIdxFieldAttrPair MIRPtrType::GetPointedTyIdxFldAttrPairWithFieldID(FieldID fie if (fieldID == 0) { return TyIdxFieldAttrPair(pointedTyIdx, FieldAttrs()); } - MIRStructType *structType = - dynamic_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointedTyIdx)); - ASSERT(structType != nullptr, - "MIRPtrType::GetPointedTyIdxWithFieldID(): cannot have non-zero fieldID for something other than a struct"); + MIRType *pointedType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointedTyIdx); + CHECK_FATAL(pointedType->IsStructType(), + "MIRPtrType::GetPointedTyIdxWithFieldID(): cannot have non-zero fieldID for something other than a struct"); + MIRStructType *structType = static_cast(pointedType); return structType->GetFieldTyIdxAttrPair(fieldID); } diff --git a/src/maple_me/include/me_function.h b/src/maple_me/include/me_function.h index d267ec48d6aefb52b1b2746b53ce06aadf75a1aa..a20e53706b5f4492d7cce3182968310c5fdb1d96 100644 --- a/src/maple_me/include/me_function.h +++ b/src/maple_me/include/me_function.h @@ -463,6 +463,7 @@ class MeFunction : public FuncEmit { MIRFunction *CurFunction(void) const { return mirModule.CurFunction(); } + void SplitBBPhysically(BB &bb, StmtNode &splitPoint, BB &newBB); MemPool *memPool; MapleAllocator alloc; diff --git a/src/maple_me/include/ver_symbol.h b/src/maple_me/include/ver_symbol.h index b557cba21da6d551cc7133cfa31c08a6c0fe0c80..f0129390e24b476183e08f64ec4e3d56e02f9faf 100644 --- a/src/maple_me/include/ver_symbol.h +++ b/src/maple_me/include/ver_symbol.h @@ -193,7 +193,9 @@ class VersionSt { class VersionStTable { public: - explicit VersionStTable(MemPool *vstMp) : vstAlloc(vstMp), versionStVector(vstAlloc.Adapter()) {} + explicit VersionStTable(MemPool *vstMp) : vstAlloc(vstMp), versionStVector(vstAlloc.Adapter()) { + versionStVector.push_back(&dummyVST); + } ~VersionStTable() = default; diff --git a/src/maple_me/src/me_function.cpp b/src/maple_me/src/me_function.cpp index b5cff5ecc5e3a168f6746a8f2453ac64882b5393..1b119302fcabaec24e75b76a125a663acba345cf 100644 --- a/src/maple_me/src/me_function.cpp +++ b/src/maple_me/src/me_function.cpp @@ -496,26 +496,31 @@ void MeFunction::CloneBasicBlock(BB &newBB, const BB &orig) { } } -/* Split BB at split_point */ -BB &MeFunction::SplitBB(BB &bb, StmtNode &splitPoint, BB *newBB) { - if (newBB == nullptr){ - newBB = memPool->New(&alloc, &versAlloc, BBId(nextBBId++)); - } +void MeFunction::SplitBBPhysically(BB &bb, StmtNode &splitPoint, BB &newBB) { + StmtNode *newBBStart = splitPoint.GetNext(); // Fix Stmt in BB. if (newBBStart != nullptr) { newBBStart->SetPrev(nullptr); for (StmtNode *stmt = newBBStart; stmt != nullptr;) { StmtNode *nextStmt = stmt->GetNext(); - newBB->AddStmtNode(stmt); + newBB.AddStmtNode(stmt); if (meSSATab != nullptr) { - meSSATab->CreateSSAStmt(*stmt, *newBB); + meSSATab->CreateSSAStmt(*stmt, newBB); } stmt = nextStmt; } } bb.SetLast(&splitPoint); splitPoint.SetNext(nullptr); +} + +/* Split BB at split_point */ +BB &MeFunction::SplitBB(BB &bb, StmtNode &splitPoint, BB *newBB) { + if (newBB == nullptr) { + newBB = memPool->New(&alloc, &versAlloc, BBId(nextBBId++)); + } + SplitBBPhysically(bb, splitPoint, *newBB); // Fix BB in CFG newBB->SetKind(bb.GetKind()); bb.SetKind(kBBFallthru);