Browse Source

Adapted generated code to support translation block linking

Eyck Jentzsch 1 year ago
parent
commit
dfcc3ace66

+ 59
- 2
.cproject View File

@@ -17,7 +17,7 @@
17 17
 					<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1751741082." name="/" resourcePath="">
18 18
 						<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1289745146" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
19 19
 							<targetPlatform binaryParser="org.eclipse.cdt.core.GNU_ELF;org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.exe.debug.1460698591" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
20
-							<builder buildPath="/DBT-RISE-RISCV/build/Debug" id="de.marw.cdt.cmake.core.genscriptbuilder.2135578907" keepEnvironmentInBuildfile="false" name="CMake Builder (portable)" parallelBuildOn="false" superClass="de.marw.cdt.cmake.core.genscriptbuilder"/>
20
+							<builder buildPath="/DBT-RISE-RISCV/build/Debug" id="de.marw.cdt.cmake.core.genscriptbuilder.2135578907" keepEnvironmentInBuildfile="false" name="CMake Builder (portable)" parallelBuildOn="true" parallelizationNumber="optimal" superClass="de.marw.cdt.cmake.core.genscriptbuilder"/>
21 21
 							<tool id="cdt.managedbuild.tool.gnu.archiver.base.366643800" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
22 22
 							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1510612390" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
23 23
 								<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.1768317780" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
@@ -70,7 +70,7 @@
70 70
 				</extensions>
71 71
 			</storageModule>
72 72
 			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
73
-				<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.1745230171" name="Release" optionalBuildProperties="" parent="cdt.managedbuild.config.gnu.exe.release">
73
+				<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.1745230171" name="Release" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=" parent="cdt.managedbuild.config.gnu.exe.release">
74 74
 					<folderInfo id="cdt.managedbuild.config.gnu.exe.release.1745230171." name="/" resourcePath="">
75 75
 						<toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.2006835092" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
76 76
 							<targetPlatform binaryParser="org.eclipse.cdt.core.GNU_ELF;org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.exe.release.1630517313" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
@@ -104,6 +104,57 @@
104 104
 			<storageModule buildDir="build/${ConfigName}" moduleId="de.marw.cdt.cmake.core.settings">
105 105
 				<options/>
106 106
 				<linux command="cmake" generator="UnixMakefiles" use-default="true">
107
+				</linux>
108
+				<win32 command="cmake" generator="MinGWMakefiles" use-default="true">
109
+				</win32>
110
+			</storageModule>
111
+		</cconfiguration>
112
+		<cconfiguration id="cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404">
113
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404" moduleId="org.eclipse.cdt.core.settings" name="RelWithDebInfo">
114
+				<externalSettings/>
115
+				<extensions>
116
+					<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
117
+					<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
118
+					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
119
+					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
120
+					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
121
+				</extensions>
122
+			</storageModule>
123
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
124
+				<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404" name="RelWithDebInfo" optionalBuildProperties="" parent="cdt.managedbuild.config.gnu.exe.release">
125
+					<folderInfo id="cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404." name="/" resourcePath="">
126
+						<toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.1502160352" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
127
+							<targetPlatform binaryParser="org.eclipse.cdt.core.GNU_ELF;org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.exe.release.689260696" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
128
+							<builder buildPath="/DBT-RISE-RISCV/build/Release" id="de.marw.cdt.cmake.core.genscriptbuilder.775458297" keepEnvironmentInBuildfile="false" name="CMake Builder (portable)" parallelBuildOn="true" parallelizationNumber="optimal" superClass="de.marw.cdt.cmake.core.genscriptbuilder"/>
129
+							<tool id="cdt.managedbuild.tool.gnu.archiver.base.1134372172" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
130
+							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1556984395" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
131
+								<option id="gnu.cpp.compiler.exe.release.option.optimization.level.1353963182" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
132
+								<option id="gnu.cpp.compiler.exe.release.option.debugging.level.1769987567" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
133
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.228859511" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
134
+							</tool>
135
+							<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.1020243188" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release">
136
+								<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.681548571" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
137
+								<option id="gnu.c.compiler.exe.release.option.debugging.level.987899513" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
138
+								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.693742822" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
139
+							</tool>
140
+							<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.1626150212" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/>
141
+							<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.1878716058" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release">
142
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.471741232" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
143
+									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
144
+									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
145
+								</inputType>
146
+							</tool>
147
+							<tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.1237246932" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release">
148
+								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1692363597" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
149
+							</tool>
150
+						</toolChain>
151
+					</folderInfo>
152
+				</configuration>
153
+			</storageModule>
154
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
155
+			<storageModule buildDir="build/${ConfigName}" moduleId="de.marw.cdt.cmake.core.settings">
156
+				<options/>
157
+				<linux command="cmake" generator="UnixMakefiles" use-default="true">
107 158
 					<defs/>
108 159
 					<undefs/>
109 160
 				</linux>
@@ -111,6 +162,9 @@
111 162
 					<defs/>
112 163
 					<undefs/>
113 164
 				</win32>
165
+				<defs>
166
+					<def name="CMAKE_BUILD_TYPE" type="STRING" val="RelWithDebInfo"/>
167
+				</defs>
114 168
 			</storageModule>
115 169
 		</cconfiguration>
116 170
 	</storageModule>
@@ -176,6 +230,9 @@
176 230
 	</storageModule>
177 231
 	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
178 232
 	<storageModule moduleId="refreshScope" versionNumber="2">
233
+		<configuration configurationName="RelWithDebInfo">
234
+			<resource resourceType="PROJECT" workspacePath="/DBT-RISE-RISCV"/>
235
+		</configuration>
179 236
 		<configuration configurationName="Default">
180 237
 			<resource resourceType="PROJECT" workspacePath="/DBT-RISE-RISCV"/>
181 238
 		</configuration>

+ 5
- 0
.settings/org.eclipse.cdt.core.prefs View File

@@ -1,6 +1,11 @@
1 1
 eclipse.preferences.version=1
2 2
 environment/project/cdt.managedbuild.config.gnu.exe.debug.1751741082/append=true
3 3
 environment/project/cdt.managedbuild.config.gnu.exe.debug.1751741082/appendContributed=true
4
+environment/project/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/LLVM_HOME/delimiter=\:
5
+environment/project/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/LLVM_HOME/operation=append
6
+environment/project/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/LLVM_HOME/value=/usr/lib/llvm-6.0
7
+environment/project/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/append=true
8
+environment/project/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/appendContributed=true
4 9
 environment/project/cdt.managedbuild.config.gnu.exe.release.1745230171/LLVM_HOME/delimiter=\:
5 10
 environment/project/cdt.managedbuild.config.gnu.exe.release.1745230171/LLVM_HOME/operation=append
6 11
 environment/project/cdt.managedbuild.config.gnu.exe.release.1745230171/LLVM_HOME/value=/usr/lib/llvm-6.0

+ 12
- 0
.settings/org.eclipse.cdt.managedbuilder.core.prefs View File

@@ -7,6 +7,14 @@ environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.175174
7 7
 environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.1751741082/C_INCLUDE_PATH/operation=remove
8 8
 environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.1751741082/append=true
9 9
 environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.1751741082/appendContributed=true
10
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/CPATH/delimiter=\:
11
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/CPATH/operation=remove
12
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/CPLUS_INCLUDE_PATH/delimiter=\:
13
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/CPLUS_INCLUDE_PATH/operation=remove
14
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/C_INCLUDE_PATH/delimiter=\:
15
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/C_INCLUDE_PATH/operation=remove
16
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/append=true
17
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/appendContributed=true
10 18
 environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171/CPATH/delimiter=\:
11 19
 environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171/CPATH/operation=remove
12 20
 environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1745230171/CPLUS_INCLUDE_PATH/delimiter=\:
@@ -19,6 +27,10 @@ environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.175174
19 27
 environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.1751741082/LIBRARY_PATH/operation=remove
20 28
 environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.1751741082/append=true
21 29
 environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.1751741082/appendContributed=true
30
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/LIBRARY_PATH/delimiter=\:
31
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/LIBRARY_PATH/operation=remove
32
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/append=true
33
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1745230171.1259602404/appendContributed=true
22 34
 environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1745230171/LIBRARY_PATH/delimiter=\:
23 35
 environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1745230171/LIBRARY_PATH/operation=remove
24 36
 environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1745230171/append=true

+ 1
- 1
CMakeLists.txt View File

@@ -26,7 +26,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
26 26
 	
27 27
 include(CheckCXXCompilerFlag)
28 28
 CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
29
-if(COMPILER_SUPPORTS_MARCH_NATIVE)
29
+if(NOT(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") AND COMPILER_SUPPORTS_MARCH_NATIVE)
30 30
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
31 31
 endif()
32 32
 

+ 1
- 1
dbt-core

@@ -1 +1 @@
1
-Subproject commit 23dbab0b768d122c492110d1db34408e9ae787f3
1
+Subproject commit b7e5fd5113ff8383668c4ad77b18b4370237f9f0

+ 87
- 0
etc/dbt-riscv dhrystone.launch View File

@@ -23,6 +23,7 @@
23 23
 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="DBT-RISE-RISCV"/>
24 24
 <booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
25 25
 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="cdt.managedbuild.config.gnu.exe.release.1745230171"/>
26
+<booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/>
26 27
 <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
27 28
 <listEntry value="/DBT-RISE-RISCV"/>
28 29
 </listAttribute>
@@ -30,5 +31,91 @@
30 31
 <listEntry value="4"/>
31 32
 </listAttribute>
32 33
 <stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;&#10;"/>
34
+<stringAttribute key="org.eclipse.linuxtools.callgraph.launch.ARGUMENTS" value=""/>
35
+<stringAttribute key="org.eclipse.linuxtools.callgraph.launch.BINARY_ARGUMENTS" value=""/>
36
+<stringAttribute key="org.eclipse.linuxtools.callgraph.launch.BINARY_PATH" value=""/>
37
+<intAttribute key="org.eclipse.linuxtools.callgraph.launch.BUFFER_BYTES" value="0"/>
38
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.BULK_MODE" value="false"/>
39
+<intAttribute key="org.eclipse.linuxtools.callgraph.launch.COMMAND_VERBOSE" value="0"/>
40
+<stringAttribute key="org.eclipse.linuxtools.callgraph.launch.C_DIRECTIVES" value=""/>
41
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.DISABLE_WARNINGS" value="false"/>
42
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.GURU" value="false"/>
43
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.IGNORE_DWARF" value="false"/>
44
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.KEEP_TEMPORARY" value="false"/>
45
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.LEAVE_RUNNING" value="false"/>
46
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.NO_CODE_ELISION" value="false"/>
47
+<stringAttribute key="org.eclipse.linuxtools.callgraph.launch.OUTPUT_PATH" value=""/>
48
+<stringAttribute key="org.eclipse.linuxtools.callgraph.launch.PARSER_CLASS" value=""/>
49
+<intAttribute key="org.eclipse.linuxtools.callgraph.launch.PASS" value="0"/>
50
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.PROLOGUE_SEARCH" value="false"/>
51
+<stringAttribute key="org.eclipse.linuxtools.callgraph.launch.SCRIPT_PATH" value=""/>
52
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.SKIP_BADVARS" value="false"/>
53
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.TAPSET_COVERAGE" value="false"/>
54
+<intAttribute key="org.eclipse.linuxtools.callgraph.launch.TARGET_PID" value="0"/>
55
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.TIMING_INFO" value="false"/>
56
+<booleanAttribute key="org.eclipse.linuxtools.callgraph.launch.USE_COLOUR" value="false"/>
57
+<stringAttribute key="org.eclipse.linuxtools.callgraph.launch.VIEW_CLASS" value=""/>
58
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.DefaultEvent" value="true"/>
59
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.HideUnresolvedSymbols" value="true"/>
60
+<stringAttribute key="org.eclipse.linuxtools.internal.perf.attr.Kernel.Location" value=""/>
61
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.Kernel.SourceLineNumbers" value="false"/>
62
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.ModuleSymbols" value="false"/>
63
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.MultipleEvents" value="false"/>
64
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.Record.Realtime" value="false"/>
65
+<intAttribute key="org.eclipse.linuxtools.internal.perf.attr.Record.Realtime.Priority" value="1"/>
66
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.Record.Verbose" value="false"/>
67
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.ShowSourceDisassembly" value="false"/>
68
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.ShowStat" value="false"/>
69
+<booleanAttribute key="org.eclipse.linuxtools.internal.perf.attr.SourceLineNumbers" value="true"/>
70
+<intAttribute key="org.eclipse.linuxtools.internal.perf.attr.StatRunCount" value="1"/>
71
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.BRANCH_SIM" value="false"/>
72
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.CACHE_SIM" value="true"/>
73
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.D1" value="false"/>
74
+<intAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.D1_ASSOC" value="0"/>
75
+<intAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.D1_LSIZE" value="0"/>
76
+<intAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.D1_SIZE" value="0"/>
77
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.I1" value="false"/>
78
+<intAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.I1_ASSOC" value="0"/>
79
+<intAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.I1_LSIZE" value="0"/>
80
+<intAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.I1_SIZE" value="0"/>
81
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.L2" value="false"/>
82
+<intAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.L2_ASSOC" value="0"/>
83
+<intAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.L2_LSIZE" value="0"/>
84
+<intAttribute key="org.eclipse.linuxtools.valgrind.cachegrind.L2_SIZE" value="0"/>
85
+<intAttribute key="org.eclipse.linuxtools.valgrind.helgrind.HELGRIND_CACHESIZE" value="1000000"/>
86
+<stringAttribute key="org.eclipse.linuxtools.valgrind.helgrind.HELGRIND_HISTORYLEVEL" value="full"/>
87
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.helgrind.HELGRIND_LOCKORDERS" value="true"/>
88
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.launch.FULLPATH_AFTER" value="true"/>
89
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_BELOWMAIN" value="false"/>
90
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_DEMANGLE" value="true"/>
91
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_DSYMUTIL" value="true"/>
92
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_ERRLIMIT" value="true"/>
93
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_FREERES" value="true"/>
94
+<intAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_MAINSTACK" value="0"/>
95
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_MAINSTACK_BOOL" value="false"/>
96
+<intAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_MAXFRAME" value="2000000"/>
97
+<intAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_NUMCALLERS" value="12"/>
98
+<stringAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_OTHER_OPTIONS" value=""/>
99
+<listAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_SUPPFILES"/>
100
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.launch.GENERAL_TRACECHILD" value="false"/>
101
+<stringAttribute key="org.eclipse.linuxtools.valgrind.launch.OUTPUT_DIR" value="/home/eyck/workspaces/cdt/.metadata/.plugins/org.eclipse.linuxtools.valgrind.launch"/>
102
+<stringAttribute key="org.eclipse.linuxtools.valgrind.launch.TOOL" value="org.eclipse.linuxtools.valgrind.launch.cachegrind"/>
103
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_ALIGNMENT_BOOL" value="false"/>
104
+<intAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_ALIGNMENT_VAL" value="0"/>
105
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_FREEFILL_BOOL" value="false"/>
106
+<stringAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_FREEFILL_VAL" value=""/>
107
+<intAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_FREELIST" value="10000000"/>
108
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_GCCWORK" value="false"/>
109
+<listAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_IGNORE_RANGES"/>
110
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_LEAKCHECK" value="true"/>
111
+<stringAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_LEAKRES" value="high"/>
112
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_MALLOCFILL_BOOL" value="false"/>
113
+<stringAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_MALLOCFILL_VAL" value=""/>
114
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_PARTIAL" value="false"/>
115
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_POSSIBLY_LOST" value="true"/>
116
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_SHOWREACH" value="false"/>
117
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_TRACKORIGINS" value="false"/>
118
+<booleanAttribute key="org.eclipse.linuxtools.valgrind.memcheck.MEMCHECK_UNDEF" value="true"/>
33 119
 <stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
120
+<stringAttribute key="provider" value="org.eclipse.linuxtools.profiling.provider.valgrind.cachegrind"/>
34 121
 </launchConfiguration>

+ 1
- 1
riscv.sc/src/sc_main.cpp View File

@@ -35,7 +35,6 @@
35 35
 ////////////////////////////////////////////////////////////////////////////////
36 36
 
37 37
 #include <boost/program_options.hpp>
38
-#include <iss/jit/MCJIThelper.h>
39 38
 #include <iss/log_categories.h>
40 39
 #include <sstream>
41 40
 #include <sysc/SiFive/platform.h>
@@ -44,6 +43,7 @@
44 43
 #include "scc/scv_tr_db.h"
45 44
 #include "scc/tracer.h"
46 45
 #include <cci_utils/broker.h>
46
+#include <iss/jit/jit_helper.h>
47 47
 
48 48
 using namespace sysc;
49 49
 namespace po = boost::program_options;

+ 5
- 1
riscv/gen_input/templates/incl-CORENAME.h.gtl View File

@@ -73,6 +73,7 @@ struct traits<${coreDef.name.toLowerCase()}> {
73 73
         TRAP_STATE,
74 74
         PENDING_TRAP,
75 75
         MACHINE_STATE,
76
+        LAST_BRANCH,
76 77
         ICOUNT
77 78
     };
78 79
 
@@ -140,6 +141,9 @@ struct ${coreDef.name.toLowerCase()}: public arch_if {
140 141
 
141 142
     virtual iss::sync_type needed_sync() const { return iss::NO_SYNC; }
142 143
 
144
+    inline
145
+    uint32_t get_last_branch(){return reg.last_branch;}
146
+
143 147
 protected:
144 148
     struct ${coreDef.name}_regs {<%
145 149
      	allRegs.each { reg -> 
@@ -152,7 +156,7 @@ protected:
152 156
             }
153 157
         }%>
154 158
         uint${generator.getSize(pc)}_t NEXT_${pc.name} = 0;
155
-        uint32_t trap_state = 0, pending_trap = 0, machine_state = 0;
159
+        uint32_t trap_state = 0, pending_trap = 0, machine_state = 0, last_branch = 0;
156 160
         uint64_t icount = 0;
157 161
     } reg;
158 162
 

+ 8
- 5
riscv/gen_input/templates/vm-vm_CORENAME.cpp.gtl View File

@@ -92,8 +92,7 @@ protected:
92 92
         vm::fp_impl::add_fp_functions_2_module(m, traits<ARCH>::FP_REGS_SIZE);
93 93
     }
94 94
 
95
-    inline llvm::Value *gen_choose(llvm::Value *cond, llvm::Value *trueVal, llvm::Value *falseVal,
96
-                                   unsigned size) const {
95
+    inline llvm::Value *gen_choose(llvm::Value *cond, llvm::Value *trueVal, llvm::Value *falseVal, unsigned size) {
97 96
         return super::gen_cond_assign(cond, this->gen_ext(trueVal, size), this->gen_ext(falseVal, size));
98 97
     }
99 98
 
@@ -266,7 +265,6 @@ vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt,
266 265
     }
267 266
     if (insn == 0x0000006f || (insn&0xffff)==0xa001) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
268 267
     // curr pc on stack
269
-    typename vm_impl<ARCH>::processing_pc_entry addr(*this, pc, paddr);
270 268
     ++inst_cnt;
271 269
     auto lut_val = extract_fields(insn);
272 270
     auto f = qlut[insn & 0x3][lut_val];
@@ -284,6 +282,7 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_behavior(llvm::BasicBlock
284 282
 template <typename ARCH> void vm_impl<ARCH>::gen_raise_trap(uint16_t trap_id, uint16_t cause) {
285 283
     auto *TRAP_val = this->gen_const(32, 0x80 << 24 | (cause << 16) | trap_id);
286 284
     this->builder.CreateStore(TRAP_val, get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
285
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
287 286
 }
288 287
 
289 288
 template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(unsigned lvl) {
@@ -293,6 +292,7 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(unsigned lvl) {
293 292
     this->builder.CreateCall(this->mod->getFunction("leave_trap"), args);
294 293
     auto *PC_val = this->gen_read_mem(traits<ARCH>::CSR, (lvl << 8) + 0x41, traits<ARCH>::XLEN / 8);
295 294
     this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
295
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
296 296
 }
297 297
 
298 298
 template <typename ARCH> void vm_impl<ARCH>::gen_wait(unsigned type) {
@@ -305,8 +305,11 @@ template <typename ARCH> void vm_impl<ARCH>::gen_wait(unsigned type) {
305 305
 template <typename ARCH> void vm_impl<ARCH>::gen_trap_behavior(llvm::BasicBlock *trap_blk) {
306 306
     this->builder.SetInsertPoint(trap_blk);
307 307
     auto *trap_state_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
308
-    std::vector<llvm::Value *> args{this->core_ptr, this->adj_to64(trap_state_val),
309
-                                    this->adj_to64(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::PC), false))};
308
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
309
+    std::vector<llvm::Value *> args{
310
+    	this->core_ptr,
311
+    	this->adj_to64(trap_state_val),
312
+        this->adj_to64(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::PC), false))};
310 313
     this->builder.CreateCall(this->mod->getFunction("enter_trap"), args);
311 314
     auto *trap_addr_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::NEXT_PC), false);
312 315
     this->builder.CreateRet(trap_addr_val);

+ 9
- 6
riscv/incl/iss/arch/riscv_hart_msu_vp.h View File

@@ -50,6 +50,9 @@
50 50
 #include <array>
51 51
 #include <type_traits>
52 52
 
53
+#define likely(x)       __builtin_expect(!!(x), 1)
54
+#define unlikely(x)     __builtin_expect(!!(x), 0)
55
+
53 56
 namespace iss {
54 57
 namespace arch {
55 58
 
@@ -647,14 +650,14 @@ iss::status riscv_hart_msu_vp<BASE>::read(const iss::addr_t &addr, unsigned leng
647 650
     try {
648 651
         switch (addr.space) {
649 652
         case traits<BASE>::MEM: {
650
-            if ((addr.access == iss::access_type::FETCH || addr.access == iss::access_type::DEBUG_FETCH) && (addr.val & 0x1) == 1) {
653
+            if (unlikely((addr.access == iss::access_type::FETCH || addr.access == iss::access_type::DEBUG_FETCH) && (addr.val & 0x1) == 1)) {
651 654
                 fault_data = addr.val;
652 655
                 if (addr.access && iss::access_type::DEBUG) throw trap_access(0, addr.val);
653 656
                 this->reg.trap_state = (1 << 31); // issue trap 0
654 657
                 return iss::Err;
655 658
             }
656 659
             try {
657
-                if ((addr.val & ~PGMASK) != ((addr.val + length - 1) & ~PGMASK)) { // we may cross a page boundary
660
+                if (unlikely((addr.val & ~PGMASK) != ((addr.val + length - 1) & ~PGMASK))) { // we may cross a page boundary
658 661
                     vm_info vm = hart_state<reg_t>::decode_vm_info(this->reg.machine_state, state.satp);
659 662
                     if (vm.levels != 0) { // VM is active
660 663
                         auto split_addr = (addr.val + length) & ~PGMASK;
@@ -666,7 +669,7 @@ iss::status riscv_hart_msu_vp<BASE>::read(const iss::addr_t &addr, unsigned leng
666 669
                     }
667 670
                 }
668 671
                 auto res = read_mem( BASE::v2p(addr), length, data);
669
-                if (res != iss::Ok) this->reg.trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault
672
+                if (unlikely(res != iss::Ok)) this->reg.trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault
670 673
                 return res;
671 674
             } catch (trap_access &ta) {
672 675
                 this->reg.trap_state = (1 << 31) | ta.id;
@@ -738,14 +741,14 @@ iss::status riscv_hart_msu_vp<BASE>::write(const iss::addr_t &addr, unsigned len
738 741
     try {
739 742
         switch (addr.space) {
740 743
         case traits<BASE>::MEM: {
741
-            if ((addr.access && iss::access_type::FETCH) && (addr.val & 0x1) == 1) {
744
+            if (unlikely((addr.access && iss::access_type::FETCH) && (addr.val & 0x1) == 1)) {
742 745
                 fault_data = addr.val;
743 746
                 if (addr.access && iss::access_type::DEBUG) throw trap_access(0, addr.val);
744 747
                 this->reg.trap_state = (1 << 31); // issue trap 0
745 748
                 return iss::Err;
746 749
             }
747 750
             try {
748
-                if ((addr.val & ~PGMASK) != ((addr.val + length - 1) & ~PGMASK)) { // we may cross a page boundary
751
+                if (unlikely((addr.val & ~PGMASK) != ((addr.val + length - 1) & ~PGMASK))) { // we may cross a page boundary
749 752
                     vm_info vm = hart_state<reg_t>::decode_vm_info(this->reg.machine_state, state.satp);
750 753
                     if (vm.levels != 0) { // VM is active
751 754
                         auto split_addr = (addr.val + length) & ~PGMASK;
@@ -757,7 +760,7 @@ iss::status riscv_hart_msu_vp<BASE>::write(const iss::addr_t &addr, unsigned len
757 760
                     }
758 761
                 }
759 762
                 auto res = write_mem(BASE::v2p(addr), length, data);
760
-                if (res != iss::Ok) this->reg.trap_state = (1 << 31) | (5 << 16); // issue trap 7 (Store/AMO access fault)
763
+                if (unlikely(res != iss::Ok)) this->reg.trap_state = (1 << 31) | (5 << 16); // issue trap 7 (Store/AMO access fault)
761 764
                 return res;
762 765
             } catch (trap_access &ta) {
763 766
                 this->reg.trap_state = (1 << 31) | ta.id;

+ 7
- 3
riscv/incl/iss/arch/rv32gc.h View File

@@ -124,6 +124,7 @@ struct traits<rv32gc> {
124 124
         TRAP_STATE,
125 125
         PENDING_TRAP,
126 126
         MACHINE_STATE,
127
+        LAST_BRANCH,
127 128
         ICOUNT
128 129
     };
129 130
 
@@ -138,12 +139,12 @@ struct traits<rv32gc> {
138 139
     using phys_addr_t = iss::typed_addr_t<iss::address_type::PHYSICAL>;
139 140
 
140 141
     constexpr static unsigned reg_bit_width(unsigned r) {
141
-        constexpr std::array<const uint32_t, 71> RV32GC_reg_size{{32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,32,32,32,32,32,64}};
142
+        constexpr std::array<const uint32_t, 72> RV32GC_reg_size{{32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,32,32,32,32,32,32,64}};
142 143
         return RV32GC_reg_size[r];
143 144
     }
144 145
 
145 146
     constexpr static unsigned reg_byte_offset(unsigned r) {
146
-    	constexpr std::array<const uint32_t, 72> RV32GC_reg_byte_offset{{0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,256,264,272,280,288,296,304,312,320,328,336,344,352,360,368,376,384,392,396,400,404,408,416,424}};
147
+    	constexpr std::array<const uint32_t, 73> RV32GC_reg_byte_offset{{0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,256,264,272,280,288,296,304,312,320,328,336,344,352,360,368,376,384,392,396,400,404,408,412,416,424}};
147 148
         return RV32GC_reg_byte_offset[r];
148 149
     }
149 150
 
@@ -191,6 +192,9 @@ struct rv32gc: public arch_if {
191 192
 
192 193
     virtual iss::sync_type needed_sync() const { return iss::NO_SYNC; }
193 194
 
195
+    inline
196
+    uint32_t get_last_branch(){return reg.last_branch;}
197
+
194 198
 protected:
195 199
     struct RV32GC_regs {
196 200
         uint32_t X0 = 0;
@@ -260,7 +264,7 @@ protected:
260 264
         uint64_t F31 = 0;
261 265
         uint32_t FCSR = 0;
262 266
         uint32_t NEXT_PC = 0;
263
-        uint32_t trap_state = 0, pending_trap = 0, machine_state = 0;
267
+        uint32_t trap_state = 0, pending_trap = 0, machine_state = 0, last_branch = 0;
264 268
         uint64_t icount = 0;
265 269
     } reg;
266 270
 

+ 7
- 3
riscv/incl/iss/arch/rv32imac.h View File

@@ -91,6 +91,7 @@ struct traits<rv32imac> {
91 91
         TRAP_STATE,
92 92
         PENDING_TRAP,
93 93
         MACHINE_STATE,
94
+        LAST_BRANCH,
94 95
         ICOUNT
95 96
     };
96 97
 
@@ -105,12 +106,12 @@ struct traits<rv32imac> {
105 106
     using phys_addr_t = iss::typed_addr_t<iss::address_type::PHYSICAL>;
106 107
 
107 108
     constexpr static unsigned reg_bit_width(unsigned r) {
108
-        constexpr std::array<const uint32_t, 38> RV32IMAC_reg_size{{32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,64}};
109
+        constexpr std::array<const uint32_t, 39> RV32IMAC_reg_size{{32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,64}};
109 110
         return RV32IMAC_reg_size[r];
110 111
     }
111 112
 
112 113
     constexpr static unsigned reg_byte_offset(unsigned r) {
113
-    	constexpr std::array<const uint32_t, 39> RV32IMAC_reg_byte_offset{{0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,152,160}};
114
+    	constexpr std::array<const uint32_t, 40> RV32IMAC_reg_byte_offset{{0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,160}};
114 115
         return RV32IMAC_reg_byte_offset[r];
115 116
     }
116 117
 
@@ -158,6 +159,9 @@ struct rv32imac: public arch_if {
158 159
 
159 160
     virtual iss::sync_type needed_sync() const { return iss::NO_SYNC; }
160 161
 
162
+    inline
163
+    uint32_t get_last_branch(){return reg.last_branch;}
164
+
161 165
 protected:
162 166
     struct RV32IMAC_regs {
163 167
         uint32_t X0 = 0;
@@ -194,7 +198,7 @@ protected:
194 198
         uint32_t X31 = 0;
195 199
         uint32_t PC = 0;
196 200
         uint32_t NEXT_PC = 0;
197
-        uint32_t trap_state = 0, pending_trap = 0, machine_state = 0;
201
+        uint32_t trap_state = 0, pending_trap = 0, machine_state = 0, last_branch = 0;
198 202
         uint64_t icount = 0;
199 203
     } reg;
200 204
 

+ 7
- 3
riscv/incl/iss/arch/rv64ia.h View File

@@ -91,6 +91,7 @@ struct traits<rv64ia> {
91 91
         TRAP_STATE,
92 92
         PENDING_TRAP,
93 93
         MACHINE_STATE,
94
+        LAST_BRANCH,
94 95
         ICOUNT
95 96
     };
96 97
 
@@ -105,12 +106,12 @@ struct traits<rv64ia> {
105 106
     using phys_addr_t = iss::typed_addr_t<iss::address_type::PHYSICAL>;
106 107
 
107 108
     constexpr static unsigned reg_bit_width(unsigned r) {
108
-        constexpr std::array<const uint32_t, 38> RV64IA_reg_size{{64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,32,32,32,64}};
109
+        constexpr std::array<const uint32_t, 39> RV64IA_reg_size{{64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,32,32,32,32,64}};
109 110
         return RV64IA_reg_size[r];
110 111
     }
111 112
 
112 113
     constexpr static unsigned reg_byte_offset(unsigned r) {
113
-    	constexpr std::array<const uint32_t, 39> RV64IA_reg_byte_offset{{0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,256,264,272,276,280,288,296}};
114
+    	constexpr std::array<const uint32_t, 40> RV64IA_reg_byte_offset{{0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,256,264,272,276,280,284,288,296}};
114 115
         return RV64IA_reg_byte_offset[r];
115 116
     }
116 117
 
@@ -158,6 +159,9 @@ struct rv64ia: public arch_if {
158 159
 
159 160
     virtual iss::sync_type needed_sync() const { return iss::NO_SYNC; }
160 161
 
162
+    inline
163
+    uint32_t get_last_branch(){return reg.last_branch;}
164
+
161 165
 protected:
162 166
     struct RV64IA_regs {
163 167
         uint64_t X0 = 0;
@@ -194,7 +198,7 @@ protected:
194 198
         uint64_t X31 = 0;
195 199
         uint64_t PC = 0;
196 200
         uint64_t NEXT_PC = 0;
197
-        uint32_t trap_state = 0, pending_trap = 0, machine_state = 0;
201
+        uint32_t trap_state = 0, pending_trap = 0, machine_state = 0, last_branch = 0;
198 202
         uint64_t icount = 0;
199 203
     } reg;
200 204
 

+ 76
- 47
riscv/src/internal/vm_rv32gc.cpp View File

@@ -92,8 +92,7 @@ protected:
92 92
         vm::fp_impl::add_fp_functions_2_module(m, traits<ARCH>::FP_REGS_SIZE);
93 93
     }
94 94
 
95
-    inline llvm::Value *gen_choose(llvm::Value *cond, llvm::Value *trueVal, llvm::Value *falseVal,
96
-                                   unsigned size) const {
95
+    inline llvm::Value *gen_choose(llvm::Value *cond, llvm::Value *trueVal, llvm::Value *falseVal, unsigned size) {
97 96
         return super::gen_cond_assign(cond, this->gen_ext(trueVal, size), this->gen_ext(falseVal, size));
98 97
     }
99 98
 
@@ -619,6 +618,8 @@ private:
619 618
     	        32, true),
620 619
     	    this->gen_const(32U, fld_imm_val));
621 620
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
621
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
622
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
622 623
     	this->gen_sync(iss::POST_SYNC, 2);
623 624
     	this->gen_trap_check(this->leave_blk);
624 625
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -664,7 +665,7 @@ private:
664 665
     	    this->gen_cond_branch(this->builder.CreateICmp(
665 666
     	        ICmpInst::ICMP_NE,
666 667
     	        align_val,
667
-    	        this->gen_const(64U, 0)),
668
+    	        this->gen_const(32U, 0)),
668 669
     	        bb_then,
669 670
     	        bb_else);
670 671
     	    this->builder.SetInsertPoint(bb_then);
@@ -684,6 +685,7 @@ private:
684 685
     	            new_pc_val,
685 686
     	            this->builder.CreateNot(this->gen_const(32U, 0x1)));
686 687
     	        this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
688
+    	        this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
687 689
     	    }
688 690
     	    this->builder.CreateBr(bbnext);
689 691
     	    bb=bbnext;
@@ -733,6 +735,8 @@ private:
733 735
     	        this->gen_const(32U, 4)),
734 736
     	    32);
735 737
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
738
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
739
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
736 740
     	this->gen_sync(iss::POST_SYNC, 4);
737 741
     	this->gen_trap_check(this->leave_blk);
738 742
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -777,6 +781,8 @@ private:
777 781
     	        this->gen_const(32U, 4)),
778 782
     	    32);
779 783
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
784
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
785
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
780 786
     	this->gen_sync(iss::POST_SYNC, 5);
781 787
     	this->gen_trap_check(this->leave_blk);
782 788
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -825,6 +831,8 @@ private:
825 831
     	        this->gen_const(32U, 4)),
826 832
     	    32);
827 833
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
834
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
835
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
828 836
     	this->gen_sync(iss::POST_SYNC, 6);
829 837
     	this->gen_trap_check(this->leave_blk);
830 838
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -873,6 +881,8 @@ private:
873 881
     	        this->gen_const(32U, 4)),
874 882
     	    32);
875 883
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
884
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
885
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
876 886
     	this->gen_sync(iss::POST_SYNC, 7);
877 887
     	this->gen_trap_check(this->leave_blk);
878 888
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -917,6 +927,8 @@ private:
917 927
     	        this->gen_const(32U, 4)),
918 928
     	    32);
919 929
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
930
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
931
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
920 932
     	this->gen_sync(iss::POST_SYNC, 8);
921 933
     	this->gen_trap_check(this->leave_blk);
922 934
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -961,6 +973,8 @@ private:
961 973
     	        this->gen_const(32U, 4)),
962 974
     	    32);
963 975
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
976
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
977
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
964 978
     	this->gen_sync(iss::POST_SYNC, 9);
965 979
     	this->gen_trap_check(this->leave_blk);
966 980
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -2126,6 +2140,7 @@ private:
2126 2140
     	    traits<ARCH>::FENCE,
2127 2141
     	    this->gen_const(64U, 1),
2128 2142
     	    this->builder.CreateZExtOrTrunc(FENCEtmp0_val,this->get_type(32)));
2143
+    	this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
2129 2144
     	this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
2130 2145
     	this->gen_sync(iss::POST_SYNC, 38);
2131 2146
     	this->gen_trap_check(this->leave_blk);
@@ -2834,7 +2849,7 @@ private:
2834 2849
     	        this->gen_cond_branch(this->builder.CreateICmp(
2835 2850
     	            ICmpInst::ICMP_NE,
2836 2851
     	            this->gen_reg_load(fld_rs2_val + traits<ARCH>::X0, 0),
2837
-    	            this->gen_const(64U, 0)),
2852
+    	            this->gen_const(32U, 0)),
2838 2853
     	            bb_then,
2839 2854
     	            bb_else);
2840 2855
     	        this->builder.SetInsertPoint(bb_then);
@@ -2963,7 +2978,7 @@ private:
2963 2978
     	        this->gen_cond_branch(this->builder.CreateICmp(
2964 2979
     	            ICmpInst::ICMP_NE,
2965 2980
     	            this->gen_reg_load(fld_rs2_val + traits<ARCH>::X0, 0),
2966
-    	            this->gen_const(64U, 0)),
2981
+    	            this->gen_const(32U, 0)),
2967 2982
     	            bb_then,
2968 2983
     	            bb_else);
2969 2984
     	        this->builder.SetInsertPoint(bb_then);
@@ -3030,7 +3045,7 @@ private:
3030 3045
     	        this->gen_cond_branch(this->builder.CreateICmp(
3031 3046
     	            ICmpInst::ICMP_NE,
3032 3047
     	            this->gen_reg_load(fld_rs2_val + traits<ARCH>::X0, 0),
3033
-    	            this->gen_const(64U, 0)),
3048
+    	            this->gen_const(32U, 0)),
3034 3049
     	            bb_then,
3035 3050
     	            bb_else);
3036 3051
     	        this->builder.SetInsertPoint(bb_then);
@@ -3163,7 +3178,7 @@ private:
3163 3178
     	        this->gen_cond_branch(this->builder.CreateICmp(
3164 3179
     	            ICmpInst::ICMP_NE,
3165 3180
     	            this->gen_reg_load(fld_rs2_val + traits<ARCH>::X0, 0),
3166
-    	            this->gen_const(64U, 0)),
3181
+    	            this->gen_const(32U, 0)),
3167 3182
     	            bb_then,
3168 3183
     	            bb_else);
3169 3184
     	        this->builder.SetInsertPoint(bb_then);
@@ -3280,7 +3295,7 @@ private:
3280 3295
     	    this->gen_cond_branch(this->builder.CreateICmp(
3281 3296
     	        ICmpInst::ICMP_NE,
3282 3297
     	        res1_val,
3283
-    	        this->gen_const(64U, 0)),
3298
+    	        this->gen_const(32U, 0)),
3284 3299
     	        bb_then,
3285 3300
     	        bbnext);
3286 3301
     	    this->builder.SetInsertPoint(bb_then);
@@ -3995,6 +4010,8 @@ private:
3995 4010
     	        32, true),
3996 4011
     	    this->gen_const(32U, fld_imm_val));
3997 4012
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4013
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
4014
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
3998 4015
     	this->gen_sync(iss::POST_SYNC, 76);
3999 4016
     	this->gen_trap_check(this->leave_blk);
4000 4017
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4381,6 +4398,8 @@ private:
4381 4398
     	        32, true),
4382 4399
     	    this->gen_const(32U, fld_imm_val));
4383 4400
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4401
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
4402
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4384 4403
     	this->gen_sync(iss::POST_SYNC, 87);
4385 4404
     	this->gen_trap_check(this->leave_blk);
4386 4405
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4424,6 +4443,8 @@ private:
4424 4443
     	        this->gen_const(32U, 2)),
4425 4444
     	    32);
4426 4445
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4446
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
4447
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4427 4448
     	this->gen_sync(iss::POST_SYNC, 88);
4428 4449
     	this->gen_trap_check(this->leave_blk);
4429 4450
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4467,6 +4488,8 @@ private:
4467 4488
     	        this->gen_const(32U, 2)),
4468 4489
     	    32);
4469 4490
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4491
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
4492
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4470 4493
     	this->gen_sync(iss::POST_SYNC, 89);
4471 4494
     	this->gen_trap_check(this->leave_blk);
4472 4495
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4600,6 +4623,7 @@ private:
4600 4623
     	
4601 4624
     	Value* PC_val = this->gen_reg_load(fld_rs1_val + traits<ARCH>::X0, 0);
4602 4625
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4626
+    	this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4603 4627
     	this->gen_sync(iss::POST_SYNC, 93);
4604 4628
     	this->gen_trap_check(this->leave_blk);
4605 4629
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4667,6 +4691,7 @@ private:
4667 4691
     	this->builder.CreateStore(Xtmp0_val, get_reg_ptr(1 + traits<ARCH>::X0), false);
4668 4692
     	Value* PC_val = this->gen_reg_load(fld_rs1_val + traits<ARCH>::X0, 0);
4669 4693
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4694
+    	this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4670 4695
     	this->gen_sync(iss::POST_SYNC, 95);
4671 4696
     	this->gen_trap_check(this->leave_blk);
4672 4697
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4906,8 +4931,8 @@ private:
4906 4931
     	    this->gen_choose(
4907 4932
     	        this->builder.CreateICmp(
4908 4933
     	            ICmpInst::ICMP_ULT,
4909
-    	            this->gen_const(64U, fld_rm_val),
4910
-    	            this->gen_const(64U, 7)),
4934
+    	            this->gen_const(8U, fld_rm_val),
4935
+    	            this->gen_const(8U, 7)),
4911 4936
     	        this->gen_const(8U, fld_rm_val),
4912 4937
     	        this->builder.CreateTrunc(
4913 4938
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -4991,8 +5016,8 @@ private:
4991 5016
     	    this->gen_choose(
4992 5017
     	        this->builder.CreateICmp(
4993 5018
     	            ICmpInst::ICMP_ULT,
4994
-    	            this->gen_const(64U, fld_rm_val),
4995
-    	            this->gen_const(64U, 7)),
5019
+    	            this->gen_const(8U, fld_rm_val),
5020
+    	            this->gen_const(8U, 7)),
4996 5021
     	        this->gen_const(8U, fld_rm_val),
4997 5022
     	        this->builder.CreateTrunc(
4998 5023
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -5076,8 +5101,8 @@ private:
5076 5101
     	    this->gen_choose(
5077 5102
     	        this->builder.CreateICmp(
5078 5103
     	            ICmpInst::ICMP_ULT,
5079
-    	            this->gen_const(64U, fld_rm_val),
5080
-    	            this->gen_const(64U, 7)),
5104
+    	            this->gen_const(8U, fld_rm_val),
5105
+    	            this->gen_const(8U, 7)),
5081 5106
     	        this->gen_const(8U, fld_rm_val),
5082 5107
     	        this->builder.CreateTrunc(
5083 5108
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -5161,8 +5186,8 @@ private:
5161 5186
     	    this->gen_choose(
5162 5187
     	        this->builder.CreateICmp(
5163 5188
     	            ICmpInst::ICMP_ULT,
5164
-    	            this->gen_const(64U, fld_rm_val),
5165
-    	            this->gen_const(64U, 7)),
5189
+    	            this->gen_const(8U, fld_rm_val),
5190
+    	            this->gen_const(8U, 7)),
5166 5191
     	        this->gen_const(8U, fld_rm_val),
5167 5192
     	        this->builder.CreateTrunc(
5168 5193
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -5237,8 +5262,8 @@ private:
5237 5262
     	    this->gen_choose(
5238 5263
     	        this->builder.CreateICmp(
5239 5264
     	            ICmpInst::ICMP_ULT,
5240
-    	            this->gen_const(64U, fld_rm_val),
5241
-    	            this->gen_const(64U, 7)),
5265
+    	            this->gen_const(8U, fld_rm_val),
5266
+    	            this->gen_const(8U, 7)),
5242 5267
     	        this->gen_const(8U, fld_rm_val),
5243 5268
     	        this->builder.CreateTrunc(
5244 5269
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -5313,8 +5338,8 @@ private:
5313 5338
     	    this->gen_choose(
5314 5339
     	        this->builder.CreateICmp(
5315 5340
     	            ICmpInst::ICMP_ULT,
5316
-    	            this->gen_const(64U, fld_rm_val),
5317
-    	            this->gen_const(64U, 7)),
5341
+    	            this->gen_const(8U, fld_rm_val),
5342
+    	            this->gen_const(8U, 7)),
5318 5343
     	        this->gen_const(8U, fld_rm_val),
5319 5344
     	        this->builder.CreateTrunc(
5320 5345
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -5389,8 +5414,8 @@ private:
5389 5414
     	    this->gen_choose(
5390 5415
     	        this->builder.CreateICmp(
5391 5416
     	            ICmpInst::ICMP_ULT,
5392
-    	            this->gen_const(64U, fld_rm_val),
5393
-    	            this->gen_const(64U, 7)),
5417
+    	            this->gen_const(8U, fld_rm_val),
5418
+    	            this->gen_const(8U, 7)),
5394 5419
     	        this->gen_const(8U, fld_rm_val),
5395 5420
     	        this->builder.CreateTrunc(
5396 5421
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -5465,8 +5490,8 @@ private:
5465 5490
     	    this->gen_choose(
5466 5491
     	        this->builder.CreateICmp(
5467 5492
     	            ICmpInst::ICMP_ULT,
5468
-    	            this->gen_const(64U, fld_rm_val),
5469
-    	            this->gen_const(64U, 7)),
5493
+    	            this->gen_const(8U, fld_rm_val),
5494
+    	            this->gen_const(8U, 7)),
5470 5495
     	        this->gen_const(8U, fld_rm_val),
5471 5496
     	        this->builder.CreateTrunc(
5472 5497
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -5536,8 +5561,8 @@ private:
5536 5561
     	    this->gen_choose(
5537 5562
     	        this->builder.CreateICmp(
5538 5563
     	            ICmpInst::ICMP_ULT,
5539
-    	            this->gen_const(64U, fld_rm_val),
5540
-    	            this->gen_const(64U, 7)),
5564
+    	            this->gen_const(8U, fld_rm_val),
5565
+    	            this->gen_const(8U, 7)),
5541 5566
     	        this->gen_const(8U, fld_rm_val),
5542 5567
     	        this->builder.CreateTrunc(
5543 5568
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -6711,8 +6736,8 @@ private:
6711 6736
     	    this->gen_choose(
6712 6737
     	        this->builder.CreateICmp(
6713 6738
     	            ICmpInst::ICMP_ULT,
6714
-    	            this->gen_const(64U, fld_rm_val),
6715
-    	            this->gen_const(64U, 7)),
6739
+    	            this->gen_const(8U, fld_rm_val),
6740
+    	            this->gen_const(8U, 7)),
6716 6741
     	        this->gen_const(8U, fld_rm_val),
6717 6742
     	        this->builder.CreateTrunc(
6718 6743
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -6793,8 +6818,8 @@ private:
6793 6818
     	    this->gen_choose(
6794 6819
     	        this->builder.CreateICmp(
6795 6820
     	            ICmpInst::ICMP_ULT,
6796
-    	            this->gen_const(64U, fld_rm_val),
6797
-    	            this->gen_const(64U, 7)),
6821
+    	            this->gen_const(8U, fld_rm_val),
6822
+    	            this->gen_const(8U, 7)),
6798 6823
     	        this->gen_const(8U, fld_rm_val),
6799 6824
     	        this->builder.CreateTrunc(
6800 6825
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -6875,8 +6900,8 @@ private:
6875 6900
     	    this->gen_choose(
6876 6901
     	        this->builder.CreateICmp(
6877 6902
     	            ICmpInst::ICMP_ULT,
6878
-    	            this->gen_const(64U, fld_rm_val),
6879
-    	            this->gen_const(64U, 7)),
6903
+    	            this->gen_const(8U, fld_rm_val),
6904
+    	            this->gen_const(8U, 7)),
6880 6905
     	        this->gen_const(8U, fld_rm_val),
6881 6906
     	        this->builder.CreateTrunc(
6882 6907
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -6957,8 +6982,8 @@ private:
6957 6982
     	    this->gen_choose(
6958 6983
     	        this->builder.CreateICmp(
6959 6984
     	            ICmpInst::ICMP_ULT,
6960
-    	            this->gen_const(64U, fld_rm_val),
6961
-    	            this->gen_const(64U, 7)),
6985
+    	            this->gen_const(8U, fld_rm_val),
6986
+    	            this->gen_const(8U, 7)),
6962 6987
     	        this->gen_const(8U, fld_rm_val),
6963 6988
     	        this->builder.CreateTrunc(
6964 6989
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -7030,8 +7055,8 @@ private:
7030 7055
     	    this->gen_choose(
7031 7056
     	        this->builder.CreateICmp(
7032 7057
     	            ICmpInst::ICMP_ULT,
7033
-    	            this->gen_const(64U, fld_rm_val),
7034
-    	            this->gen_const(64U, 7)),
7058
+    	            this->gen_const(8U, fld_rm_val),
7059
+    	            this->gen_const(8U, 7)),
7035 7060
     	        this->gen_const(8U, fld_rm_val),
7036 7061
     	        this->builder.CreateTrunc(
7037 7062
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -7103,8 +7128,8 @@ private:
7103 7128
     	    this->gen_choose(
7104 7129
     	        this->builder.CreateICmp(
7105 7130
     	            ICmpInst::ICMP_ULT,
7106
-    	            this->gen_const(64U, fld_rm_val),
7107
-    	            this->gen_const(64U, 7)),
7131
+    	            this->gen_const(8U, fld_rm_val),
7132
+    	            this->gen_const(8U, 7)),
7108 7133
     	        this->gen_const(8U, fld_rm_val),
7109 7134
     	        this->builder.CreateTrunc(
7110 7135
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -7176,8 +7201,8 @@ private:
7176 7201
     	    this->gen_choose(
7177 7202
     	        this->builder.CreateICmp(
7178 7203
     	            ICmpInst::ICMP_ULT,
7179
-    	            this->gen_const(64U, fld_rm_val),
7180
-    	            this->gen_const(64U, 7)),
7204
+    	            this->gen_const(8U, fld_rm_val),
7205
+    	            this->gen_const(8U, 7)),
7181 7206
     	        this->gen_const(8U, fld_rm_val),
7182 7207
     	        this->builder.CreateTrunc(
7183 7208
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -7249,8 +7274,8 @@ private:
7249 7274
     	    this->gen_choose(
7250 7275
     	        this->builder.CreateICmp(
7251 7276
     	            ICmpInst::ICMP_ULT,
7252
-    	            this->gen_const(64U, fld_rm_val),
7253
-    	            this->gen_const(64U, 7)),
7277
+    	            this->gen_const(8U, fld_rm_val),
7278
+    	            this->gen_const(8U, 7)),
7254 7279
     	        this->gen_const(8U, fld_rm_val),
7255 7280
     	        this->builder.CreateTrunc(
7256 7281
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -7317,8 +7342,8 @@ private:
7317 7342
     	    this->gen_choose(
7318 7343
     	        this->builder.CreateICmp(
7319 7344
     	            ICmpInst::ICMP_ULT,
7320
-    	            this->gen_const(64U, fld_rm_val),
7321
-    	            this->gen_const(64U, 7)),
7345
+    	            this->gen_const(8U, fld_rm_val),
7346
+    	            this->gen_const(8U, 7)),
7322 7347
     	        this->gen_const(8U, fld_rm_val),
7323 7348
     	        this->builder.CreateTrunc(
7324 7349
     	            this->gen_reg_load(traits<ARCH>::FCSR, 0),
@@ -8403,7 +8428,6 @@ vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt,
8403 8428
     }
8404 8429
     if (insn == 0x0000006f || (insn&0xffff)==0xa001) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
8405 8430
     // curr pc on stack
8406
-    typename vm_impl<ARCH>::processing_pc_entry addr(*this, pc, paddr);
8407 8431
     ++inst_cnt;
8408 8432
     auto lut_val = extract_fields(insn);
8409 8433
     auto f = qlut[insn & 0x3][lut_val];
@@ -8421,6 +8445,7 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_behavior(llvm::BasicBlock
8421 8445
 template <typename ARCH> void vm_impl<ARCH>::gen_raise_trap(uint16_t trap_id, uint16_t cause) {
8422 8446
     auto *TRAP_val = this->gen_const(32, 0x80 << 24 | (cause << 16) | trap_id);
8423 8447
     this->builder.CreateStore(TRAP_val, get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
8448
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
8424 8449
 }
8425 8450
 
8426 8451
 template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(unsigned lvl) {
@@ -8430,6 +8455,7 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(unsigned lvl) {
8430 8455
     this->builder.CreateCall(this->mod->getFunction("leave_trap"), args);
8431 8456
     auto *PC_val = this->gen_read_mem(traits<ARCH>::CSR, (lvl << 8) + 0x41, traits<ARCH>::XLEN / 8);
8432 8457
     this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
8458
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
8433 8459
 }
8434 8460
 
8435 8461
 template <typename ARCH> void vm_impl<ARCH>::gen_wait(unsigned type) {
@@ -8442,8 +8468,11 @@ template <typename ARCH> void vm_impl<ARCH>::gen_wait(unsigned type) {
8442 8468
 template <typename ARCH> void vm_impl<ARCH>::gen_trap_behavior(llvm::BasicBlock *trap_blk) {
8443 8469
     this->builder.SetInsertPoint(trap_blk);
8444 8470
     auto *trap_state_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
8445
-    std::vector<llvm::Value *> args{this->core_ptr, this->adj_to64(trap_state_val),
8446
-                                    this->adj_to64(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::PC), false))};
8471
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
8472
+    std::vector<llvm::Value *> args{
8473
+    	this->core_ptr,
8474
+    	this->adj_to64(trap_state_val),
8475
+        this->adj_to64(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::PC), false))};
8447 8476
     this->builder.CreateCall(this->mod->getFunction("enter_trap"), args);
8448 8477
     auto *trap_addr_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::NEXT_PC), false);
8449 8478
     this->builder.CreateRet(trap_addr_val);

+ 40
- 11
riscv/src/internal/vm_rv32imac.cpp View File

@@ -92,8 +92,7 @@ protected:
92 92
         vm::fp_impl::add_fp_functions_2_module(m, traits<ARCH>::FP_REGS_SIZE);
93 93
     }
94 94
 
95
-    inline llvm::Value *gen_choose(llvm::Value *cond, llvm::Value *trueVal, llvm::Value *falseVal,
96
-                                   unsigned size) const {
95
+    inline llvm::Value *gen_choose(llvm::Value *cond, llvm::Value *trueVal, llvm::Value *falseVal, unsigned size) {
97 96
         return super::gen_cond_assign(cond, this->gen_ext(trueVal, size), this->gen_ext(falseVal, size));
98 97
     }
99 98
 
@@ -499,6 +498,8 @@ private:
499 498
     	        32, true),
500 499
     	    this->gen_const(32U, fld_imm_val));
501 500
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
501
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
502
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
502 503
     	this->gen_sync(iss::POST_SYNC, 2);
503 504
     	this->gen_trap_check(this->leave_blk);
504 505
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -544,7 +545,7 @@ private:
544 545
     	    this->gen_cond_branch(this->builder.CreateICmp(
545 546
     	        ICmpInst::ICMP_NE,
546 547
     	        align_val,
547
-    	        this->gen_const(64U, 0)),
548
+    	        this->gen_const(32U, 0)),
548 549
     	        bb_then,
549 550
     	        bb_else);
550 551
     	    this->builder.SetInsertPoint(bb_then);
@@ -564,6 +565,7 @@ private:
564 565
     	            new_pc_val,
565 566
     	            this->builder.CreateNot(this->gen_const(32U, 0x1)));
566 567
     	        this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
568
+    	        this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
567 569
     	    }
568 570
     	    this->builder.CreateBr(bbnext);
569 571
     	    bb=bbnext;
@@ -613,6 +615,8 @@ private:
613 615
     	        this->gen_const(32U, 4)),
614 616
     	    32);
615 617
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
618
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
619
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
616 620
     	this->gen_sync(iss::POST_SYNC, 4);
617 621
     	this->gen_trap_check(this->leave_blk);
618 622
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -657,6 +661,8 @@ private:
657 661
     	        this->gen_const(32U, 4)),
658 662
     	    32);
659 663
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
664
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
665
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
660 666
     	this->gen_sync(iss::POST_SYNC, 5);
661 667
     	this->gen_trap_check(this->leave_blk);
662 668
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -705,6 +711,8 @@ private:
705 711
     	        this->gen_const(32U, 4)),
706 712
     	    32);
707 713
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
714
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
715
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
708 716
     	this->gen_sync(iss::POST_SYNC, 6);
709 717
     	this->gen_trap_check(this->leave_blk);
710 718
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -753,6 +761,8 @@ private:
753 761
     	        this->gen_const(32U, 4)),
754 762
     	    32);
755 763
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
764
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
765
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
756 766
     	this->gen_sync(iss::POST_SYNC, 7);
757 767
     	this->gen_trap_check(this->leave_blk);
758 768
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -797,6 +807,8 @@ private:
797 807
     	        this->gen_const(32U, 4)),
798 808
     	    32);
799 809
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
810
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
811
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
800 812
     	this->gen_sync(iss::POST_SYNC, 8);
801 813
     	this->gen_trap_check(this->leave_blk);
802 814
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -841,6 +853,8 @@ private:
841 853
     	        this->gen_const(32U, 4)),
842 854
     	    32);
843 855
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
856
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
857
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
844 858
     	this->gen_sync(iss::POST_SYNC, 9);
845 859
     	this->gen_trap_check(this->leave_blk);
846 860
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -2006,6 +2020,7 @@ private:
2006 2020
     	    traits<ARCH>::FENCE,
2007 2021
     	    this->gen_const(64U, 1),
2008 2022
     	    this->builder.CreateZExtOrTrunc(FENCEtmp0_val,this->get_type(32)));
2023
+    	this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
2009 2024
     	this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
2010 2025
     	this->gen_sync(iss::POST_SYNC, 38);
2011 2026
     	this->gen_trap_check(this->leave_blk);
@@ -2714,7 +2729,7 @@ private:
2714 2729
     	        this->gen_cond_branch(this->builder.CreateICmp(
2715 2730
     	            ICmpInst::ICMP_NE,
2716 2731
     	            this->gen_reg_load(fld_rs2_val + traits<ARCH>::X0, 0),
2717
-    	            this->gen_const(64U, 0)),
2732
+    	            this->gen_const(32U, 0)),
2718 2733
     	            bb_then,
2719 2734
     	            bb_else);
2720 2735
     	        this->builder.SetInsertPoint(bb_then);
@@ -2843,7 +2858,7 @@ private:
2843 2858
     	        this->gen_cond_branch(this->builder.CreateICmp(
2844 2859
     	            ICmpInst::ICMP_NE,
2845 2860
     	            this->gen_reg_load(fld_rs2_val + traits<ARCH>::X0, 0),
2846
-    	            this->gen_const(64U, 0)),
2861
+    	            this->gen_const(32U, 0)),
2847 2862
     	            bb_then,
2848 2863
     	            bb_else);
2849 2864
     	        this->builder.SetInsertPoint(bb_then);
@@ -2910,7 +2925,7 @@ private:
2910 2925
     	        this->gen_cond_branch(this->builder.CreateICmp(
2911 2926
     	            ICmpInst::ICMP_NE,
2912 2927
     	            this->gen_reg_load(fld_rs2_val + traits<ARCH>::X0, 0),
2913
-    	            this->gen_const(64U, 0)),
2928
+    	            this->gen_const(32U, 0)),
2914 2929
     	            bb_then,
2915 2930
     	            bb_else);
2916 2931
     	        this->builder.SetInsertPoint(bb_then);
@@ -3043,7 +3058,7 @@ private:
3043 3058
     	        this->gen_cond_branch(this->builder.CreateICmp(
3044 3059
     	            ICmpInst::ICMP_NE,
3045 3060
     	            this->gen_reg_load(fld_rs2_val + traits<ARCH>::X0, 0),
3046
-    	            this->gen_const(64U, 0)),
3061
+    	            this->gen_const(32U, 0)),
3047 3062
     	            bb_then,
3048 3063
     	            bb_else);
3049 3064
     	        this->builder.SetInsertPoint(bb_then);
@@ -3160,7 +3175,7 @@ private:
3160 3175
     	    this->gen_cond_branch(this->builder.CreateICmp(
3161 3176
     	        ICmpInst::ICMP_NE,
3162 3177
     	        res1_val,
3163
-    	        this->gen_const(64U, 0)),
3178
+    	        this->gen_const(32U, 0)),
3164 3179
     	        bb_then,
3165 3180
     	        bbnext);
3166 3181
     	    this->builder.SetInsertPoint(bb_then);
@@ -3875,6 +3890,8 @@ private:
3875 3890
     	        32, true),
3876 3891
     	    this->gen_const(32U, fld_imm_val));
3877 3892
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
3893
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
3894
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
3878 3895
     	this->gen_sync(iss::POST_SYNC, 76);
3879 3896
     	this->gen_trap_check(this->leave_blk);
3880 3897
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4261,6 +4278,8 @@ private:
4261 4278
     	        32, true),
4262 4279
     	    this->gen_const(32U, fld_imm_val));
4263 4280
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4281
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
4282
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4264 4283
     	this->gen_sync(iss::POST_SYNC, 87);
4265 4284
     	this->gen_trap_check(this->leave_blk);
4266 4285
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4304,6 +4323,8 @@ private:
4304 4323
     	        this->gen_const(32U, 2)),
4305 4324
     	    32);
4306 4325
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4326
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
4327
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4307 4328
     	this->gen_sync(iss::POST_SYNC, 88);
4308 4329
     	this->gen_trap_check(this->leave_blk);
4309 4330
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4347,6 +4368,8 @@ private:
4347 4368
     	        this->gen_const(32U, 2)),
4348 4369
     	    32);
4349 4370
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4371
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
4372
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4350 4373
     	this->gen_sync(iss::POST_SYNC, 89);
4351 4374
     	this->gen_trap_check(this->leave_blk);
4352 4375
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4480,6 +4503,7 @@ private:
4480 4503
     	
4481 4504
     	Value* PC_val = this->gen_reg_load(fld_rs1_val + traits<ARCH>::X0, 0);
4482 4505
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4506
+    	this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4483 4507
     	this->gen_sync(iss::POST_SYNC, 93);
4484 4508
     	this->gen_trap_check(this->leave_blk);
4485 4509
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4547,6 +4571,7 @@ private:
4547 4571
     	this->builder.CreateStore(Xtmp0_val, get_reg_ptr(1 + traits<ARCH>::X0), false);
4548 4572
     	Value* PC_val = this->gen_reg_load(fld_rs1_val + traits<ARCH>::X0, 0);
4549 4573
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4574
+    	this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4550 4575
     	this->gen_sync(iss::POST_SYNC, 95);
4551 4576
     	this->gen_trap_check(this->leave_blk);
4552 4577
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -4709,7 +4734,6 @@ vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt,
4709 4734
     }
4710 4735
     if (insn == 0x0000006f || (insn&0xffff)==0xa001) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
4711 4736
     // curr pc on stack
4712
-    typename vm_impl<ARCH>::processing_pc_entry addr(*this, pc, paddr);
4713 4737
     ++inst_cnt;
4714 4738
     auto lut_val = extract_fields(insn);
4715 4739
     auto f = qlut[insn & 0x3][lut_val];
@@ -4727,6 +4751,7 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_behavior(llvm::BasicBlock
4727 4751
 template <typename ARCH> void vm_impl<ARCH>::gen_raise_trap(uint16_t trap_id, uint16_t cause) {
4728 4752
     auto *TRAP_val = this->gen_const(32, 0x80 << 24 | (cause << 16) | trap_id);
4729 4753
     this->builder.CreateStore(TRAP_val, get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
4754
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4730 4755
 }
4731 4756
 
4732 4757
 template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(unsigned lvl) {
@@ -4736,6 +4761,7 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(unsigned lvl) {
4736 4761
     this->builder.CreateCall(this->mod->getFunction("leave_trap"), args);
4737 4762
     auto *PC_val = this->gen_read_mem(traits<ARCH>::CSR, (lvl << 8) + 0x41, traits<ARCH>::XLEN / 8);
4738 4763
     this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4764
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4739 4765
 }
4740 4766
 
4741 4767
 template <typename ARCH> void vm_impl<ARCH>::gen_wait(unsigned type) {
@@ -4748,8 +4774,11 @@ template <typename ARCH> void vm_impl<ARCH>::gen_wait(unsigned type) {
4748 4774
 template <typename ARCH> void vm_impl<ARCH>::gen_trap_behavior(llvm::BasicBlock *trap_blk) {
4749 4775
     this->builder.SetInsertPoint(trap_blk);
4750 4776
     auto *trap_state_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
4751
-    std::vector<llvm::Value *> args{this->core_ptr, this->adj_to64(trap_state_val),
4752
-                                    this->adj_to64(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::PC), false))};
4777
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4778
+    std::vector<llvm::Value *> args{
4779
+    	this->core_ptr,
4780
+    	this->adj_to64(trap_state_val),
4781
+        this->adj_to64(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::PC), false))};
4753 4782
     this->builder.CreateCall(this->mod->getFunction("enter_trap"), args);
4754 4783
     auto *trap_addr_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4755 4784
     this->builder.CreateRet(trap_addr_val);

+ 25
- 6
riscv/src/internal/vm_rv64ia.cpp View File

@@ -92,8 +92,7 @@ protected:
92 92
         vm::fp_impl::add_fp_functions_2_module(m, traits<ARCH>::FP_REGS_SIZE);
93 93
     }
94 94
 
95
-    inline llvm::Value *gen_choose(llvm::Value *cond, llvm::Value *trueVal, llvm::Value *falseVal,
96
-                                   unsigned size) const {
95
+    inline llvm::Value *gen_choose(llvm::Value *cond, llvm::Value *trueVal, llvm::Value *falseVal, unsigned size) {
97 96
         return super::gen_cond_assign(cond, this->gen_ext(trueVal, size), this->gen_ext(falseVal, size));
98 97
     }
99 98
 
@@ -1144,6 +1143,8 @@ private:
1144 1143
     	        64, true),
1145 1144
     	    this->gen_const(64U, fld_imm_val));
1146 1145
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
1146
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(64U, pc.val), "is_cont_v");
1147
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
1147 1148
     	this->gen_sync(iss::POST_SYNC, 17);
1148 1149
     	this->gen_trap_check(this->leave_blk);
1149 1150
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -1209,6 +1210,7 @@ private:
1209 1210
     	            new_pc_val,
1210 1211
     	            this->builder.CreateNot(this->gen_const(64U, 0x1)));
1211 1212
     	        this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
1213
+    	        this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
1212 1214
     	    }
1213 1215
     	    this->builder.CreateBr(bbnext);
1214 1216
     	    bb=bbnext;
@@ -1258,6 +1260,8 @@ private:
1258 1260
     	        this->gen_const(64U, 4)),
1259 1261
     	    64);
1260 1262
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
1263
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(64U, pc.val), "is_cont_v");
1264
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
1261 1265
     	this->gen_sync(iss::POST_SYNC, 19);
1262 1266
     	this->gen_trap_check(this->leave_blk);
1263 1267
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -1302,6 +1306,8 @@ private:
1302 1306
     	        this->gen_const(64U, 4)),
1303 1307
     	    64);
1304 1308
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
1309
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(64U, pc.val), "is_cont_v");
1310
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
1305 1311
     	this->gen_sync(iss::POST_SYNC, 20);
1306 1312
     	this->gen_trap_check(this->leave_blk);
1307 1313
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -1350,6 +1356,8 @@ private:
1350 1356
     	        this->gen_const(64U, 4)),
1351 1357
     	    64);
1352 1358
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
1359
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(64U, pc.val), "is_cont_v");
1360
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
1353 1361
     	this->gen_sync(iss::POST_SYNC, 21);
1354 1362
     	this->gen_trap_check(this->leave_blk);
1355 1363
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -1398,6 +1406,8 @@ private:
1398 1406
     	        this->gen_const(64U, 4)),
1399 1407
     	    64);
1400 1408
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
1409
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(64U, pc.val), "is_cont_v");
1410
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
1401 1411
     	this->gen_sync(iss::POST_SYNC, 22);
1402 1412
     	this->gen_trap_check(this->leave_blk);
1403 1413
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -1442,6 +1452,8 @@ private:
1442 1452
     	        this->gen_const(64U, 4)),
1443 1453
     	    64);
1444 1454
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
1455
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(64U, pc.val), "is_cont_v");
1456
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
1445 1457
     	this->gen_sync(iss::POST_SYNC, 23);
1446 1458
     	this->gen_trap_check(this->leave_blk);
1447 1459
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -1486,6 +1498,8 @@ private:
1486 1498
     	        this->gen_const(64U, 4)),
1487 1499
     	    64);
1488 1500
     	this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
1501
+    	Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(64U, pc.val), "is_cont_v");
1502
+    	this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false),	get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
1489 1503
     	this->gen_sync(iss::POST_SYNC, 24);
1490 1504
     	this->gen_trap_check(this->leave_blk);
1491 1505
     	return std::make_tuple(iss::vm::BRANCH, nullptr);
@@ -2528,6 +2542,7 @@ private:
2528 2542
     	    traits<ARCH>::FENCE,
2529 2543
     	    this->gen_const(64U, 1),
2530 2544
     	    this->builder.CreateZExtOrTrunc(FENCEtmp0_val,this->get_type(64)));
2545
+    	this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
2531 2546
     	this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
2532 2547
     	this->gen_sync(iss::POST_SYNC, 50);
2533 2548
     	this->gen_trap_check(this->leave_blk);
@@ -3683,7 +3698,7 @@ private:
3683 3698
     	    this->gen_cond_branch(this->builder.CreateICmp(
3684 3699
     	        ICmpInst::ICMP_NE,
3685 3700
     	        res1_val,
3686
-    	        this->gen_const(64U, 0)),
3701
+    	        this->gen_const(32U, 0)),
3687 3702
     	        bb_then,
3688 3703
     	        bbnext);
3689 3704
     	    this->builder.SetInsertPoint(bb_then);
@@ -4255,7 +4270,6 @@ vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt,
4255 4270
     }
4256 4271
     if (insn == 0x0000006f || (insn&0xffff)==0xa001) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
4257 4272
     // curr pc on stack
4258
-    typename vm_impl<ARCH>::processing_pc_entry addr(*this, pc, paddr);
4259 4273
     ++inst_cnt;
4260 4274
     auto lut_val = extract_fields(insn);
4261 4275
     auto f = qlut[insn & 0x3][lut_val];
@@ -4273,6 +4287,7 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_behavior(llvm::BasicBlock
4273 4287
 template <typename ARCH> void vm_impl<ARCH>::gen_raise_trap(uint16_t trap_id, uint16_t cause) {
4274 4288
     auto *TRAP_val = this->gen_const(32, 0x80 << 24 | (cause << 16) | trap_id);
4275 4289
     this->builder.CreateStore(TRAP_val, get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
4290
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4276 4291
 }
4277 4292
 
4278 4293
 template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(unsigned lvl) {
@@ -4282,6 +4297,7 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(unsigned lvl) {
4282 4297
     this->builder.CreateCall(this->mod->getFunction("leave_trap"), args);
4283 4298
     auto *PC_val = this->gen_read_mem(traits<ARCH>::CSR, (lvl << 8) + 0x41, traits<ARCH>::XLEN / 8);
4284 4299
     this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4300
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4285 4301
 }
4286 4302
 
4287 4303
 template <typename ARCH> void vm_impl<ARCH>::gen_wait(unsigned type) {
@@ -4294,8 +4310,11 @@ template <typename ARCH> void vm_impl<ARCH>::gen_wait(unsigned type) {
4294 4310
 template <typename ARCH> void vm_impl<ARCH>::gen_trap_behavior(llvm::BasicBlock *trap_blk) {
4295 4311
     this->builder.SetInsertPoint(trap_blk);
4296 4312
     auto *trap_state_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
4297
-    std::vector<llvm::Value *> args{this->core_ptr, this->adj_to64(trap_state_val),
4298
-                                    this->adj_to64(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::PC), false))};
4313
+    this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
4314
+    std::vector<llvm::Value *> args{
4315
+    	this->core_ptr,
4316
+    	this->adj_to64(trap_state_val),
4317
+        this->adj_to64(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::PC), false))};
4299 4318
     this->builder.CreateCall(this->mod->getFunction("enter_trap"), args);
4300 4319
     auto *trap_addr_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::NEXT_PC), false);
4301 4320
     this->builder.CreateRet(trap_addr_val);

+ 3
- 3
riscv/src/main.cpp View File

@@ -41,7 +41,7 @@
41 41
 #include <iss/arch/rv32imac.h>
42 42
 #include <iss/arch/rv32gc.h>
43 43
 #include <iss/arch/rv64ia.h>
44
-#include <iss/jit/MCJIThelper.h>
44
+#include <iss/jit/jit_helper.h>
45 45
 #include <iss/log_categories.h>
46 46
 #include <iss/plugin/instruction_count.h>
47 47
 #include <iss/plugin/cycle_estimate.h>
@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
61 61
         ("logfile,f", po::value<std::string>(), "Sets default log file.")
62 62
         ("disass,d", po::value<std::string>()->implicit_value(""), "Enables disassembly")
63 63
         ("gdb-port,g", po::value<unsigned>()->default_value(0), "enable gdb server and specify port to use")
64
-        ("instructions,i", po::value<int64_t>()->default_value(-1), "max. number of instructions to simulate")
64
+        ("instructions,i", po::value<uint64_t>()->default_value(std::numeric_limits<uint64_t>::max()), "max. number of instructions to simulate")
65 65
         ("reset,r", po::value<std::string>(), "reset address")
66 66
         ("dump-ir", "dump the intermediate representation")
67 67
         ("elf", po::value<std::vector<std::string>>(), "ELF file(s) to load")
@@ -176,7 +176,7 @@ int main(int argc, char *argv[]) {
176 176
             start_address = str.find("0x") == 0 ? std::stoull(str.substr(2), 0, 16) : std::stoull(str, 0, 10);
177 177
         }
178 178
 		vm->reset(start_address);
179
-        auto cycles = clim["instructions"].as<int64_t>();
179
+        auto cycles = clim["instructions"].as<uint64_t>();
180 180
         res = vm->start(cycles, dump);
181 181
     } catch (std::exception &e) {
182 182
         LOG(ERROR) << "Unhandled Exception reached the top of main: " << e.what() << ", application will now exit" << std::endl;