Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 06339b5

Browse files
authored
Remove (most) .ll files from QIR Runtime implementation (#811)
* WIP: Attempt to remove IR files. Things that don't work: passing struct Range by value, since C expects pointer always; converting from QIR Pauli which is `i2` to C++ enum PauliId with is `int32_t`. * Compiling again * Fix ctl tuples, tests passing * Remove qsharp-foundation-qis.ll * Additional comments * Fix Exp to convert paulis correctly * CR feedback and fixes
1 parent 96b4572 commit 06339b5

35 files changed

+821
-1862
lines changed

src/Qir/Runtime/lib/QIR/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# create qir-rt-support lib from the C++ sources
1010
#
1111
set(rt_sup_source_files
12-
QirRange.cpp
1312
OutputStream.cpp
1413
Output.cpp
1514
allocationsTracker.cpp

src/Qir/Runtime/lib/QIR/Output.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Public API:
77
extern "C"
88
{
9-
void quantum__rt__message(QirString* qstr) // NOLINT
9+
void __quantum__rt__message(QirString* qstr) // NOLINT
1010
{
1111
Microsoft::Quantum::OutputStream::Get() << qstr->str << std::endl;
1212
}

src/Qir/Runtime/lib/QIR/QirRange.cpp

-21
This file was deleted.

src/Qir/Runtime/lib/QIR/QubitManager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ namespace Quantum
1616

1717
[[noreturn]] static void FailNow(const char* message)
1818
{
19-
quantum__rt__fail_cstr(message);
19+
__quantum__rt__fail_cstr(message);
2020
}
2121

2222
static void FailIf(bool condition, const char* message)
2323
{
2424
if (condition)
2525
{
26-
quantum__rt__fail_cstr(message);
26+
__quantum__rt__fail_cstr(message);
2727
}
2828
}
2929

src/Qir/Runtime/lib/QIR/allocationsTracker.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Quantum
2020
{
2121
if (inserted.first->second > 0)
2222
{
23-
quantum__rt__fail_cstr("Allocating an object over an existing object!");
23+
__quantum__rt__fail_cstr("Allocating an object over an existing object!");
2424
}
2525
else
2626
{
@@ -34,13 +34,13 @@ namespace Quantum
3434
auto tracked = this->allocatedObjects.find(object);
3535
if (tracked == this->allocatedObjects.end())
3636
{
37-
quantum__rt__fail_cstr("Attempting to addref an object that isn't tracked!");
37+
__quantum__rt__fail_cstr("Attempting to addref an object that isn't tracked!");
3838
}
3939
else
4040
{
4141
if (tracked->second <= 0)
4242
{
43-
quantum__rt__fail_cstr("Attempting to ressurect a previously released object!");
43+
__quantum__rt__fail_cstr("Attempting to ressurect a previously released object!");
4444
}
4545
else
4646
{
@@ -54,13 +54,13 @@ namespace Quantum
5454
auto tracked = this->allocatedObjects.find(object);
5555
if (tracked == this->allocatedObjects.end())
5656
{
57-
quantum__rt__fail_cstr("Attempting to release an object that isn't tracked!");
57+
__quantum__rt__fail_cstr("Attempting to release an object that isn't tracked!");
5858
}
5959
else
6060
{
6161
if (tracked->second <= 0)
6262
{
63-
quantum__rt__fail_cstr("Attempting to release a previously released object!");
63+
__quantum__rt__fail_cstr("Attempting to release a previously released object!");
6464
}
6565
else
6666
{
@@ -75,7 +75,7 @@ namespace Quantum
7575
{
7676
if (tracked.second > 0)
7777
{
78-
quantum__rt__fail_cstr("Found a potentially leaked object!");
78+
__quantum__rt__fail_cstr("Found a potentially leaked object!");
7979
}
8080
}
8181
}

src/Qir/Runtime/lib/QIR/arrays.cpp

+33-28
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ QirArray::QirArray(TItemCount qubits_count)
6565
Qubit* qbuffer = new Qubit[count];
6666
for (TItemCount i = 0; i < count; i++)
6767
{
68-
qbuffer[i] = quantum__rt__qubit_allocate();
68+
qbuffer[i] = __quantum__rt__qubit_allocate();
6969
}
7070
this->buffer = reinterpret_cast<char*>(qbuffer);
7171
}
@@ -238,22 +238,22 @@ static QirArray::TItemCount RunCount(const QirArray::TDimContainer& dimensionSiz
238238
}
239239

240240
/*==============================================================================
241-
Implementation of quantum__rt__* methods for arrays
241+
Implementation of __quantum__rt__* methods for arrays
242242
==============================================================================*/
243243
extern "C"
244244
{
245-
QirArray* quantum__rt__qubit_allocate_array(int64_t count) // TODO: Use `QirArray::TItemCount count`
246-
{ // (breaking change).
245+
QirArray* __quantum__rt__qubit_allocate_array(int64_t count) // TODO: Use `QirArray::TItemCount count`
246+
{ // (breaking change).
247247
return new QirArray((QirArray::TItemCount)count);
248248
}
249249

250-
QirArray* quantum__rt__qubit_borrow_array(int64_t count)
250+
QirArray* __quantum__rt__qubit_borrow_array(int64_t count)
251251
{
252252
// Currently we implement borrowing as allocation.
253-
return quantum__rt__qubit_allocate_array(count);
253+
return __quantum__rt__qubit_allocate_array(count);
254254
}
255255

256-
void quantum__rt__qubit_release_array(QirArray* qa)
256+
void __quantum__rt__qubit_release_array(QirArray* qa)
257257
{
258258
if (qa == nullptr)
259259
{
@@ -266,29 +266,29 @@ extern "C"
266266
Qubit* qubits = reinterpret_cast<Qubit*>(qa->buffer);
267267
for (QirArray::TItemCount i = 0; i < qa->count; i++)
268268
{
269-
quantum__rt__qubit_release(qubits[i]);
269+
__quantum__rt__qubit_release(qubits[i]);
270270
}
271271
}
272272

273-
quantum__rt__array_update_reference_count(qa, -1);
273+
__quantum__rt__array_update_reference_count(qa, -1);
274274
}
275275

276-
void quantum__rt__qubit_return_array(QirArray* qa)
276+
void __quantum__rt__qubit_return_array(QirArray* qa)
277277
{
278278
// Currently we implement borrowing as allocation.
279-
quantum__rt__qubit_release_array(qa);
279+
__quantum__rt__qubit_release_array(qa);
280280
}
281281

282282
// TODO: Use `QirArray::TItemSize itemSizeInBytes, QirArray::TItemCount count_items` (breaking change):
283-
QirArray* quantum__rt__array_create_1d(int32_t itemSizeInBytes, int64_t count_items)
283+
QirArray* __quantum__rt__array_create_1d(int32_t itemSizeInBytes, int64_t count_items)
284284
{
285285
assert(itemSizeInBytes > 0);
286286
return new QirArray((QirArray::TItemCount)count_items, (QirArray::TItemSize)itemSizeInBytes);
287287
}
288288

289289
// Bucketing of addref/release is non-standard so for now we'll keep the more traditional addref/release semantics
290290
// in the native types. Should reconsider, if the perf of the loops becomes an issue.
291-
void quantum__rt__array_update_reference_count(QirArray* array, int32_t increment)
291+
void __quantum__rt__array_update_reference_count(QirArray* array, int32_t increment)
292292
{
293293
if (array == nullptr || increment == 0)
294294
{
@@ -316,7 +316,7 @@ extern "C"
316316
}
317317
}
318318

319-
void quantum__rt__array_update_alias_count(QirArray* array, int32_t increment)
319+
void __quantum__rt__array_update_alias_count(QirArray* array, int32_t increment)
320320
{
321321
if (array == nullptr || increment == 0)
322322
{
@@ -325,34 +325,39 @@ extern "C"
325325
array->aliasCount += increment;
326326
if (array->aliasCount < 0)
327327
{
328-
quantum__rt__fail(quantum__rt__string_create("Alias count cannot be negative!"));
328+
__quantum__rt__fail(__quantum__rt__string_create("Alias count cannot be negative!"));
329329
}
330330
}
331331

332332
// TODO: Use `QirArray::TItemCount index` (breaking change):
333-
char* quantum__rt__array_get_element_ptr_1d(QirArray* array, int64_t index)
333+
char* __quantum__rt__array_get_element_ptr_1d(QirArray* array, int64_t index)
334334
{
335335
assert(array != nullptr);
336336
return array->GetItemPointer((QirArray::TItemCount)index);
337337
}
338338

339339
// Returns the number of dimensions in the array.
340-
int32_t quantum__rt__array_get_dim(QirArray* array) // TODO: Return `QirArray::TDimCount` (breaking change).
340+
int32_t __quantum__rt__array_get_dim(QirArray* array) // TODO: Return `QirArray::TDimCount` (breaking change).
341341
{
342342
assert(array != nullptr);
343343
return array->dimensions;
344344
}
345345

346346
// TODO: Use `QirArray::TDimCount dim`, return `QirArray::TItemCount` (breaking change):
347-
int64_t quantum__rt__array_get_size(QirArray* array, int32_t dim)
347+
int64_t __quantum__rt__array_get_size(QirArray* array, int32_t dim)
348348
{
349349
assert(array != nullptr);
350350
assert(dim < array->dimensions);
351351

352352
return array->dimensionSizes[(size_t)dim];
353353
}
354354

355-
QirArray* quantum__rt__array_copy(QirArray* array, bool forceNewInstance)
355+
int64_t __quantum__rt__array_get_size_1d(QirArray* array)
356+
{
357+
return __quantum__rt__array_get_size(array, 0);
358+
}
359+
360+
QirArray* __quantum__rt__array_copy(QirArray* array, bool forceNewInstance)
356361
{
357362
if (array == nullptr)
358363
{
@@ -366,7 +371,7 @@ extern "C"
366371
return array;
367372
}
368373

369-
QirArray* quantum__rt__array_concatenate(QirArray* head, QirArray* tail)
374+
QirArray* __quantum__rt__array_concatenate(QirArray* head, QirArray* tail)
370375
{
371376
assert(head != nullptr && tail != nullptr);
372377
assert(head->dimensions == 1 && tail->dimensions == 1);
@@ -380,7 +385,7 @@ extern "C"
380385
// The variable arguments should be a sequence of int64_ts contains the length of each dimension. The bytes of the
381386
// new array should be set to zero.
382387
// TODO: Use unsigned types (breaking change):
383-
QirArray* quantum__rt__array_create_nonvariadic(int itemSizeInBytes, int countDimensions, va_list dims)
388+
QirArray* __quantum__rt__array_create_nonvariadic(int itemSizeInBytes, int countDimensions, va_list dims)
384389
{
385390
QirArray::TDimContainer dimSizes;
386391
dimSizes.reserve((size_t)countDimensions);
@@ -401,17 +406,17 @@ extern "C"
401406
std::move(dimSizes));
402407
}
403408

404-
QirArray* quantum__rt__array_create(int itemSizeInBytes, int countDimensions, ...) // NOLINT
409+
QirArray* __quantum__rt__array_create(int itemSizeInBytes, int countDimensions, ...) // NOLINT
405410
{
406411
va_list args;
407412
va_start(args, countDimensions);
408-
QirArray* array = quantum__rt__array_create_nonvariadic(itemSizeInBytes, countDimensions, args);
413+
QirArray* array = __quantum__rt__array_create_nonvariadic(itemSizeInBytes, countDimensions, args);
409414
va_end(args);
410415

411416
return array;
412417
}
413418

414-
char* quantum__rt__array_get_element_ptr_nonvariadic(QirArray* array, va_list args) // NOLINT
419+
char* __quantum__rt__array_get_element_ptr_nonvariadic(QirArray* array, va_list args) // NOLINT
415420
{
416421
assert(array != nullptr);
417422

@@ -433,13 +438,13 @@ extern "C"
433438
#pragma GCC diagnostic ignored "-Wvarargs"
434439
// Returns a pointer to the indicated element of the array. The variable arguments should be a sequence of int64_ts
435440
// that are the indices for each dimension.
436-
char* quantum__rt__array_get_element_ptr(QirArray* array, ...) // NOLINT
441+
char* __quantum__rt__array_get_element_ptr(QirArray* array, ...) // NOLINT
437442
{
438443
assert(array != nullptr);
439444

440445
va_list args;
441446
va_start(args, array->dimensions); // TODO: (Bug or hack?) Replace `array->dimensions` with `array`.
442-
char* ptr = quantum__rt__array_get_element_ptr_nonvariadic(array, args);
447+
char* ptr = __quantum__rt__array_get_element_ptr_nonvariadic(array, args);
443448
va_end(args);
444449

445450
return ptr;
@@ -546,7 +551,7 @@ extern "C"
546551
// When range covers the whole dimension, can return a copy of the array without doing any math.
547552
if (range.step == 1 && range.start == 0 && range.end == array->dimensionSizes[(size_t)dim])
548553
{
549-
return quantum__rt__array_copy(array, true /*force*/);
554+
return __quantum__rt__array_copy(array, true /*force*/);
550555
}
551556

552557
// Create slice array of appropriate size.
@@ -614,7 +619,7 @@ extern "C"
614619
// projection is on, and the int64_t specifies the specific index value to project. The returned Array* will have
615620
// one fewer dimension than the existing array.
616621
// TODO: Use `QirArray::TDimCount dim, QirArray::TItemCount index` (breaking change):
617-
QirArray* quantum__rt__array_project(QirArray* array, int dim, int64_t index) // NOLINT
622+
QirArray* __quantum__rt__array_project(QirArray* array, int dim, int64_t index) // NOLINT
618623
{
619624
assert(array != nullptr);
620625
assert(dim >= 0 && dim < array->dimensions);

0 commit comments

Comments
 (0)