|
1 | 1 | #include "LLVMWrapper.h"
|
| 2 | + |
| 3 | +#include "llvm-c/Core.h" |
| 4 | +#include "llvm/ADT/ArrayRef.h" |
| 5 | +#include "llvm/ADT/SmallVector.h" |
2 | 6 | #include "llvm/ADT/Statistic.h"
|
| 7 | +#include "llvm/ADT/StringRef.h" |
| 8 | +#include "llvm/BinaryFormat/Magic.h" |
3 | 9 | #include "llvm/Bitcode/BitcodeWriter.h"
|
| 10 | +#include "llvm/IR/DIBuilder.h" |
4 | 11 | #include "llvm/IR/DebugInfoMetadata.h"
|
5 | 12 | #include "llvm/IR/DiagnosticHandler.h"
|
6 | 13 | #include "llvm/IR/DiagnosticInfo.h"
|
7 | 14 | #include "llvm/IR/DiagnosticPrinter.h"
|
8 | 15 | #include "llvm/IR/GlobalVariable.h"
|
| 16 | +#include "llvm/IR/IRBuilder.h" |
| 17 | +#include "llvm/IR/InlineAsm.h" |
9 | 18 | #include "llvm/IR/Instructions.h"
|
10 |
| -#include "llvm/IR/Intrinsics.h" |
11 | 19 | #include "llvm/IR/IntrinsicsARM.h"
|
| 20 | +#include "llvm/IR/LLVMContext.h" |
12 | 21 | #include "llvm/IR/LLVMRemarkStreamer.h"
|
13 | 22 | #include "llvm/IR/Mangler.h"
|
| 23 | +#include "llvm/IR/Module.h" |
14 | 24 | #include "llvm/IR/Value.h"
|
15 |
| -#include "llvm/Object/Archive.h" |
16 | 25 | #include "llvm/Object/COFFImportFile.h"
|
17 |
| -#include "llvm/Object/ObjectFile.h" |
18 |
| -#include "llvm/Pass.h" |
19 | 26 | #include "llvm/Remarks/RemarkFormat.h"
|
20 | 27 | #include "llvm/Remarks/RemarkSerializer.h"
|
21 | 28 | #include "llvm/Remarks/RemarkStreamer.h"
|
| 29 | +#include "llvm/Support/Compression.h" |
| 30 | +#include "llvm/Support/FileSystem.h" |
| 31 | +#include "llvm/Support/JSON.h" |
22 | 32 | #include "llvm/Support/ModRef.h"
|
23 | 33 | #include "llvm/Support/Signals.h"
|
| 34 | +#include "llvm/Support/Timer.h" |
24 | 35 | #include "llvm/Support/ToolOutputFile.h"
|
25 |
| - |
26 | 36 | #include <iostream>
|
27 | 37 |
|
28 | 38 | // for raw `write` in the bad-alloc handler
|
@@ -216,94 +226,140 @@ extern "C" LLVMValueRef LLVMRustInsertPrivateGlobal(LLVMModuleRef M,
|
216 | 226 | GlobalValue::PrivateLinkage, nullptr));
|
217 | 227 | }
|
218 | 228 |
|
219 |
| -static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) { |
| 229 | +// Must match the layout of `rustc_codegen_llvm::llvm::ffi::AttributeKind`. |
| 230 | +enum class LLVMRustAttributeKind { |
| 231 | + AlwaysInline = 0, |
| 232 | + ByVal = 1, |
| 233 | + Cold = 2, |
| 234 | + InlineHint = 3, |
| 235 | + MinSize = 4, |
| 236 | + Naked = 5, |
| 237 | + NoAlias = 6, |
| 238 | + NoCapture = 7, |
| 239 | + NoInline = 8, |
| 240 | + NonNull = 9, |
| 241 | + NoRedZone = 10, |
| 242 | + NoReturn = 11, |
| 243 | + NoUnwind = 12, |
| 244 | + OptimizeForSize = 13, |
| 245 | + ReadOnly = 14, |
| 246 | + SExt = 15, |
| 247 | + StructRet = 16, |
| 248 | + UWTable = 17, |
| 249 | + ZExt = 18, |
| 250 | + InReg = 19, |
| 251 | + SanitizeThread = 20, |
| 252 | + SanitizeAddress = 21, |
| 253 | + SanitizeMemory = 22, |
| 254 | + NonLazyBind = 23, |
| 255 | + OptimizeNone = 24, |
| 256 | + ReadNone = 26, |
| 257 | + SanitizeHWAddress = 28, |
| 258 | + WillReturn = 29, |
| 259 | + StackProtectReq = 30, |
| 260 | + StackProtectStrong = 31, |
| 261 | + StackProtect = 32, |
| 262 | + NoUndef = 33, |
| 263 | + SanitizeMemTag = 34, |
| 264 | + NoCfCheck = 35, |
| 265 | + ShadowCallStack = 36, |
| 266 | + AllocSize = 37, |
| 267 | + AllocatedPointer = 38, |
| 268 | + AllocAlign = 39, |
| 269 | + SanitizeSafeStack = 40, |
| 270 | + FnRetThunkExtern = 41, |
| 271 | + Writable = 42, |
| 272 | + DeadOnUnwind = 43, |
| 273 | +}; |
| 274 | + |
| 275 | +static Attribute::AttrKind fromRust(LLVMRustAttributeKind Kind) { |
220 | 276 | switch (Kind) {
|
221 |
| - case AlwaysInline: |
| 277 | + case LLVMRustAttributeKind::AlwaysInline: |
222 | 278 | return Attribute::AlwaysInline;
|
223 |
| - case ByVal: |
| 279 | + case LLVMRustAttributeKind::ByVal: |
224 | 280 | return Attribute::ByVal;
|
225 |
| - case Cold: |
| 281 | + case LLVMRustAttributeKind::Cold: |
226 | 282 | return Attribute::Cold;
|
227 |
| - case InlineHint: |
| 283 | + case LLVMRustAttributeKind::InlineHint: |
228 | 284 | return Attribute::InlineHint;
|
229 |
| - case MinSize: |
| 285 | + case LLVMRustAttributeKind::MinSize: |
230 | 286 | return Attribute::MinSize;
|
231 |
| - case Naked: |
| 287 | + case LLVMRustAttributeKind::Naked: |
232 | 288 | return Attribute::Naked;
|
233 |
| - case NoAlias: |
| 289 | + case LLVMRustAttributeKind::NoAlias: |
234 | 290 | return Attribute::NoAlias;
|
235 |
| - case NoCapture: |
| 291 | + case LLVMRustAttributeKind::NoCapture: |
236 | 292 | return Attribute::NoCapture;
|
237 |
| - case NoCfCheck: |
| 293 | + case LLVMRustAttributeKind::NoCfCheck: |
238 | 294 | return Attribute::NoCfCheck;
|
239 |
| - case NoInline: |
| 295 | + case LLVMRustAttributeKind::NoInline: |
240 | 296 | return Attribute::NoInline;
|
241 |
| - case NonNull: |
| 297 | + case LLVMRustAttributeKind::NonNull: |
242 | 298 | return Attribute::NonNull;
|
243 |
| - case NoRedZone: |
| 299 | + case LLVMRustAttributeKind::NoRedZone: |
244 | 300 | return Attribute::NoRedZone;
|
245 |
| - case NoReturn: |
| 301 | + case LLVMRustAttributeKind::NoReturn: |
246 | 302 | return Attribute::NoReturn;
|
247 |
| - case NoUnwind: |
| 303 | + case LLVMRustAttributeKind::NoUnwind: |
248 | 304 | return Attribute::NoUnwind;
|
249 |
| - case OptimizeForSize: |
| 305 | + case LLVMRustAttributeKind::OptimizeForSize: |
250 | 306 | return Attribute::OptimizeForSize;
|
251 |
| - case ReadOnly: |
| 307 | + case LLVMRustAttributeKind::ReadOnly: |
252 | 308 | return Attribute::ReadOnly;
|
253 |
| - case SExt: |
| 309 | + case LLVMRustAttributeKind::SExt: |
254 | 310 | return Attribute::SExt;
|
255 |
| - case StructRet: |
| 311 | + case LLVMRustAttributeKind::StructRet: |
256 | 312 | return Attribute::StructRet;
|
257 |
| - case UWTable: |
| 313 | + case LLVMRustAttributeKind::UWTable: |
258 | 314 | return Attribute::UWTable;
|
259 |
| - case ZExt: |
| 315 | + case LLVMRustAttributeKind::ZExt: |
260 | 316 | return Attribute::ZExt;
|
261 |
| - case InReg: |
| 317 | + case LLVMRustAttributeKind::InReg: |
262 | 318 | return Attribute::InReg;
|
263 |
| - case SanitizeThread: |
| 319 | + case LLVMRustAttributeKind::SanitizeThread: |
264 | 320 | return Attribute::SanitizeThread;
|
265 |
| - case SanitizeAddress: |
| 321 | + case LLVMRustAttributeKind::SanitizeAddress: |
266 | 322 | return Attribute::SanitizeAddress;
|
267 |
| - case SanitizeMemory: |
| 323 | + case LLVMRustAttributeKind::SanitizeMemory: |
268 | 324 | return Attribute::SanitizeMemory;
|
269 |
| - case NonLazyBind: |
| 325 | + case LLVMRustAttributeKind::NonLazyBind: |
270 | 326 | return Attribute::NonLazyBind;
|
271 |
| - case OptimizeNone: |
| 327 | + case LLVMRustAttributeKind::OptimizeNone: |
272 | 328 | return Attribute::OptimizeNone;
|
273 |
| - case ReadNone: |
| 329 | + case LLVMRustAttributeKind::ReadNone: |
274 | 330 | return Attribute::ReadNone;
|
275 |
| - case SanitizeHWAddress: |
| 331 | + case LLVMRustAttributeKind::SanitizeHWAddress: |
276 | 332 | return Attribute::SanitizeHWAddress;
|
277 |
| - case WillReturn: |
| 333 | + case LLVMRustAttributeKind::WillReturn: |
278 | 334 | return Attribute::WillReturn;
|
279 |
| - case StackProtectReq: |
| 335 | + case LLVMRustAttributeKind::StackProtectReq: |
280 | 336 | return Attribute::StackProtectReq;
|
281 |
| - case StackProtectStrong: |
| 337 | + case LLVMRustAttributeKind::StackProtectStrong: |
282 | 338 | return Attribute::StackProtectStrong;
|
283 |
| - case StackProtect: |
| 339 | + case LLVMRustAttributeKind::StackProtect: |
284 | 340 | return Attribute::StackProtect;
|
285 |
| - case NoUndef: |
| 341 | + case LLVMRustAttributeKind::NoUndef: |
286 | 342 | return Attribute::NoUndef;
|
287 |
| - case SanitizeMemTag: |
| 343 | + case LLVMRustAttributeKind::SanitizeMemTag: |
288 | 344 | return Attribute::SanitizeMemTag;
|
289 |
| - case ShadowCallStack: |
| 345 | + case LLVMRustAttributeKind::ShadowCallStack: |
290 | 346 | return Attribute::ShadowCallStack;
|
291 |
| - case AllocSize: |
| 347 | + case LLVMRustAttributeKind::AllocSize: |
292 | 348 | return Attribute::AllocSize;
|
293 |
| - case AllocatedPointer: |
| 349 | + case LLVMRustAttributeKind::AllocatedPointer: |
294 | 350 | return Attribute::AllocatedPointer;
|
295 |
| - case AllocAlign: |
| 351 | + case LLVMRustAttributeKind::AllocAlign: |
296 | 352 | return Attribute::AllocAlign;
|
297 |
| - case SanitizeSafeStack: |
| 353 | + case LLVMRustAttributeKind::SanitizeSafeStack: |
298 | 354 | return Attribute::SafeStack;
|
299 |
| - case FnRetThunkExtern: |
| 355 | + case LLVMRustAttributeKind::FnRetThunkExtern: |
300 | 356 | return Attribute::FnRetThunkExtern;
|
301 |
| - case Writable: |
| 357 | + case LLVMRustAttributeKind::Writable: |
302 | 358 | return Attribute::Writable;
|
303 |
| - case DeadOnUnwind: |
| 359 | + case LLVMRustAttributeKind::DeadOnUnwind: |
304 | 360 | return Attribute::DeadOnUnwind;
|
305 | 361 | }
|
306 |
| - report_fatal_error("bad AttributeKind"); |
| 362 | + report_fatal_error("bad LLVMRustAttributeKind"); |
307 | 363 | }
|
308 | 364 |
|
309 | 365 | template <typename T>
|
@@ -333,7 +389,7 @@ extern "C" void LLVMRustAddCallSiteAttributes(LLVMValueRef Instr,
|
333 | 389 | }
|
334 | 390 |
|
335 | 391 | extern "C" LLVMAttributeRef
|
336 |
| -LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttribute RustAttr) { |
| 392 | +LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttributeKind RustAttr) { |
337 | 393 | return wrap(Attribute::get(*unwrap(C), fromRust(RustAttr)));
|
338 | 394 | }
|
339 | 395 |
|
|
0 commit comments